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
Stop the ops-daemon restart loop from duelling plist writers (#943)
Aurora Capital59c6b9a44e58
diff --git a/claude-ops/scripts/ops-daemon-manager.sh b/claude-ops/scripts/ops-daemon-manager.shindex 1058a8da..c7ab458a 100755--- a/claude-ops/scripts/ops-daemon-manager.sh+++ b/claude-ops/scripts/ops-daemon-manager.sh@@ -310,10 +310,31 @@ cmd_ensure_current() {if [[ "$plist_script" == "$current_script" ]]; thenexit 0fi+ # A wrapper living in the plugin DATA dir is a deliberate local override, not+ # stale drift. It resolves the newest plugin version itself at every start, so+ # rewriting the plist back to $PLUGIN_ROOT gains nothing — and costs a restart+ # loop: the data-dir plist guard watches this file and writes the wrapper path+ # straight back, each write booting the daemon out before it finishes its first+ # monitor pass. Leave an intentional wrapper alone.+ if [[ -n "$plist_script" ]] && _is_data_dir_wrapper "$plist_script"; then+ log "plist points at data-dir wrapper ($plist_script) — leaving it in place"+ exit 0+ filog "plist points at stale version ($plist_script); upgrading to $PLUGIN_ROOT"cmd_upgrade}+# True when PATH is an executable ops daemon wrapper inside the plugin data dir.+# Both conditions matter: the prefix proves it is ours, and the exec bit proves+# it can actually run — a stale path under the data dir must still be repaired.+_is_data_dir_wrapper() {+ local candidate="$1"+ local data_root="${CLAUDE_PLUGIN_DATA_DIR:-$HOME/.claude/plugins/data/ops-ops-marketplace}"+ [[ "$candidate" == "$data_root"/* ]] || return 1+ [[ -x "$candidate" ]] || return 1+ return 0+}+cmd_uninstall() {case "$OS" inmacos)diff --git a/claude-ops/tests/test-daemon-ensure-current-wrapper.sh b/claude-ops/tests/test-daemon-ensure-current-wrapper.shnew file mode 100755index 00000000..8cbaeef4--- /dev/null+++ b/claude-ops/tests/test-daemon-ensure-current-wrapper.sh@@ -0,0 +1,88 @@+#!/opt/homebrew/bin/bash+# End-to-end: run the real `ensure-current` against a fake HOME and assert it+# leaves a data-dir wrapper plist untouched, but still repairs a genuinely+# stale plugin-version path.+set -uo pipefail++MGR="$1"+T="$(mktemp -d)"+trap 'rm -rf "$T"' EXIT++FAKE_HOME="$T/home"+DATA="$FAKE_HOME/.claude/plugins/data/ops-ops-marketplace"+NEWROOT="$FAKE_HOME/.claude/plugins/cache/ops-marketplace/ops/9.9.9"+OLDROOT="$FAKE_HOME/.claude/plugins/cache/ops-marketplace/ops/1.0.0"+AGENTS="$FAKE_HOME/Library/LaunchAgents"+PLIST="$AGENTS/com.claude-ops.daemon.plist"++mkdir -p "$DATA/bin" "$NEWROOT/scripts" "$OLDROOT/scripts" "$AGENTS"+printf '#!/bin/sh\n' > "$DATA/bin/ops-daemon.sh"; chmod 755 "$DATA/bin/ops-daemon.sh"+printf '#!/bin/sh\n' > "$NEWROOT/scripts/ops-daemon.sh"; chmod 755 "$NEWROOT/scripts/ops-daemon.sh"+printf '#!/bin/sh\n' > "$OLDROOT/scripts/ops-daemon.sh"; chmod 755 "$OLDROOT/scripts/ops-daemon.sh"+# The manager needs its own plist template to be able to rewrite.+cp "$(dirname "$MGR")/com.claude-ops.daemon.plist" "$NEWROOT/scripts/" 2>/dev/null || true++write_plist() {+ cat > "$PLIST" <<PLISTEOF+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>Label</key>+ <string>com.claude-ops.daemon</string>+ <key>ProgramArguments</key>+ <array>+ <string>/opt/homebrew/bin/bash</string>+ <string>$1</string>+ </array>+</dict>+</plist>+PLISTEOF+}++plist_target() {+ /usr/libexec/PlistBuddy -c "Print :ProgramArguments:1" "$PLIST" 2>/dev/null+}++fails=0+check() {+ local desc="$1" want="$2" got="$3"+ if [[ "$want" == "$got" ]]; then+ printf 'PASS %s\n' "$desc"+ else+ printf 'FAIL %s\n want=%s\n got=%s\n' "$desc" "$want" "$got"+ fails=$((fails + 1))+ fi+}++# ── Case 1: plist points at the data-dir wrapper. Must be left alone. ────────+write_plist "$DATA/bin/ops-daemon.sh"+before="$(plist_target)"+HOME="$FAKE_HOME" CLAUDE_PLUGIN_DATA_DIR="$DATA" \+ /opt/homebrew/bin/bash "$MGR" ensure-current --plugin-root "$NEWROOT" --dry-run >"$T/out1" 2>&1+rc1=$?+after="$(plist_target)"+check "wrapper plist unchanged by ensure-current" "$before" "$after"+check "ensure-current exits 0 on wrapper" "0" "$rc1"+if grep -q "leaving it in place" "$T/out1"; then+ echo "PASS logged the deliberate-override decision"+else+ echo "FAIL expected 'leaving it in place' in output; got:"+ sed 's/^/ /' "$T/out1"+ fails=$((fails + 1))+fi++# ── Case 2: plist points at an OLD plugin version. Must still be repaired. ──+write_plist "$OLDROOT/scripts/ops-daemon.sh"+HOME="$FAKE_HOME" CLAUDE_PLUGIN_DATA_DIR="$DATA" \+ /opt/homebrew/bin/bash "$MGR" ensure-current --plugin-root "$NEWROOT" --dry-run >"$T/out2" 2>&1+if grep -q "stale version" "$T/out2"; then+ echo "PASS genuine stale-version drift still detected"+else+ echo "FAIL expected 'stale version' for old plugin path; got:"+ sed 's/^/ /' "$T/out2"+ fails=$((fails + 1))+fi++echo "--- $fails failure(s) ---"+exit $(( fails > 0 ? 1 : 0 ))diff --git a/claude-ops/tests/test-daemon-plist-wrapper-detect.sh b/claude-ops/tests/test-daemon-plist-wrapper-detect.shnew file mode 100755index 00000000..8f1e411f--- /dev/null+++ b/claude-ops/tests/test-daemon-plist-wrapper-detect.sh@@ -0,0 +1,58 @@+#!/opt/homebrew/bin/bash+# Focused test for _is_data_dir_wrapper from ops-daemon-manager.sh.+set -uo pipefail++MGR="$1"+T="$(mktemp -d)"+trap 'rm -rf "$T"' EXIT++mkdir -p "$T/data" "$T/plugin/scripts"+: > "$T/plugin/scripts/ops-daemon.sh"+printf '#!/bin/sh\n' > "$T/data/bin-wrapper.sh"; chmod 755 "$T/data/bin-wrapper.sh"+printf '#!/bin/sh\n' > "$T/data/not-exec.sh"; chmod 644 "$T/data/not-exec.sh"++# Pull only the helper out of the manager, so we test it without running the CLI.+sed -n '/^_is_data_dir_wrapper()/,/^}/p' "$MGR" > "$T/fn.sh"+if [[ ! -s "$T/fn.sh" ]]; then+ echo "FAIL: could not extract _is_data_dir_wrapper from $MGR"+ exit 1+fi+echo "--- extracted helper ---"+cat "$T/fn.sh"+echo "--- results ---"++export CLAUDE_PLUGIN_DATA_DIR="$T/data"+# shellcheck source=/dev/null+source "$T/fn.sh"++fails=0+check() {+ local desc="$1" want="$2" got="$3"+ if [[ "$want" == "$got" ]]; then+ printf 'PASS %-46s got=%s\n' "$desc" "$got"+ else+ printf 'FAIL %-46s want=%s got=%s\n' "$desc" "$want" "$got"+ fails=$((fails + 1))+ fi+}++run() { _is_data_dir_wrapper "$1" && echo true || echo false; }++check "exec wrapper inside data dir" true "$(run "$T/data/bin-wrapper.sh")"+check "non-exec file inside data dir" false "$(run "$T/data/not-exec.sh")"+check "plugin script outside data dir" false "$(run "$T/plugin/scripts/ops-daemon.sh")"+check "empty path" false "$(run "")"+check "missing file inside data dir" false "$(run "$T/data/absent.sh")"+check "data-dir prefix lookalike sibling" false "$(run "${T}/data-evil/bin.sh")"++# The real caller runs under set -u; prove the helper survives it.+set -u+if _is_data_dir_wrapper "$T/data/bin-wrapper.sh"; then+ echo "PASS survives set -u got=exit0"+else+ echo "FAIL survives set -u"+ fails=$((fails + 1))+fi++echo "--- $fails failure(s) ---"+exit $(( fails > 0 ? 1 : 0 ))