@jesdi/skills 0.0.77 → 0.0.78
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/README.md +3 -2
- package/package.json +1 -1
- package/skills/implement-spec/ARCHITECTURE.md +102 -54
- package/skills/implement-spec/README.md +53 -51
- package/skills/implement-spec/SKILL.md +5 -6
- package/skills/implement-spec/driver.py +67 -153
- package/skills/implement-spec/driver_agents.py +75 -25
- package/skills/implement-spec/driver_decisions.py +92 -199
- package/skills/implement-spec/driver_dispute.py +189 -0
- package/skills/implement-spec/driver_final.py +196 -97
- package/skills/implement-spec/driver_fixloop.py +102 -192
- package/skills/implement-spec/driver_legacy.py +73 -5
- package/skills/implement-spec/driver_locked.py +186 -0
- package/skills/implement-spec/driver_merge.py +3 -48
- package/skills/implement-spec/driver_report.py +84 -64
- package/skills/implement-spec/driver_review.py +12 -119
- package/skills/implement-spec/driver_run.py +167 -130
- package/skills/implement-spec/driver_state.py +11 -9
- package/skills/implement-spec/models.json +0 -2
- package/skills/implement-spec/prompts/arbitration.md +34 -0
- package/skills/implement-spec/prompts/conflict.md +1 -0
- package/skills/implement-spec/prompts/correction.md +7 -4
- package/skills/implement-spec/prompts/elsewhere.md +6 -0
- package/skills/implement-spec/prompts/final-fixer.md +1 -1
- package/skills/implement-spec/prompts/final-lens.md +40 -0
- package/skills/implement-spec/prompts/final-reviewer.md +7 -7
- package/skills/implement-spec/prompts/fixer.md +2 -2
- package/skills/implement-spec/prompts/implementer.md +1 -1
- package/skills/implement-spec/prompts/lens-copy.md +1 -0
- package/skills/implement-spec/prompts/lens-correctness.md +8 -0
- package/skills/implement-spec/prompts/lens-spec.md +2 -0
- package/skills/implement-spec/prompts/lens-structure.md +2 -0
- package/skills/implement-spec/prompts/rebase-conflict.md +1 -0
- package/skills/implement-spec/prompts/rereview.md +0 -1
- package/skills/implement-spec/prompts/rerun.md +1 -1
- package/skills/implement-spec/prompts/reviewer.md +3 -6
- package/skills/implement-spec/prompts/ruled.md +3 -0
- package/skills/implement-spec/prompts/test-writer.md +4 -5
- package/skills/implement-spec/tests/test_agents.py +23 -22
- package/skills/implement-spec/tests/test_amendments.py +6 -48
- package/skills/implement-spec/tests/test_arbitration.py +314 -0
- package/skills/implement-spec/tests/test_cli.py +3 -3
- package/skills/implement-spec/tests/test_decisions.py +251 -374
- package/skills/implement-spec/tests/test_driver.py +22 -50
- package/skills/implement-spec/tests/test_final.py +45 -77
- package/skills/implement-spec/tests/test_fixloop.py +400 -633
- package/skills/implement-spec/tests/test_landing.py +23 -126
- package/skills/implement-spec/tests/test_lenses.py +217 -0
- package/skills/implement-spec/tests/test_merge.py +0 -43
- package/skills/implement-spec/tests/test_models.py +50 -1
- package/skills/implement-spec/tests/test_report.py +9 -23
- package/skills/implement-spec/tests/test_review.py +15 -153
- package/skills/implement-spec/tests/test_review_page.py +7 -3
- package/skills/implement-spec/tests/test_scoped.py +125 -0
- package/skills/implement-spec/tests/test_state.py +8 -3
- package/skills/implement-spec/tests/test_stops.py +43 -61
- package/skills/implement-spec/tests/test_tidy.py +77 -98
- package/skills/implement-spec/tests/test_walk.py +7 -6
- package/skills/review-page/SKILL.md +1 -1
- package/skills/to-tickets/SKILL.md +1 -1
- package/skills-manifest.json +7 -7
- package/skills/implement-spec/prompts/corrected.md +0 -3
- package/skills/implement-spec/prompts/correctness.md +0 -42
- package/skills/implement-spec/prompts/final-scoped.md +0 -1
- package/skills/implement-spec/prompts/full-review.md +0 -2
- package/skills/implement-spec/prompts/overruled.md +0 -7
- package/skills/implement-spec/prompts/rejected.md +0 -1
- package/skills/implement-spec/prompts/restored-red.md +0 -3
- package/skills/implement-spec/prompts/restored.md +0 -3
- package/skills/implement-spec/prompts/stands.md +0 -2
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""The one locked-file rule: only the test-writer changes a locked file. Which files are locked, the baseline each
|
|
2
|
+
agent is checked against, and the git diff that finds a change. A check returns errors.
|
|
3
|
+
|
|
4
|
+
a ticket test-writer each locked file of another ticket that it changes is in its `locked`
|
|
5
|
+
the implementer, a fixer the ticket's own locked files as its last test-writer commit left them, or their clean
|
|
6
|
+
and the conflict agent three-way merge with the PR tip; every other ticket's as the merge base of the branch
|
|
7
|
+
of a ticket and the PR tip has them, or as the PR tip has them
|
|
8
|
+
the final fixer every ticket's locked files as the tidied tip has them
|
|
9
|
+
the rebase conflict agent every ticket's locked files as the recovery point has them
|
|
10
|
+
the landing every other ticket's locked files, but those the ticket lists, as the PR tip has them
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import subprocess
|
|
15
|
+
import tempfile
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import NamedTuple
|
|
18
|
+
|
|
19
|
+
from driver_slots import git, names
|
|
20
|
+
|
|
21
|
+
_CHECKED = ("implementer", "fixer", "conflict") # the ticket agents whose commits may not change a locked file
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def every(tickets: dict) -> list[str]:
|
|
25
|
+
"""The locked files of each ticket whose test-writer has run, merged or not. `tickets` is that of state.json."""
|
|
26
|
+
return sorted({path for entry in tickets.values() if entry["test_writer_sha"] for path in entry["locked"]})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def others(tickets: dict, number: str) -> list[str]:
|
|
30
|
+
"""`every` locked file but those of ticket `number`."""
|
|
31
|
+
return every({key: entry for key, entry in tickets.items() if key != number})
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def written(entry: dict, listed: list[str], tip: str) -> dict:
|
|
35
|
+
"""The locked-file fields of the ticket record after a test-writer commit at `tip` that lists `listed`: `tip` is
|
|
36
|
+
the new baseline of the ticket's own locked files."""
|
|
37
|
+
return {"test_writer_sha": tip, "locked": list(dict.fromkeys(entry["locked"] + listed))}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def changed_elsewhere(slot: str, pr: str, paths: list[str]) -> str:
|
|
41
|
+
"""The diff of each of `paths` that the ticket branch in `slot` changed since its merge base with `pr`."""
|
|
42
|
+
if not paths:
|
|
43
|
+
return ""
|
|
44
|
+
base = git(slot, "merge-base", "HEAD", pr).stdout.strip() or pr
|
|
45
|
+
return git(slot, "diff", base, "HEAD", "--", *paths).stdout
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Locked(NamedTuple):
|
|
49
|
+
"""The locked files that the commits of an agent are checked on, read when the agent ends."""
|
|
50
|
+
others: list[str] # locked files of other tickets: as the merge base with `pr` has them, or as `pr` has them
|
|
51
|
+
pr: str # the PR tip, which holds what landed
|
|
52
|
+
own: list[str] = [] # the files the agent may not change from `since`
|
|
53
|
+
since: str | None = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def for_ticket(tickets: dict, role: str, number: str, pr: str) -> Locked | None:
|
|
57
|
+
"""The check of a ticket agent with the PR tip `pr`: the locked files of the other tickets for a test-writer, and
|
|
58
|
+
the ticket's own too for a role that may not change one; None for a role with no check."""
|
|
59
|
+
if role == "test-writer":
|
|
60
|
+
return Locked(others(tickets, number), pr)
|
|
61
|
+
if role not in _CHECKED:
|
|
62
|
+
return None
|
|
63
|
+
return Locked(others(tickets, number), pr, tickets[number]["locked"], tickets[number]["test_writer_sha"])
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def for_end_of_run(tickets: dict, baseline: str) -> Locked:
|
|
67
|
+
"""Every ticket's locked files stay as `baseline` has them: the tidied tip, or for the rebase the recovery point.
|
|
68
|
+
With `baseline` as the PR tip too, the clean merge of `own_errors` is the file at `baseline`."""
|
|
69
|
+
return Locked([], baseline, every(tickets), baseline)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def present(repo: str, commit: str, paths: list[str]) -> list[str]:
|
|
73
|
+
"""The `paths` that are files at `commit`."""
|
|
74
|
+
return names(git(repo, "ls-tree", "-r", "--name-only", "-z", commit, "--", *paths).stdout) if paths else []
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def errors(role: str, report: dict, context: dict) -> list[str]:
|
|
78
|
+
"""The locked-file errors of the report of `role`. `context` is that of driver_report.validate; its `locked` is
|
|
79
|
+
the check (a `Locked`), None for an agent with no check."""
|
|
80
|
+
locked = context.get("locked")
|
|
81
|
+
if locked is None:
|
|
82
|
+
return []
|
|
83
|
+
if role == "test-writer":
|
|
84
|
+
return _unlisted_errors(report, context, locked)
|
|
85
|
+
return _own_errors(context, locked) + _others_errors(context, locked)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _blob(repo: str, commit: str, path: str) -> str:
|
|
89
|
+
return git(repo, "rev-parse", "-q", "--verify", f"{commit}:{path}").stdout.strip()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _unlisted_errors(report: dict, context: dict, locked: Locked) -> list[str]:
|
|
93
|
+
"""A test-writer changes a locked file of another ticket only when it lists the file in `locked`."""
|
|
94
|
+
repo, branch, start = context["repo"], context["branch"], context["start"]
|
|
95
|
+
return [f"{path} is a locked file of another ticket, and `locked` does not list it: list it in `locked`, or "
|
|
96
|
+
"leave the file as it was" for path in locked.others if path not in report.get("locked", [])
|
|
97
|
+
and _blob(repo, branch, path) not in (_blob(repo, start, path), _blob(repo, locked.pr, path))]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _differ(repo: str, old: str, new: str, paths: list[str]) -> set[str] | None:
|
|
101
|
+
"""The `paths` whose entry (mode, type, content) differs between the two commits; None when git cannot tell."""
|
|
102
|
+
diff = git(repo, "diff", "--name-only", "-z", old, new, "--", *paths)
|
|
103
|
+
return None if diff.returncode else set(names(diff.stdout))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _merge_base(repo: str, commit: str, pr: str) -> str:
|
|
107
|
+
"""The merge base of `commit` and the PR tip; the PR tip when git finds none."""
|
|
108
|
+
return git(repo, "merge-base", commit, pr).stdout.strip() or pr
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _breach(path: str, baseline: str) -> str:
|
|
112
|
+
return (f"locked file changed: {path}: only the test-writer may change a locked file, so make it as it is at "
|
|
113
|
+
f"{baseline[:7]}")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _others_errors(context: dict, locked: Locked) -> list[str]:
|
|
117
|
+
"""The locked files of other tickets, but the agent's own, that the branch changed since its merge base with the
|
|
118
|
+
PR tip. A file as the PR tip has it is no change: it holds what landed."""
|
|
119
|
+
repo, branch, pr = context["repo"], context["branch"], locked.pr
|
|
120
|
+
paths = [path for path in locked.others if path not in locked.own]
|
|
121
|
+
if not paths:
|
|
122
|
+
return []
|
|
123
|
+
baseline = _merge_base(repo, branch, pr)
|
|
124
|
+
changed, off_pr = _differ(repo, baseline, branch, paths), _differ(repo, pr, branch, paths)
|
|
125
|
+
if changed is None or off_pr is None:
|
|
126
|
+
return [f"the locked-file check failed: git cannot compare {baseline[:7]}, {pr} and {branch}"]
|
|
127
|
+
as_landed = set(present(repo, branch, paths)) - off_pr
|
|
128
|
+
return [_breach(path, baseline) for path in sorted(changed - as_landed)]
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _show(repo: str, commit: str, path: str) -> str | None:
|
|
132
|
+
"""The content of `path` at `commit`; None when it is no file there."""
|
|
133
|
+
shown = git(repo, "show", f"{commit}:{path}")
|
|
134
|
+
return None if shown.returncode else shown.stdout
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _clean_merge(repo: str, base: str, ours: str, theirs: str, path: str) -> str | None:
|
|
138
|
+
"""The three-way merge of `path` (`git merge-file`) from `base` with `ours` and `theirs`, a missing file empty;
|
|
139
|
+
None when it conflicts or git fails."""
|
|
140
|
+
with tempfile.TemporaryDirectory() as folder:
|
|
141
|
+
files = []
|
|
142
|
+
for name, commit in (("ours", ours), ("base", base), ("theirs", theirs)):
|
|
143
|
+
(Path(folder) / name).write_text(_show(repo, commit, path) or "")
|
|
144
|
+
files.append(str(Path(folder) / name))
|
|
145
|
+
merged = subprocess.run(["git", "merge-file", "-p", *files], capture_output=True, text=True)
|
|
146
|
+
return None if merged.returncode else merged.stdout
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _own_errors(context: dict, locked: Locked) -> list[str]:
|
|
150
|
+
"""The agent's own locked files that the branch changed since `locked.since`. A file is no change when it is the
|
|
151
|
+
clean three-way merge of its version there and the PR tip's, from their merge base, in content and mode: a conflict merge takes in what
|
|
152
|
+
landed and keeps the test-writer's tests."""
|
|
153
|
+
repo, branch, pr, since = context["repo"], context["branch"], locked.pr, locked.since
|
|
154
|
+
if not (since and locked.own):
|
|
155
|
+
return []
|
|
156
|
+
changed = _differ(repo, since, branch, locked.own)
|
|
157
|
+
if changed is None:
|
|
158
|
+
return [f"the locked-file check failed: git cannot compare {since[:7]} and {branch}"]
|
|
159
|
+
base = _merge_base(repo, since, pr)
|
|
160
|
+
return [_breach(path, since) for path in sorted(changed) if not _merged(repo, (base, since, pr), branch, path)]
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _mode(repo: str, commit: str, path: str) -> str:
|
|
164
|
+
"""The git mode of `path` at `commit`, which names its type too (file, executable, link); "" when it is not there."""
|
|
165
|
+
listed = git(repo, "ls-tree", commit, "--", path).stdout.split()
|
|
166
|
+
return listed[0] if listed else ""
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _merged(repo: str, sides: tuple[str, str, str], branch: str, path: str) -> bool:
|
|
170
|
+
"""`path` at `branch` is the clean three-way merge of `sides` (base, ours, theirs), in content and in mode: a mode
|
|
171
|
+
that ours did not change is theirs."""
|
|
172
|
+
base, ours, theirs = (_mode(repo, commit, path) for commit in sides)
|
|
173
|
+
merged = _clean_merge(repo, *sides, path)
|
|
174
|
+
return (merged is not None and _show(repo, branch, path) == merged
|
|
175
|
+
and _mode(repo, branch, path) == (theirs if ours == base else ours))
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def landing_errors(tickets: dict, number: str, pr_tip: str, commit: str) -> list[str]:
|
|
179
|
+
"""The locked files of every other ticket, but those ticket `number` lists, that `commit`, about to land, changes
|
|
180
|
+
from the PR tip: the PR tip holds what their test-writers locked."""
|
|
181
|
+
paths = [path for path in others(tickets, number) if path not in tickets[number]["locked"]]
|
|
182
|
+
changed = _differ(".", pr_tip, commit, paths) if paths else set()
|
|
183
|
+
if changed is None:
|
|
184
|
+
return [f"the locked-file check failed: git cannot compare {pr_tip[:7]} and {commit[:7]}"]
|
|
185
|
+
return [f"locked file changed: {path}: the commit that would land changes a locked file of another ticket, so make "
|
|
186
|
+
"it as the PR tip has it" for path in sorted(changed)]
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"""Merges into the PR branch through git plumbing: no checkout, so no slot's tree changes. Only a conflicting merge
|
|
2
|
-
gets a tree: `begin` opens it in the ticket's own slot for the conflict agent.
|
|
3
|
-
|
|
4
|
-
`refused` is the locked-file check of a landing. The caller holds the merge lock.
|
|
2
|
+
gets a tree: `begin` opens it in the ticket's own slot for the conflict agent. The caller holds the merge lock.
|
|
5
3
|
"""
|
|
6
4
|
from __future__ import annotations
|
|
7
5
|
|
|
8
6
|
import os
|
|
9
7
|
import subprocess
|
|
10
8
|
|
|
11
|
-
from driver_slots import ancestor, git
|
|
9
|
+
from driver_slots import ancestor, git
|
|
12
10
|
|
|
13
11
|
|
|
14
12
|
def identity(tip: str, slot: str = ".") -> dict[str, str]:
|
|
@@ -70,50 +68,6 @@ def abort(slot: str) -> None:
|
|
|
70
68
|
git(slot, "merge", "--abort")
|
|
71
69
|
|
|
72
70
|
|
|
73
|
-
def protected(tickets: dict, number: str) -> list[str]:
|
|
74
|
-
"""The locked files of the merged tickets that ticket `number` does not lock itself. `tickets` is that of
|
|
75
|
-
state.json; a record with no `locked` locked nothing."""
|
|
76
|
-
merged = {path for entry in tickets.values() if entry.get("phase") == "merged" for path in entry.get("locked") or []}
|
|
77
|
-
return sorted(merged - set(tickets.get(number, {}).get("locked") or []))
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def _entries(commit: str, paths: list[str]) -> tuple[dict[str, str], str]:
|
|
81
|
-
"""({path: "mode type object-id"} for each of `paths` that `commit` has, "") or ({}, why git cannot tell)."""
|
|
82
|
-
tree = git(".", "ls-tree", "-z", f"{commit}^{{commit}}", "--", *paths)
|
|
83
|
-
if tree.returncode:
|
|
84
|
-
return {}, f"cannot read the locked files at {commit}: {tree.stderr.strip() or f'git ls-tree exit {tree.returncode}'}"
|
|
85
|
-
return {path: entry for entry, _, path in (line.partition("\t") for line in names(tree.stdout))}, ""
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def refused(tickets: dict, number: str, old: str, new: str) -> tuple[list[str], str]:
|
|
89
|
-
"""Why ticket `number` may not land `new` on the PR tip `old`: (each locked file of a merged ticket that is not
|
|
90
|
-
the same blob with the same mode in both, "") or ([], why git cannot tell). ([], "") lets it land."""
|
|
91
|
-
paths = protected(tickets, number)
|
|
92
|
-
if not paths:
|
|
93
|
-
return [], "" # `git ls-tree` with no path lists the whole tree
|
|
94
|
-
(before, error), (after, failed) = _entries(old, paths), _entries(new, paths)
|
|
95
|
-
if error or failed:
|
|
96
|
-
return [], error or failed
|
|
97
|
-
return [path for path in paths if before.get(path) != after.get(path)], ""
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def changed(slot: str, pr_tip: str, paths: list[str]) -> list[str]:
|
|
101
|
-
"""Each of `paths` that the ticket changed in the tree of `slot`."""
|
|
102
|
-
# Against the merge base: a file that only the PR branch changed since then is not the ticket's change.
|
|
103
|
-
base = git(slot, "merge-base", "HEAD", pr_tip).stdout.strip() or pr_tip
|
|
104
|
-
return names(git(slot, "diff", "--name-only", "-z", base, "--", *paths).stdout) if paths else []
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def restore(slot: str, pr_tip: str, paths: list[str]) -> list[str]:
|
|
108
|
-
"""Put each of `paths` that the ticket changed back to the version of the PR tip, in the tree of `slot` only; a
|
|
109
|
-
file the PR tip does not have is removed. Returns those paths."""
|
|
110
|
-
restored = changed(slot, pr_tip, paths)
|
|
111
|
-
for path in restored:
|
|
112
|
-
if git(slot, "checkout", "-q", pr_tip, "--", path).returncode:
|
|
113
|
-
git(slot, "rm", "-q", "-f", "--", path)
|
|
114
|
-
return restored
|
|
115
|
-
|
|
116
|
-
|
|
117
71
|
def land(pr_branch: str, new: str, old: str) -> str:
|
|
118
72
|
"""Move the PR branch from `old` to `new`; "" or the error. git refuses when the branch is no longer at `old`."""
|
|
119
73
|
moved = git(".", "update-ref", "-m", "implement-spec: merge", f"refs/heads/{pr_branch}", new, old)
|
|
@@ -123,3 +77,4 @@ def land(pr_branch: str, new: str, old: str) -> str:
|
|
|
123
77
|
def delete(branch: str, pr_branch: str) -> bool:
|
|
124
78
|
"""Delete a ticket branch whose commits are all in the PR branch. git refuses one a worktree has checked out."""
|
|
125
79
|
return ancestor(branch, pr_branch) and git(".", "branch", "-q", "-D", branch).returncode == 0
|
|
80
|
+
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
"""Report validation: validate(role, path, context) -> list of errors, empty when the report is accepted.
|
|
2
2
|
|
|
3
|
-
context: repo (slot path), branch, start (HEAD when the role started), log,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
context: repo (slot path), branch, start (HEAD when the role started), log, correction (a test-writer corrects locked
|
|
4
|
+
tests), findings (the titles a correction gets), owners (ticket numbers, for the final fix batch), locked (the
|
|
5
|
+
locked-file check, a driver_locked.Locked, or None), fix (the titles of the findings a fixer gets), red (the red gate
|
|
6
|
+
a fix must make green, as `the <tier> gate is red on <sha7>`), disputed (the test ids an arbitration rules on), commits
|
|
7
|
+
(the commits the report is checked on in place of its own: the tip of a rebase the driver went on with), rejected
|
|
8
|
+
(errors the driver found when the agent ended, for a done report)."""
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
11
|
import json
|
|
12
12
|
import re
|
|
13
13
|
import subprocess
|
|
14
14
|
from pathlib import Path
|
|
15
|
+
from typing import NamedTuple
|
|
15
16
|
|
|
16
17
|
import jsonschema
|
|
17
18
|
|
|
19
|
+
import driver_locked
|
|
20
|
+
|
|
18
21
|
PROMPTS = Path(__file__).resolve().parent / "prompts"
|
|
19
22
|
RED = "red line not found in log"
|
|
23
|
+
CONTRADICTS = "locked test contradicts spec:"
|
|
24
|
+
DISPUTING = ("implementer", "fixer") # the roles whose BLOCKED report can dispute a locked test
|
|
20
25
|
|
|
21
26
|
|
|
22
27
|
def schema(role: str) -> dict:
|
|
@@ -67,25 +72,30 @@ def _must_fix_errors(report: dict, context: dict) -> list[str]:
|
|
|
67
72
|
if title not in report.get("addressed_must_fix", [])]
|
|
68
73
|
|
|
69
74
|
|
|
70
|
-
def
|
|
71
|
-
"""
|
|
72
|
-
return
|
|
75
|
+
def _rejected_errors(report: dict, context: dict) -> list[str]:
|
|
76
|
+
"""What the driver found wrong when the agent ended, for a report that says the agent is done."""
|
|
77
|
+
return context.get("rejected", []) if report.get("status") in ("DONE", "DONE_WITH_CONCERNS") else []
|
|
73
78
|
|
|
74
79
|
|
|
75
80
|
def _commit_errors(report: dict, context: dict) -> list[str]:
|
|
76
81
|
"""Every commit is new since the role started and on the branch; every locked path is in such a commit and is a
|
|
77
82
|
file at the branch tip: a deleted file holds no test that a review could prove (issue #136)."""
|
|
78
|
-
repo, branch, commits = context["repo"], context["branch"], _shas(report)
|
|
83
|
+
repo, branch, commits = context["repo"], context["branch"], context.get("commits") or _shas(report)
|
|
79
84
|
new = _git(repo, "rev-list", f"{context['start']}..{branch}")
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
return [f"commit {sha[:7]} is not a new commit on {branch}"
|
|
86
|
+
for sha in commits if not any(n.startswith(sha) for n in new)] + _locked_path_errors(report, context)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _locked_path_errors(report: dict, context: dict) -> list[str]:
|
|
90
|
+
"""Every locked path is in a commit of the role and is a file at the branch tip."""
|
|
91
|
+
repo, branch, locked = context["repo"], context["branch"], report.get("locked", [])
|
|
92
|
+
if not locked:
|
|
93
|
+
return []
|
|
94
|
+
changed = _git(repo, "log", "--name-only", "-z", "--format=", f"{context['start']}..{branch}", end="\0")
|
|
95
|
+
present = driver_locked.present(repo, branch, locked)
|
|
96
|
+
return [f"locked path {path} is not in the role's commits" for path in locked if path not in changed] + [
|
|
97
|
+
f"locked path {path} is not a file at the tip of {branch}: list in `locked` only files you keep"
|
|
98
|
+
for path in locked if path in changed and path not in present]
|
|
89
99
|
|
|
90
100
|
|
|
91
101
|
def _unchanged_errors(role: str, report: dict, context: dict) -> list[str]:
|
|
@@ -117,66 +127,75 @@ def _moved_errors(context: dict) -> list[str]:
|
|
|
117
127
|
|
|
118
128
|
|
|
119
129
|
def _correction_errors(report: dict, context: dict) -> list[str]:
|
|
120
|
-
"""A correction changes only the files it lists in `locked
|
|
130
|
+
"""A correction changes only the files it lists in `locked`."""
|
|
121
131
|
if not context.get("correction"):
|
|
122
132
|
return []
|
|
123
133
|
changed = _git(context["repo"], "diff", "--name-only", "-z", context["start"], context["branch"], end="\0")
|
|
124
|
-
more = [path for path in changed if path not in report.get("locked", [])
|
|
134
|
+
more = [path for path in changed if path not in report.get("locked", [])]
|
|
125
135
|
errors = [f"a correction may change only the files it lists in `locked`: its commits also change {', '.join(more)}"
|
|
126
136
|
] if more else []
|
|
127
|
-
if context.get("restore_red") and report["status"] in ("DONE", "DONE_WITH_CONCERNS") and not (
|
|
128
|
-
set(report["locked"]) & set(context["restored"])):
|
|
129
|
-
errors.append("the gate is red on the restore commit, so a restored file fails with the code of this ticket: "
|
|
130
|
-
"update that file and list it in `locked`, or report BLOCKED with a concern that starts with "
|
|
131
|
-
"`locked test contradicts spec:`")
|
|
132
137
|
return errors + [f"not_addressed: {item['finding']} is not the title of a finding of this correction"
|
|
133
138
|
for item in report.get("not_addressed", []) if item["finding"] not in context.get("findings", [])]
|
|
134
139
|
|
|
135
140
|
|
|
136
|
-
def
|
|
137
|
-
"""
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
def _red_errors(report: dict, context: dict) -> list[str]:
|
|
142
|
+
"""Every red line that a test-writer or a correction claims is in the agent's log."""
|
|
143
|
+
lines = [(r["test"], r["line"]) for r in report.get("red", [])]
|
|
144
|
+
log = Path(context["log"]).read_text(errors="replace") if lines else ""
|
|
145
|
+
return [f"{RED}: {test}: {line if len(line) <= 200 else line[:197] + '...'}"
|
|
146
|
+
for test, line in lines if not _seen(line, log)]
|
|
147
|
+
|
|
140
148
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
149
|
+
def _space_errors(report: dict) -> list[str]:
|
|
150
|
+
"""No locked path holds whitespace: the fast gate gets the locked paths as one space-separated list."""
|
|
151
|
+
return [f"locked path {path!r} contains whitespace: the fast gate gets the locked paths separated by spaces, so "
|
|
152
|
+
"rename the file" for path in report.get("locked", []) if re.search(r"\s", path)]
|
|
144
153
|
|
|
145
154
|
|
|
146
|
-
def
|
|
147
|
-
"""
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for test, line in lines if not _seen(line, log)]
|
|
153
|
-
if context.get("full") and "findings" in report and "mutations" not in report:
|
|
154
|
-
errors.append("mutations: required in a full review")
|
|
155
|
-
return errors
|
|
155
|
+
def _locked_file(name: str, locked: list[str]) -> str:
|
|
156
|
+
"""The locked file that `name` names: itself, or the one locked path that ends with it; "" for none."""
|
|
157
|
+
if name in locked:
|
|
158
|
+
return name
|
|
159
|
+
found = [path for path in locked if path.endswith("/" + name)]
|
|
160
|
+
return found[0] if len(found) == 1 else ""
|
|
156
161
|
|
|
157
162
|
|
|
158
|
-
|
|
159
|
-
"""
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return []
|
|
164
|
-
locked = context.get("locked", [])
|
|
165
|
-
tests, present = [proof["test"] for proof in report.get("mutations", [])], _present(context["repo"], context["start"], locked)
|
|
166
|
-
return [f"mutations: no mutation proof for the locked test file {path}" for path in locked
|
|
167
|
-
if path in present and not any(test.startswith(path) for test in tests)]
|
|
163
|
+
class Dispute(NamedTuple):
|
|
164
|
+
"""One concern `locked test contradicts spec: <file>::<test>: <reason>` of a BLOCKED implementer or fixer."""
|
|
165
|
+
file: str # the locked file it names; "" when it names no file of the ticket's `locked`
|
|
166
|
+
test: str
|
|
167
|
+
reason: str
|
|
168
168
|
|
|
169
169
|
|
|
170
|
-
def
|
|
171
|
-
"""
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
def disputes(role: str, report: dict, locked: list[str]) -> list[Dispute]:
|
|
171
|
+
"""The disputes of a BLOCKED implementer or fixer report, each file resolved against `locked`."""
|
|
172
|
+
if role not in DISPUTING or report.get("status") != "BLOCKED":
|
|
173
|
+
return []
|
|
174
|
+
found = []
|
|
175
|
+
for concern in report["concerns"]:
|
|
176
|
+
if concern.startswith(CONTRADICTS):
|
|
177
|
+
test, _, reason = concern[len(CONTRADICTS):].strip().partition(": ")
|
|
178
|
+
found.append(Dispute(_locked_file(test.partition("::")[0], locked), test, reason))
|
|
179
|
+
return found
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _dispute_errors(role: str, report: dict, context: dict) -> list[str]:
|
|
183
|
+
"""A dispute names a locked file of the ticket, and leaves no uncommitted change: the arbitration is read-only
|
|
184
|
+
and the correction commits."""
|
|
185
|
+
locked = context.get("locked")
|
|
186
|
+
found = disputes(role, report, locked.own if locked else [])
|
|
187
|
+
errors = [f"the dispute of {dispute.test or 'no test'} names no locked file of the ticket: write it as "
|
|
188
|
+
f"`{CONTRADICTS} <locked file>::<test>: <reason>`" for dispute in found if not dispute.file]
|
|
189
|
+
if found and _git(context["repo"], "status", "--porcelain"):
|
|
190
|
+
errors.append("a dispute leaves no uncommitted change: commit your work, then report the dispute")
|
|
191
|
+
return errors
|
|
174
192
|
|
|
175
193
|
|
|
176
|
-
def
|
|
177
|
-
"""
|
|
178
|
-
|
|
179
|
-
|
|
194
|
+
def _ruling_errors(report: dict, context: dict) -> list[str]:
|
|
195
|
+
"""An arbitration rules on each disputed test."""
|
|
196
|
+
given = {ruling["test"] for ruling in report.get("rulings", [])}
|
|
197
|
+
return [f"rulings: no ruling on {test}: give one ruling per disputed test, its id as the list gives it"
|
|
198
|
+
for test in context.get("disputed", []) if test not in given]
|
|
180
199
|
|
|
181
200
|
|
|
182
201
|
def locked_files(listed: list[str]) -> list[str]:
|
|
@@ -197,7 +216,8 @@ def validate(role: str, path: str, context: dict) -> list[str]:
|
|
|
197
216
|
report = {name: value for name, value in report.items() if name in rules["properties"]}
|
|
198
217
|
if "locked" in report:
|
|
199
218
|
report["locked"] = locked_files(report["locked"])
|
|
200
|
-
return (
|
|
219
|
+
return (_rejected_errors(report, context) + _space_errors(report) + _commit_errors(report, context)
|
|
220
|
+
+ _owner_errors(report, context) + _must_fix_errors(report, context)
|
|
201
221
|
+ _unchanged_errors(role, report, context) + _correction_errors(report, context)
|
|
202
|
-
+
|
|
203
|
-
+
|
|
222
|
+
+ driver_locked.errors(role, report, context) + _red_errors(report, context)
|
|
223
|
+
+ _dispute_errors(role, report, context) + _ruling_errors(report, context))
|
|
@@ -1,141 +1,34 @@
|
|
|
1
|
-
"""The driver's own part of a review: the
|
|
2
|
-
|
|
1
|
+
"""The driver's own part of a review: the routing of the findings, and the slot and the shared git config that a
|
|
2
|
+
read-only role must leave as it found them.
|
|
3
3
|
|
|
4
|
-
A finding is the dict of the reviewer schema plus `source`: the role that reported it, or `
|
|
5
|
-
A mutation proof is keyed by (production file, line); the line is the one the file has at the ticket tip.
|
|
4
|
+
A finding is the dict of the reviewer schema plus `source`: the role that reported it, or `gate` for a red full gate.
|
|
6
5
|
"""
|
|
7
6
|
from __future__ import annotations
|
|
8
7
|
|
|
9
8
|
import os
|
|
10
|
-
import re
|
|
11
9
|
import subprocess
|
|
12
10
|
from pathlib import Path
|
|
13
11
|
|
|
14
|
-
import
|
|
15
|
-
from driver_slots import git, head, names, on_branch
|
|
16
|
-
from driver_tickets import Ticket
|
|
12
|
+
from driver_slots import git, head, on_branch
|
|
17
13
|
|
|
18
|
-
# The checks of the correctness pass: this file of the review-diff skill, which is installed next to this one.
|
|
19
|
-
CORRECTNESS = driver_agents.SKILL.parent / "review-diff" / "correctness.md"
|
|
20
14
|
OPEN = ("critical", "important") # the severities that start a fix round
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
""
|
|
26
|
-
|
|
27
|
-
if CORRECTNESS.exists() or not risky:
|
|
28
|
-
return []
|
|
29
|
-
return [f"{CORRECTNESS} is missing: ticket {', '.join(risky)} has a Risk line and its correctness prompt carries "
|
|
30
|
-
"that file; install the review-diff skill next to implement-spec"]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def checks() -> str:
|
|
34
|
-
"""CORRECTNESS, inlined into the correctness prompt: the pass reads files only from git at the tip and from
|
|
35
|
-
`.agent/`, and a project-local install of review-diff sits in an ignored directory (issue #120). "" when it is
|
|
36
|
-
missing: only a ticket with a Risk line renders it, and `precondition_errors` checks the file for those."""
|
|
37
|
-
return CORRECTNESS.read_text() if CORRECTNESS.exists() else ""
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def locked_changes(slot: str, sha: str | None, locked: list[str]) -> list[dict]:
|
|
41
|
-
"""One critical finding per locked file that differs from the test-writer's commit `sha`, or for a diff that
|
|
42
|
-
git cannot make."""
|
|
43
|
-
if not (sha and locked):
|
|
44
|
-
return [] # a refactor ticket has no test-writer
|
|
45
|
-
diff = git(slot, "diff", "--name-only", "-z", f"{sha}..HEAD", "--", *locked)
|
|
46
|
-
titles = ({path: f"locked file changed: {path}" for path in names(diff.stdout)} if diff.returncode == 0
|
|
47
|
-
else {locked[0]: f"locked file check failed: {diff.stderr.strip()}"})
|
|
48
|
-
return [{"severity": "critical", "file": path, "line": 1, "title": title, "kind": "code", "source": "driver",
|
|
49
|
-
"evidence": f"git diff {sha}..HEAD -- {path}"} for path, title in titles.items()]
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def merged_changes(paths: list[str]) -> list[dict]:
|
|
53
|
-
"""One critical `fixture` finding per locked file of a merged ticket that the ticket changed. A fixture finding
|
|
54
|
-
goes to a test-writer correction: the driver puts the file back before it and gates that commit."""
|
|
55
|
-
return [{"severity": "critical", "file": path, "line": 1, "kind": "fixture", "source": "driver",
|
|
56
|
-
"basis": "regression",
|
|
57
|
-
"title": f"the ticket changed the locked file of a merged ticket: {path}",
|
|
58
|
-
"evidence": f"git diff <merge base with the PR branch> -- {path}"} for path in paths]
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def _references(entry: dict) -> list[tuple[str | None, list[str]]]:
|
|
62
|
-
"""(reference commit, the locked files it is the reference of): `test_writer_sha`, or the older commit that
|
|
63
|
-
`held` names for a file."""
|
|
64
|
-
held = entry["held"]
|
|
65
|
-
groups = [(entry["test_writer_sha"], [path for path in entry["locked"] if path not in held])]
|
|
66
|
-
return groups + [(sha, [path for path, at in held.items() if at == sha]) for sha in dict.fromkeys(held.values())]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def locked_findings(slot: str, entry: dict) -> list[dict]:
|
|
70
|
-
"""The locked-file check for the ticket record `entry`."""
|
|
71
|
-
return [finding for sha, paths in _references(entry) for finding in locked_changes(slot, sha, paths)]
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def restore_locked(slot: str, entry: dict) -> list[str]:
|
|
75
|
-
"""Put each locked file that differs from its reference back to the reference version, in the tree only.
|
|
76
|
-
Returns those paths."""
|
|
77
|
-
restored = []
|
|
78
|
-
for sha, paths in _references(entry):
|
|
79
|
-
if sha and paths:
|
|
80
|
-
restored += names(git(slot, "diff", "--name-only", "-z", sha, "--", *paths).stdout)
|
|
81
|
-
for path in restored:
|
|
82
|
-
git(slot, "checkout", "-q", entry["held"].get(path, entry["test_writer_sha"]), "--", path)
|
|
83
|
-
return restored
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def written(slot: str, entry: dict, listed: list[str], fixtures: list[str], tip: str) -> dict:
|
|
87
|
-
"""The locked-file fields of the ticket record after a test-writer commit at `tip` that lists `listed`, of which
|
|
88
|
-
`fixtures` hold no test. `tip` is the new reference. A locked file that a correction does not list and that differs
|
|
89
|
-
from the old reference keeps the old one in `held`, so a change the implementer made before stays a finding."""
|
|
90
|
-
held = {path: sha for path, sha in entry["held"].items() if path not in listed}
|
|
91
|
-
others = [path for path in entry["locked"] if path not in listed and path not in held]
|
|
92
|
-
if entry["test_writer_sha"] and others:
|
|
93
|
-
diff = git(slot, "diff", "--name-only", "-z", entry["test_writer_sha"], tip, "--", *others)
|
|
94
|
-
# A diff that git cannot make holds each file.
|
|
95
|
-
held.update(dict.fromkeys(names(diff.stdout) if diff.returncode == 0 else others, entry["test_writer_sha"]))
|
|
96
|
-
return {"test_writer_sha": tip, "locked": list(dict.fromkeys(entry["locked"] + listed)), "held": held,
|
|
97
|
-
"fixtures": [path for path in entry["fixtures"] if path not in listed] + fixtures}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _corrected(finding: dict, locked: list[str], protected: list[str]) -> bool:
|
|
18
|
+
"""Whether a correction, not a fixer, takes the finding: see `route`."""
|
|
19
|
+
return finding["kind"] == "fixture" or finding["severity"] in OPEN and (
|
|
20
|
+
finding["file"] in protected or finding["kind"] == "test" and finding["file"] in locked)
|
|
98
21
|
|
|
99
22
|
|
|
100
23
|
def route(findings: list[dict], locked: list[str], protected: list[str]) -> tuple[list[dict], list[dict]]:
|
|
101
24
|
"""(the findings for a test-writer correction; the other findings that are severe enough for a fix round).
|
|
102
25
|
A correction gets each fixture finding, whatever its severity, each severe test finding on a `locked` file, and
|
|
103
|
-
each severe finding on a `protected` file (a locked file of
|
|
26
|
+
each severe finding on a `protected` file (a locked file of another ticket): the fixer may not edit those files,
|
|
104
27
|
so a fix round cannot close it. Only a correction can take a protected file into the ticket's `locked` (#116)."""
|
|
105
|
-
correct = [finding for finding in findings if finding
|
|
106
|
-
finding["file"] in protected or finding["kind"] == "test" and finding["file"] in locked)]
|
|
28
|
+
correct = [finding for finding in findings if _corrected(finding, locked, protected)]
|
|
107
29
|
return correct, [finding for finding in findings if finding not in correct and finding["severity"] in OPEN]
|
|
108
30
|
|
|
109
31
|
|
|
110
|
-
def _hunks(slot: str, old: str, new: str, file: str) -> list[tuple[int, int, int, int]]:
|
|
111
|
-
"""(first old line, old count, first new line, new count) per hunk of `file`, with no context lines."""
|
|
112
|
-
diff = git(slot, "diff", "-U0", old, new, "--", file).stdout
|
|
113
|
-
return [(int(a), int(b or 1), int(c), int(d or 1)) for a, b, c, d in _HUNK.findall(diff)]
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def _follow(line: int, hunks: list[tuple[int, int, int, int]]) -> tuple[int, bool]:
|
|
117
|
-
"""(the number old `line` has after the hunks, whether a hunk changed the line)."""
|
|
118
|
-
shift = 0
|
|
119
|
-
for a, b, c, d in hunks:
|
|
120
|
-
if a <= line < a + b:
|
|
121
|
-
return c + min(line - a, max(d - 1, 0)), True
|
|
122
|
-
if line >= a + max(b, 1): # a hunk with no old line is an insert after line `a`
|
|
123
|
-
shift += d - b
|
|
124
|
-
return line + shift, False
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def follow(slot: str, old: str, new: str, proofs: set[tuple[str, int]]) -> dict[tuple[str, int], bool]:
|
|
128
|
-
"""The proofs of commit `old` as they are at `new`: (file, new line) -> whether the fix changed that line, so
|
|
129
|
-
its proof is due again."""
|
|
130
|
-
# ponytail: a renamed file reads as deleted, so each of its proofs is due again; follow renames if that costs.
|
|
131
|
-
hunks = {file: _hunks(slot, old, new, file) for file in {file for file, _ in proofs}}
|
|
132
|
-
found: dict[tuple[str, int], bool] = {}
|
|
133
|
-
for file, line in sorted(proofs):
|
|
134
|
-
at, changed = _follow(line, hunks[file])
|
|
135
|
-
found[file, at] = changed or found.get((file, at), False)
|
|
136
|
-
return found
|
|
137
|
-
|
|
138
|
-
|
|
139
32
|
def restore(slot: str, branch: str, tip: str) -> None:
|
|
140
33
|
"""Put the slot back on `branch` at `tip` with a clean tree. Only for a read-only role: its edits, commits and
|
|
141
34
|
untracked files go. Ignored files stay."""
|