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