diff --git a/.claude/skills/check-spec/SKILL.md b/.claude/skills/check-spec/SKILL.md index d55e81bb9..fe9c8455e 100644 --- a/.claude/skills/check-spec/SKILL.md +++ b/.claude/skills/check-spec/SKILL.md @@ -1,6 +1,6 @@ --- name: check-spec -description: Check a feature or task spec as posted on GitHub, with a fresh context, before its approval box is ticked or its ready label is set — read the body, its parent or its tasks, the ADRs it names, the agent rules and the code it points at — and report contradictions, lines nobody could check, failure modes no line answers, overlapping tasks without a Depends on, and real-device lines with no slow-lane test, in a fixed block. Read-only. Use when spec-session reaches the end of technical or split mode, or when the user says "check the spec of #N". +description: Check a feature or task spec as posted on GitHub, with a fresh context, before its approval box is ticked or its ready label is set — read the body, its parent or its tasks, the ADRs it names, the agent rules and the code it points at — and report contradictions, lines nobody could check, failure modes no line answers, overlapping tasks without a Depends on, real-device lines with no slow-lane test, and terms a rule depends on that nobody defined, in a fixed block. Read-only. Use when spec-session reaches the end of technical or split mode, or when the user says "check the spec of #N". model: opus effort: high context: fork @@ -73,6 +73,13 @@ Report a finding for each of these, and nothing else: 5. **hardware.** A Done when line that needs a real simulator or emulator but does not say so in its own words ("on a Mac with an iOS runtime: ..."), or does not name the slow-lane test that proves it. +6. **undefined.** A term a grammar, parser, filter or match rule depends on + that the body uses but never defines with examples: "bare version", + "exact match", "a valid name". Two readers would build two rules from + it. A line that says behaviour stays "as today" or "unchanged" is one + when the change could still alter it: name the inputs `main` accepts now + (run the command or grep the parser) and say which of them the new rule + would reject or reinterpret. What a rule, an accepted ADR or `always-in-scope.md` already answers is not a gap. "Nothing shows the suite is green" is never a finding: CI proves it. @@ -85,7 +92,7 @@ End with exactly this block, nothing after it: ``` Issue: #N Checked: <#N and each task read> Findings: n -- [contradiction|unverifiable|failure-mode|overlap|hardware] # "" — . Evidence: +- [contradiction|unverifiable|failure-mode|overlap|hardware|undefined] # "" — . Evidence: Verdict: ready | fix first ``` diff --git a/.claude/skills/deliver/SKILL.md b/.claude/skills/deliver/SKILL.md index 75c94b287..08bf19285 100644 --- a/.claude/skills/deliver/SKILL.md +++ b/.claude/skills/deliver/SKILL.md @@ -28,17 +28,21 @@ A report without its block, or with narration in place of it, is not a result: invoke the skill again with the same arguments plus "the last run ended without its report block; report on the work already done". -**A person present or not.** If a person is in this session, show any text -you are about to post and ask before the slow lane runs. Unattended, post -directly and run the slow lane when the lock is free (rule 16). +**Ask once, then run.** A person in this session is asked at most one +question per run up front: whether the slow lane may run for every PR of +this run (rule 16). After that, do not stop to ask. Post PR bodies and +comments directly, merge every PR the gate accepts, and decide a round cap +by rule 14 without asking. Ask a person only for what parks an issue: they +may answer instead of reading the handoff. Unattended, nothing is asked: +the slow lane runs when the lock is free. **Park only for a person's decision.** A small gap in the spec is not a reason to stop: implement closes it the conservative way and lists it as an `Assumption:` line in the PR body, and the spec review checks it (rule 3). Park only for a contradiction with the body, a rule or an accepted ADR; for behaviour a user would see that nobody decided; for a real-device check -that cannot run; for a blocking finding still confirmed after round 2; or -for what the gate refuses (step 3). +that cannot run; for a blocking finding the review reports as open after +its last round (rule 14); or for what the gate refuses (step 3). ## 1. Take stock @@ -72,18 +76,18 @@ Claim it: `gh issue edit --add-assignee @me`. Its branch is 1. **Implement.** `implement` with `issue #N, branch /, mode build`. A report with `spec needs` under Open: park (step 6). -2. **Review and hardware, in parallel.** `review` with the PR number. If - implement reported Hardware lines, invoke `verify-hardware` in the - **same message**, with the PR, the branch and those lines, so both - check the commit implement pushed. With a person present, ask before - that message, since it starts the slow lane. -3. **Decide**, once both reports are in. - - Fix lines, or Hardware `fail`: one `implement` run in mode `fix` with - the Fix lines and the hardware Evidence lines pasted together. Then - round 2: `review` with `round 2` and the report's Rerun value (`code` - at least when only the hardware failed), and in the same message - `verify-hardware` again when the fix changed anything but docs. - - Spec needs, or a confirmed blocking finding after round 2: park. +2. **Review.** `review` with the PR number. +3. **Decide** on its report. + - Fix lines: one `implement` run in mode `fix` with the Fix lines + pasted. Then the next round: `review` with `round 2` (or `round 3`) + and the report's Rerun value. + - Spec needs, or a blocking finding the review reports as open with + `Rerun: none`: park. + - No Fix lines, and implement reported Hardware lines: `verify-hardware` + with the PR, the branch and those lines, on the commit the review + passed (rule 16). On `fail`: one `implement` fix run with the Evidence + lines, then `review` with `round 2` (or the next round) and `Rerun: +code`, and `verify-hardware` again on the commit that review passes. - Hardware `busy` or `unavailable`: finish the review rounds without it, do steps 4 and 5, run `gh pr ready `, add the `needs-hardware` label to the PR, and park instead of running the gate. The gate would @@ -139,6 +143,7 @@ build`. A report with `spec needs` under Open: park (step 6). .agents/scripts/merge-pr.sh ``` + Do not ask before this step: the gate is the check. Exit 0 merged it. Any other exit: park with the line it printed. An alive mutant implement could not explain also parks: the gate does not read the report, you do. @@ -164,7 +169,10 @@ gh api graphql -F owner="$OWNER" -F repo="$REPO" -F number= -f query=' Runnable means open, `task:ready`, and unassigned; the issue-state workflow only makes a task ready once everything under its Depends on is closed, so -readiness already encodes the order. Deliver up to two runnable tasks at +readiness already encodes the order. After a merge that workflow takes a +minute: watch its run (`gh run list --workflow "Issue state" --limit 1`, +then `gh run watch `) and list again, rather than diagnosing why a task +is not ready yet. Deliver up to two runnable tasks at once: invoke each stage for both in the same message, and keep the two pipelines apart. Each task has its own worktree, so they never share files. If both reach the hardware check at once, the second `verify-hardware` diff --git a/.claude/skills/implement/SKILL.md b/.claude/skills/implement/SKILL.md index e40960647..6b67ce431 100644 --- a/.claude/skills/implement/SKILL.md +++ b/.claude/skills/implement/SKILL.md @@ -84,7 +84,9 @@ as you go, so a resumed run sees it. Implement the smallest change that turns the next test green. Each commit lowers the failing count and says so in its body: `3 failing -> 1 failing`. Run `pnpm typecheck`, `pnpm lint` and the test files you touched before -each commit; the pre-commit hook runs the rest. Never pass `--no-verify`. +each commit; the hooks run the rest (format and lint on commit, `fallow` on +push). Never pass `--no-verify`. Push once per step, not after every commit: +the pre-push hook audits the whole branch. Build what `always-in-scope.md` lists as you go: both `EVENTS.md` files for a new or changed event; a search of `README.md`, `docs/` and every @@ -96,17 +98,40 @@ not in the spec becomes a `bug:new` issue or one line under Open. ## 5. Prove it +**Check your own tests first**, the way the reviewers will. For each test +you added or changed: + +- Its title, its assertions and its fixture state make the same claim. A + title naming two claims has an assertion for each. +- Break the code it covers once (flip the condition, drop the filter, return + early) and run that test file: it must fail on the assertion its title + names. Restore the code. A test that stays green is vacuous; fix it now. +- A test that compares two outputs fails when both are wrong in the same + way: assert one of them against a literal. + +If the diff changed a schema, a contract type or a validator, rerun the +tests of every surface that publishes it (MCP `tools/list`, HTTP error +bodies, CLI help) — a refinement can empty a published schema while every +unit test stays green. + +Then run the suite once: + ```bash pnpm check # typecheck, lint, format, unit, fast e2e pnpm mutate # mutants on the lines this branch changed ``` -`pnpm check` must pass. A failing test you did not touch: if an open -`flaky-test` issue names it (`gh issue list --label flaky-test --search -""`), list it under Flaky and move on. Otherwise apply testing rule -5: run it on the base commit; if it fails there too, open a `bug:new` issue -labelled `flaky-test` naming the test, and list it. Never skip, disable or -loosen a test. +`pnpm check` must pass. Run it once per round, after the last change, and +never start a second one while one runs. A failing test you did not touch: +if an open `flaky-test` issue names it (`gh issue list --label flaky-test +--search "<title>"`), list it under Flaky and move on. Otherwise apply +testing rule 5 to that one file: run `pnpm vitest run <file>` in a worktree +of the base commit (`git worktree add <scratch>/base origin/main`), up to +three times. If it fails there, open a `bug:new` issue labelled +`flaky-test` naming the file, the title and the error line, list it, and +move on. If it never fails there, it is yours. Do not stash your work or +re-run the whole suite or the whole e2e project to decide. Never skip, +disable or loosen a test. Every mutant `pnpm mutate` reports alive is a line you can change or delete with a green suite. Write the test that kills it, or delete the line if it @@ -124,7 +149,8 @@ behaviour, write the test that fails first, then the fix; for a stale doc or comment, just fix it. A line ending in `(record as Assumption: ...)` also adds that assumption to the PR body. A hardware Evidence line is a failing slow-lane test: fix the code, not the test. One commit per finding or per -closely related group. Then step 5 again. +closely related group. Then step 5 again, including the self-check on every +test the fix touched: a fix that leaves a test vacuous costs a review round. ## Report diff --git a/.claude/skills/review/SKILL.md b/.claude/skills/review/SKILL.md index c81a0a960..4f744a32a 100644 --- a/.claude/skills/review/SKILL.md +++ b/.claude/skills/review/SKILL.md @@ -20,7 +20,7 @@ The two reviewers are the `spec-reviewer` and `code-reviewer` agents in This skill runs on Opus too: verifying decides whether a reviewer's claim is real, and a wrong rejection merges a defect nobody else will catch. -Arguments: a PR number, optionally `round 2` and which review to re-run +Arguments: a PR number, optionally `round 2` or `round 3` and which review to re-run (`spec`, `code`, or `both`). With a branch instead of a PR, find its PR with `gh pr list --head <branch>`. If the PR is not a delivery PR (a person's PR the maintainer asked about), post the findings as one comment @@ -61,7 +61,11 @@ calls with `run_in_background: false`: `subagent_type: "spec-reviewer"` and `subagent_type: "code-reviewer"`. Never pass a model: it overrides the agent's frontmatter. They run in parallel, and your turn cannot end while they run, so you never hand back -before the findings are in. On `round 2`, spawn only the review named. +before the findings are in. If a reviewer's result is missing or has no +findings block (it says it is still working, or it hands back narration), +send that same agent a message asking for its findings block and wait for +it; never report a review as missing or end your turn while one is out. +On `round 2` or `round 3`, spawn only the review named. **Spec review.** Read-only. It reads every file in `$R` except `rules/`. Brief, verbatim, with the paths filled in (leave out the sentence for a @@ -220,16 +224,19 @@ behaviour: then it is Spec needs. ## 4. Decide what runs again A confirmed blocking finding changes the diff, so the review that raised it -runs again on the next round. Notes never start a round. After round 2 -there is no third: a blocking finding still confirmed is reported as open, -and the orchestrator parks the issue. +runs again on the next round. Notes never start a round. After round 2, a +third round runs only when every confirmed blocking finding is a test that +cannot fail for the reason its title gives, or a stale doc or comment +(delivery rule 14); say so with `Rerun:` naming the review. Otherwise, and +always after round 3, a blocking finding still confirmed is reported as +open, and the orchestrator parks the issue. ## 5. Report End with exactly this block, nothing after it: ``` -PR: #M Round: 1 | 2 Kind: code | adr-only +PR: #M Round: 1 | 2 | 3 Kind: code | adr-only Spec review: n findings (b blocking) | skipped Code review: n findings (b blocking) | skipped Fix: <one confirmed blocking finding per line, as `path:line what is wrong`, or "none"> Notes: <one per line, `spec|code: path:line what could be better`, or "none"> diff --git a/.claude/skills/spec-session/SKILL.md b/.claude/skills/spec-session/SKILL.md index 57c64b26a..bb56fee33 100644 --- a/.claude/skills/spec-session/SKILL.md +++ b/.claude/skills/spec-session/SKILL.md @@ -94,7 +94,8 @@ questions remain; the feature does not leave `feature:spec` until it is empty. **`technical`** (feature delivered as one PR): fill the Technical spec section. Before writing it, ask whether any decision here constrains more than one future change or would be expensive to reverse. Each such decision -becomes an ADR: draft it in `docs/internal/adr/` at status _Proposed_ on a branch, and +becomes an ADR: draft it in `docs/internal/adr/` at status _Proposed_ on a branch, +with the diagrams `docs/internal/adr/README.md` asks for, and add its line to Decisions. Tell the maintainer the feature cannot leave `feature:spec` until that ADR is accepted. Write only what `docs/internal/agent-rules/always-in-scope.md` does not already cover. The @@ -125,8 +126,9 @@ gh api graphql -F parent="<feature node id>" -F child="<task node id>" -f query= Get a node id with `gh issue view <n> --json id -q .id`. Run the spec check (step 5) on the feature, which reads every task you created. Then remove the -Technical spec section from the feature body, add a Tasks section listing the -sub-issues in order, and change the label: +Technical spec section from the feature body, add the Tasks section the +feature template describes (the order as a diagram, then one entry per task +with what it changes for the user and its risk), and change the label: ```bash gh issue edit <feature> --add-label feature:planned --remove-label feature:spec @@ -144,6 +146,36 @@ in `task:draft`. **`revise`**: only the reconcile step plus whatever amendments it produced. +**Make it easy to follow.** The maintainer approves what they understand, +so explain before you ask, and show before you explain: + +- Open every question with the picture it is about: a Mermaid flowchart or + sequence diagram of the flow today and the flow proposed, or a before and + after example of the command and its output. Then ask, with your + recommended answer and one line on what each option costs. +- Use the words a user of the tool would use. The first time a term from + the code, an ADR or a rule appears, say what it means in plain words with + an example, and add it to the body's Words used section. Never cite a + rule or ADR number as the reason for something; say the reason. +- Keep each question to one decision and about five lines plus its + picture. If it does not fit, split it. Context the maintainer may not + have gets three lines or fewer. +- When a rule accepts, rejects or matches input, show a table of example + inputs with today's result and the proposed one, odd cases included, and + check today's column by running the tool on `main`. +- Before writing the body, play the result back: the user flow diagram, + the example, and a list of what will and will not change. Write only + after the maintainer says it matches what they meant. +- In a Technical spec, draw what the change touches: a Mermaid dependency + flowchart of the modules involved (changed ones marked), and a Mermaid + sequence diagram for any request that crosses a process or a network + hop, failure reply included. Use the same diagrams when you ask a + technical question. +- In the body, fill "How it works for the user", "Examples", "What could + go wrong" and "Words used" (feature) or "In short" (task) as the template + says. A diagram has at most about + ten boxes; split a bigger flow. + Write the spec the way rule 12 asks for everything else: short sentences, common words, one idea per sentence. A spec is read by an agent that will build exactly what it says, so every sentence that does not constrain the diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 86558c37c..52c0f5212 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -9,6 +9,14 @@ accepted. Numbers are never reused, and an ADR is never edited to say something different — a decision that changes gets a new ADR that supersedes the old one, and the old one's Status is updated to point at it. +Show the decision, not only describe it. Where it helps the reader, add +Mermaid diagrams: a flowchart of the modules or processes involved and how +they depend on each other, before and after the decision; a sequence +diagram of a request or flow the decision changes, failure paths included; +a state diagram when it changes the states a lease, device or worker can +be in. Each diagram has at most about ten boxes, and the text still states +the decision on its own. + Status values: - **Proposed** — under discussion, not binding. diff --git a/docs/internal/agent-rules/delivery.md b/docs/internal/agent-rules/delivery.md index 05eb34273..20469f0bd 100644 --- a/docs/internal/agent-rules/delivery.md +++ b/docs/internal/agent-rules/delivery.md @@ -254,9 +254,13 @@ is open, done means closed as completed. what was overruled and by whom. Accepted findings are not narrated. Notes are not verified and never start a round: after the last round they go out once, as one comment on the PR, or as a `bug:new` issue when - one is a separate piece of work. Two rounds at most: a blocking finding - still confirmed after the second round means the agent stops and hands - off with the finding under Findings (rule 2), leaving the PR in draft. A + one is a separate piece of work. Two rounds, and a third only when every + blocking finding still confirmed after the second is a test that cannot + fail for the reason its title gives, or a stale doc or comment: those + have one obvious fix and need no person to decide. Any other blocking + finding still confirmed after round 2, or any after round 3, means the + agent stops and hands off with the finding under Findings (rule 2), + leaving the PR in draft. A PR from a person gets the same two reviews when the maintainer asks for them. @@ -275,11 +279,12 @@ is open, done means closed as completed. two lanes at once produce timeouts that look like bugs. Agents run it only through `scripts/slow-e2e.sh`, which holds a machine-wide lock, runs detached so no tool time limit kills it halfway, and logs to a - file. It runs beside the two reviews, on the commit they review, not - after them. A failure joins the review's fixes in one fix run, and when - that run changed more than docs, the lane runs again beside the second - round. With a person present the agent - asks before starting it. Unattended, it runs when the lock is free; when + file. It runs once per PR, on the commit the last review round passed + (no blocking finding open), so review fixes do not each cost a lane run. + A failure gets one fix run, then the lane and the code review run again + on the new commit. With a person present the agent asks once per + delivery run, before the first lane, and that answer covers every PR in + the run. Unattended, it runs when the lock is free; when the lock stays busy or the machine has no devices, the PR gets `needs-hardware` and waits for the maintainer. diff --git a/docs/internal/templates/feature.md b/docs/internal/templates/feature.md index e78de9019..c05175ea8 100644 --- a/docs/internal/templates/feature.md +++ b/docs/internal/templates/feature.md @@ -21,6 +21,36 @@ Request: #NNN <!-- or "none" when the maintainer originated it --> <!-- What they can do after this lands that they cannot do now. Observable behaviour only. --> +## How it works for the user + +<!-- A Mermaid flowchart or sequence diagram of what the user does and sees, +step by step, including the failure paths. GitHub renders ```mermaid +blocks. Then the user's session: the exact commands a user types and what +the tool prints back, before this feature and after it, error output +included. --> + +## Examples + +<!-- For any rule that accepts, rejects or matches input: a table of inputs +and results, with today's result beside the new one, so a changed answer is +visible. Include the odd cases (names, ranges, empty, unknown). + +| Input | Today | After | +|---|---|---| +| `--os 18.4` | accepted | accepted | +| `--os Baklava` | accepted | accepted | --> + +## What could go wrong + +<!-- Two to five plain lines: what a user would notice if this goes wrong, +and how likely it is. No code terms. --> + +## Words used + +<!-- Every term this spec relies on that a newcomer would not know, or that +a rule depends on, one line each with an example: "bare version: an OS +version with no range, e.g. `--os 18.4`". "none" if there are none. --> + ## Non-goals <!-- What this feature deliberately does not do, so nobody scopes it back in. --> @@ -42,6 +72,18 @@ an end-to-end test can verify against main. --> - ADR NNNN — <title>: <one line on what it fixes for this feature> +## Tasks + +<!-- Added when the feature is split; replaces the Technical spec. First a +Mermaid flowchart of the tasks in the order they depend on each other. Then +one entry per task, in that order: + +- #NNN <title> — <one plain sentence: what the user can do after it>. + Risk: <what a user would notice if it goes wrong>. + +Do not write task states here: GitHub's sub-issue list shows them and +stays current. --> + ## Technical spec <!-- Only for a feature delivered as one PR. Delete this section when the @@ -49,6 +91,12 @@ feature is split into tasks. --> ### Modules touched +<!-- A Mermaid flowchart of the modules this changes and the ones they call, +changed ones marked, arrows pointing from caller to callee. When the change +crosses a process or a network hop (CLI, daemon, driver, gateway, worker, +HTTP or MCP client), add a Mermaid sequence diagram of one request through +it, including the failure reply. Skip a diagram that would show one box. --> + ### Contract and event changes <!-- Every new or changed event needs its EVENTS.md entry named here. --> diff --git a/docs/internal/templates/task.md b/docs/internal/templates/task.md index 7e94e4899..c9b6b7461 100644 --- a/docs/internal/templates/task.md +++ b/docs/internal/templates/task.md @@ -11,10 +11,26 @@ Part of #NNN. <!-- The slice of the parent's outcome this task delivers: what a user can do after this PR merges that they could not after the previous one. --> +## In short + +<!-- Two or three plain sentences: what changes for the user after this PR, +then a small Mermaid diagram of the flow it touches, with the changed step +marked. Define any new term here with an example. When the task changes +what input is accepted or what the tool prints, add the user's session +(commands and output, before and after) and an inputs table with today's +result beside the new one. End with one line: what a user would notice if +this task goes wrong. --> + ## Technical spec ### Modules touched +<!-- A Mermaid flowchart of the modules this changes and the ones they call, +changed ones marked, arrows pointing from caller to callee. When the change +crosses a process or a network hop (CLI, daemon, driver, gateway, worker, +HTTP or MCP client), add a Mermaid sequence diagram of one request through +it, including the failure reply. Skip a diagram that would show one box. --> + ### Contract and event changes <!-- Every new or changed event needs its EVENTS.md entry named here. --> diff --git a/lefthook.yml b/lefthook.yml index af07bcacd..feb31d14f 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -10,7 +10,11 @@ pre-commit: glob: "*.{ts,tsx,js,mjs,mts,cts}" run: pnpm exec oxlint {staged_files} fail_text: "Run 'pnpm lint' to fix lint errors." + +# fallow audits the whole branch against main and takes minutes, so it runs +# once per push rather than on every checkpoint commit. +pre-push: + commands: fallow: - glob: "*.{ts,tsx,js,mjs,mts,cts}" - run: pnpm exec fallow audit --base HEAD --format compact + run: pnpm exec fallow audit --base origin/main --format compact fail_text: "Fallow found issues in your changes. Run 'pnpm fallow' to see details."