# delivery-2: turning intent into Claude Code work

Two labs for the session page `delivery/02-intent.html`, covering the specifications, decomposition and evaluation topics. Both run offline by default: deterministic rules, no model, no network, no `claude` binary. Output goes to `delivery-2/out/`.

| Lab | What you build | Run (from `labs/`) |
|---|---|---|
| `brief_lint.py` | A brief linter for agent work. It checks that the done condition is `/goal`-checkable, that the acceptance criteria are observable, and that the brief has negative examples and boundaries. It maps each boundary to the control that enforces it, writes an `AskUserQuestion`-shaped interview, and gives you a ready `/goal` line. | `python3 delivery-2/brief_lint.py` |
| `plan_review.py` | A plan reviewer. It builds a criteria × steps coverage matrix and checks for verification commands, forbidden paths, files that don't exist, scope creep and vague steps. It picks an option at plan mode's approval prompt and writes the "No, keep planning" feedback. | `python3 delivery-2/plan_review.py` |
| `test_brief_lint.py` | Rule tests for both labs: 24 `unittest` cases, including the `/goal` docs' own example conditions. | `python3 delivery-2/test_brief_lint.py` |

Inputs live in `samples/`. They describe one tiny-app change: making discount codes case-insensitive (the `TODO` at `tinyapp/pricing.py:29`).

- `strong_brief.md`: a delegable brief with intent, existing behavior, a done condition, AC1–AC5, negative examples, boundaries, context and evidence.
- `weak_brief.md`: the same request the way it often arrives.
- `plan_good.md`: a plan that serves AC1–AC5 and stays inside the allowed files.
- `plan_drifting.md`: a plausible refactor that breaks the brief in five different ways.

## brief_lint.py

```bash
python3 delivery-2/brief_lint.py                                   # both samples, then a comparison
python3 delivery-2/brief_lint.py my_brief.md --fail-under 80       # CI mode: exit 1 below 80
python3 delivery-2/brief_lint.py my_brief.md --json --max-questions 2
```

The done-condition rules come from the `/goal` docs (https://code.claude.com/docs/en/goal). After each turn a small fast model checks the condition, and it "doesn't run commands or read files independently". So the condition needs:

- one measurable end state
- a stated check, such as "`npm test` exits 0"
- the constraints that must not change
- optionally a bound, such as "or stop after 20 turns"

It can be up to 4,000 characters.

Excerpt from a real run (`NO_COLOR=1 python3 delivery-2/brief_lint.py delivery-2/samples/weak_brief.md`):

```text
  score: 0/100  ······························  not delegable yet
  findings: 13 high, 9 medium, 3 low
[1] Findings (line, rule, severity)
line  rule  sev     finding
6     S1    high    no acceptance criteria section; the Requirements items are graded as criteria below
...
7     X3    high    contradiction (case): line 7 says 'Case-insensitive', line 10 says 'Case-sensitive'
...
13    G2    high    no stated check: the condition names no command whose output proves it
13    G3    high    no measurable end state (exit code, test result, count, empty queue)
13    G4    high    'code is clean' can't be judged from the conversation: the /goal evaluator doesn't run commands or read files
13    G4    high    'everything works' can't be judged from the conversation: the /goal evaluator doesn't run commands or read files
17    B1    high    boundaries name no file or directory
17    X3    high    contradiction (dependencies): line 18 says 'No new deps', line 17 says 'Add a library'
...
[4] Interview: 4 AskUserQuestion question(s)
  [Conflict] The brief contradicts itself: line 7 says 'Case-insensitive', line 10 says 'Case-sensitive'. Which wins?
      - Case-insensitive: Keep this; delete the other line from the brief
      - Case-sensitive: Keep this; delete the other line from the brief
  [Conflict] The brief contradicts itself: line 18 says 'No new deps', line 17 says 'Add a library'. Which wins?
      ...
  [Done when] What single check proves this brief is done?
      - Suite exits 0: `python3 -m unittest` exits 0 and Claude pastes the output
      ...
  [Scope] Which files may Claude edit for this change?
      ...
  payload valid: 1-4 questions, 2-4 options, headers <= 12 chars
```

The interview is written to `out/interview_weak_brief.json` in the `AskUserQuestionInput` shape (`questions[].question`, `header`, `options[].label`/`description`, `multiSelect`), and the lab checks the documented limits before printing it. To use it, start a session and ask: "Interview me with AskUserQuestion using `delivery-2/out/interview_weak_brief.json`, then rewrite the brief."

The strong brief scores 100, yet the enforcement map shows that brief text alone enforces nothing:

```text
[3] Boundaries -> the control that enforces them (brief text alone is advisory)
  L 27  Only edit `tinyapp/pricing.py` and `tests/test_pricing.py`.
        -> PreToolUse hook (matcher `Edit|Write|Bash`) that denies paths outside: tinyapp/pricing.py, tests/test_pricing.py. Edit|Write alone never sees shell writes (sed -i, redirects, tee, scripts), and a hook can't parse every command, so keep the `git diff --stat` check in the done condition as the backstop. PostToolUse `tool_response.bashEditDiff` (v2.1.269+) can show which files a Bash command changed, but it's best effort and, by default, recorded only in auto and bypassPermissions mode (`bashEditDiffEnabled: true` in user, managed or --settings JSON records it in every mode); the docs say to use it to find what to review, not to enforce a policy
  L 28  Never edit the `TAX_BPS` values.
        -> no permission rule can see content (`TAX_BPS`): pin it with a test, or check it in a PostToolUse/Stop hook
  L 30  Ask before changing the public API in `tinyapp/__init__.py`.
        -> permissions.ask: Edit(/tinyapp/__init__.py) (ask rules prompt even in auto mode)
[5] /goal condition
  /goal `python3 -m unittest` exits 0, `tests/test_pricing.py` has a new test that applies `welcome10` and `Vip25`, and `git diff --stat` lists only `tinyapp/pricing.py` and `tests/test_pricing.py`. Show both outputs. No other test file is modified. Or stop after 15 turns and report what is left.
  headless, in a scratch copy or a worktree: claude -p "$(cat delivery-2/out/goal_strong_brief.txt)" --permission-mode acceptEdits --allowedTools "Bash(python3 -m unittest *)" "Bash(git diff *)" --output-format stream-json --verbose --max-turns 30 --max-budget-usd 2
  (--max-turns counts tool-use turns and is the hard backstop; the condition's own 'or stop after N turns' clause is the bound the evaluator judges.)
```

In project settings, `/path` permission rules anchor at the primary working directory (https://code.claude.com/docs/en/permissions). `/goal` doesn't change the permission mode. It is unavailable when `disableAllHooks` or `allowManagedHooksOnly` applies, because the evaluator is part of the hooks system.

## plan_review.py

```bash
python3 delivery-2/plan_review.py                                       # both sample plans vs the strong brief
python3 delivery-2/plan_review.py --plan ~/.claude/plans/<file>.md --brief my_brief.md --repo .
python3 delivery-2/plan_review.py --strict                              # exit 1 if any verdict is "No, keep planning"
python3 delivery-2/plan_review.py --real --model haiku --max-budget-usd 0.25   # costs money; see below
```

Excerpt from a real run (`NO_COLOR=1 python3 delivery-2/plan_review.py`):

```text
[2] Coverage matrix (v = maps and has a check command, o = maps without a command, x = contradicts it)
criterion  S1  S2  S3  S4  S5
AC1        v   o   .   .   .
AC2        v   o   .   .   .
AC3        v   .   .   .   .
AC4        .   .   v   .   .
AC5        .   .   .   v   .
[4] Verdict
  Yes, and use auto mode
```

```text
│ Plan review · delivery-2/samples/plan_drifting.md │
[2] Coverage matrix (v = maps and has a check command, o = maps without a command, x = contradicts it)
criterion  S1  S2  S3  S4  S5  S6
AC4        .   x   .   .   .   .
[3] Findings
P1    high    S2    changes `DISCOUNTS`, which the brief rules out (negative example, AC4)
P2    high    S4    edits tinyapp/discounts.py, outside the files the brief allows (tinyapp/pricing.py, tests/test_pricing.py)
P3    high    S4    edits tinyapp/discounts.py, which doesn't exist in the repo
P1    high    S5    changes `TAX_BPS`, which the brief rules out (boundary)
P2    medium  S3    edits tinyapp/__init__.py; the brief says to ask before changing it
[4] Verdict
  No, keep planning
  Feedback to type after choosing it:
    - No step implements AC1, AC2, AC3, AC4, AC5. Add a step for each, with the command that checks it.
    - Add a verification step with the exact test command, and paste its output when done.
    - Step 2: it changes `DISCOUNTS`, which the brief rules out (negative example, AC4): drop or rework it; 'while I'm in there' is vague: say exactly what changes and how you'll check it.
```

Identifiers match case-sensitively. `DISCOUNTS` (the dict) conflicts with the negative example, while a class named `Discounts` doesn't.

### Real mode

`--real` sends the strong brief to `claude -p` with `--permission-mode plan` and read-only tools (`--tools Read,Grep,Glob`, MCP and hooks off) in a temp copy of tiny-app, then reviews the plan it returns. The real-mode harness is `common/cc.py`. Every run saves its stream-json to `out/plan_real.jsonl` and prints the per-model cost from `modelUsage`.

A recorded real run (2026-10-20, Claude Code v2.1.303, `--model haiku --max-budget-usd 0.05 --max-turns 6`) didn't get as far as a plan:

```text
[real] asking Claude Code for a plan in plan mode (read-only tools, max 6 turns, $0.05 cap)
[real] This run calls the model through your Claude Code login and costs money: capped at $0.05 (client-side estimate) and 6 turns. Working dir: /var/folders/.../cc-lab-qvokh2kb/tiny-app
error: the run returned no plan text (see subtype above; try a higher --max-turns)
  run: error_max_budget_usd, 4 turns, $0.0586 (client-side estimate)
```

(stderr and stdout interleaved as captured. The script now flushes stdout first, so the error comes last.)

The run stopped on the budget and reported `subtype: error_max_budget_usd`. The cap is checked against a client-side estimate, so the run passed it by about one response ($0.0586 against $0.05). That run predates the transcript saving and per-model breakdown, and it printed the generic hint shown above. The script now names the cap that stopped the run (`raise --max-budget-usd`). Plan-mode runs cost more than the read-only exploration in delivery-1 ($0.0037), so the documented example now uses `--max-budget-usd 0.25`. The success path (plan extraction, then review) was checked offline against a stand-in `claude` that prints documented stream-json, and in `test_brief_lint.py` against the common fixtures.

## Docs

- `/goal`: https://code.claude.com/docs/en/goal
- `AskUserQuestion`: https://code.claude.com/docs/en/agent-sdk/user-input and https://code.claude.com/docs/en/agent-sdk/typescript
- Plan mode and its approval options: https://code.claude.com/docs/en/permission-modes
- Best practices (interview, then spec, then a fresh session; give Claude a check to run; ask for evidence): https://code.claude.com/docs/en/best-practices
- Permission rules: https://code.claude.com/docs/en/permissions
- CLAUDE.md is context, not enforcement: https://code.claude.com/docs/en/memory
- Headless runs: https://code.claude.com/docs/en/headless
