oficina / docs Public

Specify reviewed delegated document operations and identity boundaries

codex agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3b154f2ec716901dee75d0b3102c0039604b8191 parent 5a4f6de
1 file changed, +123 −0
  • docs/superpowers/specs/2026-10-25-agent-access.md +123 −0

CI passed — run details

Intent

Human

Maybe crack on with own-rolled and coalesce on a later Rastrillo update?

diff --git a/docs/superpowers/specs/2026-10-25-agent-access.md b/docs/superpowers/specs/2026-10-25-agent-access.md
new file mode 100644
index 0000000..525a8fb
--- /dev/null
+++ b/docs/superpowers/specs/2026-10-25-agent-access.md
@@ -0,0 +1,123 @@
+# Delegated document operations
+
+Status: approved for implementation planning by GPT-6 Astra after independent
+review against baseline 5a4f6de. Source review, full CI and deployed verification
+remain separate gates. Paul
+requested one Oficina browser grant across apps, authorized a temporary Oficina
+transport pending Rastrillo, and selected CLI, Paseo, ChatGPT and Claude clients.
+
+## Boundary
+
+Opt in with DOCS_AGENT_ISSUER and DOCS_AGENT_TEAM, requiring configured Home.
+Refuse partial configuration before storage. Mount bearer-only operation routes
+outside browser sessions and CSRF, without changing native or browser routes.
+Verify each credential online for this exact app origin plus /api/v1. The
+credential introspection must include `identity_issuer`, supplied from the
+connection runtime's fixed HomeIssuer configuration. Require an exact match with
+Docs' configured Home issuer before any identity lookup. The connection service
+issuer is a different origin and must not be substituted. In team mode also
+require DOCS_AGENT_TEAM to equal the configured team binding. The opaque Home
+subject resolves through the existing local link/principal path;
+never EnsurePerson, EnsureHome, address matching, or synthetic browser cookies.
+Recheck current admission, configured team, scope and document permission on
+execution. Team-mode epoch/response guards remain part of the authorization
+path, including a final check before returning content. A Docs-local HTTP
+adapter establishes requestAccess, dispatches through the shared Registry.Call,
+serializes a bounded response, registers every returned document and required
+permission in responseDocs, and emits through writeGuardedBody on the actual
+response writer. It preserves lease deadlines and transfer-abort behavior;
+shared Registry.HTTP's direct JSON writer is not used for content responses.
+
+The first operations are docs_list and docs_get (docs:read), and docs_create
+(docs:write). List returns public Sqid identifiers, title, URL and updated_at, with default
+20/maximum 100 items ordered by (updated_at DESC, id DESC). An opaque base64url
+cursor contains the last returned timestamp and exact decimal database ID; both
+are validated and bound to that ordering. Apply current ListFor permission SQL
+before pagination. It is a current view, not a snapshot across requests.
+
+Get returns public Sqid, title, URL, body_revision (decimal string), plain text
+and ProseMirror JSON from a single replay handle. body_revision is that replay's
+sequence; it versions body updates, not title renames. Never separately query
+currentSeq to label an earlier replay. The maximum encoded operation result is
+1 MiB (inside the shared transport's 2 MiB limit); oversize fails explicitly with
+no truncation. A replay sequence remains coherent even if the browser updates
+the document before emission. Item refusals retain Docs' 404 policy. A read
+failure never becomes empty content.
+
+## Creation and content
+
+Create accepts a title, nonzero UUID client_id and a bounded list of plain
+paragraph/heading blocks (at most 200 blocks, 128 KiB text total; heading levels
+1 through 6). Text is literal text, not HTML, Markdown or executable content.
+This is an initial content contract, not a claim that arbitrary document editing
+or Markdown import exists. No tool asks an agent to construct CRDT bytes.
+
+Add a small core primitive to produce initial ProseMirror XML fragment content
+from these validated blocks using the pinned yrs implementation. Preserve the
+root name and native editor schema. Supply GUID/client IDs from Go, never yrs
+entropy. A new wasm export requires an ABI version bump and regenerated wasm;
+test the resulting update with the existing JavaScript/Yjs wire gate and the
+real document renderer. Parse and validate the whole payload before mutation;
+refuse malformed UTF-8, invalid blocks and oversized output without a partial
+core mutation. Do not add a second CRDT encoder in Go or invoke node at runtime.
+
+Creation shares the existing document creation/store machinery. Metadata,
+initial update, attribution and receipt commit together after taking the SQLite
+writer reservation. Recheck current create authority inside the write and before
+returning a success. Outside team mode, creation requires the configured member
+allowlist; admission through an explicit document grant alone does not suffice.
+In team mode use current member authority from the existing roster lease. Use the existing content-sealing path and row AAD. Agent
+writes require activated sealed-content storage; legacy mode refuses them with
+an explicit unavailable failure. Enabling the adapter does not convert, scrub
+or change the database's content encoding state.
+
+Receipt coordinates bind Home subject, OAuth client, selected team and UUID
+with a purpose-separated keyed digest derived from the stable Home integration
+key. Fingerprint the complete validated title and ordered block payload using a
+separate domain-separated HMAC over a canonical JSON encoding of a fixed typed
+struct (title plus ordered blocks, with explicit type/text/heading level).
+Neither coordinate nor payload fingerprint is an unkeyed hash. Persist a
+purpose-separated HMAC keycheck over a fixed public marker in adapter state
+on first enablement, under the SQLite writer reservation. On each startup and
+agent write, compare the derived keycheck before any receipt lookup; mismatch
+refuses agent writes until an explicit operator-led migration. Never silently
+reset or replace that state.
+Only digests and document ID enter the receipt table. Changed retries conflict;
+identical retries recheck current access and return the existing document. A
+trashed/deleted document is never recreated by replay. Initial content is never
+reapplied on retry, including after a person edits it in the browser. Retain
+receipts across process restarts; key changes cannot be presented as safe retries.
+
+Document titles remain plaintext metadata under the existing content-sealing
+spec; this adapter does not change that explicit exception. Bodies stay sealed
+in updates/snapshots, and never enter logs, central grant storage or receipts.
+Attribution records the verified operator and an identifiable delegated client
+without turning the client into an app person or locally minted agent token.
+
+## Initial exclusions and convergence
+
+No append/replace operation until its revision/precondition and collaborative
+update behavior has its own reviewed implementation. Sharing, deletion,
+comments, export files and invitations are separate capability work. Existing
+browser/native editing and history remain authoritative. The shared Oficina
+registry exports the same schemas for HTTP, CLI and MCP; the app owns domain
+checks and content handling when the transport later moves to Rastrillo.
+
+## Required evidence
+
+Use a real linked Home identity and real SQLite/core: browser-created documents
+remain readable through current grants; unlinked, revoked delegation or lost applicable authority, wrong-team,
+wrong-scope and foreign-document requests refuse without provisioning anything.
+Explicit document grants can preserve access independently of ownership
+membership, exactly as the current app permits. Test identity-issuer mismatch
+before local lookup, team binding mismatch, revocation after invocation and
+during emission, coherent replay sequence under concurrent browser updates,
+malformed cursors and oversized reads. Test restart and changed receipt key,
+create, concurrent retries, changed payload, deleted replay, retry after a
+browser edit, rollback on initial-update/receipt failure, and explicit legacy
+storage refusal. Confirm body canaries are absent from database, WAL, receipts
+and logs. Exercise core bounds, Unicode, literal HTML-like text, Yjs wire parity
+and existing renderer/export output. Run actual app operations through the
+shared gateway/API/MCP fixture. Every new gate must fail under a material
+mutation for the intended reason. Full repository CI and highest-capability
+whole-branch review remain separate from spec approval and deployment.