oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

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 DOCSAGENTISSUER and DOCSAGENTTEAM, 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 DOCSAGENTTEAM 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 docslist and docsget (docs:read), and docscreate (docs:write). List returns public Sqid identifiers, title, URL and updatedat, 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.

Create returns a bounded summary (public Sqid, title, URL, updatedat) and bodyrevision; it does not echo the initial body. This keeps the maximum valid input retryable even when JSON escaping expands content. Get returns public Sqid, title, URL, bodyrevision (decimal string), plain text and ProseMirror JSON from a single replay handle. bodyrevision 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 identity issuer, delegation issuer, 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 and the configured identity issuer, delegation issuer and team 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; key or authority configuration 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, changed receipt key and changed identity/delegation namespaces, 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.

Initial-content core review (2026-10-25)

GPT-6 Astra reviewed and approved the first core slice after its finding about JavaScript-unsafe client IDs was fixed: newly allocated IDs are nonzero uint32, and the initializer refuses larger IDs. This approval covers the content initializer, ABI 5 and wire fixture, not the pending app adapter or whole branch. Native Rust and Go/Wasm tests, real Yjs/ProseMirror parity and canonical Docker Wasm generation passed. Seven material mutations failed their intended gates: heading bounds, block count, total bytes, reinitialization, unsafe client ID, unsafe document allocation and discarded initial update. Full local CI reached the existing release-launch test and hit macOS's temporary socket path limit; rerun with TMPDIR=/tmp. Full CI and whole-branch review remain required.

Adapter review progress (2026-10-25)

GPT-6 Astra's early source review found five issues, now corrected and covered: reverify delegation after reserving the writer and before commit; export common contracts across teams and enforce the target team at invocation; reject lossy raw JSON Unicode; return a bounded create summary; preserve recoverable client attribution sealed separately from digest-only receipts. The revised source review found no further blocker. This is not final whole-branch approval.

Actual linked identity, sealed SQLite/core, concurrent retries, browser-edit retry, deletion, transactional failure/unlink/revocation, authority-key restart, foreign-document filtering, exact pagination, team-epoch refusal/partial abort, and independent explicit grants pass focused tests. A real HTTPS grant service, shared CLI/gateway and official MCP client create/read/retry Docs and revoke an already-open MCP connection through CLI logout. Twelve effective mutations fail the intended gates. A first legacy-storage mutation survived because the test was still using an activated database; a genuine legacy fixture corrected the test, and the same mutation now fails. Full CI and deployed verification remain separate gates.

October 30 compatibility amendment

Plan independently approved by GPT-6 Astra against main 7d218bd; final source and deployed review remain separate gates. Main replaces Docs' private Home links with shared home/connect adoption and moves standing into teammode. Preserve its boot migration, identity namespaces, ordinary browser Home-only resolution, historical schema ledgers and core rendering changes.

The first agent adapter is existing-linked-account-only. Every admission, response check and transaction check uses the shared complete keyed binding; inside a writer it uses Bridge.ResolveOn on that writer, with no HomeOnly hook or second SQL connection. Captured actor/address must remain identical. Shared identity resolution never substitutes for current app admission or standing. Use one request's latched teammode.Access, carried with withAccess, including inside writes. Completed retries repeat final delegation/identity/admission checks before the transaction returns. Unknown standing refuses docs_list with 503, including nonempty shares and lease loss during emission, because the schema has no partial-result notice; explicit-share document reads remain valid. Non-team empty lists and discovery do not require roster standing.

Regenerate canonical Wasm from combined source, retaining ABI 5 initialization. Tests cover real legacy adoption/reopen/retries, ownership and grants, Home-only refusal without allocation, keyed-binding corruption/rollback/emission, completed-retry final authority, Unknown lists versus exact shares, and the existing HTTPS CLI/MCP fixture. Do not erase receipt markers or retry state.