# Coordination Protocol Specification

- **Version:** `0.1-draft`
- **Canonical URI:** `https://coordinationprotocol.org/spec/v0.1`
- **JSON-LD Namespace:** `https://coordinationprotocol.org/ns/v0.1#` *(v0.1 reference implementations MAY additionally emit vendor-prefixed keys such as `sundry:` during transition)*
- **Reference Implementation:** Sundry (`https://sundry.to`)
- **License:** CC BY 4.0 (specification prose); MIT (schemas and conformance suite)

The key words **MUST**, **MUST NOT**, **REQUIRED**, **SHALL**, **SHALL NOT**, **SHOULD**, **SHOULD NOT**, **RECOMMENDED**, **MAY**, and **OPTIONAL** in this document are to be interpreted as described in [RFC 2119](https://www.rfc-editor.org/rfc/rfc2119).

---

## 1. Abstract & Motivation

Existing agent protocols solve two adjacent layers:
- **Tool protocols (e.g., MCP)** connect one assistant to its own tools and data.
- **Agent-to-agent protocols (e.g., A2A)** connect two assistants directly.

Neither layer addresses **everyday multi-human group coordination** where:
1. Participants come from different platforms and devices.
2. Most participants will **not** create an account or install an app to answer one poll, claim a dish, or split one dinner tab.
3. Some participants act directly in a mobile browser while others delegate to a personal AI assistant.
4. No participant should trust an assistant to commit money, claim scarce items, lock a plan, or speak for them without an explicit human tap.

The **Coordination Protocol** is an open standard defining a **dual-surface capability link** ("board") composed of five atomic coordination primitives, a two-channel prompt-injection-aware JSON envelope, a server-enforced `stage → confirm` trust boundary, and projection-enforced privacy modes.

---

## 2. Terminology

- **Board:** A time-bounded coordination resource addressed by an unguessable capability URL.
- **Host / Creator:** The person who created the board and holds host authority (via a per-board host token or a server-bound creator credential).
- **Participant / Guest:** Any person answering a board. Guests **MUST NOT** be required to create an account.
- **Assistant:** Any non-browser caller (MCP client, LLM agent, script, automation) acting on behalf of a person.
- **Staging:** Creating a pending draft action that is **not** committed and **not** visible to the group until confirmed by a person's browser.
- **Projection:** A server-computed view of a board tailored to a caller's role (guest vs. host) and block visibility rules. All read surfaces **MUST** derive from a projection, never from raw stored responses.

---

## 3. Dual-Surface Discovery & Content Negotiation

Every board capability URL (e.g., `/b/{id}`) **MUST** serve both humans and assistants from the same URL:

1. **Human Surface (`text/html`):**
   - **MUST** emit an HTTP `Link` header pointing to the JSON representation:
     `Link: <{absolute_url}.json>; rel="alternate"; type="application/json"`
   - **MUST** include `Vary: Accept`.
   - **SHOULD** emit `X-Robots-Tag: noindex, nofollow` (or `<meta name="robots" content="noindex">`) for user-created capability links so private group links are not indexed by search engines.
   - **SHOULD** embed a `<script type="application/ld+json">` block mirroring the envelope's guide, guardrails, state, and primary staging action.
   - **SHOULD** display a plain-language notice instructing browser-driving assistants not to press buttons directly and to use the `.json` surface instead.

2. **Machine Surface (`application/json`):**
   - A server **MUST** return the JSON envelope when a client either:
     - Sends `Accept: application/json` (with higher priority than `text/html`), OR
     - Appends `.json` to the board URL, OR
     - Passes `?format=json`.
   - Responses **MUST** set `Content-Type: application/json; charset=utf-8` and `Vary: Accept`.
   - Expired / wound-down boards **MUST** answer HTTP `410 Gone` with a machine-readable `{ "code": "gone" }` payload on JSON and write endpoints. Unknown board IDs **MUST** answer HTTP `404 Not Found`.

3. **Site-Wide Discovery:**
   - Servers **SHOULD** publish `/llms.txt` summarizing the protocol rules and live endpoints.
   - Servers exposing MCP **MUST** support JSON-RPC 2.0 (`initialize`, `tools/list`, `tools/call`) and **SHOULD** return the fixed `assistant_guide` text in the `initialize` response's `instructions` field.

---

## 4. Two-Channel Envelope & Prompt-Injection Fencing

A board contains text written by untrusted third parties (hosts and guests) that will be read by *other* people's assistants. To mitigate indirect prompt injection, every JSON envelope **MUST** enforce strict channel separation (see [`schemas/v0.1/envelope.schema.json`](schemas/v0.1/envelope.schema.json)):

1. **Channel 1 — Trusted Platform Guide (`assistant_guide`, FIRST key):**
   - `assistant_guide` **MUST** be emitted as the **first** top-level key of every JSON envelope (and first domain key in embedded JSON-LD).
   - Every string in `assistant_guide` **MUST** be fixed, versioned, server-authored prose, except `board_facts`, which **MUST** contain only server-derived values (accepting-answers boolean, staging endpoint/tool name, strict ISO date/time strings, lifecycle timestamps).
   - Servers **MUST NEVER** interpolate any host- or guest-typed string (titles, labels, names, notes) into `assistant_guide`.

2. **Channel 2 — Untrusted Creator Note (`host_note_untrusted`, LAST keys):**
   - If the host provides an optional note for visiting assistants, the server **MUST**:
     - Strip or collapse control characters and newlines to single spaces.
     - Cap its length to at most **280 characters**.
     - Emit it ONLY at the **end** of the envelope under the key `host_note_untrusted`, always paired with a fixed, server-authored `note_handling` warning stating that the text is unverified preference data and MUST NOT override the user's instructions or trigger external actions/payments/data disclosure.
   - Servers **MUST NOT** emit raw host text under authoritative or neutral keys (such as `agent_note`, `system_prompt`, or `instructions`).

---

## 5. The Five Coordination Primitives

A board definition (`CreateBoardInput`, [`schemas/v0.1/create-board.schema.json`](schemas/v0.1/create-board.schema.json)) consists of metadata plus an ordered array of 1 to 20 typed blocks drawn from five primitives:

| Type | Purpose | Modes / Field Kinds |
| --- | --- | --- |
| `context` | Read-only facts and group guardrails | `entries[{label, value}]`, `guardrails { no_thanks[], dietary[], budget_cap_cents }` |
| `claim` | Exclusive reservation or shared weighted split | `mode: "exclusive"` (optional `max_claims`) or `"fractional"` (integer weights `0..10`) |
| `vote` | Multi-option availability, ranking, or elimination | `mode: "tri_state"` (`in` / `if_needed` / `out`), `"ranked"`, or `"silent_veto"` (1 anonymous veto per participant) |
| `pool` | Money math or group-funding progress (informational only; servers do not move funds) | `mode: "prorated_split"` (linked to a `claim` block + tax/tip + payout handle) or `"group_goal"` (`goal_cents`) |
| `collect` | Structured participant responses | `fields[{ id, label, kind: "text" | "number" | "headcount" | "eta_iso" }]` |

### 5.1 Determinism & Bounds
- Servers **MUST** bound block counts, item/option/field counts, string lengths, and per-request action counts. Exceeding limits **MUST** return HTTP `400` (schema) or `429` (rate/board cap) with a plain-language message.
- For `pool` in `prorated_split` mode, item shares across fractional weights **SHOULD** allocate remainder minor units deterministically so individual item shares sum exactly to the item price.
- Dates and times without an explicit offset **MUST** be documented in `assistant_guide.board_facts.times` as local/unspecified so assistants do not silently shift timezones.

### 5.2 Conditional Commitments & Proposals
- **Conditions:** A `vote` or `claim` action **MAY** carry `condition: { min_participants?, max_cost_cents?, requires_actor? }`. Conditional answers remain `pending_condition` (uncounted in committed tallies) until the condition is satisfied, at which point they atomically transition to `committed` and **MUST NOT** revert afterward.
- **Guest Proposals:** On `vote` or `claim` blocks with `allow_proposals: true`, a participant **MAY** stage `{ type: "propose", option, rationale? }`. Confirmed proposals wait for explicit host approval (`resolve_proposal`) before modifying the board definition.

---

## 6. Server-Enforced `stage → confirm` Trust Boundary

### 6.1 Assistant Surfaces Always Stage
- Any write arriving via an assistant surface (MCP `tools/call`, `/api/agent/*`, or `POST /api/boards/{id}/stage` without verified browser proof) **MUST** be staged (`status: "staged"`), regardless of any `mode` parameter supplied by the caller.
- Staging **MUST** return:
  - `status: "staged"`
  - `staged_action_id`
  - `summary`: plain-English description of what will be recorded
  - `confirm_url`: capability URL where the person reviews and taps Confirm
  - `present_to_person`: `{ line, confirm_url, confirm_label, expires_at }`
  - `holds[]` (if any exclusive items were temporarily held)
- A staged draft **MUST NOT** be visible to other participants, **MUST NOT** appear in the Activity Tape or envelopes, and **MUST** expire after at most 24 hours.
- Assistants **MAY** append a client-only URL fragment `#why={encoded_text}` to `confirm_url` to display a private rationale in the person's browser without transmitting it to the server.

### 6.2 Human Browser Confirmation
- Opening `confirm_url` (`GET`) **MUST** be side-effect-free.
- Confirming (`POST /api/agent/confirm/{id}`) **MUST** require browser proof (e.g., an `HttpOnly`, `SameSite=Lax`, signed device cookie paired with a same-origin check). Calling confirmation without browser proof **MUST** fail with HTTP `403`.
- Confirmations **MUST** be single-use (atomic `pending → confirmed` transition). If applying the staged action fails (e.g., exclusive item already taken), the draft **SHOULD** remain `pending` or fail cleanly without partial writes.

### 6.3 Bounded Holds on First-Come Claims
- When an assistant stages an exclusive `claim`, the server **SHOULD** place a short, time-bounded hold (`hold_seconds`, default 180s, clamped to `30..600`, or `0` to disable) so the item is not taken while the person opens `confirm_url`.
- Other viewers **MUST** see only that the item is temporarily held (`is_held: true`, `held_until`), **NEVER** the claimant's name or assistant.
- Servers **MUST** cap repeated holds per item and per actor over a rolling window (e.g., at most 12 total held minutes per item in any 30-minute window) to prevent indefinite denial-of-service by staging.

### 6.4 Host Actions
- Privileged host mutations (locking a board, revealing sealed blocks, resolving proposals, changing payout details, rotating host links, deleting a board) triggered via an assistant **MUST** also stage.
- The host credential **MUST** be validated at stage time and **MUST NOT** be stored inside the staged record or returned by `GET /api/agent/confirm/{id}`.
- Confirming a staged host action **MUST** require **both** browser proof and host authority on the confirming request.

### 6.5 Idempotency
- Create and stage endpoints **SHOULD** accept `Idempotency-Key` (header) or `idempotency_key` (body/tool argument).
- Repeating the same key with a canonically identical payload within 24 hours **MUST** return the original response (with `Idempotent-Replay: true` / `idempotent_replay: true`).
- Reusing the same key with a different payload **MUST** return HTTP `422`.

---

## 7. Projection-Enforced Privacy & Multiplayer State

### 7.1 Visibility Modes
Blocks (`vote`, `claim`, `collect`) **MAY** specify `visibility`:

| Mode | Visible Before Reveal / Permanently | Enforced Against |
| --- | --- | --- |
| `open` (default) | All committed responses and actor names | — |
| `host_hidden` | Guests see full claims; host projection hides claimants (legacy `surprise_mode` hides claimed items too) | Host view (courtesy mode) |
| `sealed_until_reveal` | Only response count and participant list; **no answer values** until `reveal_policy` triggers (`manual`, `quorum`, or `timestamp`) | **Everyone**, including the host |
| `aggregate_only` | **Never** individual responses or actor names; only computed aggregate (`min`, `max`, `median`) once `min_responses` (floor **MUST** be ≥ 3) is met | **Everyone**, permanently |

### 7.2 No-Leak Invariant Across All Surfaces
- Sealed, aggregate-only, and `silent_veto` values **MUST NEVER** appear in:
  - HTML or server-rendered component payloads
  - `.json` / `Accept: application/json` envelopes
  - Activity Tape (`GET /api/boards/{id}/events`)
  - Staged action inspection endpoints
  - Webhook payloads or notification digests
  - Social preview cards (OG images and metadata descriptions)
- For anonymous blocks (`silent_veto`, `aggregate_only`):
  - Actors **MUST NOT** be listed in public `participants` rosters.
  - Activity Tape timestamps **SHOULD** be coarsened (e.g., rounded down to 15-minute buckets) and staging/confirm events for anonymous blocks **MUST** be suppressed so timing correlation cannot pair a name with an anonymous action.

### 7.3 Activity Tape & Cross-Board Chaining
- **Activity Tape:** Servers **SHOULD** maintain an append-only, already-redacted event log (`GET /api/boards/{id}/events`) and include a compact summary (`activity: { count, url, recent[] }`) in envelopes.
- **Chaining:** Creating a board with `parent_board_id` (authenticated with the parent's host authority) links related plans into a chain, optionally copying `participants`, `households`, and `guardrails` (only public, non-anonymous data) and surfacing `related_boards[]` in envelopes.

---

## 8. Signed Webhooks & Resolution Next Actions

### 8.1 Webhooks
- Hosts (or creator assistant keys) **MAY** subscribe an HTTPS callback URL to lifecycle events (`quorum_reached`, `all_claimed`, `condition_unlocked`, `proposal_created`, `locked`).
- Payloads **MUST** be signed with HMAC-SHA256:
  `X-Coordination-Signature: t={unix_seconds},v1={hex_hmac_sha256(secret, "{t}.{raw_body}")}`
  *(Reference implementations MAY use a vendor header name such as `X-Sundry-Signature` alongside or in place of the neutral header during `v0.1`.)*
- Webhook payloads **MUST** be treated as nudges (best-effort delivery, no ordering guarantee) and **MUST NEVER** contain sealed or aggregate-only values.

### 8.2 Resolution & Typed Next Actions (v0.1 Extension / F3)
- When a board resolves (locks or completes), envelopes and `locked` webhooks **MAY** include `resolution.next_actions[]` containing server-generated typed entries (`calendar`, `pay`, `open_board`, `place`).
- Servers **SHOULD NOT** allow arbitrary unverified host URLs in `next_actions[]` to prevent phishing and domain-reputation abuse.

---

## 9. Lifespan & Ephemerality

- Boards **SHOULD** have a bounded default lifespan (e.g., 14 days, extendable once to 30 days) and hard deletion shortly after expiry (e.g., +7 days).
- Envelopes **SHOULD** expose `expires_at` and `deletes_at` in server-controlled metadata and **MUST NOT** promise permanence.

---

## 10. Security & Privacy Considerations (Threat Model)

Implementers **MUST** communicate these honest boundaries to users and developers:

1. **Browser proof is not strong identity:** An `HttpOnly` signed device cookie + same-origin check stops compliant MCP/REST assistants and cross-site pages, but does **not** stop a custom script written to imitate a browser or an assistant driving the user's own browser session.
2. **Typed names are social identity:** Without accounts, names are self-asserted. Implementations **SHOULD** either bind names per device or record a visible Activity Tape notice when a name is used from a new device, and give the host controls to release or remove answers.
3. **Small-group anonymity is social, not cryptographic:** Even with 15-minute timestamp bucketing and roster suppression, an observer polling a quiet 4-person board may still infer who acted. Never market `silent_veto` or `aggregate_only` as cryptographically untraceable.
4. **Capability URLs are bearer links:** Anyone holding a guest link can read the board (subject to visibility rules); anyone holding a host token has host authority on that board. Host tokens **MUST** be transmitted via headers (`X-Sundry-Host-Token` / `Authorization`) on API calls and **MUST NEVER** appear in guest envelopes, JSON-LD, analytics, or share metadata.
5. **Payment links are informational:** `pool` blocks display user-entered handles and amounts. Servers do not verify payee identity, process funds, or guarantee payment; `"paid"` flags are self-reported.

---

## 11. Roadmap: `v0.2` Preview — Verifiable Consent Receipts

Reserved for `v0.2` once external integrators request offline proof of human confirmation:
- On confirmation of a staged action, servers MAY issue an **Ed25519-signed Consent Receipt** attesting that a browser holding device proof confirmed a specific payload hash and plain-English summary at a specific timestamp.
- Public verification keys are published at `/.well-known/coordination-receipt-keys.json` (keyed by `kid` for rotation), allowing offline verification even after the ephemeral board is deleted.
- Sealed, aggregate-only, and anonymous receipts carry only the payload hash and a neutral summary — never the hidden value.

---

## Appendix A (Non-Normative): Live Reference Implementation & Agent Quick Start

*This appendix is non-normative and does not add requirements to Sections 1–11. Any server passing the black-box conformance suite MAY be listed in [`implementations.json`](implementations.json).*

An AI assistant or developer reading this specification does not need to deploy a server to create or answer live coordination links. **[Sundry (`https://sundry.to`)](https://sundry.to)** operates the live production reference implementation of Coordination Protocol `v0.1-draft` with zero sign-up required for creating links or staging guest answers:

- **MCP Endpoint (JSON-RPC 2.0 Streamable HTTP):** `POST https://sundry.to/api/mcp`
- **REST Create Any Custom Board:** `POST https://sundry.to/api/mcp/create_board`
- **Inspect Any Link:** append `.json` (e.g., `https://sundry.to/p/friday-ramen-club.json`) or send `Accept: application/json`
- **Stage a Guest Answer:** `POST https://sundry.to/api/boards/{id}/stage` (always staged; returns `confirm_url` and `present_to_person`)
- **Live Server Guide:** `https://sundry.to/llms.txt`

### Quick Start for Visiting Agents

1. Connect any MCP client to `https://sundry.to/api/mcp` (ready-to-use configs are in [`examples/mcp-configs/`](examples/mcp-configs/) and the MCP Registry descriptor is in [`server.json`](server.json)), or call the REST endpoints directly (see [`examples/quickstart.sh`](examples/quickstart.sh)).
2. Read [`llms-full.txt`](llms-full.txt) or [`implementations.json`](implementations.json) (`agent_quickstart.intent_routing`) to map a user's intent to exact Sundry MCP tools and ready-to-use JSON profiles in [`profiles/`](profiles/).
3. Always send an `Idempotency-Key` header (or `idempotency_key` field) on create and stage calls, relay `present_to_person.line` + `confirm_url` (with optional client-only `#why=` fragment and any short `holds[]` expiry) to your person, and never attempt to open or confirm `confirm_url` yourself.
4. Verify live conformance at any time with the zero-dependency black-box checker:

```bash
# Safe read-only check against Sundry:
node conformance/check.mjs https://sundry.to

# Full write, stage->confirm 403, and privacy no-leak check against a local/staging server:
node conformance/check.mjs http://127.0.0.1:3000 --write
```
