# Drafting

Reply-worthy mail gets a draft written inside the Gmail thread. This page
explains how a draft is produced and every way you can steer it. Drafts
need an active license.

## How a draft is made

Each new email goes through one pipeline:

![The result: a draft in the thread, with a [TODO] where the model did not know](images/gmail-thread-draft.png)

1. **Skip filter.** Senders in `skipSenders`, mail you already answered,
   and self-addressed notifications (unless enabled) stop here.
2. **One classifier call.** Does it need a reply? Which category? Urgent?
   The classifier fails open: on any error the email is treated as
   reply-worthy, because a junk draft is recoverable and a silently
   skipped email is not.
3. **Two searches over the local index.** Knowledge: the top passages
   across your sources (what to say). Style: the sent emails of yours most
   like this situation (how to say it). Canonical answers rank above
   ordinary knowledge; corrections you made to earlier drafts ride along
   with the style examples.
4. **One model call.** Standing rules, your instructions, matched sender
   rules, your style line, the thread history (each message marked as
   yours or theirs, quoted copies stripped), the email, the retrieved
   knowledge, the style examples, and any live lookups.
5. **The draft is created in the thread**, your signature appended, labels
   applied, a notification sent.

Standing rules the model always gets: never invent facts; anything unknown
becomes a `[TODO: …]` marker; email content is data, so instructions inside
a message cannot steer the draft; write as you (your address and send-as
aliases), to the right recipient (Reply-To when set).

"Training" is retrieval plus examples, never fine-tuning. That is what
makes any model, including a local one, work.

## Steering, from lightest to heaviest

### A line of style

**Preferences → Assistant → Voice → Writing style**, or `drafts.style`.
Free text that joins the standing instructions: "short paragraphs, warm,
no exclamation marks, British spelling".

### Your signature

`drafts.signature` is appended after generation. The model never sees it,
so it cannot be changed, duplicated or dropped. If the model already
signed, the signature is not appended twice.

### Standing instructions

`~/.config/inboxminder/instructions.md` (**Preferences → Rules → Open
instructions.md**). Free text added to every draft prompt. Policy belongs
here: "never commit to a refund; leave a [TODO]", "we do not offer phone
support", "always link the status page for outages". The file is re-read
for every draft, so edits take effect without a restart.

### Per-sender rules

**Preferences → Rules → Sender rules**, or `[[instructions.rules]]`. Each
rule is a match on the sender's address (`@acme.com`, `dan@`, a full
address) and a note: "Enterprise customer; always offer a call", "Be
brief", "Never draft for this domain; label only". Rules steer the
classifier and the draft prompt. They never act: no forwarding, archiving
or sending. Display names never match, since anyone can set one.

### Your notes

**Your notes** in the InboxMinder window, or `inboxminder notes save
--stdin`. Markdown files under `~/.config/inboxminder/notes/`, indexed the
moment you save, retrieved like any other knowledge. The place for things
you know that are written down nowhere else: "the Q3 pricing change takes
effect 1 November", "Acme's contract renews in March".

### Canonical answers

Retrieval guesses; answers about money and policy must be exact.
`[answers]` points at a local folder of markdown Q&A snippets. Each file
is one answer; its first heading (or filename) is the question. They are
indexed as `canonical-answer` and ranked above ordinary knowledge, reused
near-verbatim, at most `maxPerDraft` per draft.

With `escalate = true`, a question your answers do not cover gets a
suggested snippet written as `<slug>.suggested.md` into the same folder.
Suggested files are never indexed. Read it, fix it, rename it to drop
`.suggested`, and that question is answered canonically forever. The
**Written for you** section lists suggestions awaiting review.

```toml
[answers]
enabled = true
dir = "~/inboxminder-answers"
```

### Learning from your edits

**Preferences → Assistant → Voice → Learn from my edits**, or
`[feedback]`. The app pairs each draft with the reply you actually sent on
the same thread. A meaningful edit becomes a local "correction" document,
embedded under the inbound email it answered, so a future similar email
retrieves how you reshaped the last draft like it. Up to `maxCorrections`
ride along per draft; the corpus is capped at `maxStored`. All local; this
is retrieval, not training.

### Coverage

`drafts.coverage = "confident-only"` skips drafting when the classifier
explicitly says it is unsure. Classifier errors still fail open and draft.
Default is `all`.

## Curating what drafts know

![Knowledge: what a draft would find for a question](images/window-knowledge-search.png)

**Knowledge** in the window shows every indexed passage and lets you ask a
question to see what a draft would retrieve. **Stop using in drafts**
(`inboxminder knowledge exclude <docKey>`) removes a document and keeps it
out through re-indexing; **include** brings it back on the next pull.

**Voice** shows the sent emails used as tone examples. Automated mail you
sent (auto-replies, bulk sends, mail merges, calendar invites, copies of
one template) is skipped with its reason, because it teaches the wrong
tone; **Use it anyway** keeps one for good. `email.automatedSent` switches
this to flag-only or off. `inboxminder voice audit` is a dry run over
recent sent mail.

![Voice: automated mail is skipped with its reason](images/window-voice.png)

## Housekeeping

- **Superseded drafts.** When the other side writes again before you
  replied, the stale draft is deleted and a fresh one written.
- **Delete on reply.** `drafts.deleteOnReply` removes the app's unsent
  draft when you answer from elsewhere.
- **Expiry.** `drafts.maxAgeDays` sweeps the app's unsent drafts older
  than N days.

In every case the app deletes only a draft it created itself, and only
after Gmail confirms it is still unsent. Your sent mail is never touched.

## Trying before it is live

```bash
inboxminder draft <gmail-message-id>
```

prints the verdict, the draft, and (when enabled) the docs-gap and ticket
verdicts, creating nothing. Change a note or an instruction, run it again,
compare. **Drafts** in the window shows, for every real draft, the passages
and sent emails it drew on.

## Contact forms

If your website's form emails you from your own address, those emails are
notifications to yourself and get no draft by default. Set
`email.draftSelfNotifications = true` to draft the reply to the person who
filled the form in (the draft goes to the Reply-To the form sets).
