name: alfred-imessage-triage description: "[Alfred] Scan iMessage for work leads. Flag spam for manual deletion." allowed-tools: Read, Write, Edit, Bash(sqlite3:, python3:, git:, pnpm:)
Alfred iMessage Triage
Scope: Last 100 conversations | Goal: Surface work leads, flag spam
Status Definitions
| Status | Meaning | Delete? |
|---|---|---|
ACTION_NEEDED |
Requires response | No |
REPLIED |
Ball in their court | No |
NOTED |
FYI | No |
SKIPPED |
Personal (hide content) | No |
NOTIFICATION |
Stale (verification, delivery) | Yes |
SPAM |
Scam/marketing | Yes |
Query Script
import sqlite3, os
from glob import glob
def load_contacts():
contacts = {}
for db in glob(os.path.expanduser("~/Library/Application Support/AddressBook/Sources/*/AddressBook-v22.abcddb")):
try:
for name, phone in sqlite3.connect(db).execute(
"SELECT COALESCE(r.ZFIRSTNAME,'') || ' ' || COALESCE(r.ZLASTNAME,''), p.ZFULLNUMBER "
"FROM ZABCDRECORD r JOIN ZABCDPHONENUMBER p ON p.ZOWNER = r.Z_PK"):
if phone: contacts[''.join(c for c in phone if c.isdigit() or c == '+')] = name.strip()
except: pass
return contacts
def extract_text(text, body):
if text: return text[:150].replace('\n', ' ')
if body and b'NSString' in body:
try: return ''.join(chr(b) for b in body.split(b'NSString')[1] if 32 <= b < 127)[:150]
except: pass
contacts = load_contacts()
conn = sqlite3.connect(os.path.expanduser('~/Library/Messages/chat.db'))
for chat_id, name, last in conn.execute(
"SELECT c.chat_identifier, c.display_name, datetime(MAX(m.date)/1000000000 + 978307200, 'unixepoch', 'localtime') "
"FROM chat c JOIN chat_message_join cmj ON c.ROWID = cmj.chat_id JOIN message m ON cmj.message_id = m.ROWID "
"GROUP BY c.ROWID ORDER BY MAX(m.date) DESC LIMIT 100"):
msg = conn.execute("SELECT text, attributedBody FROM message m JOIN chat_message_join cmj ON m.ROWID = cmj.message_id "
"JOIN chat c ON cmj.chat_id = c.ROWID WHERE c.chat_identifier = ? ORDER BY m.date DESC LIMIT 1", (chat_id,)).fetchone()
text = extract_text(msg[0], msg[1]) if msg else ''
contact = contacts.get(''.join(c for c in chat_id if c.isdigit() or c == '+'), name or '')
print(f"{chat_id}|{contact}|{last}|{text}")
Classification
Spam patterns: Short codes with verification only, scam jobs ("Amazon recruitment", "McCann"), phishing, loans, "reply STOP"
Privacy: SKIPPED = "Personal" only, no message content
Report Template
Output: agents/agent-alfred/outputs/YYYY-MM-DD-HHmm-imessage-triage.md
# iMessage Triage — YYYY-MM-DD HH:mm
## Summary
| Status | Count |
|--------|-------|
## Action Items
| Contact | Summary | Action |
|---------|---------|--------|
## Manual Deletion
**macOS 26+ blocks automated deletion.** Delete in Messages app:
1. Cmd+F → search chat ID
2. Right-click → Delete
### Notifications (stale)
| Chat ID | Preview |
|---------|---------|
### Spam
| Chat ID | Preview |
|---------|---------|
## Full Audit
| # | Contact | Chat ID | Status | Notes |
|---|---------|---------|--------|-------|
Limitations
- Full Disk Access required for Terminal
- Manual deletion only (AppleScript blocked on macOS 26+)