oficina / docs Public

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

Plain git — no account needed to clone.

Download

Download this file

1# Delegated document operations
2
3Status: approved for implementation planning by GPT-6 Astra after independent
4review against baseline 5a4f6de. Source review, full CI and deployed verification
5remain separate gates. Paul
6requested one Oficina browser grant across apps, authorized a temporary Oficina
7transport pending Rastrillo, and selected CLI, Paseo, ChatGPT and Claude clients.
8
9## Boundary
10
11Opt in with DOCS_AGENT_ISSUER and DOCS_AGENT_TEAM, requiring configured Home.
12Refuse partial configuration before storage. Mount bearer-only operation routes
13outside browser sessions and CSRF, without changing native or browser routes.
14Verify each credential online for this exact app origin plus /api/v1. The
15credential introspection must include `identity_issuer`, supplied from the
16connection runtime's fixed HomeIssuer configuration. Require an exact match with
17Docs' configured Home issuer before any identity lookup. The connection service
18issuer is a different origin and must not be substituted. In team mode also
19require DOCS_AGENT_TEAM to equal the configured team binding. The opaque Home
20subject resolves through the existing local link/principal path;
21never EnsurePerson, EnsureHome, address matching, or synthetic browser cookies.
22Recheck current admission, configured team, scope and document permission on
23execution. Team-mode epoch/response guards remain part of the authorization
24path, including a final check before returning content. A Docs-local HTTP
25adapter establishes requestAccess, dispatches through the shared Registry.Call,
26serializes a bounded response, registers every returned document and required
27permission in responseDocs, and emits through writeGuardedBody on the actual
28response writer. It preserves lease deadlines and transfer-abort behavior;
29shared Registry.HTTP's direct JSON writer is not used for content responses.
30
31The first operations are docs_list and docs_get (docs:read), and docs_create
32(docs:write). List returns public Sqid identifiers, title, URL and updated_at, with default
3320/maximum 100 items ordered by (updated_at DESC, id DESC). An opaque base64url
34cursor contains the last returned timestamp and exact decimal database ID; both
35are validated and bound to that ordering. Apply current ListFor permission SQL
36before pagination. It is a current view, not a snapshot across requests.
37
38Create returns a bounded summary (public Sqid, title, URL, updated_at) and
39body_revision; it does not echo the initial body. This keeps the maximum valid
40input retryable even when JSON escaping expands content. Get returns public Sqid, title, URL, body_revision (decimal string), plain text
41and ProseMirror JSON from a single replay handle. body_revision is that replay's
42sequence; it versions body updates, not title renames. Never separately query
43currentSeq to label an earlier replay. The maximum encoded operation result is
441 MiB (inside the shared transport's 2 MiB limit); oversize fails explicitly with
45no truncation. A replay sequence remains coherent even if the browser updates
46the document before emission. Item refusals retain Docs' 404 policy. A read
47failure never becomes empty content.
48
49## Creation and content
50
51Create accepts a title, nonzero UUID client_id and a bounded list of plain
52paragraph/heading blocks (at most 200 blocks, 128 KiB text total; heading levels
531 through 6). Text is literal text, not HTML, Markdown or executable content.
54This is an initial content contract, not a claim that arbitrary document editing
55or Markdown import exists. No tool asks an agent to construct CRDT bytes.
56
57Add a small core primitive to produce initial ProseMirror XML fragment content
58from these validated blocks using the pinned yrs implementation. Preserve the
59root name and native editor schema. Supply GUID/client IDs from Go, never yrs
60entropy. A new wasm export requires an ABI version bump and regenerated wasm;
61test the resulting update with the existing JavaScript/Yjs wire gate and the
62real document renderer. Parse and validate the whole payload before mutation;
63refuse malformed UTF-8, invalid blocks and oversized output without a partial
64core mutation. Do not add a second CRDT encoder in Go or invoke node at runtime.
65
66Creation shares the existing document creation/store machinery. Metadata,
67initial update, attribution and receipt commit together after taking the SQLite
68writer reservation. Recheck current create authority inside the write and before
69returning a success. Outside team mode, creation requires the configured member
70allowlist; admission through an explicit document grant alone does not suffice.
71In team mode use current member authority from the existing roster lease. Use the existing content-sealing path and row AAD. Agent
72writes require activated sealed-content storage; legacy mode refuses them with
73an explicit unavailable failure. Enabling the adapter does not convert, scrub
74or change the database's content encoding state.
75
76Receipt coordinates bind identity issuer, delegation issuer, Home subject,
77OAuth client, selected team and UUID
78with a purpose-separated keyed digest derived from the stable Home integration
79key. Fingerprint the complete validated title and ordered block payload using a
80separate domain-separated HMAC over a canonical JSON encoding of a fixed typed
81struct (title plus ordered blocks, with explicit type/text/heading level).
82Neither coordinate nor payload fingerprint is an unkeyed hash. Persist a
83purpose-separated HMAC keycheck over a fixed public marker and the configured
84identity issuer, delegation issuer and team in adapter state
85on first enablement, under the SQLite writer reservation. On each startup and
86agent write, compare the derived keycheck before any receipt lookup; key or
87authority configuration mismatch
88refuses agent writes until an explicit operator-led migration. Never silently
89reset or replace that state.
90Only digests and document ID enter the receipt table. Changed retries conflict;
91identical retries recheck current access and return the existing document. A
92trashed/deleted document is never recreated by replay. Initial content is never
93reapplied on retry, including after a person edits it in the browser. Retain
94receipts across process restarts; key changes cannot be presented as safe retries.
95
96Document titles remain plaintext metadata under the existing content-sealing
97spec; this adapter does not change that explicit exception. Bodies stay sealed
98in updates/snapshots, and never enter logs, central grant storage or receipts.
99Attribution records the verified operator and an identifiable delegated client
100without turning the client into an app person or locally minted agent token.
101
102## Initial exclusions and convergence
103
104No append/replace operation until its revision/precondition and collaborative
105update behavior has its own reviewed implementation. Sharing, deletion,
106comments, export files and invitations are separate capability work. Existing
107browser/native editing and history remain authoritative. The shared Oficina
108registry exports the same schemas for HTTP, CLI and MCP; the app owns domain
109checks and content handling when the transport later moves to Rastrillo.
110
111## Required evidence
112
113Use a real linked Home identity and real SQLite/core: browser-created documents
114remain readable through current grants; unlinked, revoked delegation or lost applicable authority, wrong-team,
115wrong-scope and foreign-document requests refuse without provisioning anything.
116Explicit document grants can preserve access independently of ownership
117membership, exactly as the current app permits. Test identity-issuer mismatch
118before local lookup, team binding mismatch, revocation after invocation and
119during emission, coherent replay sequence under concurrent browser updates,
120malformed cursors and oversized reads. Test restart, changed receipt key and changed identity/delegation namespaces,
121create, concurrent retries, changed payload, deleted replay, retry after a
122browser edit, rollback on initial-update/receipt failure, and explicit legacy
123storage refusal. Confirm body canaries are absent from database, WAL, receipts
124and logs. Exercise core bounds, Unicode, literal HTML-like text, Yjs wire parity
125and existing renderer/export output. Run actual app operations through the
126shared gateway/API/MCP fixture. Every new gate must fail under a material
127mutation for the intended reason. Full repository CI and highest-capability
128whole-branch review remain separate from spec approval and deployment.
129
130## Initial-content core review (2026-10-25)
131
132GPT-6 Astra reviewed and approved the first core slice after its finding about
133JavaScript-unsafe client IDs was fixed: newly allocated IDs are nonzero uint32,
134and the initializer refuses larger IDs. This approval covers the content
135initializer, ABI 5 and wire fixture, not the pending app adapter or whole branch.
136Native Rust and Go/Wasm tests, real Yjs/ProseMirror parity and canonical Docker
137Wasm generation passed. Seven material mutations failed their intended gates:
138heading bounds, block count, total bytes, reinitialization, unsafe client ID,
139unsafe document allocation and discarded initial update. Full local CI reached
140the existing release-launch test and hit macOS's temporary socket path limit;
141rerun with TMPDIR=/tmp. Full CI and whole-branch review remain required.
142
143## Adapter review progress (2026-10-25)
144
145GPT-6 Astra's early source review found five issues, now corrected and covered:
146reverify delegation after reserving the writer and before commit; export common
147contracts across teams and enforce the target team at invocation; reject lossy
148raw JSON Unicode; return a bounded create summary; preserve recoverable client
149attribution sealed separately from digest-only receipts. The revised source
150review found no further blocker. This is not final whole-branch approval.
151
152Actual linked identity, sealed SQLite/core, concurrent retries, browser-edit
153retry, deletion, transactional failure/unlink/revocation, authority-key restart,
154foreign-document filtering, exact pagination, team-epoch refusal/partial abort,
155and independent explicit grants pass focused tests. A real HTTPS grant service,
156shared CLI/gateway and official MCP client create/read/retry Docs and revoke an
157already-open MCP connection through CLI logout. Twelve effective mutations fail
158the intended gates. A first legacy-storage mutation survived because the test
159was still using an activated database; a genuine legacy fixture corrected the
160test, and the same mutation now fails. Full CI and deployed verification remain
161separate gates.
162
163## October 30 compatibility amendment
164
165Plan independently approved by GPT-6 Astra against main 7d218bd; final source
166and deployed review remain separate gates. Main replaces Docs' private Home
167links with shared `home/connect` adoption and moves standing into `teammode`.
168Preserve its boot migration, identity namespaces, ordinary browser Home-only
169resolution, historical schema ledgers and core rendering changes.
170
171The first agent adapter is existing-linked-account-only. Every admission,
172response check and transaction check uses the shared complete keyed binding;
173inside a writer it uses `Bridge.ResolveOn` on that writer, with no HomeOnly hook
174or second SQL connection. Captured actor/address must remain identical. Shared
175identity resolution never substitutes for current app admission or standing.
176Use one request's latched `teammode.Access`, carried with `withAccess`, including
177inside writes. Completed retries repeat final delegation/identity/admission
178checks before the transaction returns. Unknown standing refuses `docs_list`
179with 503, including nonempty shares and lease loss during emission, because the
180schema has no partial-result notice; explicit-share document reads remain valid.
181Non-team empty lists and discovery do not require roster standing.
182
183Regenerate canonical Wasm from combined source, retaining ABI 5 initialization.
184Tests cover real legacy adoption/reopen/retries, ownership and grants, Home-only
185refusal without allocation, keyed-binding corruption/rollback/emission,
186completed-retry final authority, Unknown lists versus exact shares, and the
187existing HTTPS CLI/MCP fixture. Do not erase receipt markers or retry state.
188