Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
refactor(watch): remove legacy shell watch wrappers
cyh0d252e08e842
diff --git a/docs/plans/background-watch-hook.md b/docs/plans/background-watch-hook.mddeleted file mode 100644index 305240dae..000000000--- a/docs/plans/background-watch-hook.md+++ /dev/null@@ -1,40 +0,0 @@-# Background Watch Hook--## Background--We want a reusable pattern and bundled guide that teaches agents how to wait for an external condition in the background and automatically send a `vibe hook` back into the current IM session when the condition is met.--The user explicitly does not want a new event subsystem inside Vibe Remote. The solution should stay lightweight and be built from:--1. a blocking waiter script-2. a detached shell wrapper-3. `vibe hook send`--## Goal--Add a reusable guide under `skills/` that:--- explains the detached execution pattern as a generic technique-- provides a general wrapper script for `wait -> capture stdout -> vibe hook send`-- provides a GitHub PR activity waiter as a concrete example--## Design--- `skills/background-watch-hook/SKILL.md`- - explains when to use the pattern- - explains how to derive the current `session_key`- - explains the detached-shell pattern, wrapper interface, and common pitfalls-- `skills/background-watch-hook/scripts/watch_then_hook.sh`- - runs an arbitrary waiter command- - captures stdout- - builds a prompt file- - invokes `vibe hook send`-- `skills/background-watch-hook/scripts/wait_for_github_pr_activity.py`- - waits until a PR gets new review activity- - prints a concise activity summary to stdout--## Validation--- `bash -n` on the shell script-- `python3 -m py_compile` on the Python waiter-- basic `--help` smoke checksdiff --git a/skills/background-watch-hook/scripts/watch_github_pr_then_hook.sh b/skills/background-watch-hook/scripts/watch_github_pr_then_hook.shdeleted file mode 100755index 9121110a2..000000000--- a/skills/background-watch-hook/scripts/watch_github_pr_then_hook.sh+++ /dev/null@@ -1,542 +0,0 @@-#!/usr/bin/env bash-set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"-SCRIPT_PATH="$SCRIPT_DIR/$(basename "${BASH_SOURCE[0]}")"-WRAPPER="$SCRIPT_DIR/watch_then_hook.sh"-WAITER="$SCRIPT_DIR/wait_for_github_pr_activity.py"--usage() {- cat <<'EOF'-Usage:- watch_github_pr_then_hook.sh --session-key <session_key> --repo <owner/name> --pr <number> [options]--Options:- --session-key <value> Required. Target session key for vibe hook send.- --repo <value> Required. GitHub repo in owner/name form.- --pr <number> Required. Pull request number.- --prefix <value> Optional. Hook prefix. If omitted, a sensible default is used.- --interval <seconds> Optional. Polling interval passed to the waiter.- --timeout <seconds> Optional. Per-cycle waiter timeout. Default: 21600 (6 hours).- --lifetime-timeout <seconds> Optional. Overall lifetime for --forever. Default: 0 (run until killed).- --forever Optional. Keep watching and re-arm after each detected event.- --event-limit <count> Optional. Maximum rendered events.- --catch-up Optional. Treat existing PR activity as pending immediately.- --allow-unauthenticated Optional. Allow throttled best-effort polling without GitHub auth.- --since-review-id <id> Optional. Review cursor.- --since-review-comment-id <id> Optional. Review-comment cursor.- --since-issue-comment-id <id> Optional. PR conversation comment cursor.- --since-reaction-id <id> Optional. PR-body reaction cursor.- --log-file <path> Optional. Background log file path.- --foreground Optional. Run inline instead of detaching.- --post-to <thread|channel> Optional. Passed through to the wrapper.- --deliver-key <value> Optional. Passed through to the wrapper.- --hook-bin <value> Optional. Passed through to the wrapper.- --hook-cmd <value> Optional. Passed through to the wrapper.- --timeout-exit-code <n> Optional. Must remain 124 for the bundled waiter.- -h, --help Show this help.-EOF-}--session_key=""-repo=""-pr=""-prefix=""-interval=""-timeout=""-lifetime_timeout="0"-forever=0-event_limit=""-catch_up=0-allow_unauthenticated=0-since_review_id=""-since_review_comment_id=""-since_issue_comment_id=""-since_reaction_id=""-log_file=""-foreground=0-post_to=""-deliver_key=""-hook_bin=""-hook_cmd=""-timeout_exit_code=""--normalize_nonnegative_number() {- python3 - "$1" <<'PY'-import math-import sys--value = float(sys.argv[1])-if not math.isfinite(value) or value < 0:- raise SystemExit(1)-if value.is_integer():- print(int(value))-else:- print(value)-PY-}--while [[ $# -gt 0 ]]; do- case "$1" in- --session-key)- session_key="${2:-}"- shift 2- ;;- --repo)- repo="${2:-}"- shift 2- ;;- --pr)- pr="${2:-}"- shift 2- ;;- --prefix)- prefix="${2:-}"- shift 2- ;;- --interval)- interval="${2:-}"- shift 2- ;;- --timeout)- timeout="${2:-}"- shift 2- ;;- --lifetime-timeout)- lifetime_timeout="${2:-}"- shift 2- ;;- --forever)- forever=1- shift- ;;- --event-limit)- event_limit="${2:-}"- shift 2- ;;- --catch-up)- catch_up=1- shift- ;;- --allow-unauthenticated)- allow_unauthenticated=1- shift- ;;- --since-review-id)- since_review_id="${2:-}"- shift 2- ;;- --since-review-comment-id)- since_review_comment_id="${2:-}"- shift 2- ;;- --since-issue-comment-id)- since_issue_comment_id="${2:-}"- shift 2- ;;- --since-reaction-id)- since_reaction_id="${2:-}"- shift 2- ;;- --log-file)- log_file="${2:-}"- shift 2- ;;- --foreground)- foreground=1- shift- ;;- --post-to)- post_to="${2:-}"- shift 2- ;;- --deliver-key)- deliver_key="${2:-}"- shift 2- ;;- --hook-bin)- hook_bin="${2:-}"- shift 2- ;;- --hook-cmd)- hook_cmd="${2:-}"- shift 2- ;;- --timeout-exit-code)- timeout_exit_code="${2:-}"- shift 2- ;;- -h|--help)- usage- exit 0- ;;- *)- echo "Unknown option: $1" >&2- usage >&2- exit 2- ;;- esac-done--if [[ -z "$session_key" || -z "$repo" || -z "$pr" ]]; then- echo "--session-key, --repo, and --pr are required" >&2- usage >&2- exit 2-fi--if [[ -n "$timeout_exit_code" && "$timeout_exit_code" != "124" ]]; then- echo "--timeout-exit-code must remain 124 for the bundled GitHub waiter" >&2- exit 2-fi--if [[ -z "$timeout" ]]; then- timeout="21600"-fi-if ! timeout="$(normalize_nonnegative_number "$timeout")"; then- echo "--timeout must be a finite number >= 0" >&2- exit 2-fi-if ! lifetime_timeout="$(normalize_nonnegative_number "$lifetime_timeout")"; then- echo "--lifetime-timeout must be a finite number >= 0" >&2- exit 2-fi--if [[ "$forever" -ne 1 && "$lifetime_timeout" != "0" ]]; then- echo "--lifetime-timeout requires --forever" >&2- exit 2-fi--if [[ ! -x "$WRAPPER" ]]; then- echo "Wrapper not found or not executable: $WRAPPER" >&2- exit 127-fi--if [[ ! -x "$WAITER" ]]; then- echo "Waiter not found or not executable: $WAITER" >&2- exit 127-fi--if [[ -z "$prefix" ]]; then- prefix="GitHub PR #$pr has new review activity. Fetch the latest review state, summarize actionable items, and continue handling them if needed."-fi--if [[ "$forever" -eq 1 && "$foreground" -ne 1 ]]; then- if [[ -z "$log_file" ]]; then- log_file="/tmp/background-watch-github-pr-$(date +%Y%m%d%H%M%S)-$$.log"- fi-- child_args=(- "$SCRIPT_PATH"- --foreground- --forever- --session-key "$session_key"- --repo "$repo"- --pr "$pr"- --prefix "$prefix"- --timeout "$timeout"- --lifetime-timeout "$lifetime_timeout"- )-- if [[ -n "$interval" ]]; then- child_args+=(--interval "$interval")- fi- if [[ -n "$event_limit" ]]; then- child_args+=(--event-limit "$event_limit")- fi- if [[ "$catch_up" -eq 1 ]]; then- child_args+=(--catch-up)- fi- if [[ "$allow_unauthenticated" -eq 1 ]]; then- child_args+=(--allow-unauthenticated)- fi- if [[ -n "$since_review_id" ]]; then- child_args+=(--since-review-id "$since_review_id")- fi- if [[ -n "$since_review_comment_id" ]]; then- child_args+=(--since-review-comment-id "$since_review_comment_id")- fi- if [[ -n "$since_issue_comment_id" ]]; then- child_args+=(--since-issue-comment-id "$since_issue_comment_id")- fi- if [[ -n "$since_reaction_id" ]]; then- child_args+=(--since-reaction-id "$since_reaction_id")- fi- if [[ -n "$post_to" ]]; then- child_args+=(--post-to "$post_to")- fi- if [[ -n "$deliver_key" ]]; then- child_args+=(--deliver-key "$deliver_key")- fi- if [[ -n "$hook_bin" ]]; then- child_args+=(--hook-bin "$hook_bin")- fi- if [[ -n "$hook_cmd" ]]; then- child_args+=(--hook-cmd "$hook_cmd")- fi-- nohup "${child_args[@]}" >"$log_file" 2>&1 </dev/null &- child_pid=$!-- printf 'Started forever GitHub PR watch.\n'- printf 'PID: %s\n' "$child_pid"- printf 'Log file: %s\n' "$log_file"- printf 'Lifecycle: this watcher stays alive until killed.\n'- exit 0-fi--send_status_hook() {- local status_prefix="$1"- local status_message="$2"-- local -a status_args=(- "$WRAPPER"- --foreground- --session-key "$session_key"- --prefix "$status_prefix"- --timeout 0- )-- if [[ -n "$post_to" ]]; then- status_args+=(--post-to "$post_to")- fi- if [[ -n "$deliver_key" ]]; then- status_args+=(--deliver-key "$deliver_key")- fi- if [[ -n "$hook_bin" ]]; then- status_args+=(--hook-bin "$hook_bin")- fi- if [[ -n "$hook_cmd" ]]; then- status_args+=(--hook-cmd "$hook_cmd")- fi-- status_args+=(-- python3 -c 'import sys; print(sys.argv[1])' "$status_message")- "${status_args[@]}"-}--if [[ "$forever" -eq 1 ]]; then- cursor_file="$(mktemp)"- retry_delay_seconds=30- lifetime_started_at="$(date +%s)"- cleanup() {- rm -f "$cursor_file"- }- trap cleanup EXIT-- current_since_review_id="$since_review_id"- current_since_review_comment_id="$since_review_comment_id"- current_since_issue_comment_id="$since_issue_comment_id"- current_since_reaction_id="$since_reaction_id"- current_catch_up="$catch_up"-- while true; do- cycle_timeout="$timeout"- if [[ "$lifetime_timeout" != "0" ]]; then- lifetime_window="$(- python3 - "$lifetime_started_at" "$lifetime_timeout" <<'PY'-import sys-import time--started_at = float(sys.argv[1])-lifetime_timeout = float(sys.argv[2])-remaining = lifetime_timeout - (time.time() - started_at)-print(max(0.0, remaining))-PY- )"-- if python3 - "$lifetime_window" <<'PY'-import sys--raise SystemExit(0 if float(sys.argv[1]) <= 0 else 1)-PY- then- elapsed_seconds="$(- python3 - "$lifetime_started_at" <<'PY'-import sys-import time--print(int(max(0, time.time() - float(sys.argv[1]))))-PY- )"- send_status_hook \- "GitHub PR watch stopped after reaching its lifetime timeout." \- "Lifetime timeout reached after ${elapsed_seconds} second(s) for ${repo}#${pr}. Last cursors: review=${current_since_review_id:-0} review_comment=${current_since_review_comment_id:-0} issue_comment=${current_since_issue_comment_id:-0} reaction=${current_since_reaction_id:-0}."- exit 0- fi-- cycle_timeout="$(- python3 - "$timeout" "$lifetime_window" <<'PY'-import sys--cycle_timeout = float(sys.argv[1])-remaining_lifetime = float(sys.argv[2])-if cycle_timeout <= 0:- print(remaining_lifetime)-else:- print(min(cycle_timeout, remaining_lifetime))-PY- )"- fi-- rm -f "$cursor_file"-- cycle_wrapper_args=(- "$WRAPPER"- --foreground- --session-key "$session_key"- --prefix "$prefix"- --timeout 0- --timeout-exit-code 125- )-- if [[ -n "$post_to" ]]; then- cycle_wrapper_args+=(--post-to "$post_to")- fi- if [[ -n "$deliver_key" ]]; then- cycle_wrapper_args+=(--deliver-key "$deliver_key")- fi- if [[ -n "$hook_bin" ]]; then- cycle_wrapper_args+=(--hook-bin "$hook_bin")- fi- if [[ -n "$hook_cmd" ]]; then- cycle_wrapper_args+=(--hook-cmd "$hook_cmd")- fi-- cycle_waiter_args=(- "$WAITER"- --repo "$repo"- --pr "$pr"- --timeout "$cycle_timeout"- --cursor-output "$cursor_file"- )-- if [[ -n "$interval" ]]; then- cycle_waiter_args+=(--interval "$interval")- fi- if [[ -n "$event_limit" ]]; then- cycle_waiter_args+=(--event-limit "$event_limit")- fi- if [[ "$allow_unauthenticated" -eq 1 ]]; then- cycle_waiter_args+=(--allow-unauthenticated)- fi- if [[ -n "$current_since_review_id" ]]; then- cycle_waiter_args+=(--since-review-id "$current_since_review_id")- fi- if [[ -n "$current_since_review_comment_id" ]]; then- cycle_waiter_args+=(--since-review-comment-id "$current_since_review_comment_id")- fi- if [[ -n "$current_since_issue_comment_id" ]]; then- cycle_waiter_args+=(--since-issue-comment-id "$current_since_issue_comment_id")- fi- if [[ -n "$current_since_reaction_id" ]]; then- cycle_waiter_args+=(--since-reaction-id "$current_since_reaction_id")- fi- if [[ "$current_catch_up" -eq 1 ]]; then- cycle_waiter_args+=(--catch-up)- fi-- set +e- "${cycle_wrapper_args[@]}" -- "${cycle_waiter_args[@]}"- cycle_status=$?- set -e-- if [[ "$cycle_status" -eq 124 ]]; then- continue- fi-- if [[ "$cycle_status" -ne 1 ]]; then- echo "Forever watch stopped on non-retryable cycle failure: $cycle_status" >&2- exit "$cycle_status"- fi-- if [[ "$cycle_status" -ne 0 ]]; then- echo "Forever watch cycle failed with status $cycle_status; retrying in ${retry_delay_seconds}s." >&2- sleep "$retry_delay_seconds"- continue- fi-- if [[ ! -s "$cursor_file" ]]; then- echo "No cursor output written; re-arming with existing cursors." >&2- continue- fi-- cursor_values="$(- python3 - "$cursor_file" <<'PY'-import json-import sys--with open(sys.argv[1], encoding="utf-8") as handle:- payload = json.load(handle)-print(- "%s\t%s\t%s\t%s"- % (- payload["review_cursor"],- payload["review_comment_cursor"],- payload["issue_comment_cursor"],- payload.get("reaction_cursor", 0),- )-)-PY- )"- IFS=$'\t' read -r current_since_review_id current_since_review_comment_id current_since_issue_comment_id current_since_reaction_id <<<"$cursor_values"- current_catch_up=0- done-fi--wrapper_args=("$WRAPPER" --session-key "$session_key" --prefix "$prefix")--if [[ -n "$timeout" ]]; then- wrapper_args+=(--timeout "$timeout")-fi-if [[ -n "$log_file" ]]; then- wrapper_args+=(--log-file "$log_file")-fi-if [[ "$foreground" -eq 1 ]]; then- wrapper_args+=(--foreground)-fi-if [[ -n "$post_to" ]]; then- wrapper_args+=(--post-to "$post_to")-fi-if [[ -n "$deliver_key" ]]; then- wrapper_args+=(--deliver-key "$deliver_key")-fi-if [[ -n "$hook_bin" ]]; then- wrapper_args+=(--hook-bin "$hook_bin")-fi-if [[ -n "$hook_cmd" ]]; then- wrapper_args+=(--hook-cmd "$hook_cmd")-fi-if [[ -n "$timeout_exit_code" ]]; then- wrapper_args+=(--timeout-exit-code "$timeout_exit_code")-fi--waiter_args=("$WAITER" --repo "$repo" --pr "$pr")--if [[ -n "$interval" ]]; then- waiter_args+=(--interval "$interval")-fi-if [[ -n "$timeout" ]]; then- waiter_args+=(--timeout "$timeout")-fi-if [[ -n "$event_limit" ]]; then- waiter_args+=(--event-limit "$event_limit")-fi-if [[ "$catch_up" -eq 1 ]]; then- waiter_args+=(--catch-up)-fi-if [[ "$allow_unauthenticated" -eq 1 ]]; then- waiter_args+=(--allow-unauthenticated)-fi-if [[ -n "$since_review_id" ]]; then- waiter_args+=(--since-review-id "$since_review_id")-fi-if [[ -n "$since_review_comment_id" ]]; then- waiter_args+=(--since-review-comment-id "$since_review_comment_id")-fi-if [[ -n "$since_issue_comment_id" ]]; then- waiter_args+=(--since-issue-comment-id "$since_issue_comment_id")-fi-if [[ -n "$since_reaction_id" ]]; then- waiter_args+=(--since-reaction-id "$since_reaction_id")-fi--"${wrapper_args[@]}" -- "${waiter_args[@]}"diff --git a/skills/background-watch-hook/scripts/watch_then_hook.sh b/skills/background-watch-hook/scripts/watch_then_hook.shdeleted file mode 100755index 38fdfc2e2..000000000--- a/skills/background-watch-hook/scripts/watch_then_hook.sh+++ /dev/null@@ -1,349 +0,0 @@-#!/usr/bin/env bash-set -euo pipefail--usage() {- cat <<'EOF'-Usage:- watch_then_hook.sh --session-key <session_key> [options] -- <waiter command...>--Options:- --session-key <value> Required. Target session key for vibe hook send.- --prefix <value> Optional. Text prepended before waiter stdout.- --timeout <seconds> Optional. Overall waiter timeout. Default: 21600 (6 hours), 0 means forever.- --post-to <value> Optional. Passed through to vibe hook send.- --deliver-key <value> Optional. Explicit delivery target key for vibe hook send.- --log-file <path> Optional. Background log file path when detaching.- --foreground Optional. Run inline instead of detaching.- --hook-bin <value> Optional. Hook CLI executable. Overrides auto-detection.- --hook-cmd <value> Optional. Full hook command prefix. Example: 'uv run python -m vibe'- --timeout-exit-code <n> Optional. Exit code treated as timeout. Default: 124- -h, --help Show this help.--Behavior:- - By default, detaches immediately and keeps the waiter running in the background.- - Use --foreground to run inline as a low-level primitive.- - Captures waiter stdout to a temporary file.- - If the waiter exits 0, builds a prompt file and runs vibe hook send.- - If the waiter exits with the timeout code, still sends a timeout hook summary.- - Any other non-zero exit is treated as failure and no hook is sent.-EOF-}--session_key=""-prefix=""-timeout_seconds="21600"-post_to=""-deliver_key=""-log_file=""-foreground=0-hook_bin="${VIBE_HOOK_BIN:-}"-hook_cmd_override="${VIBE_HOOK_CMD:-}"-timeout_exit_code=124--normalize_nonnegative_number() {- python3 - "$1" <<'PY'-import math-import sys--value = float(sys.argv[1])-if not math.isfinite(value) or value < 0:- raise SystemExit(1)-if value.is_integer():- print(int(value))-else:- print(value)-PY-}--while [[ $# -gt 0 ]]; do- case "$1" in- --session-key)- session_key="${2:-}"- shift 2- ;;- --prefix)- prefix="${2:-}"- shift 2- ;;- --timeout)- timeout_seconds="${2:-21600}"- shift 2- ;;- --post-to)- post_to="${2:-}"- shift 2- ;;- --deliver-key)- deliver_key="${2:-}"- shift 2- ;;- --log-file)- log_file="${2:-}"- shift 2- ;;- --foreground)- foreground=1- shift- ;;- --hook-bin)- hook_bin="${2:-}"- shift 2- ;;- --hook-cmd)- hook_cmd_override="${2:-}"- shift 2- ;;- --timeout-exit-code)- timeout_exit_code="${2:-124}"- shift 2- ;;- -h|--help)- usage- exit 0- ;;- --)- shift- break- ;;- *)- echo "Unknown option: $1" >&2- usage >&2- exit 2- ;;- esac-done--if [[ -z "$session_key" ]]; then- echo "--session-key is required" >&2- usage >&2- exit 2-fi--if [[ $# -eq 0 ]]; then- echo "A waiter command is required after --" >&2- usage >&2- exit 2-fi--if [[ -n "$post_to" && "$post_to" != "thread" && "$post_to" != "channel" ]]; then- echo "--post-to must be either 'thread' or 'channel'" >&2- exit 2-fi--if [[ -n "$post_to" && -n "$deliver_key" ]]; then- echo "--post-to and --deliver-key are mutually exclusive" >&2- exit 2-fi--if ! timeout_seconds="$(normalize_nonnegative_number "$timeout_seconds")"; then- echo "--timeout must be a finite number >= 0" >&2- exit 2-fi--script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"--output_file="$(mktemp)"-prompt_file="$(mktemp)"-cleanup() {- rm -f "$output_file" "$prompt_file"-}-trap cleanup EXIT--_resolve_hook_command() {- if [[ -n "$hook_cmd_override" ]]; then- local override_help=""- if [[ "$hook_cmd_override" == *" "* ]]; then- override_help="$(bash -lc "$hook_cmd_override hook send --help" 2>/dev/null || true)"- else- override_help="$("$hook_cmd_override" hook send --help 2>/dev/null || true)"- fi- if [[ "$override_help" == *"--session-key"* && "$override_help" == *"Queue one asynchronous turn"* ]]; then- printf '%s\n' "$hook_cmd_override"- return 0- fi- echo "Hook command override did not expose a working 'hook send' command: $hook_cmd_override" >&2- return 127- fi-- if [[ -n "$hook_bin" ]]; then- if ! command -v "$hook_bin" >/dev/null 2>&1; then- echo "Hook binary not found: $hook_bin" >&2- return 127- fi- printf '%s\n' "$hook_bin"- return 0- fi-- if command -v vibe >/dev/null 2>&1; then- local help_output=""- help_output="$(vibe hook send --help 2>/dev/null || true)"- if [[ "$help_output" == *"--session-key"* && "$help_output" == *"Queue one asynchronous turn"* ]]; then- printf '%s\n' "vibe"- return 0- fi- fi-- if command -v uv >/dev/null 2>&1 && [[ -f pyproject.toml ]] && [[ -f vibe/__main__.py ]]; then- local uv_help=""- uv_help="$(uv run python -m vibe hook send --help 2>/dev/null || true)"- if [[ "$uv_help" == *"--session-key"* && "$uv_help" == *"Queue one asynchronous turn"* ]]; then- printf '%s\n' "uv run python -m vibe"- return 0- fi- fi-- if command -v git >/dev/null 2>&1 && command -v uv >/dev/null 2>&1; then- local worktree_path=""- local worktree_help=""- while IFS= read -r worktree_path; do- [[ -z "$worktree_path" ]] && continue- [[ "$worktree_path" == "$PWD" ]] && continue- [[ -f "$worktree_path/pyproject.toml" ]] || continue- [[ -f "$worktree_path/vibe/__main__.py" ]] || continue- worktree_help="$(- bash -lc "cd $(printf '%q' "$worktree_path") && uv run python -m vibe hook send --help" 2>/dev/null || true- )"- if [[ "$worktree_help" == *"--session-key"* && "$worktree_help" == *"Queue one asynchronous turn"* ]]; then- printf 'cd %q && uv run python -m vibe\n' "$worktree_path"- return 0- fi- done < <(git worktree list --porcelain | awk '/^worktree /{print substr($0, 10)}')- fi-- echo "Could not resolve a working Vibe hook command. Set --hook-cmd or --hook-bin explicitly." >&2- return 127-}--_run_hook_command() {- local hook_cmd_prefix="$1"- shift- local -a hook_args=("$@")-- if [[ "$hook_cmd_prefix" == *" "* ]]; then- local quoted_args=""- local arg- for arg in "${hook_args[@]}"; do- quoted_args+=" $(printf '%q' "$arg")"- done- bash -lc "$hook_cmd_prefix$quoted_args"- return- fi-- "$hook_cmd_prefix" "${hook_args[@]}"-}--if [[ "$foreground" -ne 1 ]]; then- if [[ -z "$log_file" ]]; then- log_file="/tmp/background-watch-hook-$(date +%Y%m%d%H%M%S)-$$.log"- fi-- child_args=(- "$script_path"- --foreground- --session-key "$session_key"- --timeout "$timeout_seconds"- --timeout-exit-code "$timeout_exit_code"- )-- if [[ -n "$hook_cmd_override" ]]; then- _resolve_hook_command >/dev/null- child_args+=(--hook-cmd "$hook_cmd_override")- elif [[ -n "$hook_bin" ]]; then- _resolve_hook_command >/dev/null- child_args+=(--hook-bin "$hook_bin")- else- hook_runner="$(_resolve_hook_command)"- child_args+=(--hook-cmd "$hook_runner")- fi-- if [[ -n "$prefix" ]]; then- child_args+=(--prefix "$prefix")- fi- if [[ -n "$post_to" ]]; then- child_args+=(--post-to "$post_to")- fi- if [[ -n "$deliver_key" ]]; then- child_args+=(--deliver-key "$deliver_key")- fi-- child_args+=(-- "$@")-- nohup "${child_args[@]}" >"$log_file" 2>&1 </dev/null &- child_pid=$!-- printf 'Started background watch.\n'- printf 'PID: %s\n' "$child_pid"- printf 'Log file: %s\n' "$log_file"- exit 0-fi--hook_runner="$(_resolve_hook_command)"-started_at_epoch="$(date +%s)"-timed_out=0--set +e-if [[ "$timeout_seconds" == "0" ]]; then- "$@" >"$output_file"- waiter_status=$?-else- python3 - "$output_file" "$timeout_seconds" "$timeout_exit_code" "$@" <<'PY'-import subprocess-import sys--output_path = sys.argv[1]-timeout_seconds = float(sys.argv[2])-timeout_exit_code = int(sys.argv[3])-command = sys.argv[4:]--with open(output_path, "wb") as output_file:- try:- result = subprocess.run(command, stdout=output_file, timeout=timeout_seconds, check=False)- except subprocess.TimeoutExpired:- sys.exit(timeout_exit_code)--sys.exit(result.returncode)-PY- waiter_status=$?-fi-set -e--if [[ "$waiter_status" -eq "$timeout_exit_code" ]]; then- timed_out=1- elapsed_seconds="$(( $(date +%s) - started_at_epoch ))"- {- printf 'Waiter timed out after %s second(s).\n' "$elapsed_seconds"- printf 'Timeout exit code: %s\n' "$timeout_exit_code"- } >"$output_file"-fi--if [[ "$waiter_status" -ne 0 && "$timed_out" -ne 1 ]]; then- echo "Waiter exited with status $waiter_status" >&2- exit "$waiter_status"-fi--if [[ ! -s "$output_file" && -z "$prefix" ]]; then- echo "Waiter succeeded but produced no stdout; skipping hook" >&2- exit 0-fi--{- if [[ -n "$prefix" ]]; then- printf '%s\n' "$prefix"- if [[ -s "$output_file" ]]; then- printf '\n'- fi- fi- if [[ -s "$output_file" ]]; then- cat "$output_file"- fi-} >"$prompt_file"--hook_args=(hook send --session-key "$session_key" --prompt-file "$prompt_file")-if [[ -n "$post_to" ]]; then- hook_args+=(--post-to "$post_to")-fi-if [[ -n "$deliver_key" ]]; then- hook_args+=(--deliver-key "$deliver_key")-fi--_run_hook_command "$hook_runner" "${hook_args[@]}"diff --git a/tests/test_background_watch_hook_scripts.py b/tests/test_background_watch_hook_scripts.pydeleted file mode 100644index f4ae916f6..000000000--- a/tests/test_background_watch_hook_scripts.py+++ /dev/null@@ -1,482 +0,0 @@-from __future__ import annotations--import json-import os-import shutil-import stat-import subprocess-import time-from pathlib import Path---def _make_executable(path: Path, content: str) -> None:- path.write_text(content, encoding="utf-8")- path.chmod(path.stat().st_mode | stat.S_IXUSR)---def test_forever_watch_preserves_catch_up_until_success(tmp_path: Path) -> None:- source_script = (- Path(__file__).resolve().parents[1]- / "skills"- / "background-watch-hook"- / "scripts"- / "watch_github_pr_then_hook.sh"- )- script_dir = tmp_path / "scripts"- script_dir.mkdir()-- watch_script = script_dir / "watch_github_pr_then_hook.sh"- shutil.copy2(source_script, watch_script)- watch_script.write_text(- watch_script.read_text(encoding="utf-8").replace("retry_delay_seconds=30", "retry_delay_seconds=0.1"),- encoding="utf-8",- )- watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)-- count_file = tmp_path / "wrapper-count.txt"- second_call_file = tmp_path / "second-call.json"-- fake_wrapper = f"""#!/usr/bin/env bash-set -euo pipefail--count_file={str(count_file)!r}-count=0-if [[ -f "$count_file" ]]; then- count="$(cat "$count_file")"-fi-count="$((count + 1))"-printf '%s' "$count" > "$count_file"--cursor_file=""-args=("$@")-for ((i=0; i<${{#args[@]}}; i++)); do- if [[ "${{args[$i]}}" == "--" ]]; then- for ((j=i+1; j<${{#args[@]}}; j++)); do- if [[ "${{args[$j]}}" == "--cursor-output" ]]; then- cursor_file="${{args[$((j + 1))]}}"- fi- done- break- fi-done--if [[ "$count" == "1" ]]; then- exit 1-fi--python3 - <<'PY' "{str(second_call_file)}" "$count" "$@"-import json-import sys-from pathlib import Path--out_path = Path(sys.argv[1])-count = int(sys.argv[2])-args = sys.argv[3:]-if count == 2:- out_path.write_text(- json.dumps({{"args": args, "saw_catch_up": "--catch-up" in args}}),- encoding="utf-8",- )-PY--if [[ -n "$cursor_file" ]]; then- python3 - <<'PY' "$cursor_file"-import json-import sys-from pathlib import Path--Path(sys.argv[1]).write_text(- json.dumps({{- "review_cursor": 1,- "review_comment_cursor": 2,- "issue_comment_cursor": 3,- }}),- encoding="utf-8",-)-PY-fi-exit 0-"""- _make_executable(script_dir / "watch_then_hook.sh", fake_wrapper)- _make_executable(- script_dir / "wait_for_github_pr_activity.py",- "#!/usr/bin/env python3\nraise SystemExit('should not be executed directly in this test')\n",- )-- process = subprocess.Popen(- [- "bash",- str(watch_script),- "--foreground",- "--forever",- "--session-key",- "slack::channel::C123",- "--repo",- "cyhhao/vibe-remote",- "--pr",- "153",- "--catch-up",- ],- cwd=tmp_path,- text=True,- stdout=subprocess.PIPE,- stderr=subprocess.PIPE,- env={**os.environ, "PATH": os.environ.get("PATH", "")},- )- deadline = time.time() + 5- try:- while time.time() < deadline:- if second_call_file.exists():- break- if process.poll() is not None:- break- time.sleep(0.05)- finally:- if process.poll() is None:- process.terminate()- try:- process.wait(timeout=2)- except subprocess.TimeoutExpired:- process.kill()- process.wait(timeout=2)-- stderr_output = process.stderr.read() if process.stderr is not None else ""- assert second_call_file.exists(), stderr_output- payload = json.loads(second_call_file.read_text(encoding="utf-8"))- assert payload["saw_catch_up"] is True---def test_forever_watch_suppresses_per_cycle_timeout_hooks(tmp_path: Path) -> None:- source_script = (- Path(__file__).resolve().parents[1]- / "skills"- / "background-watch-hook"- / "scripts"- / "watch_github_pr_then_hook.sh"- )- script_dir = tmp_path / "scripts"- script_dir.mkdir()-- watch_script = script_dir / "watch_github_pr_then_hook.sh"- shutil.copy2(source_script, watch_script)- watch_script.write_text(- watch_script.read_text(encoding="utf-8").replace("retry_delay_seconds=30", "retry_delay_seconds=0.1"),- encoding="utf-8",- )- watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)-- calls_file = tmp_path / "calls.jsonl"-- fake_wrapper = f"""#!/usr/bin/env bash-set -euo pipefail--calls_file={str(calls_file)!r}-python3 - <<'PY' "$calls_file" "$@"-import json-import sys-from pathlib import Path--path = Path(sys.argv[1])-args = sys.argv[2:]-with path.open("a", encoding="utf-8") as handle:- handle.write(json.dumps({{"args": args}}) + "\\n")-PY--if [[ "$*" == *"GitHub PR watch stopped after reaching its lifetime timeout."* ]]; then- exit 0-fi--exit 124-"""- _make_executable(script_dir / "watch_then_hook.sh", fake_wrapper)- _make_executable(- script_dir / "wait_for_github_pr_activity.py",- "#!/usr/bin/env python3\nraise SystemExit('should not be executed directly in this test')\n",- )-- result = subprocess.run(- [- "bash",- str(watch_script),- "--foreground",- "--forever",- "--session-key",- "slack::channel::C123",- "--repo",- "cyhhao/vibe-remote",- "--pr",- "153",- "--timeout",- "10",- "--lifetime-timeout",- "2",- ],- cwd=tmp_path,- capture_output=True,- text=True,- check=False,- timeout=10,- env={**os.environ, "PATH": os.environ.get("PATH", "")},- )-- assert result.returncode == 0, result.stderr- lines = [json.loads(line) for line in calls_file.read_text(encoding="utf-8").splitlines()]- assert len(lines) >= 2- first_args = lines[0]["args"]- assert "--timeout" in first_args- assert "0" in first_args- assert "--timeout-exit-code" in first_args- assert "125" in first_args- assert "retrying" not in result.stderr---def test_detached_watch_preserves_explicit_hook_bin(tmp_path: Path) -> None:- source_script = (- Path(__file__).resolve().parents[1]- / "skills"- / "background-watch-hook"- / "scripts"- / "watch_then_hook.sh"- )- script_dir = tmp_path / "scripts"- script_dir.mkdir()-- watch_script = script_dir / "watch_then_hook.sh"- shutil.copy2(source_script, watch_script)- watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)-- hook_calls = tmp_path / "hook-calls.jsonl"- fake_hook = tmp_path / "fake-hook"- fake_hook.write_text(- f"""#!/usr/bin/env bash-set -euo pipefail--if [[ "${{1:-}}" == "hook" && "${{2:-}}" == "send" && "${{3:-}}" == "--help" ]]; then- echo "custom help without codex phrase"- exit 0-fi--python3 - <<'PY' "{str(hook_calls)}" "$@"-import json-import sys-from pathlib import Path--path = Path(sys.argv[1])-args = sys.argv[2:]-with path.open("a", encoding="utf-8") as handle:- handle.write(json.dumps({{"args": args}}) + "\\n")-PY-""",- encoding="utf-8",- )- fake_hook.chmod(fake_hook.stat().st_mode | stat.S_IXUSR)-- log_file = tmp_path / "watch.log"- result = subprocess.run(- [- "bash",- str(watch_script),- "--session-key",- "slack::channel::C123",- "--hook-bin",- str(fake_hook),- "--log-file",- str(log_file),- "--",- "bash",- "-lc",- "echo waiter output",- ],- cwd=tmp_path,- capture_output=True,- text=True,- check=False,- timeout=10,- env={**os.environ, "PATH": os.environ.get("PATH", "")},- )-- assert result.returncode == 0, result.stderr- deadline = time.time() + 5- while time.time() < deadline:- if hook_calls.exists():- break- time.sleep(0.05)-- assert hook_calls.exists(), log_file.read_text(encoding="utf-8")- payload = json.loads(hook_calls.read_text(encoding="utf-8").splitlines()[-1])- assert payload["args"][:2] == ["hook", "send"]---def test_watch_then_hook_treats_timeout_zero_point_zero_as_no_timeout(tmp_path: Path) -> None:- source_script = (- Path(__file__).resolve().parents[1]- / "skills"- / "background-watch-hook"- / "scripts"- / "watch_then_hook.sh"- )- script_dir = tmp_path / "scripts"- script_dir.mkdir()-- watch_script = script_dir / "watch_then_hook.sh"- shutil.copy2(source_script, watch_script)- watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)-- hook_calls = tmp_path / "hook-calls.jsonl"- fake_hook = tmp_path / "fake-hook"- fake_hook.write_text(- f"""#!/usr/bin/env bash-set -euo pipefail--if [[ "${{1:-}}" == "hook" && "${{2:-}}" == "send" && "${{3:-}}" == "--help" ]]; then- echo "--session-key"- echo "Queue one asynchronous turn"- exit 0-fi--python3 - <<'PY' "{str(hook_calls)}" "$@"-import json-import sys-from pathlib import Path--path = Path(sys.argv[1])-args = sys.argv[2:]-with path.open("a", encoding="utf-8") as handle:- handle.write(json.dumps({{"args": args}}) + "\\n")-PY-""",- encoding="utf-8",- )- fake_hook.chmod(fake_hook.stat().st_mode | stat.S_IXUSR)-- result = subprocess.run(- [- "bash",- str(watch_script),- "--foreground",- "--session-key",- "slack::channel::C123",- "--hook-bin",- str(fake_hook),- "--timeout",- "0.0",- "--",- "bash",- "-lc",- "sleep 0.05; echo waiter output",- ],- cwd=tmp_path,- capture_output=True,- text=True,- check=False,- timeout=10,- env={**os.environ, "PATH": os.environ.get("PATH", "")},- )-- assert result.returncode == 0, result.stderr- payload = json.loads(hook_calls.read_text(encoding="utf-8").splitlines()[-1])- assert payload["args"][:2] == ["hook", "send"]---def test_forever_watch_accepts_lifetime_timeout_zero_point_zero_without_forever_error(tmp_path: Path) -> None:- source_script = (- Path(__file__).resolve().parents[1]- / "skills"- / "background-watch-hook"- / "scripts"- / "watch_github_pr_then_hook.sh"- )- script_dir = tmp_path / "scripts"- script_dir.mkdir()-- watch_script = script_dir / "watch_github_pr_then_hook.sh"- shutil.copy2(source_script, watch_script)- watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)-- _make_executable(- script_dir / "watch_then_hook.sh",- "#!/usr/bin/env bash\nset -euo pipefail\nexit 0\n",- )- _make_executable(- script_dir / "wait_for_github_pr_activity.py",- "#!/usr/bin/env python3\nprint('done')\n",- )-- result = subprocess.run(- [- "bash",- str(watch_script),- "--foreground",- "--session-key",- "slack::channel::C123",- "--repo",- "cyhhao/vibe-remote",- "--pr",- "153",- "--lifetime-timeout",- "0.0",- ],- cwd=tmp_path,- capture_output=True,- text=True,- check=False,- timeout=10,- env={**os.environ, "PATH": os.environ.get("PATH", "")},- )-- assert result.returncode == 0, result.stderr- assert "--lifetime-timeout requires --forever" not in result.stderr---def test_forever_watch_exits_on_non_retryable_cycle_failure(tmp_path: Path) -> None:- source_script = (- Path(__file__).resolve().parents[1]- / "skills"- / "background-watch-hook"- / "scripts"- / "watch_github_pr_then_hook.sh"- )- script_dir = tmp_path / "scripts"- script_dir.mkdir()-- watch_script = script_dir / "watch_github_pr_then_hook.sh"- shutil.copy2(source_script, watch_script)- watch_script.write_text(- watch_script.read_text(encoding="utf-8").replace("retry_delay_seconds=30", "retry_delay_seconds=0.1"),- encoding="utf-8",- )- watch_script.chmod(watch_script.stat().st_mode | stat.S_IXUSR)-- _make_executable(- script_dir / "watch_then_hook.sh",- "#!/usr/bin/env bash\nset -euo pipefail\nexit 2\n",- )- _make_executable(- script_dir / "wait_for_github_pr_activity.py",- "#!/usr/bin/env python3\nraise SystemExit('should not be executed directly in this test')\n",- )-- result = subprocess.run(- [- "bash",- str(watch_script),- "--foreground",- "--forever",- "--session-key",- "slack::channel::C123",- "--repo",- "cyhhao/vibe-remote",- "--pr",- "153",- ],- cwd=tmp_path,- capture_output=True,- text=True,- check=False,- timeout=10,- env={**os.environ, "PATH": os.environ.get("PATH", "")},- )-- assert result.returncode == 2- assert "non-retryable" in result.stderr- assert "retrying" not in result.stderr