Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

fix(skills): auto-detect real vibe hook command

cyhc68498cf2704
diff --git a/skills/background-watch-hook/SKILL.md b/skills/background-watch-hook/SKILL.md
index c8acef588..253b58fd3 100644
--- a/skills/background-watch-hook/SKILL.md
+++ b/skills/background-watch-hook/SKILL.md
@@ -73,8 +73,9 @@ scripts/watch_then_hook.sh \
--session-key "<session-key>" \
[--prefix "<hook prefix>"] \
[--post-to channel] \
- [--deliver-key "<dedupe-key>"] \
+ [--deliver-key "<delivery-session-key>"] \
[--hook-bin vibe] \
+ [--hook-cmd "uv run python -m vibe"] \
[--timeout-exit-code 124] \
-- <waiter command ...>
```
@@ -86,12 +87,16 @@ scripts/watch_then_hook.sh \
- `--post-to`
Optional. Use only when the follow-up should post to the parent channel while keeping thread context.
- `--deliver-key`
- Optional. Pass through when the caller needs dedupe semantics.
+ Optional. Explicit delivery target key. Use this only when the follow-up should be delivered to a different target.
- `--hook-bin`
- Optional. Override only for testing or unusual environments.
+ Optional. Explicit hook executable override.
+- `--hook-cmd`
+ Optional. Full hook command override. Useful when the local `vibe` on `PATH` is a stub and the real CLI should run through something like `uv run python -m vibe`.
- `--timeout-exit-code`
Optional. The wrapper treats this exit code as a silent timeout.
+`--post-to` and `--deliver-key` are mutually exclusive. Fail fast if both are set.
+
## Preferred Execution Pattern
Run the wrapper itself in the background with `nohup bash -lc '...'`:
@@ -111,6 +116,8 @@ nohup bash -lc '
That command returns immediately, leaves the watcher running, and sends the hook only after the waiter exits with success.
+When running inside the Vibe Remote repo or worktree, the wrapper will auto-fallback to `uv run python -m vibe` if the `vibe` executable on `PATH` is not the real CLI.
+
## Generic Workflow
### 1. Pick the waiter
diff --git a/skills/background-watch-hook/scripts/watch_then_hook.sh b/skills/background-watch-hook/scripts/watch_then_hook.sh
index 697ce4f2b..8b6b1cbf1 100755
--- a/skills/background-watch-hook/scripts/watch_then_hook.sh
+++ b/skills/background-watch-hook/scripts/watch_then_hook.sh
@@ -10,8 +10,9 @@ Options:
--session-key <value> Required. Target session key for vibe hook send.
--prefix <value> Optional. Text prepended before waiter stdout.
--post-to <value> Optional. Passed through to vibe hook send.
- --deliver-key <value> Optional. Passed through to vibe hook send.
- --hook-bin <value> Optional. Hook CLI binary. Default: vibe
+ --deliver-key <value> Optional. Explicit delivery target key for vibe hook send.
+ --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. Silent exit code. Default: 124
-h, --help Show this help.
@@ -28,7 +29,8 @@ session_key=""
prefix=""
post_to=""
deliver_key=""
-hook_bin="${VIBE_HOOK_BIN:-vibe}"
+hook_bin="${VIBE_HOOK_BIN:-}"
+hook_cmd_override="${VIBE_HOOK_CMD:-}"
timeout_exit_code=124
while [[ $# -gt 0 ]]; do
@@ -53,6 +55,10 @@ while [[ $# -gt 0 ]]; do
hook_bin="${2:-}"
shift 2
;;
+ --hook-cmd)
+ hook_cmd_override="${2:-}"
+ shift 2
+ ;;
--timeout-exit-code)
timeout_exit_code="${2:-124}"
shift 2
@@ -85,9 +91,9 @@ if [[ $# -eq 0 ]]; then
exit 2
fi
-if ! command -v "$hook_bin" >/dev/null 2>&1; then
- echo "Hook binary not found: $hook_bin" >&2
- exit 127
+if [[ -n "$post_to" && -n "$deliver_key" ]]; then
+ echo "--post-to and --deliver-key are mutually exclusive" >&2
+ exit 2
fi
output_file="$(mktemp)"
@@ -97,6 +103,79 @@ cleanup() {
}
trap cleanup EXIT
+_resolve_hook_command() {
+ if [[ -n "$hook_cmd_override" ]]; then
+ printf '%s\n' "$hook_cmd_override"
+ return 0
+ 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[@]}"
+}
+
set +e
"$@" >"$output_file"
waiter_status=$?
@@ -128,12 +207,13 @@ fi
fi
} >"$prompt_file"
-hook_cmd=("$hook_bin" hook send --session-key "$session_key" --prompt-file "$prompt_file")
+hook_runner="$(_resolve_hook_command)"
+hook_args=(hook send --session-key "$session_key" --prompt-file "$prompt_file")
if [[ -n "$post_to" ]]; then
- hook_cmd+=(--post-to "$post_to")
+ hook_args+=(--post-to "$post_to")
fi
if [[ -n "$deliver_key" ]]; then
- hook_cmd+=(--deliver-key "$deliver_key")
+ hook_args+=(--deliver-key "$deliver_key")
fi
-"${hook_cmd[@]}"
+_run_hook_command "$hook_runner" "${hook_args[@]}"