Docs / How it works
Bulk drafts and the review queue
Status: built. How the local admin app (06) lets one person review many prepared replies quickly and safely: the agent prepares one draft per client with the reason for it (a phrase in a session, bulk-drafts), the person checks each one and sends it, one click per draft or, for the Checked drafts of one batch, Send all Checked (P85b, below). Nothing sends on its own, on a timer or for the agent, and no route or status can.
One queue
Mail (the admin section, Drafts until P96) is the only place a draft is reviewed. A batch is a read-only view of it (/mail?batch=3, in the View menu, group Batches); there is no separate bulk screen and nothing in the admin creates a batch: choosing the clients is the agent's (decision 0025). Since P85 a bulk-drafts run IS a batch: its first recorded draft makes the batches row (named by the owner's words, intent custom, audience agent, joined to the run by its batchKey) and every draft of the run carries its batchId (drafts.record, the only writer of batches). A batch draft is a Mail draft like any other: Checked reads its Mail text (no exemption), and in a batch every unacknowledged safety result blocks Checked. The list searches on the server (name, address, subject; the counts in the View menu never narrow by the search), shows "7 of 40 · 3 done, 1 sent, 14 to go", and below 640 px keeps one sticky line (View menu, search, Select). Clients the agent did not answer by email (a call to make, no reply needed, crossed off, unknown sender) are recorded with kind and an optional free-text phone (migration 0015) and listed read-only in the view "Not by email"; they never enter the reply queue, and nothing in that path sends. hub dev seed: seed-cli --many 120 adds a long list for manual viewing.
Per-client rule
Even in a batch every reply is individual. The owner's phrase gives a brief: the purpose and tone for the agent, never a body, and the hub renders no body from it. The bulk-drafts skill picks the clients from the project's Notion clients source as the phrase says, keeps only addresses draft.recipients admits, and reads each client's thread and profile first (skills/triage-mail/references/per-client.md). Every record of one run carries one batchKey, so the run is one session in Activity and one batch in Mail.
Writing on the owner's initiative (P85)
A message to a client the owner decides to send ("напиши ему ещё раз", "напиши всем клиентам про …") is bulk-drafts, for one client or many, even when the client has not answered or our last mail was sent. Each draft is a new reply to the newest message of the client's latest thread, ours (in Sent) or theirs, so its mailRef is that message and it never shares one with the sent draft before it. draft_write takes owner_request (his words, verbatim) and draft_write's record takes ownerRequest: with them a message whose drafts are all finished gets a new draft, and the record is not a reply of the client (follow-ups stay as they are). A reply to our own message goes to that message's recipients (the writer sets them, as the door does). A client with no thread at all (P85b: we never wrote and they never wrote) gets a new thread: draft_write with to (the client's address from the project's Notion Clients), subject and owner_request saves a new outgoing message (WRITE_NEW_SCRIPT, @hub/agent/new-thread: Mail's make new outgoing message, no window) from the project's sender (mail.sender, or a brand address the owner named), and draft_write's record records it with "newThread":true in place of mailRef. Its draft has no mailRef (it answers nothing, decision 0031 point 2) and newThread in its context; its Mail versions and write records are keyed by new:<client address> (newThreadKey), so a rerun is refused before a second message and its revision (draft_write {draft}, the admin's Save) writes a new message again, replacing the recorded version. Refused: without the owner's words (owner_request_needed), to our own address, to a client marked do not contact (do_not_contact), and to a client the hub already wrote to (has_thread: reply to the newest message instead). An address that is neither a recorded client nor a row of the project's Notion Clients is refused (not_a_client, P87), except in test mode (draft.recipients: test): the instance's allow_list, the owner's test addresses, passes without the Notion read, so he can get a draft he can actually send (P92; HubMcpEnv.testRecipients); the capabilities line names them. The pre-draft guard asks a Notion read of the session instead of the mail chain. The door sends it as a new message (no reply, SEND_SCRIPT's fallback); Sent detection marks it by its recorded version (P90: never by subject). Each draft is then sent by its own click or by Send all Checked.
Send all Checked (P85b)
One button in a batch's view, under the list (features/mail/batch-send.tsx), for the owner's campaign ("Рассылку по всем клиентам хочу сделать"). It is the send door applied to each Checked draft of ONE batch in turn (decision 0011 amendment of 2026-11-20 point 4), never a bulk send:
- Dry run (
POST /api/projects/:slug/batches/:id/send {apply:false},planBatchin@hub/send/batch): every Checked ready draft of the batch throughassess(manual: Checked bound to the text, Stop sending, do not contact,draft.recipientswith the test allow-list, placeholders, own address, red safety), read from Mail; sends and writes nothing. It returns the drafts that would go out (name, To and Cc, subject, the hash of the Mail text) and the held ones with every reason; drafts past today's batch cap are held with that reason. - One confirmation in place (no dialog): "Send N mails, one every 20 s (about M minutes)", every recipient listed, the held ones and why, today's batch count against the cap; Cancel or "Send N mails".
- Ticket:
POST /api/sends/batch-tickets(the admin's exact Origin, same-origin fetch, single use, 60 s) is minted for the batch and exactly the confirmed draft ids and text hashes (batchTicketKey); the apply carries both, reads the plan again and refuses a draft whose text changed or that can no longer go. - The run (
apps/server/src/send/batch-door.ts,runBatch): on the server, one at a time in the confirmed order. Before each mail: the run's Stop, the batch cap and the spacing (both counted fromsend_log, actoradmin-batch), the draft still in this batch,assessagain and the confirmed hash, thensendDraft(its ownsend_logrow with the full text first, one send, no retry). A refusal or a failure is listed and the run goes on. One run per project at a time; it lives in the server's memory, so a restart ends it between two mails (the drafts not yet sent stay Checked; every sent mail has its row). - Guards of its own (
@hub/config):BATCH_SEND_DAILY_CAP50 batch mails per project per rolling 24 hours,BATCH_SEND_SPACING_SECONDS20 between two mails (a 30-draft batch takes about ten minutes).HUB_BATCH_SPACING_SECONDSshortens the spacing only with the fake Mailer (the e2e run). - Progress and Stop:
GET .../batches/:id/send(read every 2 s while the run goes, like WhatsApp's pairing, and on thesendslive topic), and Stop (POST .../send/stop) leaves the drafts not yet tried. Stop sending (Settings ▸ Sending) also halts it between two mails. The agent has no path to any of it.
The review card
- Up to three tones per draft (
drafts.tones; short / standard / warm, keys 1 2 3); changing the tone clears Checked. - Safety results are computed at read time from rules that are data (
SAFETY_KINDSin@hub/config, for exampledo_not_contact,cc_present,unknown_recipients,risky_word,wrong_thread,already_sent_recently,fact_other_brand); defaults live in@hub/config, per-project overrides insafety_rules, and only acknowledgements are stored. A red result blocks Checked until acknowledged. - Send is gated by "I read the checks"; the card, its states and keys are in
06.
Sent detection
A recorded draft (bulk or not, draft_write's record) that the person sends from Mail is found in the project's Sent mailbox (mail.sent_mailbox) through osascript, matched only by the Message-ID of a Mail version the Hub recorded for it (P90: Mail keeps a draft's Message-ID when it sends it; never by thread or subject, which in a mailbox two people share prove only that someone answered; never by its text, P65; never by its mailRef as its own id, and never by a Sent message already attributed to another draft, P85). A Sent message that answers an open draft's thread (In-Reply-To or References name its mailRef) and is none of the project's recorded versions or sent ids is someone else's reply: a teammate in a shared mailbox, the owner from another device, or a hand send whose id Mail changed (unmeasured). It is stored on the draft (elsewhere_*) and the open card says "Last sent by when within 15 minutes of it, else the sender); it never marks, moves or edits. Each pass also reads the client's Notion Last sent at / Last sent by for each open draft (at most every 30 minutes, also with Mail closed; a stamp with this Mac's own name is ignored) into clients.team_sent_*; the card says "draft_show and mail_list carry both as repliedElsewhere and teamSent, and a draft_write revision of such a draft adds a warning; the server reads only while drafts wait, only since the oldest waiting one, and never launches Mail: when Mail is not running the loop is off and says so (decision 0026). drafts.markSent is the only writer of sent. Not built: a per-batch sent log screen (Activity's Sends view shows the send history; a batch send's rows are "admin-batch").
Data (SQLite, packages/db)
batches (audience, intent, brief, the picked and the excluded clients; read by the batch view), drafts (status ready hold done sent skipped, the checked flag, tones, reason, safety and acked, mail_ref, batch_id; one open draft per client, a partial unique index), safety_rules, send_log. Marks are the client marks of 06.
Update this page when the architecture changes.