|
1 | 1 | # Mantis Skills: Reference Guide for AI Agents |
2 | 2 |
|
| 3 | +> [!CAUTION] **USE AT YOUR OWN RISK. BE EXTREMELY CAREFUL.** This suite is |
| 4 | +> designed to generate and execute autonomously generated code that may be |
| 5 | +> unstable or perform unexpected actions. **USE THIS ONLY IN ISOLATED, |
| 6 | +> RESTRICTED ENVIRONMENTS.** Never run this suite on a machine with access to |
| 7 | +> production systems, sensitive data, or internal networks. See the "Advanced / |
| 8 | +> Unattended Cloud Deployment (GCE)" section for mandatory hardening |
| 9 | +> requirements. |
| 10 | +
|
| 11 | +> [!IMPORTANT] **RESPONSIBLE USE** AI models are non-deterministic and can |
| 12 | +> hallucinate findings or generate incorrect patches. **All findings must be |
| 13 | +> manually verified by a security expert before being reported.** Do not |
| 14 | +> mass-file unverified, AI-generated reports to open-source maintainers. A |
| 15 | +> failure to automatically reproduce a vulnerability does not definitively mean |
| 16 | +> it is a false positive, nor does a successful reproducer guarantee the bug is |
| 17 | +> exploitable in all contexts. Use these skills responsibly. |
| 18 | +
|
3 | 19 | This document is the canonical reference guide for AI Agents operating in this |
4 | 20 | workspace. It describes the Mantis pipeline architecture, the individual skills |
5 | 21 | (stages), the inter-stage data contracts, and the design patterns required to |
6 | 22 | run and extend the pipeline. |
7 | 23 |
|
| 24 | +For more information on securing AI systems, see Google's |
| 25 | +[Secure AI Framework (SAIF)](https://safety.google/safety/saif/). |
| 26 | + |
8 | 27 | As an agent, you must adhere to the contracts, file paths, and execution |
9 | 28 | patterns defined in this document. |
10 | 29 |
|
11 | 30 | ______________________________________________________________________ |
12 | 31 |
|
| 32 | +## Prerequisites and Setup |
| 33 | + |
| 34 | +Before executing any skills, ensure your local CLI environment is fully |
| 35 | +configured. Mantis is platform agnostic and works with Gemini CLI, Antigravity |
| 36 | +CLI, Google ADK, and other coding agent frameworks. Consider: |
| 37 | + |
| 38 | +1. **Docker**: For running testing containers. |
| 39 | + |
| 40 | +2. **gVisor (runsc)**: For enhanced security when executing untrusted |
| 41 | + AI-generated crash reproducer code, register the `runsc` runtime with |
| 42 | + networkless execution |
| 43 | + (`sudo runsc install -- --network=none && sudo systemctl restart docker`) or |
| 44 | + configure `/etc/docker/daemon.json`: |
| 45 | + |
| 46 | + ```json |
| 47 | + { |
| 48 | + "runtimes": { |
| 49 | + "runsc": { |
| 50 | + "path": "runsc", |
| 51 | + "runtimeArgs": [ |
| 52 | + "--network=none" |
| 53 | + ] |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + ``` |
| 58 | + |
| 59 | +3. **Cloud SDKs**: If running remote cloud sandboxes (e.g. Google Compute |
| 60 | + Engine) instead of local containers. |
| 61 | + |
| 62 | +To install the skills via CLI: |
| 63 | + |
| 64 | +```shell |
| 65 | +npx skills add google/mantis |
| 66 | +``` |
| 67 | + |
| 68 | +______________________________________________________________________ |
| 69 | + |
13 | 70 | ## Adaptability & Specialized Domains |
14 | 71 |
|
15 | 72 | While the default skills look for generic security issues, business logic |
@@ -227,6 +284,80 @@ when unavailable. Consumers query via |
227 | 284 | and patch information at `workspace/report/review_packet-latest.md` (and |
228 | 285 | archives to `review_packet_pass_<N>.md`). |
229 | 286 |
|
| 287 | +### Auxiliary & Operational Skills |
| 288 | + |
| 289 | +- **`/mantis-configure` (Configuration & Preflight Wizard):** |
| 290 | + ([`reference/skills/mantis-configure/SKILL.md`](reference/skills/mantis-configure/SKILL.md)) |
| 291 | + Manages sandbox selection (`static-only`, `microsandbox`, `gvisor`, `gce`), |
| 292 | + LLM provider options, and fast preflight testing. |
| 293 | +- **`/mantis-launch` (Automated Launch & Healing Supervisor):** |
| 294 | + ([`reference/skills/mantis-launch/SKILL.md`](reference/skills/mantis-launch/SKILL.md)) |
| 295 | + Validates the environment, performs preflight checks, and executes the |
| 296 | + pipeline with automatic sandbox downgrade fallback. |
| 297 | +- **`/mantis-advise` (Developer Security Advisor):** |
| 298 | + ([`mantis-advise/SKILL.md`](mantis-advise/SKILL.md)) Queries threat models, |
| 299 | + historical vulnerability lineages, verified patch diffs, triaged false |
| 300 | + positives, and learned trajectory invariants from `knowledge.db` before and |
| 301 | + during code edits. |
| 302 | + |
| 303 | +### Running the Pipeline (Manual Mode) |
| 304 | + |
| 305 | +You can execute the reviewing stages sequentially from inside your active CLI |
| 306 | +terminal: |
| 307 | + |
| 308 | +```text |
| 309 | +# 0. (Optional) Configure environment models and sandboxes |
| 310 | +/mantis-configure |
| 311 | +
|
| 312 | +# 0a. (Optional) Analyze repository's version control system (VCS) history |
| 313 | +/mantis-history |
| 314 | +
|
| 315 | +# 0b. (Optional) Build content-addressed semantic-unit index |
| 316 | +/mantis-structural-index |
| 317 | +
|
| 318 | +# 1. (Optional) Generate mantis-summary.md directory maps |
| 319 | +/mantis-summarize |
| 320 | +
|
| 321 | +# 2. Synthesize codebase structure and historical learnings into Markdown KB |
| 322 | +/mantis-architecture |
| 323 | +
|
| 324 | +# 3. Iteratively develop living threat model based on the KB |
| 325 | +/mantis-threat-model |
| 326 | +
|
| 327 | +# 4. Map target external boundary and build scanning roadmap |
| 328 | +/mantis-plan |
| 329 | +
|
| 330 | +# 5. Run multi-threaded/sequential security flaw sweep |
| 331 | +/mantis-researcher |
| 332 | +
|
| 333 | +# 6. Consolidate overlapping files and duplicate bugs |
| 334 | +/mantis-dedupe |
| 335 | +
|
| 336 | +# 7. Verify code validity & filter false positives |
| 337 | +/mantis-review |
| 338 | +
|
| 339 | +# 8. Eliminate non-viable production issues |
| 340 | +/mantis-critic |
| 341 | +
|
| 342 | +# 9. Generate proof-of-concept crash reproducers and run in sandboxes |
| 343 | +/mantis-reproduce |
| 344 | +
|
| 345 | +# 10. Combine validated findings into multi-step exploit chains |
| 346 | +/mantis-chain |
| 347 | +
|
| 348 | +# 11. Apply minimal fixes and verify they block the crash reproducer |
| 349 | +/mantis-patch |
| 350 | +
|
| 351 | +# 12. Calculate final matrix risk ratings and append to findings |
| 352 | +/mantis-calibrate |
| 353 | +
|
| 354 | +# 13. Extract insights from execution trajectories to learnings inbox |
| 355 | +/mantis-reflect |
| 356 | +
|
| 357 | +# 14. Generate human-readable security review packet report |
| 358 | +/mantis-report |
| 359 | +``` |
| 360 | + |
230 | 361 | ______________________________________________________________________ |
231 | 362 |
|
232 | 363 | ## The Snapshot Model |
@@ -426,6 +557,92 @@ for the adapter reference pointer. |
426 | 557 | > native tool calls or functions for state management to avoid forcing the LLM |
427 | 558 | > to write one-off scripts. |
428 | 559 |
|
| 560 | +### The ADK Reference Implementation (`reference/`) |
| 561 | + |
| 562 | +This repository includes a production-grade reference harness located in |
| 563 | +[`reference/`](reference/), built directly on top of the **Google Agent |
| 564 | +Development Kit (ADK)**. It serves as an authoritative implementation of the |
| 565 | +Mantis architecture: |
| 566 | + |
| 567 | +1. **Declarative Workflow Graph (`workflow.json` / `core/graph_loader.py`)**: |
| 568 | + |
| 569 | + - Compiles 16 sequential agent nodes into native ADK `Workflow`, `Agent`, and |
| 570 | + `Classifier` constructs. |
| 571 | + - Attaches Mantis skill directories as native `SkillToolset` instances. |
| 572 | + - Provides full runtime fallback for system prompts via |
| 573 | + `prompts/system-*.md`. |
| 574 | + |
| 575 | +2. **Layered Configuration Overlay (`workflow.local.json`)**: |
| 576 | + |
| 577 | + - **`workflow.json` (Tracked)**: Contains template configurations and clean |
| 578 | + placeholder values (`YOUR_PROJECT_ID`). |
| 579 | + - **`workflow.local.json` (Gitignored)**: Automatically generated overlay for |
| 580 | + local developer machines, containing resolved GCP projects, active |
| 581 | + sandboxes, and model overrides. |
| 582 | + - Auto-configuration (`scripts/configure.py --auto`) and launch tools |
| 583 | + (`scripts/launch.py` / `./run.sh`) write strictly to `workflow.local.json` |
| 584 | + to keep developer git trees clean. |
| 585 | + |
| 586 | +3. **Pluggable Sandboxed Environments (`core/sandboxes/`)**: |
| 587 | + |
| 588 | + - **`StaticOnlyEnvironment` (`"static-only"`)**: Safe static analysis only; |
| 589 | + dynamic crash reproduction and patch verification are skipped. |
| 590 | + - **`GvisorEnvironment` (`"gvisor"`)**: OCI container isolation via |
| 591 | + Docker/Podman and gVisor `runsc` with `--network=none`. |
| 592 | + - **`MicrosandboxEnvironment` (`"microsandbox"`)**: In-process hardware |
| 593 | + microVM isolation via `libkrun` and `Network.none()`. |
| 594 | + - **`GceEnvironment` (`"gce"`)**: Hardened ephemeral Google Compute Engine VM |
| 595 | + isolation in a private non-internet VPC with DNS blackholing, IAP |
| 596 | + tunneling, and IAM token suppression. |
| 597 | + |
| 598 | +4. **3-Tier Deduplication & Lineage Ladder (`core/embeddings.py` / |
| 599 | + `core/database.py`)**: |
| 600 | + |
| 601 | + - **Tier 1 (Exact Heuristic Anchors)**: \<1ms stable signature and AST |
| 602 | + line-shift matching. |
| 603 | + - **Tier 2 (RCA Normalization)**: Lightweight LLM extraction of standardized |
| 604 | + root cause summaries. |
| 605 | + - **Tier 3 (Semantic Vector Embeddings)**: Nearest-neighbor cosine similarity |
| 606 | + matching via `vertex_ai/gemini-embedding-001` (or configurable model) with |
| 607 | + calibrated threshold $\\ge 0.90$ and a structural CWE compatibility guard |
| 608 | + to prevent cross-vulnerability false merges. |
| 609 | + - **Observability**: Explicit warnings on live embedding fallback |
| 610 | + (`⚠️ [EMBEDDING FALLBACK]`) and vector dimension mismatch |
| 611 | + (`⚠️ [EMBEDDING MISMATCH]`). |
| 612 | + |
| 613 | +5. **Operational CLI Tools & Developer Skills**: |
| 614 | + |
| 615 | + - **`scripts/configure.py` (`mantis-configure`)**: Interactive wizard, |
| 616 | + auto-detection, and ~1s preflight validation (see |
| 617 | + [`reference/skills/mantis-configure/SKILL.md`](reference/skills/mantis-configure/SKILL.md)). |
| 618 | + - **`scripts/launch.py` (`./run.sh` / `mantis-launch`)**: Autonomous runner |
| 619 | + with preflight sanity checks and graceful sandbox downgrade handling (see |
| 620 | + [`reference/skills/mantis-launch/SKILL.md`](reference/skills/mantis-launch/SKILL.md)). |
| 621 | + - **`scripts/advise.py` (`mantis-advise`)**: Developer security advisor |
| 622 | + querying threat models, historical lineages, and verified patch diffs. |
| 623 | + - **`scripts/generate_schemas.py`**: Compiles `schema.json` into Pydantic |
| 624 | + models in `core/schemas.py`. |
| 625 | + |
| 626 | +6. **Open Knowledge Format (OKF v0.2) Semantics (`core/database.py` / |
| 627 | + `scripts/advise.py`)**: |
| 628 | + |
| 629 | + - **`okf_concepts` Storage**: SQLite schema version 3 stores scoped concepts, |
| 630 | + YAML frontmatter, and canonical trust tiers (`unverified`, `heuristic`, |
| 631 | + `machine_confirmed`, `human_reviewed`) per OKF spec §5.3. |
| 632 | + - **Bundle Import/Export**: Bi-directional OKF bundle exchange |
| 633 | + (`export_okf_bundle` / `import_okf_bundle`) with CLI support |
| 634 | + (`scripts/advise.py --export-okf <dir>` and `--import-okf <dir>`). |
| 635 | + - **Contextual Advisory Dossiers**: Generates scoped security guidance with |
| 636 | + trust badges, threat boundaries, guardrail invariants, and few-shot |
| 637 | + verified patch diffs. |
| 638 | + |
| 639 | +7. **Tamper-Proof Hermetic Dependencies (`requirements.txt` / `install.sh`)**: |
| 640 | + |
| 641 | + - Pinned and fully hashed dependency manifests compiled via `pip-tools` |
| 642 | + (`reference/requirements.in` and `reference/sandbox/requirements.in`). |
| 643 | + - `install.sh` enforces `--require-hashes` during installation to guarantee |
| 644 | + hash verification and supply-chain integrity. |
| 645 | + |
429 | 646 | ### Why Build a Programmatic Harness? |
430 | 647 |
|
431 | 648 | - **Determinism:** Some stages such as the reproduction agent or patch agent |
@@ -862,3 +1079,63 @@ to do this, including connecting the pipeline to **Google Cloud Pub/Sub**. |
862 | 1079 | Pub/Sub topic to route the alert payload directly into your team's chat, |
863 | 1080 | issue tracker, or paging system. This cleanly decouples the isolated scanning |
864 | 1081 | environment from your internal alerting infrastructure. |
| 1082 | + |
| 1083 | +______________________________________________________________________ |
| 1084 | + |
| 1085 | +## Roadmap / Future Work |
| 1086 | + |
| 1087 | +- **Continuous Pipeline (now supported, opt-in):** The pipeline can run as a |
| 1088 | + continuous review of a **living** codebase via the **snapshot-per-pass** |
| 1089 | + model: each pass pins its own immutable snapshot, every finding is stamped |
| 1090 | + with the snapshot it was discovered against, and the target is synced |
| 1091 | + **non-destructively at pass boundaries** only. This is **opt-in and default |
| 1092 | + off** — without `--sync` / snapshot arguments the pipeline behaves exactly |
| 1093 | + like a point-in-time review. Still future work: line/AST re-anchoring of |
| 1094 | + carried findings across code changes (rebasing reproducers/patches instead of |
| 1095 | + re-discovering them). See [The Snapshot Model](#the-snapshot-model). |
| 1096 | +- **Skill Self-Improvement (Meta-Learning):** The current |
| 1097 | + `workspace/learnings.jsonl` and Knowledge Base (KB) architecture tracks |
| 1098 | + codebase-specific empirical outcomes to adapt the `THREAT_MODEL.md` and |
| 1099 | + context pointers. Future iterations of the pipeline could take this a step |
| 1100 | + further and use this historical data to reflect on and automatically rewrite |
| 1101 | + its own `SKILL.md` prompts. For example, if a certain type of hallucination is |
| 1102 | + repeatedly caught by the Critic, a self-improvement meta-agent could update |
| 1103 | + the Researcher's `SKILL.md` instructions to explicitly filter out that |
| 1104 | + specific pattern before it even reaches the Review stage. **Security Note:** |
| 1105 | + Committing automated changes to `SKILL.md` files must always be human-gated to |
| 1106 | + prevent an attacker from using prompt injection (e.g., via a malicious payload |
| 1107 | + in a target file) to trick the meta-agent into ignoring a vulnerability class |
| 1108 | + globally. |
| 1109 | +- **Software Dark Factory:** Integrate this pipeline into an entirely AI driven |
| 1110 | + software development. Instead of vulnerable discovery for action by humans, |
| 1111 | + Mantis would become the autonomous vulnerability research and release gating |
| 1112 | + component of the dark factory. Before the dark factory can push to production, |
| 1113 | + it must have had N hours of adversarial vulnerability research or "red |
| 1114 | + teaming" by a pipeline like Mantis. |
| 1115 | + |
| 1116 | +______________________________________________________________________ |
| 1117 | + |
| 1118 | +## Troubleshooting Guide |
| 1119 | + |
| 1120 | +### 1. Loop Iterations are Re-Evaluating the Same Code |
| 1121 | + |
| 1122 | +- **Symptom:** The loop keeps reviewing the same files and reporting identical |
| 1123 | + bugs. |
| 1124 | +- **Solution:** Ensure `/mantis-architecture` completes successfully and writes |
| 1125 | + its synthesized knowledge to the `workspace/kb/` directory. The `/mantis-plan` |
| 1126 | + strategist checks this Knowledge Base to dynamically skip already analyzed |
| 1127 | + areas. Check that file permissions allow writing to `workspace/kb/`. |
| 1128 | + |
| 1129 | +### 2. Other Issues |
| 1130 | + |
| 1131 | +- **Symptom:** Something isn't working. |
| 1132 | +- **Solution:** Ask an AI coding tool to review your pipeline and the |
| 1133 | + conversations or trajectories that are leading to the unexpected behavior. |
| 1134 | + They will often give you useful insights. |
| 1135 | + |
| 1136 | +This is not an officially supported Google product. This project is not eligible |
| 1137 | +for the |
| 1138 | +[Google Open Source Software Vulnerability Rewards Program](https://bughunters.google.com/open-source-security). |
| 1139 | + |
| 1140 | +This project is intended for demonstration purposes only. It is not intended for |
| 1141 | +use in a production environment. |
0 commit comments