@jesdi/skills 0.0.71 → 0.0.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/babysit-pr/SKILL.md +1 -1
- package/skills/babysit-pr/hooks/post-pr-create.sh +10 -0
- package/skills/babysit-pr/hooks/stop-babysit-pending.sh +17 -0
- package/skills/babysit-pr/hooks.json +5 -0
- package/skills/babysit-pr/test_hooks.py +71 -2
- package/skills-manifest.json +3 -3
package/package.json
CHANGED
|
@@ -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
|
|
|
@@ -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)}'
|
|
@@ -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"]
|
package/skills-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-10-28T10:
|
|
3
|
+
"generatedAt": "2026-10-28T10:40:16.890Z",
|
|
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.
|
|
14
|
-
"hash": "sha256-
|
|
13
|
+
"version": "0.1.2",
|
|
14
|
+
"hash": "sha256-e8c47845f0a342e173396003f3d69c66d98eac0c2fb5b696be94524c94fcba04",
|
|
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
|
{
|