# Set up human-voice-writer

> **For the agent reading this.** Your user wants a small model, trained on their own writing, that rewrites any draft so it sounds like them. You do the whole setup. The user gets one checkpoint at the start: you show them what you found and the plan, they confirm or adjust it, and after that you run to the end and report back once.

## The rules

1. **One checkpoint, then autonomy.** Run the diagnostic and ask the user exactly once (Step 1): go with the plan, customize it, or add a source you didn't see. After they answer, don't ask anything else. Ask again only as a last resort, when every recovery path below has failed.
2. **The only other human touches** are the permission prompts their agent or OS shows anyway: connector login, browser login, macOS Full Disk Access. There is no review, approval or "does this sound like you?" step later; quality is judged automatically.
3. **Privacy.** Everything stays on this machine. Never paste raw messages into chat, logs, commit messages, issues or any outside service. When you check de-identification, read the output yourself and keep it out of your replies. Do not keep copies of raw data outside `~/.voice/raw/`; `voice prepare` deletes raw files once they are processed.
4. **Fewest calls.** Each command does a lot. The whole setup takes about 9 of our commands.
5. **Recover on your own.** If a step fails, read the error, fix it and retry. Use the troubleshooting table at the end.

Every command below exists twice: as a CLI command (`voice …`) and as an MCP tool (`voice_…`) with the same arguments. **During setup, use the CLI from your shell.** It works in any agent, and an MCP server registered mid-session usually only loads after a restart. Output is JSON.

---

## Step 0. Install (1 command + setup)

Needs Python 3.10–3.13 and [uv](https://docs.astral.sh/uv/). If `uv` is missing, install it with `curl -LsSf https://astral.sh/uv/install.sh | sh`.

```bash
# Apple Silicon Mac
uv tool install --python 3.12 "human-voice-writer[mlx,ner] @ git+https://github.com/Zelto-ai/human-voice-writer"
# PC with an NVIDIA GPU
uv tool install --python 3.12 "human-voice-writer[cuda,ner] @ git+https://github.com/Zelto-ai/human-voice-writer"

voice setup
```

`voice setup` is the diagnostic. It detects the hardware, lists every model that can train on it (`models`, recommended default first, with estimated training minutes), and scans the usual places for local sources (`local_sources`: exports in Downloads/Desktop/Documents, app databases like WhatsApp Desktop or iMessage, Obsidian vaults). The scan reports paths and sizes only and never reads contents. Setup also installs anything missing (including a local NER model), creates `~/.voice/`, and registers the `voice` MCP server with Claude Code, Codex and Cursor if they are installed.

- If it returns `"ok": false` (no Apple Silicon and no NVIDIA GPU), **stop**. Tell the user in one message that v0 trains only on their own machine and needs an Apple Silicon Mac or an NVIDIA GPU. Do not offer cloud training.
- Training times are estimates, not promises.

## Step 1. Diagnose and confirm (the one question)

**Add what your own tools can reach** to the local scan. For each connector or MCP you have (email, Slack, a unified inbox, a browser tool), run one cheap, **count-only** probe: for example, a sent-mail search that returns thread ids or a count, without opening any message. Note anything that needs a login or a permission first. Don't collect yet.

Also work out **who the user is**: full name, sending addresses and handles, company. Use their account profiles, the sender of their sent mail, or `git config`. The user's own name and company stay in the dataset; everyone else gets redacted.

**Then show the plan and ask once.** Use your question tool if you have one (multiple choice), or a short message. Keep it to one screen, with no message contents:

```
Here's what I found. My plan for your voice model:

Model: Qwen3-4B (medium), the default for this Mac (64 GB), about 30 min to train.
  Also fits: tiny 0.5B (~4 min) · small 1.7B (~12 min) · large 8B (~1 h)

Sources I'll use:
  ✓ Gmail (connector): ~1,290 sent threads in the last year
  ✓ LinkedIn: data export in Downloads, ~10k of your messages
  ✓ iMessage: local database (needs Full Disk Access)
Found, but off by default:
  – Obsidian vaults (4): notes may include AI-written docs
Not found: WhatsApp, Slack, X

I'll identify you as Agustin Suarez (a@zelto.ai) at Zelto.

1. Go with this plan
2. Customize (model, sources on/off, identity)
3. Add a source I didn't find (a connector, an export, a folder path)
```

- **Defaults:** the recommended model; every source you can reach that holds messages the user wrote. Notes folders start off unless the user turns them on, because they often contain AI-drafted text.
- **If they customize:** apply the model with `voice setup --model <id>` (it refuses models that can't train on this machine and lists the ones that can). Turn sources on or off as they say.
- **If they add a source:** a file or folder path, an export they'll download, or a connector to sign into. Probe it the same way and include it.
- Restate the final plan in one line and start. **No more questions after this.**

## Step 2. Collect and convert (you wire the sources)

The tool doesn't parse any particular app. **You** reach each source with whatever you have (connectors, MCPs, a browser, exports on disk, local databases), and you write what you find as **canonical records**. Everything after that is the tool's process.

Collect from the sources in the confirmed plan. **Write records:** One JSON object per message, as JSONL (or a JSON array), into `~/.voice/raw/` with any file name ending in `.jsonl` or `.json`:

```json
{"text": "the message exactly as sent", "is_me": true, "from": "Sender Name", "to": ["Recipient Name"],
 "thread": "conversation id", "channel": "email", "ts": "2026-03-01T10:00:00Z", "source": "gmail"}
```

| Field | |
|---|---|
| `text` | Required. The body exactly as written: no rewriting, summarizing or fixing typos (the typos are the voice). |
| `is_me` | `true` if the user wrote it. **Get this right; it decides what the model learns.** If missing, the tool falls back to a name match, then the most frequent sender. |
| `from`, `to` | Display names. Third-party names here are redacted everywhere in the dataset, so include them. |
| `thread` | A stable conversation id. Context and bursts are grouped per thread. |
| `channel` | `email`, `linkedin`, `linkedin_post`, `whatsapp`, `slack`, `x`, `x_dm`, `sms`, `notes`, or anything else. Chat channels get burst grouping; `email` gets quoted replies and signatures stripped. |
| `ts` | ISO 8601 or unix seconds/ms, as precise as you can. Bursts (messages within ~2 min) need it. |
| `source` | Optional label for stats (`gmail`, `whatsapp-desktop`, …). |

**The process rules:**

- **One record per message as sent.** Don't merge chat messages yourself; the tool groups bursts and learns how the user splits them.
- **Include the other side** of each conversation with `"is_me": false`. It becomes context and is never trained on.
- **Leave out non-messages:** system lines ("image omitted", "message deleted", missed calls, joins), reactions, bot or automated messages, auto-replies, newsletters, calendar invites, and text the user only forwarded or pasted.
- **Leave out AI-written text.** Notes or docs an agent drafted, or messages written with an AI assistant, teach the exact tone you're removing. When unsure, leave it out.
- **Don't redact anything yourself.** The tool de-identifies consistently, and you check its output in Step 3.
- **Write files with a script.** Never paste message contents into the chat.

**How to wire each source.** Stop at **1,000–2,000 messages written by the user**, favoring recent (last 12 months) and outbound or sales messages. If a source fails while collecting (permission denied, export not ready), skip it and mention it in the final report; don't ask again. Typical places:

- **Email:** the email connector's sent folder (`in:sent newer_than:1y`), or an `.mbox` export (e.g. Google Takeout) on disk. "Me" is the sender address.
- **LinkedIn:** a data export in `~/Downloads` (`messages.csv` has `FROM`/`TO`/`DATE`/`CONTENT`/`CONVERSATION ID`; `Shares.csv` has posts), or the messaging page in a browser tool. "Me" is the user's own name in `FROM`.
- **WhatsApp:** chat exports (`.txt`, iOS or Android, any locale), or the desktop app's local database. On macOS it's usually `ChatStorage.sqlite` under `~/Library/Group Containers/*WhatsApp*`, where the `ZISFROMME` column marks "me"; copy it and read the copy, never the original. It may need Full Disk Access, the one OS prompt you may surface.
- **Slack, Teams, Discord, SMS and other chats:** the connector, or an export. "Me" is the user's id.
- **X:** an archive (`tweets.js`, DMs) or a browser tool.
- **Notes:** folders the user writes in themselves (e.g. an Obsidian vault), but see the AI-written rule above.

A unified-inbox connector (one tool covering email, WhatsApp, LinkedIn and more) is the fastest route when the agent has one.

## Step 3. Prepare and de-identify (1–2 commands)

```bash
voice prepare --user-name "Full Name" --user-email me@company.com --company "Company"
```

This imports everything, merges WhatsApp/Slack bursts (messages within ~2 min become one turn), strips quoted replies and signatures, drops sensitive messages (health, credentials, personal money, intimate), replaces third-party names, emails, phones, URLs, addresses, card/bank numbers and IDs with consistent placeholders (`<PERSON_1>`, `<COMPANY_1>`…), dedupes, holds out ~12% for eval, and deletes the raw files it processed.

**Check the de-identification yourself.** It is your job, not the user's.

- Read `sample_to_check` and `leak_candidates`. Look for anything that identifies a third party: names (Spanish and nicknames are the usual misses: "Juancho", "la Colo"), other companies, street names, account handles, internal codenames, health details.
- Re-run with every leak you found (the new terms are applied to the stored dataset):

  ```bash
  voice prepare --extra-redact "Juancho" --extra-redact "Acme=COMPANY" --extra-redact "Calle Falsa 123=ADDRESS"
  ```
- To be thorough, open `~/.voice/dataset/messages.jsonl` and scan it. Repeat until it is clean. One extra run is usually enough.
- Never redact the user's own name or company. Add aliases they sign with via `--keep "Sammy"`.

If `stats.messages` is below ~150, collect more (Step 2) before training. With very little data the fine-tune will probably lose to the baseline.

## Step 4. Write the AI-style pairs (1+ commands)

The model learns `AI-style draft → the user's real message`. You write the AI-style side.

The messages that need one are in `~/.voice/dataset/pairs_todo.jsonl` (`{"id", "channel", "text"}`). By default that is every held-out message plus the 600 most recent training messages. For each one, write how a generic AI assistant would have written the **same message**:

- **Same content:** keep every fact, name, number, link and the same ask. Copy placeholders (`<PERSON_1>`, `<URL_2>`) exactly, the same number of times. Add no new facts or numbers.
- **Generic AI voice:** polished grammar, full sentences, capitalized, "I hope this message finds you well", "I wanted to reach out", "Please let me know if you have any questions", "Best regards". No slang, no typos, no emoji, no lowercase-only.
- **Same language** as the original. Never translate: a Spanish message gets a Spanish AI version. Translated pairs teach the model to switch language. A WhatsApp burst becomes one tidy message.
- **Vary it.** Don't use the same opener every time, or the model learns your template instead of the user's voice.

Example:

```
real:  "holaa <PERSON_1>! si, la vi anoche. te llamo a las 5?"
ai:    "Hola <PERSON_1>, espero que estés muy bien. Sí, revisé la propuesta anoche. ¿Te parece si te llamo a las 5 para conversarla?"
```

Write the results to a JSONL file of `{"id": "…", "ai": "…"}` lines and save them in one go:

```bash
voice add-pairs ~/.voice/dataset/pairs.agent.jsonl
```

If you can run subagents, split `pairs_todo.jsonl` into batches of ~100 and write them in parallel. Pairs with mismatched facts come back in `rejected` with the missing or extra items: fix those and add them again. Continue when the result shows `"ready": true`.

## Step 5. Train (1 command)

```bash
voice train
```

Trains a LoRA adapter on this machine with the default model for the hardware. It blocks until done; set your shell timeout to at least 2× `est_train_minutes`, or run `voice train --background` and poll `voice status`. Never move the data off the machine. The only download is the public base-model weights from Hugging Face.

## Step 6. Evaluate and fix (2 commands per round)

```bash
voice eval
```

This humanizes every held-out AI-style draft with the fine-tune and with a local "base model + style prompt" baseline, then scores style similarity, a local AI-detector score and the fact lock. It returns:

1. **`judge.pairs`.** Each pair holds one real message and one humanized message. Using `judge.real_examples` as reference, decide honestly which is real. Judge the writing, not leftover placeholder artifacts. Save `{"p1": "a", "p2": "b", …}`.
2. **`baseline_tasks`.** This is the "big model + style prompt" baseline. **Give it to a fresh subagent** that only sees `baseline_tasks` (examples + drafts). You have already seen real held-out messages (in the judge pairs), so if you write the baseline yourself it is contaminated and unfairly strong. Without subagents, write it before reading the judge pairs. Using only `baseline_tasks.examples`, rewrite each draft in the user's voice and save `{"<id>": "text", …}`.

```bash
voice eval --judge-answers judge.json --baseline-outputs baseline.json
```

**Targets** (all automatic): judge accuracy ≤ 60% (you can't tell them apart), beats the baseline, AI-detector score close to the user's real messages, and the fact lock holding on ≥ 90% of drafts on the first few tries. Names, numbers, links and the ask are always kept, because a draft that fails the lock is returned unchanged.

**Auto-fix loop.** If `pass` is false, do what `suggested_fix` says (more epochs, the next model up the catalog that fits this machine, or more data), then train and evaluate again. Run at most 3 rounds, and stop early if the next round would take the total past ~30 minutes. `voice status` shows every model, and the best one is kept as the default automatically. If the baseline still wins after that, say so plainly in the report. Honesty about this result is part of the product.

## Step 7. Report (one message to the user)

Send exactly one short message, with no raw personal content:

```
Done. Your humanizer is trained on <N> of your messages (<sources>) and runs locally on this <machine>.
Score: judge accuracy <X>% (≤60% = indistinguishable), voice score <Y> vs <Z> for a style-prompt baseline, AI-detector <A> → <B>.
<one line: passed / what still falls short>
<only if any: sources from the plan that failed, and why>
Use it: ask me to "humanize this before sending", or run  voice humanize "your draft"  (add -c whatsapp|linkedin|slack).
```

## Daily use

- **Agent:** before sending outreach, call `voice_humanize(message, channel)`. If `ok` is false, the fact lock refused every variant: send the original draft or fix the closest variant by hand. Never send a variant whose `fact_lock.ok` is false.
- **CLI:** `voice humanize "draft"` or `cat draft.txt | voice humanize -c email`. `-n 3` gives three variants. With `-c whatsapp` you get several short messages, one per line.

## Troubleshooting

| Problem | What to do |
|---|---|
| `uv tool install` fails on Python 3.14+ | Keep `--python 3.12`. MLX and spaCy wheels lag new Python versions. |
| `voice: command not found` after install | Run `uv tool update-shell` and open a new shell, or call `~/.local/bin/voice`. |
| A local app database says "Operation not permitted" | It needs Full Disk Access for the terminal app. Skip that source if it isn't granted. |
| `prepare` finds 0 messages | Check `files` in the output: every file is listed as `ok`, `skipped` (not `.jsonl`/`.json`) or `error`. Every record needs a `text` field. |
| The user's own messages are missing | Set `is_me` on every record (`files.<name>.without_is_me` counts the ones without it), or pass `--user-name` / `--user-email` for the fallback. |
| `add-pairs` rejects many pairs | Copy placeholders and numbers exactly; don't add or drop any. |
| Train: out of memory | `voice train --model tiny` (or the next model down). |
| Train refused ("not practical") | That model doesn't fit this machine. Use the default or a smaller one. |
| Eval: fine-tune loses to the baseline | Follow `suggested_fix`. With < 300 messages, more data helps most. |
| Humanize keeps failing the fact lock | Train more epochs or a bigger model; meanwhile send the original. |
