# Inbox triage

Unread count and the emails that need a reply, with buttons to refresh or archive newsletters. Your agent reads the inbox through the user's own email service; the phone doesn't share email.

**Sizes:** small (unread count), medium (two emails and the buttons), large (all of it)
**Interaction:** buttons, answered by a listener
**Rule:** archiving is reversible, so a tap is enough. Sending a reply on the user's behalf is consequential: show the recipient and the reply on the widget ("Reply to Sara ready" [Send] [Review]) so the tap is the approval, or ask with `droplet_ask`.

## Widget

```json
{
  "slug": "inbox",
  "title": "Inbox",
  "symbol": "envelope.fill",
  "accent": "#0A84FF",
  "blocks": [
    { "type": "metric", "label": "Unread", "value": "14", "change": "+3" },
    { "type": "list", "title": "Needs a reply", "items": [
      { "title": "Khalid: Q4 budget", "detail": "2h" },
      { "title": "Sara: project kickoff", "detail": "3h" },
      { "title": "Omar: contract draft", "detail": "5h" }
    ] },
    { "type": "buttons", "items": [
      { "label": "Archive news", "id": "archive-newsletters", "symbol": "archivebox.fill" },
      { "label": "Refresh", "id": "refresh", "symbol": "arrow.clockwise" }
    ] }
  ],
  "sizes": { "small": [0], "medium": [1, 2], "large": [0, 1, 2] },
  "lock": { "circular": 0, "inline": "14 unread" }
}
```

With buttons on the widget, medium shows only 2 list rows (large 5). The third email shows on large.

## Handler

```javascript
// inbox-handler.mjs, run by listen.mjs for each tap
import { readFileSync } from "node:fs";
const event = JSON.parse(readFileSync(0, "utf8"));

const buttons = { type: "buttons", items: [
  { label: "Archive news", id: "archive-newsletters", symbol: "archivebox.fill" },
  { label: "Refresh", id: "refresh", symbol: "arrow.clockwise" },
] };
const render = ({ unread, top }) => ({
  blocks: [
    { type: "metric", label: "Unread", value: String(unread) },
    top.length
      ? { type: "list", title: "Needs a reply", items: top.slice(0, 6).map((m) => ({ title: `${m.from}: ${m.subject}`.slice(0, 41), detail: m.age })) }
      : { type: "list", items: ["Nothing needs a reply"] },
    buttons,
  ],
  lock: { circular: 0, inline: `${unread} unread` },
});

console.log(JSON.stringify({ blocks: [{ type: "metric", label: "Unread", value: "…" }, { type: "list", items: ["Working…"] }, buttons] }));
if (event.target === "archive-newsletters") await archiveNewsletters();   // your email API
console.log(JSON.stringify(render(await fetchInboxSummary())));          // your email API
```

Every update keeps the same three blocks, so `sizes` and `lock` stay valid. Keep the numbers honest: if the user reads email elsewhere, refresh on a schedule too (every 15 to 30 minutes), not only on taps.
