[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6991QQNG364RSM5TK71PA9M":3,"skill-same:01M6991QQNG364RSM5TK71PA9M":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":41,"linkOnly":42,"markdownContent":43,"markdownBody":44,"frontMatter":45,"refName":46,"commitSha":47,"skillDirectory":48,"forksCount":49,"repositoryHtmlUrl":50,"repositoryHomepageUrl":51,"ownerHtmlUrl":52,"ownerBlogUrl":53,"ownerDescription":54,"updatedAt":55,"install":56,"resources":69},"01M6991QQNG364RSM5TK71PA9M","mantis-meta-agent",null,"Acts as the persistent supervisor, launching and monitoring the automated review campaign. Use when running a long-running, continuous security review campaign that needs autonomous coordination. Don't use for executing individual review stages directly.","google\u002Fmantis","google","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1342004?v=4","01M698VYEFDM0VJBZDYYJ2T83S","Google","01M6990SDGGFEAP21TJNS7HEG9",2778,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-meta-agent\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],"mantis meta agent","Meta","meta agent","autonomous","running","when","for","long","as","campaign","use","review","coordination","supervisor","monitoring","security review","security","2026-11-10 10:12:30",false,"---\nname: mantis-meta-agent\ndescription: >-\n  Acts as the persistent supervisor, launching and monitoring the automated review campaign.\n  Use when running a long-running, continuous security review campaign that needs autonomous coordination.\n  Don't use for executing individual review stages directly.\n---\n\n# Meta-Agent Orchestrator (\u002Fmantis-meta-agent)\n\n## System Goal\n\nAutonomous Campaign Manager. Supervises the continuous review loop, ensures\nresilience, and monitors long-running security pipelines.\n\n## Command Definition\n\n- **Command:** `\u002Fmantis-meta-agent`\n- **Description:** Acts as the persistent supervisor, launching and monitoring\n  the automated review campaign.\n- **Parameters:**\n  - `--sync`: OPT-IN boundary sync + snapshot pinning. When present (or when the\n    user explicitly instructs a sync for this pass), synchronize the target with\n    its upstream at the START of the pass (Block C) and pin an immutable\n    per-pass snapshot (Block D). When ABSENT (the default), do NOT sync and do\n    NOT pin: leave `active_snapshot`\u002F`snapshot_history` unwritten, leave\n    `snapshot_pinned` unset, and run the pass against the live tree exactly as\n    today (single static snapshot; `--target_root` semantics unchanged).\n  - `--snapshot_keep=\u003CN>`: retention for pinned snapshots under\n    `\u003Cstate_root>\u002F.mantis_snapshots\u002F` (Block D step 6 GC). DEFAULT 2 (this pass\n    \\+ previous), safe because correctness never re-reads an older snapshot;\n    raise it for patch\u002FPoC rebasing against a finding's discovery snapshot.\n  - `--state_root=\u003Cabsolute path>`: directory that contains `workspace\u002F` and\n    `.mantis_snapshots\u002F`. DEFAULT: the absolute path of the current working\n    directory at meta-agent launch (i.e., the parent of `workspace\u002F`). If\n    `state_root` resolves inside `CODE_ROOT` (the colocated case — the default\n    when launching from inside the target repo), Step 3 (PIN) MUST (a) HALT and\n    yield to the user with a message to pass `--state_root` outside `CODE_ROOT`\n    — this is the DEFAULT and the only safe behavior without explicit opt-in.\n    Auto-relocate (option b) is opt-in ONLY via an explicit\n    `--auto_relocate_state` flag (or an equivalent user instruction to\n    auto-relocate for this pass); without it, never move user state. When the\n    user has explicitly opted in, auto-relocate by moving `workspace\u002F` and\n    `.mantis_snapshots\u002F` to a sibling directory outside `CODE_ROOT` and updating\n    `state_root` for the remainder of the pass. This is the \"colocated state\"\n    transition that `mantis-pipeline-adapter` Scenario 1 requires. The\n    relocation is a MOVE (not copy-then-delete) and is skipped if\n    `workspace\u002F.workspace_edit.lock` is held (INV-5: no user data loss). The\n    MOVE MUST be atomic on the same filesystem: move into a fresh temp dir under\n    the sibling's parent, then `rename(2)` to the final sibling path; refuse and\n    HALT if the sibling already exists or the temp dir cannot be created (never\n    clobber an existing directory). If `rename(2)` fails, leave the source\n    untouched and HALT — do NOT fall back to copy-then-delete.\n  - `--auto_relocate_state`: OPT-IN flag. When `state_root` resolves inside\n    `CODE_ROOT` (colocated state — the default when launching from inside the\n    target repo), the default behavior is to HALT and yield to the user. Passing\n    this flag (or giving an equivalent user instruction) authorizes the\n    atomic-MOVE auto-relocate path described under `--state_root` above. Without\n    it, never move user state.\n\n## Input\u002FOutput Contract\n\n- **Reads**:\n  - `workspace\u002F.mantis_state.json` (to track current loop pass; and to read\n    `active_snapshot`\u002F`snapshot_history` for snapshot provenance and Block E\n    PREV-reference).\n  - Individual JSON findings in `workspace\u002Ffindings\u002F` (to verify states between\n    subagent transitions, including each finding's `patch_status` for the\n    pre-sync backup-hygiene gate).\n  - `workspace\u002F.workspace_edit.lock` (GATE A of the pre-sync backup-hygiene\n    step: must be FREE before deleting stale `*.bak-*` files).\n  - `CODE_ROOT\u002F.mantis_snapshot_id` sentinel (the snapshot reuse\u002FSTOP check in\n    Block D step 0).\n- **Writes**:\n  - Creates archive directory `workspace\u002Farchive\u002Ffindings_pass_N\u002F` and moves\n    finding JSON files and `.trash\u002F` to it; and (Stage 15) COPIES\n    `workspace\u002F.mantis_state.json` and `workspace\u002Fkb\u002F` (incl. `THREAT_MODEL.md`)\n    into it as the pass boundary reference.\n  - Updates `workspace\u002F.mantis_state.json`: increments `pass_number`, updates\n    `last_updated`, and (always) refreshes `vcs_info`. When `--sync` was\n    requested this pass, also writes `active_snapshot`\n    (`{root, snapshot_id, snapshot_pinned, pass, vcs_type}`) with\n    `snapshot_pinned` reflecting reality (`true` when pinned, `false` in HALT);\n    `snapshot_history` is appended by Block D step 5 (one entry per pass:\n    `{pass, snapshot_id, snapshot_pinned, timestamp}`) — Step 4 RECORD below\n    does NOT re-append. These new keys are defined in `schema.json`\n    `#\u002F$defs\u002Fstate`; they are optional and absent in MODE-OFF (no `--sync`).\n  - When `--sync` pins a snapshot (Block D): materializes an immutable snapshot\n    copy under `\u003Cstate_root>\u002F.mantis_snapshots\u002Fpass_\u003CN>\u002F` (deliberately OUTSIDE\n    any `\u002Fworkspace\u002F` path segment, so mantis-patch's existing state-vs-code\n    path guard still treats it as CODE, not state), writes the\n    `CODE_ROOT\u002F.mantis_snapshot_id` sentinel, and `chmod -R a-w` the copy.\n- **Preconditions**:\n  - Target project must be identified. Campaign orchestration tools\u002Fsubagents\n    must be ready.\n- **Idempotency Guarantee**:\n  - Skips the finding move if `workspace\u002Ffindings\u002F` is empty or missing (the\n    state\u002FKB boundary copy still runs). Determines pass number dynamically once\n    from disk if the state file is missing to avoid overwriting existing\n    archives during new runs.\n  - Snapshot pinning is crash-safe: Block D reuses an already-materialized\n    snapshot whose sentinel matches the recomputed `SNAPSHOT_ID`, else STOPs\n    (reuse-or-STOP); keep-N GC (configurable `--snapshot_keep`, default 2)\n    prunes older snapshots with matching teardown.\n\n## Instructions\n\nAct as a persistent, long-lived supervisor that drives the Mantis defensive\nsecurity reviewing pipeline continuously.\n\n> **Target Agnosticism Directive:** The target you are evaluating may be raw\n> source code, a compiled binary, a firmware blob, or a live staging\u002Fdev\n> endpoint. Ground your analysis in whatever format the target is currently in.\n> You are authorized and encouraged to use whatever suitable tools are at your\n> disposal (e.g., standard Unix tools, `unblob`, `radare2`, `angr`, `objdump`,\n> `Ghidra`, `qemu`, `unicorn`, emulator harnesses) to extract, analyze,\n> reproduce, and test the findings. If source code is not available, do not\n> attempt to force a source-code workflow; adapt and 'do what works' for the\n> artifact at hand. Ensure your subagents are aware of the tools available to\n> them.\n\nDo not perform the auditing or patching tasks yourself. Instead, delegate them\nto specialized subagents to maintain context efficiency and isolate tasks.\n\nExecute your orchestration duties in a continuous loop:\n\n1. **Sub-Agent Orchestration Loop:** For each iteration of the review loop,\n   maintain a loop pass counter `N`.\n\n   - **Initialization \u002F Startup:** Read `N` from `\"pass_number\"` in\n     `workspace\u002F.mantis_state.json`. If missing or invalid, scan\n     `workspace\u002Farchive\u002F` for folders matching `findings_pass_N` or\n     `loopN_findings` and resolve `N` to `max_found + 1` (defaulting to 1 if no\n     archives exist).\n\n     **Boundary Sync & Snapshot Pinning — Pass Lifecycle CONTRACT (STRICT\n     ORDER).** At the start of every pass perform the following four steps in\n     EXACTLY this order. The Pass Lifecycle Contract (`schema.json` → \"Non-JSON\n     Contracts\") requires you to SYNC FIRST and to NEVER record a snapshot id or\n     pin a copy before syncing. Do not reorder these steps and do not skip Step\n     1 ahead of any snapshot write.\n\n     **Sync is OPT-IN.** Perform Step 1 (SYNC) and Step 3 (PIN) ONLY when\n     `--sync` was passed OR the user explicitly instructed a sync for this pass.\n     Otherwise (the default): SKIP Steps 1 and 3 entirely, do NOT write\n     `active_snapshot` or `snapshot_history`, leave `snapshot_pinned` unset, and\n     run the pass against the live tree exactly as today. You still run Step 2\n     (fresh VCS detect) and record `vcs_info` in the default mode.\n\n     **Guard:** Sync (Step 1) must be the very first mutating action of the\n     pass. Never compute or record a `snapshot_id`, never write\n     `active_snapshot`, and never `chmod`\u002Fpin a copy before Step 1 has completed\n     for this pass.\n\n     1. **SYNC (must be the very first action of the pass; `--sync` only).**\n        First, **pre-sync backup hygiene** — remove stale `*.bak-*` files left\n        by an interrupted `@mantis-patch` run, but ONLY when it is safe:\n\n        - GATE A: the workspace edit lock `workspace\u002F.workspace_edit.lock` must\n          be FREE (no patch in flight). If it is held or cannot be acquired\n          non-blocking, SKIP deletion and proceed to sync (Block C STEP 0 hides\n          `*.bak-*` from the dirty check anyway).\n        - GATE B: every finding in `workspace\u002Ffindings\u002F` must have its\n          `patch_status` set (patching finalized). If any finding is mid-patch\n          (no `patch_status`), SKIP deletion.\n        - SCOPE: delete only within the TARGET tree, never under Mantis state.\n          The glob MUST be narrow: `mantis-patch` only ever creates\n          `\u003Ctarget>.bak-[finding_id]` where `finding_id` is a UUIDv4\n          (`schema.json` `#\u002F$defs\u002Fuuid`). The broad `*.bak-*` glob is FORBIDDEN\n          for deletion — it would also match user files like\n          `config.yaml.bak-old` or `data.bak-2024`. Use a UUID-anchored regex\n          instead:\n          `find \u003Ctarget_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 '*\u002F.mantis_snapshots\u002F*' -not -path '*\u002Fworkspace\u002F*' -delete`.\n          For full precision, enumerate `workspace\u002Ffindings\u002F*.json`, read each\n          `id`, and delete only `\u003Canything>.bak-\u003Cthat-id>` files. Never delete\n          `workspace\u002F`, `\u003Cstate_root>\u002F.mantis_snapshots\u002F`, or anything beneath\n          them. Then synchronize the target with upstream at the pass boundary:\n\n        SYNC (very first action of the pass; ONLY if a sync was requested; NEVER\n        mid-pass): STEP 0 - HIDE MANTIS ARTIFACTS from dirtiness:\n        mantis-summary.md, *.bak-*, workspace\u002F, .mantis_snapshots\u002F MUST be\n        invisible to every dirty check. Delete stray `mantis-summary.md` and\n        UUID-shaped `*.bak-\u003Cuuid>` files at the LIVE root first (same narrow\n        glob as the SCOPE rule above — never the broad `*.bak-*` glob for\n        deletion), and pass the per-VCS excludes below. (Else pass-1 summary\n        pollution makes the tree permanently \"dirty\" and sync silently never\n        runs.) STEP 1 - FRESH dirty\u002Fahead pre-check (NEVER rely on last pass's\n        vcs_info): git : dirty if\n        `git status --porcelain         -- ':(exclude)**\u002Fmantis-summary.md'         ':(exclude)**\u002F*.bak-*'         ':(exclude)workspace\u002F'         ':(exclude).mantis_snapshots\u002F'`\n        is non-empty; ahead if `git rev-list --count @{u}..HEAD 2>\u002Fdev\u002Fnull`\n        errors or > 0; detached if `git symbolic-ref -q HEAD` errors. hg : dirty\n        if\n        `hg status -X '**\u002Fmantis-summary.md' -X '*.bak-*' -X 'workspace\u002F**' -X '.mantis_snapshots\u002F**'`\n        non-empty. multi-vcs : dirty if\n        `repo forall -c \"git status         --porcelain         -- ':(exclude)**\u002Fmantis-summary.md'         ':(exclude)**\u002F*.bak-*'         ':(exclude)workspace\u002F'         ':(exclude).mantis_snapshots\u002F'\"`\n        produces ANY output. If dirty OR ahead OR detached OR no-upstream -> DO\n        NOT SYNC; log \"sync skipped: local changes \u002F detached \u002F no upstream\";\n        keep the tree. STEP 2 - SYNC (only if STEP 1 found clean AND on a\n        tracked branch): git : git fetch && git merge --ff-only hg : hg pull &&\n        hg update --check multi-vcs : repo sync -c none \u002F unknown : do NOT sync.\n        STEP 3 - POST-SYNC INTEGRITY (git, if applicable): git submodule update\n        --init --recursive ; if .gitattributes uses filter=lfs, git lfs pull. If\n        either is needed but unavailable\u002Ffails -> force content_hash into\n        SNAPSHOT_ID (do not trust the superproject commit alone). CATCH-ALL: if\n        ANY sync command exits non-zero -> abort sync, keep the current tree,\n        proceed to pin. Re-reviewing the same snapshot is always safe. NEVER\n        run: git reset --hard, git checkout -- ., git clean, hg update -C, or\n        any command that discards uncommitted \u002F untracked \u002F local-commit state.\n\n        Block C runs in the LIVE repository root, is non-destructive, and\n        per-VCS skips sync if the tree is dirty\u002Fahead\u002Fdetached. After sync\n        completes, VERIFY the Mantis state survived: `workspace\u002F` and\n        `workspace\u002F.mantis_state.json` must still exist (Block C never touches\n        `workspace\u002F`). If either is missing after sync, HALT (do not detect, do\n        not pin, do not proceed) and yield to the user.\n\n     2. **FRESH VCS DETECT (only after sync).** Re-detect the VCS AFTER syncing\n        so recorded state reflects the post-sync tree. Run these checks in the\n        LIVE repository root (Block A step 5 VCS-metadata carve-out —\n        history\u002Fdiff\u002FVCS commands run in the live root, never inside a pinned\n        CODE_ROOT):\n\n        1. Check for Git: run `git rev-parse --is-inside-work-tree`. If this\n           command succeeds (returns exit code 0 and output is `true`), a Git\n           repository is active. Set `vcs_type` to `\"git\"` and extract:\n           - `commit_hash` (via `git rev-parse HEAD`)\n           - `branch` (via `git branch --show-current` or\n             `git rev-parse --abbrev-ref HEAD`)\n           - `dirty` status (check if\n             `git status --porcelain -- ':(exclude)**\u002Fmantis-summary.md' ':(exclude)**\u002F*.bak-*' ':(exclude)workspace\u002F' ':(exclude).mantis_snapshots\u002F'`\n             is non-empty — same exclude set as STEP 1, so colocated\n             `workspace\u002F` and `.mantis_snapshots\u002F` do not make the tree falsely\n             dirty)\n        2. Check for Mercurial: check if `.hg` directory exists or run `hg root`\n           (if Mercurial is installed). If found, set `vcs_type` to `\"hg\"` and\n           extract:\n           - `commit_hash` (via `hg id -i`)\n           - `branch` (via `hg branch`)\n           - `dirty` status (check if\n             `hg status -X '**\u002Fmantis-summary.md' -X '*.bak-*' -X 'workspace\u002F**' -X '.mantis_snapshots\u002F**'`\n             is non-empty — same exclude set as STEP 1)\n        3. Check for Multi-VCS systems: check if `.repo` directory exists or\n           look for other multi-VCS markers. If found, resolve the active\n           manifest revision (set `revision`) or branch, and check if any\n           sub-repositories are dirty (set `dirty`). Set `vcs_type` to\n           `\"multi-vcs\"`.\n        4. If you confirm that no VCS is active in the repository (e.g., the\n           directory is a plain folder with no repository files or metadata),\n           set `vcs_type` to `\"none\"`.\n        5. If detection commands fail due to errors, missing tool executables\n           (e.g. `git` not found), or other unhandled exceptions during checks,\n           set `vcs_type` to `\"unknown\"`.\n\n     3. **PIN IMMUTABLE SNAPSHOT (only after sync; `--sync` only).** Materialize\n        an immutable per-pass copy and compute its identity:\n\n        PIN SNAPSHOT (after SYNC, before any stage): 0. CRASH-RESUME (run FIRST,\n        before any copy\u002Fdetect): if `state.active_snapshot.pass == N` on entry,\n        REUSE that dir (no re-copy\u002Fre-pin). This reuse check is SAME-PASS ONLY —\n        it does NOT cover cross-pass staleness (where Stage 15 preserved\n        `active_snapshot` while incrementing `pass_number`). Consumer stages\n        must apply the current-pass check\n        (`active_snapshot.pass == state.pass_number`) described in\n        `mantis-pipeline-adapter` Scenario 2. If `snapshot_pinned` was true but\n        the dir is now missing -> STOP and yield to the user (never re-pin to a\n        possibly-drifted live tree). If reusing, skip steps 1–4 and go straight\n        to step 5 (state write; the `snapshot_history` append inside Step 5 is\n        itself idempotent — see Step 5).\n\n        1. Detect vcs_info (existing meta-agent detection). VCS_ID = commit_hash\n           (git\u002Fhg) \u002F manifest revision (multi-vcs) \u002F \"\" (else).\n        2. FREE-SPACE PRECHECK: if a full copy is needed, compare `du -s` of the\n           live tree to `df` free space at state_root. If it will not fit ->\n           skip copy, go to step 5b (unpinned\u002FHALT). Never crash mid-copy on\n           ENOSPC.\n        3. Choose SNAPSHOT_ROOT and materialize (tiered):\n           - Clean git -> `git worktree add --detach \u003CSNAPSHOT_ROOT>`; clean hg\n             -> `hg archive \u003CSNAPSHOT_ROOT>` (cheap, buildable). GC MUST later\n             run the matching teardown (git worktree remove\u002Fprune).\n           - Else copyable tree -> SNAPSHOT_ROOT =\n             \\\u003Cstate_root>\u002F.mantis_snapshots\u002Fpass\\_\\\u003CN> (MUST NOT contain the\n             path segment \"\u002Fworkspace\u002F\"). Copy EXCLUDING .git .hg .repo .svn CVS\n             nested submodule VCS dirs, workspace\u002F, .mantis_snapshots\u002F,\n             mantis-summary.md, and *.bak-* (same hide-list as STEP 0, so a\n             colocated state_root cannot cause recursive self-copy); dereference\n             symlinks pointing INSIDE the tree; DROP symlinks pointing outside;\n             smudge LFS content if the analysis needs it. If `state_root` itself\n             resolves inside CODE_ROOT, the copy MUST additionally exclude the\n             `state_root` path itself.\n           - Single binary\u002Ffirmware -> copy the artifact into SNAPSHOT_ROOT.\n           - Live endpoint \u002F not a local dir -> go to step 5b.\n        4. FAILURE-TOLERANT VERIFY: check copy exit status + a cheap sanity\n           check (file count \u002F size within ~90% of source minus excludes). If a\n           failed\u002Fmissing file IS referenced by any archived\u002Fplanned code_paths\n           -> retry the copy once; if it still fails -> step 5b. If only\n           unreferenced files failed -> pin and log skipped paths. 5a. PINNED:\n           compute content_hash (whole copy), assemble SNAPSHOT_ID per the\n           ladder, snapshot_pinned=true, write SNAPSHOT_ID to\n           SNAPSHOT_ROOT\u002F.mantis_snapshot_id, best-effort chmod -R a-w\n           SNAPSHOT_ROOT. 5b. UNPINNED (HALT mode): SNAPSHOT_ROOT=\u003Clive root>,\n           snapshot_pinned=false, SNAPSHOT_ID=\"live:\"+ISO8601. Authoritative\n           verdicts are forbidden this pass.\n        5. Write state.active_snapshot = {root, snapshot_id, snapshot_pinned,\n           pass:N, vcs_type}. APPEND {pass:N, snapshot_id, snapshot_pinned,\n           timestamp} to state.snapshot_history ONLY IF no entry with\n           `pass == N` already exists (idempotency check: scan\n           `snapshot_history` for `pass == N`; this mirrors the once-only\n           pattern used for `signature` and `discovery_commit`). On crash-resume\n           reuse (Step 0 routed here), an entry for pass N may already have been\n           written by the prior run — in that case, write `active_snapshot` only\n           and do NOT append a second `snapshot_history` entry for the same\n           pass. NEVER overwrite prior entries. There must be exactly one\n           `snapshot_history` entry per pass.\n        6. RETENTION\u002FGC: keep the last N snapshot dirs (operator-configurable\n           via `--snapshot_keep`, DEFAULT 2 = this pass + previous); delete\n           older via the matching teardown (rm -rf for copies; git worktree\n           remove\u002Fprune for worktrees). Correctness never reads an old snapshot,\n           so the default of 2 is safe; raise N when you want patch\u002FPoC rebasing\n           to apply against a finding's discovery snapshot.\n        7. CRASH-RESUME (Post-Check): if Step 0 did not trigger, and Block D\n           returns `snapshot_pinned=false` (HALT mode), still write\n           `active_snapshot` in Step 4 and still pass `--snapshot_root`\u002F\n           `--snapshot_id` to stages so they see the HALT signal and degrade\n           conservatively (no authoritative verdicts).\n\n        Block D performs the free-space precheck; chooses the clean-VCS fast\n        path (git worktree \u002F hg archive) or full copy \u002F single-artifact copy \u002F\n        live- endpoint fallback per the snapshot_id ladder; computes\n        `content_hash` (sha256 over EVERY file in the pinned copy — never a\n        partial hash); assembles `SNAPSHOT_ID`; writes the\n        `CODE_ROOT\u002F.mantis_snapshot_id` sentinel; `chmod -R a-w` the copy; runs\n        keep-N GC (`--snapshot_keep`, default 2) with matching teardown; and\n        handles crash-resume (reuse-or-STOP, step 0). Block D is fail-closed: if\n        it cannot pin because the target is too big to copy or is not a local\n        dir, it either falls back to a `live:`-prefixed id with\n        `snapshot_pinned=false` (live-endpoint gate) or HALTs the pass — in\n        neither case may you proceed as if a pinned snapshot exists. If Block D\n        returns `snapshot_pinned=false` (HALT), still write `active_snapshot` in\n        Step 4 and still pass `--snapshot_root`\u002F `--snapshot_id` to stages so\n        they see the HALT signal and degrade conservatively (no authoritative\n        verdicts).\n\n     4. **RECORD (only after Steps 1–3).** Update `workspace\u002F.mantis_state.json`\n        (conforming to `schema.json` `#\u002F$defs\u002Fstate`):\n\n        - Write `\"vcs_info\"` from Step 2 (always, both modes).\n        - If `--sync` was requested this pass: write `\"active_snapshot\"` =\n          `{ \"root\": \u003Croot>, \"snapshot_id\": \u003CSNAPSHOT_ID>, \"snapshot_pinned\": \u003Ctrue if pinned, false if HALT>, \"pass\": \u003CN>, \"vcs_type\": \u003Cvcs_type> }`.\n          Use the values Block D step 5 already wrote; do NOT re-derive them.\n          `snapshot_pinned` reflects reality: `true` when Step 3 pinned an\n          immutable copy (5a), `false` in HALT (5b: live endpoint,\n          too-big-to-copy, copy-failed, or dirty\u002Fracing tree). **Do NOT\n          re-append to `\"snapshot_history\"`** — Block D step 5 already appended\n          exactly one entry for this pass\n          (`{ \"pass\": \u003CN>, \"snapshot_id\": \u003CSNAPSHOT_ID>, \"snapshot_pinned\": \u003Cbool>, \"timestamp\": \u003CISO 8601> }`).\n          Re-appending would create a duplicate; there must be exactly one\n          `snapshot_history` entry per pass. (If you are in a code path where\n          Block D step 5 did NOT run — e.g. crash-resume reuse of an\n          already-pinned snapshot — append here ONLY IF no entry for pass N\n          already exists in `snapshot_history` (idempotency check: scan for\n          `pass == N`); otherwise write `active_snapshot` only.) Match\n          `schema.json` `#\u002F$defs\u002Fstate` EXACTLY: the per-entry key is `pass`\n          (NOT `pass_number`); the separate top-level `state.pass_number` loop\n          counter is written in State Maintenance below.\n        - In MODE-OFF (no `--sync` requested): do NOT write `active_snapshot` or\n          `snapshot_history` (leave them absent → downstream stages run exactly\n          as today per the global backward-compat rule). Because Stage 15\n          sub-step 7 PRESERVES `active_snapshot` across pass boundaries, a prior\n          `--sync` pass leaves a stale `active_snapshot` (with `pass == N-1`)\n          behind. To actually achieve MODE-OFF semantics, you MUST actively\n          DELETE any pre-existing `active_snapshot` key from\n          `workspace\u002F.mantis_state.json` when running a pass without `--sync`\n          (in-place key delete, NOT a fresh-object overwrite — preserve\n          `vcs_info`, `snapshot_history`, `pass_number`, etc.). This is a\n          DELETE-when-entering-MODE-OFF, not a \"do not overwrite\": leaving the\n          stale key would trip the cross-pass staleness gate\n          (`active_snapshot.pass != state.pass_number`) in consumer stages\n          (`mantis-calibrate`, `mantis-chain`, `mantis-architecture`) and\n          contradict the schema's MODE-OFF = `active_snapshot` ABSENT rule.\n          `snapshot_history` is an append-only log — NEVER delete or truncate\n          it; it remains as historical provenance. Writing `active_snapshot`\n          with `snapshot_pinned=false` is NOT the same as omitting it: an absent\n          `active_snapshot` means MODE-OFF, while a present one with\n          `snapshot_pinned=false` means HALT (conservative, no authoritative\n          verdicts). Never erase a HALT signal by omitting `active_snapshot`\n          when `--sync` was requested. Never write `active_snapshot` or set\n          `snapshot_pinned=true` before Steps 1–3 have completed for this pass.\n\n   - **State Maintenance:** Write the current pass `N` to `\"pass_number\"` and\n     the current ISO 8601 timestamp to `\"last_updated\"` in\n     `workspace\u002F.mantis_state.json` (`\"vcs_info\"`, and — when pinned —\n     `\"active_snapshot\"`\u002F`\"snapshot_history\"`, were written in Startup Steps 2\n     and 4). Then delegate the workload sequentially to the specialized\n     subagents. Call each subagent as a tool (or using the `@agent_name` syntax\n     if instructed by your prompt) with a concise instruction to perform its\n     designated task:\n\n     **Snapshot argument passing (ALL stages, Stage 0–15).** When `--sync` was\n     requested this pass (whether PINNED or HALT — i.e. `active_snapshot` is\n     present in state), APPEND these three arguments to the instruction string\n     of EVERY `@stage` delegation below, using the values from\n     `active_snapshot`:\n     `--snapshot_root=\u003Cactive_snapshot.root> --snapshot_id=\u003Cactive_snapshot.snapshot_id> --state_root=\u003Cabsolute path of the directory that contains workspace\u002F>`.\n     Pass them to every stage uniformly and do NOT special-case the\n     findings-only stages (report, calibrate, reflect): they ignore the code\n     root via their own Block A ROLE gate. In HALT mode\n     (`active_snapshot.snapshot_pinned == false`), the stages still receive the\n     roots and read `active_snapshot` from state — they use it to degrade\n     conservatively (no authoritative verdicts). When NO `--sync` was requested\n     (MODE-OFF), pass only `--state_root=\u003C...>` (plus `--target_root=\u003C...>` if\n     you were already passing one, exactly as today); do NOT invent a\n     `--snapshot_id`. Do not edit the individual Stage 0–15 bullets — this\n     single directive governs all of them.\n\n     **Pin enablement.** Block A (Locator Resolution) is universal across all\n     code-reading stages. When `--sync` is requested, PIN in Step 3 and pass\n     `--snapshot_root`\u002F`--snapshot_id` normally — do not artificially force\n     `snapshot_pinned=false`. (The `live:`-id HALT fallback in Block D step 5b\n     handles targets that genuinely cannot be pinned.)\n\n   - **Stage 0 (Optional Pre-processing History):** Call the `@mantis-history`\n     subagent to analyze repository's version control system (VCS) history and\n     extract past vulnerabilities and security fixes into a\n     `workspace\u002Fhistorical_learnings.jsonl` file.\n\n   - **Stage 0.5 (Optional Structural Index):** Call the\n     `@mantis-structural-index` subagent to build the structural index — a\n     content-addressed semantic-unit index published as\n     `workspace\u002Fkb\u002Fstructural_index\u002Fmanifest.json` + `catalog.sqlite` (with\n     `structural_index.jsonl` as a compatibility pointer) and exposed via\n     `workspace\u002Fhelpers\u002Fquery_structural_index.py`. It runs immediately after\n     the snapshot is pinned (Block D), before the first code-reading analysis\n     stage, using only CODE_ROOT + SNAPSHOT_ID. In MODE-OFF, it builds against\n     the current directory with `snapshot_id` set to `\"unknown\"` and rebuilds\n     each pass (the live tree is mutable, so a reused index could lag current\n     code). The index is a HINT-only enhancement — it never gates findings and\n     degrades gracefully to an empty index (grep fallback) when unavailable or\n     not invoked. A non-conformant harness simply skips this stage.\n\n   - **Stage 1 (Optional Directory Mapping):** If not already mapped, call the\n     `@mantis-summarize` subagent to generate `mantis-summary.md` files for each\n     directory to optimize downstream planning and summaries with historical\n     context.\n\n   - **Stage 2 (KB Architecture):** Call the `@mantis-architecture` subagent to\n     synthesize the codebase structure and pending `workspace\u002Flearnings.jsonl`\n     into the permanent Markdown Knowledge Base (`workspace\u002Fkb\u002F`).\n\n   - **Stage 3 (Threat Modeling):** Call the `@mantis-threat-model` subagent to\n     read the KB and evaluate\u002Fupdate `workspace\u002Fkb\u002FTHREAT_MODEL.md`.\n\n   - **Stage 4 (Planning):** Call the `@mantis-plan` subagent to evaluate\n     boundaries, read the KB index, and generate `workspace\u002Fplan.json` with\n     injected context pointers.\n\n   - **Stage 5 (Research):** Call the `@mantis-researcher` subagent to perform\n     the deep code sweep using the context in `workspace\u002Fplan.json` and populate\n     the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 6 (Deduplication):** Call the `@mantis-dedupe` subagent to\n     deduplicate files in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 7 (Review):** Call the `@mantis-review` subagent to evaluate\n     findings in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 8 (Critic):** Call the `@mantis-critic` subagent to check\n     production viability of files in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 9 (Reproduce):** Call the `@mantis-reproduce` subagent to develop\n     crash reproducers and update files in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 10 (Chain):** Call the `@mantis-chain` subagent to analyze the\n     current validated findings and the Knowledge Base to construct multi-step\n     exploit chains, outputting \"Super Findings\" into the `workspace\u002Ffindings\u002F`\n     directory.\n\n   - **Stage 11 (Patch & Verify):** Call the `@mantis-patch` subagent to\n     generate fixes, and update files in the `workspace\u002Ffindings\u002F` directory.\n     Instruct it to repeatedly call a fresh `@mantis-reproduce` subagent against\n     its patches to attempt a bypass, refining the fix until the reproducer can\n     no longer bypass it.\n\n   - **Stage 12 (Calibrate):** Call the `@mantis-calibrate` subagent to read the\n     `workspace\u002Ffindings\u002F` directory and append final calibration metrics to\n     each finding file.\n\n   - **Stage 13 (Reflect):** Call the `@mantis-reflect` subagent to parse the\n     execution trajectories of the round and append false assumptions or tool\n     failures to the `workspace\u002Flearnings.jsonl` inbox. **Important:** You must\n     pass the absolute file paths to the execution log files (e.g.\n     `transcript.jsonl` files) of all subagents successfully executed during\n     this round (every stage that ran: history, structural-index, summarize,\n     architecture, threat-model, plan, researcher, dedupe, review, critic,\n     reproduce, chain, patch, calibrate) to the `@mantis-reflect` subagent.\n     Resolve these paths from whatever mechanism the ACTIVE coding-agent harness\n     exposes for per-subagent execution logs; do NOT hardcode any single\n     framework's layout. Harnesses differ — e.g. Antigravity stores them under\n     `\u003CappDataDir>\u002Fbrain\u002F\u003Cconversation_id>\u002F.system_generated\u002Flogs\u002Ftranscript.jsonl`,\n     while Gemini CLI, the Google ADK, Claude Code, and custom pipelines use\n     different locations; Antigravity is ONE example, not the default. If your\n     harness exposes no such logs, pass an EXPLICIT EMPTY list to\n     `@mantis-reflect` and instruct it to record a missing-transcript insight\n     per stage rather than silently emitting zero learnings.\n\n   - **Stage 14 (Report):** Call the `@mantis-report` subagent to generate the\n     human-readable review packet (`workspace\u002Freport\u002Freview_packet-latest.md`\n     and the per-pass archive `workspace\u002Freport\u002Freview_packet_pass_\u003CN>.md` —\n     which, when a snapshot is pinned, carries a snapshot suffix\n     `review_packet_pass_\u003CN>_\u003Csnapshot_id>.md` so a re-used pass number on a\n     different snapshot cannot overwrite a prior packet.\n     `review_packet-latest.md` remains the stable entry point) containing only\n     reproduced findings, evidence, and patches.\n\n   - **Stage 15 (Archive & KB Verification):**\n\n     1. **Call the `@mantis-architecture` subagent** to perform a final\n        synthesis of the current round's findings (especially\n        `\"FALSE_POSITIVE\"`, `\"NON_VIABLE\"`, `\"SAMPLE_OR_TEST\"`, and\n        `\"VERIFIED_SECURE\"`) into the permanent Markdown Knowledge Base\n        (`workspace\u002Fkb\u002F`).\n     2. Verify that the KB updates were successfully written and that\n        `workspace\u002Flearnings.jsonl` was processed.\n     3. **Archive and Increment Pass:**\n        1. Read the current pass number `N` from the state file\n           `workspace\u002F.mantis_state.json`.\n        2. Ensure the archive directory exists:\n           `workspace\u002Farchive\u002Ffindings_pass_N\u002F`.\n        3. **Snapshot the pass boundary (ALWAYS, even if `findings\u002F` is\n           empty).** COPY (never move) the following into\n           `workspace\u002Farchive\u002Ffindings_pass_N\u002F` so the next pass has an\n           immutable reference point:\n           - `workspace\u002F.mantis_state.json` →\n             `workspace\u002Farchive\u002Ffindings_pass_N\u002F.mantis_state.json` (preserves\n             this pass's `pass_number`, `vcs_info`, `active_snapshot`, and\n             `snapshot_history`, giving `@mantis-plan` a PREV reference for\n             Block E's changed-files diff).\n           - the entire `workspace\u002Fkb\u002F` directory (including\n             `workspace\u002Fkb\u002FTHREAT_MODEL.md`) →\n             `workspace\u002Farchive\u002Ffindings_pass_N\u002Fkb\u002F`. Use copy, not move: the\n             live `workspace\u002Fkb\u002F` and `workspace\u002F.mantis_state.json` MUST\n             survive into the next pass.\n        4. If `workspace\u002Ffindings\u002F` exists and contains findings, MOVE all\n           `.json` files and the `.trash\u002F` directory (if it exists) into\n           `workspace\u002Farchive\u002Ffindings_pass_N\u002F` (e.g.,\n           `mv workspace\u002Ffindings\u002F*.json workspace\u002Farchive\u002Ffindings_pass_N\u002F`).\n        5. If the findings directory is empty or does not exist, ensure it\n           exists and skip the finding move (the state\u002FKB copy in sub-step 3\n           still ran).\n        6. Increment `N` by 1 to get the new pass number `N_new = N + 1`.\n        7. Write `N_new` to `\"pass_number\"` and the current ISO 8601 timestamp\n           to `\"last_updated\"` in `workspace\u002F.mantis_state.json`. **PRESERVE, do\n           not delete,** the existing `\"vcs_info\"`, `\"active_snapshot\"`, and\n           `\"snapshot_history\"` keys when you rewrite the file — perform an\n           in-place key update, NOT a fresh-object overwrite. Dropping these\n           keys would strand `@mantis-plan` with no PREV reference.\n\n2. **Intelligent Supervision & Error Handling:**\n\n   - Wait for each subagent to finish its execution and report back.\n   - After a subagent returns control to you, optionally use your file reading\n     tools to quickly inspect the resulting JSON files (e.g., in\n     `workspace\u002Ffindings\u002F`) to verify the state. To avoid token bloat, do not\n     read all files if there are many; inspect only a small sample or rely on\n     the subagents to manage the state correctly.\n   - If a subagent reports a critical failure or crashes its isolated loop,\n     diagnose the issue, explain the environment fix, and retry delegating to\n     that subagent.\n\n3. **Monitoring & Reporting:** When the pipeline successfully reproduces a\n   security flaw or verifies a patch (reported by the `@mantis-patch` subagent),\n   or when `@mantis-calibrate` finishes its scoring, you may output a brief text\n   summary to the user.\n\n   - **Do NOT report findings that failed to reproduce\n     (`repro_status: \"failed_to_reproduce\"`) as confirmed vulnerabilities.**\n   - **Do NOT report findings that are marked `LOW` priority or are `NON_VIABLE`\n     as confirmed vulnerabilities.** These are considered low-quality, fragile,\n     or non-actionable. You may list them separately at the bottom of your\n     summary under a \"Hygiene & Low Priority Notes\" section, but do not present\n     them as active security flaws.\n\n4. **Human-in-the-Loop Steering & Collaboration:** While you are designed for\n   autonomy, remain responsive to user input. The user may interrupt the loop to\n   ask for progress updates, collaboratively debug environmental issues, or\n   provide high-level strategic guidance (e.g., \"Focus exclusively on the\n   networking stack in the next pass\").\n\n   - Adapt the instructions you give to your subagents based on recent user\n     feedback.\n   - You can use your subagent delegation tools to perform \"Deep Dives\" on\n     specific findings if the user requests more detail without interrupting the\n     main loop logic.\n   - **Target-change & sync requests apply only at a pass boundary.** If the\n     user asks to change the target (re-point `--target_root` \u002F a different\n     codebase) or to `--sync` now, do NOT apply it mid-pass. Defer it to the\n     START of the next pass and only when `workspace\u002Ffindings\u002F` is EMPTY (all\n     findings archived by Stage 15). Applying a target or sync change while\n     findings are in flight would strand those findings against a code root that\n     no longer matches their `discovery_commit`, producing silent wrong results.\n     If `findings\u002F` is non-empty, tell the user you will apply the change at the\n     next boundary and let the current pass finish; if they insist on aborting,\n     run Stage 15 to archive the current findings first, then apply the change\n     at the fresh boundary.\n\n5. **Resilience & Persistence:** When Stage 15 (Archive & KB Verification)\n   completes, immediately begin the next pass. Chain your tool calls\n   automatically. However, if you encounter a permanent, non-recoverable error\n   (e.g., a persistent environment failure or fundamentally broken pipeline\n   state), halt the loop and yield to the user. Try your best to recover from\n   and fix transient issues (like rate limits or temporary file locks) before\n   deciding to halt.\n","# Meta-Agent Orchestrator (\u002Fmantis-meta-agent)\n\n## System Goal\n\nAutonomous Campaign Manager. Supervises the continuous review loop, ensures\nresilience, and monitors long-running security pipelines.\n\n## Command Definition\n\n- **Command:** `\u002Fmantis-meta-agent`\n- **Description:** Acts as the persistent supervisor, launching and monitoring\n  the automated review campaign.\n- **Parameters:**\n  - `--sync`: OPT-IN boundary sync + snapshot pinning. When present (or when the\n    user explicitly instructs a sync for this pass), synchronize the target with\n    its upstream at the START of the pass (Block C) and pin an immutable\n    per-pass snapshot (Block D). When ABSENT (the default), do NOT sync and do\n    NOT pin: leave `active_snapshot`\u002F`snapshot_history` unwritten, leave\n    `snapshot_pinned` unset, and run the pass against the live tree exactly as\n    today (single static snapshot; `--target_root` semantics unchanged).\n  - `--snapshot_keep=\u003CN>`: retention for pinned snapshots under\n    `\u003Cstate_root>\u002F.mantis_snapshots\u002F` (Block D step 6 GC). DEFAULT 2 (this pass\n    \\+ previous), safe because correctness never re-reads an older snapshot;\n    raise it for patch\u002FPoC rebasing against a finding's discovery snapshot.\n  - `--state_root=\u003Cabsolute path>`: directory that contains `workspace\u002F` and\n    `.mantis_snapshots\u002F`. DEFAULT: the absolute path of the current working\n    directory at meta-agent launch (i.e., the parent of `workspace\u002F`). If\n    `state_root` resolves inside `CODE_ROOT` (the colocated case — the default\n    when launching from inside the target repo), Step 3 (PIN) MUST (a) HALT and\n    yield to the user with a message to pass `--state_root` outside `CODE_ROOT`\n    — this is the DEFAULT and the only safe behavior without explicit opt-in.\n    Auto-relocate (option b) is opt-in ONLY via an explicit\n    `--auto_relocate_state` flag (or an equivalent user instruction to\n    auto-relocate for this pass); without it, never move user state. When the\n    user has explicitly opted in, auto-relocate by moving `workspace\u002F` and\n    `.mantis_snapshots\u002F` to a sibling directory outside `CODE_ROOT` and updating\n    `state_root` for the remainder of the pass. This is the \"colocated state\"\n    transition that `mantis-pipeline-adapter` Scenario 1 requires. The\n    relocation is a MOVE (not copy-then-delete) and is skipped if\n    `workspace\u002F.workspace_edit.lock` is held (INV-5: no user data loss). The\n    MOVE MUST be atomic on the same filesystem: move into a fresh temp dir under\n    the sibling's parent, then `rename(2)` to the final sibling path; refuse and\n    HALT if the sibling already exists or the temp dir cannot be created (never\n    clobber an existing directory). If `rename(2)` fails, leave the source\n    untouched and HALT — do NOT fall back to copy-then-delete.\n  - `--auto_relocate_state`: OPT-IN flag. When `state_root` resolves inside\n    `CODE_ROOT` (colocated state — the default when launching from inside the\n    target repo), the default behavior is to HALT and yield to the user. Passing\n    this flag (or giving an equivalent user instruction) authorizes the\n    atomic-MOVE auto-relocate path described under `--state_root` above. Without\n    it, never move user state.\n\n## Input\u002FOutput Contract\n\n- **Reads**:\n  - `workspace\u002F.mantis_state.json` (to track current loop pass; and to read\n    `active_snapshot`\u002F`snapshot_history` for snapshot provenance and Block E\n    PREV-reference).\n  - Individual JSON findings in `workspace\u002Ffindings\u002F` (to verify states between\n    subagent transitions, including each finding's `patch_status` for the\n    pre-sync backup-hygiene gate).\n  - `workspace\u002F.workspace_edit.lock` (GATE A of the pre-sync backup-hygiene\n    step: must be FREE before deleting stale `*.bak-*` files).\n  - `CODE_ROOT\u002F.mantis_snapshot_id` sentinel (the snapshot reuse\u002FSTOP check in\n    Block D step 0).\n- **Writes**:\n  - Creates archive directory `workspace\u002Farchive\u002Ffindings_pass_N\u002F` and moves\n    finding JSON files and `.trash\u002F` to it; and (Stage 15) COPIES\n    `workspace\u002F.mantis_state.json` and `workspace\u002Fkb\u002F` (incl. `THREAT_MODEL.md`)\n    into it as the pass boundary reference.\n  - Updates `workspace\u002F.mantis_state.json`: increments `pass_number`, updates\n    `last_updated`, and (always) refreshes `vcs_info`. When `--sync` was\n    requested this pass, also writes `active_snapshot`\n    (`{root, snapshot_id, snapshot_pinned, pass, vcs_type}`) with\n    `snapshot_pinned` reflecting reality (`true` when pinned, `false` in HALT);\n    `snapshot_history` is appended by Block D step 5 (one entry per pass:\n    `{pass, snapshot_id, snapshot_pinned, timestamp}`) — Step 4 RECORD below\n    does NOT re-append. These new keys are defined in `schema.json`\n    `#\u002F$defs\u002Fstate`; they are optional and absent in MODE-OFF (no `--sync`).\n  - When `--sync` pins a snapshot (Block D): materializes an immutable snapshot\n    copy under `\u003Cstate_root>\u002F.mantis_snapshots\u002Fpass_\u003CN>\u002F` (deliberately OUTSIDE\n    any `\u002Fworkspace\u002F` path segment, so mantis-patch's existing state-vs-code\n    path guard still treats it as CODE, not state), writes the\n    `CODE_ROOT\u002F.mantis_snapshot_id` sentinel, and `chmod -R a-w` the copy.\n- **Preconditions**:\n  - Target project must be identified. Campaign orchestration tools\u002Fsubagents\n    must be ready.\n- **Idempotency Guarantee**:\n  - Skips the finding move if `workspace\u002Ffindings\u002F` is empty or missing (the\n    state\u002FKB boundary copy still runs). Determines pass number dynamically once\n    from disk if the state file is missing to avoid overwriting existing\n    archives during new runs.\n  - Snapshot pinning is crash-safe: Block D reuses an already-materialized\n    snapshot whose sentinel matches the recomputed `SNAPSHOT_ID`, else STOPs\n    (reuse-or-STOP); keep-N GC (configurable `--snapshot_keep`, default 2)\n    prunes older snapshots with matching teardown.\n\n## Instructions\n\nAct as a persistent, long-lived supervisor that drives the Mantis defensive\nsecurity reviewing pipeline continuously.\n\n> **Target Agnosticism Directive:** The target you are evaluating may be raw\n> source code, a compiled binary, a firmware blob, or a live staging\u002Fdev\n> endpoint. Ground your analysis in whatever format the target is currently in.\n> You are authorized and encouraged to use whatever suitable tools are at your\n> disposal (e.g., standard Unix tools, `unblob`, `radare2`, `angr`, `objdump`,\n> `Ghidra`, `qemu`, `unicorn`, emulator harnesses) to extract, analyze,\n> reproduce, and test the findings. If source code is not available, do not\n> attempt to force a source-code workflow; adapt and 'do what works' for the\n> artifact at hand. Ensure your subagents are aware of the tools available to\n> them.\n\nDo not perform the auditing or patching tasks yourself. Instead, delegate them\nto specialized subagents to maintain context efficiency and isolate tasks.\n\nExecute your orchestration duties in a continuous loop:\n\n1. **Sub-Agent Orchestration Loop:** For each iteration of the review loop,\n   maintain a loop pass counter `N`.\n\n   - **Initialization \u002F Startup:** Read `N` from `\"pass_number\"` in\n     `workspace\u002F.mantis_state.json`. If missing or invalid, scan\n     `workspace\u002Farchive\u002F` for folders matching `findings_pass_N` or\n     `loopN_findings` and resolve `N` to `max_found + 1` (defaulting to 1 if no\n     archives exist).\n\n     **Boundary Sync & Snapshot Pinning — Pass Lifecycle CONTRACT (STRICT\n     ORDER).** At the start of every pass perform the following four steps in\n     EXACTLY this order. The Pass Lifecycle Contract (`schema.json` → \"Non-JSON\n     Contracts\") requires you to SYNC FIRST and to NEVER record a snapshot id or\n     pin a copy before syncing. Do not reorder these steps and do not skip Step\n     1 ahead of any snapshot write.\n\n     **Sync is OPT-IN.** Perform Step 1 (SYNC) and Step 3 (PIN) ONLY when\n     `--sync` was passed OR the user explicitly instructed a sync for this pass.\n     Otherwise (the default): SKIP Steps 1 and 3 entirely, do NOT write\n     `active_snapshot` or `snapshot_history`, leave `snapshot_pinned` unset, and\n     run the pass against the live tree exactly as today. You still run Step 2\n     (fresh VCS detect) and record `vcs_info` in the default mode.\n\n     **Guard:** Sync (Step 1) must be the very first mutating action of the\n     pass. Never compute or record a `snapshot_id`, never write\n     `active_snapshot`, and never `chmod`\u002Fpin a copy before Step 1 has completed\n     for this pass.\n\n     1. **SYNC (must be the very first action of the pass; `--sync` only).**\n        First, **pre-sync backup hygiene** — remove stale `*.bak-*` files left\n        by an interrupted `@mantis-patch` run, but ONLY when it is safe:\n\n        - GATE A: the workspace edit lock `workspace\u002F.workspace_edit.lock` must\n          be FREE (no patch in flight). If it is held or cannot be acquired\n          non-blocking, SKIP deletion and proceed to sync (Block C STEP 0 hides\n          `*.bak-*` from the dirty check anyway).\n        - GATE B: every finding in `workspace\u002Ffindings\u002F` must have its\n          `patch_status` set (patching finalized). If any finding is mid-patch\n          (no `patch_status`), SKIP deletion.\n        - SCOPE: delete only within the TARGET tree, never under Mantis state.\n          The glob MUST be narrow: `mantis-patch` only ever creates\n          `\u003Ctarget>.bak-[finding_id]` where `finding_id` is a UUIDv4\n          (`schema.json` `#\u002F$defs\u002Fuuid`). The broad `*.bak-*` glob is FORBIDDEN\n          for deletion — it would also match user files like\n          `config.yaml.bak-old` or `data.bak-2024`. Use a UUID-anchored regex\n          instead:\n          `find \u003Ctarget_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 '*\u002F.mantis_snapshots\u002F*' -not -path '*\u002Fworkspace\u002F*' -delete`.\n          For full precision, enumerate `workspace\u002Ffindings\u002F*.json`, read each\n          `id`, and delete only `\u003Canything>.bak-\u003Cthat-id>` files. Never delete\n          `workspace\u002F`, `\u003Cstate_root>\u002F.mantis_snapshots\u002F`, or anything beneath\n          them. Then synchronize the target with upstream at the pass boundary:\n\n        SYNC (very first action of the pass; ONLY if a sync was requested; NEVER\n        mid-pass): STEP 0 - HIDE MANTIS ARTIFACTS from dirtiness:\n        mantis-summary.md, *.bak-*, workspace\u002F, .mantis_snapshots\u002F MUST be\n        invisible to every dirty check. Delete stray `mantis-summary.md` and\n        UUID-shaped `*.bak-\u003Cuuid>` files at the LIVE root first (same narrow\n        glob as the SCOPE rule above — never the broad `*.bak-*` glob for\n        deletion), and pass the per-VCS excludes below. (Else pass-1 summary\n        pollution makes the tree permanently \"dirty\" and sync silently never\n        runs.) STEP 1 - FRESH dirty\u002Fahead pre-check (NEVER rely on last pass's\n        vcs_info): git : dirty if\n        `git status --porcelain         -- ':(exclude)**\u002Fmantis-summary.md'         ':(exclude)**\u002F*.bak-*'         ':(exclude)workspace\u002F'         ':(exclude).mantis_snapshots\u002F'`\n        is non-empty; ahead if `git rev-list --count @{u}..HEAD 2>\u002Fdev\u002Fnull`\n        errors or > 0; detached if `git symbolic-ref -q HEAD` errors. hg : dirty\n        if\n        `hg status -X '**\u002Fmantis-summary.md' -X '*.bak-*' -X 'workspace\u002F**' -X '.mantis_snapshots\u002F**'`\n        non-empty. multi-vcs : dirty if\n        `repo forall -c \"git status         --porcelain         -- ':(exclude)**\u002Fmantis-summary.md'         ':(exclude)**\u002F*.bak-*'         ':(exclude)workspace\u002F'         ':(exclude).mantis_snapshots\u002F'\"`\n        produces ANY output. If dirty OR ahead OR detached OR no-upstream -> DO\n        NOT SYNC; log \"sync skipped: local changes \u002F detached \u002F no upstream\";\n        keep the tree. STEP 2 - SYNC (only if STEP 1 found clean AND on a\n        tracked branch): git : git fetch && git merge --ff-only hg : hg pull &&\n        hg update --check multi-vcs : repo sync -c none \u002F unknown : do NOT sync.\n        STEP 3 - POST-SYNC INTEGRITY (git, if applicable): git submodule update\n        --init --recursive ; if .gitattributes uses filter=lfs, git lfs pull. If\n        either is needed but unavailable\u002Ffails -> force content_hash into\n        SNAPSHOT_ID (do not trust the superproject commit alone). CATCH-ALL: if\n        ANY sync command exits non-zero -> abort sync, keep the current tree,\n        proceed to pin. Re-reviewing the same snapshot is always safe. NEVER\n        run: git reset --hard, git checkout -- ., git clean, hg update -C, or\n        any command that discards uncommitted \u002F untracked \u002F local-commit state.\n\n        Block C runs in the LIVE repository root, is non-destructive, and\n        per-VCS skips sync if the tree is dirty\u002Fahead\u002Fdetached. After sync\n        completes, VERIFY the Mantis state survived: `workspace\u002F` and\n        `workspace\u002F.mantis_state.json` must still exist (Block C never touches\n        `workspace\u002F`). If either is missing after sync, HALT (do not detect, do\n        not pin, do not proceed) and yield to the user.\n\n     2. **FRESH VCS DETECT (only after sync).** Re-detect the VCS AFTER syncing\n        so recorded state reflects the post-sync tree. Run these checks in the\n        LIVE repository root (Block A step 5 VCS-metadata carve-out —\n        history\u002Fdiff\u002FVCS commands run in the live root, never inside a pinned\n        CODE_ROOT):\n\n        1. Check for Git: run `git rev-parse --is-inside-work-tree`. If this\n           command succeeds (returns exit code 0 and output is `true`), a Git\n           repository is active. Set `vcs_type` to `\"git\"` and extract:\n           - `commit_hash` (via `git rev-parse HEAD`)\n           - `branch` (via `git branch --show-current` or\n             `git rev-parse --abbrev-ref HEAD`)\n           - `dirty` status (check if\n             `git status --porcelain -- ':(exclude)**\u002Fmantis-summary.md' ':(exclude)**\u002F*.bak-*' ':(exclude)workspace\u002F' ':(exclude).mantis_snapshots\u002F'`\n             is non-empty — same exclude set as STEP 1, so colocated\n             `workspace\u002F` and `.mantis_snapshots\u002F` do not make the tree falsely\n             dirty)\n        2. Check for Mercurial: check if `.hg` directory exists or run `hg root`\n           (if Mercurial is installed). If found, set `vcs_type` to `\"hg\"` and\n           extract:\n           - `commit_hash` (via `hg id -i`)\n           - `branch` (via `hg branch`)\n           - `dirty` status (check if\n             `hg status -X '**\u002Fmantis-summary.md' -X '*.bak-*' -X 'workspace\u002F**' -X '.mantis_snapshots\u002F**'`\n             is non-empty — same exclude set as STEP 1)\n        3. Check for Multi-VCS systems: check if `.repo` directory exists or\n           look for other multi-VCS markers. If found, resolve the active\n           manifest revision (set `revision`) or branch, and check if any\n           sub-repositories are dirty (set `dirty`). Set `vcs_type` to\n           `\"multi-vcs\"`.\n        4. If you confirm that no VCS is active in the repository (e.g., the\n           directory is a plain folder with no repository files or metadata),\n           set `vcs_type` to `\"none\"`.\n        5. If detection commands fail due to errors, missing tool executables\n           (e.g. `git` not found), or other unhandled exceptions during checks,\n           set `vcs_type` to `\"unknown\"`.\n\n     3. **PIN IMMUTABLE SNAPSHOT (only after sync; `--sync` only).** Materialize\n        an immutable per-pass copy and compute its identity:\n\n        PIN SNAPSHOT (after SYNC, before any stage): 0. CRASH-RESUME (run FIRST,\n        before any copy\u002Fdetect): if `state.active_snapshot.pass == N` on entry,\n        REUSE that dir (no re-copy\u002Fre-pin). This reuse check is SAME-PASS ONLY —\n        it does NOT cover cross-pass staleness (where Stage 15 preserved\n        `active_snapshot` while incrementing `pass_number`). Consumer stages\n        must apply the current-pass check\n        (`active_snapshot.pass == state.pass_number`) described in\n        `mantis-pipeline-adapter` Scenario 2. If `snapshot_pinned` was true but\n        the dir is now missing -> STOP and yield to the user (never re-pin to a\n        possibly-drifted live tree). If reusing, skip steps 1–4 and go straight\n        to step 5 (state write; the `snapshot_history` append inside Step 5 is\n        itself idempotent — see Step 5).\n\n        1. Detect vcs_info (existing meta-agent detection). VCS_ID = commit_hash\n           (git\u002Fhg) \u002F manifest revision (multi-vcs) \u002F \"\" (else).\n        2. FREE-SPACE PRECHECK: if a full copy is needed, compare `du -s` of the\n           live tree to `df` free space at state_root. If it will not fit ->\n           skip copy, go to step 5b (unpinned\u002FHALT). Never crash mid-copy on\n           ENOSPC.\n        3. Choose SNAPSHOT_ROOT and materialize (tiered):\n           - Clean git -> `git worktree add --detach \u003CSNAPSHOT_ROOT>`; clean hg\n             -> `hg archive \u003CSNAPSHOT_ROOT>` (cheap, buildable). GC MUST later\n             run the matching teardown (git worktree remove\u002Fprune).\n           - Else copyable tree -> SNAPSHOT_ROOT =\n             \\\u003Cstate_root>\u002F.mantis_snapshots\u002Fpass\\_\\\u003CN> (MUST NOT contain the\n             path segment \"\u002Fworkspace\u002F\"). Copy EXCLUDING .git .hg .repo .svn CVS\n             nested submodule VCS dirs, workspace\u002F, .mantis_snapshots\u002F,\n             mantis-summary.md, and *.bak-* (same hide-list as STEP 0, so a\n             colocated state_root cannot cause recursive self-copy); dereference\n             symlinks pointing INSIDE the tree; DROP symlinks pointing outside;\n             smudge LFS content if the analysis needs it. If `state_root` itself\n             resolves inside CODE_ROOT, the copy MUST additionally exclude the\n             `state_root` path itself.\n           - Single binary\u002Ffirmware -> copy the artifact into SNAPSHOT_ROOT.\n           - Live endpoint \u002F not a local dir -> go to step 5b.\n        4. FAILURE-TOLERANT VERIFY: check copy exit status + a cheap sanity\n           check (file count \u002F size within ~90% of source minus excludes). If a\n           failed\u002Fmissing file IS referenced by any archived\u002Fplanned code_paths\n           -> retry the copy once; if it still fails -> step 5b. If only\n           unreferenced files failed -> pin and log skipped paths. 5a. PINNED:\n           compute content_hash (whole copy), assemble SNAPSHOT_ID per the\n           ladder, snapshot_pinned=true, write SNAPSHOT_ID to\n           SNAPSHOT_ROOT\u002F.mantis_snapshot_id, best-effort chmod -R a-w\n           SNAPSHOT_ROOT. 5b. UNPINNED (HALT mode): SNAPSHOT_ROOT=\u003Clive root>,\n           snapshot_pinned=false, SNAPSHOT_ID=\"live:\"+ISO8601. Authoritative\n           verdicts are forbidden this pass.\n        5. Write state.active_snapshot = {root, snapshot_id, snapshot_pinned,\n           pass:N, vcs_type}. APPEND {pass:N, snapshot_id, snapshot_pinned,\n           timestamp} to state.snapshot_history ONLY IF no entry with\n           `pass == N` already exists (idempotency check: scan\n           `snapshot_history` for `pass == N`; this mirrors the once-only\n           pattern used for `signature` and `discovery_commit`). On crash-resume\n           reuse (Step 0 routed here), an entry for pass N may already have been\n           written by the prior run — in that case, write `active_snapshot` only\n           and do NOT append a second `snapshot_history` entry for the same\n           pass. NEVER overwrite prior entries. There must be exactly one\n           `snapshot_history` entry per pass.\n        6. RETENTION\u002FGC: keep the last N snapshot dirs (operator-configurable\n           via `--snapshot_keep`, DEFAULT 2 = this pass + previous); delete\n           older via the matching teardown (rm -rf for copies; git worktree\n           remove\u002Fprune for worktrees). Correctness never reads an old snapshot,\n           so the default of 2 is safe; raise N when you want patch\u002FPoC rebasing\n           to apply against a finding's discovery snapshot.\n        7. CRASH-RESUME (Post-Check): if Step 0 did not trigger, and Block D\n           returns `snapshot_pinned=false` (HALT mode), still write\n           `active_snapshot` in Step 4 and still pass `--snapshot_root`\u002F\n           `--snapshot_id` to stages so they see the HALT signal and degrade\n           conservatively (no authoritative verdicts).\n\n        Block D performs the free-space precheck; chooses the clean-VCS fast\n        path (git worktree \u002F hg archive) or full copy \u002F single-artifact copy \u002F\n        live- endpoint fallback per the snapshot_id ladder; computes\n        `content_hash` (sha256 over EVERY file in the pinned copy — never a\n        partial hash); assembles `SNAPSHOT_ID`; writes the\n        `CODE_ROOT\u002F.mantis_snapshot_id` sentinel; `chmod -R a-w` the copy; runs\n        keep-N GC (`--snapshot_keep`, default 2) with matching teardown; and\n        handles crash-resume (reuse-or-STOP, step 0). Block D is fail-closed: if\n        it cannot pin because the target is too big to copy or is not a local\n        dir, it either falls back to a `live:`-prefixed id with\n        `snapshot_pinned=false` (live-endpoint gate) or HALTs the pass — in\n        neither case may you proceed as if a pinned snapshot exists. If Block D\n        returns `snapshot_pinned=false` (HALT), still write `active_snapshot` in\n        Step 4 and still pass `--snapshot_root`\u002F `--snapshot_id` to stages so\n        they see the HALT signal and degrade conservatively (no authoritative\n        verdicts).\n\n     4. **RECORD (only after Steps 1–3).** Update `workspace\u002F.mantis_state.json`\n        (conforming to `schema.json` `#\u002F$defs\u002Fstate`):\n\n        - Write `\"vcs_info\"` from Step 2 (always, both modes).\n        - If `--sync` was requested this pass: write `\"active_snapshot\"` =\n          `{ \"root\": \u003Croot>, \"snapshot_id\": \u003CSNAPSHOT_ID>, \"snapshot_pinned\": \u003Ctrue if pinned, false if HALT>, \"pass\": \u003CN>, \"vcs_type\": \u003Cvcs_type> }`.\n          Use the values Block D step 5 already wrote; do NOT re-derive them.\n          `snapshot_pinned` reflects reality: `true` when Step 3 pinned an\n          immutable copy (5a), `false` in HALT (5b: live endpoint,\n          too-big-to-copy, copy-failed, or dirty\u002Fracing tree). **Do NOT\n          re-append to `\"snapshot_history\"`** — Block D step 5 already appended\n          exactly one entry for this pass\n          (`{ \"pass\": \u003CN>, \"snapshot_id\": \u003CSNAPSHOT_ID>, \"snapshot_pinned\": \u003Cbool>, \"timestamp\": \u003CISO 8601> }`).\n          Re-appending would create a duplicate; there must be exactly one\n          `snapshot_history` entry per pass. (If you are in a code path where\n          Block D step 5 did NOT run — e.g. crash-resume reuse of an\n          already-pinned snapshot — append here ONLY IF no entry for pass N\n          already exists in `snapshot_history` (idempotency check: scan for\n          `pass == N`); otherwise write `active_snapshot` only.) Match\n          `schema.json` `#\u002F$defs\u002Fstate` EXACTLY: the per-entry key is `pass`\n          (NOT `pass_number`); the separate top-level `state.pass_number` loop\n          counter is written in State Maintenance below.\n        - In MODE-OFF (no `--sync` requested): do NOT write `active_snapshot` or\n          `snapshot_history` (leave them absent → downstream stages run exactly\n          as today per the global backward-compat rule). Because Stage 15\n          sub-step 7 PRESERVES `active_snapshot` across pass boundaries, a prior\n          `--sync` pass leaves a stale `active_snapshot` (with `pass == N-1`)\n          behind. To actually achieve MODE-OFF semantics, you MUST actively\n          DELETE any pre-existing `active_snapshot` key from\n          `workspace\u002F.mantis_state.json` when running a pass without `--sync`\n          (in-place key delete, NOT a fresh-object overwrite — preserve\n          `vcs_info`, `snapshot_history`, `pass_number`, etc.). This is a\n          DELETE-when-entering-MODE-OFF, not a \"do not overwrite\": leaving the\n          stale key would trip the cross-pass staleness gate\n          (`active_snapshot.pass != state.pass_number`) in consumer stages\n          (`mantis-calibrate`, `mantis-chain`, `mantis-architecture`) and\n          contradict the schema's MODE-OFF = `active_snapshot` ABSENT rule.\n          `snapshot_history` is an append-only log — NEVER delete or truncate\n          it; it remains as historical provenance. Writing `active_snapshot`\n          with `snapshot_pinned=false` is NOT the same as omitting it: an absent\n          `active_snapshot` means MODE-OFF, while a present one with\n          `snapshot_pinned=false` means HALT (conservative, no authoritative\n          verdicts). Never erase a HALT signal by omitting `active_snapshot`\n          when `--sync` was requested. Never write `active_snapshot` or set\n          `snapshot_pinned=true` before Steps 1–3 have completed for this pass.\n\n   - **State Maintenance:** Write the current pass `N` to `\"pass_number\"` and\n     the current ISO 8601 timestamp to `\"last_updated\"` in\n     `workspace\u002F.mantis_state.json` (`\"vcs_info\"`, and — when pinned —\n     `\"active_snapshot\"`\u002F`\"snapshot_history\"`, were written in Startup Steps 2\n     and 4). Then delegate the workload sequentially to the specialized\n     subagents. Call each subagent as a tool (or using the `@agent_name` syntax\n     if instructed by your prompt) with a concise instruction to perform its\n     designated task:\n\n     **Snapshot argument passing (ALL stages, Stage 0–15).** When `--sync` was\n     requested this pass (whether PINNED or HALT — i.e. `active_snapshot` is\n     present in state), APPEND these three arguments to the instruction string\n     of EVERY `@stage` delegation below, using the values from\n     `active_snapshot`:\n     `--snapshot_root=\u003Cactive_snapshot.root> --snapshot_id=\u003Cactive_snapshot.snapshot_id> --state_root=\u003Cabsolute path of the directory that contains workspace\u002F>`.\n     Pass them to every stage uniformly and do NOT special-case the\n     findings-only stages (report, calibrate, reflect): they ignore the code\n     root via their own Block A ROLE gate. In HALT mode\n     (`active_snapshot.snapshot_pinned == false`), the stages still receive the\n     roots and read `active_snapshot` from state — they use it to degrade\n     conservatively (no authoritative verdicts). When NO `--sync` was requested\n     (MODE-OFF), pass only `--state_root=\u003C...>` (plus `--target_root=\u003C...>` if\n     you were already passing one, exactly as today); do NOT invent a\n     `--snapshot_id`. Do not edit the individual Stage 0–15 bullets — this\n     single directive governs all of them.\n\n     **Pin enablement.** Block A (Locator Resolution) is universal across all\n     code-reading stages. When `--sync` is requested, PIN in Step 3 and pass\n     `--snapshot_root`\u002F`--snapshot_id` normally — do not artificially force\n     `snapshot_pinned=false`. (The `live:`-id HALT fallback in Block D step 5b\n     handles targets that genuinely cannot be pinned.)\n\n   - **Stage 0 (Optional Pre-processing History):** Call the `@mantis-history`\n     subagent to analyze repository's version control system (VCS) history and\n     extract past vulnerabilities and security fixes into a\n     `workspace\u002Fhistorical_learnings.jsonl` file.\n\n   - **Stage 0.5 (Optional Structural Index):** Call the\n     `@mantis-structural-index` subagent to build the structural index — a\n     content-addressed semantic-unit index published as\n     `workspace\u002Fkb\u002Fstructural_index\u002Fmanifest.json` + `catalog.sqlite` (with\n     `structural_index.jsonl` as a compatibility pointer) and exposed via\n     `workspace\u002Fhelpers\u002Fquery_structural_index.py`. It runs immediately after\n     the snapshot is pinned (Block D), before the first code-reading analysis\n     stage, using only CODE_ROOT + SNAPSHOT_ID. In MODE-OFF, it builds against\n     the current directory with `snapshot_id` set to `\"unknown\"` and rebuilds\n     each pass (the live tree is mutable, so a reused index could lag current\n     code). The index is a HINT-only enhancement — it never gates findings and\n     degrades gracefully to an empty index (grep fallback) when unavailable or\n     not invoked. A non-conformant harness simply skips this stage.\n\n   - **Stage 1 (Optional Directory Mapping):** If not already mapped, call the\n     `@mantis-summarize` subagent to generate `mantis-summary.md` files for each\n     directory to optimize downstream planning and summaries with historical\n     context.\n\n   - **Stage 2 (KB Architecture):** Call the `@mantis-architecture` subagent to\n     synthesize the codebase structure and pending `workspace\u002Flearnings.jsonl`\n     into the permanent Markdown Knowledge Base (`workspace\u002Fkb\u002F`).\n\n   - **Stage 3 (Threat Modeling):** Call the `@mantis-threat-model` subagent to\n     read the KB and evaluate\u002Fupdate `workspace\u002Fkb\u002FTHREAT_MODEL.md`.\n\n   - **Stage 4 (Planning):** Call the `@mantis-plan` subagent to evaluate\n     boundaries, read the KB index, and generate `workspace\u002Fplan.json` with\n     injected context pointers.\n\n   - **Stage 5 (Research):** Call the `@mantis-researcher` subagent to perform\n     the deep code sweep using the context in `workspace\u002Fplan.json` and populate\n     the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 6 (Deduplication):** Call the `@mantis-dedupe` subagent to\n     deduplicate files in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 7 (Review):** Call the `@mantis-review` subagent to evaluate\n     findings in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 8 (Critic):** Call the `@mantis-critic` subagent to check\n     production viability of files in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 9 (Reproduce):** Call the `@mantis-reproduce` subagent to develop\n     crash reproducers and update files in the `workspace\u002Ffindings\u002F` directory.\n\n   - **Stage 10 (Chain):** Call the `@mantis-chain` subagent to analyze the\n     current validated findings and the Knowledge Base to construct multi-step\n     exploit chains, outputting \"Super Findings\" into the `workspace\u002Ffindings\u002F`\n     directory.\n\n   - **Stage 11 (Patch & Verify):** Call the `@mantis-patch` subagent to\n     generate fixes, and update files in the `workspace\u002Ffindings\u002F` directory.\n     Instruct it to repeatedly call a fresh `@mantis-reproduce` subagent against\n     its patches to attempt a bypass, refining the fix until the reproducer can\n     no longer bypass it.\n\n   - **Stage 12 (Calibrate):** Call the `@mantis-calibrate` subagent to read the\n     `workspace\u002Ffindings\u002F` directory and append final calibration metrics to\n     each finding file.\n\n   - **Stage 13 (Reflect):** Call the `@mantis-reflect` subagent to parse the\n     execution trajectories of the round and append false assumptions or tool\n     failures to the `workspace\u002Flearnings.jsonl` inbox. **Important:** You must\n     pass the absolute file paths to the execution log files (e.g.\n     `transcript.jsonl` files) of all subagents successfully executed during\n     this round (every stage that ran: history, structural-index, summarize,\n     architecture, threat-model, plan, researcher, dedupe, review, critic,\n     reproduce, chain, patch, calibrate) to the `@mantis-reflect` subagent.\n     Resolve these paths from whatever mechanism the ACTIVE coding-agent harness\n     exposes for per-subagent execution logs; do NOT hardcode any single\n     framework's layout. Harnesses differ — e.g. Antigravity stores them under\n     `\u003CappDataDir>\u002Fbrain\u002F\u003Cconversation_id>\u002F.system_generated\u002Flogs\u002Ftranscript.jsonl`,\n     while Gemini CLI, the Google ADK, Claude Code, and custom pipelines use\n     different locations; Antigravity is ONE example, not the default. If your\n     harness exposes no such logs, pass an EXPLICIT EMPTY list to\n     `@mantis-reflect` and instruct it to record a missing-transcript insight\n     per stage rather than silently emitting zero learnings.\n\n   - **Stage 14 (Report):** Call the `@mantis-report` subagent to generate the\n     human-readable review packet (`workspace\u002Freport\u002Freview_packet-latest.md`\n     and the per-pass archive `workspace\u002Freport\u002Freview_packet_pass_\u003CN>.md` —\n     which, when a snapshot is pinned, carries a snapshot suffix\n     `review_packet_pass_\u003CN>_\u003Csnapshot_id>.md` so a re-used pass number on a\n     different snapshot cannot overwrite a prior packet.\n     `review_packet-latest.md` remains the stable entry point) containing only\n     reproduced findings, evidence, and patches.\n\n   - **Stage 15 (Archive & KB Verification):**\n\n     1. **Call the `@mantis-architecture` subagent** to perform a final\n        synthesis of the current round's findings (especially\n        `\"FALSE_POSITIVE\"`, `\"NON_VIABLE\"`, `\"SAMPLE_OR_TEST\"`, and\n        `\"VERIFIED_SECURE\"`) into the permanent Markdown Knowledge Base\n        (`workspace\u002Fkb\u002F`).\n     2. Verify that the KB updates were successfully written and that\n        `workspace\u002Flearnings.jsonl` was processed.\n     3. **Archive and Increment Pass:**\n        1. Read the current pass number `N` from the state file\n           `workspace\u002F.mantis_state.json`.\n        2. Ensure the archive directory exists:\n           `workspace\u002Farchive\u002Ffindings_pass_N\u002F`.\n        3. **Snapshot the pass boundary (ALWAYS, even if `findings\u002F` is\n           empty).** COPY (never move) the following into\n           `workspace\u002Farchive\u002Ffindings_pass_N\u002F` so the next pass has an\n           immutable reference point:\n           - `workspace\u002F.mantis_state.json` →\n             `workspace\u002Farchive\u002Ffindings_pass_N\u002F.mantis_state.json` (preserves\n             this pass's `pass_number`, `vcs_info`, `active_snapshot`, and\n             `snapshot_history`, giving `@mantis-plan` a PREV reference for\n             Block E's changed-files diff).\n           - the entire `workspace\u002Fkb\u002F` directory (including\n             `workspace\u002Fkb\u002FTHREAT_MODEL.md`) →\n             `workspace\u002Farchive\u002Ffindings_pass_N\u002Fkb\u002F`. Use copy, not move: the\n             live `workspace\u002Fkb\u002F` and `workspace\u002F.mantis_state.json` MUST\n             survive into the next pass.\n        4. If `workspace\u002Ffindings\u002F` exists and contains findings, MOVE all\n           `.json` files and the `.trash\u002F` directory (if it exists) into\n           `workspace\u002Farchive\u002Ffindings_pass_N\u002F` (e.g.,\n           `mv workspace\u002Ffindings\u002F*.json workspace\u002Farchive\u002Ffindings_pass_N\u002F`).\n        5. If the findings directory is empty or does not exist, ensure it\n           exists and skip the finding move (the state\u002FKB copy in sub-step 3\n           still ran).\n        6. Increment `N` by 1 to get the new pass number `N_new = N + 1`.\n        7. Write `N_new` to `\"pass_number\"` and the current ISO 8601 timestamp\n           to `\"last_updated\"` in `workspace\u002F.mantis_state.json`. **PRESERVE, do\n           not delete,** the existing `\"vcs_info\"`, `\"active_snapshot\"`, and\n           `\"snapshot_history\"` keys when you rewrite the file — perform an\n           in-place key update, NOT a fresh-object overwrite. Dropping these\n           keys would strand `@mantis-plan` with no PREV reference.\n\n2. **Intelligent Supervision & Error Handling:**\n\n   - Wait for each subagent to finish its execution and report back.\n   - After a subagent returns control to you, optionally use your file reading\n     tools to quickly inspect the resulting JSON files (e.g., in\n     `workspace\u002Ffindings\u002F`) to verify the state. To avoid token bloat, do not\n     read all files if there are many; inspect only a small sample or rely on\n     the subagents to manage the state correctly.\n   - If a subagent reports a critical failure or crashes its isolated loop,\n     diagnose the issue, explain the environment fix, and retry delegating to\n     that subagent.\n\n3. **Monitoring & Reporting:** When the pipeline successfully reproduces a\n   security flaw or verifies a patch (reported by the `@mantis-patch` subagent),\n   or when `@mantis-calibrate` finishes its scoring, you may output a brief text\n   summary to the user.\n\n   - **Do NOT report findings that failed to reproduce\n     (`repro_status: \"failed_to_reproduce\"`) as confirmed vulnerabilities.**\n   - **Do NOT report findings that are marked `LOW` priority or are `NON_VIABLE`\n     as confirmed vulnerabilities.** These are considered low-quality, fragile,\n     or non-actionable. You may list them separately at the bottom of your\n     summary under a \"Hygiene & Low Priority Notes\" section, but do not present\n     them as active security flaws.\n\n4. **Human-in-the-Loop Steering & Collaboration:** While you are designed for\n   autonomy, remain responsive to user input. The user may interrupt the loop to\n   ask for progress updates, collaboratively debug environmental issues, or\n   provide high-level strategic guidance (e.g., \"Focus exclusively on the\n   networking stack in the next pass\").\n\n   - Adapt the instructions you give to your subagents based on recent user\n     feedback.\n   - You can use your subagent delegation tools to perform \"Deep Dives\" on\n     specific findings if the user requests more detail without interrupting the\n     main loop logic.\n   - **Target-change & sync requests apply only at a pass boundary.** If the\n     user asks to change the target (re-point `--target_root` \u002F a different\n     codebase) or to `--sync` now, do NOT apply it mid-pass. Defer it to the\n     START of the next pass and only when `workspace\u002Ffindings\u002F` is EMPTY (all\n     findings archived by Stage 15). Applying a target or sync change while\n     findings are in flight would strand those findings against a code root that\n     no longer matches their `discovery_commit`, producing silent wrong results.\n     If `findings\u002F` is non-empty, tell the user you will apply the change at the\n     next boundary and let the current pass finish; if they insist on aborting,\n     run Stage 15 to archive the current findings first, then apply the change\n     at the fresh boundary.\n\n5. **Resilience & Persistence:** When Stage 15 (Archive & KB Verification)\n   completes, immediately begin the next pass. Chain your tool calls\n   automatically. However, if you encounter a permanent, non-recoverable error\n   (e.g., a persistent environment failure or fundamentally broken pipeline\n   state), halt the loop and yield to the user. Try your best to recover from\n   and fix transient issues (like rate limits or temporary file locks) before\n   deciding to halt.\n",{"name":5,"description":7},"main","f3162c039ecd9c9d5d8bc404dd1373c7ca3152f7","skills\u002Fmantis-meta-agent",237,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis","https:\u002F\u002Fcloud.google.com\u002F","https:\u002F\u002Fgithub.com\u002Fgoogle","https:\u002F\u002Fopensource.google\u002F","Google ❤️ Open Source","2026-11-15 00:33:31",{"source":8,"skillName":5,"commands":57,"prompt":67,"zipAvailable":68},[58,61,64],{"tool":59,"command":60},"npx","npx skills add google\u002Fmantis --skill mantis-meta-agent",{"tool":62,"command":63},"bunx","bunx skills add google\u002Fmantis --skill mantis-meta-agent",{"tool":65,"command":66},"pnpm","pnpm dlx skills add google\u002Fmantis --skill mantis-meta-agent","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-meta-agent\u002FSKILL.md",true,[],[71,97,120,147,158,173],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":41},"01M6992XJHHV0R5N8E392EHRW3","mantis-threat-model","Synthesizes trust boundaries, attack surfaces, and attacker profiles into a living threat model. Use as Stage B of the Knowledge Base generation process, reading architecture and entity definitions from the KB. Don't use for analyzing source code or extracting raw learnings from JSONL files.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-threat-model\u002FSKILL.md",[],[78,79,80,81,82,83,84,85,86,87,88,89,90,91,32,92,93,94,95,96],"mantis threat model","threat model","model","threat","architecture","code","analyzing","knowledge","kb","files","surfaces","trust","learnings","knowledge base","extracting","reading","jsonl","source","source code",{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":106,"publishedAt":41},"01M6992TR1BPA5HVF13QRM7EP0","mantis-summarize","Pre-processes the repository by generating security-focused summaries (mantis-summary.md) for each directory to make planning and research more efficient. Use when starting a review campaign to map the codebase before threat modeling and planning. Don't use for executing code reviews, writing test scripts, or patching code.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-summarize\u002FSKILL.md",[103],{"categoryNo":104,"categoryName":105,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000021","资料检索与研究",[107,108,109,110,35,40,111,83,112,113,114,81,33,115,116,117,118,119,30,29],"summarize","mantis summarize","writing","directory","threat modeling","planning","repository","patching","map","modeling","scripts","make","reviews",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":131,"publishedAt":41},"01M6992QB4DVMDR2AGT6BPSE3N","mantis-structural-index","Builds a content-addressed semantic-unit index from source code for structural context. Use when a pinned or live codebase is available and structural cross-reference data would improve research quality. Don't use for findings analysis, patching, or reporting.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-structural-index\u002FSKILL.md",[126],{"categoryNo":127,"categoryName":128,"taxonomyType":129,"taxonomyTypeDesc":130},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[132,133,134,135,83,136,137,138,139,114,140,141,142,34,143,144,145,146,30,29],"mantis structural index","index","structural","research","content","reporting","data","analysis","improve","quality","context","research quality","reference","live","unit",{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":153,"publishedAt":41},"01M6992KRP2XYWEMV12P5M4GPE","mantis-review","Independently reviews findings and filters out false positives. Use when consolidated findings need validation against the actual source code. Don't use for reproducing crashes or patching code.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-review\u002FSKILL.md",[],[35,154,83,155,114,34,156,157,119,30,95,96,29],"mantis review","validation","filters","false",{"skillNo":159,"name":160,"nameZh":6,"description":161,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":162,"categories":163,"keywords":164,"publishedAt":41},"01M6992GKVGJ2NXEJWYFVCN01Q","mantis-researcher","Audits production source code files based on the strategy in workspace\u002Fplan.json. Use when a review plan exists and you need to perform static analysis and deep-dive reviews of targeted files. Don't use for planning, deduplicating, or writing patches.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-researcher\u002FSKILL.md",[],[165,166,109,35,167,83,112,139,168,169,34,87,170,171,119,30,95,172,96,29],"mantis researcher","researcher","static analysis","plan","strategy","deep","you","static",{"skillNo":174,"name":175,"nameZh":6,"description":176,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":177,"categories":178,"keywords":179,"publishedAt":41},"01M6992D5WXENF3TW68GM5WPHC","mantis-reproduce","Generates and runs crash reproducers to verify security flaws. Use when viable findings exist and you need to write and execute a script or payload to verify the crash. Don't use for code auditing or patching.","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fmantis\u002Fblob\u002Fmain\u002Fskills\u002Fmantis-reproduce\u002FSKILL.md",[],[180,181,40,83,114,182,183,184,34,185,186,187,171,30,29],"mantis reproduce","reproduce","verify","write","execute","crash","payload","script"]