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(ops-inbox): unread is never a triage filter, on any channel (#993)

Aurora Capital1fd96674a883
diff --git a/claude-ops/bin/ops-inbox-scan b/claude-ops/bin/ops-inbox-scan
index 3fb388a5..256f681e 100755
--- a/claude-ops/bin/ops-inbox-scan
+++ b/claude-ops/bin/ops-inbox-scan
@@ -17,8 +17,10 @@
# only for the handful of NEEDS_REPLY candidates before drafting.
#
# DOES NOT COVER (left to the skill as single, light inline MCP calls — NOT
-# subagents): Slack (one conversations_unreads call) and Telegram (one
-# list_dialogs call). Those are one round-trip each; a subagent is overkill.
+# subagents): Slack (channels_me + conversations_history per DM, never
+# conversations_unreads — unread is never a filter, Sam 2026-09-17) and
+# Telegram (one list_dialogs call). Those are one/few round-trips; a subagent
+# is overkill.
#
# OUTPUT: one JSON object on stdout. Always valid JSON, even on partial failure.
# READ-ONLY: opens every sqlite db in immutable/read-only mode; never sends,
@@ -1489,8 +1491,9 @@ result["counts"] = {
"email": {b: cnt("email", b) for b in ("needs_reply", "waiting", "fyi")} if DO_EMAIL else None,
}
result["notes"].append(
- "Slack + Telegram NOT scanned here — the skill does one light inline MCP call each "
- "(conversations_unreads / list_dialogs), no subagent."
+ "Slack + Telegram NOT scanned here — the skill does channels_me + "
+ "conversations_history per DM for Slack (never conversations_unreads) "
+ "and one list_dialogs call for Telegram, no subagent."
)
result["notes"].append(
"WhatsApp store may lag phone-sent messages; confirm 'did I already reply?' with the human "
diff --git a/claude-ops/skills/ops-inbox/SKILL.md b/claude-ops/skills/ops-inbox/SKILL.md
index 1a5b0511..869a1408 100644
--- a/claude-ops/skills/ops-inbox/SKILL.md
+++ b/claude-ops/skills/ops-inbox/SKILL.md
@@ -147,7 +147,7 @@ Every run, in order:
commitments.
1. Resolve WhatsApp accounts (`ops-wa-accounts` — never hardcode a port). Scan every agent-enabled number.
2. Freshness: `~/bin/wa-inbox-fresh.sh` (blocking, bounded). Then `bin/ops-inbox-scan` (defaults to every enabled account, `--debt-days 90`). Never an unread listing: unread is a display state and is empty for every thread already opened on a phone. Forgotten unanswered asks (archived/read, still their ball, inside 90 days) come back tagged `forgotten` — on WhatsApp AND on email, where a Gmail filter or category can hide a live thread from `in:inbox` entirely.
-2b. **Every other channel in the same pass, in parallel:** iMessage/SMS (`$HERMES_HOME/bin/imessage-inbox-scan --days 30` — copies `-wal`/`-shm` first or recent messages are invisible; alphanumeric shortcodes and OTP bodies are `fyi`, never `needs_reply`). Slack (`conversations_unreads`, DMs first). Telegram user dialogs if configured. Email is already in the scan. A miss on one channel is not absence on another.
+2b. **Every other channel in the same pass, in parallel:** iMessage/SMS (`$HERMES_HOME/bin/imessage-inbox-scan --days 30` — copies `-wal`/`-shm` first or recent messages are invisible; alphanumeric shortcodes and OTP bodies are `fyi`, never `needs_reply`). Slack: `channels_me {channel_types:"im,mpim"}` then `conversations_history` per human DM, never `conversations_unreads` — unread is never a filter (Sam, 2026-09-17), a DM he read on his phone and never answered stays invisible to an unread listing. Telegram user dialogs if configured. Email is already in the scan. A miss on one channel is not absence on another.
3. **All-context sweep** (Rule 9 + `references/details.md` "ALL CONTEXT SOURCES"): query every configured calendar, mailbox, and messaging channel before any schedule claim or NEEDS_REPLY draft. Google Calendar alone is not enough — Notion show/calendar databases count when Notion is configured.
4. `bin/ops-inbox-archive-set` report-only. Present KEEP vs ARCHIVE; `--apply` only after explicit OK.
5. Deep-read KEEP / NEEDS_REPLY. Fan out if volume (`references/fan-out.md`). One read-only worker per channel, then one per KEEP thread-chunk. Stage the next draft the moment the previous card is answered — no "next?" pause.
@@ -218,12 +218,16 @@ rule to carry into any channel you add: **debt is DIRECTION, not label or unread
The honest test is always "whose message is last in this thread, and did we answer after
it" — never "is it still in the inbox".
-**Slack is an unread listing, so it inherits the same blind spot.**
-`conversations_unreads` only sees what Sam has not opened; a DM he read on his phone and
-never answered is invisible to it. When a Slack answer matters, confirm direction with
-`conversations_history` on the DMs that matter rather than trusting an empty unreads
-result. An empty unreads result means "nothing new was left unseen", never "nobody is
-waiting".
+**Unread is never a filter, on any channel (Sam, 2026-09-17).** A message Sam
+opened and navigated away from without replying still owes a reply — read state is
+a display flag, not a proxy for "handled". `conversations_unreads` only sees what
+Sam has not opened; a DM he read on his phone and never answered is invisible to
+it. Never use it, and never use `whatsapp_unread`, to decide what needs triage.
+Always confirm direction with `conversations_history` (Slack) or `whatsapp_find` /
+`whatsapp_thread` (WhatsApp) — who spoke last, not what is marked unread. A guard
+(`unread-filter-guard.py`, wired into `pre-tool-dispatcher.py` on hub/Mac/HYPEST)
+hard-blocks `whatsapp_unread`, `conversations_unreads`, and any `is:unread` /
+`unread_count` / `unread=1` filter in a terminal command.
**ON SAM'S BOX THE WHATSAPP ZERO IS ALWAYS A LIE — measured 2026-09-06.** Every chat in
both stores is archived and `handled` is maintained on 3 of 1808 rows, so the scan prints
@@ -233,8 +237,8 @@ personal_us. That run reported inbox zero while six people were genuinely waitin
reply. Whenever a note contains "recency net disarmed" or "taken at face value", the zero
carries no information: derive needs_reply yourself — a thread needs a reply when its
NEWEST message has `is_from_me = 0`, regardless of the archive flag. Do this with the
-WhatsApp plugin tools (`whatsapp_unread`, `whatsapp_find`, `whatsapp_thread`), not with a
-hand-written sqlite read.
+WhatsApp plugin tools (`whatsapp_find`, `whatsapp_thread`), never `whatsapp_unread`, and
+never a hand-written sqlite read.
**Empty buckets are only trustworthy when the scan says it succeeded.** Check the flags
before believing a zero:
@@ -250,14 +254,19 @@ policy `ssh` + `remote_store` entries, using `VACUUM INTO` for a consistent snap
only reports `blocked` when that genuinely fails.
**ARCHIVED MEANS "DEALT WITH AS OF NOW", NOT FOREVER.** WhatsApp never moves
-the archive flag when a new message lands, so a swept thread that gets an answer
-an hour later would sit invisible while the scan reports inbox zero (observed
+the archive flag when a new message lands, so a swept thread that gets a
+reply an hour later would sit invisible while the scan reports inbox zero (observed
2026-09-06: five people replied within four hours of a sweep). `--apply` writes
a per-chat watermark (`ops-sweep-watermarks.json`, beside `messages.db`) and the
scan reopens any archived chat whose newest inbound is later than that mark,
noting how many. An archived chat that stayed quiet stays archived, and history
stays shut: the reopen is bounded by `--days`.
+**Read state is not the test, on WhatsApp either.** Use `whatsapp_find` /
+`whatsapp_thread` and classify by direction (newest message `is_from_me = 0` ==
+needs_reply), never `whatsapp_unread` — a thread Sam opened on his phone and
+never answered is empty in any unread listing but still owes a reply.
+
**CROSS-ACCOUNT: a reply on one number counts for the other.** One person often
exists in both stores under different jids. A reply sent from account A lands
only in A's database, so B's copy still ends on their inbound line and looks
@@ -338,12 +347,11 @@ genuine reasoning, not for reading a database.
**What the script does NOT do — and what you do next, in the MAIN session (no subagents):**
-1. **Slack** — one `mcp__slack__conversations_unreads {include_messages:true}` call. One
- round-trip; a subagent is pure overhead. Skip entirely if prefs show 0 workspaces.
- Remember what this call can and cannot see: it is an UNREAD listing, so a DM Sam read on
- his phone and never answered does not appear. Empty unreads is not "nobody is waiting".
- For any workspace where a real answer is owed, check direction with
- `mcp__slack__conversations_history` on the DMs that matter.
+1. **Slack** — never `conversations_unreads` (unread is not a filter, Sam 2026-09-17;
+ a guard hard-blocks the call). Instead: `channels_me {channel_types:"im,mpim"}` once
+ to list human DMs, then `conversations_history {channel_id, limit:"5d"}` per DM to
+ check who spoke last. A DM Sam read on his phone and never answered must surface —
+ an unread listing would miss it entirely.
2. **Telegram** — one `mcp__plugin_ops_telegram__list_dialogs` call (skip the
Pocket ops bot dialog — that's automation). Skip if unconfigured.
3. **FULL-THREAD AWARENESS GATE on the few NEEDS_REPLY candidates** — the script's WhatsApp
diff --git a/claude-ops/skills/ops-inbox/references/details.md b/claude-ops/skills/ops-inbox/references/details.md
index b2b378c0..75a42606 100644
--- a/claude-ops/skills/ops-inbox/references/details.md
+++ b/claude-ops/skills/ops-inbox/references/details.md
@@ -469,7 +469,7 @@ For each channel, detect availability at runtime:
1. **Parse pre-gathered data** for initial counts (unread is just a starting signal).
-2. **For each channel, run a FULL scan** (not just unread). Drive this via the **Scan engine** above: run `bin/ops-inbox-scan` FIRST (offline WhatsApp + Email triage, near-zero tokens), then one inline `mcp__slack__conversations_unreads` and one `mcp__plugin_ops_telegram__list_dialogs` call for those channels. **Then default to the `Workflow` fan-out for the per-thread deep-read/draft work whenever there is real volume** — more than ~1–3 candidates across channels, or any channel with a human-thread backlog the script can't reach (see "When to use the Workflow fan-out — DEFAULT" above). Only the trivial case (script covered everything, ~1–3 candidates left) stays fully inline with no fan-out. The per-channel detail below defines what each reader covers and how the main session presents results and replies:
+2. **For each channel, run a FULL scan** (not just unread — unread is never a filter, Sam 2026-09-17). Drive this via the **Scan engine** above: run `bin/ops-inbox-scan` FIRST (offline WhatsApp + Email triage, near-zero tokens), then for Slack use `channels_me {channel_types:"im,mpim"}` + `conversations_history` per DM (never `conversations_unreads` — a guard hard-blocks it) and one `mcp__plugin_ops_telegram__list_dialogs` call for Telegram. **Then default to the `Workflow` fan-out for the per-thread deep-read/draft work whenever there is real volume** — more than ~1–3 candidates across channels, or any channel with a human-thread backlog the script can't reach (see "When to use the Workflow fan-out — DEFAULT" above). Only the trivial case (script covered everything, ~1–3 candidates left) stays fully inline with no fan-out. The per-channel detail below defines what each reader covers and how the main session presents results and replies:
- **Email**: Search `in:inbox` (not `is:unread`) via `gog gmail search -a $GMAIL_ACCOUNT -j --results-only --no-input --max 30 "in:inbox"`. For each thread, read the last message to determine who sent it last. Check for DRAFT or SENT labels. **Before suggesting to send a draft, verify no reply was already sent in the thread.**
- **WhatsApp**: Call `mcp__whatsapp__list_chats {sort_by: "last_active"}` to get all chats. Filter to chats with `last_message_time` in the last 7 days (`last_message_time` is RFC3339+TZ — parse with timezone awareness, never strip the offset). Resolve display name from contacts.db first (`SELECT name FROM contacts WHERE jid=?`), fall back to the chat's `name` field, and only call giga memory when both are empty. Use `last_is_from_me` on the chat object (`1` = WAITING, `0` = NEEDS_REPLY) ONLY as a first pass — it does NOT finalise a classification. Before marking any chat NEEDS_REPLY you MUST clear the **FULL-THREAD AWARENESS GATE** above: fetch `mcp__whatsapp__list_messages {chat_jid, limit: 25}` reading BOTH directions (capture `is_from_me=1` rows AND `[voice]` transcripts), write the 2-sentence arc summary, and reconcile the user's own sends that may be missing from the store.
- **iMessage**: Call `mcp__plugin_imessage_imessage__chat_messages {limit: 30}` (omit `chat_guid` to pull every allowlisted thread at once). Output is rendered text, not JSON: each thread is labelled `DM`/`Group` with its participant list, then timestamped messages oldest-first. Sent-by-you messages are marked (`Me:` / `→`); inbound messages carry the sender handle. Classify each thread by who sent the LAST message — same NEEDS_REPLY / WAITING / FYI logic as WhatsApp.
diff --git a/claude-ops/skills/ops-inbox/references/fan-out.md b/claude-ops/skills/ops-inbox/references/fan-out.md
index 7c634818..664fca4d 100644
--- a/claude-ops/skills/ops-inbox/references/fan-out.md
+++ b/claude-ops/skills/ops-inbox/references/fan-out.md
@@ -67,8 +67,8 @@ Workflow({
{
key: 'slack',
select:
- 'select:mcp__slack__conversations_unreads,mcp__slack__channels_list,mcp__slack__conversations_history,mcp__slack__conversations_replies',
- steps: 'conversations_unreads to find unread DMs/channels; read latest via history/replies.',
+ 'select:mcp__slack__channels_me,mcp__slack__conversations_history,mcp__slack__conversations_replies',
+ steps: 'channels_me {channel_types:"im,mpim"} for human DMs (and public/private channels from your allowlist); conversations_history per id to find who spoke last. Never conversations_unreads — unread is never a filter (Sam, 2026-09-17); a guard hard-blocks the call.',
},
{
key: 'whatsapp',
diff --git a/claude-ops/skills/ops-rules/SKILL.md b/claude-ops/skills/ops-rules/SKILL.md
index 8bea1fe2..91c0fa90 100644
--- a/claude-ops/skills/ops-rules/SKILL.md
+++ b/claude-ops/skills/ops-rules/SKILL.md
@@ -344,7 +344,12 @@ the thread and read per-message dates.
**"Nobody replied" is not "unread".** The per-thread test is who spoke
last and whether a reply ever went out — not whether the thread is marked
unread. A sweep filtered on unread reports inbox zero while read and
-archived threads still hold open questions.
+archived threads still hold open questions. Unread is NEVER a valid
+triage filter on any channel: a message opened and navigated away from
+without a reply still owes one. `unread-filter-guard.py` (wired into
+`pre-tool-dispatcher.py` on hub/Mac/HYPEST) hard-blocks `whatsapp_unread`,
+`mcp__slack__conversations_unreads`, and any `is:unread` / `unread_count`
+/ `unread=1` filter passed to `terminal`/`execute_code`.
**"Nobody replied / it stalled."** Read every message in the chain, both
directions, before assigning fault. A stall is usually a condition nobody
diff --git a/claude-ops/tests/test-unread-filter-guard.sh b/claude-ops/tests/test-unread-filter-guard.sh
new file mode 100755
index 00000000..0ffd4b52
--- /dev/null
+++ b/claude-ops/tests/test-unread-filter-guard.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+# test-unread-filter-guard.sh — proves unread-filter-guard.py blocks the
+# forbidden unread-as-triage-filter shapes and allows normal inbox scans.
+#
+# Standing rule (Sam, 2026-09-17): "Unreads mag nooit een filter zijn."
+set -euo pipefail
+
+GUARD="${HERMES_HOME:-$HOME/.hermes}/agent-hooks/unread-filter-guard.py"
+
+if [ ! -f "$GUARD" ]; then
+ echo "SKIP: $GUARD not present on this box"
+ exit 0
+fi
+
+fail=0
+
+assert_blocked() {
+ local desc="$1" payload="$2"
+ local out
+ out=$(printf '%s' "$payload" | python3 "$GUARD")
+ if [[ "$out" == *'"action": "block"'* ]] || [[ "$out" == *'"action":"block"'* ]]; then
+ echo "PASS (blocked): $desc"
+ else
+ echo "FAIL (should have blocked): $desc -- got: $out"
+ fail=1
+ fi
+}
+
+assert_allowed() {
+ local desc="$1" payload="$2"
+ local out
+ out=$(printf '%s' "$payload" | python3 "$GUARD")
+ if [ -z "$out" ]; then
+ echo "PASS (allowed): $desc"
+ else
+ echo "FAIL (should have allowed): $desc -- got: $out"
+ fail=1
+ fi
+}
+
+assert_blocked "whatsapp_unread tool call" \
+ '{"hook_event_name":"pre_tool_call","tool_name":"whatsapp_unread","tool_input":{}}'
+
+assert_blocked "conversations_unreads tool call" \
+ '{"hook_event_name":"pre_tool_call","tool_name":"mcp__slack__conversations_unreads","tool_input":{}}'
+
+assert_blocked "gmail is:unread filter in terminal" \
+ '{"hook_event_name":"pre_tool_call","tool_name":"terminal","tool_input":{"command":"gog gmail search -a x -p \"in:inbox is:unread\""}}'
+
+assert_blocked "unread_count comparison in terminal" \
+ '{"hook_event_name":"pre_tool_call","tool_name":"terminal","tool_input":{"command":"python3 -c \"if unread_count > 0: print(1)\""}}'
+
+assert_allowed "plain in:inbox gmail search" \
+ '{"hook_event_name":"pre_tool_call","tool_name":"terminal","tool_input":{"command":"gog gmail search -a x -p \"in:inbox\""}}'
+
+assert_allowed "unrelated tool" \
+ '{"hook_event_name":"pre_tool_call","tool_name":"read_file","tool_input":{"path":"/tmp/x"}}'
+
+assert_allowed "whatsapp_find (correct triage tool)" \
+ '{"hook_event_name":"pre_tool_call","tool_name":"whatsapp_find","tool_input":{}}'
+
+exit $fail