# agengo user guide
This is the complete reference for agengo 0.4. It covers installation, the plan format, every CLI command, the workflow and its states, how to answer requests, quality gates, storage and cleanup, the adapter protocol, security limits and testing. For an overview, start with the [README](../README.md). Terms are defined in the [glossary](glossary.md). A Vietnamese translation is available: [docs/vi/huong-dan.md](vi/huong-dan.md).
**Contents:** [Requirements](#requirements) · [Quick start](#quick-start) · [Clarifying an idea](#clarifying-an-idea) · [Plan format](#plan-format) · [Commands](#commands) · [Workflow and states](#workflow-and-states) · [Answering requests](#answering-requests) · [Quality gates](#quality-gates) · [Metrics](#metrics) · [Storage and cleanup](#storage-and-cleanup) · [Adapter protocol](#adapter-protocol) · [Security](#security-limits) · [Testing](#testing)
## Requirements
- Linux, macOS or Windows 10/11. On Windows, Claude Code needs [Git for Windows](https://git-scm.com/downloads/win), and deep checkouts such as `node_modules` work best with `git config --global core.longpaths true` (agengo sets it for its own Git commands, not for the agents').
- To build from source only: Rust/Cargo 1.90+ and a C compiler (for the bundled SQLite).
- Git 2.31+ with `user.name` and `user.email` configured.
- Under WSL, keep repositories in your Linux home directory rather than `/tmp`: WSL shuts down when it has been idle for a while and may clear `/tmp`, taking the run state in `.git/agent-flow/` with it.
- One of:
- [Claude Code](https://claude.com/claude-code) on `PATH` and logged in; or
- your own adapter passed with `--agent <executable>` (see [Adapter protocol](#adapter-protocol)).
Install a prebuilt binary (Linux and macOS, x64 and arm64; Windows, x64) with npm, the shell installer or the PowerShell installer, or build from source:
```bash
npm install -g agengo # Node.js 14.18+; or run without installing: npx agengo --help
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/nguyentan510/agengo/releases/latest/download/agengo-installer.sh | sh
powershell -ExecutionPolicy ByPass -c "irm https://github.com/nguyentan510/agengo/releases/latest/download/agengo-installer.ps1 | iex" # Windows
cargo install agengo --locked # from crates.io, builds from source
cargo install --path . --locked # from a local checkout
agengo --help
```
npm and the shell and PowerShell installers download the binary for your platform from the GitHub Release of that version and check its SHA-256 checksum.
## Quick start
0. Once per repository, run `agengo init` so Claude Code, Codex and other agents working there know when to hand work to agengo (see [Agent integration](#agent-integration)).
1. Write `plan.yaml`, or let the agent draft one with `agengo plan --goal "..." --format yaml > plan.yaml`. If the goal is still a rough idea, settle it first with `agengo spec` (see [Clarifying an idea](#clarifying-an-idea)).
```yaml
schema_version: 1
goal: Add a greeting command
tasks:
- id: greet
title: Greeting helper
goal: Add greet(name) to src/greet.py returning "Hello, <name>!".
owns: [src/greet.py, tests/test_greet.py]
acceptance: ["greet('An') returns 'Hello, An!'"]
verify: [["python3", "-m", "pytest", "-q", "tests/test_greet.py"]]
- id: cli
goal: Expose greet through `python3 -m app NAME`.
depends: [greet]
owns: [src/app]
acceptance: ["python3 -m app An prints Hello, An!"]
verify: [["python3", "-m", "pytest", "-q"]]
final_verify: [["python3", "-m", "pytest", "-q"]]
```
2. Validate the plan without calling an agent: `agengo plan --file plan.yaml --brief`.
3. Run it: `agengo run plan.yaml --id demo --jobs 2`. Add `--await-approval` if you want to approve the plan before any agent starts.
4. Follow progress with `agengo status demo` and `agengo inbox demo`. Each request that needs you comes with the exact `agengo respond ...` command.
5. When the run prints `[DELIVERED]`, inspect the result with `git log af/demo`, then merge it yourself.
Exit codes: `0` delivered · `2` waiting for your answer (run `resume` after answering) · `1` error · `130` interrupted with Ctrl‑C (run `resume` to continue).
## Clarifying an idea
A one-line idea leaves the planner guessing, and its guesses are invisible. `agengo spec` turns the idea into `spec.yaml`, which states what to build and why without saying how: the problem, the people who use the result, prioritized user stories (P1 is the smallest useful slice) with Given/When/Then scenarios, requirements `FR-n`, measurable success criteria `SC-n`, what will not be built, and the assumptions the agent made, each with what would change if it is wrong.
```sh
agengo spec --idea "a sales app for my clothes shop" # round 1; exit 2 while questions are open
agengo spec spec.yaml --answer Q-1=B --answer Q-2=yes # answer, and the spec is revised
agengo spec spec.yaml --proceed # accept every remaining recommendation
agengo spec spec.yaml --approve # check readiness, lock with a digest
```
- The agent (role `specify`, read-only) proposes questions only where the answer changes scope, privacy or what users experience. Each question has a reason, 2–4 options with their consequences in plain words, and a recommended option. Technical choices are never asked: the agent decides them and records assumptions.
- agengo, not the agent, enforces the limits. It drops questions that break these rules (for example a technology question or a single option), keeps at most **5** open questions (with the default depth), most important first, and numbers them `Q-n` without ever reusing a number. Round **3**, or `--proceed`, is final: remaining uncertainty becomes assumptions.
- Answer with an option key, `yes` for the recommendation, or your own words (`--answer "Q-3=only on weekdays"`). Answers are kept under `clarifications` with their round and source.
- `--depth quick|standard|deep` sets how much to ask: up to 3 questions per round over 2 rounds, 5 over 3 (the default), or 8 over 4. These are ceilings; the agent asks fewer when fewer matter. The depth is kept in the spec, and `agengo spec spec.yaml --depth …` changes it.
- The recommended option favours results that can be checked automatically where the agents run, and `feasibility` says which part, if any, you will have to check by hand.
- `agengo spec spec.yaml` shows the spec without calling the agent; `--json` prints the open questions and readiness for scripts and agents.
- `--approve` requires: no open high-impact question, at least one P1 story, a scenario for every story, a requirement for every P1 story, a success criterion, a non-empty `out_of_scope`, and a stated problem and actors. It stores `approved: {digest, at}`; any later edit makes the digest stale, and the spec shows as not approved.
The file format is [specs/spec.schema.json](../specs/spec.schema.json). The design is in [docs/design/spec-stage.md](design/spec-stage.md).
### Planning from a spec
```sh
agengo plan --spec spec.yaml --format yaml > plan.yaml # the P1 stories
agengo plan --spec spec.yaml --stories P2 --format yaml # or US-3,US-4
```
The planner sees only the chosen stories and their requirements, plus the success criteria, out-of-scope items, constraints, assumptions and feasibility notes. Each acceptance criterion it writes carries `refs` naming the requirements (`FR-n`) and success criteria (`SC-n`) it checks, and the plan records `spec: {path, digest, stories}`. agengo checks the plan against the spec whenever it is drafted, validated (`plan --file`), run, amended or replaced:
| Rule | Check | Result |
|---|---|---|
| C0 | The spec is approved, unchanged since, and is the version the plan was drafted from; the stories exist | error |
| C1 | Every ref names a requirement or success criterion in the spec | error |
| C2 | Every requirement of the chosen stories is in the refs of at least one acceptance criterion | error |
| C3 | A ref names a requirement of another story | warning |
| C4 | An acceptance criterion has no refs | warning |
With a spec, the planner decides technical and verification matters itself. When part of the result cannot be checked where the agents run (a Windows program built on Linux, for example), the plan checks automatically what it can and the task's goal says what you must check by hand. It asks only when the answer would change what you get or how the success criteria are judged. If a draft still has `questions`, `plan --spec` prints the draft, lists the questions on stderr with the next step, and exits with code `2`; `agengo run` refuses such a draft. Record the answer in the spec, so the approved spec stays the one place where decisions live:
```sh
agengo spec spec.yaml --decision "Receipts are not printed" # revise the spec with the decision
agengo spec spec.yaml --approve # approve the revised spec
agengo plan --spec spec.yaml --format yaml > plan.yaml # draft again
```
`--decision` runs one more spec round with the decision as an answer (kept under `clarifications` with a fresh `Q-n` ID) and clears the approval. An answer that changes nothing you get can instead go to the planner directly with `--context "..."`.
A run keeps a copy of the spec, so later edits to the file do not change what its agents read. Builders and Reviewers receive `context.spec`: the requirements their task's criteria refer to (every requirement of the run's stories for the whole-branch review), all success criteria and what is out of scope. `status` shows the spec, its digest and the stories.
## Plan format
A plan is YAML or JSON, validated against [specs/plan.schema.json](../specs/plan.schema.json). agengo rejects unknown fields, dependency cycles and paths outside the repository.
| Field | Required | Meaning |
|---|---|---|
| `goal` | ✔ | Overall goal of the run |
| `tasks[].id` | ✔ | 1–64 characters from `A-Z a-z 0-9 _ -`, unique |
| `tasks[].goal`, `title` | goal ✔ | Instructions for the agent / short title for people |
| `tasks[].owns` | ✔ | Files or directories, relative to the repository root, that the Builder may change. Changes outside this scope are rejected. Tasks with overlapping `owns` never run in parallel |
| `tasks[].acceptance` | ✔ | Acceptance criteria, as strings or `{id, text}`. Strings get the IDs `AC-1`, `AC-2`, …. With a `spec`, an object may add `refs: [FR-1, SC-2]` |
| `tasks[].verify` | ✔ | argv commands, run on the candidate before review and again at integration |
| `tasks[].depends` | | Tasks that must be integrated first |
| `tasks[].setup` | | Commands that prepare this task's worktrees, in addition to the shared `setup` |
| `tasks[].dependency_context`, `related_to` | | Explain relationships to the agent (`needed_for` / `reason`, `refs`) |
| `setup` | | Commands that prepare every worktree, for example `[["npm","ci"]]` |
| `integration_verify` | | Commands run after every integration |
| `final_verify` | ✔ | Commands run on the final branch before delivery |
| `quality` | | See [Quality gates](#quality-gates) |
| `spec` | | `{path, digest, stories}`, written by `plan --spec`; see [Planning from a spec](#planning-from-a-spec) |
Commands are always argv arrays (`["cmd", "arg"]`) and never go through a shell. Use `["sh", "-c", "..."]` if you need shell syntax.
## Commands
| Command | Purpose |
|---|---|
| `spec --idea I` / `spec FILE` | Turn an idea into a spec by answering questions (`--answer Q-n=…`, `--decision`, `--proceed`, `--approve`, `--depth`, `--json`, `-o`). Exit `2` while questions are open |
| `plan --file F` / `--goal G` / `--from F` / `--spec S` | Validate a plan, or have the agent draft one (`--brief`, `--format yaml`, `--context`; `--stories` with `--spec`). Exit `2` when a `--spec` draft has questions |
| `run PLAN [--id ID] [--jobs N] [--base REV]` | Start a run. Other options: `--review-limit` (default 3), `--gate-limit` (default 2), `--timeout` seconds per agent attempt (default 900), `--builder-handoff worktree\|commit`, `--agent`, `--auth subscription\|api` (default `subscription`, see [Authentication](#authentication)), `--roles`, `--await-approval` |
| `resume ID` | Continue or recover a run |
| `resume ID --task T` / `pause ID --task T` | Unpause / pause one task |
| `status ID [--json]` | Plan, task states, requests and evidence (`--json` includes every attempt's request and result) |
| `inbox ID [--json]` | Pending requests, each with the command that answers it |
| `respond ID Y-xx ...` | Answer a request (see below) |
| `resolve ID T --note N` | Record guidance and reopen a blocked task |
| `amend ID PLAN --note N` | Approve a new plan revision (only tasks that have not started or are blocked may change) |
| `metrics ID [--json]` | Time, tokens and cost per role, per task and in total; rework count; reliability figures (see [Metrics](#metrics)) |
| `metrics --all [--json]` | One row per run in the state database, a combined row and per-model rows (see [Metrics](#metrics)) |
| `clean ID` | Remove the run's worktrees, and its temporary refs once the run is delivered |
| `roles [--file F]` | Validate a custom role catalog and its prompts |
| `init [--no-agents-md]` | Install the agengo skill and an `AGENTS.md` section, and create `.agengo/principles.md` (see [Agent integration](#agent-integration)) |
`-C <dir>` selects the repository; the default is the current directory.
## Workflow and states
```
pending → building → [verifying] → ready_review → reviewing → passed → integrated
↘───────────────── blocked (waiting for you) ─────────────────↙
```
1. **Build.** The Builder works in a fresh worktree on branch `af-work/<run>/<task>/<attempt>`. There are two handoff modes:
- `worktree` (default with Claude Code): the Builder only edits files. agengo captures the changes as a commit and pins it at `refs/agengo/builds/...`.
- `commit` (default with `--agent`): the Builder commits to its assigned branch.
2. **Verify.** The task's `setup` and `verify` commands run on the candidate commit in a clean worktree. The Reviewer only sees commits that pass.
3. **Review.** The Reviewer must report on exactly the SHA it was given. Requested changes become findings (`F-01`, …) that the next Builder attempt receives. Each finding has a severity: `critical` and `high` findings block the task, while `medium` and `low` findings are recorded with state `advisory` in `status --json` and do not go back to the Builder. A review can pass with advisory findings. After `--review-limit` rounds, the run asks you.
4. **Integrate.** agengo runs `merge --no-ff` into `af/<run>`, then the task's `verify` and `integration_verify`. Integration failures go back to the Builder; after `--gate-limit` failures, the run asks you.
5. **Final checks.** `setup`, `final_verify`, `quality.checks`, the duplicate gate and the optional whole-branch review run on the final branch. If they pass, agengo delivers and cleans up.
All state lives in SQLite. If agengo is interrupted at any point, even in the middle of an integration, `resume` continues from exactly there. A file lock ensures only one coordinator runs per run.
## Answering requests
Every request has a `Y-xx` code. `status`, `inbox` and notices print a `Command — ...` line you can copy.
| Kind | When | How to answer |
|---|---|---|
| `approval` | `run --await-approval` | `respond ID Y-xx --choice approve` (or `reject`) |
| `decision` | Review or integration limit reached; the Builder needs a choice; **an agent incident** (crash, timeout, reply that breaks the contract); final checks failed | `--choice A --note "guidance"` to retry under the current plan, or `--choice B --note "reason" --plan new-plan.yaml` to approve a new plan |
| `action` | A missing external prerequisite, for example an uninstalled check command or Claude Code not logged in | Do it, then `respond ID Y-xx --note "installed ..."` |
| `information` | The agent needs more information | `respond ID Y-xx --note "answer"` |
After answering, run `agengo resume ID`.
## Quality gates
```yaml
quality:
python_duplicates: warn # off | warn (default) | block
ignore_paths: [vendor] # skipped by the duplicate search
checks: [["ruff", "check", "."]] # extra commands for the final checks
review: false # true: add a whole-branch review
verify_findings: false # true: try to refute blocking review findings first
```
**Finding verification** (`verify_findings: true`). When a Reviewer requests changes, a verifier agent (role `verify`) checks out the same commit and tries to prove each new `critical` or `high` finding wrong. A finding is cleared only when the verifier refutes it with a confidence of at least 0.8; it is then stored as `advisory` with a `refuted` object (`confidence`, `reasoning`). An unsure verdict, a missing verdict or a verifier failure keeps the finding blocking. If every blocking finding is refuted and no earlier finding is still open, the review counts as a pass, so the task does not go back to the Builder or use up a `--review-limit` round. The same applies to the whole-branch review. The verifier's tokens and cost are added to the review attempt, and its verdicts are kept in that attempt's `result.verification`.
**Python duplicates** compares syntax fingerprints (tree-sitter) of functions. Parameter and local variable names are normalized, so a copied function with renamed variables is still found. Functions that only store values into attributes (`self.x = x` boilerplate in `__init__`) are ignored. Only new duplicates, or more copies than at `base`, count.
- `warn`: records the result in the `quality_duplicates` attempt and still delivers, with a warning.
- `block`: checks at **every integration**, so the Builder of the task that adds a duplicate has to fix it. At the final checks, duplicates block delivery.
- `true`/`false` from 0.2.x plans are still accepted and mean `block`/`off`.
## Metrics
`agengo metrics ID` reports one run; `agengo metrics --all` reports every run in the state database. Both only read the state database; they make no agent calls. Add `--json` for the full document. The text output prints the same figures, with a `[RELIABILITY]` block after the usage lines of `metrics ID`; a rate that is omitted from the JSON is printed as `n/a`.
`metrics ID --json` has the keys `run_id`, `roles` (time, attempt count and usage per role), `tasks` (build and review attempts and usage per task), `usage_total`, `additional_task_attempts` (build and review attempts beyond the first per task and role) and `reliability`.
### The `reliability` object
Only task build and review attempts count here: attempts with role `build` or `review` and a task. The first attempt of a task is the earliest one recorded. A review attempt **has a verdict** when agengo recorded it as `pass` or `changes_requested`. Review attempts without a verdict (still `active`, or ended as `blocked`, `error`, `interrupted` or `superseded`) are not counted, so an interrupted or failed review is neither a failed first review nor a review round. A review whose blocking findings were all refuted by finding verification is recorded as `pass`.
| Key | Meaning |
|---|---|
| `tasks_reviewed` | Tasks with at least one review attempt that has a verdict |
| `first_review_pass` | Tasks whose first review verdict is `pass` |
| `first_review_pass_rate` | `first_review_pass / tasks_reviewed`, from 0 to 1. **Omitted** when `tasks_reviewed` is 0 |
| `review_rounds` | `{"mean", "max"}`: review attempts with a verdict per reviewed task, averaged over `tasks_reviewed`, and the largest count. **Omitted** when `tasks_reviewed` is 0 |
| `build_attempts` | Build attempts of every task, in any state, including active ones |
| `integrated_tasks` | Tasks merged into `af/<run-id>` |
| `build_attempts_per_integrated_task` | `build_attempts / integrated_tasks`. **Omitted** when `integrated_tasks` is 0 |
| `gate_failures` | Sum over tasks of the integration failures counted toward `--gate-limit`. A failure that needs an `action` (a missing prerequisite) is not counted |
| `review_failures` | Sum over tasks of the `changes_requested` reviews counted toward `--review-limit` |
| `findings.total` | Review findings recorded in the run |
| `findings.by_state` | Findings per state: `open`, `advisory`, `resolved`, `superseded`. States with no findings are left out |
| `findings.by_severity` | Findings per severity: `critical`, `high`, `medium`, `low`. A finding stored without a severity counts as `high`, the same default agengo uses to decide whether it blocks. Severities with no findings are left out |
| `by_model` | One entry per model that reported [usage](#token-and-cost-usage-optional), sorted by model; see below |
`gate_failures` and `review_failures` are the per-task counters that the limits use. agengo sets a task's counters back to 0 when it reopens the task through `resolve`, `respond` (choice A) or `amend`, so they count failures since the task was last reopened, not over its whole history.
Each `by_model` entry:
| Key | Meaning |
|---|---|
| `model` | The `model` an attempt reported in its usage; `null` when usage had no model |
| `attempts` | Attempts of any role in the run that reported usage with this model |
| `cost_usd` | Sum of their `cost_usd`. **Omitted** when none reported a cost |
| `tasks_first_built` | Tasks whose first build attempt reported this model |
| `tasks_reviewed` | Those tasks that have at least one finished review attempt |
| `first_review_pass` | Those tasks whose first finished review attempt is `pass` |
| `first_review_pass_rate` | `first_review_pass / tasks_reviewed`. **Omitted** when `tasks_reviewed` is 0 |
`tasks_first_built`, `tasks_reviewed`, `first_review_pass` and the rate credit each task to the model of its first build attempt only, even when a later build attempt used another model. A task whose first build attempt reported no model (or no usage) is credited to the `"model": null` entry when there is one, and otherwise to no model. `attempts` and `cost_usd` count every attempt of the model, rework included.
### `metrics --all`
`metrics --all --json` returns `{"runs": [...], "combined": {...}, "by_model": [...]}`. Runs are listed in the order they were created.
| Key | Meaning |
|---|---|
| `runs[].run_id` · `runs[].state` | Run ID and run state |
| `runs[].tasks` | Tasks in the run's current plan revision |
| `runs[].agent_attempts` | Task build and review attempts (the sum of `agent_attempts` in the run's `tasks` rows) |
| `runs[].tasks_reviewed` · `first_review_pass` · `first_review_pass_rate` · `gate_failures` | As in the run's `reliability` object, including when the rate is omitted |
| `runs[].cost_usd` | The run's total reported cost (`usage_total.cost_usd`). **Omitted** when no attempt reported a cost |
| `combined.runs` | Number of runs |
| `combined.tasks` · `agent_attempts` · `tasks_reviewed` · `first_review_pass` · `gate_failures` · `cost_usd` | Sums of the run rows. `cost_usd` is **omitted** when no run has a cost |
| `combined.first_review_pass_rate` | `combined.first_review_pass / combined.tasks_reviewed`, not an average of the run rates. **Omitted** when `combined.tasks_reviewed` is 0 |
| `by_model[]` | The runs' `by_model` entries merged by model: `model`, `runs` (runs in which the model reported usage), and the sums of `attempts`, `cost_usd` (**omitted** when no run reported a cost for the model), `tasks_first_built`, `tasks_reviewed` and `first_review_pass`. `first_review_pass_rate` is computed from the sums and **omitted** when `tasks_reviewed` is 0 |
These figures compare agents and models only as well as the runs allow: tasks differ in size and difficulty, so compare models on similar plans.
## Storage and cleanup
| Data | Location |
|---|---|
| State and evidence | `.git/agent-flow/state.sqlite3` (shared by all worktrees of the repository) |
| Agent worktrees | `~/.cache/agengo/worktrees/<repo>-<id>/<run>/<step>/<attempt>`. Precedence: `$AGENGO_WORKTREES`, then `$XDG_CACHE_HOME/agengo/worktrees`, then on Windows `%LOCALAPPDATA%\agengo\worktrees`. The location chosen first is recorded in `.git/agent-flow/worktree-root` |
| Result branch | `refs/heads/af/<run>` |
| Temporary refs | `refs/heads/af-work/<run>/…`, `refs/agengo/builds/<run>/…` |
Worktrees live **outside `.git`**, because Claude Code refuses to write below `.git/`. Each step's worktree is removed as soon as the step finishes, except a blocked Builder's worktree, which is kept for inspection. On delivery, agengo removes all of the run's worktrees and temporary refs. `agengo clean ID` cleans up manually; for a run that is not delivered it keeps the temporary refs, because unfinished tasks still need those commits.
## Adapter protocol
With `--agent <exe>`, agengo runs `<exe>` once per attempt, with the assigned worktree as the working directory. The request is one JSON document on **stdin**, following [specs/request.schema.json](../specs/request.schema.json). The adapter prints exactly one JSON document on **stdout**, following [specs/outcome.schema.json](../specs/outcome.schema.json) (the `plan` role follows [specs/planner-output.schema.json](../specs/planner-output.schema.json), the `specify` role [specs/specify-output.schema.json](../specs/specify-output.schema.json)). Environment variables are inherited from agengo, except API keys in `--auth subscription` mode (see [Authentication](#authentication)). On Windows the adapter must be an `.exe`, `.cmd` or `.bat` file; to use a script, wrap it in a `.cmd` (for example `@python "%~dp0adapter.py" %*`). A bare name is looked up on `PATH` with `PATHEXT`, as are the commands in `verify` and `setup`, so `["npm", "test"]` runs `npm.cmd`.
A `specify` request carries `idea`, `spec` (the current sections, `null` in round 1), `answers` (`id`, `question`, `answer`), `round` and `finalize`; it runs in the repository root.
Main request fields: `role` (`plan`/`specify`/`build`/`review`/`verify`), `run_id`, `attempt_id`, `plan_revision`, `task` (id, goal, owns, acceptance, verify, …), `head`, `base`, `integration_sha`, `worktree`, `builder_handoff`, `merge_parent` (when present), `feedback`, `decisions`, `context` (`acceptance`, `decisions`, `open_findings`, and `spec` when the plan has one) and `relationships`. A `plan` request drafted with `--spec` carries `spec`, the part of the spec to plan.
Result:
```json
{"status": "done", "head": "<sha>", "summary": "…", "blocker": null,
"findings": [], "finding_resolutions": [], "resolved_conflicts": []}
```
- Builder, `commit` mode: `done` with the new HEAD SHA (clean worktree, unchanged branch). `worktree` mode: `ready` with `head` set to the starting commit, and the index untouched.
- Reviewer: `pass` or `changes_requested`, with `head` equal to the SHA it was given. New findings go in `findings` with an `acceptance_id` and a `severity` (`critical`, `high`, `medium` or `low`; `high` when omitted). `pass` allows only `medium` and `low` new findings, and `changes_requested` needs at least one `critical` or `high` finding, new or still open. Existing findings are answered in `finding_resolutions`.
- Verifier (only with `quality.verify_findings: true`): the request is the review request with `role` set to `verify` and a `findings` list holding the Reviewer's blocking findings, each with its position in the Reviewer's reply as `finding`. The adapter returns `{"verdicts": [{"finding": 0, "refuted": true, "confidence": 0.9, "reasoning": "…"}]}`, following [specs/verification.schema.json](../specs/verification.schema.json), and may add `usage`. It must not change the worktree.
- Any role except the verifier may return `blocked` with a `blocker` (`action`/`decision`/`information`). agengo turns it into a `Y-xx` request.
- A non-zero exit, output that is not JSON, or exceeding `--timeout` is an incident: the task is blocked with a `decision` request.
- agengo checks the result when it arrives: `status`, `blocker.kind`, `blocker.recommended_choice` and `finding_resolutions[].status` must be one of the listed values, `summary` must be a non-empty string, and every field must have the type in the schema. A result that breaks these rules is an incident whose message names the field, for example `invalid agent reply: unknown variant "finished"`. Missing lists count as empty, and unknown fields are ignored, so an adapter may add its own data. If the result echoes `attempt_id`, `run_id`, `plan_revision` or `task_id`, they must match the request.
A complete reference adapter lives in [`tests/support/mod.rs`](../tests/support/mod.rs) (function `adapter`).
### Token and cost usage (optional)
An adapter may add a top-level `usage` object next to `status`, following [specs/usage.schema.json](../specs/usage.schema.json). agengo stores it per attempt, shows it in `status --json`, and totals it in `agengo metrics` per role, per task and per run. The reported `model` is what groups the per-model [reliability figures](#metrics).
```json
{"status": "done", "head": "<sha>", "summary": "…", "blocker": null,
"findings": [], "finding_resolutions": [], "resolved_conflicts": [],
"usage": {"input_tokens": 1200, "output_tokens": 300, "cache_read_tokens": 0,
"cache_write_tokens": 0, "cost_usd": 0.012, "model": "my-model"}}
```
- Every field is optional. Fields with the wrong type or a negative value are dropped; an attempt never fails because of usage data.
- `input_tokens` counts input that was **not** read from a cache.
- agengo never prices tokens itself. If the adapter knows the cost, it fills in `cost_usd`.
- Attempts that report no `usage` are shown as "no usage", not as 0. Attempts killed by a timeout have no usage.
- For Claude Code, agengo reads `usage`, `total_cost_usd` and `modelUsage` from the `claude -p` JSON automatically.
Mapping from common providers (field names as in each provider's API):
| agengo field | Anthropic API | OpenAI Chat Completions | OpenAI Responses | Gemini (`usageMetadata`) | Ollama |
|---|---|---|---|---|---|
| `input_tokens` | `input_tokens` | `prompt_tokens − prompt_tokens_details.cached_tokens` | `input_tokens − input_tokens_details.cached_tokens` | `promptTokenCount − cachedContentTokenCount` | `prompt_eval_count` |
| `output_tokens` | `output_tokens` | `completion_tokens` | `output_tokens` | `candidatesTokenCount + thoughtsTokenCount` | `eval_count` |
| `cache_read_tokens` | `cache_read_input_tokens` | `prompt_tokens_details.cached_tokens` | `input_tokens_details.cached_tokens` | `cachedContentTokenCount` | — |
| `cache_write_tokens` | `cache_creation_input_tokens` | — | — | — | — |
If your agent calls a model several times in one attempt, sum the values before returning them.
### Claude Code
Without `--agent`, agengo runs `claude -p --output-format json --json-schema … --strict-mcp-config` with the prompts in [specs/prompts](../specs/prompts). Print mode has nobody to approve permission prompts, so permissions are granted per role:
| Role | Tools | Permissions |
|---|---|---|
| plan, specify | Read, Grep, Glob | `default` (read-only) |
| build | Read, Grep, Glob, Edit, Write, Bash | `acceptEdits`, plus `Bash` allowed |
| review | Read, Grep, Glob, Bash | `default`, plus `Bash` allowed |
Prompts can be replaced with `--roles path/roles.yaml` (see [specs/roles.yaml](../specs/roles.yaml); validate with `agengo roles --file ...`).
## Agent integration
Coding agents only use tools they know about. `agengo init` installs the agengo skill ([specs/skill/SKILL.md](../specs/skill/SKILL.md)) in two places:
| Path | Read by |
|---|---|
| `.claude/skills/agengo/SKILL.md` | Claude Code |
| `.agents/skills/agengo/SKILL.md` | Codex and other agents that load skills from `.agents/skills` |
It also adds a section between `<!-- agengo:begin -->` and `<!-- agengo:end -->` to `AGENTS.md` (created if missing) for agents that read only that file; `--no-agents-md` skips it. Re-running `init` after upgrading agengo refreshes these files. Commit them so everyone working in the repository gets them.
The skill tells the agent to use agengo for multi-task work or when the user mentions agengo or a plan, to settle a rough idea with `agengo spec` first (asking each question through the agent's multiple-choice prompt, `AskUserQuestion` in Claude Code, and leaving the answers and the approval to the user), to get the user's approval of the plan before running it, to put each `Y-xx` request to the user, and to report an agengo failure rather than building the tasks itself.
### Project principles
`agengo init` also creates `.agengo/principles.md`, a short template with four sections: **Stack**, **Commands**, **Conventions** and **Never**. Fill in what applies, in any language. agengo sends the file, without its guidance comments, to the agents that write specs (`agengo spec`) and plans (`agengo plan`), so they use your test commands and conventions instead of guessing them, and do not ask about what the file settles. While every section is empty, agengo ignores the file; it rejects one longer than 32 KiB. Re-running `init` never overwrites it. The skill offers to fill it from the repository the first time, and writes it only after you agree.
## Authentication
Claude Code and Codex use an API key from the environment ahead of the subscription you logged in with. Shells inside other agents, IDEs and CI often carry such keys, so agengo picks the login explicitly:
- `--auth subscription` (default): agengo removes `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, `OPENAI_API_KEY`, `CODEX_API_KEY`, `GEMINI_API_KEY` and `GOOGLE_API_KEY` from the environment of every agent it starts, custom adapters included. `CLAUDE_CODE_OAUTH_TOKEN` (a subscription token from `claude setup-token`) is kept. Log in once on the machine: `claude`, then `/login`; or `codex login`.
- `--auth api`: the environment is passed through unchanged.
The mode is stored with the run, so `resume` uses the same one. Runs started before this option existed pass keys through. When an attempt fails because the login or key is missing or refused, the task waits for an `action` request explaining what to do; after logging in, run `agengo resume ID`.
## Security limits
- Plan commands (`setup`, `verify`, …) run with your permissions. Only run plans you have read; `--await-approval` enforces an approval step.
- The Builder and Reviewer can use Bash and are **not sandboxed**. Worktrees separate the working directory but share `.git` with the repository, so an agent could in principle read or change refs and the state file. The checks after every attempt (HEAD, index, `owns` scope, SHA, the `af/<run>` ref) catch most deviations but do not replace a sandbox. For untrusted code or agents, run agengo inside a container or VM.
- agengo's own Git commands run with hooks and `core.fsmonitor` disabled, so a hook planted by an agent never runs inside agengo. While a run executes, agengo also watches the repository's `config`, `config.worktree`, `hooks/` and `info/attributes`: if they change during an agent attempt or a check, the result is rejected and the task waits for an `action` request. Inspect the files, remove anything you did not add, then `respond` and `resume`; the files as they are then become the new baseline. Setup commands that install hooks on their own (for example husky or pre-commit) trigger this once.
- If one of your branches or tags (anything outside `af/` and `af-work/`) moves while agents are running, agengo prints a warning with the `git reflog` command to check. It does not stop the run, because you may be committing in the same repository at the same time.
- Child processes inherit your full environment, including tokens.
- agengo never pushes and never changes your current branch.
## Testing
```bash
cargo test --locked # unit tests + system tests with a simulated agent
AGENGO_CLAUDE_E2E=1 cargo test --locked --test system # plus one real Claude Code run (uses API credits)
```
`tests/support/mod.rs` builds temporary Git repositories and a simulated adapter; scenarios are selected with `AGENGO_SYSTEM_TEST_SCENARIO`. System tests run in parallel, one thread per CPU; set `AGENGO_TEST_THREADS=1` to run them one at a time. See [CHANGELOG.md](../CHANGELOG.md) for release history.