@jesdi/skills 0.0.99 → 0.0.100

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 (42) hide show
  1. package/package.json +1 -1
  2. package/skills/implement-spec/ARCHITECTURE.md +7 -4
  3. package/skills/implement-spec/README.md +38 -14
  4. package/skills/implement-spec/SKILL.md +2 -0
  5. package/skills/implement-spec/driver.py +136 -30
  6. package/skills/implement-spec/driver_agents.py +13 -0
  7. package/skills/implement-spec/driver_arbiter.py +57 -11
  8. package/skills/implement-spec/driver_decisions.py +186 -49
  9. package/skills/implement-spec/driver_dispute.py +1 -1
  10. package/skills/implement-spec/driver_final.py +219 -232
  11. package/skills/implement-spec/driver_final_gate.py +1 -1
  12. package/skills/implement-spec/driver_legacy.py +15 -2
  13. package/skills/implement-spec/driver_overturn.py +106 -0
  14. package/skills/implement-spec/driver_pr.py +277 -0
  15. package/skills/implement-spec/driver_report.py +9 -4
  16. package/skills/implement-spec/driver_review.py +10 -4
  17. package/skills/implement-spec/driver_run.py +33 -14
  18. package/skills/implement-spec/driver_slots.py +33 -0
  19. package/skills/implement-spec/driver_state.py +29 -16
  20. package/skills/implement-spec/driver_summary.py +10 -3
  21. package/skills/implement-spec/prompts/arbiter.md +8 -4
  22. package/skills/implement-spec/prompts/conflict.md +1 -1
  23. package/skills/implement-spec/prompts/pr-body.md +1 -1
  24. package/skills/implement-spec/recovery.md +4 -4
  25. package/skills/implement-spec/tests/conftest.py +1 -0
  26. package/skills/implement-spec/tests/test_arbiter.py +74 -17
  27. package/skills/implement-spec/tests/test_arbitration.py +1 -1
  28. package/skills/implement-spec/tests/test_decisions.py +30 -6
  29. package/skills/implement-spec/tests/test_driver.py +9 -1
  30. package/skills/implement-spec/tests/test_final.py +20 -3
  31. package/skills/implement-spec/tests/test_fixloop.py +1 -1
  32. package/skills/implement-spec/tests/test_leave_out.py +203 -0
  33. package/skills/implement-spec/tests/test_legacy.py +25 -0
  34. package/skills/implement-spec/tests/test_lenses.py +6 -4
  35. package/skills/implement-spec/tests/test_overturn.py +362 -0
  36. package/skills/implement-spec/tests/test_scoped.py +6 -5
  37. package/skills/implement-spec/tests/test_ship_draft.py +203 -0
  38. package/skills/implement-spec/tests/test_slots.py +29 -0
  39. package/skills/implement-spec/tests/test_state.py +4 -2
  40. package/skills/implement-spec/tests/test_stops.py +19 -4
  41. package/skills/implement-spec/tests/test_tidy.py +4 -2
  42. 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.99",
3
+ "version": "0.0.100",
4
4
  "description": "jesdi's agent skills (content package consumed by @jesdi/skills-cli)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,8 +14,9 @@ A comment in the code is for a line that looks wrong or removable without it.
14
14
  | `driver_run.py` | `Run` (what all ticket threads share), one agent with its one rerun, the gate call, the ledger, `Blocked` |
15
15
  | `driver_fixloop.py` | A gated ticket tip in, a reviewed tip out: review, test-writer correction, fix rounds |
16
16
  | `driver_dispute.py` | A disputed locked test: the arbitration, its correction, the once-per-test record, `spec-ambiguous` |
17
- | `driver_arbiter.py` | The arbiter agent that rules on the open questions the driver's retries leave (`driver_decisions.arbitrated`) |
18
- | `driver_final.py` | The end of run: tidy, rebase, gate, final review, one fix batch, push |
17
+ | `driver_arbiter.py` | The arbiter agent that rules on the open questions the driver's retries leave (`driver_decisions.arbitrated`), in a checkout of its own |
18
+ | `driver_final.py` | The end of run: tidy, rebase, gate, final review, one fix batch, push; a ticket that lands after the tidy (`replay`, `landed_after_tidy`) |
19
+ | `driver_pr.py` | The PR: its body (the pr-writer's part and the facts), its opening, once, and the body written again while it is open |
19
20
  | `driver_tickets.py`, `driver_graph.py` | Ticket files in, tickets or errors out; which tickets can start now |
20
21
  | `driver_agents.py` | Model entries, the CLI command of each provider, prompt templates, the blocking launch |
21
22
  | `driver_report.py` | Validation of one agent report against its schema, git and the agent's log |
@@ -27,7 +28,8 @@ A comment in the code is for a line that looks wrong or removable without it.
27
28
  | `driver_state.py` | `state.json` (the resume contract) and the kernel lock |
28
29
  | `driver_names.py` | The names of one run: its ticket branches, its recovery ref and its lock file |
29
30
  | `driver_legacy.py` | The take-over of a run that an older driver started; delete it when no such run is left |
30
- | `driver_decisions.py`, `driver_answers.py`, `driver_review_page.py` | Operator questions, their answers, the page that shows them |
31
+ | `driver_decisions.py`, `driver_answers.py`, `driver_review_page.py` | Operator questions, their answers, the page that shows them; who took a ruling (`ruled_by`); the tickets left out of the run (`left_out`) |
32
+ | `driver_overturn.py` | Which overturn of a ruling of the driver or the arbiter takes effect (`--answer` on an answered question) |
31
33
  | `driver_tidy.py`, `driver_summary.py` | The history with one commit per ticket; `summary.md` |
32
34
 
33
35
  `driver.py`, `driver_fixloop.py`, `driver_dispute.py` and `driver_final.py` decide what comes next. The other modules do one thing
@@ -107,6 +109,7 @@ and do not know about the run, except `driver_run.py`, which the deciding module
107
109
  that origin has is never rewritten. `refs/implement-spec/<key>/recovery` holds the tip before the rewrite.
108
110
  - A rewrite never changes a file: the driver compares trees (`driver_tidy.same_tree`) before it moves the branch.
109
111
  - The push sends the reviewed commit, not the branch name, with no force. It refuses a commit that `origin` lacks with no good signature (when `commit.gpgsign` is on) or with a `Co-authored-by` trailer (`driver_merge.unpushable`).
112
+ - A `ship-draft` answer, the operator's or the driver's, is recorded once where answers are settled (`driver._settle` adds `driver_final.ship_record` to the fields of the end-of-run record): `run.final.ship` holds the gated tip and the stops, each with the role of its question. The review loop, the push, the body and the draft reason read that record, never the questions again; the push refuses when the branch moved from the recorded tip. The driver's own policy for an end-of-run stop is `driver_final.draft_ruling`: no `ship-draft` while a critical or must-fix finding is open that no operator ruling ships.
110
113
 
111
114
  ### Work is never dropped
112
115
 
@@ -166,7 +169,7 @@ and do not know about the run, except `driver_run.py`, which the deciding module
166
169
  lists have one: it is a preference, not a check. When the config has none, or the preflight
167
170
  (`driver_agents.preflight`) leaves none because each such entry failed it, the lens falls back to the
168
171
  `final-reviewer` entries that are left. The ledger says so, and the
169
- PR body's Review coverage (`driver_final._review_providers`) names the entries each review ran on, read from
172
+ PR body's Review coverage (`driver_pr._review_providers`) names the entries each review ran on, read from
170
173
  `run.agents`, so a fallback that a later invocation undid is not claimed. `driver_final._run_lenses` runs them at the same time in slot 1 inside one
171
174
  `Run.read_only`, so a lens that changes the slot makes all three run again. A lens that stops or is rejected
172
175
  twice stops the round only after every lens has ended, with one `final-ticket-blocked` question for each such lens
@@ -40,9 +40,10 @@ A driver before this change named the ticket branches `ticket/<NN>` and the reco
40
40
  | `--parallel N` | The number of tickets in flight at once. Default: 2. |
41
41
  | `--prepare COMMAND` | A shell command that the driver runs once in each new slot 2..N, in `.agent/worktrees/slot-K/`. Use it to install or link the dependencies. |
42
42
  | `--timeout ROLE=MINUTES` | The timeout of one role. Repeatable. The rerun after a timeout gets twice the time. |
43
- | `--answer QUESTION=OPTION` | The answer to one open question. Repeatable. The driver writes it to `.agent/implement-answers.json`. |
43
+ | `--answer QUESTION=OPTION` | The answer to one open question. Repeatable. The driver writes it to `.agent/implement-answers.json`. On a question the driver or the arbiter answered, it overturns that ruling: see "Overturn a ruling". |
44
44
  | `--retries N` | The stops of one ticket, or of the end of run, that the driver answers itself with the recommended option before it asks the operator. Default: `IMPLEMENT_SPEC_RETRIES`, else 2. `0` asks at the first stop. See "The driver rules first". |
45
- | `--ask`, `--no-ask` | Once the driver's retries are spent, ask the operator instead of the arbiter agent. Default: on with `IMPLEMENT_SPEC_ASK=1`, else off. See "The driver rules first". |
45
+ | `--must-fix-retries N` | The more fix batches, beyond `--retries`, that the driver runs itself while a critical or must-fix finding is open (a `finding-must-fix` question), before it asks the operator. Only the stops with such a question count. Default: `IMPLEMENT_SPEC_MUST_FIX_RETRIES`, else 2. See "The driver rules first". |
46
+ | `--ask`, `--no-ask` | Once the driver's retries are spent, ask the operator instead of the arbiter agent, and instead of the `ship-draft` or `leave-out` of the driver. Default: on with `IMPLEMENT_SPEC_ASK=1`, else off. See "The driver rules first". |
46
47
  | `--unattended` | Print no question. Write `--stage-json` for the dispatcher, and push without `--push` when the final review has passed. |
47
48
  | `--stage-json FILE` | With `--unattended`: the file that says how the run ended. |
48
49
  | `--push` | Local mode: when the final review has passed, push the PR branch and open the PR. Without it nothing is pushed. |
@@ -60,9 +61,9 @@ Default timeouts in minutes: test-writer 30, implementer 90, reviewer 45, fixer
60
61
 
61
62
  | Code | Meaning |
62
63
  |---|---|
63
- | 0 | Done: every ticket is merged and no question is open. Also the end of a valid `--dry-run`. In local mode without `--push`, nothing is pushed. |
64
- | 1 | A ticket is BLOCKED, or the end of run is BLOCKED. The other tickets ran as far as they could. |
65
- | 2 | Parked: a question of kind `spec-ambiguous` is open, or one of kind `ticket-blocked` after the driver's own retries are spent (`--retries`), or one of kind `finding-open` that the arbiter did not rule on (`--ask`, or an arbiter that failed). Exit 2 wins over exit 1. |
64
+ | 0 | Done: every ticket is merged, or left out by a `leave-out` ruling, and no question is open. Also the end of a valid `--dry-run`. In local mode without `--push`, nothing is pushed. |
65
+ | 1 | A ticket is BLOCKED and not left out, or the end of run is BLOCKED. The other tickets ran as far as they could. |
66
+ | 2 | Parked: a question of kind `spec-ambiguous` or `ticket-blocked` of a ticket that no one ruled on (`--ask`, an arbiter that failed, or a `leave-out` that would leave out every ticket), or one of kind `ticket-blocked` of the end of run after the driver's own retries are spent (`--retries`) with `--ask` or with no full gate run on the branch tip (a failed rebase conflict agent), or one of kind `finding-open` that the arbiter did not rule on (`--ask`, or an arbiter that failed), or one of kind `finding-must-fix` after the driver's own fix batches are spent (`--retries` and `--must-fix-retries`). Exit 2 wins over exit 1. |
66
67
  | 3 | Invalid input or a failed precondition: a usage error, a ticket error, a model error, an uncommitted change, a slot that cannot be made, another driver that runs on the same PR branch, an open question of a kind this driver no longer has (see "Resume"). No agent starts. The one exception: a review page that cannot be written gives exit 3 at the end of a run, after agents ran. |
67
68
  | 4 | Stopped: the CLI of an agent failed and wrote no report (for example, the account cannot use the model, or its usage ran out). The agent gets no rerun on another entry: the driver starts no other agent and lets the running agents end. No ticket is BLOCKED by it: fix the CLI, or move the role to another entry in a provider config file (see Models), then run the same command again to resume. The preflight of that run skips an entry that still fails. |
68
69
  | 130 | The operator interrupted the run. The driver stops each agent. The work stays in the slots for the next run. |
@@ -73,7 +74,7 @@ With `--unattended`, the `--stage-json` file holds `{"stage": "implement", "stat
73
74
  |---|---|---|
74
75
  | 2 | `awaiting-review` | `artifact` (the review page), `open_questions` (a count) |
75
76
  | 1 | `blocked` | `blocked` (ticket numbers, and `final` for the end of run) |
76
- | 0, pushed | `done` | `draft` (the PR opened as draft), `decisions` (the questions the driver or the arbiter ruled on) |
77
+ | 0, pushed | `done` | `draft` (the PR opened as draft, as it does with a ticket left out), `decisions` (the questions the driver or the arbiter ruled on) |
77
78
 
78
79
  ## Layout
79
80
 
@@ -85,7 +86,7 @@ Everything is under `.agent/`, which is never committed.
85
86
  | `<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. |
86
87
  | `<git common directory>/implement-spec-worktrees.lock` | Shared by driver processes for `worktree`, `checkout`, `switch` and `branch` commands, so a checkout never reads another driver's half-written registration. Held only during that Git command, never during preparation, agents or gates. Git commands outside the driver do not participate. |
87
88
  | `.agent/implement/ledger.md` | One plain sentence for each event. Only the driver writes it, and it reads no fact from it. |
88
- | `.agent/implement/summary.md` | The result in sentences, and the measurement table: fast gates and full gates, agents, wall time, fix rounds, human stops, the stops the driver ruled on, cost. Then `Driver decisions, taken without the operator:` with one ruling sentence for each question the driver answered itself. |
89
+ | `.agent/implement/summary.md` | The result in sentences, and the measurement table: fast gates and full gates, agents, wall time, fix rounds, human stops, the stops the driver ruled on, cost. Then `Driver decisions, taken without the operator:` with the question id and the ruling sentence of each question the driver or the arbiter answered; an overturned one shows the operator's ruling that overturns it. |
89
90
  | `.agent/implement/decisions.json` | The open questions and their `revision`. Written only after a stop. |
90
91
  | `.agent/implement/<NN>/` | One folder for each ticket. |
91
92
  | `.agent/implement/<NN>/<role>-<K>.json`, `.log`, `.prompt.md` | The report, the log and the prompt of one agent. K is the fix round. |
@@ -150,14 +151,14 @@ The full integration gate has its own final repair allowance (see End of run); i
150
151
 
151
152
  ### End of run
152
153
 
153
- The end of run starts only when every ticket is merged and every slot is idle. Its agents work in slot 1.
154
+ The end of run starts only when every ticket is merged and every slot is idle. Its agents work in slot 1. A ticket left out by a `leave-out` ruling does not count, nor any ticket it blocks: the end of run ships the merged tickets, and the PR opens as draft. Its ticket map, and the ledger line of the PR, name the tickets left out.
154
155
 
155
156
  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.
156
157
  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; the integrated tip gets the full gate in the next step. When the agent leaves the rebase open with no conflict, the driver goes on with it, then checks the rebased tip, in place of the commits the report names: a report whose rebased tip changes a locked file of any ticket from the recovery point is rejected, and the rerun fixes that tip with `git commit --amend`. When git cannot go on at the stop the agent resolved (a resolved file it did not stage), the report is rejected with git's error and the agent reruns. A second conflict leaves the branch at its recovery point.
157
158
  3. **Full gate.** A red result saves the exact gate log and sends one repair batch to the final fixer (`prompts/final-gate-fixer.md`). An evidenced no-op is allowed when no code change is needed: it consumes the same repair attempt and reruns the full gate on the unchanged tip. Its commits are attributed to tickets and obey the same locked-file checks as final-review fixes. The driver reruns the full gate on the repaired tip. A second red result asks `final-ticket-blocked` with `retry` or `edit`; retry grants one further repair batch using the saved log. This allowance is independent of completed-ticket rounds and final-review rounds. Only a green integrated tip starts the **final review**: three agents at the same time in slot 1, one for each lens of the `review-diff` method, on the whole range, each with the one lens prompt `prompts/final-lens.md` and its own method lines in it. `final-spec` follows review-diff's `spec.md` with the run's spec; `final-correctness` has review-diff's `correctness.md` inlined, reads files from git at the reviewed tip and runs no tests; `final-structure` follows the `deep-quality-review` skill. `final-spec` and `final-structure` run on the first `final-reviewer` entry, `final-correctness` on the first `final-reviewer` entry on another provider than the first `implementer` entry, or on the first `final-reviewer` entry when there is none. Each reads the driver's full gate record of the reviewed tip as its gate evidence and runs no gate. Each gets ticket observations, minor findings, the must-fix list and the rulings of the operator, writes its own report and never sees another's. The driver merges their findings into one `findings-0.json`: each finding has a `source` (`spec`, `correctness` or `structure`), and two findings with the same file, line and title are one, the more severe one, or on a tie the earlier one in the order spec, correctness, structure. The ledger line of each finding names its source. A lens that stops or is rejected runs once more on the next entry; when the rerun stops or is rejected too, the round stops once the other lenses have ended, no fix batch runs, and the end of run asks `final-ticket-blocked-<n>`. The driver keeps each accepted lens report with the tip it covers (`run.final.lenses`): the next review of that tip runs only the lenses with no kept report, and a review of another tip runs all three. A lens that changes the slot makes all three run again.
158
159
  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`. A report whose commits change a locked file of any ticket from the tidied tip is rejected naming the file, so the fixer runs once more on its next `fixer` entry. 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 **final-reviewer** (`prompts/final-reviewer.md`), one agent on the entry of `final-correctness`, so on another provider than the first `implementer` entry when the lists have one. It reads the merged findings, checks that each critical and important one is fixed and that the fix commits break nothing else, and lists each must-fix item it verified in `resolved_must_fix`; a must-fix item it leaves out stays open. The driver runs no fast gate at the end of the run.
159
- 5. Each critical or important finding the scoped review leaves open, a must-fix item too, asks one `final-finding-open-<n>` question, and nothing is pushed while one is open. `retry` runs one more fix batch and one more scoped review on the open findings that no answer ships with; `accept` and `follow-up` ship the PR with the finding. A finding once shipped asks no question again in the run. There is no third review unless a `retry` asks for one.
160
- 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`: as draft when a critical or must-fix finding that a ruling shipped is open, ready for review otherwise, and the ledger says why. Once the pr-writer's body is valid and before it opens the PR, it files each finding answered `follow-up` as an issue with `gh issue create`, and the PR body's rulings and `summary.md` link the issue. The issue body carries a marker of the run and the question; a run that stopped before it kept the URL finds the issue by that marker instead of filing it twice. A local run without `--push` files nothing. 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`.
160
+ 5. Each important finding the scoped review leaves open asks one `final-finding-open-<n>` question, and each critical or must-fix one a `final-finding-must-fix-<n>` question, all in one stop; nothing is pushed while one is open. `retry` runs one more fix batch and one more scoped review on the open findings that no answer ships with; `accept` and `follow-up` ship the PR with the finding: as draft when the arbiter ruled it, ready for review when the operator did. A finding once shipped asks no question again in the run, unless the driver or the arbiter shipped it and a later scoped review rates it critical or must-fix: only the operator's answer ships such a finding, so it asks `finding-must-fix`. There is no third review unless a `retry` asks for one.
161
+ 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`: as draft when a finding that an agent's ruling shipped is open, ready for review otherwise (the operator's own `accept` or `follow-up` keeps it ready), and the ledger says why. After a `ship-draft` ruling it pushes instead the branch tip that a full gate ran on, green or red, as draft; the review coverage of the body names the commits after the reviewed tip that no review covered. The ruling, the operator's or the driver's, records that tip and the stops once (`run.final.ship`), and the push reads only that record: a run stopped between the ruling and the push pushes the recorded tip, and refuses, pushing nothing, when the branch moved from it. Once the pr-writer's body is valid and before it opens the PR, it files each finding answered `follow-up` as an issue with `gh issue create`, and the PR body's rulings and `summary.md` link the issue. The issue body carries a marker of the run and the question; a run that stopped before it kept the URL finds the issue by that marker instead of filing it twice. A local run without `--push` files nothing. 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`.
161
162
 
162
163
  History rules:
163
164
 
@@ -231,15 +232,16 @@ For each role that commits, every commit in `commits` must be new since the role
231
232
 
232
233
  ### The driver rules first
233
234
 
234
- A stop whose question recommends `retry` does not park the run, and neither does an open final finding once the retries are spent. The driver answers it with `retry`, the one option it may take itself, writes the same `Ruling:` sentence an operator's answer writes, ending in `Ruled by the driver, not the operator.`, and goes on in the same process, as the next invocation would after `--answer`. Today that is `retry` for `ticket-blocked`; `spec-ambiguous` recommends no option, so it still asks. The driver rules on at most `--retries` stops (default 2) of one ticket, and as many of the end of run. The next stop of that ticket asks the operator, with exit 2; but a `finding-open` question goes to the **arbiter** (`prompts/arbiter.md`), unless `--ask`. The arbiter is one read-only agent on the first `arbiter` entry on another provider than the first `implementer` entry (else the first `arbiter` entry). It reads each finding's evidence and the ledger and rules `accept` or `follow-up` with a reason and the cost if it is wrong; its ruling ends in `Ruled by the arbiter, not the operator: <reason>. Cost if wrong: <cost>.` An arbiter whose rerun fails too leaves the questions to the operator, with a ledger line. `edit` is not an option of `finding-open`: editing the spec is what the operator does after the run. The operator reads the rulings of the driver and the arbiter where the run ends: in `summary.md` under `Driver decisions, taken without the operator:` and in the PR body with the other rulings. On the box, 23 answers of 23 were `retry` and each waited hours for the operator (jesdi/agent-ops retro, 2026-11-14).
235
+ A stop whose question recommends `retry` does not park the run, and neither does an open final finding once the retries are spent. The driver answers it with `retry`, the one option it may take itself, writes the same `Ruling:` sentence an operator's answer writes, ending in `Ruled by the driver, not the operator.`, and goes on in the same process, as the next invocation would after `--answer`. Today that is `retry` for `ticket-blocked`; `spec-ambiguous` recommends no option. The driver rules on at most `--retries` stops (default 2) of one ticket, and as many of the end of run. Once they are spent, a stop of a ticket does not park, unless `--ask`: the driver answers it `leave-out`. The ticket is left out of the run, with each ticket it blocks, and the merged tickets go on to the end of run and a draft PR, with exit 0. A `spec-ambiguous` question goes to the arbiter first, which rules `keep-test` or `correct-test` (never `edit-spec`) on at most `--retries` stops of one ticket; the next one leaves the ticket out. A `leave-out` that would leave out every ticket is not taken, so that stop still asks. The uncommitted work a left-out ticket left in its slot is saved as `.agent/implement/<NN>/left-out.patch`, or `left-out-2.patch` and on when one is there already, written whole before the slot is reset (`git apply` puts it back on the ticket branch, which stays), and the slot goes back to the other tickets with a clean tree. The arbiter runs in a checkout of its own, `.agent/worktrees/arbiter`, on the PR tip, which the driver makes for it and removes after it through Git alone, so a locked worktree or a directory that is no worktree there stops the arbiter and loses nothing: slot 1 may hold a stopped ticket's work. Once they are spent, an end-of-run `ticket-blocked` stop (an end-of-run agent that failed twice, or a full gate still red after its repair) does not park either, unless `--ask`: the driver answers it `ship-draft` when a full gate ran on the branch tip and no critical or must-fix finding is open that no ruling of the operator ships, and the run ends with exit 0 and a draft PR, which no agent merges. A failed rebase conflict agent leaves no such tip, so it still asks, and so does a stop while such a finding is open, including one whose fix batch landed but no later review verified (the last settled review's findings file holds it) and, before any review settled, one in a lens report already accepted or a must-fix finding carried from a ticket; the operator may still answer `ship-draft`. The next stop of that ticket asks the operator, with exit 2; but a `finding-open` question goes to the **arbiter** (`prompts/arbiter.md`), unless `--ask`. A critical or must-fix finding asks `finding-must-fix` instead, which never goes to the arbiter: no agent ships it. The driver answers it `retry` at `--retries` plus `--must-fix-retries` stops of the end of run (default 2 and 2), counting only the stops with a `finding-must-fix` question, then asks the operator, the only one who may ship it; in the same stop the arbiter still rules on the `finding-open` questions. The arbiter is one read-only agent on the first `arbiter` entry on another provider than the first `implementer` entry (else the first `arbiter` entry). It reads each finding's evidence and the ledger and rules `accept` or `follow-up`, or on a `spec-ambiguous` question `keep-test` or `correct-test`, with a reason and the cost if it is wrong; either ruling opens the PR as draft; its ruling ends in `Ruled by the arbiter, not the operator: <reason>. Cost if wrong: <cost>.` An arbiter whose rerun fails too leaves the questions to the operator, with a ledger line. `edit` is not an option of `finding-open`: editing the spec is what the operator does after the run. The operator reads the rulings of the driver and the arbiter where the run ends: in `summary.md` under `Driver decisions, taken without the operator:` and in the PR body with the other rulings, and may overturn any of them after the run (see "Overturn a ruling"). On the box, 23 answers of 23 were `retry` and each waited hours for the operator (jesdi/agent-ops retro, 2026-11-14).
235
236
 
236
237
  A question is a bounded choice for the operator. `driver_decisions.py` `KINDS` holds each kind with its fixed sentences.
237
238
 
238
239
  | Kind | Question id | Asked when | Run exit | Options |
239
240
  |---|---|---|---|---|
240
- | `spec-ambiguous` | `<NN>-spec-ambiguous-<n>` | A second dispute on a locked test that the reviewer ruled on in the ticket, or a second correction needed for a locked test of the ticket (a `test-wrong` ruling or a review finding on a test corrected before); or a dispute or a review correction after the ticket's locked tests were settled 3 times. Another test of the same file, or another missing test that a review finding asks for, is no second correction. The subject names the test, the requirement and the two readings; the evidence is `spec-ambiguous-<n>.json`. | 2 | No option is recommended. `keep-test`: the role that disputed runs again against the test; after a review finding, the ticket resumes from the review and later findings with the same key are closed: on that test, a `fixture` finding on that file that names no test, or the same missing test. `correct-test`: one more correction, to the second reading, then the role that disputed runs again (the fixer of the same round after the review of its round); after a review finding, the review runs again. `edit-spec`: the ticket stays BLOCKED, with the ruling in the ledger. None of them changes the ticket's `disputes` or `corrected`. |
241
- | `ticket-blocked` | `<NN>-ticket-blocked-<n>`, `final-ticket-blocked-<n>` | A ticket agent (test-writer, implementer, reviewer, fixer, conflict) or an agent of the end of run stopped with `BLOCKED` or `NEEDS_CONTEXT` or was rejected, and its rerun did too (the same model for a timeout or moved branch, the next entry otherwise); or the integration gate stays red after its repair. The subject names the role and the reason, or the gate. | 2 | `retry` (recommended): the role runs again on its first entry from the tip the ticket left, with its one rerun; for a fixer, the round that stopped does not count: the driver gates and reviews the tip, and a fixer runs that round again on the review's findings. An arbitration or a correction runs for another role, so its work is not kept: after a dispute, the role that disputed runs again from the tip before them; after a review correction, the driver reviews that tip again. For the end of run, the stopped agent runs again from where the end of run is. `edit`: the ticket, or the end of run, stays BLOCKED, with the ruling in the ledger, so the spec or the ticket can be edited. |
242
- | `finding-open` | `final-finding-open-<n>` | A critical or important finding, a must-fix one too, is open after the scoped review of the final fix batch: one question per finding, the subject is the finding as `<title> (<file>)`, with no line, so a fix batch that moves it does not ask again; the evidence is its findings file. | 2 | `retry` (recommended): one more fix batch and scoped review. `accept`: the PR ships with the finding open, listed in its rulings; a critical or must-fix one opens it as draft. `follow-up`: as `accept`, and the driver files the finding as an issue before it opens the PR. |
241
+ | `spec-ambiguous` | `<NN>-spec-ambiguous-<n>` | A second dispute on a locked test that the reviewer ruled on in the ticket, or a second correction needed for a locked test of the ticket (a `test-wrong` ruling or a review finding on a test corrected before); or a dispute or a review correction after the ticket's locked tests were settled 3 times. Another test of the same file, or another missing test that a review finding asks for, is no second correction. The subject names the test, the requirement and the two readings; the evidence is `spec-ambiguous-<n>.json`. | 2 | No option is recommended. `keep-test`: the role that disputed runs again against the test; after a review finding, the ticket resumes from the review and later findings with the same key are closed: on that test, a `fixture` finding on that file that names no test, or the same missing test. `correct-test`: one more correction, to the second reading, then the role that disputed runs again (the fixer of the same round after the review of its round); after a review finding, the review runs again. `leave-out`: the ticket is left out of the run, with each ticket it blocks; the merged tickets get the end of run and a draft PR that names them. The driver takes it once the arbiter ruled on `--retries` stops of the ticket. `edit-spec`: the ticket stays BLOCKED, with the ruling in the ledger. None of them changes the ticket's `disputes` or `corrected`. |
242
+ | `ticket-blocked` | `<NN>-ticket-blocked-<n>`, `final-ticket-blocked-<n>` | A ticket agent (test-writer, implementer, reviewer, fixer, conflict) or an agent of the end of run stopped with `BLOCKED` or `NEEDS_CONTEXT` or was rejected, and its rerun did too (the same model for a timeout or moved branch, the next entry otherwise); or the integration gate stays red after its repair. The subject names the role and the reason, or the gate. | 2 | `retry` (recommended): the role runs again on its first entry from the tip the ticket left, with its one rerun; for a fixer, the round that stopped does not count: the driver gates and reviews the tip, and a fixer runs that round again on the review's findings. An arbitration or a correction runs for another role, so its work is not kept: after a dispute, the role that disputed runs again from the tip before them; after a review correction, the driver reviews that tip again. For the end of run, the stopped agent runs again from where the end of run is. `ship-draft` (end of run only): the driver pushes the branch tip that a full gate ran on, green or red, and opens the PR as draft, naming the stop in the ledger and the PR body; the end of run reviews and repairs no more. With no full gate run on the tip (a failed rebase conflict agent) the answer is refused with exit 3 and the question stays open. When the pr-writer is the stop (the question's `role`), the body is the facts of the driver alone. `leave-out` (a ticket only): as for `spec-ambiguous`; the driver takes it once its retries are spent. `edit`: the ticket, or the end of run, stays BLOCKED, with the ruling in the ledger, so the spec or the ticket can be edited. |
243
+ | `finding-open` | `final-finding-open-<n>` | An important finding is open after the scoped review of the final fix batch: one question per finding, the subject is the finding as `<title> (<file>)`, with no line, so a fix batch that moves it does not ask again; the evidence is its findings file. | 2 | `retry` (recommended): one more fix batch and scoped review. `accept`: the PR ships with the finding open, listed in its rulings: as draft when the arbiter ruled it, ready for review when the operator did. `follow-up`: as `accept`, and the driver files the finding as an issue before it opens the PR. |
244
+ | `finding-must-fix` | `final-finding-must-fix-<n>` | As `finding-open`, for a critical finding or a must-fix one. The arbiter never rules on it. A run of an older driver that asked `finding-open` on such a finding gets the question as this kind, with its id. | 2 | `retry` (recommended): as for `finding-open`. `accept` and `follow-up`: as for `finding-open`, and only the operator may take them. |
243
245
 
244
246
  An older run may hold an open `final-ticket-blocked-<n>` question on a finding: it keeps its `retry` and `edit`.
245
247
 
@@ -247,6 +249,28 @@ An older run may hold an open `final-ticket-blocked-<n>` question on a finding:
247
249
 
248
250
  Answer with `--answer <question id>=<option id>` on the next run, or through the page, which gives `.agent/implement-answers.json`. An answers file counts only when it is submitted and its `revision` equals the `revision` of `decisions.json`. The driver ignores any other file or answer and says so in the ledger. Each answer becomes one `Ruling:` sentence in the ledger.
249
251
 
252
+ ### Overturn a ruling
253
+
254
+ After a run, `--answer <question id>=<other option>` on a question the driver or the arbiter answered overturns that ruling. Only such a ruling is overturned: an answer of the operator is final. The new ruling ends in `It overturns the ruling <option> of the driver.` (or `of the arbiter.`); it goes to the ledger, the PR body and the `Overturned by the operator:` list of `summary.md`, below the `Driver decisions` list, which no longer holds it. It takes effect as an answer to that question would, from where the run is now:
255
+
256
+ - `accept` or `follow-up` to `retry`: one more fix batch and scoped review on the finding, when the last review leaves it open. No agent ships a `finding-must-fix` finding, so the only ruling of one to overturn is the driver's `retry`, which is refused below: an overturn never makes an agent ship it.
257
+ - `accept` to `follow-up`: the driver files the issue; once the PR is open, at the next push. `follow-up` to `accept` keeps an issue filed already. The ship is the operator's now: a PR not open yet opens ready for review, unless a left-out ticket or a `ship-draft` ruling makes it a draft.
258
+ - `leave-out` to `retry`, `keep-test` or `correct-test`: the ticket runs again, and each ticket it blocks after it. After the rewrite of the end of run, its own work (from where its branch leaves the history before the rewrite to its tip) is replayed onto the PR tip as one commit, as the tidy makes one, before it lands, so no commit of the history before the rewrite comes back. A replay that conflicts is open in its slot as a cherry-pick for the conflict agent of the ticket; when that agent stops, the slot goes back to the ticket's tip and its `retry` runs the agent again. A run stopped in a replay replays again from the ticket's tip: its work stays. The full gate and the scoped review cover the tip it lands, even when a `ship-draft` ruling shipped the tip before it, and the final fixers keep every ticket's locked files as that tip has them. It starts from its ticket branch; the uncommitted work it left stays in its `left-out.patch`.
259
+ - `ship-draft` to `retry`: the end of run goes on from its stop: the gate repair, the stopped agent and the review it skipped.
260
+
261
+ The work lands on top of the PR branch, so the push needs no force. An open PR keeps its URL and its draft state: mark it ready for review yourself. Its body is written again with `gh pr edit --body-file` when it changed: the facts of the run (the ticket map, the left-out tickets, the rulings, the coverage), and the pr-writer's part too once a ticket landed after the tidy; else that part stays as it was. `pr-body.md` holds the body GitHub has: a failed edit is made again by the next run. Exit 3, before any agent, refuses an overturn that cannot take effect, and says why:
262
+
263
+ - the PR is merged or closed (`gh pr view --json state`): the work goes onto an open PR only;
264
+ - the question was answered by the operator;
265
+ - the ruling was `retry` or `correct-test`: its work ran, and an overturn undoes no work;
266
+ - the new option is `edit` or `edit-spec`: edit the spec or the ticket, then overturn to an option that runs the work again;
267
+ - a later stop of the same ticket, or of the end of run, followed it: only the newest stop is overturned;
268
+ - the ticket merged since;
269
+ - a `retry` of a finding that the last review leaves closed;
270
+ - a `ship-draft` of a failed pr-writer once the PR is open: edit its body on GitHub.
271
+
272
+ A run that resumes the work of an overturn asks gh again before it pushes or edits the body: a merged or closed PR blocks it, and nothing goes out.
273
+
250
274
  For an older questionless BLOCKED record, see [operator recovery](recovery.md). Recovery requires an explicit verified checkpoint; starting this version never guesses one.
251
275
 
252
276
  ## The non-negotiable checks
@@ -26,6 +26,8 @@ Run the driver. It makes every choice of the run: it answers its own `retry` que
26
26
  2. When it exits, relay `.agent/implement/summary.md`, with its `Driver decisions` list whole, 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`. When the driver opened the PR as a draft, say so and why: no agent merges a draft, so it waits for the operator's review.
27
27
  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.
28
28
 
29
+ 4. To overturn a ruling of the driver or the arbiter from the `Driver decisions` list, the operator gives its question id and another option: run the same command again with `--answer <question id>=<option id>`. The driver says why when it refuses one (exit 3).
30
+
29
31
  Answer no question the driver left open: it has spent its own retries on it. Do not edit `.agent/implement/`, the code or the branches during a run.
30
32
 
31
33
  [README.md](README.md) has each flag, the exit codes, the files of a run and the method.
@@ -15,6 +15,7 @@ import argparse
15
15
  import json
16
16
  import os
17
17
  import re
18
+ import subprocess
18
19
  import sys
19
20
  from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
20
21
  from contextlib import ExitStack
@@ -33,6 +34,7 @@ import driver_graph
33
34
  import driver_legacy
34
35
  import driver_locked
35
36
  import driver_merge
37
+ import driver_overturn
36
38
  import driver_review_page
37
39
  import driver_run
38
40
  import driver_slots
@@ -152,10 +154,18 @@ class _Landing:
152
154
  commit: str # what the PR branch moves to: `pr_tip` (merged already), `ticket_tip` (fast-forward) or a merge
153
155
 
154
156
 
155
- def _resolve_conflict(ticket: Ticket, slot: str, run: Run, tip: str, files: list[str]) -> str:
156
- """Run the conflict agent on the merge that is open in the slot. Returns the new ticket tip."""
157
+ MERGE_OPEN = "The merge of the PR branch into the ticket branch is open in this worktree"
158
+ REPLAY_OPEN = ("The ticket's own work, replayed onto the PR branch after the end of run rewrote it, is open in this "
159
+ "worktree as a cherry-pick")
160
+
161
+
162
+ def _resolve_conflict(ticket: Ticket, slot: str, run: Run, tip: str, files: list[str], opened: str = MERGE_OPEN
163
+ ) -> str:
164
+ """Run the conflict agent on the merge (or the replay, driver_final.replay) that is open in the slot. Returns the
165
+ new ticket tip."""
157
166
  number = ticket.number
158
- values = {**_prompt_values(ticket, slot, run), "start_sha": tip, "pr_sha": run.tip(), "files": " ".join(files)}
167
+ values = {**_prompt_values(ticket, slot, run), "start_sha": tip, "pr_sha": run.tip(), "files": " ".join(files),
168
+ "opened": opened}
159
169
  try:
160
170
  with during("the conflict agent"):
161
171
  run.agent(Call("conflict", number, slot, values))
@@ -196,7 +206,7 @@ def _refuse_breach(number: str, run: Run, landing: _Landing) -> None:
196
206
 
197
207
 
198
208
  def _block_landing(number: str, run: Run, tip: str, error: str) -> None:
199
- run.ask(number, "ticket-blocked", [f"the landing: {error}"], str(STATE),
209
+ run.ask(number, [("ticket-blocked", f"the landing: {error}")], str(STATE),
200
210
  retry_point("implementer", tip, 0))
201
211
  raise Blocked(error)
202
212
 
@@ -213,16 +223,26 @@ def _landing_slot(number: str, slot: str, run: Run, tip: str) -> None:
213
223
  _block_landing(number, run, tip, f"the landing slot has uncommitted work: {status.stdout.strip()}")
214
224
 
215
225
 
226
+ def _restart_replay(slot: str, branch: str, tip: str) -> subprocess.CompletedProcess:
227
+ """A run stopped in a replay (driver_final.replay) before its tip was recorded: the ticket branch goes back to the
228
+ tip the replay started from, and a cherry-pick left open is dropped, so the replay runs again."""
229
+ git(slot, "cherry-pick", "--quit")
230
+ return git(slot, "checkout", "-q", "-f", "-B", branch, tip)
231
+
232
+
216
233
  def _checked_landing(ticket: Ticket, slot: str, run: Run, may_resolve: bool) -> _Landing:
217
234
  """The reviewed commit to land, with locked-file invariants checked. Call it under the merge lock."""
218
235
  number = ticket.number
219
236
  # An earlier try left the slot on its merge commit.
220
237
  branch = run.names.ticket(number)
221
- tip = run.state.ticket(number, phase="merge")["tip"]
222
- checkout = git(slot, "checkout", "-q", branch)
238
+ entry = run.state.ticket(number, phase="merge")
239
+ tip = entry["tip"]
240
+ checkout = _restart_replay(slot, branch, tip) if entry["replayed"] == tip else git(slot, "checkout", "-q", branch)
223
241
  if checkout.returncode:
224
242
  _block_landing(number, run, tip, f"the landing checkout failed: {checkout.stderr.strip()}")
225
243
  _landing_slot(number, slot, run, tip)
244
+ tip = driver_final.replay(ticket, slot, run, tip, lambda start, files: _resolve_conflict(
245
+ ticket, slot, run, start, files, REPLAY_OPEN))
226
246
  landing = _merge_commit(ticket, slot, run, tip, may_resolve)
227
247
  _landing_slot(number, slot, run, landing.ticket_tip)
228
248
  _refuse_breach(number, run, landing)
@@ -250,6 +270,7 @@ def _record_landing(state: dict, number: str, landing: _Landing) -> None:
250
270
  state["tickets"][number]["phase"] = "merged"
251
271
  earlier = [landed for landed in state["run"]["landed"] if landed[0] != number]
252
272
  state["run"]["landed"] = earlier + [[number, pr_tip]]
273
+ driver_final.landed_after_tidy(state, number, pr_tip)
253
274
 
254
275
 
255
276
  def _merge(ticket: Ticket, slot: str, run: Run) -> None:
@@ -442,11 +463,30 @@ def _publish_questions(run: dict) -> str:
442
463
 
443
464
  def _settle(state: driver_state.State, questions: list[dict], answers: dict, ignored: list[str], by: str = "",
444
465
  why: dict[str, str] | None = None) -> None:
445
- """Turn each answer into a ruling and let its ticket go on."""
466
+ """Turn each answer into a ruling and let its ticket go on. A `ship-draft` answer, the operator's or the driver's,
467
+ records once in `run.final.ship` what the end of run ships."""
446
468
  rulings, moved = driver_decisions.apply(questions, answers, by, why)
469
+ if ship := driver_final.ship_record(state.read()["run"], [q for q in questions if q["id"] in answers]):
470
+ moved.setdefault(FINAL, {})["ship"] = ship
471
+ _record(state, questions, rulings, moved, ignored)
472
+
473
+
474
+ def _overturn(questions: list[dict], answers: dict) -> tuple[list[str], dict[str, dict]]:
475
+ """Overturn the rulings `answers` names (driver_decisions.overturn). A `ship-draft` ruling overturned clears
476
+ `run.final.ship`, so the end of run goes on from its stop."""
477
+ shipped = {q["id"] for q in questions if q["answer"] == "ship-draft"}
478
+ rulings, moved = driver_decisions.overturn(questions, answers)
479
+ if shipped & answers.keys():
480
+ moved.setdefault(FINAL, {})["ship"] = None
481
+ return rulings, moved
482
+
483
+
484
+ def _record(state: driver_state.State, questions: list[dict], rulings: list[str], moved: dict[str, dict],
485
+ ignored: list[str] | tuple[str, ...] = ()) -> None:
486
+ """Write the ruling sentences to the ledger, then the questions and the records they let go on to state.json."""
447
487
  # The ledger comes first: a run that stops between the two writes gives a ruling twice, and never an answer
448
488
  # that no ledger line names.
449
- for sentence in ignored + rulings:
489
+ for sentence in [*ignored, *rulings]:
450
490
  ledger(sentence)
451
491
 
452
492
  def change(new: dict) -> None:
@@ -458,31 +498,79 @@ def _settle(state: driver_state.State, questions: list[dict], answers: dict, ign
458
498
 
459
499
 
460
500
  def _apply_answers(state: driver_state.State, args) -> list[str]:
461
- """Turn each answer that counts into a ruling and let its ticket go on; [] or the errors that stop the run."""
501
+ """Turn each answer that counts, and each overturn of a ruling, into a ruling and let its ticket go on; [] or the
502
+ errors that stop the run."""
462
503
  _drop_merged(state)
463
- run = state.read()["run"]
504
+ whole = state.read()
505
+ run = whole["run"]
464
506
  questions, document = run["questions"], driver_decisions.document(run)
465
- if errors := driver_answers.given(args.answer, document):
507
+ answers, overturns = driver_overturn.split(args.answer, document)
508
+ if errors := driver_overturn.refusals(overturns, whole) or driver_answers.given(answers, document):
509
+ return errors
510
+ given, ignored = driver_answers.read(document)
511
+ if errors := driver_final.refused_ship(run, {**given, **dict(overturns)}):
466
512
  return errors
467
- _settle(state, questions, *driver_answers.read(document))
513
+ _record(state, questions, *_overturn(questions, dict(overturns)))
514
+ _settle(state, questions, given, ignored)
468
515
  error = _publish_questions(run)
469
516
  return [error] if error else []
470
517
 
471
518
 
472
- def _rule(run: Run) -> bool:
519
+ def _rule(run: Run, tickets: list[Ticket]) -> bool:
473
520
  """The driver answers each open question that recommends `retry` with it, at most `--retries` stops per ticket and
474
- for the end of run; then, unless `--ask`, the arbiter rules on the questions that are its own. True: one of them
475
- ruled, so the run goes on with no operator."""
521
+ for the end of run, and `--must-fix-retries` more stops with a `finding-must-fix` question; then, unless `--ask`,
522
+ the arbiter rules on the open `finding-open` questions and a ticket's `spec-ambiguous` ones, and else the driver
523
+ rules on an end-of-run stop by its draft policy (driver_final.draft_ruling) and answers a ticket's stop
524
+ `leave-out`. True: one of them ruled, so the run goes on with no operator."""
476
525
  questions = run.state.read()["run"]["questions"]
477
- answers, why, by = driver_decisions.automatic(questions, run.args.retries), {}, driver_decisions.DRIVER
478
- if not (answers or run.args.ask):
479
- answers, why = _arbitrate(run)
480
- by, questions = driver_decisions.ARBITER, run.state.read()["run"]["questions"]
526
+ answers = driver_decisions.automatic(questions, run.args.retries, run.args.must_fix_retries)
527
+ _settle_rulings(run, questions, answers, driver_decisions.DRIVER, {})
528
+ if run.args.ask:
529
+ return bool(answers)
530
+ arbitrated, why = _arbitrate(run)
531
+ _settle_rulings(run, run.state.read()["run"]["questions"], arbitrated, driver_decisions.ARBITER, why)
532
+ if answers or arbitrated:
533
+ return True
534
+ drafted = driver_final.draft_ruling(run)
535
+ _settle_rulings(run, run.state.read()["run"]["questions"], drafted, driver_decisions.DRIVER, {})
536
+ return bool(drafted or _leave_out(run, tickets))
537
+
538
+
539
+ def _leave_out(run: Run, tickets: list[Ticket]) -> dict[str, str]:
540
+ """Answer the open questions of a ticket `leave-out` (driver_decisions.leave_out_answers) and set aside the work of
541
+ each ticket it leaves out. Returns the answers."""
542
+ questions = run.state.read()["run"]["questions"]
543
+ answers = driver_decisions.leave_out_answers(questions, tickets, run.args.retries)
544
+ _settle_rulings(run, questions, answers, driver_decisions.DRIVER, {})
545
+ _set_aside(run, tickets) # an error stops the next pass, which sets aside again
546
+ return answers
547
+
548
+
549
+ def _set_aside(run: Run, tickets: list[Ticket]) -> list[str]:
550
+ """Save the uncommitted work that a left-out ticket left in its slot as a patch next to its reports, and take the
551
+ slot off its branch with a clean tree: the other tickets and the end of run get the slot. [] or the errors that
552
+ stop the run: a slot that git cannot clean stays as it is."""
553
+ state, errors = run.state.read(), []
554
+ for number in sorted(driver_decisions.left_out(state["run"]["questions"], tickets)):
555
+ slot, patch = state["tickets"][number]["slot"], driver_slots.fresh(OUT / number / "left-out.patch")
556
+ if not driver_state.holds_work(state, number):
557
+ continue
558
+ if error := driver_slots.set_aside(driver_slots.path(slot), patch):
559
+ errors.append(f"implement-spec: ticket {number} is left out, but its uncommitted work stays in slot "
560
+ f"{slot}: {error}")
561
+ continue
562
+ run.kept.pop(number, None)
563
+ ledger(f"Ticket {number}: left out; its uncommitted work in slot {slot} is saved as {patch}, and the slot is "
564
+ "free.")
565
+ return errors
566
+
567
+
568
+ def _settle_rulings(run: Run, questions: list[dict], answers: dict, by: str, why: dict[str, str]) -> None:
569
+ """Settle the `answers` that `by`, the driver or the arbiter, gave."""
481
570
  if answers:
482
571
  _settle(run.state, questions, answers, [], by, why)
483
572
  print(f"implement-spec: the {by} ruled on {len(answers)} question{'s' * (len(answers) > 1)} and goes on",
484
573
  flush=True)
485
- return bool(answers)
486
574
 
487
575
 
488
576
  def _arbitrate(run: Run) -> tuple[dict[str, str], dict[str, str]]:
@@ -531,14 +619,21 @@ def _halted_exit(halted: list[str], final: dict) -> int:
531
619
  return 4
532
620
 
533
621
 
534
- def _exit_code(final: dict, args, end_blocked: bool) -> int:
622
+ def _blocked(final: dict, tickets: list[Ticket], end_blocked: bool) -> list[str]:
623
+ """The tickets that end the run BLOCKED, with FINAL when the end of run is: no left-out ticket, which the end of
624
+ run ships without."""
625
+ left = driver_decisions.left_out(final["run"]["questions"], tickets)
626
+ blocked = [number for number, entry in final["tickets"].items()
627
+ if entry["phase"] == "blocked" and number not in left]
628
+ return blocked + [FINAL] * end_blocked
629
+
630
+
631
+ def _exit_code(final: dict, args, tickets: list[Ticket], end_blocked: bool) -> int:
535
632
  """Publish the open questions, tell the operator or the dispatcher, and return the exit code."""
536
633
  if error := _publish_questions(final["run"]):
537
634
  print(error)
538
635
  return 3
539
- blocked = [number for number, entry in final["tickets"].items() if entry["phase"] == "blocked"]
540
- if end_blocked:
541
- blocked.append(FINAL)
636
+ blocked = _blocked(final, tickets, end_blocked)
542
637
  open_questions = driver_decisions.document(final["run"])["questions"]
543
638
  code = 2 if driver_decisions.parked(final["run"]["questions"]) else int(bool(blocked))
544
639
  _tell(args, code, open_questions, blocked, final["run"])
@@ -551,11 +646,16 @@ def _record_skipped(skipped: list[str]) -> None:
551
646
  ledger(sentence)
552
647
 
553
648
 
649
+ def _prepared(tickets: list[Ticket], run: Run, slots: int) -> list[str]:
650
+ """Resume, apply the answers and set aside the work of each left-out ticket: [] or the errors that stop the run."""
651
+ return (_resume(tickets, run.state, run.pr, slots, run.args, run.kept) or _apply_answers(run.state, run.args)
652
+ or _set_aside(run, tickets))
653
+
654
+
554
655
  def _once(tickets: list[Ticket], run: Run, slots: int) -> tuple[bool, list[str]] | int:
555
656
  """Resume, apply the answers and do the work once: what `_work` returns, or exit 3 with each error printed."""
556
657
  args = run.args
557
- errors = _resume(tickets, run.state, run.pr, slots, args, run.kept) or _apply_answers(run.state, args)
558
- if errors:
658
+ if errors := _prepared(tickets, run, slots):
559
659
  print("\n".join(errors))
560
660
  return 3
561
661
  if args.unattended and args.stage_json:
@@ -573,11 +673,11 @@ def _run(tickets: list[Ticket], models: dict[str, list[str]], skipped: list[str]
573
673
  slots = 1 if args.only else min(args.parallel, len(tickets))
574
674
  _record_skipped(skipped)
575
675
  while True:
576
- run = Run(args, models, state, pr, kept)
676
+ run = Run(args, models, state, pr, kept, tickets)
577
677
  done = _once(tickets, run, slots)
578
678
  if isinstance(done, int):
579
679
  return done
580
- if run.halted or not _rule(run):
680
+ if run.halted or not _rule(run, tickets):
581
681
  break
582
682
  # The driver's own answer resumes the run as the operator's would on the next invocation.
583
683
  args.answer, kept = [], driver_state.kept(state.read())
@@ -592,7 +692,7 @@ def _finish(run: Run, args, end_blocked: bool, lines: list[str]) -> int:
592
692
  print(summary + "".join(line + "\n" for line in lines), end="")
593
693
  if run.halted:
594
694
  return _halted_exit(run.halted, final)
595
- return _exit_code(final, args, end_blocked)
695
+ return _exit_code(final, args, run.tickets, end_blocked)
596
696
 
597
697
 
598
698
  # ---------------------------------------------------------------- the command line
@@ -636,9 +736,15 @@ def _arguments(argv: list[str] | None) -> argparse.Namespace:
636
736
  parser.add_argument("--retries", type=int, default=int(os.environ.get("IMPLEMENT_SPEC_RETRIES", 2)), metavar="N",
637
737
  help="the stops of one ticket, or of the end of run, that the driver answers itself with the "
638
738
  "recommended option before it asks the operator (default: IMPLEMENT_SPEC_RETRIES, else 2)")
739
+ parser.add_argument("--must-fix-retries", type=int, metavar="N",
740
+ default=int(os.environ.get("IMPLEMENT_SPEC_MUST_FIX_RETRIES", 2)),
741
+ help="the more fix batches, beyond --retries, that the driver runs itself while a critical or "
742
+ "must-fix finding is open, before it asks the operator (default: "
743
+ "IMPLEMENT_SPEC_MUST_FIX_RETRIES, else 2)")
639
744
  parser.add_argument("--ask", action=argparse.BooleanOptionalAction,
640
745
  default=os.environ.get("IMPLEMENT_SPEC_ASK") == "1", help="once the retries are spent, ask "
641
- "the operator instead of the arbiter agent (default: IMPLEMENT_SPEC_ASK=1, else off)")
746
+ "the operator instead of the arbiter agent, and instead of the `ship-draft` or `leave-out` of "
747
+ "the driver (default: IMPLEMENT_SPEC_ASK=1, else off)")
642
748
  parser.add_argument("--unattended", action="store_true", help="at a question, print no question: write "
643
749
  "--stage-json for the dispatcher, which gives the answers file to the next run")
644
750
  parser.add_argument("--stage-json", metavar="FILE", help="with --unattended: where the driver writes how a "
@@ -360,3 +360,16 @@ def cost(log: Path, entry: str, used: dict[str, int]) -> float | None:
360
360
  + used["output"] * price["output"]) / 1e6, 4)
361
361
  found = re.findall(r'"total_cost_usd":\s*([0-9.]+)', log.read_text(errors="replace"))
362
362
  return float(found[-1]) if found else None
363
+
364
+
365
+ # The final review runs through the review-diff skill, which must sit next to this one: `installed` looks nowhere else.
366
+ REVIEW_DIFF = SKILL.parent / "review-diff" / "SKILL.md"
367
+
368
+
369
+ def installed(name: str) -> Path | None:
370
+ """The SKILL.md of a skill: next to this skill, else in the skill folder of the Claude home or of the shared
371
+ home of Codex and OpenCode. review-diff is only next to this skill."""
372
+ claude = Path(os.environ.get("CLAUDE_CONFIG_DIR") or Path.home() / ".claude")
373
+ homes = (REVIEW_DIFF.parent.parent,) if name == REVIEW_DIFF.parent.name else (
374
+ SKILL.parent, claude / "skills", Path.home() / ".agents" / "skills")
375
+ return next((home / name / "SKILL.md" for home in homes if (home / name / "SKILL.md").is_file()), None)