@jesdi/skills 0.0.100 → 0.0.102
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/babysit-pr/SKILL.md +9 -2
- package/skills/babysit-pr/babysit.py +98 -36
- package/skills/babysit-pr/exam.py +156 -0
- package/skills/babysit-pr/fixtures/exam_host.py +47 -0
- package/skills/babysit-pr/fixtures/gh +107 -11
- package/skills/babysit-pr/test_babysit.py +8 -2
- package/skills/babysit-pr/test_e2e_setup.py +1 -1
- package/skills/babysit-pr/test_exam_merge_gate.py +189 -0
- package/skills/babysit-pr/test_exam_request.py +337 -0
- package/skills/babysit-pr/test_exam_required_check.py +145 -0
- package/skills/babysit-pr/test_exam_wait.py +353 -0
- package/skills/babysit-pr/test_merge_and_handoff.py +12 -6
- package/skills/babysit-pr/test_trusted_merge_risk.py +2 -2
- package/skills/implement-spec/ARCHITECTURE.md +1 -1
- package/skills/implement-spec/README.md +6 -6
- package/skills/implement-spec/driver_final.py +24 -21
- package/skills/implement-spec/driver_final_gate.py +152 -17
- package/skills/implement-spec/driver_gate.py +12 -0
- package/skills/implement-spec/driver_pr.py +16 -7
- package/skills/implement-spec/driver_slots.py +28 -11
- package/skills/implement-spec/driver_state.py +3 -2
- package/skills/implement-spec/prompts/pr-body.md +1 -0
- package/skills/implement-spec/tests/test_final_gate.py +144 -0
- package/skills/implement-spec/tests/test_overturn.py +2 -2
- package/skills/implement-spec/tests/test_walk.py +1 -0
- package/skills/pr-exam/SKILL.md +131 -0
- package/skills/pr-exam/fixtures/README.md +20 -0
- package/skills/pr-exam/fixtures/delta-new-concept/body.md +9 -0
- package/skills/pr-exam/fixtures/delta-new-concept/diff.patch +82 -0
- package/skills/pr-exam/fixtures/delta-new-concept/exam.json +46 -0
- package/skills/pr-exam/fixtures/delta-new-concept/passed.diff +66 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0001-single-sync-leader.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0002-stale-leader-writes.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0003-fencing-token.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0004-lease-expiry.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0005-injected-monotonic-clock.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0006-leader-lifecycle.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0007-lease-rollback.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/records/0008-sync-blast-radius.md +10 -0
- package/skills/pr-exam/fixtures/delta-new-concept/request.json +43 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/body.md +9 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/diff.patch +66 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/exam.json +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/passed.diff +66 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0001-single-sync-leader.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0002-stale-leader-writes.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0003-fencing-token.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0004-lease-expiry.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0005-injected-monotonic-clock.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0006-leader-lifecycle.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0007-lease-rollback.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/records/0008-sync-blast-radius.md +10 -0
- package/skills/pr-exam/fixtures/delta-nothing-new/request.json +43 -0
- package/skills/pr-exam/fixtures/followup/body.md +9 -0
- package/skills/pr-exam/fixtures/followup/diff.patch +66 -0
- package/skills/pr-exam/fixtures/followup/exam.json +61 -0
- package/skills/pr-exam/fixtures/followup/records/0001-single-sync-leader.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0002-stale-leader-writes.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0003-fencing-token.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0004-lease-expiry.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0005-injected-monotonic-clock.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0006-lease-rollback.md +10 -0
- package/skills/pr-exam/fixtures/followup/records/0007-sync-blast-radius.md +10 -0
- package/skills/pr-exam/fixtures/followup/request.json +41 -0
- package/skills/pr-exam/fixtures/grading/answers.json +5 -0
- package/skills/pr-exam/fixtures/grading/attempt.json +10 -0
- package/skills/pr-exam/fixtures/grading/grades.json +14 -0
- package/skills/pr-exam/fixtures/grading/questions.json +26 -0
- package/skills/pr-exam/fixtures/grading/request.json +10 -0
- package/skills/pr-exam/fixtures/twelve-concepts/body.md +9 -0
- package/skills/pr-exam/fixtures/twelve-concepts/diff.patch +66 -0
- package/skills/pr-exam/fixtures/twelve-concepts/exam.json +195 -0
- package/skills/pr-exam/fixtures/twelve-concepts/request.json +15 -0
- package/skills/pr-exam/fixtures/typo-readme/body.md +1 -0
- package/skills/pr-exam/fixtures/typo-readme/diff.patch +7 -0
- package/skills/pr-exam/fixtures/typo-readme/exam.json +30 -0
- package/skills/pr-exam/fixtures/typo-readme/request.json +15 -0
- package/skills/pr-exam/pr_exam.py +705 -0
- package/skills/pr-exam/test_config.py +83 -0
- package/skills/pr-exam/test_exam_format.py +252 -0
- package/skills/pr-exam/test_followup_delta.py +90 -0
- package/skills/pr-exam/test_learning_records.py +267 -0
- package/skills/pr-exam/test_record_publication.py +45 -0
- package/skills/pr-exam/test_scoring.py +121 -0
- package/skills/pr-exam/test_served_shapes.py +38 -0
- package/skills/pr-exam/test_setup.py +349 -0
- package/skills/pr-exam/test_skill_fixtures.py +88 -0
- package/skills-manifest.json +11 -5
|
@@ -38,7 +38,7 @@ A driver before this change named the ticket branches `ticket/<NN>` and the reco
|
|
|
38
38
|
| `--tickets DIR` | The directory of the ticket files. Default: `.agent/tickets`. |
|
|
39
39
|
| `--models FILE` | A JSON file with one ordered list of `provider/model@effort` for each role. A role in this file replaces the list of that role in `models.json` and in the provider config files (see Models). |
|
|
40
40
|
| `--parallel N` | The number of tickets in flight at once. Default: 2. |
|
|
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. |
|
|
41
|
+
| `--prepare COMMAND` | A shell command that the driver runs once in each new slot 2..N, in `.agent/worktrees/slot-K/`, and in the slot of the base gate, `.agent/worktrees/slot-base/`. 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`. On a question the driver or the arbiter answered, it overturns that ruling: see "Overturn a ruling". |
|
|
44
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". |
|
|
@@ -96,7 +96,7 @@ Everything is under `.agent/`, which is never committed.
|
|
|
96
96
|
| `.agent/implement/pycache/` | Compiled Python of the gate, kept out of the slots. |
|
|
97
97
|
| `.agent/implement-review.html` | The page with the open questions. |
|
|
98
98
|
| `.agent/implement-answers.json` | The answers: `{"v": 1, "stage": "implement", "submitted": …, "revision": …, "answers": {…}}`. |
|
|
99
|
-
| `.agent/worktrees/slot-K/` | Slots 2..N. Slot 1 is the PR worktree. |
|
|
99
|
+
| `.agent/worktrees/slot-K/` | Slots 2..N. Slot 1 is the PR worktree. `slot-base` holds the base commit for the full gate on the base (End of run, Full gate). |
|
|
100
100
|
| `refs/implement-spec/<key>/recovery` | A git ref: the PR tip before the tidy. |
|
|
101
101
|
| `ticket/<key>/<NN>` | The branch of one ticket. The driver deletes it when the ticket is merged. |
|
|
102
102
|
|
|
@@ -155,16 +155,16 @@ The end of run starts only when every ticket is merged and every slot is idle. I
|
|
|
155
155
|
|
|
156
156
|
1. **Tidy.** The driver saves the PR tip in `refs/implement-spec/<key>/recovery`. It then makes one commit for each ticket, in merge order, named `feat(NN): <title>`. Each commit holds the tests, the implementation and the fixes of its ticket. The tree of the new tip must equal the tree of the old tip, or the branch stays as it was.
|
|
157
157
|
2. **Rebase** onto the fetched tip of the `--base` branch, or without it of the default branch of `origin`. A conflict goes to the conflict agent (`prompts/rebase-conflict.md`) once; the integrated tip gets the full gate in the next step. When the agent leaves the rebase open with no conflict, the driver goes on with it, then checks the rebased tip, in place of the commits the report names: a report whose rebased tip changes a locked file of any ticket from the recovery point is rejected, and the rerun fixes that tip with `git commit --amend`. When git cannot go on at the stop the agent resolved (a resolved file it did not stage), the report is rejected with git's error and the agent reruns. A second conflict leaves the branch at its recovery point.
|
|
158
|
-
3. **Full gate.** A red result saves the exact gate log and sends one repair batch to the final fixer (`prompts/final-gate-fixer.md`). An evidenced no-op is allowed when no code change is needed: it consumes the same repair attempt and reruns the full gate on the unchanged tip. Its commits are attributed to tickets and obey the same locked-file checks as final-review fixes. The driver reruns the full gate on the repaired tip. A second red result asks `final-ticket-blocked` with `retry` or `edit`; retry grants one further repair batch using the saved log. This allowance is independent of completed-ticket rounds and final-review rounds. Only a green integrated tip starts the **final review**: three agents at the same time in slot 1, one for each lens of the `review-diff` method, on the whole range, each with the one lens prompt `prompts/final-lens.md` and its own method lines in it. `final-spec` follows review-diff's `spec.md` with the run's spec; `final-correctness` has review-diff's `correctness.md` inlined, reads files from git at the reviewed tip and runs no tests; `final-structure` follows the `deep-quality-review` skill. `final-spec` and `final-structure` run on the first `final-reviewer` entry, `final-correctness` on the first `final-reviewer` entry on another provider than the first `implementer` entry, or on the first `final-reviewer` entry when there is none. Each reads the driver's full gate record of the reviewed tip as its gate evidence and runs no gate. Each gets ticket observations, minor findings, the must-fix list and the rulings of the operator, writes its own report and never sees another's. The driver merges their findings into one `findings-0.json`: each finding has a `source` (`spec`, `correctness` or `structure`), and two findings with the same file, line and title are one, the more severe one, or on a tie the earlier one in the order spec, correctness, structure. The ledger line of each finding names its source. A lens that stops or is rejected runs once more on the next entry; when the rerun stops or is rejected too, the round stops once the other lenses have ended, no fix batch runs, and the end of run asks `final-ticket-blocked-<n>`. The driver keeps each accepted lens report with the tip it covers (`run.final.lenses`): the next review of that tip runs only the lenses with no kept report, and a review of another tip runs all three. A lens that changes the slot makes all three run again.
|
|
158
|
+
3. **Full gate.** A red result first runs the full gate on the base commit, the commit the branch is rebased onto (`run.final.onto`), in `.agent/worktrees/slot-base/`, so slot 1 keeps the tip; it runs once per base commit (`run.final.base_gate`), and only when the tip's log has a failure line. A failure line is a line of the command's output that says fail, failed, failing, failure, error, names an exception (`AssertionError`), shows ✗, ×, ✖ or ●, or is the title of a failed test in mocha's list (`1) Suite does x:`), but not a wrapper's line for any red command (`make: ***`, `npm ERR!`, `exit code 2`); times, `:line:col` and the counts of the tests that passed (`40 passed`) are masked, so a test the change adds or a line it moves does not make an old failure look new, and a count of failures (`3 failed`), a test identifier (`test_limit[1]`) or any other value stays as it is. When both gates judged their commit (a complete run with an exit from 1 to 127, as one that a signal ended or that crashed exits 128 and up, on a tree clean after it) and the tip has the same failure lines as the base, as often, the failures are pre-existing: the gate counts as passed for the run, which goes on to the review and the push, and the PR opens as a draft, since a match of lines does not prove the change broke nothing: the operator reads both records and readies it. The ledger, the gate evidence of the review agents, the draft reason and the review coverage of the PR body name both records (`run.final.gate_preexisting`). Else every failure counts as new, as does a red log with no failure line, a tip with fewer or other failures than the base, or a base gate that is green or cannot run; a red result then saves the exact gate log, with the base record named in the repair finding when the base is red, and sends one repair batch to the final fixer (`prompts/final-gate-fixer.md`). An evidenced no-op is allowed when no code change is needed: it consumes the same repair attempt and reruns the full gate on the unchanged tip. Its commits are attributed to tickets and obey the same locked-file checks as final-review fixes. The driver reruns the full gate on the repaired tip. A second red result asks `final-ticket-blocked` with `retry` or `edit`; retry grants one further repair batch using the saved log. This allowance is independent of completed-ticket rounds and final-review rounds. Only a green integrated tip, or one red only with pre-existing failures, starts the **final review**: three agents at the same time in slot 1, one for each lens of the `review-diff` method, on the whole range, each with the one lens prompt `prompts/final-lens.md` and its own method lines in it. `final-spec` follows review-diff's `spec.md` with the run's spec; `final-correctness` has review-diff's `correctness.md` inlined, reads files from git at the reviewed tip and runs no tests; `final-structure` follows the `deep-quality-review` skill. `final-spec` and `final-structure` run on the first `final-reviewer` entry, `final-correctness` on the first `final-reviewer` entry on another provider than the first `implementer` entry, or on the first `final-reviewer` entry when there is none. Each reads the driver's full gate record of the reviewed tip as its gate evidence and runs no gate. Each gets ticket observations, minor findings, the must-fix list and the rulings of the operator, writes its own report and never sees another's. The driver merges their findings into one `findings-0.json`: each finding has a `source` (`spec`, `correctness` or `structure`), and two findings with the same file, line and title are one, the more severe one, or on a tie the earlier one in the order spec, correctness, structure. The ledger line of each finding names its source. A lens that stops or is rejected runs once more on the next entry; when the rerun stops or is rejected too, the round stops once the other lenses have ended, no fix batch runs, and the end of run asks `final-ticket-blocked-<n>`. The driver keeps each accepted lens report with the tip it covers (`run.final.lenses`): the next review of that tip runs only the lenses with no kept report, and a review of another tip runs all three. A lens that changes the slot makes all three run again.
|
|
159
159
|
4. **Fix batch.** Critical and important findings, including every must-fix item, go to one fixer (`prompts/final-fixer.md`), which makes the fast gate green on its final commit, with every merged ticket's locked files in `IMPLEMENT_SPEC_LOCKED`. A report whose commits change a locked file of any ticket from the tidied tip is rejected naming the file, so the fixer runs once more on its next `fixer` entry. The driver names each of its commits `fix(NN): …` from the ticket in the report. Then the full gate, then one scoped review of those commits: the **final-reviewer** (`prompts/final-reviewer.md`), one agent on the entry of `final-correctness`, so on another provider than the first `implementer` entry when the lists have one. It reads the merged findings, checks that each critical and important one is fixed and that the fix commits break nothing else, and lists each must-fix item it verified in `resolved_must_fix`; a must-fix item it leaves out stays open. The driver runs no fast gate at the end of the run.
|
|
160
160
|
5. Each important finding the scoped review leaves open asks one `final-finding-open-<n>` question, and each critical or must-fix one a `final-finding-must-fix-<n>` question, all in one stop; nothing is pushed while one is open. `retry` runs one more fix batch and one more scoped review on the open findings that no answer ships with; `accept` and `follow-up` ship the PR with the finding: as draft when the arbiter ruled it, ready for review when the operator did. A finding once shipped asks no question again in the run, unless the driver or the arbiter shipped it and a later scoped review rates it critical or must-fix: only the operator's answer ships such a finding, so it asks `finding-must-fix`. There is no third review unless a `retry` asks for one.
|
|
161
|
-
6. **Push.** With `--push` or `--unattended`, the driver pushes the reviewed tip once, with no force, and opens the PR into the branch of step 2 with `gh`: as draft when a finding that an agent's ruling shipped is open, ready for review otherwise (the operator's own `accept` or `follow-up` keeps it ready), and the ledger says why. After a `ship-draft` ruling it pushes instead the branch tip that a full gate ran on, green or red, as draft; the review coverage of the body names the commits after the reviewed tip that no review covered. The ruling, the operator's or the driver's, records that tip and the stops once (`run.final.ship`), and the push reads only that record: a run stopped between the ruling and the push pushes the recorded tip, and refuses, pushing nothing, when the branch moved from it. Once the pr-writer's body is valid and before it opens the PR, it files each finding answered `follow-up` as an issue with `gh issue create`, and the PR body's rulings and `summary.md` link the issue. The issue body carries a marker of the run and the question; a run that stopped before it kept the URL finds the issue by that marker instead of filing it twice. A local run without `--push` files nothing. The **pr-writer** (`prompts/pr-writer.md`) writes the body with the method of the `pr` skill; the driver puts the facts of the run after it: the ticket-to-commit map, the fix commits, the rulings and the review coverage (`prompts/pr-body.md`). The body carries the merge-risk block of the `pr-risk` skill under `## Merge Danger`, above the facts; the driver validates it, runs the pr-writer once more with the errors when it is invalid, and blocks the run, opening no PR, when the second body is invalid too. A push stops before any agent when no `pr` skill or no `pr-risk` skill is next to this skill, in `${CLAUDE_CONFIG_DIR:-~/.claude}/skills` or in `~/.agents/skills`. Without them it prints the two tips and the command to run again with `--push`.
|
|
161
|
+
6. **Push.** With `--push` or `--unattended`, the driver pushes the reviewed tip once, with no force, and opens the PR into the branch of step 2 with `gh`: as draft when a finding that an agent's ruling shipped is open or the full gate is red with only pre-existing failures, ready for review otherwise (the operator's own `accept` or `follow-up` keeps it ready), and the ledger says why. After a `ship-draft` ruling it pushes instead the branch tip that a full gate ran on, green or red, as draft; the review coverage of the body names the commits after the reviewed tip that no review covered. The ruling, the operator's or the driver's, records that tip and the stops once (`run.final.ship`), and the push reads only that record: a run stopped between the ruling and the push pushes the recorded tip, and refuses, pushing nothing, when the branch moved from it. Once the pr-writer's body is valid and before it opens the PR, it files each finding answered `follow-up` as an issue with `gh issue create`, and the PR body's rulings and `summary.md` link the issue. The issue body carries a marker of the run and the question; a run that stopped before it kept the URL finds the issue by that marker instead of filing it twice. A local run without `--push` files nothing. The **pr-writer** (`prompts/pr-writer.md`) writes the body with the method of the `pr` skill; the driver puts the facts of the run after it: the ticket-to-commit map, the fix commits, the rulings and the review coverage (`prompts/pr-body.md`). The body carries the merge-risk block of the `pr-risk` skill under `## Merge Danger`, above the facts; the driver validates it, runs the pr-writer once more with the errors when it is invalid, and blocks the run, opening no PR, when the second body is invalid too. A push stops before any agent when no `pr` skill or no `pr-risk` skill is next to this skill, in `${CLAUDE_CONFIG_DIR:-~/.claude}/skills` or in `~/.agents/skills`. Without them it prints the two tips and the command to run again with `--push`.
|
|
162
162
|
|
|
163
163
|
History rules:
|
|
164
164
|
|
|
165
165
|
- The branch is rewritten once, before the first review, and never after it. Fixes of the final review stay as `fix(NN)` commits.
|
|
166
166
|
- A history that `origin` already has is never rewritten. When `origin` has the PR branch or one of its commits, the driver does no tidy and no rebase. The full gate, the final review and a fast-forward push still run. The review range then starts at the merge-base of the branch and the base tip, so what the base gained since the branch left it is not shown as a change of the branch. A kept branch that shares no commit with the base stops the end of run.
|
|
167
|
-
- The push happens only when the branch tip is the reviewed tip and that tip has a green full gate record.
|
|
167
|
+
- The push happens only when the branch tip is the reviewed tip and that tip has a green full gate record, or a red one with only the failures of the base.
|
|
168
168
|
- With `commit.gpgsign` on, the driver signs every commit it makes (ticket merges, tidied and renamed commits) with the configured key. The push happens only when every commit that `origin` lacks has a good signature (`%G?` is `G`); otherwise the end of run is BLOCKED and nothing is pushed.
|
|
169
169
|
- No pushed commit has a `Co-authored-by` trailer. `claude` agents run with Claude Code's commit attribution off, every commit the driver makes (merges, tidied and renamed commits) drops the trailer, and the push is BLOCKED when a commit that `origin` lacks still has one, for example in a history that `origin` already has. Reword it, then run with `--push` again.
|
|
170
170
|
|
|
@@ -279,7 +279,7 @@ For an older questionless BLOCKED record, see [operator recovery](recovery.md).
|
|
|
279
279
|
|---|---|
|
|
280
280
|
| Demonstrated red plus green for locked tests | `driver_report.py` `_red_errors`: each red line of a test-writer report (and of a correction) must be in its log. `driver_gate.py` `run`, called from `driver_run.py` `Run.gate` and `driver_fixloop.py` `_gate`: the fast gate gets the ticket's locked files in `IMPLEMENT_SPEC_LOCKED` and must be green on the candidate before its review. |
|
|
281
281
|
| Locked files changed only by the test-writer | `driver_locked.py` `errors`, one diff check after the implementer, a fixer, the ticket conflict agent, the final fixer and the rebase conflict agent report (the baseline from `for_ticket`, or at the end of run `for_end_of_run`): the ticket's own locked files against its last test-writer commit, every other ticket's against the merge base of the branch and the PR tip, at the end of run every ticket's against the tidied tip (for the rebase conflict agent, the recovery point). A changed file rejects the report. `driver.py` `_refuse_breach` (with `driver_locked.py` `landing_errors`), under the merge lock: the commit that would land against every other ticket's locked files as the PR tip has it; a changed file blocks the ticket with one `ticket-blocked` question. `driver_locked.py` `_unlisted_errors`: a test-writer that changes another ticket's locked file must list it in `locked`, and the reviewer gets its diff (`prompts/elsewhere.md`) to judge against the spec. |
|
|
282
|
-
| The final full integration gate | `driver_final_gate.py` saves red evidence and
|
|
282
|
+
| The final full integration gate | `driver_final_gate.py` saves red evidence, bounds repair, and gates the base commit to tell a pre-existing failure from a new one. `driver_final.py` `_review_until_reviewed` runs the full gate after every ticket is integrated, tidied and rebased, and after each final fix batch, before reviewing that exact tip. |
|
|
283
283
|
| The ticket reviewer and the final correctness lens (and the scoped review) on another provider than the implementer | `models.json`: the `reviewer` list starts on another provider than the `implementer` list, which a `--models` file can change. `driver_agents.py` `other_provider_entries`: the correctness lens and the scoped review run and rerun on `final-reviewer` entries of another provider than the first `implementer` entry, when the lists have one. When the config has none, or the preflight finds none usable (a provider out of credits), `correctness_entries` falls back to the `final-reviewer` entries that are left, and the ledger says so. When the reviewer's other-provider entry is skipped, its next entry may share the implementer's provider. The PR body's Review coverage names the entries each review ran on and flags one on a provider that also wrote code. |
|
|
284
284
|
|
|
285
285
|
## Known limits
|
|
@@ -23,6 +23,9 @@ operator ships.
|
|
|
23
23
|
phase `blocked` at a stop with questions, until a `retry` answer makes it `pending` again
|
|
24
24
|
green_gates, pushed, pr
|
|
25
25
|
body the tip the pr-writer's part of the PR body was written for (driver_pr)
|
|
26
|
+
base_gate {commit, record}: the full gate on `onto`, run once when a red tip has failure lines; record "" if green
|
|
27
|
+
gate_preexisting {tip, record, base}: the tip whose red full gate fails exactly as the base does: it passes, and
|
|
28
|
+
the PR opens as a draft that names both records
|
|
26
29
|
draft the PR opened as draft
|
|
27
30
|
ship {tip, stops: [{subject, role}]} once a `ship-draft` answer settled (driver._settle): the gated tip
|
|
28
31
|
that the push ships as draft, None when no full gate ran on the branch tip, and the stops it names
|
|
@@ -391,7 +394,7 @@ def _review(run: Run, final: dict, tip: str) -> None:
|
|
|
391
394
|
the implementer's."""
|
|
392
395
|
done, folder = final["round"], OUT / FINAL
|
|
393
396
|
values = {**final_values(run), "start_sha": tip, "range": f"{final['reviewed'] or final['onto']}..{tip}",
|
|
394
|
-
"gate":
|
|
397
|
+
"gate": driver_final_gate.evidence(run, tip),
|
|
395
398
|
"ledger": str(OUT / "ledger.md"), "carried": _carried_findings(), "reviewed": str(final["reviewed"]),
|
|
396
399
|
"must_fix_list": "\n".join(f"- {driver_review.title(finding)}" for finding in final["must_fix"]),
|
|
397
400
|
"rulings": "\n".join(driver_decisions.rulings(run.state.read()["run"]["questions"])),
|
|
@@ -521,39 +524,39 @@ def _findings_list(run: Run, final: dict) -> str:
|
|
|
521
524
|
for finding in _to_fix(run, final["open"]))
|
|
522
525
|
|
|
523
526
|
|
|
524
|
-
def _fixer_values(run: Run, final: dict, tip: str,
|
|
527
|
+
def _fixer_values(run: Run, final: dict, tip: str, gate: driver_final_gate.Red | None) -> dict[str, str]:
|
|
525
528
|
"""The prompt values of the final fixer: the review findings, and the saved gate failure for a gate repair."""
|
|
526
529
|
folder = OUT / FINAL
|
|
527
530
|
values = {**final_values(run), "start_sha": tip, "findings": str(folder / f"findings-{final['round'] - 1}.json"),
|
|
528
531
|
"locked": " ".join(driver_locked.every(_shipped(run))),
|
|
529
532
|
"must_fix_list": "\n".join(f"- {driver_review.title(finding)}" for finding in final["must_fix"]),
|
|
530
533
|
"findings_list": _findings_list(run, final)}
|
|
531
|
-
return {**values, **(driver_final_gate.pointers(final,
|
|
534
|
+
return {**values, **(driver_final_gate.pointers(final, gate, tip) if gate else {})}
|
|
532
535
|
|
|
533
536
|
|
|
534
|
-
def _fixer_check(owners: list[str], final: dict, values: dict[str, str],
|
|
537
|
+
def _fixer_check(owners: list[str], final: dict, values: dict[str, str], gate: driver_final_gate.Red | None) -> dict:
|
|
535
538
|
"""What the final fixer's report is checked against: a commit of a merged ticket in `owners`, a gate repair that
|
|
536
539
|
fixes the gate, a review batch that fixes the must-fix findings."""
|
|
537
540
|
return {"owners": owners,
|
|
538
|
-
"must_fix": [] if
|
|
539
|
-
"fix": [values["gate_title"]] if
|
|
541
|
+
"must_fix": [] if gate else [driver_review.title(finding) for finding in final["must_fix"]],
|
|
542
|
+
"fix": [values["gate_title"]] if gate else []}
|
|
540
543
|
|
|
541
544
|
|
|
542
|
-
def _fixer_call(run: Run, final: dict, tip: str,
|
|
545
|
+
def _fixer_call(run: Run, final: dict, tip: str, gate: driver_final_gate.Red | None = None) -> Call:
|
|
543
546
|
"""Build a final fixer call from review findings or the saved integration-gate failure."""
|
|
544
|
-
values = _fixer_values(run, final, tip,
|
|
545
|
-
name = f"gate-fixer-{final['gate_repairs']}" if
|
|
547
|
+
values = _fixer_values(run, final, tip, gate)
|
|
548
|
+
name = f"gate-fixer-{final['gate_repairs']}" if gate else ""
|
|
546
549
|
baseline = final["locked"] or final["tidied"]
|
|
547
|
-
return Call("fixer", FINAL, ".", values, template="final-gate-fixer" if
|
|
550
|
+
return Call("fixer", FINAL, ".", values, template="final-gate-fixer" if gate else "final-fixer",
|
|
548
551
|
fix_round=final["round"], name=name,
|
|
549
|
-
check=_fixer_check(list(_shipped(run)), final, values,
|
|
552
|
+
check=_fixer_check(list(_shipped(run)), final, values, gate),
|
|
550
553
|
locked=lambda _: driver_locked.for_end_of_run(_shipped(run), baseline))
|
|
551
554
|
|
|
552
555
|
|
|
553
|
-
def _run_fixer(run: Run, final: dict, tip: str,
|
|
556
|
+
def _run_fixer(run: Run, final: dict, tip: str, gate: driver_final_gate.Red | None = None) -> dict:
|
|
554
557
|
"""Run the fixer on the PR branch in slot 1 and return its report. A rejected batch is undone."""
|
|
555
558
|
try:
|
|
556
|
-
return run.agent(_fixer_call(run, final, tip,
|
|
559
|
+
return run.agent(_fixer_call(run, final, tip, gate))
|
|
557
560
|
except Blocked as blocked:
|
|
558
561
|
raise Blocked(f"{blocked}{_undo_rejected_batch(run, tip)}") from None
|
|
559
562
|
except Halted as halted:
|
|
@@ -574,16 +577,16 @@ def _name_batch(run: Run, tip: str, report: dict) -> list[str]:
|
|
|
574
577
|
return named
|
|
575
578
|
|
|
576
579
|
|
|
577
|
-
def _fix_batch(run: Run, final: dict, tip: str,
|
|
580
|
+
def _fix_batch(run: Run, final: dict, tip: str, gate: driver_final_gate.Red | None = None) -> None:
|
|
578
581
|
"""Run one bounded batch and settle its attributed tip before the next full gate."""
|
|
579
582
|
with during("the fix batch"):
|
|
580
|
-
report = _run_fixer(run, final, tip,
|
|
583
|
+
report = _run_fixer(run, final, tip, gate)
|
|
581
584
|
named = _name_batch(run, tip, report)
|
|
582
585
|
fields = dict(open=[], batch=named[-1] if named else tip)
|
|
583
|
-
if
|
|
586
|
+
if gate:
|
|
584
587
|
fields.update(gate_repairs=final["gate_repairs"] + 1, gate_failure=None)
|
|
585
588
|
run.state.update(lambda state: state["run"]["final"].update(fields))
|
|
586
|
-
_led_batch("integration gate" if
|
|
589
|
+
_led_batch("integration gate" if gate else "final review", tip, named)
|
|
587
590
|
|
|
588
591
|
|
|
589
592
|
def _led_batch(label: str, tip: str, named: list[str]) -> None:
|
|
@@ -603,8 +606,8 @@ def _review_until_reviewed(run: Run) -> None:
|
|
|
603
606
|
if final["reviewed"] != tip:
|
|
604
607
|
_check_review_is_due(run, final, tip)
|
|
605
608
|
with during("the integration gate"):
|
|
606
|
-
if
|
|
607
|
-
_fix_batch(run, final, tip,
|
|
609
|
+
if red := driver_final_gate.failure(run, tip):
|
|
610
|
+
_fix_batch(run, final, tip, red)
|
|
608
611
|
continue
|
|
609
612
|
_review(run, final, tip)
|
|
610
613
|
elif _to_fix(run, final["open"]): # after the full review, or after a `retry` of a finding left open
|
|
@@ -701,7 +704,7 @@ def _require_pushable(run: Run, tip: str) -> None:
|
|
|
701
704
|
def _gated(final: dict, tip: str) -> str:
|
|
702
705
|
"""`tip` when a full gate ran on it, green or red; "" otherwise."""
|
|
703
706
|
red = (final["gate_failure"] or {}).get("tip") == tip
|
|
704
|
-
return tip if red or tip
|
|
707
|
+
return tip if red or driver_final_gate.passed(final, tip) else ""
|
|
705
708
|
|
|
706
709
|
|
|
707
710
|
def _must_fix_open(run: Run, final: dict) -> bool:
|
|
@@ -772,7 +775,7 @@ def _pushable_tip(run: Run, final: dict) -> str:
|
|
|
772
775
|
if final["ship"]:
|
|
773
776
|
return _shipped_tip(run, final["ship"])
|
|
774
777
|
tip = final["reviewed"]
|
|
775
|
-
if tip != run.tip() or
|
|
778
|
+
if tip != run.tip() or not driver_final_gate.passed(final, tip):
|
|
776
779
|
raise Blocked(f"the reviewed tip {str(tip)[:7]} is not the tip of {run.pr} with a green full gate record: "
|
|
777
780
|
"nothing is pushed")
|
|
778
781
|
return tip
|
|
@@ -2,40 +2,175 @@
|
|
|
2
2
|
|
|
3
3
|
A red record is durable before repair starts. Interrupted repair resumes from it;
|
|
4
4
|
only an accepted batch spends the allowance. Ticket fix budgets never change.
|
|
5
|
+
|
|
6
|
+
A red tip that fails exactly as the base commit (`run.final.onto`) does is not the change's to repair: it passes for
|
|
7
|
+
the run, which goes on to review, and the PR opens as a draft that names both records (`run.final.gate_preexisting`):
|
|
8
|
+
a match of failure lines is a heuristic, not a proof. The full gate runs on the base once per base commit
|
|
9
|
+
(`run.final.base_gate`), in driver_slots.BASE_SLOT, so slot 1 keeps the tip. A failure is a line of the gate output
|
|
10
|
+
that names a failure, an error or an exception (`AssertionError`), but a wrapper's line (`make: ***`, `npm ERR!`,
|
|
11
|
+
`exit code 2`), with times, `:line:col` and the counts of the tests that passed masked; a count of failures, an
|
|
12
|
+
identifier and any other value stay. The tip's failures are old only when both gates judged their commit (a complete
|
|
13
|
+
run with an exit under 128, so not a signal's, on a tree clean after it) and the two have the same failure lines, as
|
|
14
|
+
often. Anything unproven is new.
|
|
5
15
|
"""
|
|
6
16
|
from __future__ import annotations
|
|
7
17
|
|
|
8
18
|
import json
|
|
19
|
+
import re
|
|
20
|
+
from collections import Counter
|
|
21
|
+
from typing import NamedTuple
|
|
9
22
|
|
|
10
23
|
import driver_gate
|
|
11
|
-
|
|
24
|
+
import driver_slots
|
|
25
|
+
from driver_run import FINAL, FINAL_RESUME, OUT, Blocked, Run, ledger
|
|
12
26
|
|
|
13
27
|
RETRY_SUBJECT = 'the full integration gate remains red after its repair'
|
|
28
|
+
# A line that names a failure; `1) Suite does x:` is the title of a failed test in mocha's list.
|
|
29
|
+
_FAILURE = re.compile(r'\b(?:fail(?:ed|ures?|s|ing)?|errors?)\b|(?-i:[a-z]Error)\b|[✗×✖●]|^\d+\) \S', re.I)
|
|
30
|
+
# The line a wrapper prints for any red command it ran: it names no failure of its own.
|
|
31
|
+
_WRAPPER = re.compile(r'^(?:make(?:\[\d+\])?: \*\*\*|npm (?:ERR!|error)|ERR_PNPM_|ELIFECYCLE)'
|
|
32
|
+
r'|\bexit(?:ed)? (?:with )?(?:code|status) -?\d+', re.I)
|
|
33
|
+
# What differs between two runs of the same failures: a time, a :line:col, the count of the tests that did not
|
|
34
|
+
# fail, the place of a failed test in mocha's list. Never a count of failures, nor a number inside an identifier:
|
|
35
|
+
# test_limit[1] keeps its 1.
|
|
36
|
+
_MASKS = ((re.compile(r'(?<![\w.\[-])\d+(?:\.\d+)?m?s(?![\w\]])'), 'Ns'),
|
|
37
|
+
(re.compile(r'(?<=\S):\d+:\d+(?=[\s:]|$)'), ':N:N'),
|
|
38
|
+
(re.compile(r'(?<![\w.\[-])\d+(?= (?:passed|passing|skipped|pending|tests?)\b)', re.I), 'N'),
|
|
39
|
+
(re.compile(r'^\d+\) '), 'N) '))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Red(NamedTuple):
|
|
43
|
+
"""A red full gate to repair: its record, and the red record of the base, "" when the base is not red with it."""
|
|
44
|
+
record: str
|
|
45
|
+
base: str = ''
|
|
14
46
|
|
|
15
47
|
|
|
16
|
-
def failure(run: Run, tip: str) ->
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
|
|
48
|
+
def failure(run: Run, tip: str) -> Red | None:
|
|
49
|
+
"""The red full gate of `tip` to repair, or None when it passed; at the repair cap it parks instead."""
|
|
50
|
+
final = run.state.read()['run']['final']
|
|
51
|
+
red = _red(run, final, tip)
|
|
52
|
+
if not red or _old(run, tip, red):
|
|
53
|
+
return None
|
|
54
|
+
run.state.update(lambda s: s['run']['final'].update(gate_failure=dict(tip=tip, record=red.record)))
|
|
55
|
+
if final['gate_repairs'] >= final['gate_allowance']:
|
|
56
|
+
subject = f'{RETRY_SUBJECT}: {tip[:7]}; read {red.record}'
|
|
57
|
+
run.ask(FINAL, [('ticket-blocked', subject)], red.record, FINAL_RESUME._replace(
|
|
58
|
+
gate_allowance=final['gate_repairs'] + 1))
|
|
59
|
+
raise Blocked(subject)
|
|
60
|
+
return red
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _red(run: Run, final: dict, tip: str) -> Red | None:
|
|
64
|
+
"""The red full gate on `tip`, saved or run now, with the record of the base when the tip's failures need it."""
|
|
65
|
+
if passed(final, tip):
|
|
66
|
+
return None
|
|
20
67
|
pending = final['gate_failure']
|
|
21
68
|
record = (pending['record'] if pending and pending['tip'] == tip
|
|
22
69
|
else run.red_gate(FINAL, '.', tip, driver_gate.FULL))
|
|
23
70
|
if not record:
|
|
71
|
+
return None
|
|
72
|
+
return Red(record, _base_record(run, final['onto']) if _judged(record) else '')
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def failures(output: str) -> Counter:
|
|
76
|
+
"""The failure lines of a gate's output, but a wrapper's, with what differs between runs masked."""
|
|
77
|
+
lines = (line.strip() for line in output.splitlines())
|
|
78
|
+
return Counter(_mask(line) for line in lines if _FAILURE.search(line) and not _WRAPPER.search(line))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _mask(line: str) -> str:
|
|
82
|
+
for pattern, mask in _MASKS:
|
|
83
|
+
line = pattern.sub(mask, line)
|
|
84
|
+
return line
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _judged(record: str) -> Counter:
|
|
88
|
+
"""The failures of a red gate record that judged its commit: a complete run, not ended by a signal, on a tree
|
|
89
|
+
clean after it. No failure for any other record, which proves nothing. An exit from 128 up may be a signal's, as
|
|
90
|
+
a shell reports a crashed child (139 for SIGSEGV), so it judged nothing either."""
|
|
91
|
+
output, code, after = driver_gate.read(record)
|
|
92
|
+
if not (isinstance(code, int) and 0 < code < 128 and after == 'clean'):
|
|
93
|
+
return Counter()
|
|
94
|
+
return failures(output)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def only_old(record: str, base: str) -> bool:
|
|
98
|
+
"""The red gate `record` fails exactly as the red gate `base`: both judged their commit, with the same failure
|
|
99
|
+
lines, as often."""
|
|
100
|
+
found = _judged(record)
|
|
101
|
+
return bool(found) and found == _judged(base)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _old(run: Run, tip: str, red: Red) -> bool:
|
|
105
|
+
"""True, recorded and in the ledger, when the red gate of `tip` fails exactly as the gate of its base."""
|
|
106
|
+
if not (red.base and only_old(red.record, red.base)):
|
|
107
|
+
return False
|
|
108
|
+
final = run.state.update(lambda s: s['run']['final'].update(
|
|
109
|
+
gate_failure=None, gate_preexisting=dict(tip=tip, record=red.record, base=red.base)))['run']['final']
|
|
110
|
+
ledger(f"End of run: {preexisting(final, tip)}, so the run goes on and the PR opens as a draft.")
|
|
111
|
+
return True
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def preexisting(final: dict, tip: str) -> str:
|
|
115
|
+
"""The sentence of the full gate on `tip` that is red only as its base is; "" when it is not."""
|
|
116
|
+
old = final['gate_preexisting']
|
|
117
|
+
if not (old and old['tip'] == tip):
|
|
24
118
|
return ''
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
119
|
+
return (f"the full gate is red on {tip[:7]} only with failures that its base {final['onto'][:7]} is red with "
|
|
120
|
+
f"too: read {old['record']} and {old['base']}")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def passed(final: dict, tip: str) -> bool:
|
|
124
|
+
"""The full gate on `tip` is green, or red only as its base is."""
|
|
125
|
+
return tip in final['green_gates'][driver_gate.FULL] or bool(preexisting(final, tip))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def evidence(run: Run, tip: str) -> str:
|
|
129
|
+
"""The full gate evidence of `tip` for an agent: its record, and the sentence of its failures the base has too."""
|
|
130
|
+
record = str(driver_gate.record_path(OUT / FINAL, driver_gate.FULL, tip))
|
|
131
|
+
old = preexisting(run.state.read()['run']['final'], tip)
|
|
132
|
+
return f"{record} ({old}: they are not this change's to fix)" if old else record
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _base_record(run: Run, onto: str) -> str:
|
|
136
|
+
"""The record of the full gate on the base commit `onto` when it is red, "" when it is green or cannot run. It
|
|
137
|
+
runs once per base commit."""
|
|
138
|
+
cached = run.state.read()['run']['final']['base_gate']
|
|
139
|
+
if cached and cached['commit'] == onto:
|
|
140
|
+
return cached['record']
|
|
141
|
+
slot = driver_slots.BASE_SLOT
|
|
142
|
+
if error := (driver_slots.make(slot, 'the base slot', run.args.prepare, start=onto)
|
|
143
|
+
or driver_slots.git(slot, 'checkout', '-q', '--detach', onto).stderr.strip()):
|
|
144
|
+
ledger(f'End of run: the full gate cannot run on the base {onto[:7]}, so each failure counts as new: {error}.')
|
|
145
|
+
return ''
|
|
146
|
+
return _run_base_gate(run, slot, onto)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _run_base_gate(run: Run, slot: str, onto: str) -> str:
|
|
150
|
+
"""Run the full gate on `onto` in `slot` and keep its result. Returns its record when it is red."""
|
|
151
|
+
green, record, killed = driver_gate.run(run.args.gate, driver_gate.FULL, slot, OUT / FINAL / 'base', run.pr, [])
|
|
152
|
+
for sentence in killed:
|
|
153
|
+
ledger(f'End of run: {sentence}.')
|
|
154
|
+
kept = '' if green else str(record)
|
|
155
|
+
|
|
156
|
+
def keep(state: dict) -> None:
|
|
157
|
+
state['run']['gates'][driver_gate.FULL] += 1
|
|
158
|
+
state['run']['final']['base_gate'] = dict(commit=onto, record=kept)
|
|
159
|
+
|
|
160
|
+
run.state.update(keep)
|
|
161
|
+
ledger(f"End of run: the full gate is {'green' if green else 'red'} on the base {onto[:7]}, record {record}.")
|
|
162
|
+
return kept
|
|
32
163
|
|
|
33
164
|
|
|
34
|
-
def pointers(final: dict,
|
|
35
|
-
"""Keep gate-repair evidence separate from review findings and reports.
|
|
36
|
-
|
|
165
|
+
def pointers(final: dict, red: Red, tip: str) -> dict[str, str]:
|
|
166
|
+
"""Keep gate-repair evidence separate from review findings and reports. When the base is red too, the evidence
|
|
167
|
+
names its record: a failure in it is not this change's to repair."""
|
|
168
|
+
also = f"; the base {final['onto'][:7]} is red too, read {red.base}: its failures are not this change's" * bool(
|
|
169
|
+
red.base)
|
|
170
|
+
finding = dict(severity='critical', kind='code', source='gate', file=red.record, line=0,
|
|
37
171
|
title=f'the full integration gate is red on {tip[:7]}',
|
|
38
|
-
evidence=f'Read the exact failure log: {record}')
|
|
172
|
+
evidence=f'Read the exact failure log: {red.record}{also}')
|
|
39
173
|
path = OUT / FINAL / f"gate-findings-{final['gate_repairs']}.json"
|
|
40
174
|
path.write_text(json.dumps([finding], indent=1) + '\n')
|
|
41
|
-
return dict(gate_title=finding["title"], findings=str(path),
|
|
175
|
+
return dict(gate_title=finding["title"], findings=str(path),
|
|
176
|
+
findings_list=f"- critical: {finding['title']}; read {red.record}{also}")
|
|
@@ -70,6 +70,18 @@ def _attempt(command: str, tier: str, slot: str, commit: str, record: Path, env:
|
|
|
70
70
|
return code, after
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
def read(record: str | Path) -> tuple[str, int | str, str]:
|
|
74
|
+
"""(the command's output, its exit code or "not run", what it left behind) of a record that _attempt wrote. A
|
|
75
|
+
record with no end, as a driver stopped mid-command leaves it, has the exit "" and the after "": it judged
|
|
76
|
+
nothing."""
|
|
77
|
+
rest = Path(record).read_text(errors="replace").partition("\n\n")[2]
|
|
78
|
+
output, ended, tail = rest.rpartition("\nexit: ")
|
|
79
|
+
if not (ended and "\nend: " in tail):
|
|
80
|
+
return rest, "", ""
|
|
81
|
+
code, _, after = tail.rpartition("\nend: ")[0].partition("\nafter: ")
|
|
82
|
+
return output, int(code) if code.lstrip("-").isdigit() else code, after
|
|
83
|
+
|
|
84
|
+
|
|
73
85
|
def run(command: str, tier: str, slot: str, folder: Path, pr_branch: str,
|
|
74
86
|
locked: list[str]) -> tuple[bool, Path, list[str]]:
|
|
75
87
|
"""Gate the HEAD of `slot` on `tier`, the fast gate on the `locked` files. Returns (green, the record, a ledger
|
|
@@ -12,7 +12,7 @@ from pathlib import Path
|
|
|
12
12
|
|
|
13
13
|
import driver_agents
|
|
14
14
|
import driver_decisions
|
|
15
|
-
import
|
|
15
|
+
import driver_final_gate
|
|
16
16
|
from driver_review import title
|
|
17
17
|
from driver_run import FINAL, OUT, Blocked, Call, Run, during, final_values, ledger
|
|
18
18
|
from driver_slots import git
|
|
@@ -88,10 +88,16 @@ def _facts(run: Run, final: dict, tickets: list[Ticket], tip: str) -> str:
|
|
|
88
88
|
return driver_agents.render("pr-body", {
|
|
89
89
|
"map": _ticket_map(final, titles, left_out(run)),
|
|
90
90
|
"fixes": fixes or "None.", "rulings": "\n".join(f"- {ruling}" for ruling in rulings) or "None.",
|
|
91
|
-
**_coverage(final, tip),
|
|
91
|
+
**_coverage(final, tip), "gate": _old_failures(final, tip),
|
|
92
92
|
"providers": _review_providers(run.state.read()["run"]["agents"])})
|
|
93
93
|
|
|
94
94
|
|
|
95
|
+
def _old_failures(final: dict, tip: str) -> str:
|
|
96
|
+
"""The body's line on the failures of the full gate on the pushed tip `tip` that its base has too; "" for none."""
|
|
97
|
+
old = driver_final_gate.preexisting(final, tip)
|
|
98
|
+
return f"- Pre-existing failures: {old}" if old else ""
|
|
99
|
+
|
|
100
|
+
|
|
95
101
|
# The roles that review code, with their line in the PR body, and the roles that write it.
|
|
96
102
|
_REVIEWS = {"reviewer": "Ticket reviews", "final-correctness": "Correctness lens", "final-reviewer": "Scoped review"}
|
|
97
103
|
_AUTHORS = ("implementer", "fixer", "conflict")
|
|
@@ -150,7 +156,7 @@ def _writer_body(run: Run, final: dict, tickets: list[Ticket], tip: str) -> str:
|
|
|
150
156
|
return kept
|
|
151
157
|
method, risk = _body_skills()
|
|
152
158
|
values = {**final_values(run), "start_sha": tip, "range": f"{final['onto']}..{tip}",
|
|
153
|
-
"gate":
|
|
159
|
+
"gate": driver_final_gate.evidence(run, tip), "pr_skill": str(method),
|
|
154
160
|
"pr_risk_skill": str(risk), "risk_errors": "", "facts": _facts(run, final, tickets, tip)}
|
|
155
161
|
WRITER.write_text(_run_pr_writer(run, tip, risk, values).strip() + "\n")
|
|
156
162
|
run.state.update(lambda state: state["run"]["final"].update(body=tip))
|
|
@@ -179,9 +185,10 @@ def _gh(argv: list[str], what: str) -> str:
|
|
|
179
185
|
return (made.stdout.split() or [""])[-1]
|
|
180
186
|
|
|
181
187
|
|
|
182
|
-
def _draft(final: dict, questions: list[dict], left: list[str]) -> str:
|
|
183
|
-
"""Why the PR opens as draft; "" for a PR ready for review: the end-of-run stops that a `ship-draft` ruling
|
|
184
|
-
with, the tickets `left` out,
|
|
188
|
+
def _draft(final: dict, questions: list[dict], left: list[str], tip: str) -> str:
|
|
189
|
+
"""Why the PR of `tip` opens as draft; "" for a PR ready for review: the end-of-run stops that a `ship-draft` ruling
|
|
190
|
+
ships with, the tickets `left` out, the findings still open that the draft or an agent's ruling ships, and a full
|
|
191
|
+
gate red only as its base is, which a match of failure lines does not prove (driver_final_gate)."""
|
|
185
192
|
reasons = []
|
|
186
193
|
if final["ship"]:
|
|
187
194
|
reasons.append(f"the end of run stopped: {'; '.join(stop['subject'] for stop in final['ship']['stops'])}")
|
|
@@ -189,6 +196,8 @@ def _draft(final: dict, questions: list[dict], left: list[str]) -> str:
|
|
|
189
196
|
reasons.append(f"tickets are left out of the run: {', '.join(left)}")
|
|
190
197
|
if shipped := _shipped_open(final, questions):
|
|
191
198
|
reasons.append(f"a finding ships open: {'; '.join(shipped)}")
|
|
199
|
+
if preexisting := driver_final_gate.preexisting(final, tip):
|
|
200
|
+
reasons.append(preexisting)
|
|
192
201
|
return "; ".join(reasons)
|
|
193
202
|
|
|
194
203
|
|
|
@@ -232,7 +241,7 @@ def _body(run: Run, final: dict, tickets: list[Ticket], tip: str) -> str:
|
|
|
232
241
|
def _open(run: Run, final: dict, tickets: list[Ticket], tip: str) -> str:
|
|
233
242
|
"""Open the PR of the pushed tip `tip`, ready for review or as draft, and return its URL."""
|
|
234
243
|
BODY.write_text(_body(run, final, tickets, tip))
|
|
235
|
-
draft = _draft(final, run.state.read()["run"]["questions"], left_out(run))
|
|
244
|
+
draft = _draft(final, run.state.read()["run"]["questions"], left_out(run), tip)
|
|
236
245
|
url = _gh(["pr", "create", "--base", final["base"], "--head", run.pr, "--title", _name(run), "--body-file",
|
|
237
246
|
str(BODY), *["--draft"] * bool(draft)], "pr create")
|
|
238
247
|
run.state.update(lambda state: state["run"]["final"].update(pr=url, draft=bool(draft)))
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""Slots: the worktrees agents run in. Slot 1 is the PR worktree, slots 2..N live under .agent/worktrees
|
|
1
|
+
"""Slots: the worktrees agents run in. Slot 1 is the PR worktree, slots 2..N live under .agent/worktrees/, and so
|
|
2
|
+
does BASE_SLOT, of the end of run's full gate on the base commit (driver_final_gate).
|
|
2
3
|
|
|
3
4
|
Every path is relative to the PR worktree, which is the driver's working directory for the whole run.
|
|
4
5
|
"""
|
|
@@ -55,6 +56,9 @@ def path(number: int) -> str:
|
|
|
55
56
|
return "." if number == 1 else f".agent/worktrees/slot-{number}"
|
|
56
57
|
|
|
57
58
|
|
|
59
|
+
BASE_SLOT = ".agent/worktrees/slot-base" # the end of run's full gate on the base commit (driver_final_gate)
|
|
60
|
+
|
|
61
|
+
|
|
58
62
|
def _owned_checkout(slot: str) -> bool:
|
|
59
63
|
"""An existing slot must be this repository's checkout at exactly the assigned path."""
|
|
60
64
|
common = git(slot, "rev-parse", "--path-format=absolute", "--git-common-dir")
|
|
@@ -68,25 +72,38 @@ def _owned_checkout(slot: str) -> bool:
|
|
|
68
72
|
|
|
69
73
|
def create(number: int, prepare: str | None, keep: bool = False, *, start: str = "HEAD") -> str:
|
|
70
74
|
"""Make and prepare slot 2..N once, or reuse it off any branch (`keep`: as it is). Returns "" or the error."""
|
|
71
|
-
|
|
75
|
+
return make(path(number), f"slot {number}", prepare, keep, start=start)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def make(slot: str, name: str, prepare: str | None, keep: bool = False, *, start: str = "HEAD") -> str:
|
|
79
|
+
"""Make and prepare the worktree `slot` once, or reuse it off any branch (`keep`: as it is). Returns "" or the
|
|
80
|
+
error, which starts with `name`."""
|
|
72
81
|
if Path(slot, ".git").exists():
|
|
73
|
-
|
|
74
|
-
return f"slot {number}: {slot} is not a healthy checkout of this repository; inspect it before retrying"
|
|
75
|
-
if not (keep or release(slot)):
|
|
76
|
-
return f"slot {number}: {slot} could not be released: inspect its Git state and uncommitted changes"
|
|
77
|
-
return ""
|
|
82
|
+
return _reuse(name, slot, keep)
|
|
78
83
|
# One force recovers this missing slot registration only; a locked registration still fails.
|
|
79
84
|
# Never prune: another session may mount the shared metadata without its sibling checkouts.
|
|
80
85
|
added = git(".", "worktree", "add", "-q", "--force", "--detach", slot, start)
|
|
81
86
|
if added.returncode:
|
|
82
|
-
return f"
|
|
83
|
-
if
|
|
84
|
-
|
|
87
|
+
return f"{name}: cannot create {slot}: {added.stderr.strip()}"
|
|
88
|
+
return _prepare(name, slot, prepare) if prepare else ""
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _reuse(name: str, slot: str, keep: bool) -> str:
|
|
92
|
+
""""" when the existing `slot` is this repository's and, unless `keep`, off any branch; else the error."""
|
|
93
|
+
if not _owned_checkout(slot):
|
|
94
|
+
return f"{name}: {slot} is not a healthy checkout of this repository; inspect it before retrying"
|
|
95
|
+
if not (keep or release(slot)):
|
|
96
|
+
return f"{name}: {slot} could not be released: inspect its Git state and uncommitted changes"
|
|
97
|
+
return ""
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _prepare(name: str, slot: str, prepare: str) -> str:
|
|
101
|
+
"""Run `prepare` in the new `slot`; on a failure remove the slot and return the error."""
|
|
85
102
|
done = subprocess.run(prepare, shell=True, cwd=slot, capture_output=True, text=True, stdin=subprocess.DEVNULL)
|
|
86
103
|
if done.returncode:
|
|
87
104
|
# An unprepared slot must not look ready to the next run.
|
|
88
105
|
git(".", "worktree", "remove", "--force", slot)
|
|
89
|
-
return (f"
|
|
106
|
+
return (f"{name}: --prepare `{prepare}` exited {done.returncode} in {slot}: "
|
|
90
107
|
f"{(done.stderr or done.stdout).strip()}")
|
|
91
108
|
return ""
|
|
92
109
|
|
|
@@ -47,8 +47,9 @@ def _final() -> dict:
|
|
|
47
47
|
"""The end-of-run record before it starts. Every key is here, so a reader uses [] and a wrong name fails."""
|
|
48
48
|
return {"skipped": "", "phase": "pending", "recovery": None, "tidied": None, "onto": None, "base": None,
|
|
49
49
|
"commits": {}, "reviewed": None, "round": 0, "open": [], "must_fix": [], "lenses": {}, "batch": None,
|
|
50
|
-
"locked": None, "gate_repairs": 0, "gate_allowance": 1, "gate_failure": None, "
|
|
51
|
-
"pushed": None, "body": None, "pr": None, "draft": False,
|
|
50
|
+
"locked": None, "gate_repairs": 0, "gate_allowance": 1, "gate_failure": None, "base_gate": None,
|
|
51
|
+
"gate_preexisting": None, "green_gates": tiers(), "pushed": None, "body": None, "pr": None, "draft": False,
|
|
52
|
+
"ship": None}
|
|
52
53
|
|
|
53
54
|
|
|
54
55
|
class State:
|