Skip to content

Commit fd7e034

Browse files
committed
feat(spr): auto-start session-scoped daemon on spr update
After creating/updating PRs, agents need automatic monitoring without manual daemon management. Starting session-scoped daemon on spr update ensures timely PR notifications. Authored By: opencode (claude-sonnet-4-5) commit-id:5cd74256
1 parent 55b76d0 commit fd7e034

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

tools/setup-shared-aliases.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ git() {
4040

4141
export -f git
4242

43-
# spr wrapper to auto-load GitHub token
4443
spr() {
45-
# Auto-load GITHUB_TOKEN if available
4644
if [[ -z "${GITHUB_TOKEN:-}" ]]; then
4745
local token_file="${HOME}/.config/nixsmith/github-token"
4846
if [[ -f "$token_file" ]]; then
@@ -51,7 +49,35 @@ spr() {
5149
fi
5250
fi
5351

54-
command spr "$@"
52+
local cmd="${1:-}"
53+
local result
54+
local exit_code
55+
56+
if [[ "$cmd" == "update" ]]; then
57+
result=$(command spr "$@" 2>&1)
58+
exit_code=$?
59+
echo "$result"
60+
61+
if [[ $exit_code -eq 0 ]] && [[ -n "${OPENCODE_SESSION_ID:-}" ]]; then
62+
local pr_numbers=$(echo "$result" | grep -oE 'PR #[0-9]+|/pull/[0-9]+' | grep -oE '[0-9]+' | sort -u | tr '\n' ',')
63+
64+
if [[ -n "$pr_numbers" ]]; then
65+
pr_numbers="${pr_numbers%,}"
66+
67+
local repo_dir=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
68+
local pid_file="${repo_dir}/.pr-poll.pid"
69+
70+
if [[ ! -f "$pid_file" ]] || ! kill -0 "$(cat "$pid_file" 2>/dev/null)" 2>/dev/null; then
71+
echo "Starting PR polling daemon for PRs: $pr_numbers" >&2
72+
nohup bash "${repo_dir}/tools/pr-poll" --daemon --pr "$pr_numbers" >> "${repo_dir}/.pr-poll.log" 2>&1 &
73+
fi
74+
fi
75+
fi
76+
77+
return $exit_code
78+
else
79+
command spr "$@"
80+
fi
5581
}
5682
export -f spr
5783

0 commit comments

Comments
 (0)