@jesdi/skills 0.0.75 → 0.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/implement-spec/README.md +26 -22
- package/skills/implement-spec/SKILL.md +1 -1
- package/skills/implement-spec/driver.py +75 -44
- package/skills/implement-spec/driver_final.py +52 -34
- package/skills/implement-spec/driver_fixloop.py +65 -17
- package/skills/implement-spec/driver_gate.py +25 -12
- package/skills/implement-spec/driver_legacy.py +19 -7
- package/skills/implement-spec/driver_report.py +10 -3
- package/skills/implement-spec/driver_run.py +17 -13
- package/skills/implement-spec/driver_state.py +17 -7
- package/skills/implement-spec/driver_summary.py +1 -1
- package/skills/implement-spec/prompts/final-fixer.md +1 -1
- package/skills/implement-spec/prompts/final-reviewer.md +2 -2
- package/skills/implement-spec/prompts/fixer.md +1 -1
- package/skills/implement-spec/prompts/implementer.md +1 -1
- package/skills/implement-spec/prompts/landing-merge.md +1 -0
- package/skills/implement-spec/prompts/landing-red.md +2 -0
- package/skills/implement-spec/tests/test_agents.py +2 -2
- package/skills/implement-spec/tests/test_amendments.py +1 -1
- package/skills/implement-spec/tests/test_cli.py +4 -4
- package/skills/implement-spec/tests/test_driver.py +73 -30
- package/skills/implement-spec/tests/test_final.py +14 -7
- package/skills/implement-spec/tests/test_fixloop.py +172 -21
- package/skills/implement-spec/tests/test_landing.py +1 -1
- package/skills/implement-spec/tests/test_report.py +2 -2
- package/skills/implement-spec/tests/test_review.py +16 -8
- package/skills/implement-spec/tests/test_state.py +6 -6
- package/skills/implement-spec/tests/test_summary.py +3 -2
- package/skills/implement-spec/tests/test_tidy.py +13 -12
- package/skills/implement-spec/tests/test_walk.py +52 -35
- package/skills-manifest.json +3 -3
|
@@ -41,7 +41,7 @@ class Job:
|
|
|
41
41
|
"""The values of a prompt; `review` is the round whose findings the agent reads."""
|
|
42
42
|
entry = self.run.state.read()["tickets"][self.ticket.number]
|
|
43
43
|
findings = os.path.relpath(OUT / self.ticket.number / f"findings-{review}.json", self.slot)
|
|
44
|
-
gate = os.path.relpath(driver_gate.record_path(OUT / self.ticket.number, self.tip), self.slot)
|
|
44
|
+
gate = os.path.relpath(driver_gate.record_path(OUT / self.ticket.number, driver_gate.FAST, self.tip), self.slot)
|
|
45
45
|
return {**self.values, "start_sha": self.tip, "from_sha": self.previous, "round": str(self.round),
|
|
46
46
|
"locked": " ".join(entry["locked"]), "locked_tests": " ".join(tested(entry)), "test_writer_sha": str(entry["test_writer_sha"] or ""),
|
|
47
47
|
"findings": findings, "gate_record": gate,
|
|
@@ -59,9 +59,9 @@ def entry(models: dict[str, list[str]], round: int) -> str:
|
|
|
59
59
|
return entries[1] if round >= 2 else entries[0]
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
def _log_findings(
|
|
62
|
+
def _log_findings(number: str, findings: list[dict]) -> list[dict]:
|
|
63
63
|
for finding in findings:
|
|
64
|
-
ledger(f"Ticket {
|
|
64
|
+
ledger(f"Ticket {number}: {finding['severity']} finding of kind {finding['kind']} from the "
|
|
65
65
|
f"{finding['source']} at {finding['file']}:{finding['line']}: {finding['title']}.")
|
|
66
66
|
return findings
|
|
67
67
|
|
|
@@ -171,7 +171,7 @@ def _review(job: Job) -> list[dict]:
|
|
|
171
171
|
run, number = job.run, job.ticket.number
|
|
172
172
|
state = run.state.ticket(number, phase="review")
|
|
173
173
|
merged = driver_merge.changed(job.slot, run.tip(), driver_merge.protected(run.state.read()["tickets"], number))
|
|
174
|
-
found = _log_findings(
|
|
174
|
+
found = _log_findings(number, driver_review.locked_findings(job.slot, state) + driver_review.merged_changes(merged))
|
|
175
175
|
cast = [("reviewer", "")]
|
|
176
176
|
if job.ticket.risk:
|
|
177
177
|
cast.append(("correctness", driver_agents.correctness_entry(run.models)))
|
|
@@ -180,7 +180,7 @@ def _review(job: Job) -> list[dict]:
|
|
|
180
180
|
if state["rejected"]:
|
|
181
181
|
run.state.ticket(number, rejected={}) # the rejection is answered: no later review repeats it
|
|
182
182
|
reviewed, observations = _reviewer_results(job, cast, reports)
|
|
183
|
-
found += _log_findings(
|
|
183
|
+
found += _log_findings(number, reviewed)
|
|
184
184
|
_store_observations(job, observations)
|
|
185
185
|
(OUT / number / f"findings-{job.round}.json").write_text(json.dumps(found, indent=1) + "\n")
|
|
186
186
|
return found
|
|
@@ -199,7 +199,7 @@ def _correct(job: Job, findings: list[dict]) -> list[dict]:
|
|
|
199
199
|
# The gate was green on the tip before the restore, so a red gate here is a restored file that fails with the
|
|
200
200
|
# ticket's code. The driver decides that, not the correction (issue #90).
|
|
201
201
|
with during("the gate of the restore"):
|
|
202
|
-
record = run.red_gate(number, job.slot, job.tip) if restored else ""
|
|
202
|
+
record = run.red_gate(number, job.slot, job.tip, driver_gate.FAST, restored) if restored else ""
|
|
203
203
|
if not record and all(finding["source"] == "driver" for finding in findings):
|
|
204
204
|
job.previous = "" # no review has seen the restore commit
|
|
205
205
|
ledger(f"Ticket {number}: the code does not need the change to {', '.join(restored)}: the restore closes it, "
|
|
@@ -244,20 +244,37 @@ def _uncorrected(job: Job, findings: list[dict], not_addressed: list[dict]) -> l
|
|
|
244
244
|
return list(code.values())
|
|
245
245
|
|
|
246
246
|
|
|
247
|
-
def
|
|
247
|
+
def _red(job: Job, landing: str) -> str:
|
|
248
|
+
"""The red gate that the fixer has to make green, or ""."""
|
|
249
|
+
return (f"the fast gate is red on {job.tip[:7]}" if job.red else
|
|
250
|
+
f"the full gate is red on {landing[:7]}" if landing else "")
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _fix(job: Job, findings: list[dict], landing: str = "") -> None:
|
|
248
254
|
"""Run the next fix round: a fixer on the implementer's list, for `findings`. A fixer that makes no commit gives
|
|
249
|
-
a reason per finding, and the review of the same tip checks them (issue #123).
|
|
255
|
+
a reason per finding, and the review of the same tip checks them (issue #123). `landing` is the commit whose full
|
|
256
|
+
gate was red at the landing, when that started the round."""
|
|
250
257
|
run, number = job.run, job.ticket.number
|
|
251
258
|
job.round += 1
|
|
252
259
|
on = entry(run.models, job.round)
|
|
253
|
-
run.state.ticket(number, phase="fix", round=job.round)
|
|
260
|
+
run.state.ticket(number, phase="fix", round=job.round, landing=landing or None)
|
|
254
261
|
if job.round == 2:
|
|
255
262
|
ledger(f"Ticket {number} round 2: escalated to {on}.")
|
|
263
|
+
values, notes = job.pointers(job.round - 1), []
|
|
264
|
+
if landing:
|
|
265
|
+
record = driver_gate.record_path(OUT / number, driver_gate.FULL, landing)
|
|
266
|
+
values.update(landing_sha=landing[:7], landing_record=os.path.relpath(record, job.slot))
|
|
267
|
+
notes = ["landing-red"] + ["landing-merge"] * (landing != job.tip)
|
|
256
268
|
with during(f"fix round {job.round}"):
|
|
257
|
-
run.agent("fixer", number, job.slot,
|
|
258
|
-
check={"fix": [finding["title"] for finding in findings], "red": job
|
|
269
|
+
run.agent("fixer", number, job.slot, values, entry=on, fix_round=job.round, notes=notes,
|
|
270
|
+
check={"fix": [finding["title"] for finding in findings], "red": _red(job, landing)})
|
|
259
271
|
before, job.tip = job.tip, driver_slots.head(job.slot)
|
|
260
|
-
run.state.ticket(number, tip=job.tip)
|
|
272
|
+
run.state.ticket(number, tip=job.tip, landing=None)
|
|
273
|
+
_follow_fix(job, before)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _follow_fix(job: Job, before: str) -> None:
|
|
277
|
+
"""Carry the proofs and the range of the next review over the fix from `before` to the new tip."""
|
|
261
278
|
followed = driver_review.follow(job.slot, before, job.tip, job.proofs)
|
|
262
279
|
due = {proof for proof, changed in followed.items() if changed}
|
|
263
280
|
if job.red:
|
|
@@ -338,30 +355,61 @@ def _act_on(job: Job, found: list[dict]) -> bool:
|
|
|
338
355
|
return False
|
|
339
356
|
|
|
340
357
|
|
|
358
|
+
class Unlanded(Exception):
|
|
359
|
+
"""The full gate is red on the commit that would land, and the next fix round of the ticket has started."""
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def red_landing(run: Run, number: str, slot: str, commit: str, record: str) -> None:
|
|
363
|
+
"""The full gate is red on `commit`, the commit that would land: the PR branch does not move. At round 2 that
|
|
364
|
+
blocks. Before it, the record is a critical `gate` finding for the next round, which starts in the same write of
|
|
365
|
+
state.json that leaves the landing, so a resumed run starts that round's fixer and never gates `commit` again.
|
|
366
|
+
Call it with the ticket branch checked out in the slot: the fixer works there."""
|
|
367
|
+
entry = run.state.read()["tickets"][number]
|
|
368
|
+
if entry["round"] == ROUNDS:
|
|
369
|
+
raise Blocked(f"the full gate is red on {commit[:7]}, record {record}")
|
|
370
|
+
path = os.path.relpath(record, slot)
|
|
371
|
+
finding = {"severity": "critical", "file": path, "line": 0, "title": f"the full gate is red on {commit[:7]}",
|
|
372
|
+
"evidence": f"the output of the gate in {path}", "kind": "code", "source": "gate"}
|
|
373
|
+
# The fixer reads the findings of the last review: its minor findings stay there for the final review.
|
|
374
|
+
file = OUT / number / f"findings-{entry['round']}.json"
|
|
375
|
+
found = json.loads(file.read_text()) if file.exists() else []
|
|
376
|
+
if finding["title"] not in [old["title"] for old in found]: # a run stopped before the round gated it again
|
|
377
|
+
file.write_text(json.dumps(found + [finding], indent=1) + "\n")
|
|
378
|
+
_log_findings(number, [finding])
|
|
379
|
+
run.state.ticket(number, phase="fix", round=entry["round"] + 1, landing=commit)
|
|
380
|
+
ledger(f"Ticket {number}: the full gate is red on {commit[:7]} at the landing, so {run.pr} does not move and fix "
|
|
381
|
+
f"round {entry['round'] + 1} starts.")
|
|
382
|
+
raise Unlanded()
|
|
383
|
+
|
|
384
|
+
|
|
341
385
|
def _gate(job: Job) -> list[dict]:
|
|
342
|
-
"""
|
|
386
|
+
"""Fast-gate the candidate tip. A red gate before round 2 is a finding for the next round;
|
|
343
387
|
a red gate after round 2 or on a test-writer correction blocks. Returns the findings: the red gate,
|
|
344
388
|
or none."""
|
|
345
389
|
run, number = job.run, job.ticket.number
|
|
346
390
|
job.red = False
|
|
347
391
|
with during("the gate"):
|
|
348
392
|
if job.round == ROUNDS or job.corrected:
|
|
349
|
-
run.gate(number, job.slot, job.tip)
|
|
393
|
+
run.gate(number, job.slot, job.tip, driver_gate.FAST)
|
|
350
394
|
return []
|
|
351
|
-
record = run.red_gate(number, job.slot, job.tip)
|
|
395
|
+
record = run.red_gate(number, job.slot, job.tip, driver_gate.FAST)
|
|
352
396
|
if not record:
|
|
353
397
|
return []
|
|
354
398
|
job.red, path = True, os.path.relpath(record, job.slot)
|
|
355
|
-
found = [{"severity": "critical", "file": path, "line": 0, "title": f"the gate is red on {job.tip[:7]}",
|
|
399
|
+
found = [{"severity": "critical", "file": path, "line": 0, "title": f"the fast gate is red on {job.tip[:7]}",
|
|
356
400
|
"evidence": f"the output of the gate in {path}", "kind": "code", "source": "gate"}]
|
|
357
401
|
(OUT / number / f"findings-{job.round}.json").write_text(json.dumps(found, indent=1) + "\n")
|
|
358
|
-
return _log_findings(
|
|
402
|
+
return _log_findings(number, found)
|
|
359
403
|
|
|
360
404
|
|
|
361
405
|
def run(ticket: Ticket, slot: str, run: Run, values: dict[str, str]) -> None:
|
|
362
406
|
"""Gate, review and fix the ticket tip until a review leaves no finding open."""
|
|
363
407
|
state = run.state.read()["tickets"][ticket.number]
|
|
364
408
|
job = Job(ticket, slot, run, values, state["round"], state["tip"])
|
|
409
|
+
if state["phase"] == "fix" and state["landing"]:
|
|
410
|
+
# A red full gate at the landing started this round, and its fixer has not reported yet.
|
|
411
|
+
job.round -= 1
|
|
412
|
+
_fix(job, [{"title": f"the full gate is red on {state['landing'][:7]}"}], state["landing"])
|
|
365
413
|
while True:
|
|
366
414
|
found = _gate(job)
|
|
367
415
|
if not found:
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
"""The gate
|
|
1
|
+
"""The gate, in two tiers: the fast gate (`--fast-gate`, the ticket's locked tests, lint and types) on each candidate,
|
|
2
|
+
and the full gate (`--gate`, the repo's whole check) on each commit that would land and at the end of the run.
|
|
2
3
|
|
|
3
|
-
A gate record is `<folder>/gate-<first 7 hex of the commit>.log`. It is green only for exit 0 on a tree that is
|
|
4
|
+
A gate record is `<folder>/gate-<tier>-<first 7 hex of the commit>.log`. It is green only for exit 0 on a tree that is
|
|
4
5
|
clean before the command and after it, with HEAD still on the commit. A command that a signal ended, on a clean tree
|
|
5
6
|
with HEAD unmoved, did not judge the commit: it runs once more, and that run overwrites the record. A signal ended the
|
|
6
7
|
command when its exit is negative, or when it is 128+N for N in SIGHUP, SIGINT, SIGKILL or SIGTERM: a shell that does
|
|
7
8
|
not exec its last command, as dash does not, outlives the killed child and exits with 128+N.
|
|
9
|
+
|
|
10
|
+
Each gate has `IMPLEMENT_SPEC_BASE` (the PR branch) in its environment; the fast gate also has `IMPLEMENT_SPEC_LOCKED`,
|
|
11
|
+
the space-separated locked file paths it checks. A locked path holds no whitespace: the test-writer report is rejected.
|
|
8
12
|
"""
|
|
9
13
|
from __future__ import annotations
|
|
10
14
|
|
|
@@ -41,15 +45,19 @@ def _signal(code: int | str) -> int | None:
|
|
|
41
45
|
return code - 128 if code - 128 in _KILLS else None
|
|
42
46
|
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
FAST, FULL = "fast", "full"
|
|
49
|
+
TIERS = (FAST, FULL)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def record_path(folder: Path, tier: str, commit: str) -> Path:
|
|
53
|
+
return folder / f"gate-{tier}-{commit[:7]}.log"
|
|
46
54
|
|
|
47
55
|
|
|
48
|
-
def _attempt(command: str, slot: str, commit: str, record: Path, env: dict) -> tuple[int | str, str]:
|
|
56
|
+
def _attempt(command: str, tier: str, slot: str, commit: str, record: Path, env: dict) -> tuple[int | str, str]:
|
|
49
57
|
"""Run the command once into `record`. Returns (the exit code or "not run", the state after it)."""
|
|
50
58
|
status = git(slot, "status", "--short").stdout
|
|
51
59
|
with record.open("w") as out:
|
|
52
|
-
out.write(f"start: {_now()}\ncommit: {commit}\nstatus: {'not clean' if status else 'clean'}\n")
|
|
60
|
+
out.write(f"start: {_now()}\ntier: {tier}\ncommit: {commit}\nstatus: {'not clean' if status else 'clean'}\n")
|
|
53
61
|
out.writelines(f" {line}\n" for line in status.splitlines())
|
|
54
62
|
out.write(f"command: {command}\n\n")
|
|
55
63
|
out.flush()
|
|
@@ -62,18 +70,23 @@ def _attempt(command: str, slot: str, commit: str, record: Path, env: dict) -> t
|
|
|
62
70
|
return code, after
|
|
63
71
|
|
|
64
72
|
|
|
65
|
-
def run(command: str, slot: str, folder: Path, pr_branch: str
|
|
66
|
-
|
|
73
|
+
def run(command: str, tier: str, slot: str, folder: Path, pr_branch: str,
|
|
74
|
+
locked: list[str]) -> tuple[bool, Path, list[str]]:
|
|
75
|
+
"""Gate the HEAD of `slot` on `tier`, the fast gate on the `locked` files. Returns (green, the record, a ledger
|
|
76
|
+
sentence per gate that a signal ended)."""
|
|
67
77
|
commit = head(slot)
|
|
68
78
|
folder.mkdir(parents=True, exist_ok=True)
|
|
69
|
-
record = record_path(folder, commit)
|
|
79
|
+
record = record_path(folder, tier, commit)
|
|
70
80
|
# The cache of compiled Python stays out of the slot, so the gate leaves the tree clean.
|
|
71
81
|
env = dict(os.environ, IMPLEMENT_SPEC_BASE=pr_branch, PYTHONPYCACHEPREFIX=str(folder.parent.resolve() / "pycache"))
|
|
72
|
-
|
|
82
|
+
env.pop("IMPLEMENT_SPEC_LOCKED", None) # the full gate gets no list, not even one from the driver's environment
|
|
83
|
+
if tier == FAST:
|
|
84
|
+
env["IMPLEMENT_SPEC_LOCKED"] = " ".join(locked)
|
|
85
|
+
code, after = _attempt(command, tier, slot, commit, record, env)
|
|
73
86
|
killed = []
|
|
74
87
|
# A process outside the gate can kill it, as a `pkill -f` of another slot does: that run judged nothing.
|
|
75
88
|
number = _signal(code)
|
|
76
89
|
if number and after == "clean":
|
|
77
|
-
killed.append(f"the gate of {commit[:7]} was killed by signal {number} and runs again")
|
|
78
|
-
code, after = _attempt(command, slot, commit, record, env)
|
|
90
|
+
killed.append(f"the {tier} gate of {commit[:7]} was killed by signal {number} and runs again")
|
|
91
|
+
code, after = _attempt(command, tier, slot, commit, record, env)
|
|
79
92
|
return code == 0 and after == "clean", record, killed
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
Every run of a newer driver holds `lock` (driver._hold), so a newer and an older driver never run in one repository
|
|
5
5
|
at the same time. The driver calls `resume` once, after the locks and before any check reads a ref: a run with no
|
|
6
|
-
`schema` in state.json gets the new names of its refs.
|
|
6
|
+
`schema` in state.json gets the new names of its refs; a run before schema 3 gets its gates as the full tier.
|
|
7
7
|
ponytail: delete this module, tests/test_legacy.py and its one line in driver._hold and in driver._start_errors
|
|
8
8
|
once no older driver is left.
|
|
9
9
|
"""
|
|
@@ -80,13 +80,25 @@ def lock(common_dir: Path) -> tuple[IO | None, str]:
|
|
|
80
80
|
"Wait until it ends, then run the driver again.")
|
|
81
81
|
|
|
82
82
|
|
|
83
|
+
def _tiered(state: dict) -> None:
|
|
84
|
+
"""Schema 3: every gate of an older driver was the full gate, so its greens and its count are of the full tier."""
|
|
85
|
+
run = state["run"]
|
|
86
|
+
for record in [run.get("final", {}), *state["tickets"].values()]:
|
|
87
|
+
if isinstance(record.get("green_gates"), list):
|
|
88
|
+
record["green_gates"] = {**driver_state.tiers(), "full": record["green_gates"]}
|
|
89
|
+
if isinstance(run.get("gates"), int):
|
|
90
|
+
run["gates"] = {"fast": 0, "full": run["gates"]}
|
|
91
|
+
run["schema"] = driver_state.SCHEMA
|
|
92
|
+
|
|
93
|
+
|
|
83
94
|
def resume(state: driver_state.State) -> list[str]:
|
|
84
95
|
"""Give each ref of a run that an older driver started its new name, then mark the run: the errors, or []."""
|
|
85
|
-
if not state.path.exists() or state.read()["run"].get("schema", 1) >= driver_state.SCHEMA:
|
|
96
|
+
if not state.path.exists() or (schema := state.read()["run"].get("schema", 1)) >= driver_state.SCHEMA:
|
|
86
97
|
return []
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
if schema < 2: # the names of driver_names
|
|
99
|
+
run, names = state.read()["run"], Names(state.read()["run"]["pr_branch"])
|
|
100
|
+
moves = [_branch(entry, number, names, run["start"]) for number, entry in state.read()["tickets"].items()]
|
|
101
|
+
if errors := [error for error in [*moves, _recovery(run, names)] if error]:
|
|
102
|
+
return errors
|
|
103
|
+
state.update(_tiered)
|
|
92
104
|
return []
|
|
@@ -4,7 +4,8 @@ context: repo (slot path), branch, start (HEAD when the role started), log, full
|
|
|
4
4
|
correction (a test-writer corrects locked tests), restored (locked files the driver put back before it),
|
|
5
5
|
restore_red (the gate is red on the commit of that restore), findings (the titles a correction gets),
|
|
6
6
|
owners (ticket numbers, for the final fix batch), merged (locked files of merged tickets, not its own), pr (tip),
|
|
7
|
-
fix (the titles of the findings a fixer gets), red (the gate
|
|
7
|
+
fix (the titles of the findings a fixer gets), red (the red gate a fix must make green, as
|
|
8
|
+
`the <tier> gate is red on <sha7>`)."""
|
|
8
9
|
from __future__ import annotations
|
|
9
10
|
|
|
10
11
|
import json
|
|
@@ -111,7 +112,7 @@ def _moved_errors(context: dict) -> list[str]:
|
|
|
111
112
|
if _git(repo, "status", "--porcelain", "--untracked-files=no"):
|
|
112
113
|
errors.append("no commit, and the tree has uncommitted changes: commit the fix and list the commit")
|
|
113
114
|
if context.get("red"):
|
|
114
|
-
errors.append(f"no commit, and
|
|
115
|
+
errors.append(f"no commit, and {context['red']}: a fix of a red gate is a commit")
|
|
115
116
|
return errors
|
|
116
117
|
|
|
117
118
|
|
|
@@ -172,6 +173,12 @@ def _fixture_errors(report: dict) -> list[str]:
|
|
|
172
173
|
if path not in report.get("locked", [])]
|
|
173
174
|
|
|
174
175
|
|
|
176
|
+
def _space_errors(report: dict) -> list[str]:
|
|
177
|
+
"""No locked path holds whitespace: the fast gate gets the locked paths as one space-separated list."""
|
|
178
|
+
return [f"locked path {path!r} contains whitespace: the fast gate gets the locked paths separated by spaces, so "
|
|
179
|
+
"rename the file" for path in report.get("locked", []) if re.search(r"\s", path)]
|
|
180
|
+
|
|
181
|
+
|
|
175
182
|
def locked_files(listed: list[str]) -> list[str]:
|
|
176
183
|
"""The files of a `locked` list: a test node id `<file>::<test>` names its file. In order, each file once."""
|
|
177
184
|
return list(dict.fromkeys(entry.partition("::")[0] for entry in listed))
|
|
@@ -190,7 +197,7 @@ def validate(role: str, path: str, context: dict) -> list[str]:
|
|
|
190
197
|
report = {name: value for name, value in report.items() if name in rules["properties"]}
|
|
191
198
|
if "locked" in report:
|
|
192
199
|
report["locked"] = locked_files(report["locked"])
|
|
193
|
-
return (_commit_errors(report, context) + _owner_errors(report, context) + _must_fix_errors(report, context)
|
|
200
|
+
return (_space_errors(report) + _commit_errors(report, context) + _owner_errors(report, context) + _must_fix_errors(report, context)
|
|
194
201
|
+ _unchanged_errors(role, report, context) + _correction_errors(report, context)
|
|
195
202
|
+ _merged_errors(report, context) + _proof_errors(report, context) + _locked_errors(report, context)
|
|
196
203
|
+ _fixture_errors(report))
|
|
@@ -159,31 +159,35 @@ class Run:
|
|
|
159
159
|
raise Blocked(error or left)
|
|
160
160
|
return result
|
|
161
161
|
|
|
162
|
-
def gate(self, number: str, slot: str, commit: str) -> None:
|
|
163
|
-
"""Gate `commit` in the slot
|
|
164
|
-
if record := self.red_gate(number, slot, commit):
|
|
165
|
-
raise Blocked(f"the gate is red on {commit[:7]}, record {record}")
|
|
166
|
-
|
|
167
|
-
def red_gate(self, number: str, slot: str, commit: str) -> str:
|
|
168
|
-
"""`gate`, for a caller that acts on a red gate: returns its record, or "" when the gate is green.
|
|
169
|
-
|
|
162
|
+
def gate(self, number: str, slot: str, commit: str, tier: str) -> None:
|
|
163
|
+
"""Gate `commit` in the slot on `tier`, unless a green record of that tier names it already."""
|
|
164
|
+
if record := self.red_gate(number, slot, commit, tier):
|
|
165
|
+
raise Blocked(f"the {tier} gate is red on {commit[:7]}, record {record}")
|
|
166
|
+
|
|
167
|
+
def red_gate(self, number: str, slot: str, commit: str, tier: str, restored: list[str] | tuple = ()) -> str:
|
|
168
|
+
"""`gate`, for a caller that acts on a red gate: returns its record, or "" when the gate is green. The fast gate
|
|
169
|
+
checks the ticket's locked files and the `restored` ones, as the state holds them now."""
|
|
170
|
+
state = self.state.read()
|
|
171
|
+
if commit in _gate_record(state, number)["green_gates"][tier]:
|
|
170
172
|
return ""
|
|
171
173
|
at = driver_slots.head(slot)
|
|
172
174
|
if at != commit:
|
|
173
|
-
raise Blocked(f"the slot is at {at[:7]}, not at {commit[:7]}: the gate did not run")
|
|
174
|
-
|
|
175
|
+
raise Blocked(f"the slot is at {at[:7]}, not at {commit[:7]}: the {tier} gate did not run")
|
|
176
|
+
command = self.args.fast_gate if tier == driver_gate.FAST else self.args.gate
|
|
177
|
+
locked = list(dict.fromkeys([*state["tickets"][number]["locked"], *restored])) if tier == driver_gate.FAST else []
|
|
178
|
+
green, record, killed = driver_gate.run(command, tier, slot, OUT / number, self.pr, locked)
|
|
175
179
|
for sentence in killed:
|
|
176
180
|
ledger(f"{_owner(number)}: {sentence}.")
|
|
177
181
|
|
|
178
182
|
def count(state: dict) -> None:
|
|
179
|
-
state["run"]["gates"] += 1
|
|
183
|
+
state["run"]["gates"][tier] += 1
|
|
180
184
|
if green:
|
|
181
|
-
_gate_record(state, number)["green_gates"].append(commit)
|
|
185
|
+
_gate_record(state, number)["green_gates"][tier].append(commit)
|
|
182
186
|
|
|
183
187
|
self.state.update(count)
|
|
184
188
|
if not green:
|
|
185
189
|
return str(record)
|
|
186
|
-
ledger(f"{_owner(number)}: the gate is green on {commit[:7]}, record {record}.")
|
|
190
|
+
ledger(f"{_owner(number)}: the {tier} gate is green on {commit[:7]}, record {record}.")
|
|
187
191
|
return ""
|
|
188
192
|
|
|
189
193
|
def restore_locked_files(self, number: str, slot: str) -> list[str]:
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"""state.json, the resume contract: one lock, every write a read-modify-write, published by rename.
|
|
2
2
|
|
|
3
|
-
{"run": {revision, pr_branch, schema, gates, stops, agents: [{ticket, role, entry, seconds, cost}], questions, start,
|
|
3
|
+
{"run": {revision, pr_branch, schema, gates: {fast, full}, stops, agents: [{ticket, role, entry, seconds, cost}], questions, start,
|
|
4
4
|
landed: [[ticket, the PR tip its merge made]], final},
|
|
5
|
-
"tickets": {"NN": {phase, round, tip, test_writer_sha, locked, fixtures, green_gates, slot, note, held, rejected
|
|
5
|
+
"tickets": {"NN": {phase, round, tip, test_writer_sha, locked, fixtures, green_gates, slot, note, held, rejected,
|
|
6
|
+
landing}}}
|
|
7
|
+
|
|
8
|
+
green_gates is {"fast": [commit], "full": [commit]}, in a ticket and in run.final: a fast green never stands in for a
|
|
9
|
+
full one. landing is the commit whose full gate was red at the landing while the fixer of the round it started has
|
|
10
|
+
not reported, else None."""
|
|
6
11
|
from __future__ import annotations
|
|
7
12
|
|
|
8
13
|
import fcntl
|
|
@@ -16,20 +21,25 @@ from typing import IO
|
|
|
16
21
|
from driver_names import Names
|
|
17
22
|
from driver_slots import ancestor, git, on_branch, path
|
|
18
23
|
|
|
19
|
-
SCHEMA =
|
|
24
|
+
SCHEMA = 3 # the version of this contract; 2: the names of driver_names, 3: gate tiers. A run of an older driver has none.
|
|
20
25
|
PHASES = ("pending", "test-writer", "implement", "gate", "review", "fix", "merge", "merged", "blocked")
|
|
21
26
|
|
|
22
27
|
|
|
28
|
+
def tiers() -> dict:
|
|
29
|
+
"""The green gates of a ticket or of the end of run, per tier."""
|
|
30
|
+
return {"fast": [], "full": []}
|
|
31
|
+
|
|
32
|
+
|
|
23
33
|
def _ticket() -> dict:
|
|
24
|
-
return {"phase": "pending", "round": 0, "tip": None, "test_writer_sha": None, "locked": [], "green_gates":
|
|
34
|
+
return {"phase": "pending", "round": 0, "tip": None, "test_writer_sha": None, "locked": [], "green_gates": tiers(),
|
|
25
35
|
"slot": None, "note": "", "held": {}, "rejected": {},
|
|
26
|
-
"fixtures": []}
|
|
36
|
+
"fixtures": [], "landing": None}
|
|
27
37
|
|
|
28
38
|
|
|
29
39
|
def _final() -> dict:
|
|
30
40
|
"""The end-of-run record before it starts. Every key is here, so a reader uses [] and a wrong name fails."""
|
|
31
41
|
return {"skipped": "", "recovery": None, "tidied": None, "onto": None, "base": None, "commits": {},
|
|
32
|
-
"reviewed": None, "round": 0, "open": [], "must_fix": [], "batch": None, "green_gates":
|
|
42
|
+
"reviewed": None, "round": 0, "open": [], "must_fix": [], "batch": None, "green_gates": tiers(), "pushed": None, "body": None,
|
|
33
43
|
"pr": None}
|
|
34
44
|
|
|
35
45
|
|
|
@@ -45,7 +55,7 @@ class State:
|
|
|
45
55
|
"""Create the file for a new run, or add the tickets a resumed run does not know yet."""
|
|
46
56
|
def change(state: dict) -> None:
|
|
47
57
|
state.setdefault("run", {
|
|
48
|
-
"revision": uuid.uuid4().hex, "pr_branch": pr_branch, "schema": SCHEMA, "gates": 0, "stops": 0, "agents": [],
|
|
58
|
+
"revision": uuid.uuid4().hex, "pr_branch": pr_branch, "schema": SCHEMA, "gates": {"fast": 0, "full": 0}, "stops": 0, "agents": [],
|
|
49
59
|
"questions": [], "start": git(".", "rev-parse", f"refs/heads/{pr_branch}").stdout.strip(),
|
|
50
60
|
"landed": [], "final": _final()})
|
|
51
61
|
for key, value in _final().items(): # a run of an older driver lacks the newer keys
|
|
@@ -10,7 +10,7 @@ def _rows(run: dict, tickets: dict) -> list[tuple[str, object]]:
|
|
|
10
10
|
for agent in run["agents"]:
|
|
11
11
|
seconds[agent["role"]] += agent["seconds"]
|
|
12
12
|
rounds = ", ".join(f"{number}: {entry['round']}" for number, entry in tickets.items())
|
|
13
|
-
return [("gates run", run["gates"]),
|
|
13
|
+
return [("fast gates run", run["gates"]["fast"]), ("full gates run", run["gates"]["full"]),
|
|
14
14
|
*((f"agents, {role} on {entry}", number) for (role, entry), number in agents.items()),
|
|
15
15
|
*((f"wall time, {role}", f"{total:.1f} s") for role, total in seconds.items()),
|
|
16
16
|
("fix rounds per ticket", rounds),
|
|
@@ -14,7 +14,7 @@ Fix each finding in the list as one batch, in one commit or in several. List eve
|
|
|
14
14
|
Each commit belongs to one ticket: the ticket whose criterion or code the commit changes. A fix for two tickets is two commits.
|
|
15
15
|
Never edit a locked file: each one stays as it is at {start_sha}, and a locked file that differs is a critical finding of the next review.
|
|
16
16
|
Use targeted tests while you work.
|
|
17
|
-
Before you report DONE or DONE_WITH_CONCERNS, make the gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} in the environment, then fix, commit, and run it again until it passes. The driver runs
|
|
17
|
+
Before you report DONE or DONE_WITH_CONCERNS, make the fast gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} and IMPLEMENT_SPEC_LOCKED='{locked}' (the locked files above) in the environment, then fix, commit, and run it again until it passes. The driver runs its full gate on that commit, and a scoped review reads your commits.
|
|
18
18
|
Commit your work on the checked-out PR branch and change no commit that is on it now. Do not dispatch subagents.
|
|
19
19
|
In `commits`, give every commit you made with the number of its ticket: the driver names each commit `fix(NN): <your subject>` from it, and a commit with no ticket is a violation. In `green`, give the summary lines of the passing test output.
|
|
20
20
|
|
|
@@ -14,7 +14,7 @@ Must-fix findings carried from tickets that merged at the cap:
|
|
|
14
14
|
Rulings of the operator:
|
|
15
15
|
{rulings}
|
|
16
16
|
|
|
17
|
-
Review the range with the method of the review-diff skill in the file above, with the spec as its spec path. The gate of that method is done:
|
|
17
|
+
Review the range with the method of the review-diff skill in the file above, with the spec as its spec path. The gate of that method is done: the driver ran the full gate on {start_sha}, and its record is the gate evidence of your review. Do not run a gate yourself.
|
|
18
18
|
Decide for each carried observation whether it is still true at {start_sha}; report each one that is, with the severity it has now. Every must-fix finding stays open until the fix batch addresses it and the scoped review verifies it. A ruling does not settle a must-fix finding. In the scoped review, list each item you verified closed in `resolved_must_fix` exactly as shown in the must-fix list, including its file and line; report each unresolved one in `findings`.
|
|
19
19
|
Give each finding a severity (critical, important or minor), the file and line, a title, the evidence, and a kind: `code`, `test`, or `fixture`.
|
|
20
20
|
Do not commit. Leave the branch and the tree as you found them.
|
|
@@ -36,6 +36,6 @@ Write one JSON report at {report} that matches this schema:
|
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Run git as plain `git` in this worktree, and leave the git config as it is: all worktrees read one shared config, and one key written there, such as a `core.worktree`, breaks git in each of them. So never set GIT_DIR or GIT_WORK_TREE, and never write with `git config`.
|
|
39
|
-
To run a check off this worktree,
|
|
39
|
+
To run a targeted check off this worktree, make a copy with `git worktree add --detach <temp dir> {start_sha}`, run the check there, and remove the copy with `git worktree remove --force <temp dir>` before you report.
|
|
40
40
|
Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
|
|
41
41
|
Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
|
|
@@ -11,7 +11,7 @@ Fix each finding of severity critical or important in the findings file. Leave t
|
|
|
11
11
|
Never edit a locked file. The one exception is a finding `locked file changed`: make that file equal to its content at {test_writer_sha}.
|
|
12
12
|
If a locked test contradicts the spec or the ticket, so that no fix can make it green, stop and report BLOCKED with a concern that starts with `locked test contradicts spec:`, then the test and the evidence.
|
|
13
13
|
Use targeted tests while you work.
|
|
14
|
-
Before you report DONE or DONE_WITH_CONCERNS, make the gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} in the environment, then fix, commit, and run it again until it passes. The driver runs the gate again on that commit, and a re-review reads the lines you changed.
|
|
14
|
+
Before you report DONE or DONE_WITH_CONCERNS, make the fast gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} and IMPLEMENT_SPEC_LOCKED='{locked}' (the locked files above) in the environment, then fix, commit, and run it again until it passes. The driver runs the fast gate again on that commit, and a re-review reads the lines you changed.
|
|
15
15
|
A finding from the `gate` is a red gate: its file is the gate record. Read the output there and make the gate green.
|
|
16
16
|
Commit your work on the checked-out ticket branch. Do not dispatch subagents.
|
|
17
17
|
When a finding needs no change, for example because a correction before you already resolved it, change nothing for it. When no finding needs a change, make no commit: report DONE_WITH_CONCERNS, list no commit in `commits`, and give one concern per finding to fix that starts with its title and says why it needs no change. A re-review checks each reason. This is not for a red gate: a fix of a red gate is a commit. Report NEEDS_CONTEXT or BLOCKED only for a question that stops your work: the operator answers it.
|
|
@@ -10,7 +10,7 @@ Make the locked tests green and meet each criterion of the ticket. For internal
|
|
|
10
10
|
Never edit a locked file. If a locked test contradicts the spec or the ticket, stop and report BLOCKED with a concern that starts with `locked test contradicts spec:`, then the test and the evidence.
|
|
11
11
|
Commit your work on the checked-out ticket branch. Do not dispatch subagents. In `commits`, list only the commits you made: the start commit and each commit before it are not yours.
|
|
12
12
|
Use targeted tests while you work.
|
|
13
|
-
Before you report DONE or DONE_WITH_CONCERNS, make the gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} in the environment, then fix, commit, and run it again until it passes. The driver runs the gate again on that commit.
|
|
13
|
+
Before you report DONE or DONE_WITH_CONCERNS, make the fast gate green on your final commit: run `{gate}` with IMPLEMENT_SPEC_BASE={pr_branch} and IMPLEMENT_SPEC_LOCKED='{locked}' (the locked files above) in the environment, then fix, commit, and run it again until it passes. The driver runs the fast gate again on that commit.
|
|
14
14
|
When the start commit already meets the ticket, for example because a test-writer correction made the locked tests green, make no commit: report DONE_WITH_CONCERNS, list no commit in `commits`, and give a concern that says why the start needs no change. The driver gates and reviews the start commit. Report NEEDS_CONTEXT or BLOCKED only for a question that stops your work: the operator answers it.
|
|
15
15
|
In `green`, give the summary lines of the passing test output.
|
|
16
16
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{landing_sha} is not on {branch}: it is the merge commit of {branch} with {pr_branch} that the driver made to land the ticket. To reproduce the failure, merge {pr_branch} on {branch} with `git merge --no-commit --no-ff {pr_branch}`, run the failing tests of the record, then `git merge --abort` and make your fix on {branch}.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
|
|
2
|
+
The review passed, and then the driver ran the full gate on {landing_sha}, the commit that would land on {pr_branch}, and it is red: read the output in {landing_record}. The finding from the `gate` in the findings file is that record. Make it green with a commit on {branch}; the driver runs the fast gate on your commit, a re-review, and the full gate again when the ticket lands.
|
|
@@ -120,7 +120,7 @@ class World:
|
|
|
120
120
|
|
|
121
121
|
def run(self, plan=None, *extra, runner=True):
|
|
122
122
|
(self.runner.parent / "plan.json").write_text(json.dumps(plan or {}))
|
|
123
|
-
args = ["--tickets", ".agent/tickets", "--gate", "true", "--spec", "specs/csv/spec.md",
|
|
123
|
+
args = ["--tickets", ".agent/tickets", "--gate", "true", "--fast-gate", "true", "--spec", "specs/csv/spec.md",
|
|
124
124
|
"--models", str(self.models), *(["--runner", str(self.runner)] if runner else []), *extra]
|
|
125
125
|
return drive(self.env, self.repo, *args)
|
|
126
126
|
|
|
@@ -248,7 +248,7 @@ def test_claude_entry_launches_claude_p_and_bare_means_anthropic(env, entry):
|
|
|
248
248
|
@pytest.mark.parametrize("entry", ["mystery/model@medium", "anthropic/claude-opus-5@turbo", "openai/gpt-sol@turbo"])
|
|
249
249
|
def test_unknown_provider_or_effort_exits_3_naming_role_and_entry_before_any_agent(env, entry):
|
|
250
250
|
w = World(env, reviewer=[entry])
|
|
251
|
-
proc = drive(w.env, w.repo, "--tickets", ".agent/tickets", "--gate", "true", "--models", str(w.models), "--dry-run")
|
|
251
|
+
proc = drive(w.env, w.repo, "--tickets", ".agent/tickets", "--gate", "true", "--fast-gate", "true", "--models", str(w.models), "--dry-run")
|
|
252
252
|
assert proc.returncode == 3, proc.stdout + proc.stderr
|
|
253
253
|
assert any("reviewer" in l and entry in l for l in proc.stdout.splitlines()), proc.stdout
|
|
254
254
|
proc = w.run({"test-writer": [tw()]})
|
|
@@ -41,7 +41,7 @@ def test_with_no_origin_the_branch_is_tidied_gated_and_reviewed_with_no_rebase_a
|
|
|
41
41
|
assert ref(rig.repo, f"{rows[0]['sha']}~1") == rig.start, "no rebase: the ticket commits sit on the branch's start"
|
|
42
42
|
assert ref(rig.repo, "feat/csv^{tree}") == ref(rig.repo, "refs/implement-spec/feat%2Fcsv/recovery^{tree}")
|
|
43
43
|
records = sorted(p.name for p in (rig.repo / ".agent/implement/final").glob("gate-*.log"))
|
|
44
|
-
assert records == [f"gate-{tip[:7]}.log"], records
|
|
44
|
+
assert records == [f"gate-full-{tip[:7]}.log"], records
|
|
45
45
|
(gate,) = [g for g in rig.gates() if g["commit"] == tip]
|
|
46
46
|
(call,) = rig.final_calls("final-reviewer")
|
|
47
47
|
assert call["head"] == tip and gate["t0"] < call["t0"], "the final review reads the gated, tidied tip"
|
|
@@ -98,7 +98,7 @@ def models_file(tmp_path, **overrides):
|
|
|
98
98
|
|
|
99
99
|
def drive(env, repo, *args, script=RUN):
|
|
100
100
|
env_vars, _ = env
|
|
101
|
-
args = args or ("--tickets", ".agent/tickets", "--gate", "make check", "--dry-run")
|
|
101
|
+
args = args or ("--tickets", ".agent/tickets", "--gate", "make check", "--fast-gate", "make check", "--dry-run")
|
|
102
102
|
return subprocess.run(["sh", str(script), *args], cwd=repo, env=env_vars,
|
|
103
103
|
text=True, capture_output=True, timeout=300)
|
|
104
104
|
|
|
@@ -227,7 +227,7 @@ def test_models_file_naming_a_provider_without_its_cli_exits_3(env, tmp_path):
|
|
|
227
227
|
(tmp_path / "bin/codex").unlink()
|
|
228
228
|
repo = make_repo(tmp_path / "demo", three())
|
|
229
229
|
models = models_file(tmp_path, implementer=["openai/gpt-sol@medium"])
|
|
230
|
-
proc = drive(env, repo, "--tickets", ".agent/tickets", "--gate", "make check", "--models", str(models), "--dry-run")
|
|
230
|
+
proc = drive(env, repo, "--tickets", ".agent/tickets", "--gate", "make check", "--fast-gate", "make check", "--models", str(models), "--dry-run")
|
|
231
231
|
assert proc.returncode == 3, proc.stderr
|
|
232
232
|
assert any("implementer" in l and "codex" in l for l in proc.stdout.splitlines())
|
|
233
233
|
|
|
@@ -240,7 +240,7 @@ def test_one_implementer_model_is_rejected_before_any_agent(env, tmp_path):
|
|
|
240
240
|
models.write_text(json.dumps(entries))
|
|
241
241
|
before = snapshot(repo)
|
|
242
242
|
|
|
243
|
-
proc = drive(env, repo, "--tickets", ".agent/tickets", "--gate", "make check", "--models", str(models),
|
|
243
|
+
proc = drive(env, repo, "--tickets", ".agent/tickets", "--gate", "make check", "--fast-gate", "make check", "--models", str(models),
|
|
244
244
|
"--dry-run")
|
|
245
245
|
|
|
246
246
|
assert proc.returncode == 3, proc.stdout + proc.stderr
|
|
@@ -259,7 +259,7 @@ def test_valid_set_prints_frontier_width_and_dry_run_creates_nothing(env, tmp_pa
|
|
|
259
259
|
(tmp_path / "run link.sh").symlink_to(RUN)
|
|
260
260
|
script = tmp_path / "run link.sh"
|
|
261
261
|
before = snapshot(repo)
|
|
262
|
-
proc = drive(env, repo, "--tickets", ".agent/tickets", "--gate", "make check", "--dry-run", script=script)
|
|
262
|
+
proc = drive(env, repo, "--tickets", ".agent/tickets", "--gate", "make check", "--fast-gate", "make check", "--dry-run", script=script)
|
|
263
263
|
assert proc.returncode == 0, proc.stdout + proc.stderr
|
|
264
264
|
assert "max frontier width: 2" in proc.stdout
|
|
265
265
|
assert_untouched(proc, repo, before, tmp_path)
|