@jesdi/skills 0.0.74 → 0.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/package.json +1 -1
  2. package/skills/implement-spec/README.md +27 -22
  3. package/skills/implement-spec/SKILL.md +1 -1
  4. package/skills/implement-spec/driver.py +75 -44
  5. package/skills/implement-spec/driver_final.py +60 -34
  6. package/skills/implement-spec/driver_fixloop.py +65 -17
  7. package/skills/implement-spec/driver_gate.py +25 -12
  8. package/skills/implement-spec/driver_legacy.py +19 -7
  9. package/skills/implement-spec/driver_merge.py +20 -2
  10. package/skills/implement-spec/driver_report.py +10 -3
  11. package/skills/implement-spec/driver_run.py +17 -13
  12. package/skills/implement-spec/driver_state.py +17 -7
  13. package/skills/implement-spec/driver_summary.py +1 -1
  14. package/skills/implement-spec/driver_tidy.py +2 -8
  15. package/skills/implement-spec/prompts/final-fixer.md +1 -1
  16. package/skills/implement-spec/prompts/final-reviewer.md +2 -2
  17. package/skills/implement-spec/prompts/fixer.md +1 -1
  18. package/skills/implement-spec/prompts/implementer.md +1 -1
  19. package/skills/implement-spec/prompts/landing-merge.md +1 -0
  20. package/skills/implement-spec/prompts/landing-red.md +2 -0
  21. package/skills/implement-spec/tests/test_agents.py +2 -2
  22. package/skills/implement-spec/tests/test_amendments.py +1 -1
  23. package/skills/implement-spec/tests/test_cli.py +4 -4
  24. package/skills/implement-spec/tests/test_driver.py +73 -30
  25. package/skills/implement-spec/tests/test_final.py +41 -7
  26. package/skills/implement-spec/tests/test_fixloop.py +172 -21
  27. package/skills/implement-spec/tests/test_landing.py +1 -1
  28. package/skills/implement-spec/tests/test_merge.py +8 -0
  29. package/skills/implement-spec/tests/test_report.py +2 -2
  30. package/skills/implement-spec/tests/test_review.py +16 -8
  31. package/skills/implement-spec/tests/test_state.py +6 -6
  32. package/skills/implement-spec/tests/test_summary.py +3 -2
  33. package/skills/implement-spec/tests/test_tidy.py +16 -13
  34. package/skills/implement-spec/tests/test_walk.py +55 -36
  35. package/skills-manifest.json +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jesdi/skills",
3
- "version": "0.0.74",
3
+ "version": "0.0.76",
4
4
  "description": "jesdi's agent skills (content package consumed by @jesdi/skills-cli)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  # implement-spec driver
2
2
 
3
- `run.sh` turns a spec and its tickets into one reviewed PR branch. It is a script, not a session: it walks the ticket graph, starts one agent for each role, runs the gate, merges, and stops only at a bounded question or a BLOCKED ticket. [SKILL.md](SKILL.md) only starts it.
3
+ `run.sh` turns a spec and its tickets into one reviewed PR branch. It is a script, not a session: it walks the ticket graph, starts one agent for each role, runs the gates, merges, and stops only at a bounded question or a BLOCKED ticket. [SKILL.md](SKILL.md) only starts it.
4
4
 
5
5
  This file is written from the code. Where it and `specs/implement-spec-driver/` differ, the code is right.
6
6
 
@@ -9,7 +9,7 @@ This file is written from the code. Where it and `specs/implement-spec-driver/`
9
9
  Run it in the PR worktree, on the PR branch, with a clean tree:
10
10
 
11
11
  ```sh
12
- sh skills/implement-spec/run.sh --gate 'pnpm check' --spec specs/<slug>/spec.md
12
+ sh skills/implement-spec/run.sh --gate 'pnpm check' --fast-gate 'pnpm check:fast' --spec specs/<slug>/spec.md
13
13
  ```
14
14
 
15
15
  Before any agent starts, the driver checks these. Each failed check prints one line, and the run then ends with exit 3.
@@ -31,7 +31,8 @@ A driver before this change named the ticket branches `ticket/<NN>` and the reco
31
31
 
32
32
  | Flag | Meaning |
33
33
  |---|---|
34
- | `--gate COMMAND` | Required. The check command of the repository, as one shell line. The driver runs it on each commit it is about to trust, with `IMPLEMENT_SPEC_BASE` set to the PR branch. |
34
+ | `--gate COMMAND` | Required. The full gate: the whole check command of the repository, as one shell line. The driver runs it on each commit that would land on the PR branch and at the end of the run, with `IMPLEMENT_SPEC_BASE` set to the PR branch and no `IMPLEMENT_SPEC_LOCKED`. No agent is told this command. |
35
+ | `--fast-gate COMMAND` | Required. The fast gate: the ticket's locked tests, lint and types, as one shell line. The driver runs it on each candidate (the tip an implementer, a fixer or a test-writer correction made) before its review, with `IMPLEMENT_SPEC_BASE` set to the PR branch and `IMPLEMENT_SPEC_LOCKED` set to the space-separated locked file paths it checks: for a candidate, the ticket's locked files; for the restore commit before a test-writer correction, the ticket's locked files plus each restored file. A merged ticket's locked files are not in a candidate's list. A green record is settled per tier and commit, whatever the list was: a commit is fast gated in one context. The implementer, the fixers and the final fixer run it on their own work: their prompts name this command and the same locked list, and for the final fixer the list is every merged ticket's locked files. No agent prompt names the `--gate` command. What it checks is the operator's choice. |
35
36
  | `--spec FILE` | Required without `--dry-run`. The spec file the prompts point at. Its first heading is the PR title. |
36
37
  | `--tickets DIR` | The directory of the ticket files. Default: `.agent/tickets`. |
37
38
  | `--models FILE` | A JSON file with one ordered list of `provider/model@effort` for each role. A role in this file replaces the list of that role in `models.json`. |
@@ -80,12 +81,12 @@ Everything is under `.agent/`, which is never committed.
80
81
  | `.agent/implement/state.json` | The resume contract: the run record and one record for each ticket (`driver_state.py`). |
81
82
  | `<git common directory>/implement-spec/<key>.lock` | An empty file, not in the worktree. The driver that runs holds a kernel file lock on it (`driver_state.py` `lock`). Do not remove it during a run. |
82
83
  | `.agent/implement/ledger.md` | One plain sentence for each event. Only the driver writes it, and it reads no fact from it. |
83
- | `.agent/implement/summary.md` | The result in sentences, and the measurement table: gates, agents, wall time, fix rounds, human stops, cost. |
84
+ | `.agent/implement/summary.md` | The result in sentences, and the measurement table: fast gates and full gates, agents, wall time, fix rounds, human stops, cost. |
84
85
  | `.agent/implement/decisions.json` | The open questions and their `revision`. Written only after a stop. |
85
86
  | `.agent/implement/<NN>/` | One folder for each ticket. |
86
87
  | `.agent/implement/<NN>/<role>-<K>.json`, `.log`, `.prompt.md` | The report, the log and the prompt of one agent. K is the fix round. |
87
- | `.agent/implement/<NN>/gate-<sha7>.log` | One gate record: start, commit, status, command, output, exit, the state after the command, end. A command that a signal ended, with the tree clean and HEAD unmoved, did not judge the commit: the driver runs it once more, that run overwrites the record, and the ledger says the gate was killed by the signal and runs again. A signal ended the command when its exit is negative, or when it is 128+N for N in SIGHUP (1), SIGINT (2), SIGKILL (9) or SIGTERM (15): the gate runs in `/bin/sh -c`, and a shell that does not exec the command, as Ubuntu's dash does not, outlives its killed child and exits with 128+N. Any other exit, 142 (128+SIGALRM) among them, is a red record with no second run. A second signal leaves the record red. |
88
- | `.agent/implement/<NN>/findings-<K>.json` | The merged findings of the review after fix round K, or the red gate of round K. |
88
+ | `.agent/implement/<NN>/gate-<tier>-<sha7>.log` | One gate record, `<tier>` is `fast` or `full`: start, tier, commit, status, command, output, exit, the state after the command, end. A command that a signal ended, with the tree clean and HEAD unmoved, did not judge the commit: the driver runs it once more, that run overwrites the record, and the ledger says the gate was killed by the signal and runs again. A signal ended the command when its exit is negative, or when it is 128+N for N in SIGHUP (1), SIGINT (2), SIGKILL (9) or SIGTERM (15): the gate runs in `/bin/sh -c`, and a shell that does not exec the command, as Ubuntu's dash does not, outlives its killed child and exits with 128+N. Any other exit, 142 (128+SIGALRM) among them, is a red record with no second run. A second signal leaves the record red. |
89
+ | `.agent/implement/<NN>/findings-<K>.json` | The merged findings of the review after fix round K, or the red fast gate of round K. A red full gate at landing adds its finding to the findings of the last review. |
89
90
  | `.agent/implement/final/` | The same files for the end of run, and `pr-body.md`: the pr-writer's body, then the facts of the run. |
90
91
  | `.agent/implement/pycache/` | Compiled Python of the gate, kept out of the slots. |
91
92
  | `.agent/implement-review.html` | The page with the open questions. |
@@ -99,15 +100,15 @@ Everything is under `.agent/`, which is never committed.
99
100
  A ticket is ready when each ticket in its **Blocked by** line is merged and no running ticket touches the same place. The places are the backticked entries of the **Touches** lines: `file` or `file: function`. Two entries are the same place when they name the same file and the same function, or when one of them names the whole file. Each ready ticket takes the lowest free slot.
100
101
 
101
102
  1. **test-writer** (`prompts/test-writer.md`). It writes one black-box test for each criterion through the Seam and commits them red. Those files are locked. Its prompt names the locked tests of merged tickets: each fixture must set up the precondition of its scenario under the spec rules and those tests. When the ticket must change one of those files, the test-writer changes it and lists it in `locked`. A ticket with Seam `none — refactor` has no test-writer.
102
- 2. **implementer** (`prompts/implementer.md`). It starts from that commit and makes the locked tests green. It makes the gate (`--gate`) green on its final commit before it reports DONE or DONE_WITH_CONCERNS.
103
- 3. **Gate.** The driver runs `--gate` on the ticket tip.
103
+ 2. **implementer** (`prompts/implementer.md`). It starts from that commit and makes the locked tests green. It makes the fast gate (`--fast-gate`, with the ticket's locked files in `IMPLEMENT_SPEC_LOCKED`) green on its final commit before it reports DONE or DONE_WITH_CONCERNS.
104
+ 3. **Fast gate.** The driver runs `--fast-gate` on the ticket tip. No full gate runs on a candidate.
104
105
  4. **Review.** The driver compares each locked file of the ticket with the test-writer commit. A file that differs is a critical finding `locked file changed: <path>`. A locked file of a merged ticket that the ticket changed since its merge base with the PR branch is a critical `fixture` finding `the ticket changed the locked file of a merged ticket: <path>`, so it goes to a correction (see **Before a correction**). Then the **reviewer** (`prompts/reviewer.md`) runs, and for a ticket with a **Risk** line the **correctness** pass (`prompts/correctness.md`) runs at the same time in the same slot. A read-only role (reviewer, correctness, final-reviewer, pr-writer) leaves its slot and the git config as it found them: all worktrees share one config, and one key written there, such as a `core.worktree` on a temp directory, breaks git in each of them. To run a check off the slot, a reviewer reads the driver's gate record or makes its own `git worktree add --detach` copy and removes it. After read-only roles, the driver checks the slot and the keys of the shared config (`git rev-parse --git-common-dir`, then `config`) against what they were before. One change does not count: a new `branch.<name>` section with only `remote` on a configured remote and `merge` on `refs/heads/...`, which another session's `git worktree add -b` writes while a review runs. When the slot or another key changed, the driver restores the slot and only the changed keys, so other sessions' writes stay; when git cannot write them back (a held `config.lock`, a valueless key), the whole file goes back, and when that fails too the ticket is blocked, writes `a read-only role broke its rule: ...` to the ledger, and runs the review one more time; a second change blocks the ticket.
105
106
 
106
107
  The ticket reviewers put unmet criteria and merged-ticket regressions in `findings`; other observations go to final review. A re-review repeats its own open findings and can add regressions caused by the fix. Newly noticed issues outside that scope are deferred. The driver stores deferred observations in `observations-<round>.json` and gives them to the final reviewer.
107
- 5. **Merge.** The driver merges the reviewed tip into the PR branch with git plumbing, then deletes the ticket branch. A conflict goes to the **conflict** agent (`prompts/conflict.md`) once. Its resolution may change no locked file of the ticket. A second conflict blocks the ticket.
108
- **The landing check.** Merges are serial. Before the PR branch moves, the driver compares the tree that is about to land (the ticket tip of a fast-forward, or the merge commit) with the PR tip: each locked file of each merged ticket must be the same tree entry in both: the same blob with the same mode, so a file that became a symlink is a difference. A file that only one of them has is a difference. A file that the landing ticket lists in its own `locked` is not checked: the test-writer of a later ticket can add a test to a file that an earlier ticket locked, and must list that file. A test-writer report that changes such a file and does not list it is rejected, with the usual one rerun. The review finds such a change first; the landing check catches a change that no review saw, for example of a ticket that merged after the last review. A difference refuses the landing: the ticket is BLOCKED with `locked file changed: <path>` in the ledger and a `merged-locked-file` question for each path, the PR branch does not move, and no fix round runs. `restore` puts the file back to the version of the PR branch in a commit of the driver on the ticket branch, and `adopt` adds the file to the ticket's `locked`; then the landing runs again with its gate. When that gate is red, the driver takes the restore commit back and asks again without the option that was tried. The PR branch moves only from the tip that the check read; when another hand moved the branch in between, the driver makes the merge, the check and the gate again, one time. Only that case starts the landing again: a refused landing and a red merge gate block the ticket. The second try runs no conflict agent, so a conflict there blocks the ticket, and so does a branch that moved again.
108
+ 5. **Merge.** The driver merges the reviewed tip into the PR branch with git plumbing, then deletes the ticket branch. A conflict goes to the **conflict** agent (`prompts/conflict.md`) once. Its resolution may change no locked file of the ticket. A second conflict blocks the ticket. Before the PR branch moves, the driver runs the full gate (`--gate`) on the exact commit that would land: the ticket tip of a fast-forward, or the merge commit. A green fast record never counts for it.
109
+ **The landing check.** Merges are serial. Before the PR branch moves, the driver compares the tree that is about to land (the ticket tip of a fast-forward, or the merge commit) with the PR tip: each locked file of each merged ticket must be the same tree entry in both: the same blob with the same mode, so a file that became a symlink is a difference. A file that only one of them has is a difference. A file that the landing ticket lists in its own `locked` is not checked: the test-writer of a later ticket can add a test to a file that an earlier ticket locked, and must list that file. A test-writer report that changes such a file and does not list it is rejected, with the usual one rerun. The review finds such a change first; the landing check catches a change that no review saw, for example of a ticket that merged after the last review. A difference refuses the landing: the ticket is BLOCKED with `locked file changed: <path>` in the ledger and a `merged-locked-file` question for each path, the PR branch does not move, and no fix round runs. `restore` puts the file back to the version of the PR branch in a commit of the driver on the ticket branch, and `adopt` adds the file to the ticket's `locked`; then the landing runs again with its gate. When that gate is red, the driver takes the restore commit back and asks again without the option that was tried. The PR branch moves only from the tip that the check read; when another hand moved the branch in between, the driver makes the merge, the check and the gate again, one time. Only that case starts the landing again: a refused landing blocks the ticket. A red full gate at landing is a gate finding inside the two rounds (see Findings and fix rounds); after `restore` or `adopt` rulings it asks again, as above. The second try runs no conflict agent, so a conflict there blocks the ticket, and so does a branch that moved again.
109
110
  **Before a correction.** A test-writer that corrects locked tests (after `overrule-test`, or for a `fixture` finding or a `test` finding on a locked file) starts from the locked versions: the driver puts back each locked file of the ticket and each locked file of a merged ticket that the ticket changed, commits them in one commit of its own, and the ledger names each file. A file of a merged ticket goes back to the version of the PR branch. The commit keeps the tree of the next fixer and of the gate clean, whatever files the correction commits. The correction's prompt names the restored files: when a test in one of them fails only because the ticket changed an interface that the test uses, the correction updates the file to the new interface, keeps what each test asserts, and lists the file in `locked`. Each correction also gets `prompts/corrected.md`: when it adds a requirement, it updates each shared fake or fixture that other locked tests use, runs each whole locked file and each locked test of merged tickets, and names each red test in `concerns`.
110
- **The gate of the restore.** In the fix loop, the tip before the restore has a green gate, so the driver gates the restore commit and does not leave the question to the correction. A red gate means that a restored file fails with the ticket's code: the correction gets the gate record (`prompts/restored-red.md`), and a DONE correction must list a restored file in `locked`; else it reports BLOCKED with `locked test contradicts spec:`. A green gate with only driver findings to correct closes them with the restore: no test-writer runs. After `overrule-test` the driver does not gate the restore, because the tip before it has no green gate; a change that the next implementer makes to a merged ticket's file is a finding of the next review.
111
+ **The gate of the restore.** In the fix loop, the tip before the restore has a green gate, so the driver runs the fast gate (never the full gate) on the restore commit, with the restored files in `IMPLEMENT_SPEC_LOCKED`, and does not leave the question to the correction. A red gate means that a restored file fails with the ticket's code: the correction gets the gate record (`prompts/restored-red.md`), and a DONE correction must list a restored file in `locked`; else it reports BLOCKED with `locked test contradicts spec:`. A green gate with only driver findings to correct closes them with the restore: no test-writer runs. After `overrule-test` the driver does not gate the restore, because the tip before it has no green gate; a change that the next implementer makes to a merged ticket's file is a finding of the next review.
111
112
 
112
113
  Rules for each agent:
113
114
 
@@ -125,9 +126,11 @@ Rules for each agent:
125
126
  | `critical` or `important` | One fix round. |
126
127
  | `minor` | It stays in the ledger and in the findings file. The final reviewer gets the list. |
127
128
 
128
- A fix round has three steps: the **fixer** (`prompts/fixer.md`) makes the gate green on its final commit, as the implementer does; the driver runs the gate on the new tip; a re-review reads the range of the fix. A mutation proof is repeated only when the fix changed its production line. A fixer whose findings need no change, for example because a test-writer correction before it already resolved them, makes no commit and gives in `concerns` a reason for each finding; the round still counts, and the re-review of the same tip checks each reason.
129
+ A fix round has three steps: the **fixer** (`prompts/fixer.md`) makes the fast gate green on its final commit, as the implementer does; the driver runs the fast gate on the new tip; a re-review reads the range of the fix. A mutation proof is repeated only when the fix changed its production line. A fixer whose findings need no change, for example because a test-writer correction before it already resolved them, makes no commit and gives in `concerns` a reason for each finding; the round still counts, and the re-review of the same tip checks each reason.
129
130
 
130
- A red gate on the commit of the implementer or of a fixer is a critical finding with source `gate`. Its file is the gate record, and the record holds the output. No review runs on that tip, and the next round starts: a red gate on the commit of the implementer starts round 1. The review after that round covers each fix since the last review and repeats each proof that one of them made due. A red gate after round 2 or on a test-writer correction blocks the ticket.
131
+ A red fast gate on the commit of the implementer or of a fixer is a critical finding with source `gate`, titled `the fast gate is red on <sha7>`. Its file is the gate record, and the record holds the output. No review runs on that tip, and the next round starts: a red gate on the commit of the implementer starts round 1. The review after that round covers each fix since the last review and repeats each proof that one of them made due. A red fast gate after round 2 or on a test-writer correction blocks the ticket.
132
+
133
+ A red full gate on the commit that would land is a gate finding too, inside the same two rounds. The PR branch does not move and the merge lock is released. Before round 2, the driver adds a critical finding with source `gate`, titled `the full gate is red on <sha7>`, to the findings file of the last review, its file the full record, and the next round starts: the fixer (with `prompts/landing-red.md`) works on the ticket branch, its commit gets the fast gate and a re-review of the fix, and the landing runs a new full gate on the new commit that would land. When the red commit is a merge commit, the fixer's prompt also names that merge commit (`prompts/landing-merge.md`), so it can merge the PR branch to reproduce the failure. After round 2 a red full gate at landing blocks the ticket, with no third round.
131
134
 
132
135
  - Round 1 runs on the first entry of the implementer list; round 2 runs on the second. Both entries are required.
133
136
  - After round 2, a red gate or an unmet ticket criterion blocks the ticket and its dependents. Independent tickets continue. When the gate is green and criteria are met, other open findings move to the final must-fix list; the ticket can merge. A tip that changes a locked file of a merged ticket still gets a `merged-locked-file` question at its landing.
@@ -137,24 +140,26 @@ A red gate on the commit of the implementer or of a fixer is a critical finding
137
140
  The end of run starts only when every ticket is merged and every slot is idle. Its agents work in slot 1.
138
141
 
139
142
  1. **Tidy.** The driver saves the PR tip in `refs/implement-spec/<key>/recovery`. It then makes one commit for each ticket, in merge order, named `feat(NN): <title>`. Each commit holds the tests, the implementation and the fixes of its ticket. The tree of the new tip must equal the tree of the old tip, or the branch stays as it was.
140
- 2. **Rebase** onto the fetched tip of the `--base` branch, or without it of the default branch of `origin`. A conflict goes to the conflict agent (`prompts/rebase-conflict.md`) once, and the rebased tip is gated.
141
- 3. **Gate**, then the **final-reviewer** (`prompts/final-reviewer.md`) on the whole range, with the method of the `review-diff` skill. It gets ticket observations, minor findings, the must-fix list and the rulings of the operator.
142
- 4. **Fix batch.** Critical and important findings, including every must-fix item, go to one fixer (`prompts/final-fixer.md`). The driver names each of its commits `fix(NN): …` from the ticket in the report. Then the gate, then one scoped review of those commits.
143
+ 2. **Rebase** onto the fetched tip of the `--base` branch, or without it of the default branch of `origin`. A conflict goes to the conflict agent (`prompts/rebase-conflict.md`) once, and the rebased tip gets the full gate.
144
+ 3. **Full gate**, then the **final-reviewer** (`prompts/final-reviewer.md`) on the whole range, with the method of the `review-diff` skill. It reads the driver's full gate record of the reviewed tip as the gate of that method and runs no gate itself. It gets ticket observations, minor findings, the must-fix list and the rulings of the operator.
145
+ 4. **Fix batch.** Critical and important findings, including every must-fix item, go to one fixer (`prompts/final-fixer.md`), which makes the fast gate green on its final commit, with every merged ticket's locked files in `IMPLEMENT_SPEC_LOCKED`. The driver names each of its commits `fix(NN): …` from the ticket in the report. Then the full gate, then one scoped review of those commits. The driver runs no fast gate at the end of the run.
143
146
  5. Other findings open after the second review become questions of kind `final-finding`; unresolved must-fix items keep the run blocked. There is no third review.
144
147
  6. **Push.** With `--push` or `--unattended`, the driver pushes the reviewed tip once, with no force, and opens the PR into the branch of step 2 with `gh`, ready for review. The **pr-writer** (`prompts/pr-writer.md`) writes the body with the method of the `pr` skill; the driver puts the facts of the run after it: the ticket-to-commit map, the fix commits, the rulings and the review coverage (`prompts/pr-body.md`). The body carries the merge-risk block of the `pr-risk` skill under `## Merge Danger`, above the facts; the driver validates it, runs the pr-writer once more with the errors when it is invalid, and blocks the run, opening no PR, when the second body is invalid too. A push stops before any agent when no `pr` skill or no `pr-risk` skill is next to this skill, in `${CLAUDE_CONFIG_DIR:-~/.claude}/skills` or in `~/.agents/skills`. Without them it prints the two tips and the command to run again with `--push`.
145
148
 
146
149
  History rules:
147
150
 
148
151
  - The branch is rewritten once, before the first review, and never after it. Fixes of the final review stay as `fix(NN)` commits.
149
- - A history that `origin` already has is never rewritten. When `origin` has the PR branch or one of its commits, the driver does no tidy and no rebase. The gate, the final review and a fast-forward push still run.
150
- - The push happens only when the branch tip is the reviewed tip and that tip has a green gate record.
152
+ - A history that `origin` already has is never rewritten. When `origin` has the PR branch or one of its commits, the driver does no tidy and no rebase. The full gate, the final review and a fast-forward push still run.
153
+ - The push happens only when the branch tip is the reviewed tip and that tip has a green full gate record.
154
+ - With `commit.gpgsign` on, the driver signs every commit it makes (ticket merges, tidied and renamed commits) with the configured key. The push happens only when every commit that `origin` lacks has a good signature (`%G?` is `G`); otherwise the end of run is BLOCKED and nothing is pushed.
151
155
 
152
156
  A repository with no `origin` remote skips only step 2 and step 6. The tidied commits stay on the commit that the PR branch had when the run started, and the review range starts there. One ledger sentence says that the rebase and the push were skipped. The driver prints the two tips and ends with exit 0. When you add `origin` after such an end of run, `--push` does not push: the branch is on no base of that remote, so the end of run is BLOCKED.
153
157
 
154
158
  ### Resume
155
159
 
156
- - A green gate record is settled. The driver never runs the gate again for that commit.
160
+ - A green gate record is settled per tier and commit. The driver never runs the same tier again on that commit, and a green fast record never stands in for a full one. A `state.json` before `schema` 3 has one untiered list of green commits and one gate count: every gate then was the full gate, so the resume makes them the full tier.
157
161
  - A ticket whose recorded tip is not on its branch goes back to `implement`, from the test-writer commit. A merged ticket whose tip is not in the PR branch does the same.
162
+ - A red full gate at landing moves the ticket to `fix`, advances its round and records the red commit in `landing`, in one write of `state.json`. A resumed run starts that round's fixer and does not gate the red commit again; the fixer's report clears `landing`.
158
163
  - A slot with the uncommitted work of an interrupted role stays as it is. The role runs there again and is told so.
159
164
 
160
165
  ## Models
@@ -178,7 +183,7 @@ Every report has `status` (`DONE`, `DONE_WITH_CONCERNS`, `NEEDS_CONTEXT`, `BLOCK
178
183
 
179
184
  | Role | Template | More fields | Checks after the schema |
180
185
  |---|---|---|---|
181
- | test-writer | `prompts/test-writer.md` | `locked` (test file paths), `red` (`test`, `line`), optional `fixtures` (each locked file that holds no test, as a fake `gh`) | The driver reads a test node id `<file>::<test>` in `locked` as its file. Each fixture is in `locked`; the ticket record keeps it a fixture until a later correction lists the file again. With DONE: one commit, one locked file and one red line or more. A correction's test can be green on the implementer's code, so its red line comes from a production edit that the correction makes and reverts. Each locked path is in a commit that the role made and is a file at the tip: a correction that deletes a locked file leaves it out of `locked`. Each `line` is in the log. A locked file of a merged ticket that the role changed is in `locked`. A correction (after `overrule-test`, or for a review finding) changes only the files that it lists in `locked` and the files that the driver restored before it. When the gate is red on the restore commit, a DONE correction lists a restored file in `locked`. Each `not_addressed[].finding` is the title of a finding of the correction, or after `overrule-test` an overruled concern as its prompt lists it (the driver logs its reason, and the implementer runs again); a DONE correction with each of its findings there needs no commit. |
186
+ | test-writer | `prompts/test-writer.md` | `locked` (test file paths), `red` (`test`, `line`), optional `fixtures` (each locked file that holds no test, as a fake `gh`) | The driver reads a test node id `<file>::<test>` in `locked` as its file. Each fixture is in `locked`; the ticket record keeps it a fixture until a later correction lists the file again. With DONE: one commit, one locked file and one red line or more. A correction's test can be green on the implementer's code, so its red line comes from a production edit that the correction makes and reverts. No locked path contains whitespace, since `IMPLEMENT_SPEC_LOCKED` separates the paths by spaces. Each locked path is in a commit that the role made and is a file at the tip: a correction that deletes a locked file leaves it out of `locked`. Each `line` is in the log. A locked file of a merged ticket that the role changed is in `locked`. A correction (after `overrule-test`, or for a review finding) changes only the files that it lists in `locked` and the files that the driver restored before it. When the gate is red on the restore commit, a DONE correction lists a restored file in `locked`. Each `not_addressed[].finding` is the title of a finding of the correction, or after `overrule-test` an overruled concern as its prompt lists it (the driver logs its reason, and the implementer runs again); a DONE correction with each of its findings there needs no commit. |
182
187
  | implementer | `prompts/implementer.md` | `green` | With DONE and no commit: no new commit on the branch, no uncommitted change, and a concern that says why the start needs no change. The driver then gates and reviews the start commit. |
183
188
  | reviewer | `prompts/reviewer.md` | `findings` (`severity`, `file`, `line`, `title`, `evidence`, `kind`), `mutations` (`test`, `file`, `line`, `red`) | In a full review (one with no fix range: round 1, and the review after a test-writer correction): `mutations` is required, with a proof for each locked test file (`test` is `<locked file>::<test name>`). A locked fixture needs no proof: it holds no test that a proof could name, and the locked-file check protects it. Neither does a locked file that is not at the reviewed tip. Each `red` is in the log. |
184
189
  | correctness | `prompts/correctness.md` | the same as the reviewer | `mutations` is optional. |
@@ -217,8 +222,8 @@ Answer with `--answer <question id>=<option id>` on the next run, or through the
217
222
  | Locked tests with a demonstrated red | `driver_report.py` `_proof_errors`: each red line of the test-writer report must be in its log. `driver_review.py` `locked_findings`: a locked file of the ticket that differs from the test-writer commit is a critical finding, before each review. `driver_review.py` `merged_changes`: a locked file of a merged ticket that the ticket changed is a critical `fixture` finding, before each review. `driver_merge.py` `refused`, called from `driver.py` `_checked_landing` under the merge lock: a locked file of a merged ticket that differs between the PR tip and the tree that is about to land refuses the landing with a `merged-locked-file` question, so a later ticket changes the locked test of an earlier one only by the operator's `adopt`. `driver_report.py` `_merged_errors` rejects a test-writer report that changes such a file and does not list it. |
218
223
  | One mutation proof for each locked test | `prompts/full-review.md`, the note of each full review, names the locked test files that need a proof: each locked file that is not a fixture. `driver_report.py` `_locked_errors` and `_proof_errors` reject a full review with no proof for a locked test file, or with a red line that is not in the log. `driver_review.py` `follow` finds the proofs that a fix makes due again. |
219
224
  | One independent correctness pass for each risky ticket | `driver_fixloop.py` `_review` adds the pass for a ticket with a **Risk** line. `driver_agents.py` `correctness_entry` picks the entry of another provider, and `load_models` stops the run when there is none or its CLI is not on PATH. |
220
- | One full gate for each candidate | `driver_gate.py` `run`, called from `driver_run.py` `Run.gate`: one record for each commit the driver is about to trust. Green is exit 0 on a tree that is clean before and after, with HEAD not moved. |
221
- | Post-merge check on the PR branch | `driver.py` `_checked_landing`: a merge commit is gated before the PR branch moves to it. A fast-forward of a gated tip uses the record of that tip. `driver_final.py` `_review_until_reviewed` gates the tip again after the tidy and after the fix batch. |
225
+ | One fast gate for each candidate | `driver_gate.py` `run`, called from `driver_run.py` `Run.gate` with the tier: one record for each tier and commit the driver is about to trust. Green is exit 0 on a tree that is clean before and after, with HEAD not moved. `driver_fixloop.py` `_gate` fast-gates each candidate. |
226
+ | Post-merge check on the PR branch | `driver.py` `_checked_landing`: the full gate runs on the commit that would land, a fast-forward as well as a merge commit, before the PR branch moves to it. `driver_final.py` `_review_until_reviewed` runs the full gate again after the tidy and after the fix batch. |
222
227
 
223
228
  The driver enforces the mutation proof for each locked test file, not for each locked test.
224
229
 
@@ -23,7 +23,7 @@ has passed. The review rounds adapt superpowers' subagent-driven-development
23
23
 
24
24
  Run the driver. It makes every choice of the run; you start it and relay its result.
25
25
 
26
- 1. In the PR worktree, run `sh <skill-dir>/run.sh` with the flags the operator gave, unchanged. `<skill-dir>` is the directory of this file. The driver needs `--gate` and `--spec`: ask the operator for a flag that is missing. A run can take hours: run the command in the background and wait for it to exit.
26
+ 1. In the PR worktree, run `sh <skill-dir>/run.sh` with the flags the operator gave, unchanged. `<skill-dir>` is the directory of this file. The driver needs `--gate`, `--fast-gate` and `--spec`: ask the operator for a flag that is missing. A run can take hours: run the command in the background and wait for it to exit.
27
27
  2. When it exits, relay `.agent/implement/summary.md` and the exit code: 0 is done, 1 is a BLOCKED ticket, 2 is parked on questions, 3 is invalid input, 4 is stopped by a CLI failure (after the fix, the same command resumes). Relay the lines the driver printed after the summary too. With exit 0 and a PR URL such as `https://github.com/jesdi/demo/pull/61`, tell the operator to start the babysitter: run `/babysit-pr https://github.com/jesdi/demo/pull/61`.
28
28
  3. With exit 2, and with exit 1 when the driver printed questions, show the operator those questions. When the operator answers, run the same command again with one `--answer <question id>=<option id>` for each answer.
29
29
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  """implement-spec driver: validate the ticket set and the environment, then walk the ticket graph.
3
3
 
4
- sh run.sh --gate COMMAND --spec FILE [--tickets DIR] [--models FILE] [--parallel N] [--prepare COMMAND]
4
+ sh run.sh --gate COMMAND --fast-gate COMMAND --spec FILE [--tickets DIR] [--models FILE] [--parallel N] [--prepare COMMAND]
5
5
  [--timeout ROLE=MINUTES] [--answer QUESTION=OPTION] [--unattended [--stage-json FILE]] [--push]
6
6
  [--base BRANCH] [--dry-run]
7
7
 
@@ -99,11 +99,37 @@ def _prompt_values(ticket: Ticket, slot: str, run: Run) -> dict[str, str]:
99
99
  return {"spec": os.path.relpath(run.args.spec, slot), "seam": ticket.seam, "pr_branch": run.pr,
100
100
  "branch": run.names.ticket(ticket.number),
101
101
  "ticket": os.path.relpath(Path(run.args.tickets) / ticket.file, slot),
102
- "correctness": driver_review.checks(), "gate": run.args.gate,
102
+ "correctness": driver_review.checks(), "gate": run.args.fast_gate,
103
103
  "blocked_report": os.path.relpath(_blocked_report(ticket.number, run), slot),
104
104
  "writer_report": os.path.relpath(folder / "test-writer-0.json", slot)}
105
105
 
106
106
 
107
+ def _first_notes(number: str, slot_number: int, entry: dict, run: Run, roles: list[str]) -> list[str]:
108
+ """The one more template of the first role: the ruling that sent the ticket back, or that its work was
109
+ interrupted."""
110
+ if entry["note"]:
111
+ return [entry["note"]]
112
+ if run.kept.get(number) == slot_number:
113
+ ledger(f"Ticket {number}: resumed in slot {slot_number} with the work the interrupted {roles[0]} left.")
114
+ return ["interrupted"]
115
+ return []
116
+
117
+
118
+ def _role_check(role: str, number: str, slot: str, entry: dict, run: Run, values: dict,
119
+ notes: list[str]) -> tuple[dict, list[str]]:
120
+ """(the check of the report of `role`, its notes). A test-writer on a ticket that has locked tests is the
121
+ correction after a ruling: it gets the overruled concerns, and the locked files it changed are put back first."""
122
+ check = {"correction": role == "test-writer" and bool(entry["test_writer_sha"])}
123
+ if not check["correction"]:
124
+ return check, notes
125
+ check["findings"] = _overruled(number, run)
126
+ values["overruled"] = "".join(f"- {concern}\n" for concern in check["findings"])
127
+ if restored := run.restore_locked_files(number, slot):
128
+ values.update(start_sha=driver_slots.head(slot), restored=" ".join(restored))
129
+ notes, check["restored"] = [*notes, "restored"], restored
130
+ return check, notes
131
+
132
+
107
133
  def _run_roles(ticket: Ticket, slot_number: int, run: Run) -> None:
108
134
  """Run the test-writer and the implementer, as far as the phase of the ticket still needs them."""
109
135
  number, slot = ticket.number, driver_slots.path(slot_number)
@@ -111,26 +137,13 @@ def _run_roles(ticket: Ticket, slot_number: int, run: Run) -> None:
111
137
  roles = _roles_left(ticket, entry["phase"], run.args.only)
112
138
  with during("the start"):
113
139
  start = _check_out_ticket(ticket, slot_number, entry, run)
114
- # The first role gets one more template: the ruling that sent the ticket back, or that its work was interrupted.
115
- if entry["note"]:
116
- notes = [entry["note"]]
117
- elif run.kept.get(number) == slot_number:
118
- notes = ["interrupted"]
119
- ledger(f"Ticket {number}: resumed in slot {slot_number} with the work the interrupted {roles[0]} left.")
120
- else:
121
- notes = []
140
+ notes = _first_notes(number, slot_number, entry, run, roles)
122
141
  values = {**_prompt_values(ticket, slot, run), "locked": " ".join(entry["locked"])}
123
142
  for role in roles:
124
143
  run.state.ticket(number, phase=DURING.get(role, "review"))
125
- values.update(start_sha=start, gate_record=os.path.relpath(driver_gate.record_path(OUT / number, start), slot))
126
- # A test-writer on a ticket that has locked tests is the correction after a ruling.
127
- check = {"correction": role == "test-writer" and bool(entry["test_writer_sha"])}
128
- if check["correction"]:
129
- check["findings"] = _overruled(number, run)
130
- values["overruled"] = "".join(f"- {concern}\n" for concern in check["findings"])
131
- if check["correction"] and (restored := run.restore_locked_files(number, slot)):
132
- values.update(start_sha=driver_slots.head(slot), restored=" ".join(restored))
133
- notes, check["restored"] = [*notes, "restored"], restored
144
+ values.update(start_sha=start, gate_record=os.path.relpath(driver_gate.record_path(OUT / number, driver_gate.FAST, start),
145
+ slot))
146
+ check, notes = _role_check(role, number, slot, entry, run, values, notes)
134
147
  with during(f"the {role}"):
135
148
  try:
136
149
  report = run.agent(role, number, slot, values, notes=notes, check=check)
@@ -237,20 +250,24 @@ def _refused(number: str, run: Run, landing: _Landing, rulings: _Rulings) -> Non
237
250
  raise Blocked("; ".join(f"locked file changed: {path}" for path in changed))
238
251
 
239
252
 
240
- def _red_landing(number: str, slot: str, run: Run, rulings: _Rulings, record: str) -> None:
241
- """A red merge gate after `restore` or `adopt` rulings: the restore commit leaves the ticket branch, and each
242
- ruled file is asked again, without the option that was tried."""
243
- if rulings.paths:
244
- if run.state.read()["tickets"][number]["tip"] != rulings.before:
245
- driver_review.restore(slot, run.names.ticket(number), rulings.before)
246
- run.state.ticket(number, tip=rulings.before)
247
- ledger(f"Ticket {number}: the merge gate is red after the restore, so the driver took the restore commit "
248
- f"back: the ticket tip is {rulings.before[:7]} again.")
249
- run.ask(number, MERGED_LOCKED, list(rulings.paths), record)
253
+ def _red_landing(number: str, slot: str, run: Run, rulings: _Rulings, commit: str, record: str) -> None:
254
+ """A red full gate on `commit`, the commit that would land. After `restore` or `adopt` rulings, the restore
255
+ commit leaves the ticket branch, and each ruled file is asked again, without the option that was tried. Else it
256
+ is a finding of the fix loop, inside the cap."""
257
+ if not rulings.paths:
258
+ git(slot, "checkout", "-q", run.names.ticket(number)) # the fixer works on the ticket branch
259
+ driver_fixloop.red_landing(run, number, slot, commit, record)
260
+ if run.state.read()["tickets"][number]["tip"] != rulings.before:
261
+ driver_review.restore(slot, run.names.ticket(number), rulings.before)
262
+ run.state.ticket(number, tip=rulings.before)
263
+ ledger(f"Ticket {number}: the merge gate is red after the restore, so the driver took the restore commit "
264
+ f"back: the ticket tip is {rulings.before[:7]} again.")
265
+ run.ask(number, MERGED_LOCKED, list(rulings.paths), record)
266
+ raise Blocked(f"the full gate is red on {commit[:7]}, record {record}")
250
267
 
251
268
 
252
269
  def _checked_landing(ticket: Ticket, slot: str, run: Run, may_resolve: bool, rulings: _Rulings) -> _Landing:
253
- """The commit to land, with the locked-file check passed and the gate green. Call it under the merge lock."""
270
+ """The commit to land, with the locked-file check passed and the full gate green. Call it under the merge lock."""
254
271
  number = ticket.number
255
272
  # An earlier try left the slot on its merge commit.
256
273
  git(slot, "checkout", "-q", run.names.ticket(number))
@@ -258,12 +275,11 @@ def _checked_landing(ticket: Ticket, slot: str, run: Run, may_resolve: bool, rul
258
275
  landing = _merge_commit(ticket, slot, run, tip, may_resolve)
259
276
  _refused(number, run, landing, rulings)
260
277
  if landing.commit != landing.pr_tip:
261
- # No gate has seen a merge commit. A fast-forward to a gated tip finds its green record.
262
- # When the checkout fails, the slot is on another commit and the gate refuses to run.
278
+ # The full gate runs on the commit that lands, a fast-forward as well as a merge commit: a fast green record
279
+ # does not count. When the checkout fails, the slot is on another commit and the gate refuses to run.
263
280
  git(slot, "checkout", "-q", "--detach", landing.commit)
264
- if record := run.red_gate(number, slot, landing.commit):
265
- _red_landing(number, slot, run, rulings, record)
266
- raise Blocked(f"the gate is red on {landing.commit[:7]}, record {record}")
281
+ if record := run.red_gate(number, slot, landing.commit, driver_gate.FULL):
282
+ _red_landing(number, slot, run, rulings, landing.commit, record)
267
283
  return landing
268
284
 
269
285
 
@@ -354,10 +370,15 @@ def _run_ticket(ticket: Ticket, slot_number: int, run: Run) -> bool:
354
370
  try:
355
371
  _run_roles(ticket, slot_number, run)
356
372
  if not run.args.only:
357
- # A ticket that an earlier run left in `merge` has passed its review.
358
- if run.state.read()["tickets"][number]["phase"] != "merge":
359
- driver_fixloop.run(ticket, slot, run, _prompt_values(ticket, slot, run))
360
- _merge(ticket, slot, run)
373
+ while True:
374
+ # A ticket that an earlier run left in `merge` has passed its review.
375
+ if run.state.read()["tickets"][number]["phase"] != "merge":
376
+ driver_fixloop.run(ticket, slot, run, _prompt_values(ticket, slot, run))
377
+ try:
378
+ _merge(ticket, slot, run)
379
+ break
380
+ except driver_fixloop.Unlanded:
381
+ pass # the merge lock is released and the next fix round has started: its fixer runs now
361
382
  except Blocked as blocked:
362
383
  _block(number, run, ledger(f"Ticket {number}: BLOCKED at {blocked}."))
363
384
  print(f"{ticket.file}: BLOCKED at {blocked}")
@@ -602,8 +623,11 @@ def _arguments(argv: list[str] | None) -> argparse.Namespace:
602
623
  defaults = ", ".join(f"{role} {minutes}" for role, minutes in driver_agents.TIMEOUTS.items())
603
624
  parser = _Parser(prog="implement-spec", description="Validate tickets and preconditions, then walk the graph.")
604
625
  parser.add_argument("--tickets", default=".agent/tickets", help="directory of NN-name.md ticket files")
605
- parser.add_argument("--gate", help="the repo's check command (required); the driver runs it on each commit it "
606
- "is about to trust, with IMPLEMENT_SPEC_BASE set to the PR branch")
626
+ parser.add_argument("--gate", help="the full gate: the repo's whole check command (required); the driver runs it "
627
+ "on each commit that would land and at the end of the run, with IMPLEMENT_SPEC_BASE set to "
628
+ "the PR branch")
629
+ parser.add_argument("--fast-gate", help="the fast gate: the ticket's locked tests, lint and types (required); the "
630
+ "driver runs it on each candidate before its review, and the agents run it on their work")
607
631
  parser.add_argument("--spec", help="the spec file the prompts point at (required without --dry-run)")
608
632
  parser.add_argument("--models", help="JSON file: one ordered list of provider/model@effort per role, "
609
633
  "on top of the skill's models.json")
@@ -646,13 +670,20 @@ def _worktree_errors(slot_1_is_kept: bool) -> list[str]:
646
670
  return errors
647
671
 
648
672
 
649
- def _validated(args: argparse.Namespace) -> tuple[list[Ticket], dict[str, list[str]], dict[str, int]] | None:
650
- """(the tickets, the models, the kept slots) of a valid call, or None with each error printed."""
651
- errors = [] if args.gate else ["--gate is required: the command the driver runs as the gate"]
673
+ def _argument_errors(args: argparse.Namespace) -> list[str]:
674
+ errors = [] if args.gate else ["--gate is required: the command the driver runs as the full gate"]
675
+ if not args.fast_gate:
676
+ errors.append("--fast-gate is required: the command the driver and the agents run as the fast gate")
652
677
  if not (args.spec or args.dry_run):
653
678
  errors.append("--spec is required: the spec file the prompts point at")
654
679
  if args.parallel < 1:
655
680
  errors.append("--parallel must be 1 or more")
681
+ return errors
682
+
683
+
684
+ def _validated(args: argparse.Namespace) -> tuple[list[Ticket], dict[str, list[str]], dict[str, int]] | None:
685
+ """(the tickets, the models, the kept slots) of a valid call, or None with each error printed."""
686
+ errors = _argument_errors(args)
656
687
  kept = driver_state.kept(driver_state.State(STATE).read()) if STATE.exists() else {}
657
688
  errors += _worktree_errors(1 in kept.values())
658
689
  models, model_errors = driver_agents.load_models(args.models)
@@ -109,7 +109,7 @@ def finish_interrupted_move(state: State, pr: str) -> None:
109
109
  def _prompt_values(run: Run) -> dict[str, str]:
110
110
  """The pointers every prompt of the end of run gets. Its agents work in slot 1, the PR worktree."""
111
111
  return {"spec": run.args.spec, "tickets": run.args.tickets, "pr_branch": run.pr, "branch": run.pr,
112
- "gate": run.args.gate}
112
+ "gate": run.args.fast_gate}
113
113
 
114
114
 
115
115
  def _title(finding: dict) -> str:
@@ -182,21 +182,26 @@ def _files_in_conflict() -> list[str]:
182
182
  return git(".", "diff", "--name-only", "--diff-filter=U").stdout.split()
183
183
 
184
184
 
185
- def _resolve_rebase_conflict(run: Run, env: dict, base: str, onto: str) -> None:
186
- """Run the conflict agent, once, on the rebase that is open in slot 1, then gate the rebased tip. No rebase is
187
- open afterwards, also when this raises."""
188
- files = _files_in_conflict()
189
- values = {**_prompt_values(run), "branch": "HEAD", "start_sha": onto, "base": base, "files": " ".join(files)}
190
- error = ""
185
+ def _run_rebase_conflict_agent(run: Run, env: dict, values: dict) -> str:
186
+ """Run the conflict agent on the open rebase and continue the rebase it resolved. Returns "" or why it blocked."""
191
187
  try:
192
188
  run.agent("conflict", FINAL, ".", values, template="rebase-conflict", detached=True)
193
189
  except Blocked as blocked:
194
- error = str(blocked)
190
+ return str(blocked)
195
191
  except Halted:
196
192
  git(".", "rebase", "--abort")
197
193
  raise
198
- if not error and _rebase_is_open(): # the agent resolved the files and did not go on
194
+ if _rebase_is_open(): # the agent resolved the files and did not go on
199
195
  subprocess.run(["git", "-c", "core.editor=true", "rebase", "--continue"], capture_output=True, env=env)
196
+ return ""
197
+
198
+
199
+ def _resolve_rebase_conflict(run: Run, env: dict, base: str, onto: str) -> None:
200
+ """Run the conflict agent, once, on the rebase that is open in slot 1, then gate the rebased tip. No rebase is
201
+ open afterwards, also when this raises."""
202
+ files = _files_in_conflict()
203
+ values = {**_prompt_values(run), "branch": "HEAD", "start_sha": onto, "base": base, "files": " ".join(files)}
204
+ error = _run_rebase_conflict_agent(run, env, values)
200
205
  if _rebase_is_open():
201
206
  again = _files_in_conflict()
202
207
  git(".", "rebase", "--abort")
@@ -209,7 +214,7 @@ def _resolve_rebase_conflict(run: Run, env: dict, base: str, onto: str) -> None:
209
214
  raise Blocked(f"the conflict agent: {error}")
210
215
  ledger(f"Rebase: the conflict agent resolved the conflict with {base} in {', '.join(files)} at {head('.')[:7]}.")
211
216
  with during("the gate after the rebase"):
212
- run.gate(FINAL, ".", head("."))
217
+ run.gate(FINAL, ".", head("."), driver_gate.FULL)
213
218
 
214
219
 
215
220
  def _rebase(run: Run, tip: str, base: str, onto: str) -> None:
@@ -370,7 +375,7 @@ def _review(run: Run, final: dict, tip: str) -> None:
370
375
  """One round of the final review on `tip`: the full review, or after it the scoped one."""
371
376
  done, folder = final["round"], OUT / FINAL
372
377
  values = {**_prompt_values(run), "start_sha": tip, "range": f"{final['reviewed'] or final['onto']}..{tip}",
373
- "gate": str(driver_gate.record_path(folder, tip)), "review_diff": str(REVIEW_DIFF),
378
+ "gate": str(driver_gate.record_path(folder, driver_gate.FULL, tip)), "review_diff": str(REVIEW_DIFF),
374
379
  "ledger": str(OUT / "ledger.md"), "carried": _carried_findings(), "reviewed": str(final["reviewed"]),
375
380
  "must_fix_list": "\n".join(f"- {_title(finding)}" for finding in final["must_fix"]),
376
381
  "rulings": "\n".join(driver_decisions.rulings(run.state.read()["run"]["questions"])),
@@ -381,18 +386,28 @@ def _review(run: Run, final: dict, tip: str) -> None:
381
386
  with during("the final review"):
382
387
  report = run.read_only(FINAL, ".", run.pr, tip, lambda: run.agent(
383
388
  "final-reviewer", FINAL, ".", values, notes=["final-scoped"] if done else [], fix_round=done))
389
+ _settle_review(run, done, tip, values["range"], _round_findings(final, found + report["findings"],
390
+ _carried_must_fix(final, done, report)))
391
+
392
+
393
+ def _carried_must_fix(final: dict, done: int, report: dict) -> list[dict]:
394
+ """The must-fix findings that stay open after the round: all of them after the full review, else those the
395
+ scoped review did not resolve."""
384
396
  if not done:
385
- carried = final["must_fix"]
386
- else:
387
- resolved = set(report.get("resolved_must_fix", []))
388
- carried = [finding for finding in final["must_fix"] if _title(finding) not in resolved]
397
+ return final["must_fix"]
398
+ resolved = set(report.get("resolved_must_fix", []))
399
+ return [finding for finding in final["must_fix"] if _title(finding) not in resolved]
400
+
401
+
402
+ def _round_findings(final: dict, found: list[dict], carried: list[dict]) -> list[dict]:
403
+ """The findings of the round: each one `found`, a must-fix one with its ticket, then each `carried` one that
404
+ was not found again."""
389
405
  must_by_key = {(finding["file"], finding["title"]): finding for finding in final["must_fix"]}
390
406
  reported = [{**finding, "must_fix": True, "ticket": must_by_key[key]["ticket"]} if
391
407
  (key := (finding["file"], finding["title"])) in must_by_key else finding
392
- for finding in found + report["findings"]]
408
+ for finding in found]
393
409
  identity = {(finding["file"], finding["title"]) for finding in reported}
394
- _settle_review(run, done, tip, values["range"], reported + [finding for finding in carried
395
- if (finding["file"], finding["title"]) not in identity])
410
+ return reported + [finding for finding in carried if (finding["file"], finding["title"]) not in identity]
396
411
 
397
412
 
398
413
  def _fix_commit_message(commit: str, report: dict) -> str:
@@ -460,7 +475,7 @@ def _review_until_reviewed(run: Run, tickets: list[Ticket]) -> None:
460
475
  if final["reviewed"] != tip:
461
476
  _check_review_is_due(run, final, tip)
462
477
  with during("the gate"):
463
- run.gate(FINAL, ".", tip)
478
+ run.gate(FINAL, ".", tip, driver_gate.FULL)
464
479
  _review(run, final, tip)
465
480
  elif final["open"]:
466
481
  if final["round"] >= ROUNDS:
@@ -492,6 +507,19 @@ def _facts(run: Run, final: dict, tickets: list[Ticket]) -> str:
492
507
  "scoped": f"{final['tidied']}..{tip}" if fixes else "not needed"})
493
508
 
494
509
 
510
+ def _run_pr_writer(run: Run, tip: str, risk: Path, values: dict) -> str:
511
+ """Run the pr-writer, and once more with the errors of its merge-risk block. Returns the body it wrote."""
512
+ for round_ in range(2):
513
+ with during("the PR body"):
514
+ report = run.read_only(FINAL, ".", run.pr, tip,
515
+ lambda: run.agent("pr-writer", FINAL, ".", values, fix_round=round_))
516
+ if not (errors := _risk_errors(risk, report["body"])):
517
+ return report["body"]
518
+ values["risk_errors"] = (f"Your previous body has an invalid merge-risk block. Fix it with the pr-risk "
519
+ f"skill; its errors:\n{errors}\n")
520
+ raise Blocked(f"the merge-risk block of the PR body is invalid after a second run of the pr-writer: {errors}")
521
+
522
+
495
523
  def _write_body(run: Run, final: dict, tickets: list[Ticket]) -> Path:
496
524
  """Write the PR body: what the pr-writer wrote with the method of the pr skill, then the facts of the run. A body
497
525
  written for the reviewed tip is kept when its merge-risk block still validates, so a PR that failed to open costs
@@ -507,19 +535,9 @@ def _write_body(run: Run, final: dict, tickets: list[Ticket]) -> Path:
507
535
  raise Blocked(f"the pr-risk skill is missing: the PR body carries its merge-risk block; install it with "
508
536
  f"{PR_RISK_INSTALL}")
509
537
  values = {**_prompt_values(run), "start_sha": tip, "range": f"{final['onto']}..{tip}",
510
- "gate": str(driver_gate.record_path(OUT / FINAL, tip)), "pr_skill": str(method),
538
+ "gate": str(driver_gate.record_path(OUT / FINAL, driver_gate.FULL, tip)), "pr_skill": str(method),
511
539
  "pr_risk_skill": str(risk), "risk_errors": "", "facts": facts}
512
- for round_ in range(2): # the pr-writer gets one more run with the errors of the block
513
- with during("the PR body"):
514
- report = run.read_only(FINAL, ".", run.pr, tip,
515
- lambda: run.agent("pr-writer", FINAL, ".", values, fix_round=round_))
516
- if not (errors := _risk_errors(risk, report["body"])):
517
- break
518
- values["risk_errors"] = (f"Your previous body has an invalid merge-risk block. Fix it with the pr-risk "
519
- f"skill; its errors:\n{errors}\n")
520
- else:
521
- raise Blocked(f"the merge-risk block of the PR body is invalid after a second run of the pr-writer: {errors}")
522
- body.write_text(f"{report['body'].strip()}\n\n{facts}")
540
+ body.write_text(f"{_run_pr_writer(run, tip, risk, values).strip()}\n\n{facts}")
523
541
  run.state.update(lambda state: state["run"]["final"].update(body=tip))
524
542
  return body
525
543
 
@@ -537,19 +555,27 @@ def _open_pr(run: Run, final: dict, tickets: list[Ticket]) -> str:
537
555
  return url
538
556
 
539
557
 
558
+ def _require_signed(run: Run, tip: str) -> None:
559
+ """Block the push when commit.gpgsign is on and a commit that origin lacks has no good signature."""
560
+ if bad := driver_merge.unsigned(tip):
561
+ raise Blocked(f"commit.gpgsign is on but {len(bad)} commit{'s' if len(bad) > 1 else ''} of {run.pr} "
562
+ f"{'have' if len(bad) > 1 else 'has'} no good signature ({', '.join(bad)}): nothing is pushed")
563
+
564
+
540
565
  def _push(run: Run, final: dict, tickets: list[Ticket]) -> list[str]:
541
566
  """Push the reviewed tip to origin, once and with no force, then open the PR, once. Returns the lines for the
542
567
  operator."""
543
568
  tip = final["reviewed"]
544
- if tip != run.tip() or tip not in final["green_gates"]:
545
- raise Blocked(f"the reviewed tip {tip[:7]} is not the tip of {run.pr} with a green gate record: nothing is "
546
- "pushed")
569
+ if tip != run.tip() or tip not in final["green_gates"][driver_gate.FULL]:
570
+ raise Blocked(f"the reviewed tip {tip[:7]} is not the tip of {run.pr} with a green full gate record: nothing "
571
+ "is pushed")
547
572
  if not final["base"]:
548
573
  raise Blocked(f"the end of run tidied {run.pr} when the repository had no origin remote, so it is on no base "
549
574
  "branch of origin: nothing is pushed")
550
575
  if not shutil.which("gh"):
551
576
  raise Blocked("gh is not on PATH: nothing is pushed")
552
577
  if final["pushed"] != tip:
578
+ _require_signed(run, tip)
553
579
  # The commit, not the branch name: what leaves the machine is the tip the review covered.
554
580
  sent = git(".", "push", "-q", "origin", f"{tip}:refs/heads/{run.pr}")
555
581
  if sent.returncode: