@jesdi/skills 0.0.90 → 0.0.92
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 +4 -1
- package/skills/implement-spec/WORKTREES.md +13 -0
- package/skills/implement-spec/driver.py +20 -5
- package/skills/implement-spec/driver_decisions.py +6 -4
- package/skills/implement-spec/driver_run.py +5 -6
- package/skills/implement-spec/driver_slots.py +44 -11
- package/skills/implement-spec/prompts/workspace.md +2 -0
- package/skills/implement-spec/recovery.md +63 -0
- package/skills/implement-spec/tests/test_agents.py +3 -3
- package/skills/implement-spec/tests/test_driver.py +170 -4
- package/skills/implement-spec/tests/test_slots.py +154 -1
- package/skills/implement-spec/tests/test_tidy.py +2 -1
- package/skills/implement-spec/tests/test_walk.py +6 -2
- package/skills-manifest.json +3 -3
package/package.json
CHANGED
|
@@ -81,6 +81,7 @@ Everything is under `.agent/`, which is never committed.
|
|
|
81
81
|
|---|---|
|
|
82
82
|
| `.agent/implement/state.json` | The resume contract: the run record and one record for each ticket (`driver_state.py`). |
|
|
83
83
|
| `<git common directory>/implement-spec/<key>.lock` | An empty file, not in the worktree. The driver that runs holds a kernel file lock on it (`driver_state.py` `lock`). Do not remove it during a run. |
|
|
84
|
+
| `<git common directory>/implement-spec-worktrees.lock` | Shared by driver processes for `worktree`, `checkout`, `switch` and `branch` commands, so a checkout never reads another driver's half-written registration. Held only during that Git command, never during preparation, agents or gates. Git commands outside the driver do not participate. |
|
|
84
85
|
| `.agent/implement/ledger.md` | One plain sentence for each event. Only the driver writes it, and it reads no fact from it. |
|
|
85
86
|
| `.agent/implement/summary.md` | The result in sentences, and the measurement table: fast gates and full gates, agents, wall time, fix rounds, human stops, cost. |
|
|
86
87
|
| `.agent/implement/decisions.json` | The open questions and their `revision`. Written only after a stop. |
|
|
@@ -229,7 +230,7 @@ A question is a bounded choice for the operator. `driver_decisions.py` `KINDS` h
|
|
|
229
230
|
| Kind | Question id | Asked when | Run exit | Options |
|
|
230
231
|
|---|---|---|---|---|
|
|
231
232
|
| `spec-ambiguous` | `<NN>-spec-ambiguous-<n>` | A second dispute on a locked test that the reviewer ruled on in the ticket, or a second correction needed for a locked test of the ticket (a `test-wrong` ruling or a review finding on a test corrected before); or a dispute or a review correction after the ticket's locked tests were settled 3 times. Another test of the same file, or another missing test that a review finding asks for, is no second correction. The subject names the test, the requirement and the two readings; the evidence is `spec-ambiguous-<n>.json`. | 2 | No option is recommended. `keep-test`: the role that disputed runs again against the test; after a review finding, the ticket resumes from the review and later findings with the same key are closed: on that test, a `fixture` finding on that file that names no test, or the same missing test. `correct-test`: one more correction, to the second reading, then the role that disputed runs again (the fixer of the same round after the review of its round); after a review finding, the review runs again. `edit-spec`: the ticket stays BLOCKED, with the ruling in the ledger. None of them changes the ticket's `disputes` or `corrected`. |
|
|
232
|
-
| `ticket-blocked` | `<NN>-ticket-blocked-<n>`, `final-ticket-blocked-<n>` | A ticket agent (test-writer, implementer, reviewer, fixer, conflict) or an agent of the end of run stopped with `BLOCKED` or `NEEDS_CONTEXT` or was rejected, and its rerun
|
|
233
|
+
| `ticket-blocked` | `<NN>-ticket-blocked-<n>`, `final-ticket-blocked-<n>` | A ticket agent (test-writer, implementer, reviewer, fixer, conflict) or an agent of the end of run stopped with `BLOCKED` or `NEEDS_CONTEXT` or was rejected, and its rerun did too (the same model for a timeout or moved branch, the next entry otherwise); or a finding is open after the scoped review of the final fix batch (one question per finding). The subject names the role and the reason, or the finding. | 2 | `retry` (recommended): the role runs again on its first entry from the tip the ticket left, with its one rerun; for a fixer, the round that stopped does not count: the driver gates and reviews the tip, and a fixer runs that round again on the review's findings. An arbitration or a correction runs for another role, so its work is not kept: after a dispute, the role that disputed runs again from the tip before them; after a review correction, the driver reviews that tip again. For the end of run, the stopped agent runs again from where the end of run is; for an open finding, one more fix batch and scoped review run. `edit`: the ticket, or the end of run, stays BLOCKED, with the ruling in the ledger, so the spec or the ticket can be edited. |
|
|
233
234
|
|
|
234
235
|
`final-finding` (fix or accept a finding open after the second round of the final review) became a `ticket-blocked` question of the end of run, id `final-ticket-blocked-<n>`: whether one more batch runs is the operator's call, and nothing ships with an open finding, so there is no `accept`.
|
|
235
236
|
|
|
@@ -237,6 +238,8 @@ A question is a bounded choice for the operator. `driver_decisions.py` `KINDS` h
|
|
|
237
238
|
|
|
238
239
|
Answer with `--answer <question id>=<option id>` on the next run, or through the page, which gives `.agent/implement-answers.json`. An answers file counts only when it is submitted and its `revision` equals the `revision` of `decisions.json`. The driver ignores any other file or answer and says so in the ledger. Each answer becomes one `Ruling:` sentence in the ledger.
|
|
239
240
|
|
|
241
|
+
For an older questionless BLOCKED record, see [operator recovery](recovery.md). Recovery requires an explicit verified checkpoint; starting this version never guesses one.
|
|
242
|
+
|
|
240
243
|
## The non-negotiable checks
|
|
241
244
|
|
|
242
245
|
| Check | Where it lives |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Worktree lifecycle
|
|
2
|
+
|
|
3
|
+
The driver owns a bounded pool of ticket checkouts. Slot 1 is the existing PR checkout; additional slots live at `.agent/worktrees/slot-N`, up to `--parallel`. The scheduler creates an additional slot only when a ready ticket first needs it. A serial dependency chain uses slot 1 alone, and a completed resume creates no slots.
|
|
4
|
+
|
|
5
|
+
Before scheduling, the driver validates existing slots. A slot must be a healthy checkout of this repository at the assigned path. Clean slots are detached for reuse; interrupted work stays in its recorded slot. A foreign checkout or a Git failure stops reuse rather than being treated as an empty status result.
|
|
6
|
+
|
|
7
|
+
New slots start at a captured PR tip. Slot 1 may already be on an unmerged ticket commit, so its current HEAD is not the preparation baseline. `--prepare` runs once per new slot; later tickets and fix rounds reuse that checkout and its installed dependencies.
|
|
8
|
+
|
|
9
|
+
A missing slot is recreated with one `git worktree add --force --detach` targeting its path and the captured tip. Git refuses a locked registration. The driver never runs `git worktree prune`: a session can see shared repository metadata while another active task's checkout is outside its mounts.
|
|
10
|
+
|
|
11
|
+
If preparation fails during scheduling, the driver starts no further tickets. Already running tickets finish and retain their progress. The failed slot is removed, a clean slot 1 returns to the PR branch, and the driver exits 3 with the preparation error. Fix the preparation command and rerun the same invocation to resume; the ticket whose slot failed remains pending.
|
|
12
|
+
|
|
13
|
+
Role agents reuse their assigned checkout. Read-only reviewers first consult existing gate evidence and create a temporary checkout only for a specific isolated check that the evidence cannot answer.
|
|
@@ -323,15 +323,27 @@ def _take_slot(number: str, kept: dict, free: list[int]) -> int:
|
|
|
323
323
|
return slot
|
|
324
324
|
|
|
325
325
|
|
|
326
|
+
def _prepare_slot(number: int, prepared: set[int], run: Run) -> None:
|
|
327
|
+
"""Create a worker checkout only when first assigned; keep its dependencies for later tickets."""
|
|
328
|
+
if number in prepared:
|
|
329
|
+
return
|
|
330
|
+
if error := driver_slots.create(number, run.args.prepare, number in run.kept.values(), start=run.tip()):
|
|
331
|
+
raise driver_slots.PreparationError(error)
|
|
332
|
+
prepared.add(number)
|
|
333
|
+
|
|
334
|
+
|
|
326
335
|
def _walk(tickets: list[Ticket], slots: int, run: Run, pool: ThreadPoolExecutor) -> None:
|
|
327
336
|
"""Start each ready ticket in the lowest free slot, and look again each time a ticket ends."""
|
|
328
337
|
kept, told = dict(run.kept), set() # a kept slot waits for its ticket
|
|
329
338
|
free = [slot for slot in range(1, slots + 1) if slot not in kept.values()]
|
|
330
339
|
running: dict = {} # future -> (ticket number, slot number)
|
|
340
|
+
prepared = {1} | {number for number in range(2, slots + 1)
|
|
341
|
+
if Path(driver_slots.path(number), ".git").exists()}
|
|
331
342
|
|
|
332
343
|
def start_ready() -> None:
|
|
333
344
|
while (ticket := _next_ticket(tickets, running, told, run, kept)) and (ticket.number in kept or free):
|
|
334
345
|
slot = _take_slot(ticket.number, kept, free)
|
|
346
|
+
_prepare_slot(slot, prepared, run)
|
|
335
347
|
running[pool.submit(_run_ticket, ticket, slot, run)] = (ticket.number, slot)
|
|
336
348
|
|
|
337
349
|
while True:
|
|
@@ -401,11 +413,11 @@ def _resume_error(number: str, state: driver_state.State) -> str:
|
|
|
401
413
|
|
|
402
414
|
|
|
403
415
|
def _resume(tickets: list[Ticket], state: driver_state.State, pr: str, slots: int, args, kept: dict) -> list[str]:
|
|
404
|
-
"""Start or resume state.json on the PR branch `pr` and
|
|
416
|
+
"""Start or resume state.json on the PR branch `pr` and check existing slots: the errors that stop the run."""
|
|
405
417
|
state.start(pr, [ticket.number for ticket in tickets])
|
|
406
418
|
driver_final.finish_interrupted_move(state, pr)
|
|
407
419
|
errors = [error for error in (_resume_error(ticket.number, state) for ticket in tickets) if error]
|
|
408
|
-
return errors or driver_slots.setup(slots, args.prepare, set(kept.values()))
|
|
420
|
+
return errors or driver_slots.setup(slots, args.prepare, set(kept.values()), existing_only=True)
|
|
409
421
|
|
|
410
422
|
|
|
411
423
|
def _publish_questions(run: dict) -> str:
|
|
@@ -509,15 +521,18 @@ def _run(tickets: list[Ticket], models: dict[str, list[str]], skipped: list[str]
|
|
|
509
521
|
slots = 1 if args.only else min(args.parallel, len(tickets))
|
|
510
522
|
errors = _resume(tickets, state, pr, slots, args, kept)
|
|
511
523
|
errors = errors or _apply_answers(state, args)
|
|
512
|
-
for error in errors:
|
|
513
|
-
print(error)
|
|
514
524
|
if errors:
|
|
525
|
+
print("\n".join(errors))
|
|
515
526
|
return 3
|
|
516
527
|
run = Run(args, models, state, pr, kept)
|
|
517
528
|
_record_skipped(skipped)
|
|
518
529
|
if args.unattended and args.stage_json:
|
|
519
530
|
Path(args.stage_json).unlink(missing_ok=True) # the file tells how this run ends, never an earlier one
|
|
520
|
-
|
|
531
|
+
try:
|
|
532
|
+
end_blocked, lines = _work(tickets, slots, run)
|
|
533
|
+
except driver_slots.PreparationError as error:
|
|
534
|
+
print(f"implement-spec: {error}; fix slot preparation and run the same command to resume")
|
|
535
|
+
return 3
|
|
521
536
|
final = state.read()
|
|
522
537
|
summary = driver_summary.render(final)
|
|
523
538
|
(OUT / "summary.md").write_text(summary)
|
|
@@ -68,13 +68,15 @@ KINDS = {
|
|
|
68
68
|
# The end of run asks it too, with the ticket `final`: for an agent, or for a finding open after the scoped review.
|
|
69
69
|
"ticket-blocked": Kind(
|
|
70
70
|
"{owner}: an agent stopped or was rejected, and its rerun too, or a final-review finding is open: {subject}",
|
|
71
|
-
"An agent ran two times, the
|
|
72
|
-
"both times; or the scoped review after the fix batch of the final review left
|
|
71
|
+
"An agent ran two times, using the same model for a timeout or moved branch and the next entry otherwise, "
|
|
72
|
+
"and stopped or was rejected both times; or the scoped review after the fix batch of the final review left "
|
|
73
|
+
"a finding open. {owner} is "
|
|
73
74
|
"BLOCKED, each ticket that it blocks waits, and nothing is pushed.",
|
|
74
75
|
"retry",
|
|
75
76
|
{"retry": Option(
|
|
76
|
-
"The role runs again on its first entry from the tip the ticket left, with
|
|
77
|
-
"entry; for an open final-review finding,
|
|
77
|
+
"The role runs again on its first entry from the tip the ticket left, with one rerun (the same model "
|
|
78
|
+
"for a timeout or moved branch, the next entry otherwise); for an open final-review finding, "
|
|
79
|
+
"one more fix batch and scoped review run.",
|
|
78
80
|
"Ruling: {ticket} runs again (retry): {subject}.", True),
|
|
79
81
|
"edit": Option(
|
|
80
82
|
"Keep it BLOCKED, so the spec or the ticket can be edited before more work on it.",
|
|
@@ -319,11 +319,9 @@ def _ask_blocked(run: Run, call: Call, report: Path, error: str) -> None:
|
|
|
319
319
|
run.ask(call.number, "ticket-blocked", [f"the {call.role}: {error}"], str(report), resume)
|
|
320
320
|
|
|
321
321
|
|
|
322
|
-
def _give_up(run: Run, call: Call, report: Path, error: str
|
|
323
|
-
"""
|
|
324
|
-
|
|
325
|
-
if not same:
|
|
326
|
-
_ask_blocked(run, call, report, error)
|
|
322
|
+
def _give_up(run: Run, call: Call, report: Path, error: str) -> NoReturn:
|
|
323
|
+
"""Every exhausted rerun asks before another attempt, including timeouts and moved branches."""
|
|
324
|
+
_ask_blocked(run, call, report, error)
|
|
327
325
|
raise Blocked(error)
|
|
328
326
|
|
|
329
327
|
|
|
@@ -336,6 +334,7 @@ def _files(folder: Path, role: str, fix_round: int, name: str) -> tuple[Path, Pa
|
|
|
336
334
|
def _first_prompt(template: str, values: dict[str, str], notes: tuple | list, report: str) -> str:
|
|
337
335
|
"""The template of the role, then the lines of each `notes` template and the ending of the prompt again."""
|
|
338
336
|
text = driver_agents.render(template, {**values, "report": report})
|
|
337
|
+
text = text.replace("\n\n", "\n\n" + driver_agents.render("workspace", {}), 1)
|
|
339
338
|
if notes:
|
|
340
339
|
text += "".join(driver_agents.render(note, values) for note in notes) + driver_agents.tail(text, report)
|
|
341
340
|
return text
|
|
@@ -402,4 +401,4 @@ def _attempts(run: Run, call: Call) -> dict:
|
|
|
402
401
|
if code is None:
|
|
403
402
|
minutes *= 2
|
|
404
403
|
entry = entry if same else rerun_on
|
|
405
|
-
_give_up(run, call, report, error
|
|
404
|
+
_give_up(run, call, report, error)
|
|
@@ -4,13 +4,29 @@ Every path is relative to the PR worktree, which is the driver's working directo
|
|
|
4
4
|
"""
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
import fcntl
|
|
7
8
|
import subprocess
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
|
|
10
11
|
|
|
12
|
+
class PreparationError(RuntimeError):
|
|
13
|
+
"""A requested slot could not be prepared; already running tickets may finish."""
|
|
14
|
+
|
|
15
|
+
|
|
11
16
|
def git(slot: str, *args: str) -> subprocess.CompletedProcess[str]:
|
|
12
17
|
# core.quotePath off: git prints a path with a non-ASCII name as it is, so it equals the path that a report names.
|
|
13
|
-
|
|
18
|
+
command = ["git", "-C", slot, "-c", "core.quotePath=false", *args]
|
|
19
|
+
if not args or args[0] not in ("checkout", "switch", "branch", "worktree"):
|
|
20
|
+
return subprocess.run(command, capture_output=True, text=True)
|
|
21
|
+
# These commands mutate or scan the shared registry. Git exposes a temporarily empty
|
|
22
|
+
# commondir while adding a checkout; another checkout can otherwise fail reading it.
|
|
23
|
+
common = subprocess.run(["git", "-C", slot, "rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
24
|
+
capture_output=True, text=True)
|
|
25
|
+
if common.returncode:
|
|
26
|
+
return common
|
|
27
|
+
with (Path(common.stdout.strip()) / "implement-spec-worktrees.lock").open("a") as held:
|
|
28
|
+
fcntl.flock(held, fcntl.LOCK_EX)
|
|
29
|
+
return subprocess.run(command, capture_output=True, text=True)
|
|
14
30
|
|
|
15
31
|
|
|
16
32
|
def names(listing: str) -> list[str]:
|
|
@@ -39,15 +55,29 @@ def path(number: int) -> str:
|
|
|
39
55
|
return "." if number == 1 else f".agent/worktrees/slot-{number}"
|
|
40
56
|
|
|
41
57
|
|
|
42
|
-
def
|
|
58
|
+
def _owned_checkout(slot: str) -> bool:
|
|
59
|
+
"""An existing slot must be this repository's checkout at exactly the assigned path."""
|
|
60
|
+
common = git(slot, "rev-parse", "--path-format=absolute", "--git-common-dir")
|
|
61
|
+
root = git(slot, "rev-parse", "--show-toplevel")
|
|
62
|
+
expected = git(".", "rev-parse", "--path-format=absolute", "--git-common-dir")
|
|
63
|
+
return (common.returncode == root.returncode == expected.returncode == 0
|
|
64
|
+
and common.stdout == expected.stdout
|
|
65
|
+
and Path(root.stdout.strip()).resolve() == Path(slot).absolute()
|
|
66
|
+
and not Path(slot).is_symlink())
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def create(number: int, prepare: str | None, keep: bool = False, *, start: str = "HEAD") -> str:
|
|
43
70
|
"""Make and prepare slot 2..N once, or reuse it off any branch (`keep`: as it is). Returns "" or the error."""
|
|
44
71
|
slot = path(number)
|
|
45
|
-
git(".", "worktree", "prune") # a slot directory that was removed by hand
|
|
46
72
|
if Path(slot, ".git").exists():
|
|
73
|
+
if not _owned_checkout(slot):
|
|
74
|
+
return f"slot {number}: {slot} is not a healthy checkout of this repository; inspect it before retrying"
|
|
47
75
|
if not (keep or release(slot)):
|
|
48
|
-
return f"slot {number}: {slot}
|
|
76
|
+
return f"slot {number}: {slot} could not be released: inspect its Git state and uncommitted changes"
|
|
49
77
|
return ""
|
|
50
|
-
|
|
78
|
+
# One force recovers this missing slot registration only; a locked registration still fails.
|
|
79
|
+
# Never prune: another session may mount the shared metadata without its sibling checkouts.
|
|
80
|
+
added = git(".", "worktree", "add", "-q", "--force", "--detach", slot, start)
|
|
51
81
|
if added.returncode:
|
|
52
82
|
return f"slot {number}: cannot create {slot}: {added.stderr.strip()}"
|
|
53
83
|
if not prepare:
|
|
@@ -61,17 +91,20 @@ def create(number: int, prepare: str | None, keep: bool = False) -> str:
|
|
|
61
91
|
return ""
|
|
62
92
|
|
|
63
93
|
|
|
64
|
-
def setup(count: int, prepare: str | None, keep: set[int] = frozenset()
|
|
65
|
-
|
|
94
|
+
def setup(count: int, prepare: str | None, keep: set[int] = frozenset(),
|
|
95
|
+
*, existing_only: bool = False) -> list[str]:
|
|
96
|
+
"""Check slots before agents; existing_only defers absent slots until their first assignment."""
|
|
66
97
|
for number in range(2, count + 1):
|
|
98
|
+
if existing_only and not Path(path(number), ".git").exists():
|
|
99
|
+
continue
|
|
67
100
|
if error := create(number, prepare, number in keep):
|
|
68
101
|
return [error]
|
|
69
102
|
return []
|
|
70
103
|
|
|
71
104
|
|
|
72
105
|
def release(slot: str) -> bool:
|
|
73
|
-
"""Take a clean slot off its branch. False: the slot has uncommitted work, which stays where it is."""
|
|
74
|
-
|
|
106
|
+
"""Take a clean slot off its branch. False: Git failed or the slot has uncommitted work, which stays where it is."""
|
|
107
|
+
status = git(slot, "status", "--porcelain")
|
|
108
|
+
if status.returncode or status.stdout.strip():
|
|
75
109
|
return False
|
|
76
|
-
git(slot, "checkout", "-q", "--detach")
|
|
77
|
-
return True
|
|
110
|
+
return git(slot, "checkout", "-q", "--detach").returncode == 0
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
The driver has already assigned your working checkout. Reuse it for this role and every fix attempt; it satisfies the requirement to work in a worktree. Do not create another worktree for a ticket or fix. Only a read-only review whose instructions explicitly permit an isolated check may create a temporary checkout; read the existing gate evidence first and create a copy only when that evidence cannot answer a specific finding. Never run `git worktree prune`: the shared repository can contain live checkouts that this session cannot see.
|
|
2
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Recover an older questionless implementer stop
|
|
2
|
+
|
|
3
|
+
Use this only when an older run stopped after two implementer attempts and left ticket `phase: blocked` with no question. Repair the reported environment problem first. New runs ask `ticket-blocked` after exhausted retries, including timeouts and moved branches.
|
|
4
|
+
|
|
5
|
+
Stop the driver and prevent the dispatcher from resuming it during recovery. In the PR worktree, preserve any dirty files with a binary patch and exact file copies outside tracked paths. Do not reset the checkout or overwrite locked tests. Keep the branch and driver records; recovery adds a question, not a passing gate.
|
|
6
|
+
|
|
7
|
+
Read the ticket's ledger and reports. Confirm that the implementer stopped before any accepted implementation and that its recorded tip is still the test-writer commit. The command below accepts only that narrow checkpoint: schema 5, round zero, no gate results, no prior question for this ticket, two recorded implementer attempts, and an intact test-writer commit on the ticket branch. Other phases, uncertain evidence, or prior operator decisions require investigation; do not guess a phase or delete state to start over.
|
|
8
|
+
|
|
9
|
+
Run the following from the PR worktree, replacing the skill path, ticket number and full verified test-writer SHA. It takes the driver's locks, backs up state, records a question through the existing helper and leaves the ticket BLOCKED. No checkout, branch or gate is changed.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
python3 - /path/to/implement-spec 01 VERIFIED_TEST_WRITER_SHA <<'PY'
|
|
13
|
+
import json
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
sys.path.insert(0, sys.argv[1])
|
|
18
|
+
import driver
|
|
19
|
+
import driver_decisions
|
|
20
|
+
import driver_names
|
|
21
|
+
import driver_slots
|
|
22
|
+
import driver_state
|
|
23
|
+
|
|
24
|
+
number, tip = sys.argv[2:]
|
|
25
|
+
path = Path('.agent/implement/state.json')
|
|
26
|
+
state = driver_state.State(path)
|
|
27
|
+
pr = state.read()['run']['pr_branch']
|
|
28
|
+
common = Path(driver_slots.git('.', 'rev-parse', '--git-common-dir').stdout.strip()).resolve()
|
|
29
|
+
held, error = driver._hold(common, pr)
|
|
30
|
+
if not held:
|
|
31
|
+
raise SystemExit(error)
|
|
32
|
+
with held:
|
|
33
|
+
before = path.read_bytes()
|
|
34
|
+
data = json.loads(before)
|
|
35
|
+
entry = data['tickets'][number]
|
|
36
|
+
attempts = [a['role'] for a in data['run']['agents'] if a['ticket'] == number]
|
|
37
|
+
branch = driver_names.Names(pr).ticket(number)
|
|
38
|
+
valid = (data['run']['schema'] == 5 and entry['phase'] == 'blocked'
|
|
39
|
+
and entry['round'] == 0 and entry['tip'] == entry['test_writer_sha'] == tip
|
|
40
|
+
and entry['locked'] and not any(entry['green_gates'].values())
|
|
41
|
+
and not any(q['ticket'] == number for q in data['run']['questions'])
|
|
42
|
+
and attempts[-2:] == ['implementer', 'implementer']
|
|
43
|
+
and driver_slots.git('.', 'rev-parse', '--verify', branch).stdout.strip() == tip)
|
|
44
|
+
if not valid:
|
|
45
|
+
raise SystemExit('Checkpoint not verified; leave state unchanged and investigate.')
|
|
46
|
+
backup = path.with_name(f'state-before-recovery-{number}.json')
|
|
47
|
+
with backup.open('xb') as out:
|
|
48
|
+
out.write(before)
|
|
49
|
+
def recover(current):
|
|
50
|
+
driver_decisions.stop(current['run'], 'ticket-blocked', number,
|
|
51
|
+
['Operator verified the repaired environment and pre-implementation checkpoint.'],
|
|
52
|
+
['.agent/implement/ledger.md'], driver_decisions.Resume('implement', tip))
|
|
53
|
+
updated = state.update(recover)
|
|
54
|
+
question = updated['run']['questions'][-1]['id']
|
|
55
|
+
with path.with_name('ledger.md').open('a') as out:
|
|
56
|
+
out.write(f'Operator recovery: backup {backup}; added {question} at verified tip {tip}.\n')
|
|
57
|
+
print(f'Rerun the original driver command with --answer {question}=retry')
|
|
58
|
+
PY
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The normal driver invocation publishes the question and consumes that answer. Keep all original gate, spec and push flags. It reruns the implementer, then the normal gates and reviews; locked-test ownership stays unchanged. An unanswered invocation stays parked and creates no second question.
|
|
62
|
+
|
|
63
|
+
If the driver refuses dirty files, keep their verified backup and determine which slot owns them before restoring anything. Inspect preserved implementation as input to the resumed implementer; do not apply test changes over its locked baseline. Keep the recovery backup until the ticket is safely completed.
|
|
@@ -270,7 +270,7 @@ def test_implementer_prompt_carries_pointers_and_only_template_sentences(env):
|
|
|
270
270
|
for pointer in ("specs/csv/spec.md", ".agent/tickets/01-export-rows.md", "`export_csv()`", sha,
|
|
271
271
|
"tests/test_export.py", report):
|
|
272
272
|
assert pointer in prompt, pointer
|
|
273
|
-
template = (SKILL / "prompts/implementer.md").read_text()
|
|
273
|
+
template = (SKILL / "prompts/implementer.md").read_text() + (SKILL / "prompts/workspace.md").read_text()
|
|
274
274
|
for prefix in (str(w.repo.resolve()) + "/", str(w.repo) + "/"):
|
|
275
275
|
prompt = prompt.replace(prefix, "")
|
|
276
276
|
for value in (report, "specs/csv/spec.md", ".agent/tickets/01-export-rows.md", "`export_csv()`", sha,
|
|
@@ -422,10 +422,10 @@ def test_timeout_keeps_the_tree_and_reruns_once_with_double_the_limit(env):
|
|
|
422
422
|
assert git(w.repo, "show", "feat/csv:wip.txt") == "half done\n"
|
|
423
423
|
|
|
424
424
|
|
|
425
|
-
def
|
|
425
|
+
def test_second_timeout_asks_before_retrying_the_ticket(env):
|
|
426
426
|
w = World(env, refactor=True)
|
|
427
427
|
hang = {"files": {"wip.txt": "half done\n"}, "sleep": 60}
|
|
428
|
-
|
|
428
|
+
asks(w.run({"implementer": [hang, hang, impl()]}, "--timeout", "implementer=0.04"))
|
|
429
429
|
assert len(w.calls("implementer")) == 2
|
|
430
430
|
assert any("BLOCKED" in l and "timed out" in l for l in w.ledger().splitlines()), w.ledger()
|
|
431
431
|
assert (w.repo / "wip.txt").exists()
|
|
@@ -240,6 +240,7 @@ def test_a_rerun_prompt_holds_only_template_lines_and_keeps_its_ending(repo, tmp
|
|
|
240
240
|
ending = first[first.index("\nWrite one JSON report"):]
|
|
241
241
|
line = (driver_report.PROMPTS / "timeout.md").read_text().replace("{minutes}", "0.005")
|
|
242
242
|
assert "timed out" in line and "in the tree" in line
|
|
243
|
+
first = first.replace("\n\n", "\n\n" + driver_agents.render("workspace", {}), 1)
|
|
243
244
|
assert prompt == first + line + ending
|
|
244
245
|
|
|
245
246
|
|
|
@@ -303,10 +304,10 @@ def test_concurrent_first_runs_of_the_launcher_all_succeed(tmp_path):
|
|
|
303
304
|
assert [p.name for p in (cache / "venv").iterdir()] == ["3.13.7-jsonschema-4.26.0"]
|
|
304
305
|
|
|
305
306
|
|
|
306
|
-
def
|
|
307
|
+
def test_a_timeout_doubles_the_limit_and_a_second_one_asks_to_retry(repo, tmp_path, capsys):
|
|
307
308
|
repo()
|
|
308
309
|
code, ledger = agents(tmp_path, capsys, "exec sleep 30\n", "--timeout", "implementer=0.005")
|
|
309
|
-
assert code ==
|
|
310
|
+
assert code == 2
|
|
310
311
|
assert ledger[0].endswith(": timed out after 0.005 minutes.") and ledger[1].endswith(": timed out after 0.01 minutes.")
|
|
311
312
|
assert ledger[2].startswith("Ticket 01: BLOCKED at the implementer: timed out")
|
|
312
313
|
|
|
@@ -329,6 +330,70 @@ def test_a_moved_head_resets_the_slot_and_reruns(repo, tmp_path, capsys, move, p
|
|
|
329
330
|
assert subprocess.run(["git", "rev-parse", "feat/x~1"], capture_output=True, text=True).stdout.strip() == tip
|
|
330
331
|
|
|
331
332
|
|
|
333
|
+
@pytest.mark.parametrize("failure", [
|
|
334
|
+
"git checkout -q --detach; git branch -q -D ticket/feat%2Fx/01; exit 0\n",
|
|
335
|
+
"echo unfinished > code.txt; exec sleep 30\n",
|
|
336
|
+
])
|
|
337
|
+
def test_exhausted_same_model_retry_can_resume_without_losing_locked_tests(repo, tmp_path, capsys, failure):
|
|
338
|
+
repo()
|
|
339
|
+
writer = f"if [ $role = test-writer ]; then\n{COMMIT}{WRITER}{REPORT}exit 0; fi\n"
|
|
340
|
+
code, _ = agents(tmp_path, capsys, writer + failure,
|
|
341
|
+
"--timeout", "implementer=0.005", seam="`f()`")
|
|
342
|
+
assert code == 2
|
|
343
|
+
state = state_of(tmp_path)
|
|
344
|
+
entry = state["tickets"]["01"]
|
|
345
|
+
locked = entry["test_writer_sha"]
|
|
346
|
+
question, = state["run"]["questions"]
|
|
347
|
+
assert question["id"] == "01-ticket-blocked-1"
|
|
348
|
+
assert question["resume"] == {"phase": "implement", "tip": locked}
|
|
349
|
+
assert entry["phase"] == "blocked" and entry["locked"] == ["work.txt"]
|
|
350
|
+
assert state["run"]["gates"] == {"fast": 0, "full": 0}
|
|
351
|
+
if "unfinished" in failure:
|
|
352
|
+
assert (tmp_path / "code.txt").read_text() == "unfinished\n"
|
|
353
|
+
code, _ = agents(tmp_path, capsys, failure, seam="`f()`")
|
|
354
|
+
assert code == 2 and state_of(tmp_path)["run"]["questions"] == [question]
|
|
355
|
+
assert state_of(tmp_path)["run"]["agents"] == state["run"]["agents"]
|
|
356
|
+
good = COMMIT.replace("work.txt", "code.txt") + IMPLEMENTER + REPORT
|
|
357
|
+
code, _ = agents(tmp_path, capsys, good, "--answer", question["id"] + "=retry", seam="`f()`")
|
|
358
|
+
assert code == 0
|
|
359
|
+
final = state_of(tmp_path)
|
|
360
|
+
assert final["tickets"]["01"]["phase"] == "merged"
|
|
361
|
+
assert final["tickets"]["01"]["test_writer_sha"] == locked
|
|
362
|
+
assert final["run"]["gates"]["fast"] >= 1 and final["run"]["gates"]["full"] >= 1
|
|
363
|
+
assert (tmp_path / "work.txt").read_text() == "test-writer\n"
|
|
364
|
+
assert sum(agent["role"] == "test-writer" for agent in final["run"]["agents"]) == 1
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def test_documented_recovery_validates_an_older_checkpoint_before_adding_a_question(repo, tmp_path, capsys):
|
|
368
|
+
repo()
|
|
369
|
+
writer = f"if [ $role = test-writer ]; then\n{COMMIT}{WRITER}{REPORT}exit 0; fi\n"
|
|
370
|
+
failure = "git checkout -q --detach; git branch -q -D ticket/feat%2Fx/01; exit 0\n"
|
|
371
|
+
assert agents(tmp_path, capsys, writer + failure, seam="`f()`")[0] == 2
|
|
372
|
+
path = tmp_path / ".agent/implement/state.json"
|
|
373
|
+
data = state_of(tmp_path)
|
|
374
|
+
data["run"]["questions"] = [] # persisted by the older same-model failure path
|
|
375
|
+
path.write_text(json.dumps(data))
|
|
376
|
+
before = path.read_bytes()
|
|
377
|
+
tip = data["tickets"]["01"]["test_writer_sha"]
|
|
378
|
+
skill = Path(driver.__file__).parent
|
|
379
|
+
script = (skill / "recovery.md").read_text().split("<<'PY'\n", 1)[1].split("\nPY\n", 1)[0]
|
|
380
|
+
command = [sys.executable, "-", str(skill), "01"]
|
|
381
|
+
refused = subprocess.run([*command, "0" * 40], input=script, text=True, capture_output=True)
|
|
382
|
+
assert refused.returncode != 0 and "Checkpoint not verified" in refused.stderr
|
|
383
|
+
assert path.read_bytes() == before and not path.with_name("state-before-recovery-01.json").exists()
|
|
384
|
+
recovered = subprocess.run([*command, tip], input=script, text=True, capture_output=True)
|
|
385
|
+
assert recovered.returncode == 0, recovered.stderr
|
|
386
|
+
assert "--answer 01-ticket-blocked-1=retry" in recovered.stdout
|
|
387
|
+
assert path.with_name("state-before-recovery-01.json").read_bytes() == before
|
|
388
|
+
after = path.read_bytes()
|
|
389
|
+
repeated = subprocess.run([*command, tip], input=script, text=True, capture_output=True)
|
|
390
|
+
assert repeated.returncode != 0 and path.read_bytes() == after
|
|
391
|
+
good = COMMIT.replace("work.txt", "code.txt") + IMPLEMENTER + REPORT
|
|
392
|
+
assert agents(tmp_path, capsys, good, "--answer", "01-ticket-blocked-1=retry", seam="`f()`")[0] == 0
|
|
393
|
+
assert state_of(tmp_path)["tickets"]["01"]["test_writer_sha"] == tip
|
|
394
|
+
assert (tmp_path / "work.txt").read_text() == "test-writer\n"
|
|
395
|
+
|
|
396
|
+
|
|
332
397
|
def test_an_existing_ticket_branch_stops_the_run(repo, tmp_path, capsys):
|
|
333
398
|
repo()
|
|
334
399
|
subprocess.run(["git", "branch", "ticket/feat%2Fx/01"], check=True)
|
|
@@ -509,10 +574,15 @@ def test_a_tree_that_is_not_clean_is_a_red_gate_and_the_slot_keeps_the_work(repo
|
|
|
509
574
|
|
|
510
575
|
def test_a_failing_prepare_stops_the_run_and_removes_the_slot(repo, tmp_path, capsys):
|
|
511
576
|
two(repo)
|
|
512
|
-
code,
|
|
513
|
-
assert
|
|
577
|
+
code, _, out = walk(tmp_path, capsys, WORK + REPORT, "--prepare", "echo no-deps >&2; false")
|
|
578
|
+
assert code == 3
|
|
514
579
|
assert "slot 2: --prepare `echo no-deps >&2; false` exited 1 in .agent/worktrees/slot-2: no-deps" in out
|
|
515
580
|
assert not (tmp_path / ".agent/worktrees/slot-2").exists() and branches() == ["feat/x"]
|
|
581
|
+
assert state_of(tmp_path)["tickets"]["01"]["phase"] == "merged" # already running work finishes
|
|
582
|
+
assert state_of(tmp_path)["tickets"]["02"]["phase"] == "pending"
|
|
583
|
+
assert all(line.startswith("01 ") for line in Path(f"{tmp_path}-runner.calls").read_text().splitlines())
|
|
584
|
+
assert out_of("git", "symbolic-ref", "--short", "HEAD") == "feat/x"
|
|
585
|
+
assert walk(tmp_path, capsys, WORK + REPORT)[0] == 0 # same state resumes safely
|
|
516
586
|
|
|
517
587
|
|
|
518
588
|
def test_a_touches_overlap_holds_the_second_ticket_and_the_ledger_says_why(repo, tmp_path, capsys):
|
|
@@ -1004,3 +1074,99 @@ def test_last_words_takes_the_result_of_a_stream_json_line(tmp_path):
|
|
|
1004
1074
|
log.write_text("ERROR: plain\n")
|
|
1005
1075
|
assert driver_agents.last_words(log) == "ERROR: plain"
|
|
1006
1076
|
assert driver_agents.last_words(tmp_path / "none.log") == "no output"
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
def test_a_serial_chain_uses_only_the_existing_checkout(repo, tmp_path, capsys):
|
|
1080
|
+
two(repo, second="01")
|
|
1081
|
+
log = tmp_path.parent / f"{tmp_path.name}-prepare.log"
|
|
1082
|
+
code, _, out = walk(tmp_path, capsys, WORK + REPORT, "--prepare", f"pwd >> {log}")
|
|
1083
|
+
assert code == 0, out
|
|
1084
|
+
assert not log.exists()
|
|
1085
|
+
assert not (tmp_path / '.agent/worktrees/slot-2').exists()
|
|
1086
|
+
calls = Path(f"{tmp_path}-runner.calls").read_text().splitlines()
|
|
1087
|
+
assert {line.split()[1] for line in calls} == {str(tmp_path.resolve())}
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
def test_a_completed_resume_does_not_recreate_unused_slots(repo, tmp_path, capsys):
|
|
1091
|
+
two(repo)
|
|
1092
|
+
log = tmp_path.parent / f"{tmp_path.name}-prepare.log"
|
|
1093
|
+
assert walk(tmp_path, capsys, WORK + TOGETHER + REPORT, "--prepare", f"pwd >> {log}")[0] == 0
|
|
1094
|
+
subprocess.run(['git', 'worktree', 'remove', '.agent/worktrees/slot-2'], check=True)
|
|
1095
|
+
code, _, out = walk(tmp_path, capsys, 'exit 9\n', '--prepare', f'pwd >> {log}')
|
|
1096
|
+
assert code == 0, out
|
|
1097
|
+
assert len(log.read_text().splitlines()) == 1
|
|
1098
|
+
assert not (tmp_path / '.agent/worktrees/slot-2').exists()
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
def test_lazy_preparation_uses_the_pr_tip_not_a_running_tickets_commit(repo, tmp_path):
|
|
1102
|
+
from types import SimpleNamespace
|
|
1103
|
+
repo()
|
|
1104
|
+
pr_tip = out_of('git', 'rev-parse', 'HEAD')
|
|
1105
|
+
subprocess.run(['git', 'checkout', '-qb', 'ticket/running'], check=True)
|
|
1106
|
+
(tmp_path / 'running-ticket-dependency').write_text('not merged\n')
|
|
1107
|
+
subprocess.run(['git', 'add', 'running-ticket-dependency'], check=True)
|
|
1108
|
+
subprocess.run(['git', 'commit', '-qm', 'running ticket'], check=True)
|
|
1109
|
+
run = SimpleNamespace(args=SimpleNamespace(prepare='test ! -e running-ticket-dependency'), kept={},
|
|
1110
|
+
tip=lambda: pr_tip)
|
|
1111
|
+
driver._prepare_slot(2, {1}, run)
|
|
1112
|
+
assert out_of('git', '-C', '.agent/worktrees/slot-2', 'rev-parse', 'HEAD') == pr_tip
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
def test_resume_reports_all_saved_state_errors_without_starting_an_agent(repo, tmp_path, capsys):
|
|
1116
|
+
two(repo)
|
|
1117
|
+
state = driver_state.State(tmp_path / '.agent/implement/state.json')
|
|
1118
|
+
state.start('feat/x', ['01', '02'])
|
|
1119
|
+
state.ticket('01', phase='polish')
|
|
1120
|
+
state.ticket('02', phase='ship')
|
|
1121
|
+
started = tmp_path.parent / f'{tmp_path.name}-agent-started'
|
|
1122
|
+
code, _, out = walk(tmp_path, capsys, f'touch {started}; exit 9\n')
|
|
1123
|
+
assert code == 3 and not started.exists()
|
|
1124
|
+
errors = [line for line in out.splitlines() if 'unknown phase' in line]
|
|
1125
|
+
assert errors == [
|
|
1126
|
+
".agent/implement/state.json: ticket 01 has the unknown phase 'polish'",
|
|
1127
|
+
".agent/implement/state.json: ticket 02 has the unknown phase 'ship'",
|
|
1128
|
+
]
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
def test_parallel_checkout_waits_for_worktree_registration_to_finish(repo, tmp_path, capsys, monkeypatch):
|
|
1132
|
+
"""Pause Git at its visible-but-incomplete registry entry while the other ticket starts."""
|
|
1133
|
+
import shutil
|
|
1134
|
+
import threading
|
|
1135
|
+
import driver_slots
|
|
1136
|
+
|
|
1137
|
+
two(repo)
|
|
1138
|
+
partial, checked = threading.Event(), threading.Event()
|
|
1139
|
+
real_run, real_ticket = subprocess.run, driver._run_ticket
|
|
1140
|
+
failures = []
|
|
1141
|
+
|
|
1142
|
+
def ticket_after_registration_starts(ticket, slot, run):
|
|
1143
|
+
if slot == 1:
|
|
1144
|
+
assert partial.wait(5), "slot 2 was never registered"
|
|
1145
|
+
return real_ticket(ticket, slot, run)
|
|
1146
|
+
|
|
1147
|
+
def paused_git(argv, *args, **kwargs):
|
|
1148
|
+
if argv[0] == "git" and "worktree" in argv and "add" in argv:
|
|
1149
|
+
metadata = tmp_path / ".git/worktrees/slot-2"
|
|
1150
|
+
metadata.mkdir(parents=True)
|
|
1151
|
+
checkout = tmp_path / ".agent/worktrees/slot-2"
|
|
1152
|
+
checkout.mkdir(parents=True)
|
|
1153
|
+
(checkout / ".git").write_text(f"gitdir: {metadata}\n")
|
|
1154
|
+
(metadata / "gitdir").write_text(str(checkout / ".git") + "\n")
|
|
1155
|
+
(metadata / "HEAD").write_text(out_of("git", "rev-parse", "feat/x") + "\n")
|
|
1156
|
+
(metadata / "commondir").touch() # open(O_CREAT) precedes Git writing ../..
|
|
1157
|
+
partial.set()
|
|
1158
|
+
checked.wait(1)
|
|
1159
|
+
shutil.rmtree(metadata)
|
|
1160
|
+
shutil.rmtree(checkout)
|
|
1161
|
+
result = real_run(argv, *args, **kwargs)
|
|
1162
|
+
if argv[0] == "git" and "checkout" in argv and "ticket/feat%2Fx/01" in argv:
|
|
1163
|
+
if result.returncode:
|
|
1164
|
+
failures.append(result.stderr)
|
|
1165
|
+
checked.set()
|
|
1166
|
+
return result
|
|
1167
|
+
|
|
1168
|
+
monkeypatch.setattr(driver, "_run_ticket", ticket_after_registration_starts)
|
|
1169
|
+
monkeypatch.setattr(driver_slots.subprocess, "run", paused_git)
|
|
1170
|
+
code, _, out = walk(tmp_path, capsys, WORK + REPORT)
|
|
1171
|
+
assert code == 0, out + "\n" + "\n".join(failures)
|
|
1172
|
+
assert failures == []
|
|
@@ -20,7 +20,7 @@ def test_a_slot_with_uncommitted_work_stops_the_run_and_keeps_the_work(repo, tmp
|
|
|
20
20
|
assert driver_slots.setup(2, None) == []
|
|
21
21
|
(tmp_path / ".agent/worktrees/slot-2/wip.txt").write_text("half done\n")
|
|
22
22
|
assert driver_slots.setup(3, None) == [
|
|
23
|
-
"slot 2: .agent/worktrees/slot-2
|
|
23
|
+
"slot 2: .agent/worktrees/slot-2 could not be released: inspect its Git state and uncommitted changes"]
|
|
24
24
|
assert (tmp_path / ".agent/worktrees/slot-2/wip.txt").exists() and not (tmp_path / ".agent/worktrees/slot-3").exists()
|
|
25
25
|
|
|
26
26
|
|
|
@@ -30,3 +30,156 @@ def test_a_slot_that_cannot_be_created_is_an_error(repo, tmp_path):
|
|
|
30
30
|
(tmp_path / ".agent/worktrees/slot-2").write_text("a file is in the way\n")
|
|
31
31
|
(error,) = driver_slots.setup(2, None)
|
|
32
32
|
assert error.startswith("slot 2: cannot create .agent/worktrees/slot-2: ")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_preparing_a_slot_does_not_prune_another_tasks_invisible_checkout(repo, tmp_path):
|
|
36
|
+
repo()
|
|
37
|
+
other = tmp_path.parent / f"{tmp_path.name}-other"
|
|
38
|
+
subprocess.run(["git", "worktree", "add", "-q", "--detach", str(other)], check=True)
|
|
39
|
+
hidden = other.with_name(other.name + "-hidden")
|
|
40
|
+
other.rename(hidden) # as in a session whose mounts hide the other task's checkout
|
|
41
|
+
try:
|
|
42
|
+
assert driver_slots.setup(2, None) == []
|
|
43
|
+
finally:
|
|
44
|
+
hidden.rename(other)
|
|
45
|
+
result = subprocess.run(["git", "-C", str(other), "status", "--porcelain"], capture_output=True, text=True)
|
|
46
|
+
assert result.returncode == 0, result.stderr
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_only_a_missing_slots_registration_is_recovered(repo, tmp_path):
|
|
50
|
+
import shutil
|
|
51
|
+
repo()
|
|
52
|
+
log = tmp_path.parent / f"{tmp_path.name}-prepare.log"
|
|
53
|
+
assert driver_slots.setup(2, f"pwd >> {log}") == []
|
|
54
|
+
shutil.rmtree(tmp_path / driver_slots.path(2))
|
|
55
|
+
assert driver_slots.setup(2, f"pwd >> {log}") == []
|
|
56
|
+
assert driver_slots.git(driver_slots.path(2), "status", "--porcelain").returncode == 0
|
|
57
|
+
assert len(log.read_text().splitlines()) == 2
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_a_missing_locked_slot_is_not_recreated(repo, tmp_path):
|
|
61
|
+
import shutil
|
|
62
|
+
repo()
|
|
63
|
+
assert driver_slots.setup(2, None) == []
|
|
64
|
+
slot = driver_slots.path(2)
|
|
65
|
+
subprocess.run(["git", "worktree", "lock", slot], check=True)
|
|
66
|
+
shutil.rmtree(tmp_path / slot)
|
|
67
|
+
assert driver_slots.setup(2, None)
|
|
68
|
+
assert not (tmp_path / slot).exists()
|
|
69
|
+
assert "locked" in driver_slots.git(".", "worktree", "list", "--porcelain").stdout
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_releasing_a_broken_checkout_fails_without_reporting_it_reusable(repo, tmp_path):
|
|
73
|
+
repo()
|
|
74
|
+
assert driver_slots.setup(2, None) == []
|
|
75
|
+
slot = tmp_path / driver_slots.path(2)
|
|
76
|
+
(slot / '.git').write_text('gitdir: /missing/diagnosis-metadata\n')
|
|
77
|
+
assert not driver_slots.release(str(slot))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_slot_reuse_preserves_installed_dependencies_and_worktree_identity(repo, tmp_path):
|
|
81
|
+
repo()
|
|
82
|
+
log = tmp_path.parent / f"{tmp_path.name}-prepare.log"
|
|
83
|
+
prepare = f"mkdir -p .agent/dependencies; pwd >> {log}"
|
|
84
|
+
assert driver_slots.setup(3, prepare) == []
|
|
85
|
+
slot = driver_slots.path(2)
|
|
86
|
+
metadata = (tmp_path / slot / '.git').read_text()
|
|
87
|
+
dependencies = tmp_path / slot / '.agent/dependencies'
|
|
88
|
+
inode = dependencies.stat().st_ino
|
|
89
|
+
for ticket in ('ticket/01', 'ticket/02', 'ticket/03'):
|
|
90
|
+
subprocess.run(['git', '-C', slot, 'checkout', '-qb', ticket], check=True)
|
|
91
|
+
assert driver_slots.release(slot)
|
|
92
|
+
assert driver_slots.setup(3, prepare) == []
|
|
93
|
+
assert len(log.read_text().splitlines()) == 2
|
|
94
|
+
assert (tmp_path / slot / '.git').read_text() == metadata
|
|
95
|
+
assert dependencies.stat().st_ino == inode
|
|
96
|
+
assert len(driver_slots.git('.', 'worktree', 'list', '--porcelain').stdout.split('worktree ')) - 1 == 3
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_a_foreign_repository_in_a_slot_is_left_untouched_even_when_kept(repo, tmp_path):
|
|
100
|
+
repo()
|
|
101
|
+
slot = tmp_path / driver_slots.path(2)
|
|
102
|
+
slot.mkdir(parents=True)
|
|
103
|
+
subprocess.run(['git', 'init', '-q', '-b', 'foreign', str(slot)], check=True)
|
|
104
|
+
subprocess.run(['git', '-C', str(slot), 'commit', '--allow-empty', '-qm', 'foreign'], check=True)
|
|
105
|
+
assert driver_slots.setup(2, None, {2})
|
|
106
|
+
assert driver_slots.on_branch(str(slot)) == 'foreign'
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_a_locked_index_does_not_report_a_slot_released(repo, tmp_path):
|
|
110
|
+
repo()
|
|
111
|
+
assert driver_slots.setup(2, None) == []
|
|
112
|
+
slot = driver_slots.path(2)
|
|
113
|
+
subprocess.run(['git', '-C', slot, 'checkout', '-qb', 'ticket/held'], check=True)
|
|
114
|
+
index = driver_slots.git(slot, 'rev-parse', '--path-format=absolute', '--git-path', 'index.lock').stdout.strip()
|
|
115
|
+
from pathlib import Path
|
|
116
|
+
Path(index).touch()
|
|
117
|
+
assert not driver_slots.release(slot)
|
|
118
|
+
assert driver_slots.on_branch(slot) == 'ticket/held'
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_registry_operations_coordinate_across_processes_and_linked_checkouts(repo, tmp_path):
|
|
122
|
+
import sys
|
|
123
|
+
from pathlib import Path
|
|
124
|
+
import pytest
|
|
125
|
+
|
|
126
|
+
repo()
|
|
127
|
+
other = tmp_path.parent / f"{tmp_path.name}-linked"
|
|
128
|
+
subprocess.run(["git", "worktree", "add", "-q", "--detach", str(other)], check=True)
|
|
129
|
+
unrelated = tmp_path.parent / f"{tmp_path.name}-independent"
|
|
130
|
+
subprocess.run(["git", "clone", "-q", "--no-hardlinks", str(tmp_path), str(unrelated)], check=True)
|
|
131
|
+
program = r'''
|
|
132
|
+
import subprocess, sys
|
|
133
|
+
sys.path.insert(0, sys.argv[1])
|
|
134
|
+
import driver_slots
|
|
135
|
+
real_run = subprocess.run
|
|
136
|
+
mode = sys.argv[2]
|
|
137
|
+
def pause_add(command, *args, **kwargs):
|
|
138
|
+
if "worktree" in command and "add" in command:
|
|
139
|
+
print("holding registration", flush=True)
|
|
140
|
+
sys.stdin.readline()
|
|
141
|
+
return real_run(command, *args, **kwargs)
|
|
142
|
+
if mode == "add":
|
|
143
|
+
driver_slots.subprocess.run = pause_add
|
|
144
|
+
result = driver_slots.git(".", "worktree", "add", "-q", "--detach", ".agent/worktrees/new")
|
|
145
|
+
else:
|
|
146
|
+
print("requesting checkout", flush=True)
|
|
147
|
+
result = driver_slots.git(".", "checkout", "-q", "--detach")
|
|
148
|
+
print(result.stderr, flush=True)
|
|
149
|
+
sys.exit(result.returncode)
|
|
150
|
+
'''
|
|
151
|
+
command = [sys.executable, "-u", "-c", program, str(Path(driver_slots.__file__).parent)]
|
|
152
|
+
add = subprocess.Popen([*command, "add"], cwd=tmp_path, stdin=subprocess.PIPE,
|
|
153
|
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
154
|
+
checkout = None
|
|
155
|
+
try:
|
|
156
|
+
assert add.stdout.readline().strip() == "holding registration"
|
|
157
|
+
checkout = subprocess.Popen([*command, "checkout"], cwd=other, stdout=subprocess.PIPE,
|
|
158
|
+
stderr=subprocess.PIPE, text=True)
|
|
159
|
+
assert checkout.stdout.readline().strip() == "requesting checkout"
|
|
160
|
+
with pytest.raises(subprocess.TimeoutExpired):
|
|
161
|
+
checkout.communicate(timeout=0.2)
|
|
162
|
+
# Read-only commands do not wait on worktree registration.
|
|
163
|
+
probe = "import sys; sys.path.insert(0, sys.argv[1]); import driver_slots; print(driver_slots.head('.'))"
|
|
164
|
+
read = subprocess.run([sys.executable, "-c", probe, str(Path(driver_slots.__file__).parent)],
|
|
165
|
+
cwd=tmp_path, capture_output=True, text=True, timeout=5)
|
|
166
|
+
assert read.returncode == 0 and read.stdout.strip(), read.stderr
|
|
167
|
+
independent = subprocess.run([*command, "checkout"], cwd=unrelated, capture_output=True, text=True, timeout=5)
|
|
168
|
+
assert independent.returncode == 0, independent.stderr
|
|
169
|
+
add.stdin.write("continue\n")
|
|
170
|
+
add.stdin.flush()
|
|
171
|
+
out, err = add.communicate(timeout=5)
|
|
172
|
+
assert add.returncode == 0, out + err
|
|
173
|
+
out, err = checkout.communicate(timeout=5)
|
|
174
|
+
assert checkout.returncode == 0, out + err
|
|
175
|
+
finally:
|
|
176
|
+
for process in (add, checkout):
|
|
177
|
+
if process is not None and process.poll() is None:
|
|
178
|
+
process.kill()
|
|
179
|
+
process.communicate()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_git_without_a_command_still_returns_gits_usage_error(repo):
|
|
183
|
+
repo()
|
|
184
|
+
result = driver_slots.git(".")
|
|
185
|
+
assert result.returncode != 0 and "usage: git" in result.stdout + result.stderr
|
|
@@ -260,7 +260,8 @@ def test_a_fixer_that_times_out_twice_keeps_its_files_and_the_branch_stays_at_th
|
|
|
260
260
|
rig.run(plan(**{"final/final-spec": [final(finding("Q-ONE"))], "final/fixer": [slow, slow]}),
|
|
261
261
|
"--timeout", "fixer=0.01", *UNATTENDED)
|
|
262
262
|
reviewed = rig.final()["reviewed"]
|
|
263
|
-
assert rig.code ==
|
|
263
|
+
assert rig.code == 2 and rig.pushes() == [] and rig.branch() == reviewed, rig.out
|
|
264
|
+
assert decisions(rig)["questions"][0]["id"] == "final-ticket-blocked-1"
|
|
264
265
|
assert (rig.repo / "wip.txt").read_text() == "half done\n"
|
|
265
266
|
assert rig.led(f"End of run: the fix batch was rejected, so the driver moved feat/csv back to its reviewed tip "
|
|
266
267
|
f"{reviewed[:7]}; the fixer made no commit. The files of the fixer stay in slot 1 as they are.")
|
|
@@ -314,11 +314,15 @@ def test_prepare_runs_once_in_slot_2_and_the_slot_is_reused(tmp_path):
|
|
|
314
314
|
assert (rig.slot2 / "node_modules").is_symlink() and all(g["status"] == "" for g in rig.gates())
|
|
315
315
|
|
|
316
316
|
|
|
317
|
-
def
|
|
317
|
+
def test_failing_prepare_exits_3_after_running_tickets_finish_naming_slot_and_command(tmp_path):
|
|
318
318
|
rig = Rig(tmp_path).run(plan(), "--prepare", "false")
|
|
319
319
|
assert rig.code == 3, rig.output()
|
|
320
320
|
assert re.search(r"slot[- ]?2", rig.out + rig.err) and "false" in rig.out + rig.err
|
|
321
|
-
assert
|
|
321
|
+
assert {call["nn"] for call in rig.calls()} == {"01"}
|
|
322
|
+
assert rig.gates() and not rig.slot2.exists()
|
|
323
|
+
assert git(rig.repo, "symbolic-ref", "--short", "HEAD").strip() == "feat/csv"
|
|
324
|
+
rig.run(plan())
|
|
325
|
+
assert rig.code == 0, rig.output()
|
|
322
326
|
|
|
323
327
|
|
|
324
328
|
def test_a_fast_forward_merge_has_one_fast_and_one_full_record_of_the_ticket_tip(tmp_path):
|
package/skills-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-08T03:27:01.103Z",
|
|
4
4
|
"skills": [
|
|
5
5
|
{
|
|
6
6
|
"name": "agents-wayfinder",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
"name": "implement-spec",
|
|
61
|
-
"version": "0.1.
|
|
62
|
-
"hash": "sha256-
|
|
61
|
+
"version": "0.1.55",
|
|
62
|
+
"hash": "sha256-2580c33f386f59b4eb362c1416eeb84420baa8cd3a2edbff1ed07950dcea8ef4",
|
|
63
63
|
"description": "Implement a specification in code."
|
|
64
64
|
},
|
|
65
65
|
{
|