# Build a morning and evening inbox brief

At 8 AM a studio owner has two deadlines in two different inboxes. By 5 PM the estimate has gone out, the website link is still owed, a new lead wants pricing, and the logo is still with the client. This guide builds the two reports and shows how to trace each item back to a message.

## 1. Try it before you connect anything

Unzip **owner-inbox-brief.zip**. Open a terminal in the extracted `owner-inbox-brief` folder. Use Python 3.11 or newer on macOS or Linux.

```sh
python3 brief.py demo
python3 -m unittest -v test_brief
```

Open `demo-output/2026-11-16-morning.md` and `demo-output/2026-11-16-evening.md`. The first run adds three messages in the morning and three more in the evening. Run it again and both counts of **new** messages are zero. The morning view always cuts off at 8 AM, even after you have run the evening.

The six messages and the attachment metadata are fictional. We ran a local Qwen2.5-1.5B-Instruct model with llama.cpp on each body, then shipped its actual responses in `fixtures/model.json`. The default demo replays those responses offline. An input fingerprint ties each response to its message. The live setup below uses Ollama and your own model. It can give different answers. We tested the Gmail transport with simulated API responses. No customer mailbox was used to make this guide.

## 2. What to copy into your own project

Keep **CLAUDE.md** at the project root for Claude Code, or **AGENTS.md** for Codex. They tell your assistant what makes a useful morning or evening brief. To try the morning prompt, ask “Read today's morning report. Who needs me first? Give me the original sentence and the mailbox.” At 5 PM ask “What did I deliver, what did I promise, and what rolled over?” An instruction file provides the rules. The reader below supplies mailbox access, and the timer in step 5 supplies the schedule.

If you use a hosted assistant to read a real report, its contents go to that provider under your account settings. You can also read the Markdown directly and keep the workflow local. [Claude Code project instructions](https://code.claude.com/docs/en/memory) · [Codex project instructions](https://developers.openai.com/codex/guides/agents-md/)

## 3. Connect one Gmail account, then a second if you need it

1. Start with a test mailbox you control. In Gmail, create a label such as **Owner brief** and apply it to a handful of business threads you want covered. Label the client request, then reply normally. The reader follows selected threads so a sent reply can supply evidence even if the reply itself lacks the custom label.
2. In your own Google Cloud project enable **Gmail API**. Configure Google Auth Platform branding, audience and data access. For an external app still in Testing, add each participating account as a test user. Create an OAuth client of type **Desktop app** and download its JSON file. Your Workspace administrator may need to allow the application. Google’s read-only scope permits mailbox-wide reading; the label is a filter enforced by this script. External testing tokens can expire and require a fresh authorization. [Google setup](https://developers.google.com/workspace/gmail/api/quickstart/python) · [Scope reference](https://developers.google.com/workspace/gmail/api/auth/scopes) · [Token expiration](https://developers.google.com/identity/protocols/oauth2#expiration)
3. Save the client file as `~/.config/owner-inbox/client.json`, outside the project. Create a private environment and run the user-consent flow on your own computer.

```sh
mkdir -p -m 700 ~/.config/owner-inbox
chmod 600 ~/.config/owner-inbox/client.json
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements-gmail.txt
.venv/bin/python gmail_setup.py --client ~/.config/owner-inbox/client.json --token ~/.config/owner-inbox/sales-token.json
```

Pick your sales account in Google's sign-in window. The script prints your custom label IDs. Copy the ID next to **Owner brief**. For a second inbox rerun the last command with `studio-token.json`, sign in with the second account and copy its own label ID.

4. Copy `config.example.json` to `~/.config/owner-inbox/config.json`. Replace the example addresses, label IDs and token paths. Delete the second account entry if you use one inbox. Choose your local IANA timezone and the first day of your pilot. Keep one stable alias per account. Each token is checked against the configured email address. Use a dedicated private state folder. Reusing it with different accounts or demo data is rejected.
5. Install Ollama for your operating system from [Ollama](https://ollama.com/download). Start its local service and pull a model. The default suggested model for the optional live path is `qwen2.5:3b`. Its first download requires network access and local disk space. Inference runs through the loopback endpoint on your computer. [Model](https://ollama.com/library/qwen2.5:3b) · [Structured output](https://docs.ollama.com/capabilities/structured-outputs)

```sh
ollama pull qwen2.5:3b
.venv/bin/python brief.py demo --local-model qwen2.5:3b
.venv/bin/python brief.py live morning --config ~/.config/owner-inbox/config.json
.venv/bin/python brief.py live evening --config ~/.config/owner-inbox/config.json
```

Start with a labeled request, a sent attachment and a promise from your own authorized test account. Check the printed Markdown file against Gmail. A token failure, wrong-account token or unavailable model aborts the run. Check the timestamps on existing reports after an error. Never share the private folder, credentials or real messages in a public repo.

## 4. How a message becomes an action

**Collect.** `gmail_reader.py` lists labeled messages, follows their threads using read-only GETs and skips draft, spam and trash messages. Google timestamps and the SENT system label supply timing and direction. The tracking key is mailbox alias plus provider message ID. When a valid Message-ID header is available, the brief includes a search you can paste into Gmail to find that exact email. Repeated imports reuse the saved decision. The pilot covers up to 250 selected threads per account, including previously tracked threads. Choose a narrow label and a recent start date. Use a fresh private folder when starting a new pilot with a different scope. [Gmail search and labels](https://developers.google.com/workspace/gmail/api/guides/filtering)

**Read.** `extract.py` gives the local model the current plain-text body. The model picks a work type and a source line. It has no email tools. The Python code checks the selected line, catches explicit requests and future promises, and routes unclear cases into “Read the original.” HTML-only, long and ambiguous messages can need a person. Multiple asks in one sentence, unusual quote formats and implied deadlines deserve a spot-check. Model output is a suggestion.

**Prove.** In the example, Mara asked for `estimate-N41.pdf`. Sam later sent Mara a message in that same sales thread with exactly that filename attached. The report credits delivery. Conversely, “I will send the preview link tomorrow morning” leaves the website task open. Juniper's incoming promise stays under “Waiting on someone else.” The model called it an update. You can inspect the raw response, the quoted line and the Python rule in the download. A matching filename establishes evidence of sending a named attachment, not its contents, acceptance or payment.

**Close other work.** Generic replies, newly sent links and “done” from a third party aren't enough for the strict file rule. If you finished work on a call, checked the portal or sent a link yourself, use the original request's account/message reference from the report. Supply your own note as the operator. Substitute your actual state path and source ID.

```sh
.venv/bin/python record_done.py --state ~/.local/share/owner-inbox-brief --source studio/YOUR_MESSAGE_ID --note 'Opened the preview with the client on our call at 3:15.'
```

The next brief credits the recorded owner confirmation and keeps the note. A promise made to a client stays visible alongside the client's original requested day. For multi-action or ambiguous requests, review the source before marking the whole item complete.

## 5. Get the reports on weekdays

The build writes Markdown and JSON locally. On macOS the included scheduler runs at **8 AM and 5 PM, Monday–Friday, in the computer's local timezone**, and requests a desktop notification after a successful report. Set the config timezone to match your computer. Run these commands only after the two manual runs succeed. Keep the project and its virtual environment in their final location.

```sh
.venv/bin/python schedule_mac.py --config ~/.config/owner-inbox/config.json --out ./schedules
plutil -lint schedules/local.inboxbrief.morning.plist
plutil -lint schedules/local.inboxbrief.evening.plist
mkdir -p ~/Library/LaunchAgents
cp -i schedules/local.inboxbrief.*.plist ~/Library/LaunchAgents/
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/local.inboxbrief.morning.plist
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/local.inboxbrief.evening.plist
```

The Mac needs a logged-in user, network access and the model service. A sleeping or powered-off computer can deliver late or miss a run. If notifications are disabled, read the dated reports directly. Logs are in the configured private folder. To stop the jobs run `launchctl bootout gui/$(id -u)/local.inboxbrief.morning` and the same for `local.inboxbrief.evening`, then remove the two installed plist files. The generator only writes files for you to inspect. It doesn't install them.

On an always-on Linux machine, use `crontab -e` in the intended local timezone. Replace the paths below with absolute paths for that machine. A headless runner delivers the reports as files.

```cron
0 8 * * 1-5 /ABS/kit/.venv/bin/python /ABS/kit/brief.py live morning --config /ABS/private/config.json >> /ABS/private/brief.log 2>&1
0 17 * * 1-5 /ABS/kit/.venv/bin/python /ABS/kit/brief.py live evening --config /ABS/private/config.json >> /ABS/private/brief.log 2>&1
```

## 6. Decide whether it earns its place

For a week, compare the first two actions against what you actually did first. Note a missed commitment, a stale deadline or work the report incorrectly called finished. Change one input or rule, rerun the fictional example and compare again. If a mailbox isn't covered or a supplier called you instead, say so in the review. An empty list only describes the inputs the agent saw.
