For AI agents: the complete documentation index is available at https://docs.phax.run/llms.txt, the full documentation bundle is available at https://docs.phax.run/llms-full.txt, and this page is available as Markdown at https://docs.phax.run/guide/extend.md.

Extending phax

Extend phax

Five hooks let your own tools inform a run: a gate step that prints a gate report, a brief provider that answers with a brief report, an architecture provider that answers with the repository's architecture for planners, an acceptance provider that judges an acceptance pair, and a plan auditor. A provider is a command in phax.json, split on spaces and run without a shell, that reads a JSON request on stdin and answers JSON on stdout. A gate step reads a request only when it declares "input": "gate-request" (see Gate request); otherwise its stdin is not connected.

The two reports share one location, guide and finding, and phax routes each fact to whoever acts on it: findings and their guides go to the agent, review notes to the reviewer, and a refusal to you.

Gate report steps

A gate step with "output": "gate-report" prints a gate report on stdout, and phax judges the step from that report rather than from its exit code:

{
  "$schema": "https://docs.phax.run/schemas/gate-report/0.21.0.json",
  "outcome": "checked",
  "findings": [
    {
      "id": "no-node-import src/greet.ts node:fs",
      "rule": "a module under src/ imports no node: module",
      "location": { "file": "src/greet.ts", "lines": [1, 1] },
      "message": "imports node:fs",
      "related": [
        { "file": "src/cli.ts", "lines": [3, 5], "why": "the caller, where the read belongs" }
      ],
      "guide": { "summary": "keep I/O in the module's caller", "read": "guides/no-node-import.md" }
    },
    {
      "id": "exports-function src/farewell.ts",
      "rule": "a module under src/ exports its function",
      "location": { "file": "src/farewell.ts", "lines": null },
      "message": "no exported function",
      "related": [],
      "guide": null
    }
  ],
  "review": [
    {
      "owner": "hw-maintainers",
      "note": "whether 'Hello, <name>!' is the greeting the product wants"
    }
  ]
}

Every key shown is required, and a key not shown is refused at any level. lines is [start, end], 1-based and inclusive, or null for the whole file. guide may be null, and findings, related and review may be empty. id belongs to the step: keep it stable across runs of the same check. phax compares ids by equality only and never shows them. read names a file, relative to the working tree, that the agent reads; phax never opens it.

The verdict:

  • Any finding fails the step, whatever the exit code. The fix prompt lists each finding with its rule, location, message, related locations and guide, and tells the agent to read each guide's file before changing code.
  • An empty findings list passes the step on exit 0: { "$schema": …, "outcome": "checked", "findings": [], "review": [] }.
  • A refused report stops the phase without a fix attempt (below).
  • Anything else is a broken step that fails with the raw log: empty or non-JSON output, a document without $schema or in another format, a duplicate id, a lines pair out of order, a key the format does not name, or an empty list on a non-zero exit. The failure names the gate-report URL phax reads.

$schema names the gate-report shape the report is written in: the release that last changed the format. A report stamped newer than the running phax, or in an older shape, fails the step too, and phax names the URL it reads. The step must print a report every time it runs. phax never decides when a finding is due, so report only what is: the gate request is how a step learns what the phase changed and what later phases will bring.

A step that cannot run its checks says so with a refused report, which carries exactly these keys:

{
  "$schema": "https://docs.phax.run/schemas/gate-report/0.21.0.json",
  "outcome": "refused",
  "reason": "the checks need hw-rules 2, and 1 is installed",
  "remedy": "pnpm add -D hw-rules@2"
}

A refusal goes to you, not to the agent, whatever the exit code. No later step runs, no fix attempt is made, and the run exits 4, naming the step, the reason and the remedy. The phase pauses as it does when its fix attempts run out (gates_exhausted), and phax resume runs the gate again before any agent turn, with the full agent.maxFixAttempts budget. gate-attribution.json records the step as refused.

Review notes are for the person who reviews the run. They never fail a step and never reach the agent. phax gathers the notes of each phase's last gate attempt into a ## Review notes section of the review handoff and the PR body, one group per owner, with a note several phases left listed once, naming those phases. When the PR body must be shortened to fit GitHub's limit, it cuts review notes last.

When a step fails again on the next attempt, the fix prompt marks each finding whose id the step with the same command listed in the previous attempt as still failing, wherever it now sits. The previous attempt is the highest-numbered attempt before this one, even across a phax resume. Two commands are the same when they split into the same words (pnpm test is pnpm test), so a gate profile may not list the same command twice: config loading refuses it with exit 2, naming the profile and the command. Nothing else from earlier attempts reaches the agent.

Nothing in a report grants a command. When a guide asks the agent to run a tool, grant it yourself through security.agentCommands.

phax saves every readable report exactly as printed, beside the attempt's log, as checks-attempt-NN.report-SS.json, where SS is the step's position among the steps the attempt runs. The log itself names that file (report: checks-attempt-NN.report-SS.json) rather than holding the report's text, so a later step's failure, whose fix prompt carries the log, never shows the agent a review note. Each attempt also writes checks-attempt-NN.attribution.json, the attempt's step record in the gate-attribution format: the commands it ran, in order, with their results, which ties report-SS to the step that printed it. phax records explain --gates prints each report after its attempt's log and request.

Gate request

A gate step that declares "input": "gate-request" gets a JSON request on stdin, whatever its output. A report step reads the request when it declares input, and does not have to declare it:

{
  "command": "node ./audit.mjs",
  "surface": "structural",
  "firing": "every-phase",
  "output": "gate-report",
  "input": "gate-request"
}
{
  "$schema": "https://docs.phax.run/schemas/gate-request/0.20.0.json",
  "phase": "phase-02",
  "base": "3f9c2a7d1e8b4c6a0f5d9e2b7a1c4d8e6f0b3a5c",
  "terminal": false,
  "phases": [
    { "id": "phase-01", "files": ["src/greet.ts"] },
    { "id": "phase-02", "files": ["src/cli.ts", "tests/cli.test.ts"] },
    { "id": "phase-03", "files": ["README.md"] }
  ]
}
  • phase is the phase being gated.
  • base is the full object name of the commit the phase's branch was created from. phax notes it when it creates the branch and never re-derives it.
  • terminal is true exactly when the gated phase is the run's terminal phase, the one terminal steps fire on.
  • phases is every phase of the run in execution order, each with its planned files to create and edit (optional files excluded).

phax sends facts and decides nothing: the step decides what is due. Read stdin to its end, then parse it. The past is git diff --name-only <base> plus the untracked files (git ls-files --others --exclude-standard). The future is the phases entries after phase, so a finding a later phase is planned to fix need not fail this one. When terminal is true, audit everything. A report step still prints {"$schema": "https://docs.phax.run/schemas/gate-report/0.21.0.json", "outcome": "checked", ...}, never a document without $schema.

phax writes the same bytes to every declaring step of every attempt, then closes stdin. Before an attempt's first declaring step it saves them beside the attempt's log as checks-attempt-NN.request.json, and the log shows stdin: checks-attempt-NN.request.json right after the step's $ line; phax records explain --gates prints the request after its attempt's log. To replay a verdict, run the step on the saved copy in the phase's worktree:

node ./audit.mjs < checks-attempt-01.request.json

Partial commands

A gate step can carry a partial object naming cheaper commands that cover part of what the step checks. The files variant holds a <name> placeholder; the diff variant holds none:

{
  "command": "pnpm test",
  "surface": "local",
  "firing": "every-phase",
  "partial": {
    "files": "pnpm exec vitest run <files>",
    "diff": "pnpm exec vitest run --changed"
  }
}
  • Each phase prompt shows both commands under the step, as "on some files" and "on your changes", and tells the agent to replace the placeholder with the files it chooses.
  • In secure mode the agent may run them without you listing them in security.agentCommands. phax allows the start of every pipe segment of a partial command (its words before a placeholder), for every step of the profile, whatever its firing.
  • phax never runs a partial command. The gate still runs pnpm test, in full.
  • The grammar is small: files needs a <name> placeholder (lowercase letters, digits and -), diff takes none, and the parts of a command are joined with | only. Anything else (&&, ||, ;, &, >, >>, $(…), a backtick, a line break, a stray <, a quote, a backslash, a *, an empty segment, a segment whose first word holds a placeholder) is refused when the config loads, and phax validate names the step, the variant and the construct. phax parses no quotes, escapes or globs, so wrap a command that needs them in a committed script.
  • phax validate and phax run --dry-run list the prefixes each profile's partial commands allow. A prefix that ends at a launcher (sh -c <cmd>, xargs <files>, env FOO=1 <files>, node <files>) lets the agent start any command through it: read the list before you commit a partial.

A piped diff command has two traps. With an empty diff, xargs may run the tool on the whole repository unless it skips empty input (xargs -r). And git diff does not list new untracked files, which a phase worktree holds until phax commits. This form avoids the first trap only:

"partial": {
  "diff": "git diff --name-only --diff-filter=d | xargs -r pnpm exec oxlint"
}

It still skips the files the phase created. A partial command cannot join two listings, so to cover new files too, point diff at a committed script that lists both (git diff --name-only --diff-filter=d and git ls-files --others --exclude-standard) and runs the tool on them.

Brief provider

{ "brief": { "command": "node ./brief.mjs", "push": "findings" } }

A brief tells the agent which rules cover some paths, what fails there and how to fix it. Declare brief in phax.json, phax.local.json or ~/.phax/config.json; the nearest layer that declares it wins whole, command and push together. Both keys are required: a brief without push, or with any other value, fails config loading with exit 2. phax ties the brief to no gate step: a brief informs and never blocks, and the gate still decides. phax judges nothing in the report; it only reads it by its $schema.

phax asks for a brief at two moments:

  • Pushed, once when a phase starts fresh, before the agent's first turn. It goes into the first prompt under ## Brief for this phase, one line per item, as push chooses:

    • "findings" lists the findings due in this phase, in your order, each with its location, rule, message and guide.
    • "findings-and-rules" lists those findings, then each rule over the phase's planned files, with its files and guide.

    A finding due later, or with a null due, is never pushed. At most 50 items are listed, findings first, then one line says how many more phax brief prints. With nothing to list, the section says so in one line. phax asks once per phase: a re-entry after a rate limit shows the recorded brief again, and a resumed phase gets no new section.

  • Pulled, with phax brief [path…], by the agent or by you, at any time. It prints the whole report: each rule with its files and guide, then each finding with its location, due, rule, message, related locations and guide. It exits 0 on any readable report, an empty one included, and 1 otherwise.

The request on stdin has two variants. Inside a phase, it carries the phase facts and files:

{
  "$schema": "https://docs.phax.run/schemas/brief-request/0.20.0.json",
  "phase": "phase-02",
  "base": "3f9c2a7d1e8b4c6a0f5d9e2b7a1c4d8e6f0b3a5c",
  "terminal": false,
  "phases": [
    { "id": "phase-01", "files": ["src/greet.ts"] },
    { "id": "phase-02", "files": ["src/cli.ts", "tests/cli.test.ts"] },
    { "id": "phase-03", "files": ["README.md"] }
  ],
  "files": null
}

Outside a phase (phax brief src/greet.ts in your own checkout), it carries files alone:

{ "$schema": "https://docs.phax.run/schemas/brief-request/0.20.0.json", "files": ["src/greet.ts"] }
  • phase, base, terminal and phases hold the same values as the phase's gate request.
  • files is null for the phase's brief (the pushed one, and phax brief with no path): brief the files of the phases entry whose id is phase. Otherwise it lists working-tree-root-relative paths, deduplicated, in the order given. phax never checks they exist; a path may name a file the phase has yet to create.

The provider runs from the working tree's root, the phase worktree inside a phase. It answers with a brief report:

{
  "$schema": "https://docs.phax.run/schemas/brief-report/0.21.0.json",
  "rules": [
    {
      "rule": "a module under src/ exports its function",
      "files": ["src/greet.ts", "src/farewell.ts"],
      "guide": null
    },
    {
      "rule": "a module under src/ imports no node: module",
      "files": ["src/greet.ts", "src/farewell.ts"],
      "guide": { "summary": "keep I/O in the module's caller", "read": "guides/no-node-import.md" }
    }
  ],
  "findings": [
    {
      "id": "no-node-import src/greet.ts node:fs",
      "rule": "a module under src/ imports no node: module",
      "location": { "file": "src/greet.ts", "lines": [1, 1] },
      "message": "imports node:fs",
      "related": [],
      "guide": { "summary": "keep I/O in the module's caller", "read": "guides/no-node-import.md" },
      "due": "this-phase"
    },
    {
      "id": "exports-function src/farewell.ts",
      "rule": "a module under src/ exports its function",
      "location": { "file": "src/farewell.ts", "lines": null },
      "message": "no exported function",
      "related": [],
      "guide": null,
      "due": "later"
    }
  ]
}
  • rules says what a file at the requested paths must or must not do, even a file not written yet: each rule with the requested files it covers (at least one) and its guide, or null.
  • findings says what fails at those paths. A finding has the keys of a gate report's finding (id, rule, location, message, related and guide), plus due.
  • due is "this-phase" or "later", from what the later phases entries still plan, and null when the request carried no phase facts. It is your word: phax never computes or checks it.
  • guide is a summary and a file to read, relative to the working tree, that the agent reads and follows. phax never opens it.
  • The order of each list is your rank, most important first; phax never re-sorts. Every key shown is required, and a key not shown is refused at any level: there is no outcome and no review note. { "$schema": …, "rules": [], "findings": [] } means nothing to report, and phax brief then prints No brief for ….
  • $schema names the brief-report shape the report is written in: the release that last changed the format. A report without $schema, naming another format, stamped newer than the running phax or in an older shape is refused by name, as is a finding id used twice or a lines pair out of order, and the refusal names the URL phax reads.

A provider that declines to run exits non-zero, with its reason on stderr. A brief that fails (a non-zero exit, output that is not JSON, a refused report, or more than 60 seconds; the limit is fixed) never fails the phase. A pushed brief becomes a run-output warning and a line in the prompt saying the brief is unavailable and why, with the provider's stderr; a pulled one prints the reason and exits 1.

Inside a phase, phax writes the phase's request to .phax-context/brief-request.json when the phase starts or resumes; phax brief reads its phase from there, from any directory of the worktree. Replay the phase's brief in the worktree:

node ./brief.mjs < .phax-context/brief-request.json

Every brief of a phase is recorded in its phase folder: brief-00.json for the pushed one, brief-01.json onwards for each pull, in call order. Each holds the request as sent and the outcome: the report as printed, every key in its printed order. The phase record carries them; phax records explain <commit> --briefs prints them. A pull after the phase's record is written is answered and not recorded. Replay a recorded brief:

jq -c .request brief-01.json | node ./brief.mjs

In secure mode the in-phase agent is granted phax brief (source brief in security.json) whenever a brief provider is configured, and a pull runs inside the agent's sandbox. Inside a phase worktree phax refuses every command but phax brief and the read-only ones, as a guard against mistakes; the sandbox's write scope is the boundary. The authoring --brief flag and docs/briefs/ are something else: a brief a person writes for an authoring session.

Architecture provider

An architecture provider tells a planner how the repository is built:

{ "architecture": { "command": "acme-guard architecture" } }

phax architecture [path]… prints the report the provider answers, the Markdown body then each part (id, name, description, globs), for the whole repository or the parts that hold the paths. When phax.json declares assignments, it then lists the bounds. With no provider configured it prints one line telling the agent to read the code and its documentation, followed by the bounds when declared, and exits 1; it writes nothing either way. A headless plan authoring session is told whether a provider is configured or bounds are declared, and is granted this command when either is. See Architecture provider for the request, the report and the limits a provider runs under.

Acceptance provider

An acceptance provider judges the two phases of an acceptance pair: the phase that writes the acceptance tests and the phase that passes them.

{ "acceptance": { "command": "node scripts/acceptance-verdicts.mjs" } }

At the gate of each of the two phases, after every configured step passed, phax runs the command (split on spaces, no shell, in the phase worktree, 120-second limit) and sends it an acceptance-request on stdin. The verdict is authored at the acceptance phase, where every test must carry the runner's expected-failure marker, and passed at the passing phase, which may only remove those markers; the request then also names the acceptance phase's commit. The provider answers a gate-report on stdout, judged like any report step: findings go to the fix loop, a refusal pauses the phase with exit 4, and a fix loop that runs out on a failing acceptance test exits 4 too. The request is saved as checks-attempt-NN.acceptance-request.json. When no provider is configured, phax plans lint reports an acceptance error on every acceptance phase and exits 1, and phax run and phax resume refuse the plan with exit 11; none of them spawns the provider. A committed acceptance phase is not reset, so when the passing phase shows that the acceptance test itself is wrong, correct it in the stopped phase (phax enter-phase <run> <phase>) and run phax resume <run> --yes --skip-acceptance: that phase's configured gate still runs, with the usual fix loop, its acceptance step is recorded skipped, and acceptance is then not among its verified surfaces or the run's. To review the acceptance tests before they are passed, hold the acceptance phases with phax run --hold acceptance: a correction to an acceptance test file is judged again with the authored verdict at the close (see Reviews inside an acceptance pair). phax knows no test framework: the provider does. See Acceptance phases for the formats, a worked example and how to write the plan. The phax repository carries a Vitest acceptance provider that compares syntax trees in examples/vitest-acceptance/, declared in its own phax.json as node examples/vitest-acceptance/main.mjs and shipped in no package: copy it and adapt it to your runner.

Assignment bounds

The repository's owner can bound which model, at which efforts, a phase takes where it touches certain files:

{
  "assignments": [
    {
      "kind": "part",
      "part": "core-decide",
      "model": "claude-opus-5-5",
      "effort": { "min": "medium", "max": "high" }
    },
    {
      "kind": "globs",
      "globs": ["src/*/schemas/**"],
      "model": "claude-sonnet-5-5",
      "effort": { "min": "medium", "max": "high" }
    }
  ]
}

A part bound names an architecture-report part by its id; a globs bound lists globs. The list is ordered and the first bound that matches any file a phase plans to touch governs it; with none, the policy default stands in. A phase that departs from its governing bound needs an **Assignment reason:** line: without one, phax plans lint reports an error and phax run / phax resume refuse with exit 11 before the run is named. assignments is accepted in phax.json only, and phax validate checks each bound against the routing catalog. See Assignment bounds.

Plan auditor

{ "planAuditor": { "command": "node ./audit-plan.mjs" } }

Reviews a plan's shape for phax plans lint (never during a run). It receives every phase's planned files, {"phases": [{"id", "files"}]} — nothing else leaves phax — and answers {"findings": [{"message", "phases": [...]}]}. Its findings are warnings; a provider that fails or takes more than 30 seconds becomes one warning saying why.

examples/hello-world/ has a gate report step, a brief provider and a plan auditor; the acceptance provider's example is examples/vitest-acceptance/. The architecture provider has none yet.