@jesdi/skills 0.0.97 → 0.0.98
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 +7 -2
- package/skills/implement-spec/SKILL.md +3 -3
- package/skills/implement-spec/driver.py +56 -20
- package/skills/implement-spec/driver_agents.py +16 -5
- package/skills/implement-spec/driver_decisions.py +39 -8
- package/skills/implement-spec/driver_summary.py +16 -2
- package/skills/implement-spec/tests/conftest.py +2 -0
- package/skills/implement-spec/tests/test_report.py +16 -0
- package/skills/implement-spec/tests/test_scoped.py +11 -0
- package/skills/implement-spec/tests/test_stops.py +28 -0
- package/skills-manifest.json +3 -3
package/package.json
CHANGED
|
@@ -41,6 +41,7 @@ A driver before this change named the ticket branches `ticket/<NN>` and the reco
|
|
|
41
41
|
| `--prepare COMMAND` | A shell command that the driver runs once in each new slot 2..N, in `.agent/worktrees/slot-K/`. Use it to install or link the dependencies. |
|
|
42
42
|
| `--timeout ROLE=MINUTES` | The timeout of one role. Repeatable. The rerun after a timeout gets twice the time. |
|
|
43
43
|
| `--answer QUESTION=OPTION` | The answer to one open question. Repeatable. The driver writes it to `.agent/implement-answers.json`. |
|
|
44
|
+
| `--retries N` | The stops of one ticket, or of the end of run, that the driver answers itself with the recommended option before it asks the operator. Default: `IMPLEMENT_SPEC_RETRIES`, else 2. `0` asks at the first stop. See "The driver rules first". |
|
|
44
45
|
| `--unattended` | Print no question. Write `--stage-json` for the dispatcher, and push without `--push` when the final review has passed. |
|
|
45
46
|
| `--stage-json FILE` | With `--unattended`: the file that says how the run ended. |
|
|
46
47
|
| `--push` | Local mode: when the final review has passed, push the PR branch and open the PR. Without it nothing is pushed. |
|
|
@@ -60,7 +61,7 @@ Default timeouts in minutes: test-writer 30, implementer 90, reviewer 45, fixer
|
|
|
60
61
|
|---|---|
|
|
61
62
|
| 0 | Done: every ticket is merged and no question is open. Also the end of a valid `--dry-run`. In local mode without `--push`, nothing is pushed. |
|
|
62
63
|
| 1 | A ticket is BLOCKED, or the end of run is BLOCKED. The other tickets ran as far as they could. |
|
|
63
|
-
| 2 | Parked: a question of kind `spec-ambiguous` or `ticket-blocked`
|
|
64
|
+
| 2 | Parked: a question of kind `spec-ambiguous` is open, or one of kind `ticket-blocked` after the driver's own retries are spent (`--retries`). Exit 2 wins over exit 1. |
|
|
64
65
|
| 3 | Invalid input or a failed precondition: a usage error, a ticket error, a model error, an uncommitted change, a slot that cannot be made, another driver that runs on the same PR branch, an open question of a kind this driver no longer has (see "Resume"). No agent starts. The one exception: a review page that cannot be written gives exit 3 at the end of a run, after agents ran. |
|
|
65
66
|
| 4 | Stopped: the CLI of an agent failed and wrote no report (for example, the account cannot use the model, or its usage ran out). The agent gets no rerun on another entry: the driver starts no other agent and lets the running agents end. No ticket is BLOCKED by it: fix the CLI, or move the role to another entry in a provider config file (see Models), then run the same command again to resume. The preflight of that run skips an entry that still fails. |
|
|
66
67
|
| 130 | The operator interrupted the run. The driver stops each agent. The work stays in the slots for the next run. |
|
|
@@ -83,7 +84,7 @@ Everything is under `.agent/`, which is never committed.
|
|
|
83
84
|
| `<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
85
|
| `<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. |
|
|
85
86
|
| `.agent/implement/ledger.md` | One plain sentence for each event. Only the driver writes it, and it reads no fact from it. |
|
|
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. |
|
|
87
|
+
| `.agent/implement/summary.md` | The result in sentences, and the measurement table: fast gates and full gates, agents, wall time, fix rounds, human stops, the stops the driver ruled on, cost. Then `Driver decisions, taken without the operator:` with one ruling sentence for each question the driver answered itself. |
|
|
87
88
|
| `.agent/implement/decisions.json` | The open questions and their `revision`. Written only after a stop. |
|
|
88
89
|
| `.agent/implement/<NN>/` | One folder for each ticket. |
|
|
89
90
|
| `.agent/implement/<NN>/<role>-<K>.json`, `.log`, `.prompt.md` | The report, the log and the prompt of one agent. K is the fix round. |
|
|
@@ -226,6 +227,10 @@ For each role that commits, every commit in `commits` must be new since the role
|
|
|
226
227
|
|
|
227
228
|
## Question kinds
|
|
228
229
|
|
|
230
|
+
### The driver rules first
|
|
231
|
+
|
|
232
|
+
A stop whose question recommends `retry` does not park the run. The driver answers it with `retry`, the one option it may take itself, writes the same `Ruling:` sentence an operator's answer writes, ending in `Ruled by the driver, not the operator.`, and goes on in the same process, as the next invocation would after `--answer`. Today that is `retry` for `ticket-blocked`; `spec-ambiguous` recommends no option, so it still asks. The driver rules on at most `--retries` stops (default 2) of one ticket, and as many of the end of run. The next stop of that ticket asks the operator, with exit 2. The operator reads the driver's rulings where the run ends: in `summary.md` under `Driver decisions, taken without the operator:` and in the PR body with the other rulings. On the box, 23 answers of 23 were `retry` and each waited hours for the operator (jesdi/agent-ops retro, 2026-11-14).
|
|
233
|
+
|
|
229
234
|
A question is a bounded choice for the operator. `driver_decisions.py` `KINDS` holds each kind with its fixed sentences.
|
|
230
235
|
|
|
231
236
|
| Kind | Question id | Asked when | Run exit | Options |
|
|
@@ -20,12 +20,12 @@ has passed. The review rounds adapt superpowers' subagent-driven-development
|
|
|
20
20
|
(obra/superpowers, MIT).
|
|
21
21
|
-->
|
|
22
22
|
|
|
23
|
-
Run the driver. It makes every choice of the run; you start it and relay its result.
|
|
23
|
+
Run the driver. It makes every choice of the run, and answers its own `retry` questions; you start it and relay its result and its decisions.
|
|
24
24
|
|
|
25
25
|
1. In the PR worktree, run `sh <skill-dir>/run.sh` with the flags the operator gave, unchanged. `<skill-dir>` is the directory of this file. The driver needs `--gate`, `--fast-gate` and `--spec`: ask the operator for a flag that is missing. A run can take hours: run the command in the background and wait for it to exit.
|
|
26
|
-
2. When it exits, relay `.agent/implement/summary.md` and the exit code: 0 is done, 1 is a BLOCKED ticket, 2 is parked on questions, 3 is invalid input, 4 is stopped by a CLI failure (after the fix, the same command resumes). Relay the lines the driver printed after the summary too. With exit 0 and a PR URL such as `https://github.com/jesdi/demo/pull/61`, tell the operator to start the babysitter: run `/babysit-pr https://github.com/jesdi/demo/pull/61`.
|
|
26
|
+
2. When it exits, relay `.agent/implement/summary.md`, with its `Driver decisions` list whole, and the exit code: 0 is done, 1 is a BLOCKED ticket, 2 is parked on questions, 3 is invalid input, 4 is stopped by a CLI failure (after the fix, the same command resumes). Relay the lines the driver printed after the summary too. With exit 0 and a PR URL such as `https://github.com/jesdi/demo/pull/61`, tell the operator to start the babysitter: run `/babysit-pr https://github.com/jesdi/demo/pull/61`.
|
|
27
27
|
3. With exit 2, and with exit 1 when the driver printed questions, show the operator those questions. When the operator answers, run the same command again with one `--answer <question id>=<option id>` for each answer.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Answer no question the driver left open: it has spent its own retries on it. Do not edit `.agent/implement/`, the code or the branches during a run.
|
|
30
30
|
|
|
31
31
|
[README.md](README.md) has each flag, the exit codes, the files of a run and the method.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"""implement-spec driver: validate the ticket set and the environment, then walk the ticket graph.
|
|
3
3
|
|
|
4
4
|
sh run.sh --gate COMMAND --fast-gate COMMAND --spec FILE [--tickets DIR] [--models FILE] [--parallel N] [--prepare COMMAND]
|
|
5
|
-
[--timeout ROLE=MINUTES] [--answer QUESTION=OPTION] [--unattended [--stage-json FILE]] [--push]
|
|
5
|
+
[--timeout ROLE=MINUTES] [--answer QUESTION=OPTION] [--retries N] [--unattended [--stage-json FILE]] [--push]
|
|
6
6
|
[--base BRANCH] [--dry-run]
|
|
7
7
|
|
|
8
8
|
Run it in the PR worktree. Exit 0 = every ticket merged (and pushed, when unattended), 1 = a ticket or the end of
|
|
@@ -439,15 +439,9 @@ def _publish_questions(run: dict) -> str:
|
|
|
439
439
|
return ""
|
|
440
440
|
|
|
441
441
|
|
|
442
|
-
def
|
|
443
|
-
"""Turn each answer
|
|
444
|
-
|
|
445
|
-
run = state.read()["run"]
|
|
446
|
-
questions, document = run["questions"], driver_decisions.document(run)
|
|
447
|
-
if errors := driver_answers.given(args.answer, document):
|
|
448
|
-
return errors
|
|
449
|
-
answers, ignored = driver_answers.read(document)
|
|
450
|
-
rulings, moved = driver_decisions.apply(questions, answers)
|
|
442
|
+
def _settle(state: driver_state.State, questions: list[dict], answers: dict, ignored: list[str], by: str = "") -> None:
|
|
443
|
+
"""Turn each answer into a ruling and let its ticket go on."""
|
|
444
|
+
rulings, moved = driver_decisions.apply(questions, answers, by)
|
|
451
445
|
# The ledger comes first: a run that stops between the two writes gives a ruling twice, and never an answer
|
|
452
446
|
# that no ledger line names.
|
|
453
447
|
for sentence in ignored + rulings:
|
|
@@ -459,10 +453,32 @@ def _apply_answers(state: driver_state.State, args) -> list[str]:
|
|
|
459
453
|
driver_run.record_of(new, number).update(fields)
|
|
460
454
|
|
|
461
455
|
state.update(change)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _apply_answers(state: driver_state.State, args) -> list[str]:
|
|
459
|
+
"""Turn each answer that counts into a ruling and let its ticket go on; [] or the errors that stop the run."""
|
|
460
|
+
_drop_merged(state)
|
|
461
|
+
run = state.read()["run"]
|
|
462
|
+
questions, document = run["questions"], driver_decisions.document(run)
|
|
463
|
+
if errors := driver_answers.given(args.answer, document):
|
|
464
|
+
return errors
|
|
465
|
+
_settle(state, questions, *driver_answers.read(document))
|
|
462
466
|
error = _publish_questions(run)
|
|
463
467
|
return [error] if error else []
|
|
464
468
|
|
|
465
469
|
|
|
470
|
+
def _rule(state: driver_state.State, budget: int) -> bool:
|
|
471
|
+
"""The driver answers each open question that recommends an option with that option, at most `budget` stops per
|
|
472
|
+
ticket and for the end of run. True: it ruled, so the run goes on with no operator."""
|
|
473
|
+
questions = state.read()["run"]["questions"]
|
|
474
|
+
answers = driver_decisions.automatic(questions, budget)
|
|
475
|
+
if answers:
|
|
476
|
+
_settle(state, questions, answers, [], driver_decisions.DRIVER)
|
|
477
|
+
print(f"implement-spec: the driver ruled on {len(answers)} question{'s' * (len(answers) > 1)} with the "
|
|
478
|
+
"recommended option and goes on", flush=True)
|
|
479
|
+
return bool(answers)
|
|
480
|
+
|
|
481
|
+
|
|
466
482
|
# ---------------------------------------------------------------- the end of the process
|
|
467
483
|
|
|
468
484
|
def _write_stage(path: str, code: int, open_questions: int, blocked: list[str]) -> None:
|
|
@@ -518,25 +534,42 @@ def _record_skipped(skipped: list[str]) -> None:
|
|
|
518
534
|
ledger(sentence)
|
|
519
535
|
|
|
520
536
|
|
|
521
|
-
def
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
errors = _resume(tickets, state, pr, slots, args, kept)
|
|
526
|
-
errors = errors or _apply_answers(state, args)
|
|
537
|
+
def _once(tickets: list[Ticket], run: Run, slots: int) -> tuple[bool, list[str]] | int:
|
|
538
|
+
"""Resume, apply the answers and do the work once: what `_work` returns, or exit 3 with each error printed."""
|
|
539
|
+
args = run.args
|
|
540
|
+
errors = _resume(tickets, run.state, run.pr, slots, args, run.kept) or _apply_answers(run.state, args)
|
|
527
541
|
if errors:
|
|
528
542
|
print("\n".join(errors))
|
|
529
543
|
return 3
|
|
530
|
-
run = Run(args, models, state, pr, kept)
|
|
531
|
-
_record_skipped(skipped)
|
|
532
544
|
if args.unattended and args.stage_json:
|
|
533
545
|
Path(args.stage_json).unlink(missing_ok=True) # the file tells how this run ends, never an earlier one
|
|
534
546
|
try:
|
|
535
|
-
|
|
547
|
+
return _work(tickets, slots, run)
|
|
536
548
|
except driver_slots.PreparationError as error:
|
|
537
549
|
print(f"implement-spec: {error}; fix slot preparation and run the same command to resume")
|
|
538
550
|
return 3
|
|
539
|
-
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
def _run(tickets: list[Ticket], models: dict[str, list[str]], skipped: list[str], args, kept: dict[str, int],
|
|
554
|
+
pr: str) -> int:
|
|
555
|
+
state = driver_state.State(STATE)
|
|
556
|
+
slots = 1 if args.only else min(args.parallel, len(tickets))
|
|
557
|
+
_record_skipped(skipped)
|
|
558
|
+
while True:
|
|
559
|
+
run = Run(args, models, state, pr, kept)
|
|
560
|
+
done = _once(tickets, run, slots)
|
|
561
|
+
if isinstance(done, int):
|
|
562
|
+
return done
|
|
563
|
+
if run.halted or not _rule(state, args.retries):
|
|
564
|
+
break
|
|
565
|
+
# The driver's own answer resumes the run as the operator's would on the next invocation.
|
|
566
|
+
args.answer, kept = [], driver_state.kept(state.read())
|
|
567
|
+
return _finish(run, args, *done)
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
def _finish(run: Run, args, end_blocked: bool, lines: list[str]) -> int:
|
|
571
|
+
"""Write and print the summary, and return the exit code."""
|
|
572
|
+
final = run.state.read()
|
|
540
573
|
summary = driver_summary.render(final)
|
|
541
574
|
(OUT / "summary.md").write_text(summary)
|
|
542
575
|
print(summary + "".join(line + "\n" for line in lines), end="")
|
|
@@ -583,6 +616,9 @@ def _arguments(argv: list[str] | None) -> argparse.Namespace:
|
|
|
583
616
|
parser.add_argument("--answer", action="append", type=driver_answers.pair, default=[],
|
|
584
617
|
metavar="QUESTION=OPTION", help="the answer to one open question of "
|
|
585
618
|
f"{DECISIONS}, repeatable; it goes to {driver_answers.FILE}")
|
|
619
|
+
parser.add_argument("--retries", type=int, default=int(os.environ.get("IMPLEMENT_SPEC_RETRIES", 2)), metavar="N",
|
|
620
|
+
help="the stops of one ticket, or of the end of run, that the driver answers itself with the "
|
|
621
|
+
"recommended option before it asks the operator (default: IMPLEMENT_SPEC_RETRIES, else 2)")
|
|
586
622
|
parser.add_argument("--unattended", action="store_true", help="at a question, print no question: write "
|
|
587
623
|
"--stage-json for the dispatcher, which gives the answers file to the next run")
|
|
588
624
|
parser.add_argument("--stage-json", metavar="FILE", help="with --unattended: where the driver writes how a "
|
|
@@ -251,15 +251,26 @@ def last_message(report: str | Path) -> str:
|
|
|
251
251
|
return f"{report}.last"
|
|
252
252
|
|
|
253
253
|
|
|
254
|
+
def _spoken(log: Path) -> str:
|
|
255
|
+
"""The JSON object in the `result` of the last claude stream-json line: a report the agent gave as its answer
|
|
256
|
+
and did not write; "" when there is none."""
|
|
257
|
+
with contextlib.suppress(OSError, ValueError, AttributeError, IndexError):
|
|
258
|
+
said = str(json.loads(log.read_text(errors="replace").splitlines()[-1]).get("result"))
|
|
259
|
+
found = said[said.index("{"):said.rindex("}") + 1]
|
|
260
|
+
json.loads(found)
|
|
261
|
+
return found
|
|
262
|
+
return ""
|
|
263
|
+
|
|
264
|
+
|
|
254
265
|
def settle_report(report: Path) -> None:
|
|
255
|
-
"""The report is the one the agent wrote when it parses
|
|
256
|
-
|
|
257
|
-
if not last.exists():
|
|
258
|
-
return
|
|
266
|
+
"""The report is the one the agent wrote when it parses; else the last message codex saved, or the JSON object a
|
|
267
|
+
claude agent gave as its answer in the log next to the report, when there is one."""
|
|
259
268
|
with contextlib.suppress(OSError, ValueError):
|
|
260
269
|
json.loads(report.read_text())
|
|
261
270
|
return
|
|
262
|
-
|
|
271
|
+
last = Path(last_message(report))
|
|
272
|
+
if said := last.read_text() if last.exists() else _spoken(report.with_suffix(".log")):
|
|
273
|
+
report.write_text(said)
|
|
263
274
|
|
|
264
275
|
|
|
265
276
|
def render(name: str, values: dict[str, str]) -> str:
|
|
@@ -9,9 +9,11 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import hashlib
|
|
11
11
|
import json
|
|
12
|
+
from collections import Counter
|
|
12
13
|
from typing import NamedTuple
|
|
13
14
|
|
|
14
15
|
PUBLIC = ("id", "title", "why", "evidence", "options", "recommended")
|
|
16
|
+
DRIVER = "driver" # `by` of a question the driver answered itself
|
|
15
17
|
FINAL = "final" # the end of run asks its questions, and has its record and its files, under this name
|
|
16
18
|
|
|
17
19
|
|
|
@@ -162,19 +164,48 @@ def _settled(questions: list[dict], ticket: str, stop: int) -> dict:
|
|
|
162
164
|
return {name: value for one in fields for name, value in one.items()} if all(fields) else {}
|
|
163
165
|
|
|
164
166
|
|
|
165
|
-
def
|
|
166
|
-
"""
|
|
167
|
-
|
|
167
|
+
def ruled(questions: list[dict]) -> Counter:
|
|
168
|
+
"""ticket (or FINAL) -> the stops of it that the driver ruled on."""
|
|
169
|
+
return Counter(ticket for ticket, _ in {(q["ticket"], q["stop"]) for q in by_driver(questions)})
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def automatic(questions: list[dict], budget: int) -> dict:
|
|
173
|
+
"""The answers the driver gives itself: `retry` for each open question that recommends it, while the driver ruled
|
|
174
|
+
on fewer than `budget` stops of its ticket (or of the end of run). No other option is the driver's to take: a
|
|
175
|
+
kind that recommends one still asks the operator."""
|
|
176
|
+
spent = ruled(questions)
|
|
177
|
+
asked = [q for q in questions if q["answer"] is None and q["recommended"] == "retry"]
|
|
178
|
+
return {q["id"]: q["recommended"] for q in asked if spent[q["ticket"]] < budget}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _answer(q: dict, answers: dict, by: str) -> str:
|
|
182
|
+
"""Answer `q` from `answers` and return its ruling, with the note of the operator."""
|
|
183
|
+
q["answer"], q["by"] = answers[q["id"]], by
|
|
184
|
+
q["ruling"] = ruling(q) + " Ruled by the driver, not the operator." * (by == DRIVER)
|
|
185
|
+
note = answers.get(f"{q['id']}.note")
|
|
186
|
+
return q["ruling"] + f" Note of the operator: {note}" * bool(note)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def apply(questions: list[dict], answers: dict, by: str = "") -> tuple[list[str], dict[str, dict]]:
|
|
190
|
+
"""Answer the open questions in `answers`; `by` is DRIVER for the answers of `automatic`. Returns (a ruling per
|
|
191
|
+
answer, ticket or FINAL -> the fields that let its record go on)."""
|
|
168
192
|
rulings, stops = [], {}
|
|
169
193
|
for q in questions:
|
|
170
194
|
if q["answer"] is None and q["id"] in answers:
|
|
171
|
-
q
|
|
172
|
-
q["ruling"] = ruling(q)
|
|
173
|
-
note = answers.get(f"{q['id']}.note")
|
|
174
|
-
rulings.append(q["ruling"] + f" Note of the operator: {note}" * bool(note))
|
|
195
|
+
rulings.append(_answer(q, answers, by))
|
|
175
196
|
stops[q["ticket"]] = q["stop"]
|
|
197
|
+
return rulings, _moved(questions, stops)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _moved(questions: list[dict], stops: dict) -> dict[str, dict]:
|
|
201
|
+
"""ticket or FINAL -> the fields that let its record go on, for each of `stops` whose answers settle it."""
|
|
176
202
|
moved = {ticket: _settled(questions, ticket, stop) for ticket, stop in stops.items()}
|
|
177
|
-
return
|
|
203
|
+
return {ticket: fields for ticket, fields in moved.items() if fields}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def by_driver(questions: list[dict]) -> list[dict]:
|
|
207
|
+
"""The questions the driver answered itself."""
|
|
208
|
+
return [q for q in questions if q.get("by") == DRIVER]
|
|
178
209
|
|
|
179
210
|
|
|
180
211
|
def text(open_questions: list[dict], answers: str, page: str) -> str:
|
|
@@ -3,6 +3,8 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
from collections import Counter, defaultdict
|
|
5
5
|
|
|
6
|
+
import driver_decisions
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
def _rows(run: dict, tickets: dict) -> list[tuple[str, object]]:
|
|
8
10
|
agents = Counter((agent["role"], agent["entry"]) for agent in run["agents"])
|
|
@@ -14,10 +16,22 @@ def _rows(run: dict, tickets: dict) -> list[tuple[str, object]]:
|
|
|
14
16
|
*((f"agents, {role} on {entry}", number) for (role, entry), number in agents.items()),
|
|
15
17
|
*((f"wall time, {role}", f"{total:.1f} s") for role, total in seconds.items()),
|
|
16
18
|
("fix rounds per ticket", rounds),
|
|
17
|
-
(
|
|
19
|
+
*_stops(run),
|
|
18
20
|
*_cost(run["agents"])]
|
|
19
21
|
|
|
20
22
|
|
|
23
|
+
def _stops(run: dict) -> list[tuple[str, object]]:
|
|
24
|
+
"""The stops that waited for the operator, and a row for those the driver ruled on itself, when it did."""
|
|
25
|
+
ruled = sum(driver_decisions.ruled(run.get("questions", [])).values())
|
|
26
|
+
return [("human stops", run["stops"] - ruled), *([("stops the driver ruled on", ruled)] if ruled else [])]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _decisions(run: dict) -> list[str]:
|
|
30
|
+
"""What the driver decided without the operator, for the end of the summary."""
|
|
31
|
+
rulings = [q["ruling"] for q in driver_decisions.by_driver(run.get("questions", []))]
|
|
32
|
+
return ["", "Driver decisions, taken without the operator:", *(f"- {ruling}" for ruling in rulings)] * bool(rulings)
|
|
33
|
+
|
|
34
|
+
|
|
21
35
|
def _cost(agents: list[dict]) -> list[tuple[str, object]]:
|
|
22
36
|
"""The cost row, and a row that counts the agents with no price (cost None), which the cost leaves out."""
|
|
23
37
|
unpriced = sum(agent["cost"] is None for agent in agents)
|
|
@@ -44,4 +58,4 @@ def render(state: dict) -> str:
|
|
|
44
58
|
lines += [f"Ticket {number} is not merged: its phase is {entry['phase']}."
|
|
45
59
|
for number, entry in tickets.items() if entry["phase"] != "merged"] + _end(run)
|
|
46
60
|
table = ["| Measure | Value |", "|---|---|"] + [f"| {name} | {value} |" for name, value in _rows(run, tickets)]
|
|
47
|
-
return "\n".join(lines + ["", *table]) + "\n"
|
|
61
|
+
return "\n".join(lines + ["", *table] + _decisions(run)) + "\n"
|
|
@@ -27,6 +27,8 @@ def pr_skill(tmp_path_factory):
|
|
|
27
27
|
patch.setenv("CLAUDE_CONFIG_DIR", str(home))
|
|
28
28
|
# No test reads the operator's own provider config (driver_agents.load_models).
|
|
29
29
|
patch.setenv("XDG_CONFIG_HOME", str(tmp_path_factory.mktemp("config-home")))
|
|
30
|
+
# The tests of a stop see its question: the driver answers none itself unless a test passes --retries.
|
|
31
|
+
patch.setenv("IMPLEMENT_SPEC_RETRIES", "0")
|
|
30
32
|
yield home / "skills/pr/SKILL.md"
|
|
31
33
|
|
|
32
34
|
|
|
@@ -206,3 +206,19 @@ def test_a_read_only_role_lists_no_commits_so_the_commits_it_reviewed_are_not_re
|
|
|
206
206
|
template = "final-lens" if role in LENSES else role # the lenses share one prompt
|
|
207
207
|
assert check(template, report, start=shas["impl"]) == []
|
|
208
208
|
assert check(template, {**report, "commits": [shas["tests"], shas["impl"]]}, start=shas["impl"]) == []
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def test_a_report_a_claude_agent_gave_as_its_answer_and_did_not_write_is_taken_from_its_log(tmp_path):
|
|
212
|
+
import driver_agents
|
|
213
|
+
report, log = tmp_path / "reviewer-0.json", tmp_path / "reviewer-0.log"
|
|
214
|
+
said = "Here is my report:\n```json\n{\"status\": \"DONE\", \"findings\": []}\n```"
|
|
215
|
+
log.write_text(json.dumps({"type": "assistant"}) + "\n" + json.dumps({"type": "result", "result": said}) + "\n")
|
|
216
|
+
driver_agents.settle_report(report)
|
|
217
|
+
assert json.loads(report.read_text()) == {"status": "DONE", "findings": []}
|
|
218
|
+
report.write_text('{"status": "BLOCKED"}') # a written report that parses stays
|
|
219
|
+
driver_agents.settle_report(report)
|
|
220
|
+
assert json.loads(report.read_text()) == {"status": "BLOCKED"}
|
|
221
|
+
report.unlink()
|
|
222
|
+
log.write_text("no json here\n")
|
|
223
|
+
driver_agents.settle_report(report)
|
|
224
|
+
assert not report.exists()
|
|
@@ -75,6 +75,17 @@ def test_retry_on_an_open_final_finding_runs_one_more_fix_batch_and_one_scoped_r
|
|
|
75
75
|
assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
def test_with_retries_the_driver_runs_the_one_more_fix_batch_itself_and_pushes_with_its_ruling(tmp_path):
|
|
79
|
+
rig = rig_of(tmp_path)
|
|
80
|
+
steps = plan(**{"final/final-spec": [final(ATOMIC)], "final/final-reviewer": [final(ATOMIC), final()],
|
|
81
|
+
"final/fixer": [fixer(fn("02"), "fix the ledger"), fixer(fn("02"), "write the ledger atomically")]})
|
|
82
|
+
rig.run(steps, "--retries", "1", *UNATTENDED)
|
|
83
|
+
assert rig.code == 0 and rig.pushes() == [f"refs/heads/feat/csv {rig.branch()}"], rig.out
|
|
84
|
+
assert len(rig.final_calls("fixer")) == 2 and len(rig.final_calls("final-reviewer")) == 2
|
|
85
|
+
assert rig.led("Ruling: final runs again (retry)") and rig.led("Ruled by the driver, not the operator.")
|
|
86
|
+
assert [len(rig.final_calls(role)) for role in LENSES] == [1, 1, 1]
|
|
87
|
+
|
|
88
|
+
|
|
78
89
|
def test_edit_on_an_open_final_finding_keeps_the_end_of_run_blocked_and_runs_no_agent(tmp_path):
|
|
79
90
|
rig, steps = open_after_batch(tmp_path)
|
|
80
91
|
calls = len(rig.calls())
|
|
@@ -223,3 +223,31 @@ def test_unattended_blocked_ticket_ends_with_stage_json_blocked_naming_it_and_ex
|
|
|
223
223
|
rig.run(plan(**{"01/fixer": [fix("01", n) for n in (1, 2)]}), *UNATTENDED)
|
|
224
224
|
assert rig.code == 1, rig.output()
|
|
225
225
|
assert stage(rig) == {"stage": "implement", "status": "blocked", "blocked": ["01"]}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# ---------------------------------------------------------------- the driver rules (--retries)
|
|
229
|
+
|
|
230
|
+
def test_with_retries_the_driver_answers_retry_itself_and_lists_its_decision_at_the_end(tmp_path):
|
|
231
|
+
rig = Review(tmp_path, ONE).run(steps(blocked(), blocked(), impl("01")), "--retries", "2")
|
|
232
|
+
assert rig.code == 0, rig.output()
|
|
233
|
+
assert rig.led(RULED) and rig.led("Ruled by the driver, not the operator.")
|
|
234
|
+
assert len(rig.calls("01", "implementer")) == 3 and "feat: 01 rows" in rig.pr_subjects()
|
|
235
|
+
summary = (rig.repo / ".agent/implement/summary.md").read_text()
|
|
236
|
+
assert "| human stops | 0 |" in summary and "| stops the driver ruled on | 1 |" in summary
|
|
237
|
+
assert "Driver decisions, taken without the operator:\n- " + RULED in summary
|
|
238
|
+
assert not answers_file(rig).exists()
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def test_after_the_retries_are_spent_the_next_stop_of_the_ticket_asks_the_operator(tmp_path):
|
|
242
|
+
rig = Review(tmp_path, ONE).run(steps(*[blocked()] * 6, impl("01")), "--retries", "2")
|
|
243
|
+
assert rig.code == 2, rig.output()
|
|
244
|
+
assert [q["id"] for q in decisions(rig)["questions"]] == ["01-ticket-blocked-3"]
|
|
245
|
+
assert len(rig.calls("01", "implementer")) == 6
|
|
246
|
+
assert "| human stops | 1 |" in (rig.repo / ".agent/implement/summary.md").read_text()
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def test_the_driver_answers_only_a_recommended_retry():
|
|
250
|
+
import driver_decisions
|
|
251
|
+
ask = lambda id, recommended: {"id": id, "ticket": "01", "stop": 1, "answer": None, "recommended": recommended}
|
|
252
|
+
questions = [ask("a", "retry"), ask("b", "accept"), ask("c", "")]
|
|
253
|
+
assert driver_decisions.automatic(questions, 2) == {"a": "retry"}
|
package/skills-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-15T02:04:59.583Z",
|
|
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.60",
|
|
62
|
+
"hash": "sha256-7a558238b6b63630865609d10cba0d5798aca66eaa48a5fb6fb0f141ce91ebad",
|
|
63
63
|
"description": "Implement a specification in code."
|
|
64
64
|
},
|
|
65
65
|
{
|