Add mail_evidence and an evidence token scope #84

Merged
svc-agent-writer merged 2 commits from feat/mail-evidence into main 2026-11-01 03:28:53 +00:00

Closes #78. Decision: ADR 0008.

Summary

 scopes (auth.py)
-  read token:  read            write token: read, write
+  evidence token: evidence     read token: evidence, read     write token: evidence, read, write
+  verifier floor: evidence (was read)
 tools
+  mail_evidence                      evidence
~  mail_people, mail_status          read → evidence
~  mail_changes                      read → evidence, + envelope=true
   mail_read, mail_search, …         read (unchanged)
mail_evidence(address)
  own address, or a From in Sent/Drafts of that account   → "no evidence" (unless include_self)
  Store.evidence                                           # one read: counts per role, Sent To/Cc, newest rows
  domain: example.test
  received: 4 2026-10-01..2026-10-04
  roles: inbox=2 archive=1 other=1
  sent: 2 2026-10-10..2026-10-11                          # To or Cc, exact match after parsing
  signature:                                               # evidence.signatures: last paragraph ≤ 8 lines,
    <untrusted> … </untrusted>                             #   deduplicated, max_chars at a line boundary,
  subjects:                                                #   every address → [address]
  2026-10-04 | id | Agenda                                 # Re:/Fwd: removed
  shown=4

New module evidence.py: the sign-off rule, the address parser for the stored Name <addr> columns, and display subjects. It is pure.

Evidence

  • Before: an evidence-only client needs the read token, which reaches mail_read and every body.
    After: with the evidence token, list_tools returns exactly mail_evidence, mail_people, mail_status and mail_changes. mail_read, mail_search, mail_thread and mail_mailboxes raise ToolError. The read and write tokens list every tool they listed before, plus mail_evidence.
  • tests/test_evidence.py, 48 tests:
the exact field list                         → domain received roles sent signature subjects
no other content                             → no body line, attachment name, flag, owner or other address
sign-off: one paragraph / none / 9 lines     → None;  8 lines → the block
two messages, one sign-off                   → once
max_chars mid-block                          → cut at a line boundary
addresses in a sign-off                      → [address]
sent: To, Cc (upper case), lookalike, From   → 2, owner with include_self → 0
owner, alias seen in Sent, From in Drafts    → no evidence; include_self → evidence
envelope=true                                → from | to | cc, addresses only; - when empty or gone
flags rows and envelope=false                → 4 cells, unchanged
token scopes, distinct tokens, own bucket    → as ADR 0008 §1
  • make check: lint, mypy --strict, 299 unit tests, pip-audit clean.

Points to rule on

  • ADR 0008 §2 is amended in this PR (needs your ruling). The first rule, "the lines after the last blank line", returned body text. Probe on the first build:
Mail First build Now
"…\n\nThe price is $40k, final, do not share." that sentence (a body leak) nothing
"Yes, fine.\n\nSent from my iPhone" Sent from my iPhone nothing
"Done.\n\nAlice\n\nCONFIDENTIAL: …" the disclaimer Alice
Outlook top-post, Gmail HTML signature correct correct
"Thanks,\nAlice\n-- \nAlice Example | CFO…" Thanks, / Alice the same: #85

A block now starts at an anchor: a closing phrase from a closed list, or a line that starts with the sender's name. Lines above it are never returned. Disclaimers and client footers are skipped. A corpus of 13 mails that must give nothing and 16 that must give a block guards the rule.

  • The small bounds are now in the ADR: a 120-character subject cut, max_messages 1 to 50, max_chars 100 to 4,000, one line per Message-ID, and FW: removed.
  • A -- signature is still lost at ingest. Filed as #85: a sign_off column, a backlog, and a counts-only hit-rate report. It needs its own ADR 0008 amendment.
  • Bcc is not counted, by ADR 0008 §2. It is not stored, either.

Merge Danger

Door: two-way

No schema change. The scope floor drops from read to evidence, but only a configured evidence token holds evidence alone.

Blast Radius: api

  • Existing deployments have no evidence_token_file, so no new token exists until an operator adds one. The deploy base already routes every *.token file to api.
  • The read and write tokens gain mail_evidence. It returns less than mail_read already gives them.

🤖 Generated with Claude Code

Closes #78. Decision: ADR 0008. ## Summary ```diff scopes (auth.py) - read token: read write token: read, write + evidence token: evidence read token: evidence, read write token: evidence, read, write + verifier floor: evidence (was read) tools + mail_evidence evidence ~ mail_people, mail_status read → evidence ~ mail_changes read → evidence, + envelope=true mail_read, mail_search, … read (unchanged) ``` ```text mail_evidence(address) own address, or a From in Sent/Drafts of that account → "no evidence" (unless include_self) Store.evidence # one read: counts per role, Sent To/Cc, newest rows domain: example.test received: 4 2026-10-01..2026-10-04 roles: inbox=2 archive=1 other=1 sent: 2 2026-10-10..2026-10-11 # To or Cc, exact match after parsing signature: # evidence.signatures: last paragraph ≤ 8 lines, <untrusted> … </untrusted> # deduplicated, max_chars at a line boundary, subjects: # every address → [address] 2026-10-04 | id | Agenda # Re:/Fwd: removed shown=4 ``` New module `evidence.py`: the sign-off rule, the address parser for the stored `Name <addr>` columns, and display subjects. It is pure. ## Evidence - **Before:** an evidence-only client needs the read token, which reaches `mail_read` and every body. **After:** with the evidence token, `list_tools` returns exactly `mail_evidence`, `mail_people`, `mail_status` and `mail_changes`. `mail_read`, `mail_search`, `mail_thread` and `mail_mailboxes` raise `ToolError`. The read and write tokens list every tool they listed before, plus `mail_evidence`. - `tests/test_evidence.py`, 48 tests: ```text the exact field list → domain received roles sent signature subjects no other content → no body line, attachment name, flag, owner or other address sign-off: one paragraph / none / 9 lines → None; 8 lines → the block two messages, one sign-off → once max_chars mid-block → cut at a line boundary addresses in a sign-off → [address] sent: To, Cc (upper case), lookalike, From → 2, owner with include_self → 0 owner, alias seen in Sent, From in Drafts → no evidence; include_self → evidence envelope=true → from | to | cc, addresses only; - when empty or gone flags rows and envelope=false → 4 cells, unchanged token scopes, distinct tokens, own bucket → as ADR 0008 §1 ``` - `make check`: lint, `mypy --strict`, 299 unit tests, pip-audit clean. ## Points to rule on - **ADR 0008 §2 is amended in this PR (needs your ruling).** The first rule, "the lines after the last blank line", returned body text. Probe on the first build: | Mail | First build | Now | |---|---|---| | "…\n\nThe price is $40k, final, do not share." | that sentence (**a body leak**) | nothing | | "Yes, fine.\n\nSent from my iPhone" | `Sent from my iPhone` | nothing | | "Done.\n\nAlice\n\nCONFIDENTIAL: …" | the disclaimer | `Alice` | | Outlook top-post, Gmail HTML signature | correct | correct | | "Thanks,\nAlice\n-- \nAlice Example \| CFO…" | `Thanks, / Alice` | the same: #85 | A block now starts at an anchor: a closing phrase from a closed list, or a line that starts with the sender's name. Lines above it are never returned. Disclaimers and client footers are skipped. A corpus of 13 mails that must give nothing and 16 that must give a block guards the rule. - **The small bounds are now in the ADR:** a 120-character subject cut, `max_messages` 1 to 50, `max_chars` 100 to 4,000, one line per Message-ID, and `FW:` removed. - **A `-- ` signature is still lost at ingest.** Filed as #85: a `sign_off` column, a backlog, and a counts-only hit-rate report. It needs its own ADR 0008 amendment. - **Bcc is not counted, by ADR 0008 §2.** It is not stored, either. ## Merge Danger **Door:** two-way No schema change. The scope floor drops from `read` to `evidence`, but only a configured evidence token holds `evidence` alone. **Blast Radius:** api - Existing deployments have no `evidence_token_file`, so no new token exists until an operator adds one. The deploy base already routes every `*.token` file to `api`. - The read and write tokens gain `mail_evidence`. It returns less than `mail_read` already gives them. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Three nested scopes (ADR 0008 §1): an evidence token reaches mail_evidence, mail_people, mail_status and mail_changes only, never a body. The read and write tokens keep every tool they reach today.

mail_evidence returns the closed field list of ADR 0008 §2 for one sender: domain, received, roles, sent (To or Cc in Sent), the distinct sign-off blocks of the newest messages with every address redacted, and subjects. The owner's addresses give no evidence unless include_self. mail_changes envelope=true adds from | to | cc to each add row, addresses only (§3).

Closes #78.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first rule took the last paragraph after a blank line, so a short closing sentence of the body ("The price is $40k, final") came back as a signature, against ADR 0008 §2. A block now starts at an anchor line: a closing phrase from a closed list, or a line that starts with the sender's name. Lines above the anchor are never returned. Disclaimers and mail-client footers are skipped.

A corpus of 13 mails that must give nothing and 16 that must give a block guards the rule. ADR 0008 §2 is amended to match, with the bounds the first build chose. Delimited signatures, which ingest trims, are #85.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.