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-comms-scanner): correct is_from_me direction, time_ago math, name resolution (#342)

Aurora Capital133cc6a81612
diff --git a/claude-ops/agents/comms-scanner.md b/claude-ops/agents/comms-scanner.md
index 5f9a0a27..66a6ab70 100644
--- a/claude-ops/agents/comms-scanner.md
+++ b/claude-ops/agents/comms-scanner.md
@@ -25,11 +25,31 @@ Run all channel scans in parallel:
```bash
# WhatsApp — ALL non-archived chats (not just unread)
-# WhatsApp via bridge MCP tools
-mcp__whatsapp__list_chats sort_by=last_active # or via sqlite3 direct query
-# Then for each chat with recent activity (last 7 days):
-# mcp__whatsapp__list_messages chat_jid="<JID>" limit=5
-# Check FromMe on last message to classify NEEDS_REPLY vs WAITING
+# Step 1: list chats — the response includes last_is_from_me (int 0/1) and last_message_time (RFC3339+TZ string)
+mcp__whatsapp__list_chats sort_by=last_active
+
+# Step 2: for each chat active in last 7 days, resolve contact name and compute time_ago:
+#
+# NAME RESOLUTION — contacts.db is PRIMARY source; giga memory is fallback only.
+# DB="${WHATSAPP_BRIDGE_DB:-$HOME/.local/share/whatsapp-mcp/whatsapp-bridge/store/messages.db}"
+# sqlite3 "$DB" "SELECT name FROM contacts WHERE jid='$JID' LIMIT 1;"
+# If empty → use the name field from list_chats response.
+# Only consult giga memory (mcp__giga__evoke) when both DB lookup and list_chats name are empty.
+#
+# TIME_AGO — last_message_time is RFC3339 with timezone offset (e.g. "2026-05-24T14:55:06+02:00").
+# Parse with full TZ awareness. In Python:
+# from datetime import datetime, timezone
+# dt = datetime.fromisoformat(last_message_time) # preserves tz offset
+# delta = datetime.now(timezone.utc) - dt.astimezone(timezone.utc)
+# Never strip the timezone suffix before parsing — doing so causes wrong "now" delta.
+#
+# DIRECTION — use last_is_from_me from list_chats directly (do NOT re-derive from last message).
+# last_is_from_me == 1 → WAITING (you sent last; no reply needed)
+# last_is_from_me == 0 → NEEDS_REPLY (they sent last)
+#
+# For chats where last_is_from_me is absent or null, fall back to fetching the thread:
+# mcp__whatsapp__list_messages chat_jid="<JID>" limit=5
+# Check is_from_me on the LAST element of the returned array.
```
```bash
diff --git a/claude-ops/skills/ops-inbox/SKILL.md b/claude-ops/skills/ops-inbox/SKILL.md
index 0f0a60ba..862546aa 100644
--- a/claude-ops/skills/ops-inbox/SKILL.md
+++ b/claude-ops/skills/ops-inbox/SKILL.md
@@ -321,7 +321,7 @@ For each channel, detect availability at runtime:
2. **For each channel, run a FULL scan** (not just unread):
- **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. For each, fetch the FULL conversation via `mcp__whatsapp__list_messages {chat_jid, limit: 20}` (20 messages, not 5 — you need the full thread). Parse message array with fields `is_from_me`, `content`, `timestamp`, `sender`. Classify by last message `is_from_me` field.
+ - **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. Classify direction using `last_is_from_me` on the chat object (`1` = WAITING, `0` = NEEDS_REPLY). Only fetch the full thread via `mcp__whatsapp__list_messages {chat_jid, limit: 20}` when `last_is_from_me` is absent/null or when building reply context for NEEDS_REPLY chats.
- **Slack**: Search via Slack MCP tools. Check who sent last message in each thread.
- **Telegram**: Use user-auth MCP (NOT bot API) to read recent conversations.
@@ -368,15 +368,32 @@ If only 3 channels are configured, "All channels" + 3 channel options = 4, fits
**Phase 1 — Classify:**
1. Get all chats: `mcp__whatsapp__list_chats` with `{sort_by: "last_active"}`
2. Filter to chats with `last_message_time` in the last 7 days
-3. For each, fetch the FULL recent conversation: `mcp__whatsapp__list_messages` with `{chat_jid: "<JID>", limit: 20}` — get 20 messages, NOT 5.
-4. Parse message array — fields: `is_from_me`, `content`, `timestamp`, `sender`
-5. For EVERY chat, understand the conversation:
- - Read ALL messages in order. Know which have `is_from_me: true` (user sent) vs `is_from_me: false` (contact sent)
- - Understand what the conversation is about, what was discussed, what's pending
- - Identify the user's tone and style in their sent messages
-6. Classify each chat:
- - **NEEDS REPLY**: Last message has `is_from_me: false` (they sent last)
- - **WAITING**: Last message has `is_from_me: true` (you sent last)
+
+ **TIME_AGO — `last_message_time` is an RFC3339 string with timezone offset** (e.g. `"2026-05-24T14:55:06+02:00"`), NOT a unix epoch integer. Parse with full TZ awareness:
+ ```python
+ from datetime import datetime, timezone
+ dt = datetime.fromisoformat(last_message_time) # preserves offset
+ delta = datetime.now(timezone.utc) - dt.astimezone(timezone.utc)
+ ```
+ Never strip the timezone suffix before parsing — that produces a naive datetime and wrong deltas.
+
+3. **NAME RESOLUTION — contacts.db is PRIMARY, giga memory is fallback only.**
+ ```bash
+ DB="${WHATSAPP_BRIDGE_DB:-$HOME/.local/share/whatsapp-mcp/whatsapp-bridge/store/messages.db}"
+ sqlite3 "$DB" "SELECT name FROM contacts WHERE jid='$JID' LIMIT 1;"
+ ```
+ Use the DB result as the display name. If the DB returns empty, fall back to the `name` field in the `list_chats` response. Only call `mcp__giga__evoke` when both are empty.
+
+4. **DIRECTION — classify from `last_is_from_me` on the chat object itself.** Do NOT re-derive from the last message in a fetched thread unless `last_is_from_me` is absent or null:
+ - `last_is_from_me == 1` → **WAITING** (you sent last; no reply needed)
+ - `last_is_from_me == 0` → **NEEDS REPLY** (they sent last)
+
+5. For chats where `last_is_from_me` is absent or null, fetch the thread as fallback:
+ `mcp__whatsapp__list_messages` with `{chat_jid: "<JID>", limit: 20}` — check `is_from_me` on the **last element** of the returned array.
+
+6. Classify each chat (same direction rule as step 4 — use `last_is_from_me` on the chat object; only after the step 5 thread fallback use the last element's `is_from_me`):
+ - **NEEDS REPLY**: `last_is_from_me == 0`, or (fallback only) last thread message `is_from_me: false`
+ - **WAITING**: `last_is_from_me == 1`, or (fallback only) last thread message `is_from_me: true`
- **ARCHIVE**: Newsletters (`@newsletter` JIDs), dead group chats with no recent activity, one-word reactions, or concluded conversations. Bulk-archive these via `mcp__whatsapp__archive_chat {chat_jid, archive: true}` after user confirmation. If the call fails with `LTHash mismatch`, run `mcp__whatsapp__resync_app_state {name: "regular_low", full_sync: true}` first, then retry.
**Phase 2 — Build context for NEEDS REPLY chats (run in parallel):**