@jesdi/skills 0.0.77 → 0.0.79

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 (74) 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/test-prune/SKILL.md +7 -3
  61. package/skills/test-prune/prune_source.py +48 -0
  62. package/skills/test-prune/prune_strengthen.py +87 -2
  63. package/skills/test-prune/tests/test_prune_strengthen.py +93 -0
  64. package/skills/to-tickets/SKILL.md +1 -1
  65. package/skills-manifest.json +9 -9
  66. package/skills/implement-spec/prompts/corrected.md +0 -3
  67. package/skills/implement-spec/prompts/correctness.md +0 -42
  68. package/skills/implement-spec/prompts/final-scoped.md +0 -1
  69. package/skills/implement-spec/prompts/full-review.md +0 -2
  70. package/skills/implement-spec/prompts/overruled.md +0 -7
  71. package/skills/implement-spec/prompts/rejected.md +0 -1
  72. package/skills/implement-spec/prompts/restored-red.md +0 -3
  73. package/skills/implement-spec/prompts/restored.md +0 -3
  74. package/skills/implement-spec/prompts/stands.md +0 -2
@@ -87,20 +87,11 @@ def test_models_file_checks_the_first_entry_of_each_role(repo, capsys, tmp_path,
87
87
  models = tmp_path.parent / f"{tmp_path.name}-models.json"
88
88
  # The default reviewer and final-reviewer start on codex, so this file gives both a claude entry.
89
89
  claude = {"reviewer": ["claude-opus-5-5@medium"], "final-reviewer": ["claude-opus-5-5@medium"]}
90
- models.write_text(json.dumps({"implementer": ["openai/gpt-sol@medium"], **claude,
91
- "correctness": ["openai/gpt-sol@medium"], "fixer": ["other/x@low"]}))
90
+ models.write_text(json.dumps({"implementer": ["openai/gpt-sol@medium"], **claude, "fixer": ["other/x@low"]}))
92
91
  assert run(capsys, "--models", str(models)) == (
93
92
  3, "implementer: codex is not on PATH (model entry openai/gpt-sol@medium)\n"
94
93
  "fixer: model entry other/x@low names an unknown provider (known: anthropic, openai)\n"
95
- "implementer: a second implementer model entry is required for fix round 2\n"
96
- "correctness: no entry of its list (openai/gpt-sol@medium) is on another provider than the implementer's "
97
- "first entry openai/gpt-sol@medium; the correctness pass never runs on the implementer's provider\n")
98
- # Requirement 2 names the first entry only: a later implementer entry whose CLI is missing is no error. For the
99
- # correctness role it names the entry requirement 13 selects, which here is the second of its list.
100
- models.write_text(json.dumps({"implementer": ["opus@medium", "openai/gpt-sol@medium"], **claude,
101
- "correctness": ["opus@high", "openai/gpt-sol@low", "openai/gpt-astra@low"]}))
102
- assert run(capsys, "--models", str(models)) == (
103
- 3, "correctness: codex is not on PATH (model entry openai/gpt-sol@low)\n")
94
+ "implementer: a second implementer model entry is required for fix round 2\n")
104
95
 
105
96
 
106
97
  # Each entry is invalid on purpose: `turbo` is no effort of the anthropic provider, the second entry has no
@@ -139,9 +130,9 @@ REPORT = """printf '{"status": "%s", "commits": ["%s"], "files": [], "concerns":
139
130
  COMMIT = "echo $role >> work.txt; git add -A; git commit -q -m $role\n"
140
131
  WRITER = """fields='"locked": ["work.txt"], "red": [{"test": "t", "line": "FAILED t"}]'; echo FAILED t\n"""
141
132
  IMPLEMENTER = """fields='"green": ["1 passed"]'; echo '{"total_cost_usd": 0.25}'\n"""
142
- # The reviewer of a plain run: it finds nothing and proves the locked file of WRITER.
143
- CLEAN = """case $role in reviewer|correctness|final-reviewer) echo FAILED t
144
- printf '{"status": "DONE", "commits": [], "files": [], "concerns": [], "findings": [], "mutations": [{"test": "work.txt::t", "file": "work.txt", "line": 1, "red": "FAILED t"}]}' > "$report"; exit 0;; esac
133
+ # The reviewer of a plain run: it finds nothing.
134
+ CLEAN = """case $role in reviewer|final-reviewer|final-spec|final-correctness|final-structure)
135
+ printf '{"status": "DONE", "commits": [], "files": [], "concerns": [], "findings": []}' > "$report"; exit 0;; esac
145
136
  """
146
137
  ONCE = '[ -e "$0.again" ] || { touch "$0.again"; %s; }\n' # the first attempt only
147
138
 
@@ -203,9 +194,9 @@ def test_accepted_reports_end_the_run_with_exit_0(repo, tmp_path, capsys):
203
194
  def test_a_violation_reruns_once_with_the_error_then_blocks(repo, tmp_path, capsys):
204
195
  repo()
205
196
  code, ledger = agents(tmp_path, capsys, f"STATUS=FINISHED\n{COMMIT}{IMPLEMENTER}{REPORT}")
206
- assert code == 1 and len(ledger) == 3
197
+ assert code == 2 and len(ledger) == 4 and "question of kind ticket-blocked" in ledger[3]
207
198
  assert ledger[2].startswith("Ticket 01: BLOCKED at the implementer: status: 'FINISHED' is not one of")
208
- assert "The driver rejected the earlier attempt: status: 'FINISHED'" in (
199
+ assert "The earlier attempt did not finish the role: status: 'FINISHED'" in (
209
200
  tmp_path / ".agent/implement/01/implementer-0.prompt.md").read_text()
210
201
 
211
202
 
@@ -216,12 +207,11 @@ def prompt_of(tmp_path, role="implementer"):
216
207
  def test_an_agent_that_writes_no_report_is_rerun_once_then_blocks(repo, tmp_path, capsys):
217
208
  repo()
218
209
  code, ledger = agents(tmp_path, capsys, "exit 0\n", "--only", "reviewer")
219
- assert code == 1 and len(ledger) == 3
210
+ assert code == 2 and len(ledger) == 4
220
211
  assert ledger[2].startswith("Ticket 01: BLOCKED at the reviewer: report .agent/implement/01/reviewer-0.json is not")
221
212
 
222
213
 
223
- @pytest.mark.parametrize("extra", ['"locked": 5', '"locked": ["work.txt", "never-committed.txt"]', '"red": 5',
224
- '"mutations": "x"'])
214
+ @pytest.mark.parametrize("extra", ['"locked": 5', '"locked": ["work.txt", "never-committed.txt"]', '"red": 5'])
225
215
  def test_a_field_of_another_role_is_ignored(repo, tmp_path, capsys, extra):
226
216
  repo()
227
217
  code, ledger = agents(tmp_path, capsys, f"{COMMIT}fields='\"green\": [], {extra}'\n{REPORT}")
@@ -229,12 +219,12 @@ def test_a_field_of_another_role_is_ignored(repo, tmp_path, capsys, extra):
229
219
 
230
220
 
231
221
  @pytest.mark.parametrize("status", ["BLOCKED", "NEEDS_CONTEXT"])
232
- def test_a_report_that_says_blocked_blocks_the_ticket_without_a_rerun(repo, tmp_path, capsys, status):
222
+ def test_a_report_that_says_blocked_reruns_once_then_asks_ticket_blocked(repo, tmp_path, capsys, status):
233
223
  repo()
234
224
  body = f"""printf '{{"status": "{status}", "commits": [], "files": [], "concerns": ["test_x contradicts the spec"], "green": []}}' > "$report"\n"""
235
225
  code, ledger = agents(tmp_path, capsys, body)
236
- assert code == 2 and len(ledger) == 3 and "question of kind implementer-stopped" in ledger[2]
237
- assert ledger[1] == f"Ticket 01: BLOCKED at the implementer: the implementer reported {status}: test_x contradicts the spec."
226
+ assert code == 2 and len(ledger) == 4 and "question of kind ticket-blocked" in ledger[3]
227
+ assert ledger[2] == f"Ticket 01: BLOCKED at the implementer: it reported {status}: test_x contradicts the spec."
238
228
 
239
229
 
240
230
  def test_a_rerun_prompt_holds_only_template_lines_and_keeps_its_ending(repo, tmp_path, capsys):
@@ -377,8 +367,8 @@ REFACTOR = {"seam": "none — refactor"}
377
367
  FIXES = """[ $role != fixer ] || fields="$fields, \\"ticket\\": \\"$nn\\""\n"""
378
368
  # A fixer that cannot make the red gate green: the ticket blocks at fix round 1.
379
369
  GIVE_UP = """[ $role != fixer ] || { printf '{"status": "BLOCKED", "commits": [], "files": [], "concerns": ["the gate stays red"], "green": [], "ticket": "01"}' > "$report"; exit 0; }\n"""
380
- GAVE_UP = "Ticket 01: BLOCKED at fix round 1: the fixer reported BLOCKED: the gate stays red."
381
- ASKED = "Ticket 01: the operator decides on 1 question of kind fixer-stopped in .agent/implement/decisions.json."
370
+ GAVE_UP = "Ticket 01: BLOCKED at fix round 1: it reported BLOCKED: the gate stays red."
371
+ ASKED = "Ticket 01: the operator decides on 1 question of kind ticket-blocked in .agent/implement/decisions.json."
382
372
 
383
373
 
384
374
  def walk(tmp_path, capsys, body, *args, gate="true"):
@@ -451,7 +441,7 @@ def test_a_conflict_agent_that_does_not_resolve_blocks_the_ticket_and_keeps_its_
451
441
  two(repo)
452
442
  stuck = '[ $role != conflict ] || exit 0\n'
453
443
  code, ledger, out = walk(tmp_path, capsys, stuck + "FILE=work.txt\n" + WORK + TOGETHER + REPORT)
454
- assert code == 1, out
444
+ assert code == 2 and "ticket-blocked" in out, out
455
445
  (line,) = [line for line in ledger if "BLOCKED" in line]
456
446
  number = line[7:9]
457
447
  assert f"BLOCKED at the merge: the conflict agent: report .agent/implement/{number}/conflict-0.json is not" in line
@@ -507,7 +497,7 @@ def test_a_merge_gate_red_after_round_2_blocks_the_ticket_and_the_pr_branch_does
507
497
  def test_a_tree_that_is_not_clean_is_a_red_gate_and_the_slot_keeps_the_work(repo, tmp_path, capsys):
508
498
  repo(t01=ticket("01", **REFACTOR))
509
499
  code, ledger, out = walk(tmp_path, capsys, GIVE_UP + WORK + REPORT + "echo left > junk.txt\n", gate="echo NEVER")
510
- assert code == 2 and "from the gate at .agent/implement/01/gate-" in ledger[-4] and ledger[-2:] == [GAVE_UP, ASKED], out
500
+ assert code == 2 and "from the gate at .agent/implement/01/gate-" in ledger[-5] and ledger[-2:] == [GAVE_UP, ASKED], out
511
501
  record = next((tmp_path / ".agent/implement/01").glob("gate-*.log")).read_text()
512
502
  assert "status: not clean\n ?? junk.txt\n" in record and "exit: not run" in record and "\nNEVER\n" not in record
513
503
  assert out_of("git", "symbolic-ref", "--short", "HEAD") == "ticket/feat%2Fx/01" and (tmp_path / "junk.txt").exists()
@@ -533,10 +523,12 @@ def test_a_touches_overlap_holds_the_second_ticket_and_the_ledger_says_why(repo,
533
523
 
534
524
 
535
525
  def blocked_then_edited(repo, tmp_path, capsys, **fields):
536
- """A one-ticket run that a red gate blocks, then state.json edited as the resume tests need."""
526
+ """A one-ticket run that a red gate blocks, then state.json edited as the resume tests need. Its fixer writes no
527
+ valid report, so the ticket blocks with a question, which the edit drops."""
537
528
  repo(t01=ticket("01", **REFACTOR))
538
- assert walk(tmp_path, capsys, WORK + REPORT, gate="false")[0] == 1
529
+ assert walk(tmp_path, capsys, WORK + REPORT, gate="false")[0] == 2
539
530
  state = state_of(tmp_path)
531
+ state["run"]["questions"] = []
540
532
  state["tickets"]["01"].update(fields)
541
533
  (tmp_path / ".agent/implement/state.json").write_text(json.dumps(state))
542
534
  return state["tickets"]["01"]
@@ -579,7 +571,7 @@ def test_a_run_of_a_driver_with_untiered_gates_resumes_with_its_greens_as_full_g
579
571
  code, ledger, out = walk(tmp_path, capsys, "exit 9\n", gate='[ "$(git rev-parse --abbrev-ref HEAD)" != ticket/feat%2Fx/01 ]')
580
572
  after = state_of(tmp_path)
581
573
  assert code == 0 and walked() == tip and not full.exists(), out # the fast-forward ran no gate
582
- assert after["run"]["schema"] == 3 and after["tickets"]["01"]["green_gates"] == {"fast": [], "full": [tip]}
574
+ assert after["run"]["schema"] == driver_state.SCHEMA and after["tickets"]["01"]["green_gates"] == {"fast": [], "full": [tip]}
583
575
  assert after["run"]["gates"] == {"fast": 0, "full": 5} # the four of the older run and the end of run
584
576
 
585
577
 
@@ -891,26 +883,6 @@ def test_a_conflict_on_the_second_try_blocks_the_ticket_with_no_conflict_agent(r
891
883
  assert "| fast gates run | 2 |" in out and "| full gates run | 2 |" in out
892
884
 
893
885
 
894
- def test_the_landing_check_runs_while_the_ticket_holds_the_merge_lock(repo, tmp_path, capsys, monkeypatch):
895
- """Review round 1, m2: the check and the ref move are one step only under the lock that makes merges serial."""
896
- two(repo)
897
- runs, held, check = [], [], driver.driver_merge.refused
898
-
899
- class Seen(driver.Run):
900
- def __init__(self, *args, **kwargs):
901
- super().__init__(*args, **kwargs)
902
- runs.append(self)
903
-
904
- def refused(*args):
905
- held.append(runs[0].merging.locked())
906
- return check(*args)
907
-
908
- monkeypatch.setattr(driver, "Run", Seen)
909
- monkeypatch.setattr(driver.driver_merge, "refused", refused)
910
- code, _, out = walk(tmp_path, capsys, WORK + TOGETHER + REPORT)
911
- assert code == 0 and held == [True, True], out
912
-
913
-
914
886
  # Fix round 1 of ticket 03.
915
887
 
916
888
  def test_a_merge_commit_the_slot_cannot_check_out_is_not_gated_and_does_not_land(repo, tmp_path, capsys):
@@ -931,7 +903,7 @@ def test_a_merge_commit_the_slot_cannot_check_out_is_not_gated_and_does_not_land
931
903
  def test_a_gate_that_changes_the_tree_or_moves_head_is_red(repo, tmp_path, capsys, gate, after):
932
904
  repo(t01=ticket("01", **REFACTOR))
933
905
  code, ledger, out = walk(tmp_path, capsys, GIVE_UP + WORK + REPORT, gate=gate)
934
- assert code == 2 and "from the gate at .agent/implement/01/gate-" in ledger[-4] and ledger[-2:] == [GAVE_UP, ASKED], out
906
+ assert code == 2 and "from the gate at .agent/implement/01/gate-" in ledger[-5] and ledger[-2:] == [GAVE_UP, ASKED], out
935
907
  record = next((tmp_path / ".agent/implement/01").glob("gate-*.log")).read_text()
936
908
  assert "\nexit: 0\n" in record and after in record
937
909
  assert state_of(tmp_path)["tickets"]["01"]["green_gates"] == {"fast": [], "full": []}
@@ -8,14 +8,14 @@ PATH. No test reaches a real remote or a real `gh`.
8
8
  Interface choices (ticket 06):
9
9
  - end-of-run starts only when every ticket is merged and every slot is idle. A repository with no `origin` skips only
10
10
  the rebase and the push (ticket 08): test_amendments.py holds those tests.
11
- - its agents report into `.agent/implement/final/`, so the fake runner keys them `final/final-reviewer`,
12
- `final/fixer` and `final/conflict`; gate records there are `gate-<first 7 hex>.log`.
11
+ - its agents report into `.agent/implement/final/`, so the fake runner keys them `final/final-spec` (and the other
12
+ lenses), `final/final-reviewer`, `final/fixer` and `final/conflict`; gate records there are `gate-<first 7 hex>.log`.
13
13
  - recovery point: before the rebase the driver sets `refs/implement-spec/feat%2Fcsv/recovery` to the PR tip and writes the ledger
14
14
  sentence "Recovery point: ... <sha>". An ended run leaves the ref in place.
15
15
  - a tidied commit has the subject `feat(NN): <ticket title>` and a body line `Ticket: <ticket file name>`.
16
16
  - the final fixer's `commits` hold `{"sha", "ticket"}` objects, and the driver renames each fixer commit to
17
17
  `fix(NN): <its subject>` before the gate and the scoped review run (no rewrite after a review).
18
- - triage after the second final-review round: question `final-finding-<n>`, options `fix` and `accept`.
18
+ - a finding open after the scoped review: question `final-ticket-blocked-<n>`, options `retry` and `edit`.
19
19
  - local stop: stdout lines `Branch tip: <sha>`, `Reviewed tip: <sha>` and the rerun command, which has `--push`.
20
20
  - the PR body lists, per ticket, a line with the ticket number and its commit's first 7 hex, and every ruling line.
21
21
  - stage.json at a clean unattended end is `{"stage": "implement", "status": "done"}`.
@@ -35,11 +35,11 @@ from types import SimpleNamespace
35
35
  import pytest
36
36
 
37
37
  from test_cli import SKILL, git, ticket
38
- from test_review import FABLE, HOOKED, ONE, OPUS, Review, finding, gate_rule, no_full_gate, review
39
- from test_stops import UNATTENDED, decisions, stage
40
- from test_walk import fix, impl, plan, tw
38
+ from test_review import ASTRA, FABLE, HOOKED, ONE, OPUS, Review, finding, gate_rule, no_full_gate, review
39
+ from test_stops import UNATTENDED, stage
40
+ from test_walk import fix, impl, plan
41
41
 
42
- SCOPED = HOOKED.replace('("reviewer", "correctness")', '("reviewer", "correctness", "final-reviewer")')
42
+ SCOPED = HOOKED
43
43
  RUNNER = SCOPED.replace(
44
44
  'for cmd in step.get("git", []):',
45
45
  '''if step.get("wait_pr_has"):
@@ -70,7 +70,7 @@ if "commit" in step:''', 1).replace(
70
70
  'for cmd in step.get("git_end", []):\n git(*cmd)\n sha = git("rev-parse", "HEAD")\nif step.get("report") is not None:', 1,
71
71
  ).replace('json.dumps(step["report"]).replace("$SHA", sha)', 'render(step["report"])', 1)
72
72
  assert "render(step" in RUNNER and RUNNER.count("git_end") == 1 and RUNNER.count("wait_pr_has") == 2
73
- assert '"final-reviewer")' in RUNNER and RUNNER.count("final-reviewer") == 1
73
+ assert '"final-structure")' in RUNNER and RUNNER.count("final-reviewer") == 1
74
74
 
75
75
  GH = f"""#!{sys.executable}
76
76
  import json, os, sys
@@ -94,7 +94,7 @@ THREE = {
94
94
  "03-cli-flag.md": ticket("03", "CLI flag", seam="`demo export` CLI", touches="`demo/cli.py: main`"),
95
95
  }
96
96
  FILES = {nn: f"{nn}-{TITLES[nn].lower().replace(' ', '-')}.md" for nn in TITLES}
97
- FINAL_MODELS = {"final-reviewer": [FABLE, OPUS]}
97
+ FINAL_MODELS = {"final-reviewer": [FABLE, OPUS, ASTRA]}
98
98
 
99
99
 
100
100
  def ref(root, name):
@@ -187,22 +187,20 @@ def stop_lines(out):
187
187
 
188
188
  # ---------------------------------------------------------------- the story: stop, local stop, rerun, push
189
189
 
190
- NEW_03 = "def test_x():\n assert '03' == '03'\n"
191
- CONTRA_03 = "locked test contradicts spec: tests/test_03.py::test_x"
190
+ STOP_03 = {"report": {"status": "BLOCKED", "commits": [], "files": [], "concerns": ["no write access to fixtures/"],
191
+ "green": []}}
192
192
 
193
193
 
194
194
  @pytest.fixture(scope="module")
195
195
  def story(tmp_path_factory):
196
- """01 merges, 03 stops on a contradicted locked test and is overruled, 02 is held in review, then end-of-run."""
196
+ """01 merges, 03 stops two times and is retried, 02 is held in review, then end-of-run."""
197
197
  rig = Final(tmp_path_factory.mktemp("story"), THREE, FINAL_MODELS)
198
198
  steps = plan(**{
199
- "03/test-writer": [tw("03"), {**tw("03"), "files": {"tests/test_03.py": NEW_03}, "commit": "test: 03 overruled"}],
200
- "03/implementer": [{"report": {"status": "BLOCKED", "commits": [], "files": [], "concerns": [CONTRA_03],
201
- "green": []}}, impl("03", "demo/cli.py")],
199
+ "03/implementer": [STOP_03, STOP_03, impl("03", "demo/cli.py")],
202
200
  "02/reviewer": [review("02", [finding("M-MINOR", "minor")], hold=0.8)]})
203
201
  rig.run(steps)
204
202
  stopped = rig.snap()
205
- rig.run(steps, "--answer", "03-locked-test-1=overrule-test")
203
+ rig.run(steps, "--answer", "03-ticket-blocked-1=retry")
206
204
  local = rig.snap()
207
205
  rig.run(steps)
208
206
  again = rig.snap()
@@ -215,15 +213,15 @@ def test_end_of_run_work_does_not_start_while_02_is_in_review(story):
215
213
  assert story.local.code == 0, rig.output()
216
214
  (held,) = [c["held"] for c in rig.calls("02", "reviewer")]
217
215
  assert held["before"] == held["after"] and not held["recovery"], "nothing rewrote the branch while 02 ran"
218
- finals = rig.final_calls("final-reviewer")
216
+ finals = rig.final_calls("final-spec")
219
217
  assert finals and finals[0]["t0"] >= rig.calls("02", "reviewer")[0]["t1"], "no final review before 02 left review"
220
218
 
221
219
 
222
- def test_seven_commits_in_merge_order_are_tidied_into_three_ticket_commits_with_the_same_tree(story):
220
+ def test_six_commits_in_merge_order_are_tidied_into_three_ticket_commits_with_the_same_tree(story):
223
221
  rig = story.rig
224
222
  assert story.local.code == 0, rig.output()
225
223
  assert rig.recovery(), "no recovery point"
226
- assert len(rig.commits(rig.start, rig.recovery())) == 7
224
+ assert len(rig.commits(rig.start, rig.recovery())) == 6
227
225
  rows = rig.commits(rig.start)
228
226
  assert [r["subject"] for r in rows] == [f"feat({nn}): {TITLES[nn]}" for nn in ("01", "03", "02")]
229
227
  assert all(f"Ticket: {FILES[nn]}" in r["body"] for nn, r in zip(("01", "03", "02"), rows))
@@ -236,16 +234,16 @@ def test_one_gate_record_exists_for_the_tidied_tip_and_the_final_reviewer_is_poi
236
234
  assert [p.name for p in records] == [f"gate-full-{tip[:7]}.log"], records
237
235
  assert "GATE-OUTPUT-MARK" in records[0].read_text() and tip[:7] in records[0].read_text()
238
236
  (gate,) = [g for g in rig.gates() if g["commit"] == tip]
239
- first = rig.final_calls("final-reviewer")[0]
237
+ first = rig.final_calls("final-spec")[0]
240
238
  assert gate["t0"] < first["t0"], "the gate runs before the final review"
241
239
  assert f"final/gate-full-{tip[:7]}.log" in first["prompt"]
242
240
 
243
241
 
244
- def test_the_final_reviewer_runs_on_the_first_model_entry_pointed_at_review_diff_minors_and_rulings(story):
242
+ def test_the_spec_lens_runs_on_the_first_model_entry_pointed_at_review_diff_minors_and_rulings(story):
245
243
  rig = story.rig
246
- assert rig.led("final-reviewer", FABLE) and not rig.led("final-reviewer", OPUS)
247
- prompt = rig.final_calls("final-reviewer")[0]["prompt"]
248
- assert "review-diff" in prompt and "M-MINOR" in prompt and "locked test overruled" in prompt
244
+ assert rig.led("final-spec", FABLE) and not rig.led("final-spec", OPUS)
245
+ prompt = rig.final_calls("final-spec")[0]["prompt"]
246
+ assert "review-diff" in prompt and "M-MINOR" in prompt and "Ruling: 03 runs again (retry)" in prompt
249
247
  assert '"severity"' in prompt and '"findings"' in prompt, "the reviewer schema"
250
248
 
251
249
 
@@ -277,7 +275,7 @@ def test_the_push_rerun_pushes_once_opens_the_pr_with_map_and_rulings_and_runs_o
277
275
  lines = pr["body"].splitlines()
278
276
  for nn, row in zip(("01", "03", "02"), rig.commits(rig.start)):
279
277
  assert [l for l in lines if nn in l and row["sha"][:7] in l], (nn, pr["body"])
280
- assert "locked test overruled" in pr["body"]
278
+ assert "Ruling: 03 runs again (retry)" in pr["body"]
281
279
 
282
280
 
283
281
  # ---------------------------------------------------------------- the fix batch
@@ -285,7 +283,7 @@ def test_the_push_rerun_pushes_once_opens_the_pr_with_map_and_rulings_and_runs_o
285
283
  @pytest.fixture(scope="module")
286
284
  def fixed(tmp_path_factory):
287
285
  rig = Final(tmp_path_factory.mktemp("fixed"), THREE, FINAL_MODELS)
288
- rig.run(plan(**{"final/final-reviewer": [final(finding("Q-ONE"), finding("Q-TWO")), final()],
286
+ rig.run(plan(**{"final/final-spec": [final(finding("Q-ONE"), finding("Q-TWO"))], "final/final-reviewer": [final()],
289
287
  "final/fixer": [fixer(fn("02"), "quote embedded commas", "escape quotes")]}))
290
288
  return rig
291
289
 
@@ -294,7 +292,7 @@ def test_two_findings_make_one_fixer_batch_of_fix_commits_on_top_of_the_unchange
294
292
  assert fixed.code == 0, fixed.output()
295
293
  (batch,) = fixed.final_calls("fixer")
296
294
  assert "Q-ONE" in batch["prompt"] and "Q-TWO" in batch["prompt"]
297
- reviewed = fixed.final_calls("final-reviewer")[0]["head"]
295
+ reviewed = fixed.final_calls("final-spec")[0]["head"]
298
296
  assert [r["subject"] for r in fixed.commits(reviewed)] == ["fix(02): quote embedded commas", "fix(02): escape quotes"]
299
297
  assert len(fixed.commits(fixed.start, reviewed)) == 3
300
298
  assert ref(fixed.repo, "feat/csv~2") == reviewed
@@ -308,7 +306,7 @@ def test_green_ticket_carries_cap_finding_into_required_final_fix(tmp_path):
308
306
  batch = fixer(fn("02"), "restore quoting", ticket_of="02")
309
307
  batch["report"]["addressed_must_fix"] = ["MERGED-QUOTING-REGRESSION (demo/export.py:99)"]
310
308
  steps = plan(**{"02/reviewer": [recurring] * 3, "02/fixer": [fix("02", 1), fix("02", 2)],
311
- "final/final-reviewer": [final(), scoped], "final/fixer": [batch]})
309
+ "final/final-reviewer": [scoped], "final/fixer": [batch]})
312
310
 
313
311
  rig.run(steps)
314
312
 
@@ -325,17 +323,18 @@ def test_unresolved_must_fix_cannot_be_accepted_or_published(tmp_path):
325
323
  batch = fixer(fn("02"), "attempt quoting fix", ticket_of="02")
326
324
  batch["report"]["addressed_must_fix"] = ["MERGED-QUOTING-REGRESSION (demo/export.py:99)"]
327
325
  steps = plan(**{"02/reviewer": [recurring] * 3, "02/fixer": [fix("02", 1), fix("02", 2)],
328
- "final/final-reviewer": [final(), final(finding("MERGED-QUOTING-REGRESSION"))],
326
+ "final/final-reviewer": [final(finding("MERGED-QUOTING-REGRESSION"))],
329
327
  "final/fixer": [batch]})
330
328
 
331
329
  rig.run(steps)
332
330
 
333
- assert rig.code == 1, rig.output()
334
- assert not rig.state()["run"]["questions"]
331
+ assert rig.code == 2, rig.output()
332
+ (question,) = rig.state()["run"]["questions"]
333
+ assert question["id"] == "final-ticket-blocked-1" and "MERGED-QUOTING-REGRESSION" in question["subject"]
335
334
  assert [item["title"] for item in rig.state()["run"]["final"]["open"]] == ["MERGED-QUOTING-REGRESSION"]
336
335
  assert not rig.pushes() and not rig.prs()
337
336
  rig.run(steps)
338
- assert rig.code == 1 and len(rig.final_calls("fixer")) == 1
337
+ assert rig.code == 2 and len(rig.final_calls("fixer")) == 1
339
338
  assert not rig.pushes() and not rig.prs()
340
339
 
341
340
 
@@ -343,12 +342,11 @@ def test_final_fix_batch_rejects_an_unaddressed_must_fix(tmp_path):
343
342
  rig = Final(tmp_path, THREE, {"implementer": [OPUS, FABLE]})
344
343
  recurring = review("02", [{**finding("MERGED-QUOTING-REGRESSION"), "basis": "regression"}])
345
344
  steps = plan(**{"02/reviewer": [recurring] * 3, "02/fixer": [fix("02", 1), fix("02", 2)],
346
- "final/final-reviewer": [final()],
347
345
  "final/fixer": [fixer(fn("02"), "attempt quoting fix", ticket_of="02")]})
348
346
 
349
347
  rig.run(steps)
350
348
 
351
- assert rig.code == 1, rig.output()
349
+ assert rig.code == 2, rig.output()
352
350
  assert not rig.pushes() and not rig.prs()
353
351
  assert any("addressed_must_fix: missing MERGED-QUOTING-REGRESSION (demo/export.py:99)" in line for line in rig.ledger())
354
352
 
@@ -359,20 +357,20 @@ def test_the_fixer_of_the_final_review_gets_the_fast_gate_with_every_merged_lock
359
357
  no_full_gate(fixed)
360
358
 
361
359
 
362
- def test_the_final_reviewer_reads_the_full_record_of_the_reviewed_tip_and_runs_no_gate(fixed):
363
- for call in fixed.final_calls("final-reviewer"):
360
+ def test_the_final_review_reads_the_full_record_of_the_reviewed_tip_and_runs_no_gate(fixed):
361
+ for call in fixed.final_calls("final-spec") + fixed.final_calls("final-reviewer"):
364
362
  assert f"final/gate-full-{call['head'][:7]}.log" in call["prompt"]
365
363
  assert "Do not run a gate yourself." in call["prompt"] and "run the gate yourself" not in call["prompt"]
366
364
 
367
365
 
368
366
  def test_a_scoped_review_covers_the_range_after_the_reviewed_tip_and_one_gate_runs_on_the_new_tip(fixed):
369
- reviewed, tip = fixed.final_calls("final-reviewer")[0]["head"], fixed.branch()
370
- first, scoped = fixed.final_calls("final-reviewer")
367
+ reviewed, tip = fixed.final_calls("final-spec")[0]["head"], fixed.branch()
368
+ (scoped,) = fixed.final_calls("final-reviewer")
371
369
  assert reviewed[:7] in scoped["prompt"] and tip[:7] in scoped["prompt"]
372
370
  assert len([g for g in fixed.gates() if g["commit"] == tip]) == 1
373
371
  records = sorted(p.name for p in (fixed.repo / ".agent/implement/final").glob("gate-*.log"))
374
372
  assert records == sorted({f"gate-full-{reviewed[:7]}.log", f"gate-full-{tip[:7]}.log"})
375
- assert len(fixed.final_calls("final-reviewer")) == 2 and all(stop_lines(fixed.out))
373
+ assert all(stop_lines(fixed.out))
376
374
 
377
375
 
378
376
  # ---------------------------------------------------------------- schema violations
@@ -385,54 +383,23 @@ def violation(tmp_path_factory):
385
383
  attempt = fixer(fn("01"), "tidy the header", ticket_of="01")
386
384
  del attempt["report"]["commits"][0]["ticket"]
387
385
  retry = {"report": dict(attempt["report"], commits=[{"sha": "$HEAD", "ticket": "01"}])}
388
- rig.run(plan(**{"final/final-reviewer": [final(bad), final(finding("HEADER")), final()],
386
+ rig.run(plan(**{"final/final-spec": [final(bad), final(finding("HEADER"))], "final/final-reviewer": [final()],
389
387
  "final/fixer": [attempt, retry]}))
390
388
  return rig
391
389
 
392
390
 
393
391
  def test_a_final_review_report_follows_the_reviewer_schema_or_is_rerun_once(violation):
394
392
  assert violation.code == 0, violation.output()
395
- calls = violation.final_calls("final-reviewer")
396
- assert len(calls) == 3 and "HEADER" in violation.final_calls("fixer")[0]["prompt"]
393
+ calls = violation.final_calls("final-spec")
394
+ assert len(calls) == 2 and "HEADER" in violation.final_calls("fixer")[0]["prompt"]
397
395
 
398
396
 
399
397
  def test_a_fixer_commit_without_its_ticket_is_a_schema_violation(violation):
400
398
  assert len(violation.final_calls("fixer")) == 2
401
- reviewed = violation.final_calls("final-reviewer")[0]["head"]
399
+ reviewed = violation.final_calls("final-spec")[0]["head"]
402
400
  assert [r["subject"] for r in violation.commits(reviewed)] == ["fix(01): tidy the header"]
403
401
 
404
402
 
405
- # ---------------------------------------------------------------- the third round
406
-
407
- @pytest.fixture(scope="module")
408
- def third(tmp_path_factory):
409
- rig = Final(tmp_path_factory.mktemp("third"), ONE)
410
- steps = plan(**{"final/final-reviewer": [final(finding("STILL-OPEN")), final(finding("STILL-OPEN"))],
411
- "final/fixer": [fixer(fn("01"), "first try", ticket_of="01")]})
412
- rig.run(steps)
413
- parked = rig.snap()
414
- questions = decisions(rig)["questions"] if parked.code == 2 else []
415
- rig.run(steps, "--answer", "final-finding-1=accept")
416
- return SimpleNamespace(rig=rig, parked=parked, questions=questions, answered=rig.snap())
417
-
418
-
419
- def test_findings_open_after_the_second_round_become_fix_or_accept_questions_and_no_third_round_starts(third):
420
- rig = third.rig
421
- assert third.parked.code == 2, third.parked.out
422
- (q,) = third.questions
423
- assert q["id"] == "final-finding-1" and {o["id"] for o in q["options"]} == {"fix", "accept"}
424
- assert "STILL-OPEN" in q["title"] + q["why"] and "final-finding-1" in third.parked.out
425
- assert len(rig.final_calls("final-reviewer")) == 2 and len(rig.final_calls("fixer")) == 1
426
- assert third.parked.pushes == 0
427
-
428
-
429
- def test_accepting_the_finding_ends_the_run_with_a_ruling_and_starts_no_more_agents(third):
430
- rig = third.rig
431
- assert third.answered.code == 0, rig.output()
432
- assert rig.led("Ruling", "STILL-OPEN", "accept")
433
- assert (third.answered.calls, third.answered.pushes) == (third.parked.calls, 0) and all(stop_lines(third.answered.out))
434
-
435
-
436
403
  # ---------------------------------------------------------------- the rebase
437
404
 
438
405
  CLI_RESOLVED = "def main():\n return 'resolved'\n"
@@ -475,7 +442,7 @@ def conflicted_twice(tmp_path_factory):
475
442
  def test_a_second_conflict_ends_the_run_with_exit_1_and_the_branch_unrewritten_at_its_recovery_point(conflicted_twice):
476
443
  rig = conflicted_twice
477
444
  assert rig.code == 1, rig.output()
478
- assert len(rig.final_calls("conflict")) == 1 and not rig.final_calls("final-reviewer")
445
+ assert len(rig.final_calls("conflict")) == 1 and not rig.final_calls("final-spec")
479
446
  recovery = rig.recovery()
480
447
  assert recovery and rig.branch() == recovery and len(rig.commits(rig.start, recovery)) == 6
481
448
  assert rig.led("ecovery", recovery[:7])
@@ -505,7 +472,7 @@ def test_unattended_with_everything_validated_pushes_once_opens_the_pr_and_write
505
472
 
506
473
  def test_unattended_with_a_blocked_ticket_pushes_nothing_and_exits_1(tmp_path):
507
474
  rig = Final(tmp_path, THREE, gate={"red": ["ticket/feat%2Fcsv/01"]})
508
- rig.run(plan(), *UNATTENDED)
475
+ rig.run(plan(**{"01/fixer": [fix("01", n) for n in (1, 2)]}), *UNATTENDED)
509
476
  assert rig.code == 1, rig.output()
510
477
  assert rig.pushes() == [] and not rig.prs() and not ref(rig.origin, "refs/heads/feat/csv")
511
478
  assert stage(rig) == {"stage": "implement", "status": "blocked", "blocked": ["01"]}
@@ -565,7 +532,8 @@ def pushed_run(tmp_path, monkeypatch, steps, risk_in, gh_fails=False):
565
532
  (tmp_path / "bin/gh").write_text("#!/bin/sh\necho gh down >&2\nexit 1\n")
566
533
  skills = tmp_path / "installed/skills"
567
534
  shutil.copytree(SKILL, skills / "implement-spec", ignore=shutil.ignore_patterns("__pycache__", ".pytest_cache", "test_*"))
568
- shutil.copytree(SKILL.parent / "review-diff", skills / "review-diff", ignore=shutil.ignore_patterns("__pycache__"))
535
+ for name in ("review-diff", "deep-quality-review"):
536
+ shutil.copytree(SKILL.parent / name, skills / name, ignore=shutil.ignore_patterns("__pycache__"))
569
537
  home = tmp_path / "home"
570
538
  claude = tmp_path / "claude-home"
571
539
  claude.mkdir(), home.mkdir()