Skip to content

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.

fix(marketing): label dormant ad accounts Idle, not Critical (#609)

Aurora Capital5da408c7e2cf
diff --git a/claude-ops/scripts/lib/marketing-kpis.sh b/claude-ops/scripts/lib/marketing-kpis.sh
index 192e823f..25f6facc 100755
--- a/claude-ops/scripts/lib/marketing-kpis.sh
+++ b/claude-ops/scripts/lib/marketing-kpis.sh
@@ -98,13 +98,17 @@ kpi_ctr() {
# ---------------------------------------------------------------------------
# kpi_health_score <project_json>
-# Composite 0-100 score. Returns JSON: {"score":N,"label":"Healthy|Warning|Critical"}
+# Composite 0-100 score. Returns JSON: {"score":N,"label":"Healthy|Warning|Critical|Idle"}
# Scoring:
# ROAS: >=3 → +30, 1-3 → +15, else 0
# CVR: >=2% → +20, 1-2% → +10, else 0
# Crash: >=0.99 → +20, 0.95-0.99 → +10, <0.90 → -20, else 0
# Profit: revenue > ad_spend → +20
# Active: ad_spend > 0 → +10
+# Idle override: a dormant account (no spend, no revenue, no ROAS/CVR signal) with
+# no crash problem is paused, not failing — label it "Idle" so €0-spend/paused
+# accounts don't trip a false Critical alarm. A real crash signal
+# (crash_free < 0.99) still routes through the Critical path.
# ---------------------------------------------------------------------------
kpi_health_score() {
local data="${1:-{}}"
@@ -113,11 +117,14 @@ kpi_health_score() {
roas="$(echo "$data" | jq -r '.roas // 0' 2>/dev/null | tr -d '\n' || echo 0)"
cvr="$(echo "$data" | jq -r '.cvr // 0' 2>/dev/null | tr -d '\n' || echo 0)"
crash_free="$(echo "$data" | jq -r '.crash_free_rate // 1' 2>/dev/null | tr -d '\n' || echo 1)"
- ad_spend="$(echo "$data" | jq -r '.ad_spend // 0' 2>/dev/null | tr -d '\n' || echo 0)"
+ ad_spend="$(echo "$data" | jq -r '((.ad_spend // 0) | tonumber) as $a | ((.spend // 0) | tonumber) as $s | if $a > 0 then $a else $s end' 2>/dev/null | tr -d '\n' || echo 0)"
revenue="$(echo "$data" | jq -r '.revenue // 0' 2>/dev/null | tr -d '\n' || echo 0)"
- local score label
- score="$(awk "BEGIN {
+ local score idle
+ # awk prints "<score> <idle-flag>": idle=1 when there is zero activity and no
+ # crash signal — i.e. nothing to judge, the account is simply dormant.
+ read -r score idle <<EOF
+$(awk "BEGIN {
roas=$roas+0; cvr=$cvr+0; cf=$crash_free+0;
spend=$ad_spend+0; rev=$revenue+0;
s=0;
@@ -137,10 +144,16 @@ kpi_health_score() {
if (spend > 0) s += 10;
# Floor at 0
if (s < 0) s = 0;
- print s
- }")"
-
- if [ "$score" -ge 70 ] 2>/dev/null; then
+ # Idle: no spend, no revenue, no ROAS/CVR signal, and no crash problem.
+ idle = (spend == 0 && rev == 0 && roas == 0 && cvr == 0 && cf >= 0.99) ? 1 : 0;
+ print s, idle
+ }")
+EOF
+
+ local label
+ if [ "$idle" = "1" ] 2>/dev/null; then
+ label="Idle"
+ elif [ "$score" -ge 70 ] 2>/dev/null; then
label="Healthy"
elif [ "$score" -ge 40 ] 2>/dev/null; then
label="Warning"
diff --git a/claude-ops/tests/test-marketing-kpis.sh b/claude-ops/tests/test-marketing-kpis.sh
index 99e43272..8c0a9ba6 100755
--- a/claude-ops/tests/test-marketing-kpis.sh
+++ b/claude-ops/tests/test-marketing-kpis.sh
@@ -125,6 +125,22 @@ h="$(kpi_health_score '{"roas":0,"cvr":0,"crash_free_rate":0.89,"ad_spend":0,"re
score="$(echo "$h" | jq -r '.score')"
[ "$score" = "0" ] && ok "health crash penalty floored at 0" || err "health crash floor: expected 0, got $score"
+# Idle: no activity at all, no crash signal → "Idle", NOT a false Critical.
+# (paused / €0-spend account is dormant, not failing)
+h="$(kpi_health_score '{"roas":0,"cvr":0,"ad_spend":0,"revenue":0}')"
+label="$(echo "$h" | jq -r '.label')"
+[ "$label" = "Idle" ] && ok "health Idle label for dormant account" || err "health Idle: expected Idle, got $label"
+
+# Idle guard must NOT swallow a real crash signal even with zero spend.
+h="$(kpi_health_score '{"roas":0,"cvr":0,"crash_free_rate":0.88,"ad_spend":0,"revenue":0}')"
+label="$(echo "$h" | jq -r '.label')"
+[ "$label" = "Critical" ] && ok "crash signal stays Critical despite no spend" || err "crash-not-idle: expected Critical, got $label"
+
+# Active-but-failing stays Critical: spend>0, ROAS<1 → burning money.
+h="$(kpi_health_score '{"roas":0.4,"cvr":0,"crash_free_rate":1,"ad_spend":200,"revenue":80}')"
+label="$(echo "$h" | jq -r '.label')"
+[ "$label" = "Critical" ] && ok "active unprofitable stays Critical" || err "active-unprofitable: expected Critical, got $label"
+
# ---------------------------------------------------------------------------
# kpi_compute_all
# ---------------------------------------------------------------------------