oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1# Coordinator email through Keymail
2
3Status: blocked on upstream contract/access, 2026-11-13. This is an integration
4proposal, not an available email feature. No mailbox, transport, credentials,
5database migration, worker or UI is enabled by this change.
6
7## Evidence and exact blocker
8
9Checked the reachable resources before choosing an implementation:
10
11- MCP resource and resource-template discovery both returned empty lists.
12 No Keymail backend or mail-service API is exposed by the tools in this step.
13- Repository searches for Keymail find sign-in configuration in
14 `internal/equipo/setup/session_handlers.go` (`auth.New`, `KeymailServers`)
15 and `github.com/keymaildev/signin v0.1.1` in `go.mod`. Neither establishes a
16 mailbox or two-way delivery contract.
17- `README.md:50-53` describes CARLOS SMTP credentials for **sign-in mail**.
18 These must not be reused for this feature.
19- Existing “connector” contracts concern model providers and token scheduling,
20 not Keymail delivery.
21- The coordinator's repository lookup found only Docs' OAuth client, not a
22 Keymail backend. That is supplied investigation evidence, not a fresh backend
23 inspection here. No Docs code was changed.
24
25We cannot verify Keymail's mailbox capabilities, authentication scopes, inbound
26sender guarantees, delivery semantics or test access. This does **not** establish
27that Keymail lacks those capabilities. No guessed endpoints or live probes were
28used. The unblocker is a Keymail maintainer supplying a versioned service contract,
29an identified backend/repository owner and authorized sandbox access, with fixtures
30for the capabilities below. Mailbox provisioning and real sending require separate
31explicit authorization even after that contract is available.
32
33## Proposed upstream contract, not discovered API
34
35Ask Keymail to confirm or provide:
36
371. An explicitly provisioned coordinator identity with stable mailbox ID, verified
38 sending domain, inbound address and revocation. Display name must disclose
39 “Equipo coordinator”; never impersonate the person. Equipo stores the mapping
40 of mailbox, coordinator, team and person. Provisioning is an operator-approved
41 operation, not an agent tool.
422. Submission restricted to that mailbox, to one verified recipient, with immutable
43 content and a client idempotency key. Reusing the key with different content
44 must conflict. Supply retention guarantees, provider message ID, RFC Message-ID,
45 correlation headers, structured temporary/permanent errors, Retry-After and
46 a lookup-by-key operation for ambiguous submission outcomes.
473. Authenticated inbound and delivery events with stable IDs, mailbox and message
48 IDs, signed timestamp, key rotation, replay window, retry/ack semantics and
49 reconciliation cursor. Specify signature coverage of raw bytes and envelope,
50 not just user-controlled headers. Events include accepted, delivered, deferred,
51 permanent bounce and complaint. Acceptance must not be labelled delivery.
524. An explicit sender-verification assertion binding a Keymail authenticated
53 subject to its currently verified address, audience, message and mailbox.
54 Signing a webhook or reporting SPF/DKIM/DMARC does not by itself bind an
55 arbitrary From address to an Equipo person. If this assertion is unavailable
56 for external senders, hold their messages for confirmation in an authenticated
57 Equipo session before importing them. Do not treat a reply token as identity.
585. Separate least-privilege credentials for sending from one mailbox and reading
59 its events, plus rotation/revocation and quotas. No domain administration,
60 arbitrary-recipient sending or access to the person's other mail. Provide
61 bounded MIME fixtures and attachment retrieval semantics without arbitrary
62 URL fetching.
63
64**Required Keymail work is conditional:** if these facilities exist, provide
65documentation and sandbox access; otherwise implement only the missing agreed
66capabilities. There is no evidence here to claim a particular backend change is
67necessary, or to estimate one as completed.
68
69## Equipo ownership and conversation handoff
70
71The new `internal/coordinatormail` package is an isolated, pure policy prototype.
72It refuses unconfigured/unapproved outbound, unverified or third-party recipients,
73opt-outs, suppressed recipients, undisclosed identity, mismatched reply scopes and
74unverified/automatic replies. Its inputs are trusted server-resolved facts, not
75JSON request fields. It is **not** a verifier, persistence layer or runtime guard
76until a reviewed adapter integrates it. Tests exercise those refusal boundaries.
77
78Leave ongoing conversation-thread work in `internal/equipo/conversation` alone.
79Its `EnsureThread` already joins task creation's transaction and `RouteMessage`
80has requester and mutation checks. Do not introduce another task/thread store or
81call RouteMessage from email. Agree this interface with that work's owner before
82wiring it:
83
84- Resolve a stored opaque reply-route hash to mailbox, team, person, verified
85 address, coordinator, project, task and existing conversation/thread ID. Bind
86 the original outbound Message-ID too. References/In-Reply-To must match that
87 stored route; subject text never selects a task. Ambiguity, expired routes,
88 deleted tasks and lost access go to quarantine, never automatic task creation.
89- Append an **untrusted external discussion** entry to that thread, atomically
90 with the inbound event receipt, using a deterministic mutation ID. The thread
91 owner must supply a non-executing append boundary; do not assume SendMessage
92 is non-executing. Until agreed, no inbound adapter is enabled.
93- Retain source provenance and provider/event IDs. From, quoted/forwarded text,
94 attachments and model interpretations never grant authority. Even a verified
95 sender does not approve spending, permissions, execution, deployment or other
96 sensitive actions by email. Existing authenticated approval gates remain.
97
98## Durable delivery design required before enabling
99
100Use Equipo's SQL store, not an in-memory queue. Keep a separate mail delivery
101ledger from device notification acknowledgments. Existing integration points are
102`internal/equipo/notifications/outbox.go`, its person-scoped Event model and
103migration `0031_notifications.sql`. Do not alter their device cursor semantics.
104
105In a transaction with selection of an eligible source event, insert:
106
107- delivery ID; unique `(team, person, source_event, channel)`; immutable scope,
108 content hash, preference revision and sender identity; provider idempotency key;
109- state, attempt count, next-attempt time, lease owner/expiry, provider IDs,
110 timestamps and sanitized error code;
111- an append-only audit entry containing actor, decision, scope and correlation ID,
112 never tokens, raw MIME or message bodies.
113
114States: queued -> submitting -> accepted -> delivered. Temporary failures become
115retry_wait; permanent failures become failed; bounces become bounced; complaints
116or opt-out become suppressed. Unknown submission outcome becomes uncertain, not
117a fresh send. Lease claims use compare-and-swap and fencing. After a crash, query
118by the **same** key before resubmitting identical content. If upstream cannot
119resolve uncertainty or its idempotency retention has expired, stop for operator
120reconciliation, never retry with a new key. Exactly-once mail cannot be promised
121without upstream guarantees.
122
123Proposed initial limits: five submission attempts total within 24 hours, delays
124of 1 minute, 5 minutes, 30 minutes and 2 hours plus bounded jitter. Honor a longer
125Retry-After only within the deadline, otherwise stop. Every provider attempt must
126be recorded before I/O. Recheck verified address, membership, recipient consent,
127mailbox authorization and suppression before each attempt. Address changes cancel
128old queued mail rather than rewriting its recipient under the same key.
129
130Deduplicate status events and inbound receipts with unique
131`(provider, mailbox_id, event_id)` constraints, plus a mailbox-scoped stable
132provider message ID for repeated inbound events. Persist receipt, audit and
133thread append atomically before acknowledging. Reject conflicting payload hashes
134for the same ID. Apply status changes monotonically: a late accepted/delivered
135event must not erase a bounce or complaint. Persist hard-bounce/complaint
136suppression before scheduling further mail; soft bounces consume the bounded
137retry budget. Re-enablement requires authenticated confirmation.
138
139Default preference is off. Authenticated person settings explicitly opt in per
140coordinator/project and notification category, support quiet hours and frequency
141caps, and can disable all email. Device subscriptions are not email consent.
142Include a clear sender, project/task context, why the mail was sent and an
143authenticated preference link. Never send to addresses supplied in prompts,
144headers, forwarded messages, Cc or Bcc. This initial slice covers existing task
145threads only.
146
147## Inbound containment and loops
148
149Do not reply automatically to inbound mail. Filter coordinator-originated mail,
150delivery reports, Auto-Submitted messages and bulk/list traffic. Suppress email
151notifications for the imported message's source event, and do not allow that
152event to trigger an automatic coordinator email response. Rate-limit by mailbox
153and bound pending/quarantine storage. Bounce handling uses authenticated provider
154events, not text that claims to be a bounce.
155
156Initially quarantine attachments, do not feed them to tools or models. Bound raw
157MIME to 10 MiB, decoded aggregate to 10 MiB, part count to 20 and nesting to 5;
158reject over-limit messages before expansion. Do not unpack archives, execute
159files, load remote images or follow attachment URLs. Render plain text safely;
160keep quoted/forwarded content labelled as untrusted context. A later explicit
161attachment import must use `internal/attach` byte sniffing, filename cleanup,
162image metadata stripping and limits, with private storage, access checks and
163authenticated downloads. Malware scanning and retention/deletion policies must
164be agreed before enabling attachment import. Logs must omit mail bodies and
165credentials; raw quarantined mail requires restricted access and bounded retention.
166
167## Release acceptance, beyond the offline policy tests
168
169Before opt-in is offered, run sandbox contract tests for:
170
171- Restart after provider acceptance but before local commit; concurrent workers;
172 expired leases; repeated source events; key/content conflicts; uncertainty
173 without lookup. Each produces at most one provider submission identity.
174- Duplicate/reordered webhook events, lost acknowledgments, replayed/invalid
175 signatures, rotation, forged From and valid DKIM without subject binding.
176- Cross-person/team/project/task routes, stolen reply token, subject spoofing,
177 revoked membership, changed address and ambiguous References. No new task.
178- Atomic thread append/receipt rollback; retries append once and never execute
179 instructions. Approval-required actions still require the existing UI flow.
180- Opt-out racing dispatch, hard/soft bounces, complaints, retry exhaustion,
181 rate limits, self loops and automatic replies.
182- Oversized/nested MIME, malicious HTML, archives, remote URLs and quoted
183 instructions. No authority or automatic tool access from any content.
184
185This change implements only offline policy tests. Persistence, webhook verification,
186preference UI, conversation handoff and all above end-to-end tests remain release
187blockers. No real sending, provisioning, paid service or broader permission was used.
188