One-page reference for what's wired and how. User-facing docs are in README.md; start there if you're using agentgg rather than working on it.
agentgg scan runs as a pipeline, orchestrated by scan.ts. The first two phases each write a durable artifact under state/, so the steps are inspectable (and, later, distributable):
- Recon — one tool-enabled survey of the repo via the built-in recon agent (
src/agents/recon.md, loaded byrecon-agent.ts). Produces a conciseReconReport→state/recon.json. Cached byreconHash(source identity +fingerprinttags);--re-reconforces a refresh,--no-reconskips it entirely. The brief is injected into precondition prompt checks and into every agent's detection prompt. - Precondition — for each selected agent, decide queued vs skipped (
precondition.ts). The decisions (with reasons) are written tostate/plan.jsonbefore any agent runs. Reused like recon: when aplan.jsonalready matches the recon brief and covers the-tselection, the for-loop is skipped and its decisions are lifted from disk (--re-reconre-evaluates;--no-reconbypasses gating and queues every-tagent). - Run — each queued agent runs over its
wherefile set, in batches. - Dedup, then Validate (
--scopefor rules;--live-validateadds a live sub-pass at its end), then Score, then Fix — second-pass passes over the findings. Dedup leads so validation, scoring and fixing only run on primaries; scoring and fixing read the combined static + live verdict. Fix writes asuggestedFixonly for a primary that verdict confirmed (fix-phase.ts). All four run by default; disable individually with--no-validate/--no-score/--no-fix/--no-dedup. - Report — per-finding
findings/*.md+summary.md. Skippable with--no-summary(state still persists); regenerate later withagentgg summary.--serve(opt-in) boots the viewer once the report is written.
Each phase is also a standalone command over the same --output dir, sharing the artifacts above: agentgg recon (phases 1–2 only, no detection), agentgg revalidate (phase 4 validate), agentgg score (phase 4 score), agentgg fix (phase 4 fix), agentgg summary (phase 5). recon writes recon.json + plan.json that a later scan reuses — the durable plan→run hand-off.
agentgg create (commands/create.ts → create.ts) is a standalone, single-shot flow that takes a past security report and emits a new agent .md shaped for the codebase the report came from. No state/ dir, no resume, no recon brief — just one tool-enabled LLM session per report.
- Resolve reports —
report-loader.tsturns--report(a.md/.txtfile, a directory of them, or a.txtlist of paths) into aLoadedReport[]. A.txtis auto-detected as a list iff every non-blank, non-comment line resolves to an existing path. - Distill — for each report, call
detector.createAgent(see Detector contract). The built-in instructions live insrc/agents/create.md, loaded bycreate-agent.tsthe same way recon loads its prompt. The wrapper indetect.ts(buildCreateAgentPrompt) appends the report verbatim plus the scope rules. The model returns anAgentSpec(the LLM-authored subset ofAgent: slug, name, description, noiseTier, references, precondition, where, prompt body), schema-constrained by Zod at the protocol layer. - Render + lint —
agent-spec.tsrenders the spec to the standard agent.mdshape (YAML frontmatter + body), then round-trips it throughparseAgentMarkdownfrom@agentgg/coreto catch bad regex, malformed slug, or schema mismatch before write. - Write — filename is
<slug>-<shortHash>.mdwhere the hash issha256(codeRoot|reportPath|reportContent).slice(0, 8). Reruns on identical inputs overwrite in place; different reports never collide.
The generated agents land in --output only. Installing them (so scan picks them up) is an explicit follow-up: agentgg agents add <output-dir>.
There is one agent shape — no mode. Every agent declares a precondition, a where, and a prompt body (the instructions), and is always tool-enabled (Read/Glob/Grep). At runtime:
- Precondition (
precondition.ts) — aregexblock (fileextensions/files/directories/ contentpatterns) is pure filesystem work; apromptis one cheap LLM call that sees the recon brief; both present = AND; neither = always run. Regex short-circuits before the LLM. Apromptcall that fails logs a warning and queues the agent, so a flaky gate never costs coverage; only an error that would fail every call (bad key, no credits) stops the scan. - Where (
walker.ts) — when the agent declaresextensionsand/orfilePatterns, the walker enumerates matching files (a bare directory/path matches everything under it) minusexcludePatterns, thenpreFilterregexes narrow to files with a line hit (and surface those lines as anchors). An agent that declares neither has no file scope (hasFileScopereturns false): the walker is skipped entirely, the whole repository is its scope, and it finds its own targets with Read/Glob/Grep at a higher turn budget (150 vs 50; see the CLI flags table below). - Run — a scoped agent's candidates are chunked into batches of
where.maxFilesPerBatch(default 5); each batch is one tool-enabled session (detector.runAgent). An agent with no file scope runs as a single session with no seeded files. Batches from every queued agent are flattened into a single scan-wide pool capped by--concurrency, so different agents' batches interleave (safe because per-file writes are namespaced byagent.slug). A session can read beyond its seeded files to confirm a finding. One agent per session; findings are stamped with the agent's slug.
Declare a scope whenever you can: a scoped agent reports how many candidate files it reviewed against a known total, while an agent with no file scope can't say what fraction of the repository it covered. No file scope is for a question with no syntax to anchor on, such as whether a control is missing everywhere rather than misused somewhere.
Backend-agnostic (detect.ts). One Detector is held for the whole scan:
recon— tool-enabled survey →ReconResult.suggestExcludes—--auto-excludeonly; one no-tools call over the directory layout → folder globs to skip (SuggestExcludesResult).checkPrecondition— one-shot LLM relevance gate (no tools) →{ relevant, reason }.runAgent— tool-enabled investigation over a batch of seeded files →Finding[].validateFinding/validateFindingByScope— second-pass classifier.scoreFinding— picks the 8 CVSS 3.1 base metrics.createAgent—agentgg createonly; tool-enabled session that reads a past security report and explores the repo →AgentSpec. Optional on the interface so a backend can opt out; every shipped detector implements it.
Three implementations in detectors/:
ClaudeAgentDetector— wraps@anthropic-ai/claude-agent-sdk(spawns theclaudeCLI), SDK-enforced structured output. Handles both Anthropic auth types.recon/runAgentget["Read","Glob","Grep"]; precondition/validate/score gettools: [].VercelAgentDetector— Vercel AI SDK. Tool-using methods (recon,runAgent) use a hand-rolled multi-stepgenerateTextloop (Read/Glob/Grep astool()defs, TPM-retry, JSON parsed from the final text with astructuredModelreformat fallback); no-tool methods usegenerateObject. The tool implementations are bounded to the scan root and honor the exclude set.MultiProviderDetector—generateObjectwith strict structured output, no tools. Itsrecon/runAgentare best-effort (work from prompt context only, no file browsing).
Provider → detector:
- Anthropic (API key + OAuth) →
ClaudeAgentDetectorfor every method. - OpenAI / Bedrock / Vertex / OpenRouter →
VercelAgentDetectorfor every method. - Ollama → a composite: tool-using calls (
recon,runAgent) →VercelAgentDetector(best-effort JSON); no-tool calls (checkPrecondition,validate,score) →MultiProviderDetector.
Notes: Anthropic via the Vercel SDK was dropped (OAuth tokens get rate-limited; mode: "json" is rejected). Ollama splits because structuredOutputs: true (required for generateObject) conflicts with tool-calling. Vertex routes through @ai-sdk/openai against the Model Garden OpenAI-compatible endpoint with a fetch middleware stamping Google ADC tokens; GLM-5's non-standard message.reasoning_content is ignored by the JSON extractor. OpenRouter uses the same @ai-sdk/openai path against openrouter.ai/api/v1, with a fetch middleware that injects an OpenRouter provider-routing block (tool-calling required and price sort by default, no quantization filter unless set; saved with agentgg config --openrouter-routing, overridden by OPENROUTER_* and the scan-time --openrouter-routing). The reasoning/content split that Vertex handles above is, on OpenRouter, the individual host's job, and hosts get it wrong: one that returns the model's whole answer as reasoning leaves message.content empty, so generateObject throws NoObjectGeneratedError on a response the transport layer sees as successful. OPENROUTER_IGNORE exists to drop such a host, since no retry or fallback can detect it.
Providers are standalone modules under providers/. Adding one = a module + an entry in providers/index.ts + a Provider enum entry + a UserConfig block in core/types.ts. No edits to llm.ts / init.ts / config.ts / scan.ts. Each ProviderModule carries buildDetector, collectCredentials, acceptedFlags (passing a flag the active provider doesn't accept is a hard error), curatedModels/listModels, and formatForList/redact.
The walker is a pure enumerator — it applies only the excludePatterns it's handed and carries no built-in policy. The shared default skip set (node_modules, .git, build dirs, lockfiles, binaries) lives as data in DEFAULT_EXCLUDES (walker.ts) and is merged in by scan.ts. It can be dropped globally (--no-default-excludes) or per-agent (where.useDefaultExcludes: false). CLI --exclude paths are always applied (treated as deleted) and, on the Vercel tool path, enforced at the tool layer so a tool read can't reach them. (The Claude Agent SDK's built-in tools aren't bounded, so there it's prompt-level only.)
Auto-exclude (smart-exclude.ts) is on by default (--no-auto-exclude disables it) and runs before recon: a no-tools LLM call classifies the directory layout and returns folders not worth scanning (tests, fixtures, docs, generated output, vendored deps). Those globs are folded into excludePatterns exactly like a CLI --exclude, so recon, the precondition census, and every agent inherit them (and they fold into the resume scope signature). It only removes folders. A pass failure is advisory — the scan continues with no auto-excludes.
out/
├── summary.md
├── findings/...
└── state/
├── scan.json ← root + timestamps
├── recon.json ← ReconReport (phase 1)
├── plan.json ← ScanPlan: queued/skipped decisions (phase 2)
├── usage.json ← ScanUsage: LLM token usage (input / output / cached) for this invocation
├── runs/<id>.json ← RunMeta per scan / recon / revalidate / score / summary
├── agents/<slug>.json ← AgentRun resume sidecar (one per agent)
└── files/<path>.json ← FileRecord per scanned source file
usage.json (ScanUsage) records how many tokens a run actually spent — input, output, and prompt-cached, plus a call count. The detector checkpoints it as the run proceeds (written incrementally, force-flushed on SIGTERM), so even an interrupted run leaves an accurate tally. It's purely an observability surface: the CLI records raw counts and doesn't price or bill anything (you run your own model) — whatever reads usage.json (a dashboard, a CI summary, your own accounting) decides what to do with the numbers. One file per invocation, written for every provider: the Vercel AI SDK path (vertex / openai / bedrock / openrouter), the Claude Agent SDK (Anthropic, from its result message's usage), and the structured-output path (Ollama).
Resume:
- Recon + plan — a
recon.jsonwhosereconHashmatches is reused without re-surveying; aplan.jsonwith the samereconHashthat covers the current-tselection is reused without re-running the precondition for-loop (scan.tsreadsreadScanPlanand filters the selection to the plan's queued slugs).--re-reconforces both to recompute. - Per-agent — an agent is skipped on re-run when its
AgentRunsidecar matches the current scope (source identity + diff + excludePatterns + includePatterns + maxFileSizeKb + reconHash); prior findings are lifted from disk. An agent only writes its sidecar on full completion, so an interrupted agent re-runs in full. - Per-file — within an agent, a
(file, agent)pair is skipped when theFileRecordshows a priordetectwith the samecontentHashand agent slug.
--rescan bypasses resume. Changing scope (--diff, --exclude, --only, --max-file-size, source identity) or the recon brief (--re-recon / a stack change) invalidates the affected agents. Source identity is the absolute scan root unless --source-id <id> overrides it; the override is what lets a distributed runner (or a CI job with a moving checkout path) extract the same source to a different path each run and still resume. It is recorded verbatim as scope.rootPath on the sidecar and rootPath on plan.json, and is never resolved as a path. --no-recon uses a synthetic reconHash ("no-recon") and queues every -t agent, so its runs resume independently of recon-bearing runs.
Four Detector methods, so any provider participates without bespoke wiring:
validateFinding— full classifier; re-reads source →confirmed/false-positive/out-of-scope/uncertain+ reasoning. Used by--validateandagentgg revalidate.validateFindingByScope— cheap variant, no source read; onlyout-of-scope/uncertain. Triggered by an explicit--scope <path>combined with--no-validate(a pre-filter that stands in for the full validator when it's turned off).scoreFinding— picks the 8 CVSS 3.1 base metrics; vector string, base score, and severity bucket are computed deterministically inscoring.asCvssScore. Triggered by--scoreoragentgg score.suggestFix— one tool-enabled session per confirmed primary (Read/Glob/Grep rooted at the repo, the validator's loop and filters); returns the remediation as plain text (a fix is mostly code, which is what breaks structured output). The tools are there because a fix leans on code outside the finding's file: written blind, it invents a helper's signature or a template engine's syntax. Each generation has an output cap and the session its own turn limit, below the validator's, so a model that cannot find a fix stops instead of reasoning to the provider's limit or reading the repository for fifty turns; a session that ends on a tool call (made, or written out as text) gets one more ask with no tools. The prompt carries the finding, its file, the recon brief, and whichever proof confirmed it: the validator's reasoning, and for a reproduced live run its reasoning, its negative control, and its reproduction script (labelled when the replay did not pass). With no script it lists the requests the live agent itself cites in its reasoning, never the first or last N: a session mixes the hunt for the page, the attack and the control in no fixed order. The code comes as SEARCH/REPLACE blocks, each under the path of its file, andfinishFixinfix-edits.tschecks them against the repository: each SEARCH must match whole lines at exactly one place of its file, and a path outside the repository reads as no file. Blocks that pass are stored as one unified diff per file with real line numbers, each under a plainLocation:line that names the file and the lines that change; an answer that fails is sent back once with the problems, and after a second miss the finding gets no fix, so the report never shows code the check could not place. The check proves the edit applies to the file as scanned, not that the fix is correct.fix-phase.tspersists each fix as soon as its call returns, and a fatal provider error stops the phase, not the scan: the report is still written. Writing a new verdict clears the finding's fix, so the next fix pass writes one for that verdict. Every reader goes throughsuggestedFixOfinverdict.ts, which hides the fix unless the combined verdict isconfirmed, so a verdict that changes later hides a fix still on disk. Triggered by--fixoragentgg fix; the command is how a finding thatrevalidateorlive-validateconfirmed afterwards gets its fix, and--forcerewrites existing ones.
| Flag | Applies to | Notes |
|---|---|---|
--max-turns <n> |
recon, agent runs, validator | When set, a uniform cap. Unset: agent batches use where.maxTurnsPerBatch, defaulting to 50 for a scoped agent and 150 for one with no file scope; recon 50, validator 50. |
--max-files-per-batch <n> |
agent runs | Candidate files per batch. Overrides where.maxFilesPerBatch (default 5). |
--concurrency <n> |
precondition gates, agent runs, validation, scoring | One scan-wide cap on in-flight LLM sessions. Phase 3 flattens every (agent, batch) pair into a single pool; validation and scoring fan out one finding per session through the same runConcurrent worker pool. Default 5. |
--re-recon |
recon + plan | Re-run recon and re-evaluate the precondition plan instead of reusing the cached brief/plan. |
--no-recon |
recon + precondition | Skip the survey and the gating loop; run every -t agent unconditionally with no injected brief. |
--no-summary |
report | Skip rendering summary.md + findings/*.md. Also accepted by revalidate / score. State still persists; render later with agentgg summary. |
--effort / --thinking |
provider-dependent | Reasoning knobs. --effort → Claude SDK effort (Anthropic) or reasoning_effort (OpenAI reasoning models only — a non-reasoning model returns HTTP 400); --thinking is Anthropic-only. No-op on providers that don't map them. |
--diff <commit> |
agent runs | Each agent's candidate list is intersected with the touched files; the commit patch is injected as a focus hint. Accepts <ref>, a..b, a...b. |
--exclude / --only / --max-file-size / --no-default-excludes |
file selection | Walk filters. --exclude = deleted; --only restricts; --no-default-excludes drops the built-in skip set. |
--auto-exclude / --no-auto-exclude |
file selection (pre-recon) | LLM pass that picks non-runtime folders to skip, folded in like --exclude. On by default; --no-auto-exclude disables. Logged (reasons under --verbose). |
--validate / --no-validate / --revalidate-all / --scope |
post-detection | Validation passes (see above). On by default; --no-validate for a detection-only run. |
--score / --no-score / --rescore |
post-detection | CVSS scoring pass. On by default; --no-score to skip. |
--fix / --no-fix |
post-detection | Suggested-fix pass over confirmed primaries. On by default; --no-fix to skip. |
--dedup / --no-dedup / --delete-duplicates |
post-detection | De-duplication pass, clustering same-root-cause findings per file. On by default; --no-dedup to skip. |
--serve [port] |
after report | Boot the local web UI when the scan finishes. Opt-in (default port 3737). |
CLI flag wins → frontmatter → hardcoded default. Batch size and per-batch turns:
batchSize = opts.maxFilesPerBatch ?? agent.where.maxFilesPerBatch (default 5)
maxTurnsPerBatch = opts.maxTurns ?? agent.where.maxTurnsPerBatch ?? (50 scoped / 150 no file scope)
ClaudeAgentDetector passes tools: ["Read","Glob","Grep"] for recon/runAgent and tools: [] for the precondition gate / validator / scorer. The SDK option tools controls what's in the model's context (not allowedTools, which only governs auto-approval and is a no-op under bypassPermissions).
VercelAgentDetector declares the same three tools via tool() definitions and runs them in a multi-step generateText loop. The implementations are bounded to the scan root and skip excluded paths.
packages/core/— types (Agent,Precondition,Where,ReconReport,ScanPlan,Finding,FileRecord,AgentRun,UserConfig,CvssScore), CVSS math,fingerprint, persistence helpers (writeFileRecord/readAgentRun/writeReconReport/writeScanPlan/ …), agent loader, path resolution.packages/cli/— commander wiring, detectors, providers, recon, precondition, walker, validator, scoring, reporters, the built-inreconandcreateagents (src/agents/), theAgentSpecschema + renderer (src/agent-spec.ts) used byagentgg create, viewer bootstrap.packages/viewer/— Next.js app served byagentgg view/agentgg scan --serve.