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(pocket-approvals): A/B/C options + ⭐recommended + freeform + untruncated Telegram ASKs (#459)
Aurora Capitale2f2bd0b6957
diff --git a/claude-ops/email-cos/pocket-responder.py b/claude-ops/email-cos/pocket-responder.pyindex 856fa7c5..bf75f3e0 100644--- a/claude-ops/email-cos/pocket-responder.py+++ b/claude-ops/email-cos/pocket-responder.py@@ -122,8 +122,11 @@ def _norm(item):return (t.get("id") or item.get("id"),t.get("kind") or item.get("kind", "action_item"),- (t.get("title") or item.get("title") or "")[:120],- (t.get("context") or item.get("context") or "")[:600],+ (t.get("title") or item.get("title") or "")[:140],+ # Keep generous context here; cmd_send() does the final Telegram-fit+ # truncation. The old 600-char cap silently amputated long ASKs+ # (email drafts, voice-memo action items) before they were ever rendered.+ (t.get("context") or item.get("context") or "")[:6000],t,)@@ -176,6 +179,51 @@ def _sid(item_id):return "i" + hashlib.sha1(item_id.encode()).hexdigest()[:10]+def _recommended_key(it, opts):+ """Recommended option key for an ASK, if any: a per-option `recommended:true`+ first, then a top-level recommended_option/recommended_key (also checked in raw+ + raw.triage). '' if none. Backward-compatible — producers that don't set it+ just get no star."""+ for o in opts or []:+ if isinstance(o, dict) and o.get("recommended"):+ return str(o.get("key") or "")+ raw = it.get("raw") if isinstance(it.get("raw"), dict) else {}+ tri = raw.get("triage") if isinstance(raw.get("triage"), dict) else {}+ for src in (it, raw, tri):+ if isinstance(src, dict) and (src.get("recommended_option") or src.get("recommended_key")):+ return str(src.get("recommended_option") or src.get("recommended_key"))+ return ""+++# Words signalling "change this before it goes out" rather than a plain yes. Used+# to block the footgun where a freeform reply like "send but say Friday" on an+# outbound email ASK gets mis-mapped to a bare APPROVE and the UNEDITED draft is+# sent to a third party. Edit-then-send re-drafting is not wired yet.+_RE_EDIT_INTENT = re.compile(+ r"\b(change|instead of|edit|reword|rewrite|replace|revise|adjust|tweak|shorter|"+ r"longer|add that|mention|leave out|take out|remove the|"+ r"make it (?:shorter|longer|clearer|more|less|sound|polite|formal|casual|better)|"+ r"don'?t say|say(?:\s+that)?|send but|reslant|soften|reschedule to)\b", re.I)+++def _edit_intent(body):+ return bool(_RE_EDIT_INTENT.search(body or ""))+++def _classic_approve_clause(body, ent, codemap):+ """Matched `approve <ref>` token for ent, if any — not the full Telegram reply."""+ tid = ent.get("id")+ if not tid:+ return ""+ for mt in _RE_CLASSIC.finditer(body or ""):+ if mt.group(1).upper() != "APPROVE":+ continue+ e = _resolve_code(codemap, mt.group(2))+ if e and e.get("id") == tid:+ return mt.group(0)+ return ""++# ---------------------------------------------------------------------------# Telegram API# ---------------------------------------------------------------------------@@ -239,22 +287,36 @@ def cmd_send():sid = _sid(iid)opts = it.get("options") or []ap = it.get("action_preview") or ""- title = (it.get("title") or "")[:120]- ctx = _truncate_words(it.get("ctx") or "", 500)+ dq = it.get("decision_question") or ""+ kind = it.get("kind") or ""+ title = (it.get("title") or "")[:140]+ # Give the body the bulk of Telegram's 4096-char budget; the old 500-char+ # cut amputated long ASKs (full email drafts, voice-memo action items).+ ctx = _truncate_words(it.get("ctx") or "", 3200)+ rk = _recommended_key(it, opts)text = f"*{title}*\n{ctx}"+ if dq:+ text += f"\n\n❓ *{dq}*"if ap:text += f"\n\n→ *Approve =* {ap}"if opts:- rows = [- [{"text": f"{o['key']}) {o['label'][:40]}", "callback_data": f"po:{sid}:{o['key']}"}]- for o in opts- ]- rows.append([{"text": "❌ Reject", "callback_data": f"pr:{sid}"}])+ rows = []+ for o in opts:+ star = "⭐ " if rk and str(o.get("key", "")).lower() == rk.lower() else ""+ rows.append([{"text": f"{star}{o['key']}) {o['label'][:38]}", "callback_data": f"po:{sid}:{o['key']}"}])+ rows.append([{"text": "❌ None / reject", "callback_data": f"pr:{sid}"}])+ if rk:+ text += f"\n\n⭐ _= recommended ({rk})_"else:rows = [[{"text": "✅ Approve", "callback_data": f"pa:{sid}"},{"text": "❌ Reject", "callback_data": f"pr:{sid}"},]]+ # Advertise freeform reply — but NOT on outbound message kinds, where a+ # freeform "send but change X" would mis-map to a bare APPROVE and silently+ # send the unedited draft to a third party (also guarded in _handle_text).+ if not _is_outbound(it):+ text += "\n\n💬 _Or just reply in your own words — e.g. “do b”, “skip this one”, or your own instruction._"r = _api("sendMessage", {"chat_id": CHAT, "text": text[:3800], "parse_mode": "Markdown","reply_markup": {"inline_keyboard": rows},@@ -665,6 +727,11 @@ def _handle_text(ev, codemap, callmap, resolved, seen):if verb == "APPROVE" and (ent.get("options") or []):_send(f"`{ref}` is a choice item — reply e.g. `{ref} a`.")continue+ if verb == "APPROVE" and _is_outbound(ent) and _edit_intent(mt.group(0)):+ _send(f"`{ref}` looks like an *edit*, not a plain approve — I won't send the "+ f"original draft as-is. Tap ✅ Approve (or reply `approve {ref}`) to send "+ f"it unchanged, or `reject {ref}` to skip. _(Edit-then-send for emails isn't wired yet.)_")+ continuetoast = _apply_decision(ent, "APPROVE" if verb == "APPROVE" else "REJECT")resolved.add(tid); handled_ids.add(tid); acted += 1_, cment = _callmap_entry_for_id(callmap, tid)@@ -706,6 +773,12 @@ def _handle_text(ev, codemap, callmap, resolved, seen):continuetoast = _apply_decision(ent, "CHOOSE", option=option)else:+ clause = _classic_approve_clause(body, ent, codemap) or body+ if dec == "approve" and _is_outbound(ent) and _edit_intent(clause):+ _send(f"That looks like an *edit* of “{ent.get('title','')[:50]}”, not a plain "+ f"approve — I won't send the original draft as-is. Tap ✅ Approve to send it "+ f"unchanged, or reply `reject` to skip. _(Edit-then-send for emails isn't wired yet.)_")+ continuetoast = _apply_decision(ent, dec.upper())resolved.add(tid); handled_ids.add(tid); acted += 1_, cment = _callmap_entry_for_id(callmap, tid)diff --git a/claude-ops/email-cos/prompts/orchestrator.prompt b/claude-ops/email-cos/prompts/orchestrator.promptindex 9ae66784..54ba08f2 100644--- a/claude-ops/email-cos/prompts/orchestrator.prompt+++ b/claude-ops/email-cos/prompts/orchestrator.prompt@@ -13,11 +13,13 @@ PER ITEM:2. ENRICH: recall the contact/thread via `mcp__gbrain__search` (+ get_page on a hit). If the counterparty/company is unfamiliar, do ONE Tavily web search to identify them.3. ACT by category:- Legal / Finance: do NOT draft a reply. Append a reminder-style ASK to the pocket review.jsonl (use the configured POCKET_STATE_DIR / {{EMAIL_COS_POCKET_STATE_DIR}} path the template already uses) with kind "action_item", source "email-triage", title "Review: <sender>: <subject ≤60>", context "WHO: <who>\nGIST: <what they need>\nACTION NEEDED: <what Sam must decide/do>", verdict ASK, and NO email_reply field (approving just acknowledges it — nothing is sent). This surfaces it as a Telegram button. Do NOT call icloud-reminder.sh or any other channel.+ Also set "action_preview" to one concrete sentence on what approving does (usually "Marks this as acknowledged — nothing is sent."). When the item is a GENUINE fork the owner must decide (not a yes/no acknowledge), additionally set "decision_question" to the single question being decided and "options" to a 2–4 element array of {"key":"a","label":"<≤38 chars>","recommended":true|false} — keys a/b/c/d in order, exactly ONE option recommended:true (your best-guess answer). For a plain acknowledge with no real fork leave decision_question "" and options []. NEVER invent facts to manufacture options.- Other categories: COMPOSE a reply in the owner's voice (match the email's language; warm, concise, professional; end "Best,\n[Name]"). Then create a pocket APPROVAL ASK by appending ONE json line to {{EMAIL_COS_POCKET_STATE_DIR}}/review.jsonl using this exact python (fill the variables):```python3 - <<PYimport json,timerec={"id":"email-reply-<gmail_msg_id>","kind":"send_message","title":"Reply to <sender name>: <subject ≤60 chars>",+ "action_preview":"Sends this reply to <sender name> (<sender email>) — exactly as written, nothing edited.","context":"WHO: <1-line who they are>\nGIST: <1-line what they want>\n\nPROPOSED REPLY:\n<the full reply body>","source":"email-triage","confidence":1.0,"captured_at":time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime()),"triage":{"verdict":"ASK","confidence":1.0,"reasoning":"Outbound email reply needs owner approval (Rule 6).","decided_at":time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime())},diff --git a/claude-ops/scripts/ops-pocket-triage.py b/claude-ops/scripts/ops-pocket-triage.pyindex aa13ae4a..10ac5b87 100755--- a/claude-ops/scripts/ops-pocket-triage.py+++ b/claude-ops/scripts/ops-pocket-triage.py@@ -186,12 +186,12 @@ Return STRICT JSON, no markdown, no prose outside the JSON:"action_preview": "<ASK only — one concrete sentence: what will happen if the owner approves this item. E.g. 'Creates a GitHub issue in your-org/your-repo with the given title and assigns it to you.' Leave empty string for non-ASK verdicts.>","decision_question": "<ASK only, and only when the item is a genuine multi-choice decision — the single question being decided. E.g. 'Which environment should this deploy target?' Leave empty string when it is a simple yes/no.>","options": [- {{"key": "a", "label": "<concrete option text — what choosing this means>"}},+ {{"key": "a", "label": "<concrete option text — what choosing this means>", "recommended": true}},{{"key": "b", "label": "<concrete option text>"}}]}}-For the options array: include 2–4 options only when decision_question is non-empty. Use keys a/b/c/d in order. When the item is a plain yes/no ASK, set options to an empty array []. Non-ASK verdicts must also set options to [].+For the options array: include 2–4 options only when decision_question is non-empty. Use keys a/b/c/d in order. Mark exactly ONE option with "recommended": true — your best-guess answer (shown with a ⭐ in the approval UI); omit the key on the others. When the item is a plain yes/no ASK, set options to an empty array []. Non-ASK verdicts must also set options to [].Owner context (NEVER assume otherwise):• Owner name: {owner_name}@@ -405,7 +405,12 @@ def route(task: dict, decision: dict) -> str:routed["decision_question"] = dqif opts and isinstance(opts, list):routed["options"] = [- {"key": str(o.get("key", "")).lower(), "label": str(o.get("label", ""))}+ {+ "key": str(o.get("key", "")).lower(),+ "label": str(o.get("label", "")),+ # Carry the recommended flag through so the approval UI can ⭐ it.+ **({"recommended": True} if o.get("recommended") else {}),+ }for o in optsif o.get("key") and o.get("label")]