@jesdi/skills 0.0.88 → 0.0.90

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jesdi/skills",
3
- "version": "0.0.88",
3
+ "version": "0.0.90",
4
4
  "description": "jesdi's agent skills (content package consumed by @jesdi/skills-cli)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,7 +21,7 @@ Run with `/babysit-pr <pr-url>`. The PostToolUse hook in `hooks/post-pr-create.s
21
21
  2. `update-plan --base <base>` when the base moved; follow its plan (see Base moved). Every step uses `origin/<base>` of the PR (a stacked PR's parent), never `main`.
22
22
  3. `checks --wait-minutes <waitMinutes>` until the head is green, red, stalled (`CI stalled`) or empty (`no checks`). Green means every check passed.
23
23
  4. Red: `round start --op <id>` (keep the id), then the fix round below. Renew the lease each round and `lease check` before each push.
24
- 5. Green: run the gate (`pr-risk` `merge_risk.py gate`), then `judge`, then `merge-method` and `merge`. Pass the judge's verdict label to `merge --judge agree` (or `--judge 'same-model agree'` for fallback), never an output file path. The merge pins the head SHA the gate and judge saw.
24
+ 5. Green: run the gate (`pr-risk` `merge_risk.py gate`), then `judge`, then `merge-method` and `merge`. Pass the judge's label and risk to `merge --judge agree --judge-risk <risk>` (or `--judge 'same-model agree'` for fallback), never an output file path. The merge pins the head SHA the gate and judge saw, and hands off when the gate's or the judge's risk is above the repo's limit.
25
25
 
26
26
  ## A fix round
27
27
 
@@ -124,7 +124,8 @@ class CommentIdentities:
124
124
  return path.read_text() if path.exists() else None
125
125
 
126
126
  def remember(self, cid, body):
127
- kind = "lease" if LEASE.match(body) else "handoff" if HANDOFF.match(body) else None
127
+ kind = ("lease" if LEASE.match(body) else "handoff" if HANDOFF.match(body)
128
+ else "seen" if body.startswith(SEEN) else None)
128
129
  if kind:
129
130
  self.root.mkdir(parents=True, exist_ok=True, mode=0o700)
130
131
  try:
@@ -556,13 +557,14 @@ def owner_comments(repo, number):
556
557
  author = login_of(c)
557
558
  editor = (c.get("editor") or {}).get("login")
558
559
  kind = kinds[c["databaseId"]]
559
- if author == owner and kind == "lease":
560
- continue # creation receipt, independent of the lease's current body
560
+ if author == owner and kind in ("lease", "seen"):
561
+ continue # creation receipt of the babysitter's own state, independent of its current body
561
562
  if author == owner and not c["body"].startswith(MENTION):
562
- # An unknown edited lease may be a handoff with its heading removed.
563
- # Without a receipt it is safe to ignore only if no earlier instruction
564
- # could be replayed. This also supports leases from another host.
565
- if c.get("lastEditedAt") and (kind == "handoff" or not LEASE.match(c["body"])
563
+ # An unknown edited lease or seen comment may be a handoff with its heading
564
+ # removed. Without a receipt it is safe to ignore only if no earlier instruction
565
+ # could be replayed. This also supports state comments from another host.
566
+ own_state = LEASE.match(c["body"]) or c["body"].startswith(SEEN)
567
+ if c.get("lastEditedAt") and (kind == "handoff" or not own_state
566
568
  or editor != owner or instructions):
567
569
  handoff = handoff or "handoff comment edited, boundary unverifiable"
568
570
  continue # the babysitter's own lease comments and the owner's plain chatter
@@ -659,7 +661,7 @@ def load_merge_risk(base=None):
659
661
 
660
662
 
661
663
  JUDGE_NEEDS = ("base_policy", "classify_diff", "diff_stats", "FENCE")
662
- GATE_NEEDS = ("gate", "base_policy", "classify_diff", "diff_stats", "parse")
664
+ GATE_NEEDS = ("gate", "base_policy", "classify_diff", "diff_stats", "parse", "risk_floor")
663
665
 
664
666
 
665
667
  def missing_functions(mr, *names):
@@ -736,13 +738,15 @@ def judge(base, head, body_file, agent):
736
738
  return {"verdict": "disagree", "reason": "judge timeout", "sameModel": same_model}
737
739
  try:
738
740
  data = json.loads(answer)
739
- verdict, reason = data["verdict"], data.get("reason")
741
+ verdict, reason, risk = data["verdict"], data.get("reason"), data.get("risk")
740
742
  except (TypeError, ValueError, KeyError, AttributeError):
741
- verdict, reason = None, None
743
+ verdict, reason, risk = None, None, None
742
744
  if verdict == "agree" and not (isinstance(reason, str) and reason.strip()):
743
745
  verdict = None
746
+ if verdict == "agree" and not (type(risk) is int and 1 <= risk <= 10):
747
+ verdict = None
744
748
  if verdict == "agree":
745
- return {"verdict": "agree", "sameModel": same_model,
749
+ return {"verdict": "agree", "risk": risk, "sameModel": same_model,
746
750
  "label": "same-model agree" if same_model else "agree"}
747
751
  if verdict != "disagree":
748
752
  reason = "invalid answer"
@@ -839,7 +843,8 @@ def handoff(repo, number, reason, ci, rounds, gate, judge_line, fix_log, extra="
839
843
  "next": "In Claude Code send PushNotification, then end the turn. Otherwise end the turn now."}))
840
844
 
841
845
 
842
- def merge_cmd(repo, number, sha, body_file, policy, judge_label, approved, session=None, base=None):
846
+ def merge_cmd(repo, number, sha, body_file, policy, judge_label, approved, session=None, base=None,
847
+ judge_risk=None):
843
848
  pr = json.loads(gh("api", f"repos/{repo}/pulls/{number}"))
844
849
  if base not in (None, pr["base"]["ref"]):
845
850
  fail(f"--base {base} is not the PR's base {pr['base']['ref']}")
@@ -870,10 +875,17 @@ def merge_cmd(repo, number, sha, body_file, policy, judge_label, approved, sessi
870
875
  mr = load_merge_risk(base)
871
876
  if old := missing_functions(mr, *GATE_NEEDS):
872
877
  stop(f"pr-risk is too old: {', '.join(old)}")
873
- result = mr.gate(body, base, sha) # trusted policy, recomputed for this sha
878
+ public = pr["base"].get("repo", {}).get("private") is not True # unknown counts as public
879
+ result = mr.gate(body, base, sha, public) # trusted policy, recomputed for this sha
874
880
  if result["verdict"] != "auto":
875
- gate = "gate: human"
881
+ gate = f"gate: human, risk {result['risk']}/10"
876
882
  stop(f"gate is human: {'; '.join(result['reasons'])}")
883
+ gate = f"gate: passed, risk {result['risk']}/10"
884
+ if judge_risk is None:
885
+ stop("judge risk missing: pass --judge-risk")
886
+ if judge_risk > result["maxAutoRisk"]:
887
+ stop(f"judge risk {judge_risk} > max auto risk {result['maxAutoRisk']}")
888
+ risk_line = f"risk {max(result['risk'], judge_risk)}/10 (auto up to {result['maxAutoRisk']}), "
877
889
  else:
878
890
  judge_line = f"owner approved {approved}"
879
891
  commits = pr_commits(repo, number)
@@ -924,8 +936,8 @@ def merge_cmd(repo, number, sha, body_file, policy, judge_label, approved, sessi
924
936
  fail(f"head moved since the gate saw {sha}: gate again")
925
937
  stop(f"merge blocked: {'approval required' if 'approv' in err.lower() else err}")
926
938
  pr = Pr(repo, number)
927
- pr.post("🤖 Merged by babysit-pr: gate passed, " + (
928
- f"judge {judge_label}" if approved is None else f"owner approved {approved}"))
939
+ pr.post("🤖 Merged by babysit-pr: " + (
940
+ f"{risk_line}gate passed, judge {judge_label}" if approved is None else f"owner approved {approved}"))
929
941
  if session:
930
942
  release(pr, session)
931
943
 
@@ -968,6 +980,7 @@ def main():
968
980
  mg.add_argument("--sha", required=True)
969
981
  mg.add_argument("--body", required=True)
970
982
  mg.add_argument("--judge")
983
+ mg.add_argument("--judge-risk", type=int, choices=range(1, 11), metavar="1-10")
971
984
  mg.add_argument("--approved-sha")
972
985
  mg.add_argument("--base")
973
986
  for p in (mg, hp):
@@ -991,7 +1004,7 @@ def main():
991
1004
  elif a.cmd == "merge":
992
1005
  if not (a.judge or a.approved_sha):
993
1006
  ap.error("merge needs --judge or --approved-sha")
994
- merge_cmd(a.repo, a.pr, a.sha, a.body, a.policy, a.judge, a.approved_sha, a.session, a.base)
1007
+ merge_cmd(a.repo, a.pr, a.sha, a.body, a.policy, a.judge, a.approved_sha, a.session, a.base, a.judge_risk)
995
1008
  elif a.cmd == "handoff":
996
1009
  handoff(a.repo, a.pr, a.reason, a.ci, a.rounds, a.gate, a.judge, Path(a.fix_log).read_text(), session=a.session)
997
1010
  elif a.cmd == "update-plan":
@@ -155,7 +155,8 @@ def api(args):
155
155
  "user": {"login": st["user"]},
156
156
  "title": st.get("title", ""), "body": st.get("body", ""),
157
157
  "head": {"sha": st.get("head_sha", "head1"), "ref": st.get("head_ref", "feature")},
158
- "base": {"ref": st.get("base_ref", "main"), **({"sha": st["base_sha"]} if "base_sha" in st else {})}}, jq, include)
158
+ "base": {"ref": st.get("base_ref", "main"), "repo": {"private": st.get("private", False)},
159
+ **({"sha": st["base_sha"]} if "base_sha" in st else {})}}, jq, include)
159
160
  if path == "pulls" and method == "GET" and fields.get("state") == "open":
160
161
  log(False)
161
162
  return emit([{"number": p["number"], "base": {"ref": p["base"]}} for p in st.get("open_prs", [])
@@ -2,8 +2,12 @@ You are an independent judge of merge risk. You see only the input below: the di
2
2
  files, the names and line counts of the other files, the PR's merge-risk block and the categories
3
3
  of the diff. You have no other context, and you must not assume any.
4
4
 
5
- Decide whether an agent may merge this change without a human. Any doubt is `disagree`: public
6
- interfaces, auth, money, data loss, anything hard to revert, or a block that understates the diff.
5
+ Score the risk of merging this change from 1 to 10: 1 is a typo fix nobody can break, 10 is a
6
+ change that can lose data, money or access, or cannot be undone. Weigh public interfaces, auth,
7
+ money, data loss, anything hard to revert, and a block that understates the diff. Any doubt raises
8
+ the score.
9
+
10
+ Then decide whether an agent may merge it without a human. Any doubt is `disagree`.
7
11
 
8
12
  Answer with one JSON object and nothing else:
9
- {"verdict": "agree" | "disagree", "reason": "<one short sentence>"}
13
+ {"verdict": "agree" | "disagree", "risk": <whole number 1-10>, "reason": "<one short sentence>"}
@@ -8,6 +8,7 @@ file is the PR body (summary + merge-risk block). Exit 0, one JSON object on std
8
8
  reason the handoff reason when disagree: "judge: <judge reason>", or "judge timeout"
9
9
  sameModel true when the other vendor's CLI was missing and a fresh agent of the same vendor judged
10
10
  label what the merge comment shows after "judge ": "agree" | "same-model agree" (agree only)
11
+ risk the judge's risk, 1-10 (agree only); an agree without a whole risk from 1 to 10 is disagree
11
12
  Env BABYSIT_JUDGE_TIMEOUT overrides the 10 minute limit, in seconds.
12
13
 
13
14
  The judge CLIs are fakes on PATH (`codex`, `claude`). A fake logs {name, argv, stdin} to
@@ -40,7 +41,7 @@ print(ans)
40
41
  sys.exit(int(os.environ.get("FAKE_EXIT_{NAME}", "0")))
41
42
  """
42
43
 
43
- AGREE = '{"verdict": "agree", "reason": "small and reversible"}'
44
+ AGREE = '{"verdict": "agree", "risk": 2, "reason": "small and reversible"}'
44
45
 
45
46
 
46
47
  def git(repo, *args):
@@ -69,7 +70,7 @@ door: two-way
69
70
  blast_radius: isolated
70
71
  touches: [logic]
71
72
  rollback: revert
72
- verdict: auto
73
+ risk: 1
73
74
  reasons:
74
75
  - "BLOCK-REASON-TEXT small and reversible"
75
76
  ```
@@ -82,7 +83,7 @@ class Judge:
82
83
  self.repo = tmp_path / "repo"
83
84
  self.repo.mkdir()
84
85
  git(self.repo, "init", "-q", "-b", "work")
85
- base = commit(self.repo, {"README.md": "hi\n", ".merge-risk.json": '{"agentMerge": true}'},
86
+ base = commit(self.repo, {"README.md": "hi\n", ".merge-risk.json": '{"maxAutoRisk": 5}'},
86
87
  "base")
87
88
  git(self.repo, "update-ref", "refs/remotes/origin/main", base)
88
89
  self.head = commit(self.repo, {
@@ -231,7 +232,12 @@ def test_only_a_plain_reasoned_agree_is_agree(tmp_path):
231
232
  for answer in ('{"verdict": "auto", "reason": "ok"}', '{"verdict": "human", "reason": "ok"}',
232
233
  '{"verdict": "approve", "reason": "ok"}', '{"verdict": "AGREE", "reason": "ok"}',
233
234
  '{"verdict": true, "reason": "ok"}', '{"verdict": "agree"}',
234
- '{"verdict": "agree", "reason": ""}', '["agree"]', 'null'):
235
+ '{"verdict": "agree", "reason": ""}', '["agree"]', 'null',
236
+ '{"verdict": "agree", "reason": "ok"}', '{"verdict": "agree", "risk": 0, "reason": "ok"}',
237
+ '{"verdict": "agree", "risk": 11, "reason": "ok"}',
238
+ '{"verdict": "agree", "risk": "2", "reason": "ok"}',
239
+ '{"verdict": "agree", "risk": 2.5, "reason": "ok"}',
240
+ '{"verdict": "agree", "risk": true, "reason": "ok"}'):
235
241
  sub = tmp_path / f"case{len(list(tmp_path.iterdir()))}"
236
242
  sub.mkdir()
237
243
  out = Judge(sub).run(answer)
@@ -240,16 +246,16 @@ def test_only_a_plain_reasoned_agree_is_agree(tmp_path):
240
246
 
241
247
 
242
248
  def test_agree_on_a_human_gate_block_never_becomes_auto(tmp_path):
243
- """The gate said human (block verdict: human); the judge agreeing must not turn that into an
249
+ """The gate said human (block risk: 8); the judge agreeing must not turn that into an
244
250
  auto: the result is only agree/disagree with the known keys, never an auto or human verdict."""
245
251
  j = Judge(tmp_path)
246
- j.body.write_text(BODY.replace("verdict: auto", "verdict: human"))
252
+ j.body.write_text(BODY.replace("risk: 1", "risk: 8"))
247
253
  out = j.run(AGREE)
248
254
  assert out["verdict"] == "agree"
249
- assert set(out) <= {"verdict", "sameModel", "label"}, out
255
+ assert set(out) <= {"verdict", "risk", "sameModel", "label"}, out
250
256
  assert "auto" not in json.dumps(out) and "human" not in json.dumps(out)
251
257
  c = j.calls()[0]
252
- assert "verdict: human" in json.dumps(c["argv"]) + c["stdin"]
258
+ assert "risk: 8" in json.dumps(c["argv"]) + c["stdin"]
253
259
 
254
260
 
255
261
  def test_a_judge_that_agrees_but_exits_nonzero_falls_back(tmp_path):
@@ -270,7 +276,7 @@ def test_a_judge_that_agrees_but_exits_nonzero_falls_back(tmp_path):
270
276
 
271
277
 
272
278
  def test_a_gate_human_stays_human_whatever_the_judge_says(tmp_path):
273
- """The block's advisory `verdict: auto` is ignored by the gate. With a one-way door the gate
279
+ """The block's advisory `risk: 1` is ignored by the gate. With a one-way door the gate
274
280
  says human; a judge agree on that same input is only agree and carries nothing that could
275
281
  turn the gate's human into auto."""
276
282
  j = Judge(tmp_path)
@@ -282,5 +288,5 @@ def test_a_gate_human_stays_human_whatever_the_judge_says(tmp_path):
282
288
  assert json.loads(gate.stdout)["verdict"] == "human", gate.stdout + gate.stderr
283
289
  out = j.run(AGREE)
284
290
  assert out["verdict"] == "agree"
285
- assert set(out) <= {"verdict", "sameModel", "label"}, out
291
+ assert set(out) <= {"verdict", "risk", "sameModel", "label"}, out
286
292
  assert "auto" not in json.dumps(out) and "human" not in json.dumps(out)
@@ -30,7 +30,7 @@ with open(os.environ["FAKE_LOG"], "a") as log:
30
30
  "session": {k: os.environ.get(k) for k in
31
31
  ("GIT_DIR", "CLAUDE_PROJECT_DIR", "CODEX_THREAD_ID", "CLAUDECODE")},
32
32
  "stdin": sys.stdin.read()}) + "\\n")
33
- print(json.dumps({"verdict": "disagree" if leaked else "agree",
33
+ print(json.dumps({"verdict": "disagree" if leaked else "agree", "risk": 1,
34
34
  "reason": "checkout instructions loaded" if leaked else "isolated"}))
35
35
  ''')
36
36
  result = j.run(agent=agent, TMPDIR=j.repo, GIT_DIR=j.repo / ".git",
@@ -94,7 +94,7 @@ def test_merge_after_takeover_leaves_the_new_holders_labels_and_reports_it(tmp_p
94
94
  w = world(tmp_path, repo_labels=["babysitting", "needs-human"])
95
95
  assert w.run("acquire", "s1").returncode == 0
96
96
  takeover_before_label_write(w)
97
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--session", "s1")
97
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1", "--session", "s1")
98
98
  assert w.github().get("taken"), "the takeover never fired"
99
99
  assert len(w.github()["merges"]) == 1
100
100
  assert holder(w) == ["s2"]
@@ -10,7 +10,8 @@ Interface under test (defined here):
10
10
  is recomputed for SHA with the trusted merge_risk and the policy committed on origin/<base>.
11
11
  --judge agree merges only when that gate is auto; else it hands off with the gate's reasons.
12
12
  Merges with `gh pr merge N --<method> --match-head-commit SHA`, never `--auto`, then posts
13
- `🤖 Merged by babysit-pr: gate passed, judge <label>` and exits 0.
13
+ `🤖 Merged by babysit-pr: risk <n>/10 (auto up to <limit>), gate passed, judge <label>` and
14
+ exits 0. <n> is the higher of the gate's risk and --judge-risk.
14
15
  --approved-sha is the owner's `@babysitter merge <sha>` approval (instead of --judge): it
15
16
  needs an owner comment `@babysitter merge <sha>` for it (else nothing merges and it hands
16
17
  off with "merge approval must name a commit: @babysitter merge <sha>"), and is honoured only
@@ -44,7 +45,7 @@ door: two-way
44
45
  blast_radius: isolated
45
46
  touches: [logic, tests]
46
47
  rollback: revert
47
- verdict: auto
48
+ risk: 1
48
49
  reasons:
49
50
  - "small and reversible"
50
51
  ```
@@ -82,10 +83,10 @@ def world(tmp_path, head="a1b2c3d", commits=None, body=BLOCK, policy=None, appro
82
83
  green = [{"name": "ci", "status": "completed", "conclusion": "success",
83
84
  "created_at": iso(T), "started_at": iso(T)}]
84
85
  st.update(head_sha=head, title="feat: parse empty rows", body=body, # the live PR body is the gated one
85
- commits=commits or [commit(head)], **{"check_runs": {head: green}, **state})
86
+ commits=commits or [commit(head)], **{"check_runs": {head: green}, "private": True, **state})
86
87
  w.state.write_text(json.dumps(st))
87
88
  (tmp_path / "body.md").write_text(body)
88
- checkout(w, [c["sha"] for c in st["commits"]], policy or {"agentMerge": True})
89
+ checkout(w, [c["sha"] for c in st["commits"]], policy or {"maxAutoRisk": 5})
89
90
  if policy: # the same policy also feeds `--policy`, the merge method
90
91
  w.policy_file = tmp_path / "policy.json"
91
92
  w.policy_file.write_text(json.dumps(policy))
@@ -117,14 +118,14 @@ def handoffs(w):
117
118
 
118
119
  def test_stale_gate_sha_fails_and_nothing_merges(tmp_path):
119
120
  w = world(tmp_path, head="f0e1d2c", commits=[commit("a1b2c3d"), commit("f0e1d2c", author="alice")])
120
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
121
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
121
122
  assert p.returncode != 0
122
123
  assert "gate again" in p.output
123
124
  assert w.github().get("merges", []) == []
124
125
  assert not any("Merged by babysit-pr" in b for b in comments(w))
125
126
 
126
127
 
127
- @pytest.mark.parametrize("extra", [("--judge", "agree"), ("--approved-sha", "a1b2c3d")])
128
+ @pytest.mark.parametrize("extra", [("--judge", "agree", "--judge-risk", "1"), ("--approved-sha", "a1b2c3d")])
128
129
  def test_head_with_no_checks_hands_off_and_nothing_merges(tmp_path, extra):
129
130
  w = world(tmp_path, check_runs={}, approvals=("a1b2c3d",))
130
131
  p = merge(w, tmp_path, "a1b2c3d", *extra)
@@ -136,18 +137,18 @@ def test_head_with_no_checks_hands_off_and_nothing_merges(tmp_path, extra):
136
137
 
137
138
  def test_default_method_is_rebase_pinned_to_the_gated_sha_and_commented(tmp_path):
138
139
  w = world(tmp_path)
139
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
140
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
140
141
  assert p.returncode == 0, p.output
141
142
  [m] = w.github()["merges"]
142
143
  assert (m["number"], m["method"], m["match"], m["auto"]) == ("58", "rebase", "a1b2c3d", False)
143
- assert "🤖 Merged by babysit-pr: gate passed, judge agree" in comments(w)
144
+ assert "🤖 Merged by babysit-pr: risk 4/10 (auto up to 5), gate passed, judge agree" in comments(w)
144
145
 
145
146
 
146
147
  def test_same_model_judge_shows_in_the_merge_comment(tmp_path):
147
148
  w = world(tmp_path)
148
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "same-model agree")
149
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "same-model agree", "--judge-risk", "1")
149
150
  assert p.returncode == 0, p.output
150
- assert "🤖 Merged by babysit-pr: gate passed, judge same-model agree" in comments(w)
151
+ assert "🤖 Merged by babysit-pr: risk 4/10 (auto up to 5), gate passed, judge same-model agree" in comments(w)
151
152
 
152
153
 
153
154
  def test_merge_method_is_merge_when_the_branch_has_a_merge_commit(tmp_path):
@@ -155,7 +156,7 @@ def test_merge_method_is_merge_when_the_branch_has_a_merge_commit(tmp_path):
155
156
  p = cli(w, "merge-method", "--repo", "jesdi/demo", "--pr", "58")
156
157
  assert p.returncode == 0, p.output
157
158
  assert json.loads(p.stdout) == {"method": "merge"}
158
- assert merge(w, tmp_path, "a1b2c3d", "--judge", "agree").returncode == 0
159
+ assert merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1").returncode == 0
159
160
  assert w.github()["merges"][0]["method"] == "merge"
160
161
 
161
162
 
@@ -166,8 +167,8 @@ def test_merge_method_is_rebase_for_a_linear_branch(tmp_path):
166
167
 
167
168
 
168
169
  def test_squash_policy_keeps_the_title_summary_and_block_digest(tmp_path):
169
- w = world(tmp_path, policy={"agentMerge": True, "mergeMethod": "squash"})
170
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
170
+ w = world(tmp_path, policy={"maxAutoRisk": 5, "mergeMethod": "squash"})
171
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
171
172
  assert p.returncode == 0, p.output
172
173
  [m] = w.github()["merges"]
173
174
  assert m["method"] == "squash"
@@ -180,7 +181,7 @@ def test_squash_policy_keeps_the_title_summary_and_block_digest(tmp_path):
180
181
  def test_required_approval_failure_hands_off(tmp_path):
181
182
  w = world(tmp_path, merge_error="At least 1 approving review is required by reviewers "
182
183
  "with write access.")
183
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
184
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
184
185
  assert p.returncode != 0
185
186
  [h] = handoffs(w)
186
187
  assert h.startswith("## 🧑 Needs human: merge blocked: approval required")
@@ -249,9 +250,9 @@ def test_approval_voided_by_a_rebase_hands_off(tmp_path):
249
250
 
250
251
 
251
252
  @pytest.mark.parametrize("method", [None, "squash", "merge", "rebase"])
252
- @pytest.mark.parametrize("extra", [("--judge", "agree"), ("--approved-sha", "a1b2c3d")])
253
+ @pytest.mark.parametrize("extra", [("--judge", "agree", "--judge-risk", "1"), ("--approved-sha", "a1b2c3d")])
253
254
  def test_auto_merge_is_never_requested(tmp_path, extra, method):
254
- policy = {"agentMerge": True, "mergeMethod": method} if method else None
255
+ policy = {"maxAutoRisk": 5, "mergeMethod": method} if method else None
255
256
  w = world(tmp_path, policy=policy, approvals=("a1b2c3d",))
256
257
  assert merge(w, tmp_path, "a1b2c3d", *extra).returncode == 0
257
258
  [m] = w.github()["merges"]
@@ -4,7 +4,7 @@ from test_merge_and_handoff import merge, world
4
4
 
5
5
  def test_remote_base_ahead_of_the_local_ref_merges_nothing(tmp_path):
6
6
  w = world(tmp_path, base_sha="f" * 40) # origin/main locally is another commit
7
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
7
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
8
8
  assert p.returncode != 0
9
9
  assert "gate again" in p.output
10
10
  assert w.github().get("merges", []) == []
@@ -17,26 +17,61 @@ def merged(w):
17
17
  return w.github().get("merges", [])
18
18
 
19
19
 
20
- def test_agent_merge_off_hands_off_with_the_policy_as_the_reason(tmp_path):
21
- w = world(tmp_path, policy={"agentMerge": False})
22
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
20
+ def test_max_auto_risk_0_hands_off_with_the_policy_as_the_reason(tmp_path):
21
+ w = world(tmp_path, policy={"maxAutoRisk": 0})
22
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
23
23
  assert p.returncode != 0
24
24
  assert merged(w) == []
25
25
  [h] = handoffs(w)
26
- assert "agentMerge" in h.splitlines()[0]
26
+ assert "max auto risk 0" in h.splitlines()[0]
27
27
  assert not any("Merged by babysit-pr" in c["body"] for c in w.github()["comments"])
28
28
 
29
29
 
30
30
  def test_one_way_door_hands_off_although_the_block_says_auto(tmp_path):
31
- assert "verdict: auto" in BLOCK
31
+ assert "risk: 1" in BLOCK
32
32
  w = world(tmp_path, body=BLOCK.replace("door: two-way", "door: one-way"))
33
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
33
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
34
34
  assert p.returncode != 0
35
35
  assert merged(w) == []
36
36
  [h] = handoffs(w)
37
37
  assert "door one-way" in h.splitlines()[0]
38
38
 
39
39
 
40
+ def test_judge_risk_above_the_limit_hands_off(tmp_path):
41
+ w = world(tmp_path)
42
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "6")
43
+ assert p.returncode != 0
44
+ assert merged(w) == []
45
+ [h] = handoffs(w)
46
+ assert h.startswith("## 🧑 Needs human: judge risk 6 > max auto risk 5")
47
+
48
+
49
+ def test_agree_without_a_judge_risk_hands_off(tmp_path):
50
+ w = world(tmp_path)
51
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
52
+ assert p.returncode != 0
53
+ assert merged(w) == []
54
+ [h] = handoffs(w)
55
+ assert h.startswith("## 🧑 Needs human: judge risk missing")
56
+
57
+
58
+ def test_public_repo_caps_the_limit_at_3(tmp_path):
59
+ w = world(tmp_path, private=False) # the policy allows 5; the diff is logic, risk 4
60
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
61
+ assert p.returncode != 0
62
+ assert merged(w) == []
63
+ [h] = handoffs(w)
64
+ assert "risk 4 > max auto risk 3 (public repo)" in h.splitlines()[0]
65
+
66
+
67
+ def test_owner_approval_merges_a_one_way_door(tmp_path):
68
+ body = BLOCK.replace("door: two-way", "door: one-way")
69
+ w = world(tmp_path, head=HEAD, body=body, approvals=(HEAD,))
70
+ p = merge(w, tmp_path, HEAD, "--approved-sha", HEAD)
71
+ assert p.returncode == 0, p.output
72
+ assert len(merged(w)) == 1
73
+
74
+
40
75
  def test_approved_sha_without_an_owner_comment_approves_nothing(tmp_path):
41
76
  w = world(tmp_path)
42
77
  p = merge(w, tmp_path, "a1b2c3d", "--approved-sha", "a1b2c3d")
@@ -48,7 +83,7 @@ def test_approved_sha_without_an_owner_comment_approves_nothing(tmp_path):
48
83
 
49
84
  def test_owner_comment_with_a_sha_prefix_merges_a_human_verdict_pinned_to_the_head(tmp_path):
50
85
  # the policy gives human, so only the owner's comment can merge; the caller passes the full SHA
51
- w = world(tmp_path, head=HEAD, policy={"agentMerge": False}, approvals=(HEAD[:7],))
86
+ w = world(tmp_path, head=HEAD, policy={"maxAutoRisk": 0}, approvals=(HEAD[:7],))
52
87
  p = merge(w, tmp_path, HEAD, "--approved-sha", HEAD)
53
88
  assert p.returncode == 0, p.output
54
89
  [m] = merged(w)
@@ -83,7 +118,7 @@ def test_judge_with_a_trusted_pr_risk_lacking_classify_diff_hands_off(tmp_path):
83
118
  def test_merge_with_a_trusted_pr_risk_lacking_classify_diff_hands_off(tmp_path):
84
119
  w = world(tmp_path, pr_risk=False)
85
120
  old_install(w.home / ".claude" / "skills" / "pr-risk", ["classify_diff"])
86
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
121
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
87
122
  assert p.returncode != 0
88
123
  assert "AttributeError" not in p.output
89
124
  assert merged(w) == []
@@ -93,8 +128,8 @@ def test_merge_with_a_trusted_pr_risk_lacking_classify_diff_hands_off(tmp_path):
93
128
 
94
129
  def test_gate_reads_the_diff_of_the_sha_it_merges_not_the_checked_out_head(tmp_path):
95
130
  # the checkout sits on `work` (= origin/main, an empty diff); only HEAD's own commit adds a counted line
96
- w = world(tmp_path, policy={"agentMerge": True, "judgeMaxLines": 0})
97
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
131
+ w = world(tmp_path, policy={"maxAutoRisk": 5, "judgeMaxLines": 0})
132
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
98
133
  assert p.returncode != 0
99
134
  assert merged(w) == []
100
135
  [h] = handoffs(w)
@@ -111,14 +146,14 @@ def live_body_differs(tmp_path, live, *extra):
111
146
 
112
147
 
113
148
  def test_saved_body_does_not_stand_in_for_a_one_way_live_body(tmp_path):
114
- w, p = live_body_differs(tmp_path, BLOCK.replace("door: two-way", "door: one-way"), "--judge", "agree")
149
+ w, p = live_body_differs(tmp_path, BLOCK.replace("door: two-way", "door: one-way"), "--judge", "agree", "--judge-risk", "1")
115
150
  assert p.returncode != 0
116
151
  assert merged(w) == []
117
152
  assert not any("Merged by babysit-pr" in c["body"] for c in w.github()["comments"])
118
153
 
119
154
 
120
155
  def test_saved_body_does_not_stand_in_for_an_empty_live_body(tmp_path):
121
- w, p = live_body_differs(tmp_path, "", "--judge", "agree")
156
+ w, p = live_body_differs(tmp_path, "", "--judge", "agree", "--judge-risk", "1")
122
157
  assert p.returncode != 0
123
158
  assert merged(w) == []
124
159
  assert not any("Merged by babysit-pr" in c["body"] for c in w.github()["comments"])
@@ -129,7 +164,7 @@ def test_open_prs_into_the_head_branch_hand_off_and_nothing_merges(tmp_path):
129
164
  w = world(tmp_path, head_ref="feat/new-cart",
130
165
  open_prs=[{"number": 57, "base": "feat/new-cart"}, {"number": 60, "base": "main"},
131
166
  {"number": 61, "base": "feat/new-cart"}])
132
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
167
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
133
168
  assert p.returncode != 0
134
169
  assert merged(w) == []
135
170
  [h] = handoffs(w)
@@ -138,6 +173,6 @@ def test_open_prs_into_the_head_branch_hand_off_and_nothing_merges(tmp_path):
138
173
 
139
174
  def test_open_prs_into_other_branches_do_not_block_the_merge(tmp_path):
140
175
  w = world(tmp_path, head_ref="feat/new-cart", open_prs=[{"number": 60, "base": "main"}])
141
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
176
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
142
177
  assert p.returncode == 0, p.output
143
178
  assert len(merged(w)) == 1
@@ -41,7 +41,7 @@ def test_handoff_retry_cannot_end_resumed_session(tmp_path):
41
41
  def test_stale_session_cannot_merge_or_release_new_holder(tmp_path):
42
42
  w = world(tmp_path)
43
43
  assert w.run("acquire", "s2").returncode == 0
44
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--session", "s1")
44
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1", "--session", "s1")
45
45
  assert p.returncode != 0, p.output
46
46
  assert w.github().get("merges", []) == []
47
47
  assert handoffs(w) == []
@@ -52,7 +52,7 @@ def test_sessionless_merge_cannot_adopt_a_lease(tmp_path):
52
52
  w = world(tmp_path)
53
53
  assert w.run("acquire", "s2").returncode == 0
54
54
  before = w.github()
55
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
55
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1")
56
56
  assert p.returncode != 0, p.output
57
57
  assert "--session" in p.output
58
58
  assert w.github() == before
@@ -110,7 +110,7 @@ def test_handoff_rechecks_ownership_after_posting_comment(tmp_path):
110
110
  def test_merge_with_own_session_ends_only_its_lease(tmp_path):
111
111
  w = world(tmp_path)
112
112
  assert w.run("acquire", "s1").returncode == 0
113
- p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--session", "s1")
113
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree", "--judge-risk", "1", "--session", "s1")
114
114
  assert p.returncode == 0, p.output
115
115
  assert len(w.github()["merges"]) == 1
116
116
  assert w.active_leases() == []
@@ -51,7 +51,7 @@ if fire:
51
51
  check=True, stdout=subprocess.DEVNULL)
52
52
  if kind == "successor":
53
53
  subprocess.run([*base, "merge", *where, "--sha", "a1b2c3d", "--body", {body!r},
54
- "--judge", "agree", "--session", "s2"], check=True, stdout=subprocess.DEVNULL)
54
+ "--judge", "agree", "--judge-risk", "1", "--session", "s2"], check=True, stdout=subprocess.DEVNULL)
55
55
  subprocess.run([*base, "lease", "release", *where, "--session", "s2"], stdout=subprocess.DEVNULL)
56
56
  st = json.loads(state.read_text())
57
57
  st["taken"] = True
@@ -24,3 +24,32 @@ def test_removing_handoff_heading_does_not_reactivate_approval(tmp_path, editor)
24
24
  out = read(w)
25
25
  assert out["handoff"] == "handoff comment edited, boundary unverifiable"
26
26
  assert out["instructions"] == []
27
+
28
+
29
+ SEEN_BODY = '<!-- babysit-pr seen -->\n{"a1b2c3d#ci": "2026-01-01T00:00:00Z"}'
30
+
31
+
32
+ def test_the_babysitters_edited_seen_comment_does_not_block_an_approval(tmp_path):
33
+ """`checks` edits its own seen comment on every run; that edit is no forged handoff."""
34
+ w = World(tmp_path, comments=[
35
+ comment(1001, "jesdi", SEEN_BODY, at=T - 20 * MIN, editor="jesdi"),
36
+ comment(1002, "jesdi", "@babysitter merge a1b2c3d", at=T - 10 * MIN)])
37
+ state = w.github()
38
+ state["commits"] = [{"sha": "a1b2c3d", "date": iso(T - 30 * MIN)}]
39
+ w.state.write_text(json.dumps(state))
40
+ out = read(w)
41
+ assert out["handoff"] is None
42
+ assert [i["text"] for i in out["instructions"]] == ["@babysitter merge a1b2c3d"]
43
+
44
+
45
+ def test_a_handoff_edited_to_look_like_a_seen_comment_is_still_flagged(tmp_path):
46
+ w = World(tmp_path, comments=[
47
+ comment(1001, "jesdi", "@babysitter merge a1b2c3d", at=T - 20 * MIN),
48
+ comment(1002, "jesdi", HANDOFF_BODY, at=T - 10 * MIN)])
49
+ state = w.github()
50
+ state["commits"] = [{"sha": "a1b2c3d", "date": iso(T - 30 * MIN)}]
51
+ w.state.write_text(json.dumps(state))
52
+ assert read(w) == {"handoff": None, "instructions": []} # records the handoff's receipt
53
+ state["comments"][1] = comment(1002, "jesdi", SEEN_BODY, at=T - 10 * MIN, editor="jesdi")
54
+ w.state.write_text(json.dumps(state))
55
+ assert read(w)["handoff"] == "handoff comment edited, boundary unverifiable"
@@ -87,7 +87,7 @@ def test_completed_successor_merge_clears_stale_handoff(tmp_path, finish_at):
87
87
  st["s2merged"] = True
88
88
  state.write_text(json.dumps(st))
89
89
  subprocess.run([sys.executable, SCRIPT, "merge", "--repo", "jesdi/demo", "--pr", "58",
90
- "--sha", "a1b2c3d", "--body", BODY, "--judge", "agree", "--session", "s2"],
90
+ "--sha", "a1b2c3d", "--body", BODY, "--judge", "agree", "--judge-risk", "1", "--session", "s2"],
91
91
  check=True, stdout=subprocess.DEVNULL)
92
92
  st = json.loads(state.read_text())
93
93
  '''.replace("TRIGGER", trigger)
@@ -56,7 +56,7 @@ def run_judge(j, script, home):
56
56
 
57
57
  def judge_world(tmp_path):
58
58
  j = Judge(tmp_path)
59
- j.answer.write_text('{"verdict": "agree", "reason": "ok"}')
59
+ j.answer.write_text('{"verdict": "agree", "risk": 1, "reason": "ok"}')
60
60
  home = tmp_path / "home"
61
61
  home.mkdir()
62
62
  return j, home, stage_script(tmp_path)
@@ -505,7 +505,7 @@ def test_with_commit_gpgsign_on_every_pushed_commit_is_signed_with_the_configure
505
505
  # ---------------------------------------------------------------- the merge-risk block of the PR body (ticket 15)
506
506
 
507
507
  PR_RISK = SKILL.parent / "pr-risk"
508
- BLOCK = ("door: two-way\nblast_radius: isolated\ntouches: [%s]\nrollback: revert\nverdict: auto\n"
508
+ BLOCK = ("door: two-way\nblast_radius: isolated\ntouches: [%s]\nrollback: revert\nrisk: 1\n"
509
509
  "reasons:\n - \"Only prose changes\"\n")
510
510
 
511
511