Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .agents/scripts/ci-failures.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node
// `node .agents/scripts/ci-failures.mjs <pr>`: the tests that failed in the newest finished run
// of each workflow on the PR's branch. A push cancels the run before it, so while pushes come
// faster than CI the head's own checks stay pending and only an older run shows a failure.
//
// Prints `none`, or for each workflow whose newest finished run failed: `<workflow> run <id> at
// <sha>`, then one indented line per failed test (`<file> > <title>`), or per failed job when
// its log names no test.
import { execFileSync } from "node:child_process";

const pr = process.argv[2];
if (pr === undefined) {
console.error("usage: ci-failures.mjs <pr>");
process.exit(2);
}
const gh = (...args) =>
execFileSync("gh", args, { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 });
// GitHub's stored logs spell the escape byte as the two characters `^[`.
const ANSI = new RegExp(`(?:${String.fromCharCode(27)}|\\^\\[)\\[[0-9;]*m`, "g");

const branch = JSON.parse(gh("pr", "view", pr, "--json", "headRefName")).headRefName;
const runs = JSON.parse(
gh(
"run",
"list",
"--branch",
branch,
"--limit",
"100",
"--json",
"databaseId,workflowName,headSha,conclusion,createdAt",
),
);

const newest = new Map();
for (const run of runs) {
if (run.conclusion !== "success" && run.conclusion !== "failure") continue;
const seen = newest.get(run.workflowName);
if (seen === undefined || run.createdAt > seen.createdAt) newest.set(run.workflowName, run);
}

const failed = [...newest.values()].filter((run) => run.conclusion === "failure");
if (failed.length === 0) console.log("none");
for (const run of failed) {
const id = String(run.databaseId);
console.log(`${run.workflowName} run ${id} at ${run.headSha.slice(0, 7)}`);
const tests = new Set();
for (const line of gh("run", "view", id, "--log-failed").split("\n")) {
const plain = line.replace(ANSI, "");
if (!/ FAIL |\) \[[a-z]+\] › /.test(plain)) continue;
const test = /(?:e2e|src|ui)\/[\w./-]+\.(?:test|spec)\.tsx?.*/.exec(plain);
if (test !== null) tests.add(test[0].trim());
}
const lines =
tests.size > 0
? [...tests]
: JSON.parse(gh("run", "view", id, "--json", "jobs"))
.jobs.filter((job) => job.conclusion === "failure")
.map((job) => `job ${job.name}`);
for (const line of lines) console.log(` ${line}`);
}
28 changes: 25 additions & 3 deletions .claude/agents/comment-reviewer.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
---
name: comment-reviewer
description: The blind comment review from delivery rule 14 — checks each comment in reach of a diff against the comment rule. Spawned only by the reviewer agent, which passes the brief, the rule, the comment list and a worktree.
description: Checks each comment in reach of a diff against the comment rule (architecture rule 17) — the blind comment review from delivery rule 14, and the implementer's audit sweep. Spawned by the reviewer agent or the implementer with `rules`, `comments` and `worktree`.
model: haiku
tools: Read, Grep, Glob
---

You are the comment reviewer. Follow the brief you are given exactly: read
only the worktree and files it names, edit nothing, and report in its form.
You are checking comments against one rule. You have no other context and
have not seen the issue the diff implements.

Arguments: `rules`, the rules directory; `comments`, the output of
`.agents/scripts/comments.mjs`: each block is a comment the diff adds or
edits, or one within 20 lines of code it adds, followed by the code line
after it (`>`); `worktree`, the repository at the commit under review.

The rule is rule 17 in `<rules>/architecture.md`. Read the worktree only to
see what a comment sits on, or whether a declaration is exported from an
entry point the rule names. Edit nothing and run nothing.

For each block, one line: `path:line keep <the why, at most 8 words>` or
`path:line F<n>`. A block stays only when the rule allows all of it. A block
or part of a block the rule does not allow is blocking, class `architecture
17`.

Output only your list, then your findings: no preamble, no headings, no
summary, no narration. Report every finding; there is no limit on how many.
One line per finding, in this form and no other:

F<n> B <path:line> <the part the rule does not allow, at most 25 words> [architecture 17]

No findings: `F0`.
33 changes: 21 additions & 12 deletions .claude/agents/implementer.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ states the failing count: `3 failing -> 1 failing`.
changed unit tests, and the e2e files you added or edited. Never run a
check listed under "Checks agents never run", nor a tool behind it, from
any path. A type or lint error shows in the commit hook's output.
- Push once per step, not after every commit, in the background, and read
its output when it ends. The last push before your report runs in the
foreground, with the longest timeout your shell tool allows: never end
your turn while a push runs. Never pass
`--no-verify` or `-n`.
- Each push runs the push hook, mutation testing included, for minutes.
Push when you need its output (the mutants left alive), and once before
your report; commits save progress, pushes do not need to. A push you
need nothing from yet runs in the background. The last push before your
report runs in the foreground, with the longest timeout your shell tool
allows: never end your turn while a push runs. Read its whole output,
not a tail. Never pass `--no-verify` or `-n`.
- Never wait on CI: no polling `gh pr checks`, no `gh run watch`, no
`sleep` loops. Read `gh pr checks <M>` at most once, before the report.
`sleep` loops. Run `node .agents/scripts/ci-failures.mjs <M>` at most
once, before the report: `none` is `ci: pass`, a failed test `ci: fail`.
- Never use `git stash`: all worktrees share one stash list. Commit instead.
Temporary files go in your scratchpad, not `/tmp`.
- Build what `always-in-scope.md` lists as you go. Anything else you notice
Expand Down Expand Up @@ -143,10 +146,14 @@ built.
other spellings, other paths, other import or call forms, empty and
boundary values. Each one it lets through gets a fixture or an `open`
line.
- **Commented.** Run `node .agents/scripts/comments.mjs origin/main`: it
lists every comment the diff adds or edits, and every comment within 20
lines of code it adds. Delete each one the comment rule in
`architecture.md` does not allow.
- **Commented.** Write the output of this to your scratchpad (in fix
mode, with the head you started from in place of `origin/main`):
`node .agents/scripts/comments.mjs origin/main`. It lists every comment
the diff adds or edits, and every comment within 20 lines of code it
adds. Hand it to a `comment-reviewer` agent with
`rules: docs/internal/agent-rules`, `comments: <that file>` and
`worktree: <your worktree>`. Delete each part it flags; never reword one
into a new comment.
- **Promised.** For every Scope and Done when line, name the hunk or test
that delivers it. None: do it, or leave the line unticked and say why
under `open`. Never tick a box on intent.
Expand Down Expand Up @@ -202,8 +209,10 @@ the rule it breaks.
2. **Fix every instance:**
- behaviour: write the failing test first, then the fix;
- stale doc: fix it. Stale comment: delete it, or fix it if the comment
rule allows it. Told to edit comments and docs only:
a finding that needs any other change goes under `open` instead;
rule allows it. Each fact in the new text (who does it, which cases,
which values) names the `path:line` that shows it before you commit;
a fact you cannot point to stays out. Told to edit comments and docs
only: a finding that needs any other change goes under `open` instead;
- a line ending in `(record as Assumption: ...)`: also add that
assumption to the PR body;
- a slow-lane Evidence line is a failing test: fix the code, not the
Expand Down
30 changes: 8 additions & 22 deletions .claude/agents/reviewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ and wait. Never report a review as missing.

Each brief below is passed verbatim, paths filled in; leave out a sentence
about a file that does not exist. Every brief ends with the **common tail**.
From round 2, every brief starts with the **re-review head**.
From round 2, every brief starts with the **re-review head**. The comment
review brings its own brief.

**Re-review head** (round 2 and later, every review but the comment
review):
Expand Down Expand Up @@ -252,34 +253,19 @@ file: `path: 12 34-40 true, 56 F3`:
and the doc comment of every declaration the diff changes.

Find them all now: a false claim this round misses costs a later round.
Whether a comment should exist at all (rule 17 in architecture.md) is the
comment review's: judge only whether it is true.

A claim is false when the code at this commit contradicts it: a name or
path that no longer exists, a behaviour, order, owner, default or limit that
changed. Blocking: a false claim. Note: a claim that is true but misleading.
```

**Comment review**: `subagent_type: "comment-reviewer"`, in the claims
worktree. It reads `$R/rules/architecture.md` and `$R/comments.txt`; from
round 2, `$R/comments-fix.txt` in its place.
**Comment review**: `subagent_type: "comment-reviewer"`, with
`rules: $R/rules`, `comments: $R/comments.txt` (from round 2,
`$R/comments-fix.txt`) and `worktree:` the claims worktree. Nothing else.

```markdown
You are checking comments against one rule. You have no other context and
have not seen the issue the diff implements.

Rule: rule 17 in <rules/architecture.md>. Comments: <comments.txt>: each
block is a comment the diff adds or edits, or one within 20 lines of code it
adds, followed by the code line after it (`>`). Repository: <worktree>,
checked out at the reviewed commit: read it only to see what a comment sits
on, or whether a declaration is exported from an entry point the rule
names. Edit nothing and run nothing.

For each block, one line: `path:line keep <the why, at most 8 words>` or
`path:line F<n>`. A block stays only when the rule allows all of it. A block
or part of a block the rule does not allow is blocking, class `architecture
17`.
```

**Common tail** (every brief):
**Common tail** (every brief but the comment review's):

```markdown
Output only your list, then your findings: no preamble, no headings, no
Expand Down
12 changes: 8 additions & 4 deletions .claude/skills/deliver/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ they name; never build again or restart review at round 1.
`failing` and turned at least one test green since the last, another
`green` with its `map`; then `mode: audit`. `spec needs` under `open`
in any report: park (step 6).
2. **Review**: `reviewer` with the PR number. Before every review round,
read `gh pr checks <M>` and `gh pr view <M> --json mergeable` once. A
failed check no open `flaky-test` issue names, or a conflict, goes into
one `implementer` fix run first.
2. **Review**: `reviewer` with the PR number. Before every review round
and every fix run, run `node .agents/scripts/ci-failures.mjs <M>` and
`gh pr view <M> --json mergeable` once. The script reads the newest
finished CI run, which is often older than the head: newer pushes cancel
theirs. Each failed test no open `flaky-test` issue names joins the fix
run's `fixes` as `ci: <its line> run <id>`, and a conflict as a line
asking to merge the base branch. With no fix run due, they get one
before the round.
3. **Decide** on the review report:
- Fix lines: one `implementer` run with `mode: fix` and the Fix lines
pasted under `fixes`, then the next round: `reviewer` with `round <n+1>`, the
Expand Down
13 changes: 9 additions & 4 deletions docs/internal/DELIVERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ agent per phase, so no context grows past one phase: one commits the spec's
tests red and opens a draft PR, so CI runs from the first push; the next
turns them green in commits that each lower the failing count, starting
from a map of which files each test needs; the last audits the diff with
fresh eyes. Agents pass each other `key: value` lines, not prose. It
fresh eyes, and has the comment reviewer below sweep its comments. Agents
pass each other `key: value` lines, not prose. It
runs only the tests its change can reach — `pnpm test:changed` and the e2e
files it touched. Every other check runs on its own: format, lint and
typecheck on commit; Fallow, the e2e typecheck and `pnpm mutate` (mutants
on the changed lines only, so every changed line is shown to matter before
anyone reviews it) on push; the full suite in CI.
anyone reviews it) on push; the full suite in CI. Each push cancels the CI
run before it, so before every review round and fix run the orchestrator
reads the newest finished run with `.agents/scripts/ci-failures.mjs`, and
its failed tests go into the next fix run.

A spec never answers every question. What any change includes without
asking — docs it makes false, both `EVENTS.md` files, a test for every new
Expand Down Expand Up @@ -335,7 +339,8 @@ a fixed layout:
- `docs/internal/adr/` with a `README.md` index, and
`docs/internal/templates/` with `feature.md` and `task.md`.
- `.agents/scripts/`: `worktree.sh`, `review-inputs.sh`, `stale-refs.sh`,
`merge-pr.sh`, `delivery-stats.mjs` and `budget-guard.mjs`. `worktree.sh` and
`comments.mjs`, `ci-failures.mjs`, `merge-pr.sh`, `delivery-stats.mjs`
and `budget-guard.mjs`. `worktree.sh` and
`ensure-pnpm.sh` are this project's (they install its dependencies); the
others are not.
- `.github/workflows/issue-state.yml` and the labels in `.github/labels.json`.
Expand Down Expand Up @@ -367,7 +372,7 @@ To move it: copy the agents, skills, scripts, workflow, labels,
`.claude/settings.json`), `.agents/scripts/ensure-pnpm.sh` (the session-start
hook; installs the pinned pnpm into a cache when PATH lacks it),
`.agents/scripts/review-inputs.sh`, `.agents/scripts/stale-refs.sh`,
`.agents/scripts/comments.mjs`,
`.agents/scripts/comments.mjs`, `.agents/scripts/ci-failures.mjs`,
`.agents/scripts/merge-pr.sh`,
`.agents/scripts/delivery-stats.mjs`,
`scripts/slow-e2e.sh`, `scripts/mutate.mjs` (`pnpm mutate`)
Expand Down
2 changes: 1 addition & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ pre-push:
# an equivalent mutant cannot be killed, so each survivor is killed or explained in the PR body.
mutate:
priority: 3
run: pnpm run mutate || echo "Mutants survived (listed above). Kill each one, or explain it in the PR body."
run: pnpm run mutate || true
13 changes: 9 additions & 4 deletions scripts/mutate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
// under src/ or ui/src/ since the branch's last run reprints that run's result.
//
// A survivor is a line you can change, or delete, with a green suite: testing rules 2 and 3.
// Exit 0 when every mutant died, 1 when any survived or had no covering test.
// Exit 0 when every mutant died, 1 when any survived or had no covering test, 2 when Stryker
// failed without a report.
import { execFileSync, spawnSync } from "node:child_process";
import {
existsSync,
Expand Down Expand Up @@ -93,11 +94,14 @@ const run = spawnSync(
"--incrementalFile",
`${branch}.json`,
],
{ stdio: ["ignore", "inherit", "inherit"] },
{ stdio: ["ignore", "inherit", "pipe"], encoding: "utf8", maxBuffer: 64 * 1024 * 1024 },
);
process.stderr.write(run.stderr ?? "");
if (!existsSync(REPORT)) {
console.error(`Stryker exited ${run.status} without a report.`);
process.exit(run.status || 1);
// Last, so a caller that keeps only the tail of the output still sees why.
const tail = (run.stderr ?? "").trimEnd().split("\n").slice(-15).join("\n");
console.error(`\nStryker exited ${run.status} without a report: no mutant was tested.\n${tail}`);
process.exit(2);
}

const report = JSON.parse(readFileSync(REPORT, "utf8"));
Expand All @@ -118,5 +122,6 @@ print(total, ranges.length, alive);
function print(total, rangeCount, alive) {
console.log(`\n${total} mutants on ${rangeCount} changed ranges; ${alive.length} alive.`);
for (const line of alive) console.log(line);
if (alive.length > 0) console.log("Kill each one, or explain it in the PR body.");
process.exit(alive.length === 0 ? 0 : 1);
}
Loading
Loading