@jesdi/skills 0.0.63 → 0.0.64
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 +15 -0
- package/package.json +2 -2
- package/skills/babysit-pr/SKILL.md +54 -0
- package/skills/babysit-pr/babysit.py +998 -0
- package/skills/babysit-pr/fixtures/gh +310 -0
- package/skills/babysit-pr/hooks/post-pr-create.sh +56 -0
- package/skills/babysit-pr/hooks.json +10 -0
- package/skills/babysit-pr/judge-prompt.md +10 -0
- package/skills/babysit-pr/test_babysit.py +242 -0
- package/skills/babysit-pr/test_babysit_judge.py +286 -0
- package/skills/babysit-pr/test_babysit_judge_diff.py +25 -0
- package/skills/babysit-pr/test_babysit_judge_isolation.py +61 -0
- package/skills/babysit-pr/test_checks_regressions.py +210 -0
- package/skills/babysit-pr/test_comment_fidelity.py +88 -0
- package/skills/babysit-pr/test_comment_identity.py +70 -0
- package/skills/babysit-pr/test_e2e_setup.py +74 -0
- package/skills/babysit-pr/test_handoff_takeover.py +141 -0
- package/skills/babysit-pr/test_handoff_terminal.py +29 -0
- package/skills/babysit-pr/test_hook_quoting.py +25 -0
- package/skills/babysit-pr/test_hooks.py +62 -0
- package/skills/babysit-pr/test_lease_regressions.py +198 -0
- package/skills/babysit-pr/test_merge_and_handoff.py +260 -0
- package/skills/babysit-pr/test_merge_base_pin.py +10 -0
- package/skills/babysit-pr/test_merge_gate.py +124 -0
- package/skills/babysit-pr/test_merge_session_safety.py +117 -0
- package/skills/babysit-pr/test_merged_pr_labels.py +144 -0
- package/skills/babysit-pr/test_owner_comment_edits.py +26 -0
- package/skills/babysit-pr/test_owner_comments.py +316 -0
- package/skills/babysit-pr/test_retry_and_stall_hardening.py +143 -0
- package/skills/babysit-pr/test_rounds_and_checks.py +305 -0
- package/skills/babysit-pr/test_terminal_label_regressions.py +117 -0
- package/skills/babysit-pr/test_trusted_merge_risk.py +184 -0
- package/skills/babysit-pr/test_update_plan.py +157 -0
- package/skills/implement-spec/README.md +1 -1
- package/skills/implement-spec/SKILL.md +1 -1
- package/skills/implement-spec/driver_final.py +49 -10
- package/skills/implement-spec/prompts/pr-writer.md +3 -2
- package/skills/implement-spec/tests/test_final.py +112 -1
- package/skills/implement-spec/tests/test_tidy.py +2 -2
- package/skills/implement-spec/tests/test_walk.py +2 -2
- package/skills/pr-risk/SKILL.md +33 -0
- package/skills/pr-risk/hooks/pre-pr-create.sh +274 -0
- package/skills/pr-risk/hooks.json +10 -0
- package/skills/pr-risk/merge_policy.py +81 -0
- package/skills/pr-risk/merge_risk.py +314 -0
- package/skills/pr-risk/test_hook_commands.py +47 -0
- package/skills/pr-risk/test_hook_heredoc.py +16 -0
- package/skills/pr-risk/test_hook_substitution.py +40 -0
- package/skills/pr-risk/test_hooks.py +175 -0
- package/skills/pr-risk/test_merge_risk.py +97 -0
- package/skills/pr-risk/test_merge_risk_gate.py +217 -0
- package/skills/pr-risk/test_merge_risk_regressions.py +37 -0
- package/skills/pr-risk/test_merge_risk_structure.py +101 -0
- package/skills-manifest.json +15 -3
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Acceptance tests for `babysit.py update-plan --base <ref>`.
|
|
2
|
+
|
|
3
|
+
Interface under test (run with the PR branch checked out, cwd = the clone):
|
|
4
|
+
babysit.py update-plan --base <ref>
|
|
5
|
+
Prints one JSON object on stdout, exit 0:
|
|
6
|
+
plan "rebase" | "rebase-with-conflict" | "merge"
|
|
7
|
+
compare the ref compared against, e.g. "origin/main"
|
|
8
|
+
push the push command: rebase plans use
|
|
9
|
+
`git push --force-with-lease=<branch>:<old sha> origin <branch>`;
|
|
10
|
+
the merge plan pushes without any force flag
|
|
11
|
+
files conflicting files (rebase-with-conflict only)
|
|
12
|
+
It never changes the worktree, the index, HEAD or any ref.
|
|
13
|
+
"""
|
|
14
|
+
import json
|
|
15
|
+
import subprocess
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
SCRIPT = Path(__file__).with_name("babysit.py").resolve()
|
|
19
|
+
BRANCH = "feat/x"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def git(cwd, *args):
|
|
23
|
+
return subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True, text=True,
|
|
24
|
+
env={"GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",
|
|
25
|
+
"GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t",
|
|
26
|
+
"PATH": "/usr/bin:/bin:/usr/local/bin:/opt/homebrew/bin",
|
|
27
|
+
"HOME": str(cwd)}).stdout.strip()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def commit(cwd, path, text, msg):
|
|
31
|
+
f = Path(cwd) / path
|
|
32
|
+
f.parent.mkdir(parents=True, exist_ok=True)
|
|
33
|
+
f.write_text(text)
|
|
34
|
+
git(cwd, "add", path)
|
|
35
|
+
git(cwd, "commit", "-m", msg)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Repo:
|
|
39
|
+
"""origin (bare) + clone `work`, with main history that already touched src/parse.py twice."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, tmp):
|
|
42
|
+
self.origin = tmp / "origin.git"
|
|
43
|
+
self.work = tmp / "work"
|
|
44
|
+
git(tmp, "init", "--bare", "-b", "main", str(self.origin))
|
|
45
|
+
git(tmp, "clone", str(self.origin), str(self.work))
|
|
46
|
+
git(self.work, "checkout", "-b", "main")
|
|
47
|
+
commit(self.work, "src/parse.py", "a\nb\nc\n", "old 1")
|
|
48
|
+
commit(self.work, "src/parse.py", "a\nb\nc\nd\n", "old 2")
|
|
49
|
+
git(self.work, "push", "origin", "main")
|
|
50
|
+
git(self.work, "checkout", "-b", BRANCH)
|
|
51
|
+
|
|
52
|
+
def branch_commits(self, n, path="src/parse.py"):
|
|
53
|
+
for i in range(n):
|
|
54
|
+
commit(self.work, path, f"X{i}\nb\nc\nd\n", f"branch {i}")
|
|
55
|
+
git(self.work, "push", "origin", BRANCH)
|
|
56
|
+
|
|
57
|
+
def advance(self, branch, n, path="other.txt", text=None):
|
|
58
|
+
git(self.work, "checkout", branch)
|
|
59
|
+
for i in range(n):
|
|
60
|
+
commit(self.work, path, text or f"base {i}\n", f"{branch} {i}")
|
|
61
|
+
git(self.work, "push", "origin", branch)
|
|
62
|
+
git(self.work, "checkout", BRANCH)
|
|
63
|
+
|
|
64
|
+
def plan(self, base="main"):
|
|
65
|
+
git(self.work, "fetch", "origin")
|
|
66
|
+
r = subprocess.run(["python3", str(SCRIPT), "update-plan", "--base", base],
|
|
67
|
+
cwd=self.work, capture_output=True, text=True)
|
|
68
|
+
assert r.returncode == 0, r.stdout + r.stderr
|
|
69
|
+
return json.loads(r.stdout)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_new_base_commits_without_conflict_plan_rebase(tmp_path):
|
|
73
|
+
r = Repo(tmp_path)
|
|
74
|
+
r.branch_commits(1)
|
|
75
|
+
r.advance("main", 3)
|
|
76
|
+
old = git(r.work, "rev-parse", "HEAD")
|
|
77
|
+
p = r.plan()
|
|
78
|
+
assert p["plan"] == "rebase"
|
|
79
|
+
assert p["push"] == f"git push --force-with-lease={BRANCH}:{old} origin {BRANCH}"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_conflict_in_two_branch_commits_plans_rebase_with_conflict(tmp_path):
|
|
83
|
+
r = Repo(tmp_path)
|
|
84
|
+
r.branch_commits(2)
|
|
85
|
+
r.advance("main", 1, "src/parse.py", "M\nb\nc\nd\n")
|
|
86
|
+
p = r.plan()
|
|
87
|
+
assert p["plan"] == "rebase-with-conflict"
|
|
88
|
+
assert "src/parse.py" in p["files"]
|
|
89
|
+
assert "--force-with-lease=" in p["push"]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_conflict_in_three_branch_commits_plans_merge(tmp_path):
|
|
93
|
+
r = Repo(tmp_path)
|
|
94
|
+
r.branch_commits(3)
|
|
95
|
+
r.advance("main", 1, "src/parse.py", "M\nb\nc\nd\n")
|
|
96
|
+
p = r.plan()
|
|
97
|
+
assert p["plan"] == "merge"
|
|
98
|
+
assert p["compare"] == "origin/main"
|
|
99
|
+
assert "force" not in p["push"]
|
|
100
|
+
assert p["push"].endswith(f"origin {BRANCH}")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_update_plan_leaves_worktree_index_and_head_unchanged(tmp_path):
|
|
104
|
+
r = Repo(tmp_path)
|
|
105
|
+
r.branch_commits(2)
|
|
106
|
+
r.advance("main", 1, "src/parse.py", "M\nb\nc\nd\n")
|
|
107
|
+
(r.work / "src/parse.py").write_text("dirty\n")
|
|
108
|
+
(r.work / "untracked.txt").write_text("u\n")
|
|
109
|
+
(r.work / "staged.txt").write_text("s\n")
|
|
110
|
+
git(r.work, "add", "staged.txt")
|
|
111
|
+
git(r.work, "fetch", "origin")
|
|
112
|
+
before = (git(r.work, "status", "--porcelain"), git(r.work, "rev-parse", "HEAD"),
|
|
113
|
+
git(r.work, "for-each-ref"), git(r.work, "diff", "--cached"),
|
|
114
|
+
(r.work / "src/parse.py").read_text())
|
|
115
|
+
p = r.plan()
|
|
116
|
+
assert p["plan"] == "rebase-with-conflict"
|
|
117
|
+
after = (git(r.work, "status", "--porcelain"), git(r.work, "rev-parse", "HEAD"),
|
|
118
|
+
git(r.work, "for-each-ref"), git(r.work, "diff", "--cached"),
|
|
119
|
+
(r.work / "src/parse.py").read_text())
|
|
120
|
+
assert after == before
|
|
121
|
+
assert not (r.work / ".git" / "MERGE_HEAD").exists()
|
|
122
|
+
assert not (r.work / ".git" / "rebase-merge").exists()
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def test_base_feat_parent_compares_with_origin_feat_parent(tmp_path):
|
|
126
|
+
r = Repo(tmp_path)
|
|
127
|
+
r.branch_commits(1)
|
|
128
|
+
# main would conflict with the branch; the parent does not
|
|
129
|
+
r.advance("main", 1, "src/parse.py", "M\nb\nc\nd\n")
|
|
130
|
+
git(r.work, "checkout", "-b", "feat/parent", "origin/main~1")
|
|
131
|
+
git(r.work, "push", "origin", "feat/parent")
|
|
132
|
+
git(r.work, "checkout", BRANCH)
|
|
133
|
+
r.advance("feat/parent", 1)
|
|
134
|
+
p = r.plan("feat/parent")
|
|
135
|
+
assert p["compare"] == "origin/feat/parent"
|
|
136
|
+
assert p["plan"] == "rebase"
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_commits_across_two_conflicting_files_are_counted_as_a_union(tmp_path):
|
|
140
|
+
r = Repo(tmp_path)
|
|
141
|
+
git(r.work, "checkout", "main")
|
|
142
|
+
commit(r.work, "a.py", "a\nb\nc\n", "add a")
|
|
143
|
+
commit(r.work, "b.py", "a\nb\nc\n", "add b")
|
|
144
|
+
git(r.work, "push", "origin", "main")
|
|
145
|
+
git(r.work, "checkout", BRANCH)
|
|
146
|
+
git(r.work, "merge", "--ff-only", "main")
|
|
147
|
+
commit(r.work, "a.py", "A1\nb\nc\n", "branch a1")
|
|
148
|
+
commit(r.work, "a.py", "A2\nb\nc\n", "branch a2")
|
|
149
|
+
commit(r.work, "b.py", "B1\nb\nc\n", "branch b1")
|
|
150
|
+
git(r.work, "push", "origin", BRANCH)
|
|
151
|
+
git(r.work, "checkout", "main")
|
|
152
|
+
commit(r.work, "a.py", "M\nb\nc\n", "main a")
|
|
153
|
+
commit(r.work, "b.py", "M\nb\nc\n", "main b")
|
|
154
|
+
git(r.work, "push", "origin", "main")
|
|
155
|
+
git(r.work, "checkout", BRANCH)
|
|
156
|
+
p = r.plan()
|
|
157
|
+
assert p["plan"] == "merge"
|
|
@@ -140,7 +140,7 @@ The end of run starts only when every ticket is merged and every slot is idle. I
|
|
|
140
140
|
3. **Gate**, then the **final-reviewer** (`prompts/final-reviewer.md`) on the whole range, with the method of the `review-diff` skill. It gets the minor findings of the tickets and the rulings of the operator.
|
|
141
141
|
4. **Fix batch.** Critical and important findings go to one fixer (`prompts/final-fixer.md`). The driver names each of its commits `fix(NN): …` from the ticket in the report. Then the gate, then one scoped review of those commits.
|
|
142
142
|
5. Findings that are open after the second review become questions of kind `final-finding`. There is no third review.
|
|
143
|
-
6. **Push.** With `--push` or `--unattended`, the driver pushes the reviewed tip once, with no force, and opens the PR with `gh`, ready for review. 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`). A push stops before any agent when no `pr` 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`.
|
|
143
|
+
6. **Push.** With `--push` or `--unattended`, the driver pushes the reviewed tip once, with no force, and opens the PR with `gh`, ready for review. 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`.
|
|
144
144
|
|
|
145
145
|
History rules:
|
|
146
146
|
|
|
@@ -24,7 +24,7 @@ has passed. The review rounds adapt superpowers' subagent-driven-development
|
|
|
24
24
|
Run the driver. It makes every choice of the run; you start it and relay its result.
|
|
25
25
|
|
|
26
26
|
1. In the PR worktree, run `sh <skill-dir>/run.sh` with the flags the operator gave, unchanged. `<skill-dir>` is the directory of this file. The driver needs `--gate` and `--spec`: ask the operator for a flag that is missing. A run can take hours: run the command in the background and wait for it to exit.
|
|
27
|
-
2. When it exits, relay `.agent/implement/summary.md` and the exit code: 0 is done, 1 is a BLOCKED ticket, 2 is parked on questions, 3 is invalid input, 4 is stopped by a CLI failure (after the fix, the same command resumes). Relay the lines the driver printed after the summary too.
|
|
27
|
+
2. When it exits, relay `.agent/implement/summary.md` and the exit code: 0 is done, 1 is a BLOCKED ticket, 2 is parked on questions, 3 is invalid input, 4 is stopped by a CLI failure (after the fix, the same command resumes). Relay the lines the driver printed after the summary too. With exit 0 and a PR URL such as `https://github.com/jesdi/demo/pull/61`, tell the operator to start the babysitter: run `/babysit-pr https://github.com/jesdi/demo/pull/61`.
|
|
28
28
|
3. With exit 2, and with exit 1 when the driver printed questions, show the operator those questions. When the operator answers, run the same command again with one `--answer <question id>=<option id>` for each answer.
|
|
29
29
|
|
|
30
30
|
Do not answer a question for the operator. Do not edit `.agent/implement/`, the code or the branches during a run.
|
|
@@ -22,6 +22,7 @@ import re
|
|
|
22
22
|
import shlex
|
|
23
23
|
import shutil
|
|
24
24
|
import subprocess
|
|
25
|
+
import sys
|
|
25
26
|
from pathlib import Path
|
|
26
27
|
|
|
27
28
|
import driver_agents
|
|
@@ -41,12 +42,34 @@ ROUNDS = 2 # the full review and the scoped one after the fix batch
|
|
|
41
42
|
REVIEW_DIFF = driver_agents.SKILL.parent / "review-diff" / "SKILL.md"
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
def
|
|
45
|
-
"""The SKILL.md of
|
|
46
|
-
|
|
45
|
+
def _installed(name: str) -> Path | None:
|
|
46
|
+
"""The SKILL.md of a skill: next to this skill, else in the skill folder of the Claude home or of the shared
|
|
47
|
+
home of Codex and OpenCode."""
|
|
47
48
|
claude = Path(os.environ.get("CLAUDE_CONFIG_DIR") or Path.home() / ".claude")
|
|
48
49
|
homes = (driver_agents.SKILL.parent, claude / "skills", Path.home() / ".agents" / "skills")
|
|
49
|
-
return next((home /
|
|
50
|
+
return next((home / name / "SKILL.md" for home in homes if (home / name / "SKILL.md").is_file()), None)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def pr_skill() -> Path | None:
|
|
54
|
+
"""The SKILL.md of the pr skill, which the PR body follows."""
|
|
55
|
+
return _installed("pr")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def pr_risk_skill() -> Path | None:
|
|
59
|
+
"""The SKILL.md of the pr-risk skill, which parses and validates the merge-risk block of the PR body."""
|
|
60
|
+
return _installed("pr-risk")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
PR_RISK_INSTALL = "`npx skills add jesdi/general-skills --skill pr-risk`"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _risk_errors(method: Path, body: str) -> str:
|
|
67
|
+
"""The errors of the merge-risk block of `body` as `pr-risk` names them, or "" when the block is valid."""
|
|
68
|
+
checked = OUT / FINAL / "pr-risk-check.md"
|
|
69
|
+
checked.write_text(body)
|
|
70
|
+
done = subprocess.run([sys.executable, str(method.parent / "merge_risk.py"), "validate", str(checked)],
|
|
71
|
+
capture_output=True, text=True)
|
|
72
|
+
return (done.stdout + done.stderr).strip() if done.returncode else ""
|
|
50
73
|
|
|
51
74
|
|
|
52
75
|
def _has_origin() -> bool:
|
|
@@ -62,6 +85,9 @@ def precondition_errors(push: bool) -> list[str]:
|
|
|
62
85
|
if push and not pr_skill():
|
|
63
86
|
errors.append("the pr skill is missing: the PR body follows it; install it with "
|
|
64
87
|
"`npx skills add mattpocock/skills --skill pr`, or run without --push and --unattended")
|
|
88
|
+
if push and not pr_risk_skill():
|
|
89
|
+
errors.append(f"the pr-risk skill is missing: the PR body carries its merge-risk block; install it with "
|
|
90
|
+
f"{PR_RISK_INSTALL}, or run without --push and --unattended")
|
|
65
91
|
if push and not _has_origin():
|
|
66
92
|
errors.append("the repository has no origin remote: --unattended and --push push the PR branch to origin; "
|
|
67
93
|
"add the remote, or run without them to stop before the push")
|
|
@@ -433,18 +459,31 @@ def _facts(run: Run, final: dict, tickets: list[Ticket]) -> str:
|
|
|
433
459
|
|
|
434
460
|
def _write_body(run: Run, final: dict, tickets: list[Ticket]) -> Path:
|
|
435
461
|
"""Write the PR body: what the pr-writer wrote with the method of the pr skill, then the facts of the run. A body
|
|
436
|
-
written for the reviewed tip is kept, so a PR that failed to open costs
|
|
462
|
+
written for the reviewed tip is kept when its merge-risk block still validates, so a PR that failed to open costs
|
|
463
|
+
no second agent."""
|
|
437
464
|
body, tip = OUT / FINAL / "pr-body.md", final["reviewed"]
|
|
438
|
-
|
|
465
|
+
method, risk, facts = pr_skill(), pr_risk_skill(), _facts(run, final, tickets)
|
|
466
|
+
if final["body"] == tip and body.is_file() and risk and not _risk_errors(risk, body.read_text()):
|
|
439
467
|
return body
|
|
440
|
-
method, facts = pr_skill(), _facts(run, final, tickets)
|
|
441
468
|
if not method:
|
|
442
469
|
raise Blocked("the pr skill is missing: the PR body follows it; install it with "
|
|
443
470
|
"`npx skills add mattpocock/skills --skill pr`")
|
|
471
|
+
if not risk:
|
|
472
|
+
raise Blocked(f"the pr-risk skill is missing: the PR body carries its merge-risk block; install it with "
|
|
473
|
+
f"{PR_RISK_INSTALL}")
|
|
444
474
|
values = {**_prompt_values(run), "start_sha": tip, "range": f"{final['onto']}..{tip}",
|
|
445
|
-
"gate": str(driver_gate.record_path(OUT / FINAL, tip)), "pr_skill": str(method),
|
|
446
|
-
|
|
447
|
-
|
|
475
|
+
"gate": str(driver_gate.record_path(OUT / FINAL, tip)), "pr_skill": str(method),
|
|
476
|
+
"pr_risk_skill": str(risk), "risk_errors": "", "facts": facts}
|
|
477
|
+
for round_ in range(2): # the pr-writer gets one more run with the errors of the block
|
|
478
|
+
with during("the PR body"):
|
|
479
|
+
report = run.read_only(FINAL, ".", run.pr, tip,
|
|
480
|
+
lambda: run.agent("pr-writer", FINAL, ".", values, fix_round=round_))
|
|
481
|
+
if not (errors := _risk_errors(risk, report["body"])):
|
|
482
|
+
break
|
|
483
|
+
values["risk_errors"] = (f"Your previous body has an invalid merge-risk block. Fix it with the pr-risk "
|
|
484
|
+
f"skill; its errors:\n{errors}\n")
|
|
485
|
+
else:
|
|
486
|
+
raise Blocked(f"the merge-risk block of the PR body is invalid after a second run of the pr-writer: {errors}")
|
|
448
487
|
body.write_text(f"{report['body'].strip()}\n\n{facts}")
|
|
449
488
|
run.state.update(lambda state: state["run"]["final"].update(body=tip))
|
|
450
489
|
return body
|
|
@@ -6,11 +6,12 @@ PR branch: {pr_branch}, at commit {start_sha}
|
|
|
6
6
|
Range: {range}
|
|
7
7
|
Gate record of the driver for {start_sha}: {gate}
|
|
8
8
|
PR method: {pr_skill}
|
|
9
|
+
Merge-risk block: {pr_risk_skill}
|
|
9
10
|
Facts of the run, which the driver puts after your body:
|
|
10
11
|
{facts}
|
|
11
12
|
|
|
12
|
-
Write the body of the PR of the range with the method of the pr skill in the file above: its sections, in its order. Read the spec, the tickets and the range first. The gate record and the tests of the range are the execution-based evidence; you cannot take screenshots. Do not repeat the facts of the run: the driver puts them after your body.
|
|
13
|
-
Do not commit. Leave the branch and the tree as you found them.
|
|
13
|
+
Write the body of the PR of the range with the method of the pr skill in the file above: its sections, in its order. Put the merge-risk block, as the pr-risk skill describes it, under `## Merge Danger`, and check it with `python3 merge_risk.py validate <body-file>` from that skill's folder. Read the spec, the tickets and the range first. The gate record and the tests of the range are the execution-based evidence; you cannot take screenshots. Do not repeat the facts of the run: the driver puts them after your body.
|
|
14
|
+
{risk_errors}Do not commit. Leave the branch and the tree as you found them.
|
|
14
15
|
|
|
15
16
|
Write one JSON report at {report} that matches this schema:
|
|
16
17
|
|
|
@@ -24,13 +24,14 @@ Interface choices (ticket 06):
|
|
|
24
24
|
"""
|
|
25
25
|
import json
|
|
26
26
|
import re
|
|
27
|
+
import shutil
|
|
27
28
|
import subprocess
|
|
28
29
|
import sys
|
|
29
30
|
from types import SimpleNamespace
|
|
30
31
|
|
|
31
32
|
import pytest
|
|
32
33
|
|
|
33
|
-
from test_cli import git, ticket
|
|
34
|
+
from test_cli import SKILL, git, ticket
|
|
34
35
|
from test_review import FABLE, HOOKED, ONE, OPUS, Review, finding, gate_rule, review
|
|
35
36
|
from test_stops import UNATTENDED, decisions, stage
|
|
36
37
|
from test_walk import impl, plan, tw
|
|
@@ -445,3 +446,113 @@ def test_unattended_with_a_blocked_ticket_pushes_nothing_and_exits_1(tmp_path):
|
|
|
445
446
|
assert rig.code == 1, rig.output()
|
|
446
447
|
assert rig.pushes() == [] and not rig.prs() and not ref(rig.origin, "refs/heads/feat/csv")
|
|
447
448
|
assert stage(rig) == {"stage": "implement", "status": "blocked", "blocked": ["01"]}
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
# ---------------------------------------------------------------- the merge-risk block of the PR body (ticket 15)
|
|
452
|
+
|
|
453
|
+
PR_RISK = SKILL.parent / "pr-risk"
|
|
454
|
+
BLOCK = ("door: two-way\nblast_radius: isolated\ntouches: [%s]\nrollback: revert\nverdict: auto\n"
|
|
455
|
+
"reasons:\n - \"Only prose changes\"\n")
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def risk_body(touches="docs"):
|
|
459
|
+
return ("## Summary\n\nCSV export.\n\n## Merge Danger\n\n```merge-risk v1\n" + BLOCK % touches + "```\n")
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def writer(body):
|
|
463
|
+
return {"report": dict(status="DONE", commits=[], files=[], concerns=[], body=body)}
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def risk_valid(tmp_path, body):
|
|
467
|
+
f = tmp_path / "check-body.md"
|
|
468
|
+
f.write_text(body)
|
|
469
|
+
return subprocess.run([sys.executable, str(PR_RISK / "merge_risk.py"), "validate", str(f)],
|
|
470
|
+
capture_output=True, text=True).returncode == 0
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def pushed_run(tmp_path, monkeypatch, steps, risk_in, gh_fails=False):
|
|
474
|
+
"""`implement-spec` as installed (a copy next to review-diff) with `pr` installed in `risk_in`'s home, and
|
|
475
|
+
`pr-risk` there too unless `risk_in` is None; the run is `--push`."""
|
|
476
|
+
rig = Final(tmp_path, ONE)
|
|
477
|
+
if gh_fails:
|
|
478
|
+
(tmp_path / "bin/gh").write_text("#!/bin/sh\necho gh down >&2\nexit 1\n")
|
|
479
|
+
skills = tmp_path / "installed/skills"
|
|
480
|
+
shutil.copytree(SKILL, skills / "implement-spec", ignore=shutil.ignore_patterns("__pycache__", ".pytest_cache", "test_*"))
|
|
481
|
+
shutil.copytree(SKILL.parent / "review-diff", skills / "review-diff", ignore=shutil.ignore_patterns("__pycache__"))
|
|
482
|
+
home = tmp_path / "home"
|
|
483
|
+
claude = tmp_path / "claude-home"
|
|
484
|
+
claude.mkdir(), home.mkdir()
|
|
485
|
+
where = {"claude": claude / "skills", "agents": home / ".agents/skills", None: claude / "skills"}[risk_in]
|
|
486
|
+
names = ["pr", "pr-risk"] if risk_in else ["pr"]
|
|
487
|
+
for name in names:
|
|
488
|
+
(where / name).mkdir(parents=True)
|
|
489
|
+
(where / name / "SKILL.md").write_text(f"---\nname: {name}\n---\n")
|
|
490
|
+
if risk_in:
|
|
491
|
+
for module in ("merge_risk.py", "merge_policy.py"):
|
|
492
|
+
shutil.copy(PR_RISK / module, where / "pr-risk" / module)
|
|
493
|
+
env = {**rig.env, "HOME": str(home), "CLAUDE_CONFIG_DIR": str(claude)}
|
|
494
|
+
(rig.rig / "plan.json").write_text(json.dumps(steps))
|
|
495
|
+
args = ["--tickets", ".agent/tickets", "--gate", str(rig.rig / "gate"), "--spec", "specs/csv/spec.md",
|
|
496
|
+
"--models", str(rig.models), "--runner", str(rig.rig / "run-agent"), "--push"]
|
|
497
|
+
rig.rerun = lambda: _rerun(rig, ["sh", str(skills / "implement-spec/run.sh"), *args], env)
|
|
498
|
+
rig.rerun()
|
|
499
|
+
return rig, where / "pr-risk/SKILL.md"
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def _rerun(rig, cmd, env):
|
|
503
|
+
proc = subprocess.run(cmd, cwd=rig.repo, env=env, text=True, capture_output=True, timeout=180)
|
|
504
|
+
rig.code, rig.out = proc.returncode, proc.stdout + proc.stderr
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
@pytest.mark.parametrize("home", ["claude", "agents"])
|
|
508
|
+
def test_the_pr_writer_gets_the_pr_risk_path_and_the_pr_opens_with_a_valid_block_above_the_facts(tmp_path, monkeypatch, home):
|
|
509
|
+
rig, skill = pushed_run(tmp_path, monkeypatch, plan(**{"final/pr-writer": [writer(risk_body())]}), home)
|
|
510
|
+
assert rig.code == 0, rig.out
|
|
511
|
+
(call,) = rig.final_calls("pr-writer")
|
|
512
|
+
assert str(skill) in call["prompt"]
|
|
513
|
+
(pr,) = rig.prs()
|
|
514
|
+
body = pr["body"]
|
|
515
|
+
assert risk_valid(tmp_path, body), body
|
|
516
|
+
assert 0 <= body.index("## Merge Danger") < body.index("## Tickets"), "the driver's facts come after the block"
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
def test_without_pr_risk_installed_the_run_is_blocked_with_the_install_command_and_pushes_nothing(tmp_path, monkeypatch):
|
|
520
|
+
rig, _ = pushed_run(tmp_path, monkeypatch, plan(), None)
|
|
521
|
+
assert rig.code != 0 and "pr-risk" in rig.out and "install" in rig.out.lower(), rig.out
|
|
522
|
+
assert re.search(r"npx [^\n]*pr-risk", rig.out), f"no executable install command: {rig.out}"
|
|
523
|
+
assert rig.pushes() == [] and not rig.prs() and not rig.final_calls("pr-writer")
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def test_an_invalid_first_body_runs_the_pr_writer_once_more_and_a_valid_second_body_opens_the_pr(tmp_path, monkeypatch):
|
|
527
|
+
steps = plan(**{"final/pr-writer": [writer(risk_body("styles")), writer(risk_body())]})
|
|
528
|
+
rig, _ = pushed_run(tmp_path, monkeypatch, steps, "claude")
|
|
529
|
+
assert rig.code == 0, rig.out
|
|
530
|
+
assert len(rig.final_calls("pr-writer")) == 2
|
|
531
|
+
(pr,) = rig.prs()
|
|
532
|
+
assert risk_valid(tmp_path, pr["body"]) and "styles" not in pr["body"].split("## Tickets")[0]
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
def test_an_invalid_second_body_blocks_the_run_and_opens_no_pr(tmp_path, monkeypatch):
|
|
536
|
+
steps = plan(**{"final/pr-writer": [writer(risk_body("styles")), writer(risk_body("styles")), writer(risk_body())]})
|
|
537
|
+
rig, _ = pushed_run(tmp_path, monkeypatch, steps, "claude")
|
|
538
|
+
assert rig.code != 0, rig.out
|
|
539
|
+
assert len(rig.final_calls("pr-writer")) == 2 and not rig.prs()
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def test_skill_md_step_2_tells_the_operator_to_start_the_babysitter_on_the_pr_url():
|
|
543
|
+
step = next(l for l in (SKILL / "SKILL.md").read_text().splitlines() if l.startswith("2. "))
|
|
544
|
+
assert "/babysit-pr https://github.com/jesdi/demo/pull/61" in step
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
def test_a_cached_body_that_no_longer_validates_is_rewritten_before_gh_pr_create_on_resume(tmp_path, monkeypatch):
|
|
548
|
+
steps = plan(**{"final/pr-writer": [writer(risk_body()), writer(risk_body())]})
|
|
549
|
+
rig, _ = pushed_run(tmp_path, monkeypatch, steps, "claude", gh_fails=True)
|
|
550
|
+
assert rig.code != 0 and "gh pr create failed" in rig.out and len(rig.final_calls("pr-writer")) == 1, rig.out
|
|
551
|
+
cached = rig.repo / ".agent/implement/final/pr-body.md"
|
|
552
|
+
cached.write_text(cached.read_text().replace("touches: [docs]", "touches: [styles]"))
|
|
553
|
+
(tmp_path / "bin/gh").write_text(GH)
|
|
554
|
+
rig.rerun()
|
|
555
|
+
assert rig.code == 0, rig.out
|
|
556
|
+
assert len(rig.final_calls("pr-writer")) == 2, "the invalid cached body was not rewritten"
|
|
557
|
+
(pr,) = rig.prs()
|
|
558
|
+
assert risk_valid(tmp_path, pr["body"].split("## Tickets")[0]) and "styles" not in pr["body"].split("## Tickets")[0]
|
|
@@ -95,8 +95,8 @@ def test_a_local_run_stops_before_the_push_and_a_push_rerun_pushes_and_opens_the
|
|
|
95
95
|
(pr,) = rig.prs()
|
|
96
96
|
assert pr["argv"][:10] == ["pr", "create", "--base", "main", "--head", "feat/csv", "--title", "csv spec",
|
|
97
97
|
"--body-file", ".agent/implement/final/pr-body.md"]
|
|
98
|
-
assert pr["body"].startswith("## Summary\n\nCSV export.\n\n##
|
|
99
|
-
assert [f"- {nn}: {row['sha'][:7]} {TITLES[nn]}" for nn, row in zip(order, rows)] == pr["body"].splitlines()[
|
|
98
|
+
assert pr["body"].startswith("## Summary\n\nCSV export.\n\n## Merge Danger\n"), "the pr-writer's body, then the facts"
|
|
99
|
+
assert [f"- {nn}: {row['sha'][:7]} {TITLES[nn]}" for nn, row in zip(order, rows)] == pr["body"].split("## Tickets\n\nOne commit per ticket, in merge order:\n\n")[1].splitlines()[:3]
|
|
100
100
|
(writer,) = rig.final_calls("pr-writer")
|
|
101
101
|
assert f"PR method: {pr_skill}\n" in writer["prompt"]
|
|
102
102
|
assert "Facts of the run, which the driver puts after your body:\n## Tickets" in writer["prompt"]
|
|
@@ -66,8 +66,8 @@ if role in ("reviewer", "correctness", "final-reviewer") and "report" not in ste
|
|
|
66
66
|
proofs = [dict(test=r.split()[1], file="demo/export.py", line=1, red=r) for r in reds]
|
|
67
67
|
step = dict(step, stdout="".join(r + "\\n" for r in reds), report=dict(
|
|
68
68
|
status="DONE", commits=[], files=[], concerns=[], findings=[], mutations=proofs))
|
|
69
|
-
if role == "pr-writer" and "report" not in step: # an unscripted pr-writer writes
|
|
70
|
-
step = dict(step, report=dict(status="DONE", commits=[], files=[], concerns=[], body="## Summary\\n\\nCSV export
|
|
69
|
+
if role == "pr-writer" and "report" not in step: # an unscripted pr-writer writes a summary and a valid merge-risk block
|
|
70
|
+
step = dict(step, report=dict(status="DONE", commits=[], files=[], concerns=[], body="## Summary\\n\\nCSV export.\\n\\n## Merge Danger\\n\\n```merge-risk v1\\ndoor: two-way\\nblast_radius: isolated\\ntouches: [docs]\\nrollback: revert\\nverdict: auto\\nreasons:\\n - \\"Only prose changes\\"\\n```\\n"))
|
|
71
71
|
for name in step.get("touch", []):
|
|
72
72
|
(rig / "sig" / name).touch()
|
|
73
73
|
for name in step.get("wait", []):
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pr-risk
|
|
3
|
+
description: >-
|
|
4
|
+
Merge-risk block of a PR body. Use when a PR body needs its ```merge-risk v1
|
|
5
|
+
block parsed or validated, with every error named.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# pr-risk
|
|
9
|
+
|
|
10
|
+
`python3 merge_risk.py parse <body-file>` prints the block as JSON, with an `errors` list.
|
|
11
|
+
`python3 merge_risk.py validate <body-file>` prints the errors and exits non-zero when the block is invalid.
|
|
12
|
+
|
|
13
|
+
The block is the one fenced ```` ```merge-risk v1 ```` block in the body. Keys: `door`, `blast_radius`,
|
|
14
|
+
`touches`, `rollback`, `verdict`, `reasons`.
|
|
15
|
+
|
|
16
|
+
`python3 merge_risk.py gate --body <file> --base <ref> --head <sha>` prints JSON with `verdict` (`auto | human`),
|
|
17
|
+
`reasons`, `categories` and `countedLines`. The policy is read from `origin/<base>`; the block's `verdict` is ignored.
|
|
18
|
+
|
|
19
|
+
## Writing the block
|
|
20
|
+
|
|
21
|
+
In a repo with `.merge-risk.json`, a hook denies `gh pr create` unless the body, passed with `--body` or
|
|
22
|
+
`--body-file`, holds a valid block. Write the body with `/pr`, then run `/pr-risk` to add the block.
|
|
23
|
+
|
|
24
|
+
Read `.merge-risk.json` for the policy, then fill the block from the diff:
|
|
25
|
+
|
|
26
|
+
- `door`: `one-way` if the change cannot be undone once shipped, else `two-way`.
|
|
27
|
+
- `blast_radius`: how far a bad change reaches: `isolated`, `module`, `service` or `consumers`.
|
|
28
|
+
- `touches`: inline list of categories the diff touches, e.g. `[docs, tests]`.
|
|
29
|
+
- `rollback`: `revert`, `revert+redeploy`, `data-fix` or `impossible`.
|
|
30
|
+
- `verdict`: `auto` only when the policy allows an agent to merge this change, else `human`.
|
|
31
|
+
- `reasons`: one quoted line per reason for the verdict.
|
|
32
|
+
|
|
33
|
+
Check it with `python3 merge_risk.py validate <body-file>` before opening the PR.
|