@jesdi/skills 0.0.71 → 0.0.73

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.71",
3
+ "version": "0.0.73",
4
4
  "description": "jesdi's agent skills (content package consumed by @jesdi/skills-cli)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -5,7 +5,7 @@ description: Babysit an open pull request until it is merged or handed to a huma
5
5
 
6
6
  # babysit-pr
7
7
 
8
- Run with `/babysit-pr <pr-url>`. The PostToolUse hook in `hooks/post-pr-create.sh` asks for this after a ready PR is opened in a repo with `.merge-risk.json`.
8
+ Run with `/babysit-pr <pr-url>`. The PostToolUse hook in `hooks/post-pr-create.sh` asks for this after a ready PR is opened in a repo with `.merge-risk.json`. When a subagent opened the PR, the hook queues it instead, and the Stop hook in `hooks/stop-babysit-pending.sh` asks the main session for it when that session stops.
9
9
 
10
10
  `babysit.py` is next to this file; every state change below goes through it (`python3 babysit.py <cmd> --repo <owner/name> --pr <n> ...`). Work in a checkout of the PR branch. The base is the PR's `baseRefName`, never a fixed `main`.
11
11
 
@@ -45,7 +45,7 @@ Push only after the ladder passes, then wait for CI on the new head. If a resolu
45
45
 
46
46
  ## Handoff
47
47
 
48
- `python3 babysit.py handoff ...` posts `## 🧑 Needs human: <reason>`, adds `needs-human`, releases the lease, and prints JSON with `status: handoff`, `terminal: true`, and the reason. `merge` can also perform this handoff before exiting with an error (for example, judge disagreement or a blocked merge). This terminal JSON is the completion signal even on a nonzero exit; proceed straight to notification and end the turn.
48
+ `python3 babysit.py handoff ...` posts `## 🧑 Needs human: <reason>`, adds `needs-human`, releases the lease, and prints JSON with `status: handoff`, `terminal: true`, and the reason. `merge` can also perform this handoff before exiting with an error (for example, judge disagreement, a blocked merge, or open PRs that still target this PR's head branch). This terminal JSON is the completion signal even on a nonzero exit; proceed straight to notification and end the turn.
49
49
 
50
50
  Finish any worktree cleanup before calling `handoff` or `merge`, and run either command alone: a shell suffix would keep working after a terminal result. After a completed handoff, the only remaining tool call in Claude Code is `PushNotification` with the reason (notification-specific tool discovery is allowed). Then end the turn immediately. In Codex, end the turn immediately. This completion rule takes precedence over inherited instructions for memory writes, session summaries, cleanup or verification; those are work after handoff.
51
51
 
@@ -897,6 +897,12 @@ def merge_cmd(repo, number, sha, body_file, policy, judge_label, approved, sessi
897
897
  extra += "\n".join(f"- `{c['sha']}` {c['commit']['message'].splitlines()[0]} ({who(c)})"
898
898
  for c in commits[oids.index(full) + 1:]) + "\n"
899
899
  stop(f"approval was for {approved}", extra)
900
+ # PRs into this head branch would land on a branch already merged, so their work never reaches the base.
901
+ head_ref = pr["head"]["ref"]
902
+ stacked = gh("api", f"repos/{repo}/pulls", "-X", "GET", "-f", "state=open", "-f", f"base={head_ref}",
903
+ "--paginate", "--jq", ".[].number").split()
904
+ if stacked:
905
+ stop(f"open PRs still target {head_ref}: {', '.join('#' + n for n in stacked)}")
900
906
  state = ci_state(repo, number, 0)
901
907
  if state != "green":
902
908
  stop(f"CI is {state} at merge time")
@@ -22,6 +22,8 @@ State is the JSON file $GH_FAKE_STATE:
22
22
  title, body PR title and body (default "" )
23
23
  repo_settings {allow_rebase_merge, allow_merge_commit, allow_squash_merge} served by `gh api repos/O/R`
24
24
  merge_error when set, `gh pr merge` fails printing it (e.g. a required approval)
25
+ head_ref head branch of every PR (default "feature")
26
+ open_prs [{number, base}] served by `gh api pulls -X GET -f state=open -f base=B` (filtered by base)
25
27
  merges recorded successful `gh pr merge` calls: {number, method, match, subject, body, auto}
26
28
  Commits may carry `message`, `author` (login) and `parents` (list of shas; 2 = a merge commit).
27
29
  `gh pr merge N --rebase|--merge|--squash --match-head-commit SHA [--subject S] [--body B]` fails
@@ -30,7 +32,7 @@ State is the JSON file $GH_FAKE_STATE:
30
32
  (a race: the other session posts after our first read)
31
33
  Every call is appended to $GH_FAKE_LOG as one JSON line {argv, write, unsupported}.
32
34
  Supported: `gh api` (user, pulls/N/reviews, pulls/N/comments (review comments, always empty),
33
- pulls/N/commits, `graphql` (answers the one connection the query asks for, with only the fields it selects), issues/N, pulls/N, issues/N/comments, issues/comments/ID,
35
+ pulls/N/commits, pulls (open list), `graphql` (answers the one connection the query asks for, with only the fields it selects), issues/N, pulls/N, issues/N/comments, issues/comments/ID,
34
36
  issues/N/labels[/NAME], commits/SHA/check-runs, commits/SHA/statuses, branches/B/protection/required_status_checks; -X, -f/-F, --input, --jq, --paginate, -i), `gh pr|issue view|comment|edit`.
35
37
  """
36
38
  import json
@@ -152,8 +154,12 @@ def api(args):
152
154
  return emit({"number": int(path.split("/")[1]), "state": "open", "labels": labels_obj(),
153
155
  "user": {"login": st["user"]},
154
156
  "title": st.get("title", ""), "body": st.get("body", ""),
155
- "head": {"sha": st.get("head_sha", "head1")},
157
+ "head": {"sha": st.get("head_sha", "head1"), "ref": st.get("head_ref", "feature")},
156
158
  "base": {"ref": st.get("base_ref", "main"), **({"sha": st["base_sha"]} if "base_sha" in st else {})}}, jq, include)
159
+ if path == "pulls" and method == "GET" and fields.get("state") == "open":
160
+ log(False)
161
+ return emit([{"number": p["number"], "base": {"ref": p["base"]}} for p in st.get("open_prs", [])
162
+ if fields.get("base") in (None, p["base"])], jq, include)
157
163
  if re.fullmatch(r"repos/[^/]+/[^/]+", path) and method == "GET":
158
164
  log(False)
159
165
  return emit(st.get("repo_settings", {"allow_rebase_merge": True, "allow_merge_commit": True,
@@ -52,5 +52,15 @@ root="$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null || printf '%s' "$cwd
52
52
  url="$(printf '%s' "$payload" | jq -r '.tool_response | if type == "object" then .stdout // "" else . // "" end' |
53
53
  grep -Eo 'https://[^ /]+/[^ /]+/[^ /]+/pull/[0-9]+' | tail -n 1)"
54
54
  [ -n "$url" ] || exit 0
55
+ # In a subagent the nudge would die with it (its brief may even forbid merging):
56
+ # queue the URL for the session, whose stop hook (stop-babysit-pending.sh) babysits it.
57
+ session="$(printf '%s' "$payload" | jq -r 'select(.agent_id // "" | . != "") | .session_id // ""' | tr -c 'A-Za-z0-9_-' '_')"
58
+ if [ -n "$session" ]; then
59
+ dir="${TMPDIR:-/tmp}/babysit-pr-pending"
60
+ mkdir -p "$dir" && printf '%s\n' "$url" >> "$dir/$session" || exit 0
61
+ jq -n --arg url "$url" '{hookSpecificOutput: {hookEventName: "PostToolUse",
62
+ additionalContext: "A pull request was opened: \($url). The session that started you babysits it when it stops; do not run /babysit-pr yourself. Give the URL in your report."}}'
63
+ exit 0
64
+ fi
55
65
  jq -n --arg url "$url" '{hookSpecificOutput: {hookEventName: "PostToolUse",
56
66
  additionalContext: "A pull request was opened. Run `/babysit-pr \($url)`."}}'
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ # Stop hook (Claude): run /babysit-pr for each PR a subagent of this session opened.
3
+ # post-pr-create.sh queues them, since a subagent's own nudge ends with the subagent.
4
+ payload="$(cat)"
5
+ command -v jq >/dev/null 2>&1 || exit 0
6
+ # Only the main session takes the queue: a subagent's stop leaves it for its parent.
7
+ session="$(printf '%s' "$payload" | jq -r 'select(.agent_id // "" | . == "") | .session_id // ""' | tr -c 'A-Za-z0-9_-' '_')"
8
+ [ -n "$session" ] || exit 0
9
+ file="${TMPDIR:-/tmp}/babysit-pr-pending/$session"
10
+ [ -s "$file" ] || exit 0
11
+ # Take the queue with one rename, so a URL appended meanwhile starts a new queue.
12
+ taken="$file.$$"
13
+ mv "$file" "$taken" 2>/dev/null || exit 0
14
+ runs="$(sort -u "$taken" | sed 's|.*|/babysit-pr &|')"
15
+ rm -f "$taken"
16
+ jq -n --arg runs "$runs" '{decision: "block",
17
+ reason: ("A subagent opened pull requests in this session. Babysit each one, in turn:\n" + $runs)}'
@@ -5,6 +5,11 @@
5
5
  "matcher": "Bash",
6
6
  "hooks": [{ "type": "command", "command": "hooks/post-pr-create.sh" }]
7
7
  }
8
+ ],
9
+ "Stop": [
10
+ {
11
+ "hooks": [{ "type": "command", "command": "hooks/stop-babysit-pending.sh" }]
12
+ }
8
13
  ]
9
14
  }
10
15
  }
@@ -1,10 +1,12 @@
1
1
  import json
2
+ import os
2
3
  import subprocess
3
4
  from pathlib import Path
4
5
 
5
6
  import pytest
6
7
 
7
8
  HOOK = Path(__file__).parent / "hooks" / "post-pr-create.sh"
9
+ STOP_HOOK = Path(__file__).parent / "hooks" / "stop-babysit-pending.sh"
8
10
  URL = "https://github.com/jesdi/demo/pull/58"
9
11
 
10
12
 
@@ -14,7 +16,7 @@ def repo(tmp_path):
14
16
  return tmp_path
15
17
 
16
18
 
17
- def run(cwd, command, response, codex=False):
19
+ def run(cwd, command, response, codex=False, **fields):
18
20
  """Feed one PostToolUse payload to the hook; return its stdout."""
19
21
  if codex:
20
22
  response = response["stdout"] if isinstance(response, dict) else response
@@ -24,9 +26,24 @@ def run(cwd, command, response, codex=False):
24
26
  "tool_input": {"command": command},
25
27
  "tool_response": response,
26
28
  "cwd": str(cwd),
29
+ **fields,
27
30
  }
28
31
  p = subprocess.run(["bash", str(HOOK)], input=json.dumps(payload),
29
- capture_output=True, text=True)
32
+ capture_output=True, text=True, env=_env(cwd))
33
+ assert p.returncode == 0, p.stderr
34
+ return p.stdout.strip()
35
+
36
+
37
+ def _env(tmp):
38
+ """Each test gets its own pending queue: TMPDIR points into its tmp_path."""
39
+ return {**os.environ, "TMPDIR": str(tmp)}
40
+
41
+
42
+ def stop(tmp, session="s1"):
43
+ """Feed one Stop payload to the stop hook; return its stdout."""
44
+ payload = {"hook_event_name": "Stop", "session_id": session, "cwd": str(tmp)}
45
+ p = subprocess.run(["bash", str(STOP_HOOK)], input=json.dumps(payload),
46
+ capture_output=True, text=True, env=_env(tmp))
30
47
  assert p.returncode == 0, p.stderr
31
48
  return p.stdout.strip()
32
49
 
@@ -60,3 +77,55 @@ def test_failed_create_adds_nothing(repo, codex):
60
77
  @pytest.mark.parametrize("codex", [False, True])
61
78
  def test_repo_without_policy_adds_nothing(tmp_path, codex):
62
79
  assert run(tmp_path, "gh pr create --title x --body y", OK, codex) == ""
80
+
81
+
82
+ SUB = {"session_id": "s1", "agent_id": "a1", "agent_type": "general-purpose"}
83
+
84
+
85
+ def test_subagent_pr_is_left_to_the_main_session(repo):
86
+ out = context(run(repo, "gh pr create --title x --body y", OK, **SUB))
87
+ assert URL in out
88
+ assert f"/babysit-pr {URL}" not in out
89
+
90
+
91
+ def test_main_session_babysits_a_subagent_pr_when_it_stops(repo):
92
+ run(repo, "gh pr create --title x --body y", OK, **SUB)
93
+ out = json.loads(stop(repo))
94
+ assert out["decision"] == "block"
95
+ assert f"/babysit-pr {URL}" in out["reason"]
96
+
97
+
98
+ def test_subagent_pr_is_handed_over_once(repo):
99
+ run(repo, "gh pr create --title x --body y", OK, **SUB)
100
+ stop(repo)
101
+ assert stop(repo) == ""
102
+
103
+
104
+ def test_two_subagent_prs_are_both_handed_over(repo):
105
+ other = "https://github.com/jesdi/demo/pull/59"
106
+ run(repo, "gh pr create --title x --body y", OK, **SUB)
107
+ run(repo, "gh pr create --title x --body y",
108
+ {**OK, "stdout": f"{other}\n"}, **{**SUB, "agent_id": "a2"})
109
+ reason = json.loads(stop(repo))["reason"]
110
+ assert f"/babysit-pr {URL}" in reason and f"/babysit-pr {other}" in reason
111
+
112
+
113
+ def test_other_session_does_not_pick_up_the_pr(repo):
114
+ run(repo, "gh pr create --title x --body y", OK, **SUB)
115
+ assert stop(repo, session="s2") == ""
116
+ assert f"/babysit-pr {URL}" in json.loads(stop(repo))["reason"]
117
+
118
+
119
+ def test_stop_with_nothing_pending_adds_nothing(tmp_path):
120
+ assert stop(tmp_path) == ""
121
+
122
+
123
+ def test_main_session_pr_is_not_queued(repo):
124
+ run(repo, "gh pr create --title x --body y", OK, session_id="s1")
125
+ assert stop(repo) == ""
126
+
127
+
128
+ def test_unsafe_session_id_stays_inside_the_queue(repo):
129
+ run(repo, "gh pr create --title x --body y", OK, **{**SUB, "session_id": "../../x"})
130
+ assert not (repo.parent / "x").exists()
131
+ assert f"/babysit-pr {URL}" in json.loads(stop(repo, session="../../x"))["reason"]
@@ -122,3 +122,22 @@ def test_saved_body_does_not_stand_in_for_an_empty_live_body(tmp_path):
122
122
  assert p.returncode != 0
123
123
  assert merged(w) == []
124
124
  assert not any("Merged by babysit-pr" in c["body"] for c in w.github()["comments"])
125
+
126
+
127
+ def test_open_prs_into_the_head_branch_hand_off_and_nothing_merges(tmp_path):
128
+ # the final PR of a feat/<name> cut-over: increments #57 and #58 still target its head branch
129
+ w = world(tmp_path, head_ref="feat/new-cart",
130
+ open_prs=[{"number": 57, "base": "feat/new-cart"}, {"number": 60, "base": "main"},
131
+ {"number": 61, "base": "feat/new-cart"}])
132
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
133
+ assert p.returncode != 0
134
+ assert merged(w) == []
135
+ [h] = handoffs(w)
136
+ assert h.splitlines()[0] == "## 🧑 Needs human: open PRs still target feat/new-cart: #57, #61"
137
+
138
+
139
+ def test_open_prs_into_other_branches_do_not_block_the_merge(tmp_path):
140
+ w = world(tmp_path, head_ref="feat/new-cart", open_prs=[{"number": 60, "base": "main"}])
141
+ p = merge(w, tmp_path, "a1b2c3d", "--judge", "agree")
142
+ assert p.returncode == 0, p.output
143
+ assert len(merged(w)) == 1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-10-28T10:29:04.769Z",
3
+ "generatedAt": "2026-10-28T12:41:08.065Z",
4
4
  "skills": [
5
5
  {
6
6
  "name": "agents-wayfinder",
@@ -10,8 +10,8 @@
10
10
  },
11
11
  {
12
12
  "name": "babysit-pr",
13
- "version": "0.1.1",
14
- "hash": "sha256-bf09318dcaf40422f9c2433698b4f1c6f8e10b8893f84b1e81ee9f04f7d6cad9",
13
+ "version": "0.1.3",
14
+ "hash": "sha256-cfc51ea1a1ed378c87e4b682bbbf9ecd01a8a5ce1bf4ed89380bb43346ad466f",
15
15
  "description": "Babysit an open pull request until it is merged or handed to a human. Started by the PostToolUse hook after `gh pr create`, or by hand with `/babysit-pr <pr-url>`."
16
16
  },
17
17
  {