mantis-meta-agent
此技能作为常驻监督者,启动并监控长周期的自动化代码审查循环,维护轮次状态、发现清单与快照记录,在子代理交接前校验各发现状态。它让多轮、多代理协作的审查任务可以断点续跑、全程可审计,避免长任务中断后从头重来。
npx skills add https://github.com/google/mantis --skill mantis-meta-agentBefore / After 效果对比
2 组开发者需要手动启动每一轮审查、记录进度与发现清单,子代理交接时靠人反复核对状态,长任务一旦中断往往只能从头重跑,前面的结果全部作废。
此技能自动维护轮次计数、发现状态与快照记录,在交接前逐一校验每个发现的状态,中断后可从最后一次快照继续,整条审查链路保持可审计。
Meta-Agent Orchestrator (/mantis-meta-agent)
System Goal
Autonomous Campaign Manager. Supervises the continuous review loop, ensures resilience, and monitors long-running security pipelines.
Command Definition
- Command:
/mantis-meta-agent - Description: Acts as the persistent supervisor, launching and monitoring the automated review campaign.
- Parameters:
--sync: OPT-IN boundary sync + snapshot pinning. When present (or when the user explicitly instructs a sync for this pass), synchronize the target with its upstream at the START of the pass (Block C) and pin an immutable per-pass snapshot (Block D). When ABSENT (the default), do NOT sync and do NOT pin: leaveactive_snapshot/snapshot_historyunwritten, leavesnapshot_pinnedunset, and run the pass against the live tree exactly as today (single static snapshot;--target_rootsemantics unchanged).--snapshot_keep=<N>: retention for pinned snapshots under<state_root>/.mantis_snapshots/(Block D step 6 GC). DEFAULT 2 (this pass + previous), safe because correctness never re-reads an older snapshot; raise it for patch/PoC rebasing against a finding's discovery snapshot.--state_root=<absolute path>: directory that containsworkspace/and.mantis_snapshots/. DEFAULT: the absolute path of the current working directory at meta-agent launch (i.e., the parent ofworkspace/). Ifstate_rootresolves insideCODE_ROOT(the colocated case — the default when launching from inside the target repo), Step 3 (PIN) MUST (a) HALT and yield to the user with a message to pass--state_rootoutsideCODE_ROOT— this is the DEFAULT and the only safe behavior without explicit opt-in. Auto-relocate (option b) is opt-in ONLY via an explicit--auto_relocate_stateflag (or an equivalent user instruction to auto-relocate for this pass); without it, never move user state. When the user has explicitly opted in, auto-relocate by movingworkspace/and.mantis_snapshots/to a sibling directory outsideCODE_ROOTand updatingstate_rootfor the remainder of the pass. This is the "colocated state" transition thatmantis-pipeline-adapterScenario 1 requires. The relocation is a MOVE (not copy-then-delete) and is skipped ifworkspace/.workspace_edit.lockis held (INV-5: no user data loss). The MOVE MUST be atomic on the same filesystem: move into a fresh temp dir under the sibling's parent, thenrename(2)to the final sibling path; refuse and HALT if the sibling already exists or the temp dir cannot be created (never clobber an existing directory). Ifrename(2)fails, leave the source untouched and HALT — do NOT fall back to copy-then-delete.--auto_relocate_state: OPT-IN flag. Whenstate_rootresolves insideCODE_ROOT(colocated state — the default when launching from inside the target repo), the default behavior is to HALT and yield to the user. Passing this flag (or giving an equivalent user instruction) authorizes the atomic-MOVE auto-relocate path described under--state_rootabove. Without it, never move user state.
Input/Output Contract
- Reads:
workspace/.mantis_state.json(to track current loop pass; and to readactive_snapshot/snapshot_historyfor snapshot provenance and Block E PREV-reference).- Individual JSON findings in
workspace/findings/(to verify states between subagent transitions, including each finding'spatch_statusfor the pre-sync backup-hygiene gate). workspace/.workspace_edit.lock(GATE A of the pre-sync backup-hygiene step: must be FREE before deleting stale*.bak-*files).CODE_ROOT/.mantis_snapshot_idsentinel (the snapshot reuse/STOP check in Block D step 0).
- Writes:
- Creates archive directory
workspace/archive/findings_pass_N/and moves finding JSON files and.trash/to it; and (Stage 15) COPIESworkspace/.mantis_state.jsonandworkspace/kb/(incl.THREAT_MODEL.md) into it as the pass boundary reference. - Updates
workspace/.mantis_state.json: incrementspass_number, updateslast_updated, and (always) refreshesvcs_info. When--syncwas requested this pass, also writesactive_snapshot({root, snapshot_id, snapshot_pinned, pass, vcs_type}) withsnapshot_pinnedreflecting reality (truewhen pinned,falsein HALT);snapshot_historyis appended by Block D step 5 (one entry per pass:{pass, snapshot_id, snapshot_pinned, timestamp}) — Step 4 RECORD below does NOT re-append. These new keys are defined inschema.json#/$defs/state; they are optional and absent in MODE-OFF (no--sync). - When
--syncpins a snapshot (Block D): materializes an immutable snapshot copy under<state_root>/.mantis_snapshots/pass_<N>/(deliberately OUTSIDE any/workspace/path segment, so mantis-patch's existing state-vs-code path guard still treats it as CODE, not state), writes theCODE_ROOT/.mantis_snapshot_idsentinel, andchmod -R a-wthe copy.
- Creates archive directory
- Preconditions:
- Target project must be identified. Campaign orchestration tools/subagents must be ready.
- Idempotency Guarantee:
- Skips the finding move if
workspace/findings/is empty or missing (the state/KB boundary copy still runs). Determines pass number dynamically once from disk if the state file is missing to avoid overwriting existing archives during new runs. - Snapshot pinning is crash-safe: Block D reuses an already-materialized
snapshot whose sentinel matches the recomputed
SNAPSHOT_ID, else STOPs (reuse-or-STOP); keep-N GC (configurable--snapshot_keep, default 2) prunes older snapshots with matching teardown.
- Skips the finding move if
Instructions
Act as a persistent, long-lived supervisor that drives the Mantis defensive security reviewing pipeline continuously.
Target Agnosticism Directive: The target you are evaluating may be raw source code, a compiled binary, a firmware blob, or a live staging/dev endpoint. Ground your analysis in whatever format the target is currently in. You are authorized and encouraged to use whatever suitable tools are at your disposal (e.g., standard Unix tools,
unblob,radare2,angr,objdump,Ghidra,qemu,unicorn, emulator harnesses) to extract, analyze, reproduce, and test the findings. If source code is not available, do not attempt to force a source-code workflow; adapt and 'do what works' for the artifact at hand. Ensure your subagents are aware of the tools available to them.
Do not perform the auditing or patching tasks yourself. Instead, delegate them to specialized subagents to maintain context efficiency and isolate tasks.
Execute your orchestration duties in a continuous loop:
-
Sub-Agent Orchestration Loop: For each iteration of the review loop, maintain a loop pass counter
N.-
Initialization / Startup: Read
Nfrom"pass_number"inworkspace/.mantis_state.json. If missing or invalid, scanworkspace/archive/for folders matchingfindings_pass_NorloopN_findingsand resolveNtomax_found + 1(defaulting to 1 if no archives exist).Boundary Sync & Snapshot Pinning — Pass Lifecycle CONTRACT (STRICT ORDER). At the start of every pass perform the following four steps in EXACTLY this order. The Pass Lifecycle Contract (
schema.json→ "Non-JSON Contracts") requires you to SYNC FIRST and to NEVER record a snapshot id or pin a copy before syncing. Do not reorder these steps and do not skip Step 1 ahead of any snapshot write.Sync is OPT-IN. Perform Step 1 (SYNC) and Step 3 (PIN) ONLY when
--syncwas passed OR the user explicitly instructed a sync for this pass. Otherwise (the default): SKIP Steps 1 and 3 entirely, do NOT writeactive_snapshotorsnapshot_history, leavesnapshot_pinnedunset, and run the pass against the live tree exactly as today. You still run Step 2 (fresh VCS detect) and recordvcs_infoin the default mode.Guard: Sync (Step 1) must be the very first mutating action of the pass. Never compute or record a
snapshot_id, never writeactive_snapshot, and neverchmod/pin a copy before Step 1 has completed for this pass.-
SYNC (must be the very first action of the pass;
--synconly). First, pre-sync backup hygiene — remove stale*.bak-*files left by an interrupted@mantis-patchrun, but ONLY when it is safe:- GATE A: the workspace edit lock
workspace/.workspace_edit.lockmust be FREE (no patch in flight). If it is held or cannot be acquired non-blocking, SKIP deletion and proceed to sync (Block C STEP 0 hides*.bak-*from the dirty check anyway). - GATE B: every finding in
workspace/findings/must have itspatch_statusset (patching finalized). If any finding is mid-patch (nopatch_status), SKIP deletion. - SCOPE: delete only within the TARGET tree, never under Mantis state.
The glob MUST be narrow:
mantis-patchonly ever creates<target>.bak-[finding_id]wherefinding_idis a UUIDv4 (schema.json#/$defs/uuid). The broad*.bak-*glob is FORBIDDEN for deletion — it would also match user files likeconfig.yaml.bak-oldordata.bak-2024. Use a UUID-anchored regex instead:find <target_root> -regextype posix-extended -regex '.*\.bak-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' -not -path '*/.mantis_snapshots/*' -not -path '*/workspace/*' -delete. For full precision, enumerateworkspace/findings/*.json, read eachid, and delete only<anything>.bak-<that-id>files. Never deleteworkspace/,<state_root>/.mantis_snapshots/, or anything beneath them. Then synchronize the target with upstream at the pass boundary:
SYNC (very first action of the pass; ONLY if a sync was requested; NEVER mid-pass): STEP 0 - HIDE MANTIS ARTIFACTS from dirtiness: mantis-summary.md, .bak-, workspace/, .mantis_snapshots/ MUST be invisible to every dirty check. Delete stray
mantis-summary.mdand UUID-shaped*.bak-<uuid>files at the LIVE root first (same narrow glob as the SCOPE rule above — never the broad*.bak-*glob for deletion), and pass the per-VCS excludes below. (Else pass-1 summary pollution makes the tree permanently "dirty" and sync silently never runs.) STEP 1 - FRESH dirty/ahead pre-check (NEVER rely on last pass's vcs_info): git : dirty ifgit status --porcelain -- ':(exclude)**/mantis-summary.md' ':(exclude)**/*.bak-*' ':(exclude)workspace/' ':(exclude).mantis_snapshots/'is non-empty; ahead ifgit rev-list --count @{u}..HEAD 2>/dev/nullerrors or > 0; detached ifgit symbolic-ref -q HEADerrors. hg : dirty ifhg status -X '**/mantis-summary.md' -X '*.bak-*' -X 'workspace/**' -X '.mantis_snapshots/**'non-empty. multi-vcs : dirty ifrepo forall -c "git status --porcelain -- ':(exclude)**/mantis-summary.md' ':(exclude)**/*.bak-*' ':(exclude)workspace/' ':(exclude).mantis_snapshots/'"produces ANY output. If dirty OR ahead OR detached OR no-upstream -> DO NOT SYNC; log "sync skipped: local changes / detached / no upstream"; keep the tree. STEP 2 - SYNC (only if STEP 1 found clean AND on a tracked branch): git : git fetch && git merge --ff-only hg : hg pull && hg update --check multi-vcs : repo sync -c none / unknown : do NOT sync. STEP 3 - POST-SYNC INTEGRITY (git, if applicable): git submodule update --init --recursive ; if .gitattributes uses filter=lfs, git lfs pull. If either is needed but unavailable/fails -> force content_hash into SNAPSHOT_ID (do not trust the superproject commit alone). CATCH-ALL: if ANY sync command exits non-zero -> abort sync, keep the current tree, proceed to pin. Re-reviewing the same snapshot is always safe. NEVER run: git reset --hard, git checkout -- ., git clean, hg update -C, or any command that discards uncommitted / untracked / local-commit state.Block C runs in the LIVE repository root, is non-destructive, and per-VCS skips sync if the tree is dirty/ahead/detached. After sync completes, VERIFY the Mantis state survived:
workspace/andworkspace/.mantis_state.jsonmust still exist (Block C never touchesworkspace/). If either is missing after sync, HALT (do not detect, do not pin, do not proceed) and yield to the user. - GATE A: the workspace edit lock
-
FRESH VCS DETECT (only after sync). Re-detect the VCS AFTER syncing so recorded state reflects the post-sync tree. Run these checks in the LIVE repository root (Block A step 5 VCS-metadata carve-out — history/diff/VCS commands run in the live root, never inside a pinned CODE_ROOT):
- Check for Git: run
git rev-parse --is-inside-work-tree. If this command succeeds (returns exit code 0 and output istrue), a Git repository is active. Setvcs_typeto"git"and extract:commit_hash(viagit rev-parse HEAD)branch(viagit branch --show-currentorgit rev-parse --abbrev-ref HEAD)dirtystatus (check ifgit status --porcelain -- ':(exclude)**/mantis-summary.md' ':(exclude)**/*.bak-*' ':(exclude)workspace/' ':(exclude).mantis_snapshots/'is non-empty — same exclude set as STEP 1, so colocatedworkspace/and.mantis_snapshots/do not make the tree falsely dirty)
- Check for Mercurial: check if
.hgdirectory exists or runhg root(if Mercurial is installed). If found, setvcs_typeto"hg"and extract:commit_hash(viahg id -i)branch(viahg branch)dirtystatus (check ifhg status -X '**/mantis-summary.md' -X '*.bak-*' -X 'workspace/**' -X '.mantis_snapshots/**'is non-empty — same exclude set as STEP 1)
- Check for Multi-VCS systems: check if
.repodirectory exists or look for other multi-VCS markers. If found, resolve the active manifest revision (setrevision) or branch, and check if any sub-repositories are dirty (setdirty). Setvcs_typeto"multi-vcs". - If you confirm that no VCS is active in the repository (e.g., the directory is a plain folder with no reposit
- Check for Git: run
-
-
...
用户评价 (0)
发表评价
暂无评价
统计数据
用户评分
为此 Skill 评分