Email Agent Runbook Email Agent Runbook Service: Email Agent Daemon Location: ~/system/daemons/email-agent.js LaunchAgent: com.john.email-agent Interval: Every 5 minutes (300s) Last Updated: 2026-04-15 1. Architecture What It Does The Email Agent is a 24/7 daemon that: Fetches unseen emails from 6 IMAP accounts every 5 minutes Classifies emails using VIP bypass → quick filter → Ollama (llama3.1:8b, $0 cost) Creates Mission Control tasks for ACTION-worthy emails Auto-archives INFO and SPAM emails Downloads attachments for CEO-forwarded emails Logs all activity to HiveMind and JSONL results Accounts Monitored Account Key Email Address Bitwarden Vault Name john john@basicconsulting.no Email - john@basicconsulting.no info info@basicconsulting.no Email - info@basicconsulting.no alai john@alai.no Email - john@alai.no alem alem@alai.no Email - alem@alai.no dev dev@alai.no Email - dev@alai.no gmail alembasic@gmail.com Email - alembasic@gmail.com Classification Pipeline VIP Bypass: Emails from CEO/family → forced to ACTION/high , label: CEO FORWARD Quick Filter: Pattern-based detection for OWN emails and known SPAM Ollama Classification: Remaining emails sent to local llama3.1:8b model Circuit Breaker: Falls back to pattern heuristics if Ollama is down (3 failure threshold) VIP Senders (CEO Bypass List) Emails from these addresses bypass all filters and are always classified as ACTION/high with label CEO FORWARD : alem@alai.no alem@basicconsulting.no alem.basic@gmail.com alembasic@gmail.com sibilabasic@gmail.com (CEO's wife) riadbasic007@gmail.com (CEO's brother) Transport: Himalaya Adapter The daemon uses ~/system/tools/himalaya-adapter.js , which wraps the Rust-based himalaya CLI ( /opt/homebrew/bin/himalaya ). Config: ~/.config/himalaya/config.toml — all 6 accounts configured. 2. Credentials Bitwarden Storage All email accounts are stored in Bitwarden with vault item names following the pattern: Email -
. Gmail Account (Special Configuration) The Gmail account ( alembasic@gmail.com ) uses App Password authentication (not the regular Google account password). Bitwarden Item: Email - alembasic@gmail.com Custom Fields in Vault: imap_host = imap.gmail.com imap_port = 993 password = App Password (16-character token from Google) Himalaya Config File: ~/.config/himalaya/config.toml Contains 6 account blocks with IMAP/SMTP settings. Credentials are loaded from Bitwarden at runtime via mail-native.js . 3. How to Verify Is the Daemon Running? launchctl list | grep email-agent # Expected output: PID + exit status 0 # Example: 12345 0 com.john.email-agent Last Heartbeat (Should Be < 10 Minutes Ago) cat ~/system/logs/email-agent-heartbeat.txt # Shows timestamp of last successful run Recent Activity Log tail -20 ~/system/logs/email-agent-launchd.log # Should show recent classification activity like: # {"timestamp":"2026-04-15T13:49:06.450Z","service":"email-agent","level":"info","message":"Classifying via Ollama: ..."} Pending Emails (Email Inbox Tool) node ~/system/tools/email-inbox.js pending # Lists emails waiting for classification or action Daemon Status (Full Details) launchctl print gui/$(id -u)/com.john.email-agent # Shows full launchd status, last run time, exit codes 4. Troubleshooting Problem: Daemon Dead (MODULE_NOT_FOUND Error) Symptom: tail -20 ~/system/logs/email-agent-launchd-error.log # Shows: Error: Cannot find module '~/system/tools/himalaya-adapter' Root Cause: The himalaya-adapter.js file was accidentally archived or deleted. Fix: Verify the file exists: ls -lh ~/system/tools/himalaya-adapter.js If missing, restore from ~/system/tools/archive/ or Git history Restart the daemon: launchctl unload ~/Library/LaunchAgents/com.john.email-agent.plist launchctl load ~/Library/LaunchAgents/com.john.email-agent.plist Verify restart: launchctl list | grep email-agent Problem: Gmail "Unknown Account" Error Symptom: Error: Unknown account: gmail. Available: john, info, alai, alem, dev Root Cause: The gmail key is missing from the VAULT_NAMES object in ~/system/tools/mail-native.js . Fix: Open ~/system/tools/mail-native.js Locate the VAULT_NAMES object (around line 20) Add the gmail entry: const VAULT_NAMES = { john: 'Email - john@basicconsulting.no', info: 'Email - info@basicconsulting.no', alai: 'Email - john@alai.no', alem: 'Email - alem@alai.no', dev: 'Email - dev@alai.no', gmail: 'Email - alembasic@gmail.com' // Add this line }; Save and reload daemon Problem: Gmail Hanging Daemon (High CPU/Memory) Symptom: Multiple overlapping email-agent processes running 400%+ CPU usage (seen in top ) Email agent not completing runs Root Cause: Gmail IMAP fetch is hanging indefinitely, causing overlapping daemon instances. Fix: Identify stuck process: ps aux | grep email-agent Kill the stuck process gracefully: kill -QUIT