Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.
Shell agent-teamsai-agentai-automationanthropicautonomous-agentawsbusiness-operationsclaudeclaude-codeclaude-code-plugindevopsecommerceinbox-zeroklaviyomarketingmcpmorning-briefingpr-automationshopifyterminal
feat(update): notice a stale install on any skill call, optionally self-heal (#986)
hypehouseagencya953abe0ebbb
diff --git a/claude-ops/CHANGELOG.md b/claude-ops/CHANGELOG.mdindex 62027e75..bf8ad390 100644--- a/claude-ops/CHANGELOG.md+++ b/claude-ops/CHANGELOG.md@@ -2,6 +2,32 @@## Unreleased+### Added+- The plugin now notices its own staleness. `bin/ops-update-check` only ever ran+ from the daemon's daily cron and wrote a verdict to a state file that nothing+ read, so a box whose daemon was never installed could sit months behind+ without a word — one install surfaced this at 3.4.3 while 3.10.18 was+ published, 144 releases back. A new `PreToolUse` hook on `^Skill$`+ (`bin/ops-pretool-skill-update`) re-uses that same throttled check whenever an+ ops skill is invoked, so the first skill call of the day reports what the cron+ would have reported. `auto_update` in `preferences.json` picks the response:+ `off`, `notify` (default, just says so) or `auto`, which additionally runs+ `bin/ops-update` detached behind a lock and asks for a reload. `auto` is+ opt-in precisely because detection and application are otherwise kept apart;+ the running session keeps its old version until it reloads. The hook cannot+ block the skill it fired on — it exits 0 on every path, including a failing+ version check — and only fires for skills that belong to this plugin.+ Guard: `tests/test-skill-update-gate.sh` (10 cases).++### Fixed+- `ops-update` no longer deletes the tree it is running from. Step 5 pruned+ every cache version except the target, including the one the executing script+ lived in; bash reads a script incrementally, so that could truncate the update+ mid-run, and any session rooted in that version lost its hooks and scripts+ underneath it. The running version is now kept, with a note that the next run+ prunes it — by which time the live root has moved on. Guard: two cases in+ `tests/test-ops-update-downgrade-guard.sh`, mutation proven red.+## [3.10.18] - 2026-09-16### Fixeddiff --git a/claude-ops/bin/ops-pretool-skill-update b/claude-ops/bin/ops-pretool-skill-updatenew file mode 100755index 00000000..f2fbf99f--- /dev/null+++ b/claude-ops/bin/ops-pretool-skill-update@@ -0,0 +1,101 @@+#!/usr/bin/env bash+# ops-pretool-skill-update — PreToolUse(Skill) hook: notice a newer published+# version when an ops skill is invoked, and (opt-in) install it in the+# background so the box stops drifting versions behind.+#+# Without this, `bin/ops-update-check` only ever runs from the daemon's 09:17+# cron and writes a state file nobody reads, so a box whose daemon is not+# installed (Linux, or launchd never set up) can sit months behind and never+# hear about it.+#+# Usage: invoked by hooks.json on PreToolUse matcher ^Skill$, stdin = hook JSON.+#+# auto_update = off do nothing+# notify (default) tell the session an update is available+# auto also run `ops-update` in the background, then tell+# the session to reload+#+# Set in preferences.json ("auto_update": "auto") or via the environment+# (OPS_AUTO_UPDATE / CLAUDE_PLUGIN_OPTION_AUTO_UPDATE).+#+# Exit codes: always 0 — a hook must never block the skill it fired on.+#+# Public repo: no personal data. All paths derive from $HOME / env. (Rule 0)++# No `set -e`: a failure anywhere here must not take the Skill call with it.+set -uo pipefail++PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}"+STATE_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/state/ops-update"+LOG_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/logs/ops"+LOCK_DIR="$STATE_DIR/.auto-update.lock"++# shellcheck source=/dev/null+. "$PLUGIN_ROOT/scripts/lib/deploy-fix-common.sh" 2>/dev/null || { config() { echo "${2:-}"; }; }++MODE="${OPS_AUTO_UPDATE:-$(config auto_update notify)}"+[ "$MODE" = "off" ] && exit 0++command -v jq >/dev/null 2>&1 || exit 0++INPUT=$(cat 2>/dev/null || true)+skill=$(printf '%s' "$INPUT" | jq -r '.tool_input.skill // ""' 2>/dev/null)+[ -n "$skill" ] || exit 0++# Only fire for skills that belong to THIS plugin. Skills arrive either bare+# ("ops-status") or plugin-qualified ("ops:ops-status"); the directory is the+# authority, so an unrelated plugin's skill can never trigger a self-update.+[ -d "$PLUGIN_ROOT/skills/${skill##*:}" ] || exit 0++# Detect. ops-update-check throttles itself (24h by default), so the common+# case costs one file read and no network.+"$PLUGIN_ROOT/bin/ops-update-check" --quiet >/dev/null 2>&1+rc=$?+[ "$rc" -eq 3 ] || exit 0 # 0 = already current, 1 = undeterminable++published=$(jq -r '.published // ""' "$STATE_DIR/update-available.json" 2>/dev/null)+installed=$(jq -r '.installed // ""' "$STATE_DIR/update-available.json" 2>/dev/null)+[ -n "$published" ] || exit 0++emit() {+ python3 -c '+import json, sys+print(json.dumps({+ "hookSpecificOutput": {+ "hookEventName": "PreToolUse",+ "additionalContext": sys.argv[1],+ },+ "suppressOutput": True,+}))' "$1" 2>/dev/null+}++if [ "$MODE" != "auto" ]; then+ emit "claude-ops ${installed:-?} is behind published ${published}. Run /ops:ops-update to upgrade."+ exit 0+fi++# ── auto ──────────────────────────────────────────────────────────────────+# One updater at a time. mkdir is the atomic test-and-set; a stale lock older+# than an hour is reclaimed so a killed updater cannot wedge this forever.+mkdir -p "$STATE_DIR" "$LOG_DIR" 2>/dev/null+if ! mkdir "$LOCK_DIR" 2>/dev/null; then+ if [ -n "$(find "$LOCK_DIR" -maxdepth 0 -mmin +60 2>/dev/null)" ]; then+ rmdir "$LOCK_DIR" 2>/dev/null && mkdir "$LOCK_DIR" 2>/dev/null || exit 0+ else+ exit 0 # an update is already running+ fi+fi++# Detached: the skill this hook fired on must not wait for a plugin upgrade.+# The updater releases the lock itself, including on failure.+(+ {+ printf '[%s] auto-update %s → %s\n' "$(date '+%Y-%m-%dT%H:%M:%S')" "${installed:-?}" "$published"+ OPS_UPDATE_IN_SESSION=1 bash "$PLUGIN_ROOT/bin/ops-update"+ printf '[%s] exit=%s\n' "$(date '+%Y-%m-%dT%H:%M:%S')" "$?"+ } >>"$LOG_DIR/auto-update.log" 2>&1+ rmdir "$LOCK_DIR" 2>/dev/null+) </dev/null >/dev/null 2>&1 &++emit "claude-ops ${installed:-?} is behind published ${published}; upgrading in the background (log: ~/.claude/logs/ops/auto-update.log). Run /reload-plugins, or restart, once it finishes — this session keeps running the old version until then."+exit 0diff --git a/claude-ops/bin/ops-update b/claude-ops/bin/ops-updateindex 213a5751..eb7838a1 100755--- a/claude-ops/bin/ops-update+++ b/claude-ops/bin/ops-update@@ -297,7 +297,7 @@ step "5/11 Prune old cache versions"if [[ "$PRUNE" -eq 0 ]]; thensay " ${c_dim}(skipped: --no-prune)${c_rst}"else- pruned=0; kept_newer=""+ pruned=0; kept_newer=""; kept_running=""for d in "$CACHE_ROOT"/*/; do[[ -d "$d" ]] || continuev="$(basename "$d")"@@ -309,10 +309,19 @@ elseif semver_lt "$NEW" "$v" && [[ "$ALLOW_DOWNGRADE" -eq 0 ]]; thenkept_newer="$kept_newer $v"; continuefi+ # Never delete the tree this very script is running from. bash reads a+ # script incrementally, so rm -rf'ing it mid-run can truncate the rest of+ # the update — and any session currently rooted there loses its hooks and+ # scripts under its feet. The next run prunes it, by which time the live+ # root is the new version (or `current/`, which is refreshed in step 7).+ if [[ "$d" == "$THIS_ROOT"/ || "$THIS_ROOT" == "$d"* ]]; then+ kept_running="$v"; continue+ firun "rm -rf \"$d\""ok "pruned cache $v"; pruned=$((pruned+1))done[[ -n "$kept_newer" ]] && warn "kept cache(s) newer than $NEW:${kept_newer} (pass --allow-downgrade to prune them)"+ [[ -n "$kept_running" ]] && warn "kept cache $kept_running: this update is running from it (the next run prunes it)"[[ "$pruned" -eq 0 ]] && say " ${c_dim}no old cache versions to prune${c_rst}"fidiff --git a/claude-ops/hooks/hooks.json b/claude-ops/hooks/hooks.jsonindex 78370e67..491508ff 100644--- a/claude-ops/hooks/hooks.json+++ b/claude-ops/hooks/hooks.json@@ -70,6 +70,16 @@}]},+ {+ "matcher": "^Skill$",+ "hooks": [+ {+ "type": "command",+ "command": "bash ${CLAUDE_PLUGIN_ROOT}/bin/ops-pretool-skill-update 2>/dev/null || true",+ "timeout": 5+ }+ ]+ },{"matcher": "*","hooks": [diff --git a/claude-ops/skills/ops-update/SKILL.md b/claude-ops/skills/ops-update/SKILL.mdindex fec44218..c2f9c7c6 100644--- a/claude-ops/skills/ops-update/SKILL.md+++ b/claude-ops/skills/ops-update/SKILL.md@@ -40,6 +40,28 @@ Then a single `AskUserQuestion`: `[Update now]` `[Show what changed]` `[Not now]Only on `Update now` do you run `bin/ops-update`. Never chain the two, and neverapply an update the user has not just agreed to in that exchange.+## Checking on every skill call++The daily cron is the only thing that ever ran the check, so a box without the+daemon (Linux, or launchd never set up) heard about a new version exactly never.+`bin/ops-pretool-skill-update` closes that: a `PreToolUse` hook on `^Skill$`+re-uses the same throttled check whenever an ops skill is invoked, so the first+skill call of the day says what the daily cron would have said.++Behaviour is set by `auto_update` in `preferences.json` (or `$OPS_AUTO_UPDATE`):++| Mode | What happens on a stale install |+| -------------------- | ------------------------------------------------------------------------ |+| `off` | nothing |+| `notify` _(default)_ | the session is told it is behind, and to run `/ops:ops-update` |+| `auto` | also runs `bin/ops-update` in the background, then asks for a reload |++`auto` is the one exception to the split above, and it stays opt-in for the+reason stated there: the running session keeps the old version until it reloads,+so the upgrade lands detached, behind a lock, and never prunes the tree the+session is rooted in. Turning it on is the user's decision, not yours — never+switch a box to `auto` on your own initiative.+Flags: `--json` (verdict on stdout), `--no-fetch` (compare against the cataloguealready on disk, no network), `--force` (ignore the once-a-day throttle),`--quiet` (write state, print nothing — how the daemon runs it). Override thediff --git a/claude-ops/tests/run-all.sh b/claude-ops/tests/run-all.shindex 4428b299..7f8cb95e 100755--- a/claude-ops/tests/run-all.sh+++ b/claude-ops/tests/run-all.sh@@ -43,6 +43,7 @@ run_suite "$TESTS_DIR/test-ops-ci.sh"run_suite "$TESTS_DIR/test-ops-speedup.sh"run_suite "$TESTS_DIR/test-ops-update-stale-clone.sh"run_suite "$TESTS_DIR/test-ops-update-downgrade-guard.sh"+run_suite "$TESTS_DIR/test-skill-update-gate.sh"run_suite "$TESTS_DIR/test-ops-status.sh"run_suite "$TESTS_DIR/test-pid-performance-monitor.sh"run_suite "$TESTS_DIR/test-run-pressure-monitor-if-needed.sh"diff --git a/claude-ops/tests/test-ops-update-downgrade-guard.sh b/claude-ops/tests/test-ops-update-downgrade-guard.shindex 5893397b..97b2aa95 100755--- a/claude-ops/tests/test-ops-update-downgrade-guard.sh+++ b/claude-ops/tests/test-ops-update-downgrade-guard.sh@@ -231,6 +231,27 @@ elsefail "cross-digit tag check flags 3.9.20 catalogue behind v3.10.0 (rc=$RC, got: $(head -c 400 <<<"$out10"))"fi+# ── 11. The running tree survives its own prune.+# Step 5 used to delete every cache dir except the target, including the one+# ops-update itself was executing from. bash reads a script incrementally,+# so that can truncate the update mid-run, and any session rooted there+# loses its hooks. The next run prunes it, once the live root has moved.+b11="$tmpdir/self-prune"+make_fixture "$b11" 3.10.17 "v3.10.17" 3.10.15,3.10.16 >/dev/null+CLAUDE_PLUGIN_ROOT="$b11/cfg/plugins/cache/ops-marketplace/ops/3.10.15" \+ run_update "$b11" --dry-run+out11="$OUT"+if grep -qF "kept cache 3.10.15: this update is running from it" <<<"$out11"; then+ pass "does not prune the cache dir it is running from"+else+ fail "does not prune the cache dir it is running from (rc=$RC, got: $(head -c 400 <<<"$out11"))"+fi+if grep -qF "pruned cache 3.10.16" <<<"$out11"; then+ pass "still prunes the other superseded caches"+else+ fail "still prunes the other superseded caches (got: $(head -c 400 <<<"$out11"))"+fi+echo ""echo "test-ops-update-downgrade-guard.sh: $PASS passed, $FAIL failed"[ "$FAIL" -eq 0 ]diff --git a/claude-ops/tests/test-skill-update-gate.sh b/claude-ops/tests/test-skill-update-gate.shnew file mode 100755index 00000000..e85bc638--- /dev/null+++ b/claude-ops/tests/test-skill-update-gate.sh@@ -0,0 +1,171 @@+#!/usr/bin/env bash+# Contract tests for bin/ops-pretool-skill-update — the PreToolUse(Skill) hook+# that notices a newer published version and, in "auto" mode, upgrades in the+# background.+#+# The hook fires on every Skill call, so the properties that matter are mostly+# about what it must NOT do: never block the skill, never fire for another+# plugin's skill, never start a second updater while one is running, and never+# run at all when switched off.+#+# ops-update-check is stubbed via PATH-independent plugin-root layout: the+# fixture is a fake plugin root, so no real install is touched.+# Public plugin: no real host paths or personal data.+set -euo pipefail++ROOT="$(cd "$(dirname "$0")/.." && pwd)"+PASS=0+FAIL=0++pass() { echo " PASS: $1"; PASS=$((PASS + 1)); }+fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }++echo "== skill update gate =="++if ! command -v jq >/dev/null 2>&1; then+ echo " SKIP: jq is required"+ echo "test-skill-update-gate.sh: 0 passed, 0 failed (skipped)"+ exit 0+fi++tmpdir=$(mktemp -d)+trap 'rm -rf "$tmpdir"' EXIT++# Fixture: a plugin root holding the real hook, a stub ops-update-check that+# exits with $1, a stub ops-update that just records that it ran, and one+# skill directory named "ops-status".+make_root() {+ local base="$1" check_exit="$2"+ local root="$base/plugin"+ mkdir -p "$root/bin" "$root/skills/ops-status" "$root/scripts/lib"+ cp "$ROOT/bin/ops-pretool-skill-update" "$root/bin/"+ cat >"$root/bin/ops-update-check" <<EOF+#!/usr/bin/env bash+mkdir -p "\$CLAUDE_CONFIG_DIR/state/ops-update"+printf '{"installed":"1.0.0","published":"2.0.0"}\n' \+ >"\$CLAUDE_CONFIG_DIR/state/ops-update/update-available.json"+exit $check_exit+EOF+ cat >"$root/bin/ops-update" <<'EOF'+#!/usr/bin/env bash+touch "$CLAUDE_CONFIG_DIR/updater-ran"+EOF+ chmod +x "$root/bin/ops-update-check" "$root/bin/ops-update"+ echo "$root"+}++# Run the hook with skill name $2 and mode $3 against fixture root $1.+# Echoes stdout; the caller inspects it and the fixture's side effects.+run_hook() {+ local root="$1" skill="$2" mode="$3"+ printf '{"tool_input":{"skill":"%s"}}' "$skill" |+ CLAUDE_PLUGIN_ROOT="$root" \+ CLAUDE_CONFIG_DIR="$(dirname "$root")/cfg" \+ HOME="$(dirname "$root")/cfg" \+ OPS_AUTO_UPDATE="$mode" \+ bash "$root/bin/ops-pretool-skill-update" 2>/dev/null+}++# ── 1. auto mode: update available → updater starts, session is told ───────+base="$tmpdir/auto"; mkdir -p "$base/cfg"+root=$(make_root "$base" 3)+out=$(run_hook "$root" "ops-status" auto)+# The updater is detached, so give it a moment to touch its marker.+for _ in 1 2 3 4 5 6 7 8 9 10; do+ [ -f "$base/cfg/updater-ran" ] && break+ sleep 0.2+done+if [ -f "$base/cfg/updater-ran" ]; then+ pass "auto mode starts the updater"+else+ fail "auto mode did not start the updater"+fi+if printf '%s' "$out" | jq -e '.hookSpecificOutput.additionalContext | test("2.0.0")' >/dev/null 2>&1; then+ pass "auto mode reports the new version to the session"+else+ fail "auto mode did not report the new version (got: ${out:-<empty>})"+fi++# ── 2. notify mode: tells, never upgrades ─────────────────────────────────+base="$tmpdir/notify"; mkdir -p "$base/cfg"+root=$(make_root "$base" 3)+out=$(run_hook "$root" "ops-status" notify)+sleep 0.4+if [ ! -f "$base/cfg/updater-ran" ]; then+ pass "notify mode leaves the install alone"+else+ fail "notify mode ran the updater"+fi+if printf '%s' "$out" | jq -e '.hookSpecificOutput.additionalContext | test("ops-update")' >/dev/null 2>&1; then+ pass "notify mode points at /ops:ops-update"+else+ fail "notify mode said nothing useful (got: ${out:-<empty>})"+fi++# ── 3. off: does nothing at all, even with an update waiting ──────────────+base="$tmpdir/off"; mkdir -p "$base/cfg"+root=$(make_root "$base" 3)+out=$(run_hook "$root" "ops-status" off)+sleep 0.4+if [ ! -f "$base/cfg/updater-ran" ] && [ -z "$out" ]; then+ pass "off mode is silent and inert"+else+ fail "off mode was not inert (output: ${out:-<empty>})"+fi++# ── 4. already current (exit 0) → nothing happens ─────────────────────────+base="$tmpdir/current"; mkdir -p "$base/cfg"+root=$(make_root "$base" 0)+out=$(run_hook "$root" "ops-status" auto)+sleep 0.4+if [ ! -f "$base/cfg/updater-ran" ] && [ -z "$out" ]; then+ pass "no update available → no upgrade, no noise"+else+ fail "acted despite being current (output: ${out:-<empty>})"+fi++# ── 5. another plugin's skill → not our business ──────────────────────────+base="$tmpdir/foreign"; mkdir -p "$base/cfg"+root=$(make_root "$base" 3)+out=$(run_hook "$root" "some-other-plugin-skill" auto)+sleep 0.4+if [ ! -f "$base/cfg/updater-ran" ] && [ -z "$out" ]; then+ pass "a non-ops skill does not trigger a self-update"+else+ fail "fired for a foreign skill (output: ${out:-<empty>})"+fi++# ── 6. plugin-qualified skill name ("ops:ops-status") still matches ───────+base="$tmpdir/qualified"; mkdir -p "$base/cfg"+root=$(make_root "$base" 3)+out=$(run_hook "$root" "ops:ops-status" auto)+if printf '%s' "$out" | jq -e '.hookSpecificOutput' >/dev/null 2>&1; then+ pass "plugin-qualified skill names match"+else+ fail "plugin-qualified skill name was ignored (got: ${out:-<empty>})"+fi++# ── 7. lock held → no second updater ──────────────────────────────────────+base="$tmpdir/locked"; mkdir -p "$base/cfg/state/ops-update/.auto-update.lock"+root=$(make_root "$base" 3)+out=$(run_hook "$root" "ops-status" auto)+sleep 0.4+if [ ! -f "$base/cfg/updater-ran" ]; then+ pass "a held lock prevents a concurrent updater"+else+ fail "started a second updater while the lock was held"+fi++# ── 8. a broken update-check must not break the skill call ────────────────+base="$tmpdir/broken"; mkdir -p "$base/cfg"+root=$(make_root "$base" 3)+printf '#!/usr/bin/env bash\nexit 9\n' >"$root/bin/ops-update-check"+chmod +x "$root/bin/ops-update-check"+if run_hook "$root" "ops-status" auto >/dev/null 2>&1; then+ pass "hook exits 0 when the version check fails"+else+ fail "hook returned non-zero — that would surface on every Skill call"+fi++echo "test-skill-update-gate.sh: $PASS passed, $FAIL failed"+[ "$FAIL" -eq 0 ]