SKILL.md
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: leave activesnapshot/snapshothistory unwritten, leave snapshotpinned unset, and run the pass against the live tree exactly as today (single static snapshot; --targetroot semantics unchanged). - --snapshotkeep=<N>: retention for pinned snapshots under <stateroot>/.mantissnapshots/ (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. - --stateroot=<absolute path>: directory that contains workspace/ and .mantissnapshots/. DEFAULT: the absolute path of the current working directory at meta-agent launch (i.e., the parent of workspace/). If stateroot resolves inside CODEROOT (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 --stateroot outside CODEROOT — this is the DEFAULT and the only safe behavior without explicit opt-in. Auto-relocate (option b) is opt-in ONLY via an explicit --autorelocatestate flag (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 moving workspace/ and .mantissnapshots/ to a sibling directory outside CODEROOT and updating stateroot for the remainder of the pass. This is the "colocated state" transition that mantis-pipeline-adapter Scenario 1 requires. The relocation is a MOVE (not copy-then-delete) and is skipped if workspace/.workspaceedit.lock is 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, then rename(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). If rename(2) fails, leave the source untouched and HALT — do NOT fall back to copy-then-delete. - --autorelocatestate: OPT-IN flag. When stateroot resolves inside CODEROOT (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 --stateroot above. Without it, never move user state.
Input/Output Contract
- Reads:
- workspace/.mantisstate.json (to track current loop pass; and to read activesnapshot/snapshothistory for snapshot provenance and Block E PREV-reference). - Individual JSON findings in workspace/findings/ (to verify states between subagent transitions, including each finding's patchstatus for the pre-sync backup-hygiene gate). - workspace/.workspaceedit.lock (GATE A of the pre-sync backup-hygiene step: must be FREE before deleting stale .bak- files). - CODEROOT/.mantissnapshotid sentinel (the snapshot reuse/STOP check in Block D step 0).
- Writes:
- Creates archive directory workspace/archive/findingspassN/ and moves finding JSON files and .trash/ to it; and (Stage 15) COPIES workspace/.mantisstate.json and workspace/kb/ (incl. THREATMODEL.md) into it as the pass boundary reference. - Updates workspace/.mantisstate.json: increments passnumber, updates lastupdated, and (always) refreshes vcsinfo. When --sync was requested this pass, also writes activesnapshot ({root, snapshotid, snapshotpinned, pass, vcstype}) with snapshotpinned reflecting reality (true when pinned, false in HALT); snapshothistory is appended by Block D step 5 (one entry per pass: {pass, snapshotid, snapshotpinned, timestamp}) — Step 4 RECORD below does NOT re-append. These new keys are defined in schema.json #/$defs/state; they are optional and absent in MODE-OFF (no --sync). - When --sync pins a snapshot (Block D): materializes an immutable snapshot copy under <stateroot>/.mantissnapshots/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 the CODEROOT/.mantissnapshotid sentinel, and chmod -R a-w the copy.
- 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 SNAPSHOTID, else STOPs (reuse-or-STOP); keep-N GC (configurable --snapshotkeep, default 2) prunes older snapshots with matching teardown.
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 N from "passnumber" in workspace/.mantisstate.json. If missing or invalid, scan workspace/archive/ for folders matching findingspassN or loopNfindings and resolve N to maxfound + 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 --sync was passed OR the user explicitly instructed a sync for this pass. Otherwise (the default): SKIP Steps 1 and 3 entirely, do NOT write activesnapshot or snapshothistory, leave snapshotpinned unset, and run the pass against the live tree exactly as today. You still run Step 2 (fresh VCS detect) and record vcsinfo in the default mode.
Guard: Sync (Step 1) must be the very first mutating action of the pass. Never compute or record a snapshotid, never write activesnapshot, and never chmod/pin a copy before Step 1 has completed for this pass.
1. SYNC (must be the very first action of the pass; --sync only). First, pre-sync backup hygiene — remove stale .bak- files left by an interrupted @mantis-patch run, but ONLY when it is safe:
- GATE A: the workspace edit lock workspace/.workspaceedit.lock must 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 its patchstatus set (patching finalized). If any finding is mid-patch (no patchstatus), SKIP deletion. - SCOPE: delete only within the TARGET tree, never under Mantis state. The glob MUST be narrow: mantis-patch only ever creates <target>.bak-[findingid] where findingid is a UUIDv4 (schema.json #/$defs/uuid). The broad .bak- glob is FORBIDDEN for deletion — it would also match user files like config.yaml.bak-old or data.bak-2024. Use a UUID-anchored regex instead: find <targetroot> -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 '/.mantissnapshots/' -not -path '/workspace/' -delete. For full precision, enumerate workspace/findings/.json, read each id, and delete only <anything>.bak-<that-id> files. Never delete workspace/, <stateroot>/.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/, .mantissnapshots/ MUST be invisible to every dirty check. Delete stray mantis-summary.md and 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 vcsinfo): git : dirty if git status --porcelain -- ':(exclude)/mantis-summary.md' ':(exclude)/.bak-*' ':(exclude)workspace/' ':(exclude).mantissnapshots/' is non-empty; ahead if git rev-list --count @{u}..HEAD 2>/dev/null errors or > 0; detached if git symbolic-ref -q HEAD errors. hg : dirty if hg status -X '**/mantis-summary.md' -X '.bak-' -X 'workspace/' -X '.mantissnapshots/' non-empty. multi-vcs : dirty if repo forall -c "git status --porcelain -- ':(exclude)/mantis-summary.md' ':(exclude)/.bak-' ':(exclude)workspace/' ':(exclude).mantissnapshots/'" 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 contenthash 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/ and workspace/.mantis_state.json must still exist (Block C never touches workspace/). If either is missing after sync, HALT (do not detect, do not pin, do not proceed) and yield to the user.
2. 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):
1. Check for Git: run git rev-parse --is-inside-work-tree. If this command succeeds (returns exit code 0 and output is true), a Git repository is active. Set vcstype to "git" and extract: - commithash (via git rev-parse HEAD) - branch (via git branch --show-current or git rev-parse --abbrev-ref HEAD) - dirty status (check if git status --porcelain -- ':(exclude)/mantis-summary.md' ':(exclude)/.bak-' ':(exclude)workspace/' ':(exclude).mantissnapshots/' is non-empty — same exclude set as STEP 1, so colocated workspace/ and .mantissnapshots/ do not make the tree falsely dirty) 2. Check for Mercurial: check if .hg directory exists or run hg root (if Mercurial is installed). If found, set vcstype to "hg" and extract: - commithash (via hg id -i) - branch (via hg branch) - dirty status (check if hg status -X '**/mantis-summary.md' -X '.bak-' -X 'workspace/' -X '.mantissnapshots/' is non-empty — same exclude set as STEP 1) 3. Check for Multi-VCS systems: check if .repo directory exists or look for other multi-VCS markers. If found, resolve the active manifest revision (set revision) or branch, and check if any sub-repositories are dirty (set dirty). Set vcstype to "multi-vcs". 4. If you confirm that no VCS is active in the repository (e.g., the directory is a plain folder with no repository files or metadata), set vcstype to "none". 5. If detection commands fail due to errors, missing tool executables (e.g. git not found), or other unhandled exceptions during checks, set vcstype to "unknown".
3. PIN IMMUTABLE SNAPSHOT (only after sync; --sync only). Materialize an immutable per-pass copy and compute its identity:
PIN SNAPSHOT (after SYNC, before any stage): 0. CRASH-RESUME (run FIRST, before any copy/detect): if state.activesnapshot.pass == N on entry, REUSE that dir (no re-copy/re-pin). This reuse check is SAME-PASS ONLY — it does NOT cover cross-pass staleness (where Stage 15 preserved activesnapshot while incrementing passnumber). Consumer stages must apply the current-pass check (activesnapshot.pass == state.passnumber) described in mantis-pipeline-adapter Scenario 2. If snapshotpinned was true but the dir is now missing -> STOP and yield to the user (never re-pin to a possibly-drifted live tree). If reusing, skip steps 1–4 and go straight to step 5 (state write; the snapshot_history append inside Step 5 is itself idempotent — see Step 5).
1. Detect vcsinfo (existing meta-agent detection). VCSID = commithash (git/hg) / manifest revision (multi-vcs) / "" (else). 2. FREE-SPACE PRECHECK: if a full copy is needed, compare du -s of the live tree to df free space at stateroot. If it will not fit -> skip copy, go to step 5b (unpinned/HALT). Never crash mid-copy on ENOSPC. 3. Choose SNAPSHOTROOT and materialize (tiered): - Clean git -> git worktree add --detach <SNAPSHOTROOT>; clean hg -> hg archive <SNAPSHOTROOT> (cheap, buildable). GC MUST later run the matching teardown (git worktree remove/prune). - Else copyable tree -> SNAPSHOTROOT = \<stateroot>/.mantissnapshots/pass\\<N> (MUST NOT contain the path segment "/workspace/"). Copy EXCLUDING .git .hg .repo .svn CVS nested submodule VCS dirs, workspace/, .mantissnapshots/, mantis-summary.md, and .bak- (same hide-list as STEP 0, so a colocated stateroot cannot cause recursive self-copy); dereference symlinks pointing INSIDE the tree; DROP symlinks pointing outside; smudge LFS content if the analysis needs it. If stateroot itself resolves inside CODEROOT, the copy MUST additionally exclude the stateroot path itself. - Single binary/firmware -> copy the artifact into SNAPSHOTROOT. - Live endpoint / not a local dir -> go to step 5b. 4. FAILURE-TOLERANT VERIFY: check copy exit status + a cheap sanity check (file count / size within ~90% of source minus excludes). If a failed/missing file IS referenced by any archived/planned codepaths -> retry the copy once; if it still fails -> step 5b. If only unreferenced files failed -> pin and log skipped paths. 5a. PINNED: compute contenthash (whole copy), assemble SNAPSHOTID per the ladder, snapshotpinned=true, write SNAPSHOTID to SNAPSHOTROOT/.mantissnapshotid, best-effort chmod -R a-w SNAPSHOTROOT. 5b. UNPINNED (HALT mode): SNAPSHOTROOT=<live root>, snapshotpinned=false, SNAPSHOTID="live:"+ISO8601. Authoritative verdicts are forbidden this pass. 5. Write state.activesnapshot = {root, snapshotid, snapshotpinned, pass:N, vcstype}. APPEND {pass:N, snapshotid, snapshotpinned, timestamp} to state.snapshothistory ONLY IF no entry with pass == N already exists (idempotency check: scan snapshothistory for pass == N; this mirrors the once-only pattern used for signature and discoverycommit). On crash-resume reuse (Step 0 routed here), an entry for pass N may already have been written by the prior run — in that case, write activesnapshot only and do NOT append a second snapshothistory entry for the same pass. NEVER overwrite prior entries. There must be exactly one snapshothistory entry per pass. 6. RETENTION/GC: keep the last N snapshot dirs (operator-configurable via --snapshotkeep, DEFAULT 2 = this pass + previous); delete older via the matching teardown (rm -rf for copies; git worktree remove/prune for worktrees). Correctness never reads an old snapshot, so the default of 2 is safe; raise N when you want patch/PoC rebasing to apply against a finding's discovery snapshot. 7. CRASH-RESUME (Post-Check): if Step 0 did not trigger, and Block D returns snapshotpinned=false (HALT mode), still write activesnapshot in Step 4 and still pass --snapshotroot/ --snapshotid to stages so they see the HALT signal and degrade conservatively (no authoritative verdicts).
Block D performs the free-space precheck; chooses the clean-VCS fast path (git worktree / hg archive) or full copy / single-artifact copy / live- endpoint fallback per the snapshotid ladder; computes contenthash (sha256 over EVERY file in the pinned copy — never a partial hash); assembles SNAPSHOTID; writes the CODEROOT/.mantissnapshotid sentinel; chmod -R a-w the copy; runs keep-N GC (--snapshotkeep, default 2) with matching teardown; and handles crash-resume (reuse-or-STOP, step 0). Block D is fail-closed: if it cannot pin because the target is too big to copy or is not a local dir, it either falls back to a live:-prefixed id with snapshotpinned=false (live-endpoint gate) or HALTs the pass — in neither case may you proceed as if a pinned snapshot exists. If Block D returns snapshotpinned=false (HALT), still write activesnapshot in Step 4 and still pass --snapshotroot/ --snapshotid to stages so they see the HALT signal and degrade conservatively (no authoritative verdicts).
4. RECORD (only after Steps 1–3). Update workspace/.mantis_state.json (conforming to schema.json #/$defs/state):
- Write "vcsinfo" from Step 2 (always, both modes). - If --sync was requested this pass: write "activesnapshot" = { "root": <root>, "snapshotid": <SNAPSHOTID>, "snapshotpinned": <true if pinned, false if HALT>, "pass": <N>, "vcstype": <vcstype> }. Use the values Block D step 5 already wrote; do NOT re-derive them. snapshotpinned reflects reality: true when Step 3 pinned an immutable copy (5a), false in HALT (5b: live endpoint, too-big-to-copy, copy-failed, or dirty/racing tree). Do NOT re-append to "snapshothistory" — Block D step 5 already appended exactly one entry for this pass ({ "pass": <N>, "snapshotid": <SNAPSHOTID>, "snapshotpinned": <bool>, "timestamp": <ISO 8601> }). Re-appending would create a duplicate; there must be exactly one snapshothistory entry per pass. (If you are in a code path where Block D step 5 did NOT run — e.g. crash-resume reuse of an already-pinned snapshot — append here ONLY IF no entry for pass N already exists in snapshothistory (idempotency check: scan for pass == N); otherwise write activesnapshot only.) Match schema.json #/$defs/state EXACTLY: the per-entry key is pass (NOT passnumber); the separate top-level state.passnumber loop counter is written in State Maintenance below. - In MODE-OFF (no --sync requested): do NOT write activesnapshot or snapshothistory (leave them absent → downstream stages run exactly as today per the global backward-compat rule). Because Stage 15 sub-step 7 PRESERVES activesnapshot across pass boundaries, a prior --sync pass leaves a stale activesnapshot (with pass == N-1) behind. To actually achieve MODE-OFF semantics, you MUST actively DELETE any pre-existing activesnapshot key from workspace/.mantisstate.json when running a pass without --sync (in-place key delete, NOT a fresh-object overwrite — preserve vcsinfo, snapshothistory, passnumber, etc.). This is a DELETE-when-entering-MODE-OFF, not a "do not overwrite": leaving the stale key would trip the cross-pass staleness gate (activesnapshot.pass != state.passnumber) in consumer stages (mantis-calibrate, mantis-chain, mantis-architecture) and contradict the schema's MODE-OFF = activesnapshot ABSENT rule. snapshothistory is an append-only log — NEVER delete or truncate it; it remains as historical provenance. Writing activesnapshot with snapshotpinned=false is NOT the same as omitting it: an absent activesnapshot means MODE-OFF, while a present one with snapshotpinned=false means HALT (conservative, no authoritative verdicts). Never erase a HALT signal by omitting activesnapshot when --sync was requested. Never write activesnapshot or set snapshot_pinned=true before Steps 1–3 have completed for this pass.
- State Maintenance: Write the current pass N to "passnumber" and the current ISO 8601 timestamp to "lastupdated" in workspace/.mantisstate.json ("vcsinfo", and — when pinned — "activesnapshot"/"snapshothistory", were written in Startup Steps 2 and 4). Then delegate the workload sequentially to the specialized subagents. Call each subagent as a tool (or using the @agent_name syntax if instructed by your prompt) with a concise instruction to perform its designated task:
Snapshot argument passing (ALL stages, Stage 0–15). When --sync was requested this pass (whether PINNED or HALT — i.e. activesnapshot is present in state), APPEND these three arguments to the instruction string of EVERY @stage delegation below, using the values from activesnapshot: --snapshotroot=<activesnapshot.root> --snapshotid=<activesnapshot.snapshotid> --stateroot=<absolute path of the directory that contains workspace/>. Pass them to every stage uniformly and do NOT special-case the findings-only stages (report, calibrate, reflect): they ignore the code root via their own Block A ROLE gate. In HALT mode (activesnapshot.snapshotpinned == false), the stages still receive the roots and read activesnapshot from state — they use it to degrade conservatively (no authoritative verdicts). When NO --sync was requested (MODE-OFF), pass only --stateroot=<...> (plus --targetroot=<...> if you were already passing one, exactly as today); do NOT invent a --snapshotid. Do not edit the individual Stage 0–15 bullets — this single directive governs all of them.
Pin enablement. Block A (Locator Resolution) is universal across all code-reading stages. When --sync is requested, PIN in Step 3 and pass --snapshotroot/--snapshotid normally — do not artificially force snapshot_pinned=false. (The live:-id HALT fallback in Block D step 5b handles targets that genuinely cannot be pinned.)
- Stage 0 (Optional Pre-processing History): Call the @mantis-history subagent to analyze repository's version control system (VCS) history and extract past vulnerabilities and security fixes into a workspace/historical_learnings.jsonl file.
- Stage 0.5 (Optional Structural Index): Call the @mantis-structural-index subagent to build the structural index — a content-addressed semantic-unit index published as workspace/kb/structuralindex/manifest.json + catalog.sqlite (with structuralindex.jsonl as a compatibility pointer) and exposed via workspace/helpers/querystructuralindex.py. It runs immediately after the snapshot is pinned (Block D), before the first code-reading analysis stage, using only CODEROOT + SNAPSHOTID. In MODE-OFF, it builds against the current directory with snapshot_id set to "unknown" and rebuilds each pass (the live tree is mutable, so a reused index could lag current code). The index is a HINT-only enhancement — it never gates findings and degrades gracefully to an empty index (grep fallback) when unavailable or not invoked. A non-conformant harness simply skips this stage.
- Stage 1 (Optional Directory Mapping): If not already mapped, call the @mantis-summarize subagent to generate mantis-summary.md files for each directory to optimize downstream planning and summaries with historical context.
- Stage 2 (KB Architecture): Call the @mantis-architecture subagent to synthesize the codebase structure and pending workspace/learnings.jsonl into the permanent Markdown Knowledge Base (workspace/kb/).
- Stage 3 (Threat Modeling): Call the @mantis-threat-model subagent to read the KB and evaluate/update workspace/kb/THREAT_MODEL.md.
- Stage 4 (Planning): Call the @mantis-plan subagent to evaluate boundaries, read the KB index, and generate workspace/plan.json with injected context pointers.
- Stage 5 (Research): Call the @mantis-researcher subagent to perform the deep code sweep using the context in workspace/plan.json and populate the workspace/findings/ directory.
- Stage 6 (Deduplication): Call the @mantis-dedupe subagent to deduplicate files in the workspace/findings/ directory.
- Stage 7 (Review): Call the @mantis-review subagent to evaluate findings in the workspace/findings/ directory.
- Stage 8 (Critic): Call the @mantis-critic subagent to check production viability of files in the workspace/findings/ directory.
- Stage 9 (Reproduce): Call the @mantis-reproduce subagent to develop crash reproducers and update files in the workspace/findings/ directory.
- Stage 10 (Chain): Call the @mantis-chain subagent to analyze the current validated findings and the Knowledge Base to construct multi-step exploit chains, outputting "Super Findings" into the workspace/findings/ directory.
- Stage 11 (Patch & Verify): Call the @mantis-patch subagent to generate fixes, and update files in the workspace/findings/ directory. Instruct it to repeatedly call a fresh @mantis-reproduce subagent against its patches to attempt a bypass, refining the fix until the reproducer can no longer bypass it.
- Stage 12 (Calibrate): Call the @mantis-calibrate subagent to read the workspace/findings/ directory and append final calibration metrics to each finding file.
- Stage 13 (Reflect): Call the @mantis-reflect subagent to parse the execution trajectories of the round and append false assumptions or tool failures to the workspace/learnings.jsonl inbox. Important: You must pass the absolute file paths to the execution log files (e.g. transcript.jsonl files) of all subagents successfully executed during this round (every stage that ran: history, structural-index, summarize, architecture, threat-model, plan, researcher, dedupe, review, critic, reproduce, chain, patch, calibrate) to the @mantis-reflect subagent. Resolve these paths from whatever mechanism the ACTIVE coding-agent harness exposes for per-subagent execution logs; do NOT hardcode any single framework's layout. Harnesses differ — e.g. Antigravity stores them under <appDataDir>/brain/<conversationid>/.systemgenerated/logs/transcript.jsonl, while Gemini CLI, the Google ADK, Claude Code, and custom pipelines use different locations; Antigravity is ONE example, not the default. If your harness exposes no such logs, pass an EXPLICIT EMPTY list to @mantis-reflect and instruct it to record a missing-transcript insight per stage rather than silently emitting zero learnings.
- Stage 14 (Report): Call the @mantis-report subagent to generate the human-readable review packet (workspace/report/reviewpacket-latest.md and the per-pass archive workspace/report/reviewpacketpass<N>.md — which, when a snapshot is pinned, carries a snapshot suffix reviewpacketpass<N><snapshotid>.md so a re-used pass number on a different snapshot cannot overwrite a prior packet. reviewpacket-latest.md remains the stable entry point) containing only reproduced findings, evidence, and patches.
- Stage 15 (Archive & KB Verification):
1. Call the @mantis-architecture subagent to perform a final synthesis of the current round's findings (especially "FALSEPOSITIVE", "NONVIABLE", "SAMPLEORTEST", and "VERIFIEDSECURE") into the permanent Markdown Knowledge Base (workspace/kb/). 2. Verify that the KB updates were successfully written and that workspace/learnings.jsonl was processed. 3. Archive and Increment Pass: 1. Read the current pass number N from the state file workspace/.mantisstate.json. 2. Ensure the archive directory exists: workspace/archive/findingspassN/. 3. Snapshot the pass boundary (ALWAYS, even if findings/ is empty). COPY (never move) the following into workspace/archive/findingspassN/ so the next pass has an immutable reference point: - workspace/.mantisstate.json → workspace/archive/findingspassN/.mantisstate.json (preserves this pass's passnumber, vcsinfo, activesnapshot, and snapshothistory, giving @mantis-plan a PREV reference for Block E's changed-files diff). - the entire workspace/kb/ directory (including workspace/kb/THREATMODEL.md) → workspace/archive/findingspassN/kb/. Use copy, not move: the live workspace/kb/ and workspace/.mantisstate.json MUST survive into the next pass. 4. If workspace/findings/ exists and contains findings, MOVE all .json files and the .trash/ directory (if it exists) into workspace/archive/findingspassN/ (e.g., mv workspace/findings/*.json workspace/archive/findingspassN/). 5. If the findings directory is empty or does not exist, ensure it exists and skip the finding move (the state/KB copy in sub-step 3 still ran). 6. Increment N by 1 to get the new pass number Nnew = N + 1. 7. Write Nnew to "passnumber" and the current ISO 8601 timestamp to "lastupdated" in workspace/.mantisstate.json. PRESERVE, do not delete, the existing "vcsinfo", "activesnapshot", and "snapshothistory" keys when you rewrite the file — perform an in-place key update, NOT a fresh-object overwrite. Dropping these keys would strand @mantis-plan with no PREV reference.
- Intelligent Supervision & Error Handling:
- Wait for each subagent to finish its execution and report back. - After a subagent returns control to you, optionally use your file reading tools to quickly inspect the resulting JSON files (e.g., in workspace/findings/) to verify the state. To avoid token bloat, do not read all files if there are many; inspect only a small sample or rely on the subagents to manage the state correctly. - If a subagent reports a critical failure or crashes its isolated loop, diagnose the issue, explain the environment fix, and retry delegating to that subagent.
- Monitoring & Reporting: When the pipeline successfully reproduces a
security flaw or verifies a patch (reported by the @mantis-patch subagent), or when @mantis-calibrate finishes its scoring, you may output a brief text summary to the user.
- Do NOT report findings that failed to reproduce (reprostatus: "failedtoreproduce") as confirmed vulnerabilities. - Do NOT report findings that are marked LOW priority or are NONVIABLE as confirmed vulnerabilities. These are considered low-quality, fragile, or non-actionable. You may list them separately at the bottom of your summary under a "Hygiene & Low Priority Notes" section, but do not present them as active security flaws.
- Human-in-the-Loop Steering & Collaboration: While you are designed for
autonomy, remain responsive to user input. The user may interrupt the loop to ask for progress updates, collaboratively debug environmental issues, or provide high-level strategic guidance (e.g., "Focus exclusively on the networking stack in the next pass").
- Adapt the instructions you give to your subagents based on recent user feedback. - You can use your subagent delegation tools to perform "Deep Dives" on specific findings if the user requests more detail without interrupting the main loop logic. - Target-change & sync requests apply only at a pass boundary. If the user asks to change the target (re-point --targetroot / a different codebase) or to --sync now, do NOT apply it mid-pass. Defer it to the START of the next pass and only when workspace/findings/ is EMPTY (all findings archived by Stage 15). Applying a target or sync change while findings are in flight would strand those findings against a code root that no longer matches their discoverycommit, producing silent wrong results. If findings/ is non-empty, tell the user you will apply the change at the next boundary and let the current pass finish; if they insist on aborting, run Stage 15 to archive the current findings first, then apply the change at the fresh boundary.
- Resilience & Persistence: When Stage 15 (Archive & KB Verification)
completes, immediately begin the next pass. Chain your tool calls automatically. However, if you encounter a permanent, non-recoverable error (e.g., a persistent environment failure or fundamentally broken pipeline state), halt the loop and yield to the user. Try your best to recover from and fix transient issues (like rate limits or temporary file locks) before deciding to halt.