@jesdi/skills 0.0.77 → 0.0.78

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 (70) hide show
  1. package/README.md +3 -2
  2. package/package.json +1 -1
  3. package/skills/implement-spec/ARCHITECTURE.md +102 -54
  4. package/skills/implement-spec/README.md +53 -51
  5. package/skills/implement-spec/SKILL.md +5 -6
  6. package/skills/implement-spec/driver.py +67 -153
  7. package/skills/implement-spec/driver_agents.py +75 -25
  8. package/skills/implement-spec/driver_decisions.py +92 -199
  9. package/skills/implement-spec/driver_dispute.py +189 -0
  10. package/skills/implement-spec/driver_final.py +196 -97
  11. package/skills/implement-spec/driver_fixloop.py +102 -192
  12. package/skills/implement-spec/driver_legacy.py +73 -5
  13. package/skills/implement-spec/driver_locked.py +186 -0
  14. package/skills/implement-spec/driver_merge.py +3 -48
  15. package/skills/implement-spec/driver_report.py +84 -64
  16. package/skills/implement-spec/driver_review.py +12 -119
  17. package/skills/implement-spec/driver_run.py +167 -130
  18. package/skills/implement-spec/driver_state.py +11 -9
  19. package/skills/implement-spec/models.json +0 -2
  20. package/skills/implement-spec/prompts/arbitration.md +34 -0
  21. package/skills/implement-spec/prompts/conflict.md +1 -0
  22. package/skills/implement-spec/prompts/correction.md +7 -4
  23. package/skills/implement-spec/prompts/elsewhere.md +6 -0
  24. package/skills/implement-spec/prompts/final-fixer.md +1 -1
  25. package/skills/implement-spec/prompts/final-lens.md +40 -0
  26. package/skills/implement-spec/prompts/final-reviewer.md +7 -7
  27. package/skills/implement-spec/prompts/fixer.md +2 -2
  28. package/skills/implement-spec/prompts/implementer.md +1 -1
  29. package/skills/implement-spec/prompts/lens-copy.md +1 -0
  30. package/skills/implement-spec/prompts/lens-correctness.md +8 -0
  31. package/skills/implement-spec/prompts/lens-spec.md +2 -0
  32. package/skills/implement-spec/prompts/lens-structure.md +2 -0
  33. package/skills/implement-spec/prompts/rebase-conflict.md +1 -0
  34. package/skills/implement-spec/prompts/rereview.md +0 -1
  35. package/skills/implement-spec/prompts/rerun.md +1 -1
  36. package/skills/implement-spec/prompts/reviewer.md +3 -6
  37. package/skills/implement-spec/prompts/ruled.md +3 -0
  38. package/skills/implement-spec/prompts/test-writer.md +4 -5
  39. package/skills/implement-spec/tests/test_agents.py +23 -22
  40. package/skills/implement-spec/tests/test_amendments.py +6 -48
  41. package/skills/implement-spec/tests/test_arbitration.py +314 -0
  42. package/skills/implement-spec/tests/test_cli.py +3 -3
  43. package/skills/implement-spec/tests/test_decisions.py +251 -374
  44. package/skills/implement-spec/tests/test_driver.py +22 -50
  45. package/skills/implement-spec/tests/test_final.py +45 -77
  46. package/skills/implement-spec/tests/test_fixloop.py +400 -633
  47. package/skills/implement-spec/tests/test_landing.py +23 -126
  48. package/skills/implement-spec/tests/test_lenses.py +217 -0
  49. package/skills/implement-spec/tests/test_merge.py +0 -43
  50. package/skills/implement-spec/tests/test_models.py +50 -1
  51. package/skills/implement-spec/tests/test_report.py +9 -23
  52. package/skills/implement-spec/tests/test_review.py +15 -153
  53. package/skills/implement-spec/tests/test_review_page.py +7 -3
  54. package/skills/implement-spec/tests/test_scoped.py +125 -0
  55. package/skills/implement-spec/tests/test_state.py +8 -3
  56. package/skills/implement-spec/tests/test_stops.py +43 -61
  57. package/skills/implement-spec/tests/test_tidy.py +77 -98
  58. package/skills/implement-spec/tests/test_walk.py +7 -6
  59. package/skills/review-page/SKILL.md +1 -1
  60. package/skills/to-tickets/SKILL.md +1 -1
  61. package/skills-manifest.json +7 -7
  62. package/skills/implement-spec/prompts/corrected.md +0 -3
  63. package/skills/implement-spec/prompts/correctness.md +0 -42
  64. package/skills/implement-spec/prompts/final-scoped.md +0 -1
  65. package/skills/implement-spec/prompts/full-review.md +0 -2
  66. package/skills/implement-spec/prompts/overruled.md +0 -7
  67. package/skills/implement-spec/prompts/rejected.md +0 -1
  68. package/skills/implement-spec/prompts/restored-red.md +0 -3
  69. package/skills/implement-spec/prompts/restored.md +0 -3
  70. package/skills/implement-spec/prompts/stands.md +0 -2
@@ -24,31 +24,32 @@ from pathlib import Path
24
24
  import driver_agents
25
25
  import driver_answers
26
26
  import driver_decisions
27
+ import driver_dispute
27
28
  import driver_final
28
29
  import driver_fixloop
29
30
  import driver_gate
30
31
  import driver_graph
31
32
  import driver_legacy
33
+ import driver_locked
32
34
  import driver_merge
33
- import driver_review
34
35
  import driver_review_page
36
+ import driver_run
35
37
  import driver_slots
36
38
  import driver_state
37
39
  import driver_summary
38
40
  import driver_tickets
39
41
  from driver_names import Names
40
- from driver_run import FINAL, OUT, Blocked, Halted, Run, during, ledger
42
+ from driver_run import FINAL, OUT, Blocked, Call, Halted, Run, during, ledger, retry_point
41
43
  from driver_slots import git
42
44
  from driver_tickets import Ticket
43
45
 
44
46
  STATE = OUT / "state.json"
45
47
  DECISIONS = OUT / "decisions.json"
46
48
  PAGE = Path(".agent/implement-review.html")
47
- ONLY = ("test-writer", "implementer", "reviewer", "correctness") # `--only` is for tests
49
+ ONLY = ("test-writer", "implementer", "reviewer") # `--only` is for tests
48
50
  # The phase of a ticket while a role runs, and the phase it reaches when the role's report is accepted.
49
51
  DURING = {"test-writer": "test-writer", "implementer": "implement"}
50
52
  AFTER = {"test-writer": "implement", "implementer": "gate"}
51
- MERGED_LOCKED = "merged-locked-file" # the question of a landing that changes a locked file of a merged ticket
52
53
 
53
54
 
54
55
  # ---------------------------------------------------------------- one ticket: the roles
@@ -75,22 +76,12 @@ def _check_out_ticket(ticket: Ticket, slot_number: int, entry: dict, run: Run) -
75
76
  return driver_slots.head(slot)
76
77
 
77
78
 
78
- def _locked_test_stop(number: str, run: Run) -> dict:
79
- """The last `locked-test` question of the ticket; {} when it has none."""
80
- asked = [q for q in run.state.read()["run"]["questions"] if (q["ticket"], q["kind"]) == (number, "locked-test")]
81
- return asked[-1] if asked else {}
82
-
83
-
84
- def _blocked_report(number: str, run: Run) -> str:
85
- """The report of the last `locked-test` stop of the ticket: an implementer's or a fixer's."""
86
- return _locked_test_stop(number, run).get("evidence", [str(OUT / number / "implementer-0.json")])[0]
87
-
88
-
89
- def _overruled(number: str, run: Run) -> list[str]:
90
- """The concerns of that report that the operator overruled: what an overrule correction names in
91
- `not_addressed` (issue #134)."""
92
- concerns = json.loads(Path(_blocked_report(number, run)).read_text())["concerns"]
93
- return [concern for concern in concerns if concern.startswith(driver_decisions.CONTRADICTS)]
79
+ def _risk(ticket: Ticket) -> str:
80
+ """The reviewer's line on the Risk line of the ticket: one more criterion to check."""
81
+ if not ticket.risk:
82
+ return "The ticket names no risk."
83
+ return (f"Check the Risk line of the ticket as one more criterion: {ticket.risk}. A risk that the diff does not "
84
+ "handle is an unmet criterion.")
94
85
 
95
86
 
96
87
  def _prompt_values(ticket: Ticket, slot: str, run: Run) -> dict[str, str]:
@@ -99,8 +90,7 @@ def _prompt_values(ticket: Ticket, slot: str, run: Run) -> dict[str, str]:
99
90
  return {"spec": os.path.relpath(run.args.spec, slot), "seam": ticket.seam, "pr_branch": run.pr,
100
91
  "branch": run.names.ticket(ticket.number),
101
92
  "ticket": os.path.relpath(Path(run.args.tickets) / ticket.file, slot),
102
- "correctness": driver_review.checks(), "gate": run.args.fast_gate,
103
- "blocked_report": os.path.relpath(_blocked_report(ticket.number, run), slot),
93
+ "risk": _risk(ticket), "gate": run.args.fast_gate,
104
94
  "writer_report": os.path.relpath(folder / "test-writer-0.json", slot)}
105
95
 
106
96
 
@@ -115,19 +105,19 @@ def _first_notes(number: str, slot_number: int, entry: dict, run: Run, roles: li
115
105
  return []
116
106
 
117
107
 
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
108
+ def _run_role(run: Run, call: Call, entry: dict) -> tuple[str, dict]:
109
+ """Run `call`. Returns (the phase of the ticket after it, the fields its report gives the ticket record). A
110
+ test-writer on a ticket that has locked tests is the correction of a `correct-test` answer: the phase after it is
111
+ the one its question resumes, the implementer or the review before the fixer of that round."""
112
+ questions = run.state.read()["run"]["questions"]
113
+ if call.role == "test-writer" and entry["test_writer_sha"] and (question := driver_dispute.correction(questions,
114
+ call.number)):
115
+ driver_dispute.correct_as_answered(run, call, question)
116
+ return question["resume"]["phase"], {}
117
+ report = driver_dispute.agent(run, call)
118
+ if call.role != "test-writer":
119
+ return AFTER.get(call.role, "review"), {}
120
+ return AFTER["test-writer"], driver_locked.written(entry, report["locked"], driver_slots.head(call.slot))
131
121
 
132
122
 
133
123
  def _run_roles(ticket: Ticket, slot_number: int, run: Run) -> None:
@@ -143,25 +133,13 @@ def _run_roles(ticket: Ticket, slot_number: int, run: Run) -> None:
143
133
  run.state.ticket(number, phase=DURING.get(role, "review"))
144
134
  values.update(start_sha=start, gate_record=os.path.relpath(driver_gate.record_path(OUT / number, driver_gate.FAST, start),
145
135
  slot))
146
- check, notes = _role_check(role, number, slot, entry, run, values, notes)
147
136
  with during(f"the {role}"):
148
- try:
149
- report = run.agent(role, number, slot, values, notes=notes, check=check)
150
- except Blocked:
151
- if check["correction"]:
152
- # The ruling did not take: the operator rules on the same locked test again (issue #134).
153
- run.ask(number, "locked-test", [_locked_test_stop(number, run)["subject"]],
154
- _blocked_report(number, run))
155
- raise
156
- for item in report.get("not_addressed", []):
157
- ledger(f"Ticket {number}: the test-writer correction did not correct {item['finding']}: {item['reason']}.")
158
- facts = {"tip": driver_slots.head(slot)}
159
- if role == "test-writer":
160
- facts.update(driver_review.written(slot, entry, report["locked"], report.get("fixtures", []),
161
- facts["tip"]))
162
- values["locked"] = " ".join(facts["locked"])
163
- run.state.ticket(number, phase=AFTER.get(role, "review"), note="", **facts)
164
- start, notes = facts["tip"], []
137
+ phase, facts = _run_role(run, Call(role, number, slot, values, notes=notes), entry)
138
+ start, notes = driver_slots.head(slot), []
139
+ entry = run.state.ticket(number, phase=phase, note="", tip=start, **facts)
140
+ values["locked"] = " ".join(entry["locked"])
141
+ if phase != AFTER.get(role, "review"):
142
+ break # the fixer that disputed runs again after the review
165
143
 
166
144
 
167
145
  # ---------------------------------------------------------------- one ticket: the landing on the PR branch
@@ -169,32 +147,17 @@ def _run_roles(ticket: Ticket, slot_number: int, run: Run) -> None:
169
147
  @dataclass
170
148
  class _Landing:
171
149
  ticket_tip: str
172
- pr_tip: str # the PR tip that the landing check read
150
+ pr_tip: str # the PR tip the merge was made on
173
151
  commit: str # what the PR branch moves to: `pr_tip` (merged already), `ticket_tip` (fast-forward) or a merge
174
152
 
175
153
 
176
- @dataclass
177
- class _Rulings:
178
- """The answers to the `merged-locked-file` questions of the ticket, as its landing applies them."""
179
- before: str # the ticket tip before the driver put a file back
180
- paths: dict[str, str] # file -> `restore` or `adopt`
181
-
182
- def adopted(self) -> list[str]:
183
- return [path for path, answer in self.paths.items() if answer == "adopt"]
184
-
185
-
186
154
  def _resolve_conflict(ticket: Ticket, slot: str, run: Run, tip: str, files: list[str]) -> str:
187
155
  """Run the conflict agent on the merge that is open in the slot. Returns the new ticket tip."""
188
156
  number = ticket.number
189
157
  values = {**_prompt_values(ticket, slot, run), "start_sha": tip, "pr_sha": run.tip(), "files": " ".join(files)}
190
158
  try:
191
159
  with during("the conflict agent"):
192
- run.agent("conflict", number, slot, values)
193
- # The resolution may not change a locked test of the ticket. Those of the merged tickets are checked
194
- # when the resolved tip lands.
195
- changed = driver_review.locked_changes(slot, tip, run.state.read()["tickets"][number]["locked"])
196
- if changed:
197
- raise Blocked("; ".join(finding["title"] for finding in changed))
160
+ run.agent(Call("conflict", number, slot, values))
198
161
  except (Blocked, Halted):
199
162
  driver_merge.abort(slot) # closes the merge when the agent did not commit it
200
163
  raise
@@ -222,90 +185,60 @@ def _merge_commit(ticket: Ticket, slot: str, run: Run, tip: str, may_resolve: bo
222
185
  return _Landing(tip, pr_tip, commit)
223
186
 
224
187
 
225
- def _rulings(number: str, slot: str, run: Run) -> _Rulings:
226
- """Apply the `restore` rulings on the ticket's files of merged tickets: one commit of the driver. Call it under
227
- the merge lock."""
228
- paths = {path: answer for path, answer in
229
- driver_decisions.ruled(run.state.read()["run"]["questions"], number, MERGED_LOCKED).items()
230
- if answer != "redesign"}
231
- rulings = _Rulings(run.state.read()["tickets"][number]["tip"], paths)
232
- if restore := [path for path, answer in paths.items() if answer == "restore"]:
233
- git(slot, "checkout", "-q", run.names.ticket(number))
234
- run.restore_merged_files(number, slot, restore)
235
- return rulings
236
-
237
-
238
- def _refused(number: str, run: Run, landing: _Landing, rulings: _Rulings) -> None:
239
- """The landing check: a locked file of a merged ticket that the landing changes asks a `merged-locked-file`
240
- question. A file that an `adopt` ruling names is the ticket's own."""
241
- tickets = run.state.read()["tickets"]
242
- entry = tickets[number]
243
- own = {**tickets, number: {**entry, "locked": entry["locked"] + rulings.adopted()}}
244
- changed, error = driver_merge.refused(own, number, landing.pr_tip, landing.commit)
245
- if error:
188
+ def _red_landing(number: str, slot: str, run: Run, commit: str, record: str) -> None:
189
+ """A red full gate on `commit`, the commit that would land: a finding of the fix loop, inside the cap."""
190
+ git(slot, "checkout", "-q", run.names.ticket(number)) # the fixer works on the ticket branch
191
+ driver_fixloop.red_landing(run, number, slot, commit, record)
192
+
193
+
194
+ def _refuse_breach(number: str, run: Run, landing: _Landing) -> None:
195
+ """The commit that would land leaves every other ticket's locked file as the PR tip has it, but those the ticket
196
+ lists as its own (driver_locked.landing_errors). A change blocks the ticket with one `ticket-blocked` question: its
197
+ `retry` runs the implementer
198
+ again, whose locked-file check names the file until the ticket branch leaves it as the merge base has it."""
199
+ if errors := driver_locked.landing_errors(run.state.read()["tickets"], number, landing.pr_tip, landing.commit):
200
+ error = "; ".join(errors)
201
+ run.ask(number, "ticket-blocked", [f"the landing: {error}"], str(STATE),
202
+ retry_point("implementer", landing.ticket_tip, 0))
246
203
  raise Blocked(error)
247
- if changed:
248
- run.ask(number, MERGED_LOCKED, changed,
249
- f"git diff {landing.pr_tip[:7]} {landing.commit[:7]} -- {' '.join(changed)}")
250
- raise Blocked("; ".join(f"locked file changed: {path}" for path in changed))
251
-
252
-
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}")
267
-
268
-
269
- def _checked_landing(ticket: Ticket, slot: str, run: Run, may_resolve: bool, rulings: _Rulings) -> _Landing:
270
- """The commit to land, with the locked-file check passed and the full gate green. Call it under the merge lock."""
204
+
205
+
206
+ def _checked_landing(ticket: Ticket, slot: str, run: Run, may_resolve: bool) -> _Landing:
207
+ """The commit to land, with the full gate green. Call it under the merge lock."""
271
208
  number = ticket.number
272
209
  # An earlier try left the slot on its merge commit.
273
210
  git(slot, "checkout", "-q", run.names.ticket(number))
274
211
  tip = run.state.ticket(number, phase="merge")["tip"]
275
212
  landing = _merge_commit(ticket, slot, run, tip, may_resolve)
276
- _refused(number, run, landing, rulings)
213
+ _refuse_breach(number, run, landing)
277
214
  if landing.commit != landing.pr_tip:
278
215
  # The full gate runs on the commit that lands, a fast-forward as well as a merge commit: a fast green record
279
216
  # does not count. When the checkout fails, the slot is on another commit and the gate refuses to run.
280
217
  git(slot, "checkout", "-q", "--detach", landing.commit)
281
218
  if record := run.red_gate(number, slot, landing.commit, driver_gate.FULL):
282
- _red_landing(number, slot, run, rulings, landing.commit, record)
219
+ _red_landing(number, slot, run, landing.commit, record)
283
220
  return landing
284
221
 
285
222
 
286
- def _land(ticket: Ticket, slot: str, run: Run) -> tuple[_Landing, _Rulings]:
223
+ def _land(ticket: Ticket, slot: str, run: Run) -> _Landing:
287
224
  """Move the PR branch to the checked commit. Call it under the merge lock."""
288
- rulings = _rulings(ticket.number, slot, run)
289
- landing = _checked_landing(ticket, slot, run, True, rulings)
225
+ landing = _checked_landing(ticket, slot, run, True)
290
226
  # git moves the ref only from the tip that the check read, so the check and the move are one step.
291
227
  error = driver_merge.land(run.pr, landing.commit, landing.pr_tip)
292
228
  if error and run.tip() != landing.pr_tip:
293
229
  # Another hand moved the PR branch in between: start again from the new tip, one time, with no conflict agent.
294
- landing = _checked_landing(ticket, slot, run, False, rulings)
230
+ landing = _checked_landing(ticket, slot, run, False)
295
231
  error = driver_merge.land(run.pr, landing.commit, landing.pr_tip)
296
232
  if error:
297
233
  raise Blocked(error)
298
- return landing, rulings
234
+ return landing
299
235
 
300
236
 
301
- def _record_landing(state: dict, number: str, landing: _Landing, adopted: list[str]) -> None:
237
+ def _record_landing(state: dict, number: str, landing: _Landing) -> None:
302
238
  """The ticket is merged, and `landing.commit` is the PR tip its merge made: a later merge of the ticket replaces
303
- it. The ticket locks each `adopted` file from its landed tip on."""
304
- entry, pr_tip = state["tickets"][number], landing.commit
305
- entry["phase"] = "merged"
306
- new = [path for path in adopted if path not in entry["locked"]]
307
- entry["locked"] += new
308
- entry["held"].update(dict.fromkeys(new, landing.ticket_tip))
239
+ it."""
240
+ pr_tip = landing.commit
241
+ state["tickets"][number]["phase"] = "merged"
309
242
  earlier = [landed for landed in state["run"]["landed"] if landed[0] != number]
310
243
  state["run"]["landed"] = earlier + [[number, pr_tip]]
311
244
 
@@ -315,12 +248,9 @@ def _merge(ticket: Ticket, slot: str, run: Run) -> None:
315
248
  number, branch = ticket.number, run.names.ticket(ticket.number)
316
249
  # The merge gate and the conflict agent run under the lock: the commit the gate saw is the one that lands.
317
250
  with run.merging, during("the merge"):
318
- landing, rulings = _land(ticket, slot, run)
319
- run.state.update(lambda state: _record_landing(state, number, landing, rulings.adopted()))
251
+ landing = _land(ticket, slot, run)
252
+ run.state.update(lambda state: _record_landing(state, number, landing))
320
253
  _drop_merged(run.state)
321
- for path in rulings.adopted():
322
- ledger(f"Ticket {number}: by the ruling (adopt), the ticket locks {path}, so its change to that locked file of "
323
- "a merged ticket landed.")
324
254
  driver_slots.release(slot) # git deletes no branch that a worktree has checked out
325
255
  kept = "" if driver_merge.delete(branch, run.pr) else f"; {branch} is kept"
326
256
  if landing.commit == landing.pr_tip:
@@ -334,22 +264,6 @@ def _merge(ticket: Ticket, slot: str, run: Run) -> None:
334
264
 
335
265
  # ---------------------------------------------------------------- one ticket, and the walk of the graph
336
266
 
337
- def _block(number: str, run: Run, ledger_line: int) -> None:
338
- """Block the ticket and add the questions it asked for, in one write of state.json."""
339
- ask = run.asks.pop(number, None)
340
-
341
- def change(state: dict) -> None:
342
- state["tickets"][number]["phase"] = "blocked"
343
- if ask:
344
- state["tickets"][number].update(ask.fields)
345
- evidence = [ask.report, f"{OUT / 'ledger.md'}:{ledger_line}"]
346
- driver_decisions.stop(state["run"], ask.kind, number, ask.subjects, evidence)
347
-
348
- run.state.update(change)
349
- if ask and ask.subjects:
350
- ledger(f"Ticket {number}: {driver_decisions.decides(ask.kind, len(ask.subjects))} in {DECISIONS}.")
351
-
352
-
353
267
  def _drop_merged(state: driver_state.State) -> None:
354
268
  """Drop the open questions of each merged ticket: a stopped ticket that the operator set to `merge` has them."""
355
269
  dropped: list[dict] = []
@@ -380,7 +294,7 @@ def _run_ticket(ticket: Ticket, slot_number: int, run: Run) -> bool:
380
294
  except driver_fixloop.Unlanded:
381
295
  pass # the merge lock is released and the next fix round has started: its fixer runs now
382
296
  except Blocked as blocked:
383
- _block(number, run, ledger(f"Ticket {number}: BLOCKED at {blocked}."))
297
+ run.block(number, ledger(f"Ticket {number}: BLOCKED at {blocked}."))
384
298
  print(f"{ticket.file}: BLOCKED at {blocked}")
385
299
  except Halted as halted:
386
300
  _halt(run, f"Ticket {number}", str(halted))
@@ -527,7 +441,7 @@ def _apply_answers(state: driver_state.State, args) -> list[str]:
527
441
  def change(new: dict) -> None:
528
442
  new["run"]["questions"] = questions
529
443
  for number, fields in moved.items():
530
- new["tickets"][number].update(fields)
444
+ driver_run.record_of(new, number).update(fields)
531
445
 
532
446
  state.update(change)
533
447
  error = _publish_questions(run)
@@ -688,7 +602,7 @@ def _validated(args: argparse.Namespace) -> tuple[list[Ticket], dict[str, list[s
688
602
  errors += _worktree_errors(1 in kept.values())
689
603
  models, model_errors = driver_agents.load_models(args.models)
690
604
  tickets, ticket_errors = driver_tickets.parse(args.tickets)
691
- errors += model_errors + ticket_errors + driver_review.precondition_errors(tickets)
605
+ errors += model_errors + ticket_errors
692
606
  errors += driver_final.precondition_errors(args.push or args.unattended, args.base)
693
607
  for error in errors:
694
608
  print(error)
@@ -15,15 +15,35 @@ import tempfile
15
15
  import threading
16
16
  import time
17
17
  from concurrent.futures import ThreadPoolExecutor
18
+ from dataclasses import dataclass
18
19
  from pathlib import Path
19
20
 
20
21
  SKILL = Path(__file__).resolve().parent
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class Lens:
26
+ """A lens of the full final review: a role with no model list, on an entry of the `final-reviewer` list. Its lines
27
+ of the prompt are `prompts/lens-<source>.md`."""
28
+ source: str # the `source` of its findings, and its name in the prompt
29
+ skill: str # the skill that holds its method
30
+ method: str # the file of that skill it follows
31
+ inline: bool # its lines hold the method text, not its path
32
+ other_provider: bool # it runs on another provider than the implementer's first entry
33
+
34
+
35
+ # In the order a tie of the merge keeps.
36
+ LENSES = {
37
+ "final-spec": Lens("spec", "review-diff", "spec.md", False, False),
38
+ # Inlined: this lens reads from git, and a project-local review-diff sits in an ignored folder (#120).
39
+ "final-correctness": Lens("correctness", "review-diff", "correctness.md", True, True),
40
+ "final-structure": Lens("structure", "deep-quality-review", "SKILL.md", False, False)}
21
41
  # Minutes per role.
22
- TIMEOUTS = {"explorer": 30, "test-writer": 30, "implementer": 90, "reviewer": 45, "correctness": 30, "fixer": 60,
23
- "final-reviewer": 60, "conflict": 30, "pr-writer": 20}
42
+ TIMEOUTS = {"test-writer": 30, "implementer": 90, "reviewer": 45, "fixer": 60, "final-reviewer": 60,
43
+ **dict.fromkeys(LENSES, 60), "conflict": 30, "pr-writer": 20}
24
44
  PROVIDERS = {"anthropic": ("claude", ("low", "medium", "high", "xhigh", "max")),
25
45
  "openai": ("codex", ("minimal", "low", "medium", "high", "xhigh"))}
26
- READ_ONLY = ("reviewer", "correctness", "final-reviewer", "pr-writer")
46
+ READ_ONLY = ("reviewer", "final-reviewer", *LENSES, "pr-writer")
27
47
  PREFLIGHT = "implement-spec preflight: reply with the word OK. Read no file and run no command.\n"
28
48
  # The time limit of one preflight call: a CLI that gives no answer in this time fails the preflight.
29
49
  PREFLIGHT_MINUTES = 5
@@ -51,37 +71,67 @@ def _entry_error(role: str, entry: str, first: bool) -> str | None:
51
71
  return None
52
72
 
53
73
 
54
- def correctness_entry(models: dict[str, list[str]]) -> str:
55
- """The first correctness entry on another provider than the implementer's first entry; "" when there is none."""
56
- own = split(models["implementer"][0])[0]
57
- return next((entry for entry in models["correctness"] if split(entry)[0] != own), "")
74
+ # Roles of older drivers: a --models file that still names one is told to delete the key.
75
+ REMOVED = ("correctness", "explorer")
76
+
77
+
78
+ def _role_errors(given: dict, known: dict) -> list[str]:
79
+ """One error per role of the --models file that the skill's models.json does not define."""
80
+ return [f"{role}: the role was removed; delete its key from the --models file" if role in REMOVED else
81
+ f"{role}: unknown role (known: {', '.join(known)})" for role in given if role not in known]
58
82
 
59
83
 
60
84
  def load_models(path: str | None) -> tuple[dict[str, list[str]], list[str]]:
61
- """The skill's default lists with the roles of `path` on top, and every entry error."""
62
- models = json.loads((SKILL / "models.json").read_text())
85
+ """The skill's default lists with the roles of `path` on top, and every role and entry error."""
86
+ defaults = json.loads((SKILL / "models.json").read_text())
63
87
  try:
64
- models = {**models, **(json.loads(Path(path).read_text()) if path else {})} # a list is a TypeError
65
- # The entry of each role whose CLI must be on PATH; entries[0]: an empty list is an error.
66
- first = {**{role: entries[0] for role, entries in models.items()}, "correctness": correctness_entry(models)}
67
- found = [_entry_error(role, entry, entry == first[role]) for role, entries in models.items() for entry in entries]
68
- if len(models["implementer"]) < 2:
69
- found.append("implementer: a second implementer model entry is required for fix round 2")
70
- if not first["correctness"]:
71
- found.append(f"correctness: no entry of its list ({', '.join(models['correctness'])}) is on another "
72
- f"provider than the implementer's first entry {models['implementer'][0]}; the correctness "
73
- "pass never runs on the implementer's provider")
88
+ given = json.loads(Path(path).read_text()) if path else {}
89
+ models = {**defaults, **given} # a list is a TypeError
90
+ if unknown := _role_errors(given, defaults):
91
+ return {}, unknown
92
+ return models, _entry_errors(models)
74
93
  except (OSError, ValueError, AttributeError, LookupError, TypeError) as exc:
75
94
  return {}, [f"--models {path}: {exc!r}"]
76
- return models, [error for error in found if error]
95
+
96
+
97
+ def other_provider_entries(models: dict[str, list[str]]) -> list[str]:
98
+ """The entries of the `final-reviewer` list on another provider than the implementer's first entry: the correctness
99
+ lens and the scoped review run and rerun only on these."""
100
+ own = split(models["implementer"][0])[0]
101
+ return [entry for entry in models["final-reviewer"] if split(entry)[0] != own]
102
+
103
+
104
+ def other_provider_entry(models: dict[str, list[str]]) -> str:
105
+ """The other-provider entry of the `final-reviewer` list, its first one; "" when there is none."""
106
+ return next(iter(other_provider_entries(models)), "")
107
+
108
+
109
+ def lens_entries(models: dict[str, list[str]], role: str) -> list[str]:
110
+ """The entries a lens of the final review runs on, the first one first, its rerun on the next one."""
111
+ return other_provider_entries(models) if LENSES[role].other_provider else models["final-reviewer"]
112
+
113
+
114
+ def _entry_errors(models: dict[str, list[str]]) -> list[str]:
115
+ """Every entry error of the merged lists."""
116
+ # The entries whose CLI must be on PATH; entries[0]: an empty list is an error.
117
+ first = {(role, entries[0]) for role, entries in models.items()} | {
118
+ ("final-reviewer", other_provider_entry(models))}
119
+ found = [_entry_error(role, entry, (role, entry) in first) for role, entries in models.items() for entry in entries]
120
+ if len(models["implementer"]) < 2:
121
+ found.append("implementer: a second implementer model entry is required for fix round 2")
122
+ if not other_provider_entry(models):
123
+ found.append(f"final-reviewer: no entry of its list ({', '.join(models['final-reviewer'])}) is on another "
124
+ f"provider than the implementer's first entry {models['implementer'][0]}; its other-provider "
125
+ "entry serves the correctness lens of the final review and the scoped review, which never run on "
126
+ "the implementer's provider")
127
+ return [error for error in found if error]
77
128
 
78
129
 
79
130
  def used_entries(models: dict[str, list[str]]) -> list[str]:
80
- """Each entry the driver can start an agent on: the first of each role but the explorer, the correctness entry
81
- and the second implementer entry (fix round 2)."""
82
- entries = [entries[0] for role, entries in models.items() if role not in ("explorer", "correctness")]
83
- entries += [correctness_entry(models), *models["implementer"][1:2]]
84
- return sorted(set(entries))
131
+ """Each entry the driver can start an agent on: the first of each role, the other-provider entry and the second
132
+ implementer entry (fix round 2)."""
133
+ firsts = (entries[0] for entries in models.values())
134
+ return sorted({*firsts, other_provider_entry(models), *models["implementer"][1:2]})
85
135
 
86
136
 
87
137
  def preflight(models: dict[str, list[str]]) -> list[str]: