Skip to main content

22 · Email assistant

The planner has its own mailbox. The couple email it, or forward things to it (a quote, an invoice, a supplier’s reply). Claude reads each message, updates the plan through the same tools the MCP connector offers (notebook 26), and replies. Code: worker/src/assistant.js (pipeline and rules), worker/src/mailbox.js (IMAP/SMTP).

When it runs

  • Every 15 minutes from the cron. Check mailbox now on Email & Reminders (POST /api/assistant/run) checks immediately; GET /api/assistant/status lists recent activity.
  • Up to 3 emails per run (5 fetch rounds), up to 14 model turns per email, up to 3 attempts per email, a 10-minute processing lock. ASSISTANT_DAILY_LIMIT (default 50) caps emails per day.
  • Model ASSISTANT_MODEL, default claude-haiku-5-5. Key ANTHROPIC_API_KEY.
  • Limits: 10 MB per message, 40,000 characters of body, up to 5 attachments of 4 MB each (PDFs and PNG/JPEG/GIF/WEBP images go to Claude).
  • An email that can’t be read is skipped for good rather than retried forever.

Safety rules (enforced in code, not left to the model)

Rule Detail
Only allow-listed senders count ASSISTANT_ALLOWED_EMAILS (the couple). Mail from anyone else is logged as ignored.
Replies only ever go to the couple The model has no send tool and never chooses recipients.
Cc/bcc with other people = a separate note If anyone outside the allow-list is on the email (or the mailbox was bcc’d), the plan is updated and the couple get a new “Filed: …” email of their own. Nothing is ever sent on the original thread. (mode: direct vs copied)
Only the sender’s own words are instructions Forwarded text, quoted replies, signatures and attachments are information to file, never instructions.
Confirm first Marking a payment paid, any create/update of a payment with a paid date, any delete, and update_setup are queued with a 6-character code (assistant_pending). They run only when one of the couple approves it in a reply on the same thread (confirm_action / cancel_action). A change queued while reading an email can’t be confirmed in that same email.
Sender check Only the mail server named by ASSISTANT_AUTHSERV_ID is trusted in Authentication-Results, and only a pass that vouches for the From domain. With ASSISTANT_SENDER_AUTH=strict it acts only on verified senders; otherwise an unverified sender’s changes all wait for a confirmation code.
Simulation ASSISTANT_DRY_RUN=1 reads and replies but saves nothing (“(simulation: not saved)”).

How it’s told to work (system prompt, summarised)

  • Start with get_overview; use list/get tools to find ids before changing anything; check something doesn’t already exist before creating it.
  • Money in pence in the tools, pounds in the reply. Dates YYYY-MM-DD, times HH:MM.
  • Record what the email actually establishes (a quote, a date, a payment due, contact details, a to-do). If it’s ambiguous, ask rather than guess.
  • The reply is a short, friendly plain-text email in British English (no markdown), sent to both of them: what it understood, what it needs, anything wrong or urgent (a close deadline, a price over budget). A list of the exact changes made is added underneath automatically.
  • If a supplier needs a reply, it says so and can offer wording they can send themselves.
  • When it needs an answer it asks in the reply and calls ask_in_app, so the question also appears in an “Email: …” chat in the app with a notification (notebook 23).

What gets stored (assistant_messages, migration 0011)

kind (inbound / brief), Message-ID and thread id, sender, subject, a body excerpt, mode (direct / copied), status (processing / done / ignored / failed) and reason, the reply text and its Message-ID, the actions taken (JSON), attempts, token counts, dry-run flag. Pending confirmations are in assistant_pending (pending / confirmed / cancelled).

Settings (Worker variables / secrets)

Variable Meaning
ASSISTANT_MAIL_USER, ASSISTANT_MAIL_PASSWORD (secret) the mailbox
ASSISTANT_IMAP_HOST (+ ASSISTANT_SMTP_HOST, _IMAP_PORT, _SMTP_PORT) mail server
ASSISTANT_ALLOWED_EMAILS the couple’s addresses
ANTHROPIC_API_KEY (secret) Claude
ASSISTANT_MODEL, ASSISTANT_DAILY_LIMIT, ASSISTANT_DRY_RUN, ASSISTANT_SENDER_AUTH, ASSISTANT_AUTHSERV_ID optional behaviour

Email settings are read-only in the app (Email & Reminders shows them). Every run is logged to AI usage (notebook 25). Test suite: worker/test-assistant.mjs, against a fake mailbox and fake Claude API.