oficina / sheets Public

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

Plain git — no account needed to clone.

Download

Download this file

1# Delegated spreadsheet operations
2
3Status: approved by GPT-6 Astra after independent design review against
4baseline 6d700d6. Source review, tests, CI and deployed verification remain
5separate gates. Paul requested
6suite-wide API, CLI and MCP access after browser permission, authorized a
7transport owned by Oficina until Rastrillo converges, and selected CLI, Paseo,
8ChatGPT and Claude as the first clients.
9
10## Authority and transport
11
12Opt in with SHEETS_AGENT_ISSUER and SHEETS_AGENT_TEAM alongside Home. Validate
13complete configuration before storage. An online verifier checks a short-lived
14app-audience credential for this exact origin plus /api/v1. Introspection's
15identity_issuer must exactly match configured Home.Issuer before resolving its
16opaque subject through the existing connection bridge to an existing member.
17No EnsureMember, address matching, synthetic browser cookie or local agent key.
18Recheck current admission and sheet grants for every operation. Grant admission
19alone never grants create authority. Existing explicit-grant/team-role semantics
20remain authoritative; preserve roleFor precedence in new error-returning authority and tab-ownership
21helpers, and use grant-scoped queries, never scope.Owned. The existing boolean
22helpers erase storage errors and cannot satisfy the unavailable contract.
23Revoked delegation, unlinked identities and lost applicable permission refuse.
24
25The shared Oficina registry defines identical HTTP, CLI and MCP contracts.
26Bearer routes are separate from browser CSRF/session routes. Sanitized errors
27contain no values, formulas, sheet titles or tab names. Unknown or inaccessible
28items both return 404; infrastructure failure returns unavailable, not empty
29results. Request bodies are at most 1 MiB; every encoded result is at most 1 MiB, with
30an explicit oversize failure and no partial success. Metadata enumeration is
31bounded before decryption/materialization: list returns sheet metadata only;
32tab discovery is a separate bounded sheets_list_tabs (sheets:read) operation (default 20,
33maximum 100, ascending exact ID cursor) on one currently readable sheet.
34
35## First operations
36
37- sheets_list (sheets:read): live/non-filling permitted sheets, default 20 and
38 maximum 100 per page, descending numeric ID cursor decoded exactly. Return
39 canonical decimal ID strings, title and URL. Decode sealed titles/names
40 through store helpers and fail if opening fails. A grant join filters before
41 pagination; guests see only explicitly granted sheets.
42- sheets_get_range (sheets:read): one tab, integer start row/column and height/
43 width, at most 500 cells. Return coordinates, raw input, calculated display
44 value/error, and the tab revision as a decimal string. Read from a single
45 current handle while its mutex is held so values and revision are coherent.
46 A content-bearing result larger than 1 MiB fails explicitly without truncation.
47- sheets_create (sheets:write): nonzero UUID client_id, title, first tab name,
48 and up to 500 unique cell coordinates/raw inputs, within existing row/column,
49 raw-input, total-cell and calculation limits. Accept the same formulas and
50 value rules as the browser. The response contains the sheet/tab identifiers,
51 member URL, and a current coherent snapshot revision. This is Handle.Version's
52 next-stamp watermark, matching range reads, not SetBatch.Report.Version's last
53 assigned stamp; a retry after a browser edit returns the current watermark. It sends no invitation.
54
55This initial creation path supports a populated budget or table directly.
56Editing existing sheets, formatting, extra tabs, comments, sharing and import/
57export are later capability slices. Editing will require a reviewed revision
58precondition and guarded SetBatch transaction, rather than optimistic read then
59unconditional write. These omissions remain visible in the capability matrix.
60
61## Atomic creation and retries
62
63Refactor the existing newSheet creation service only as needed to reuse its
64sealed title/tab name and owner grant invariants inside an outer transaction.
65A receipt insertion first takes SQLite's writer reservation. Recheck the
66existing local operator and current create membership inside that transaction.
67Create metadata, first tab, owner grant, cells through the existing parser/
68calculation/store machinery, attribution and receipt in that same transaction.
69Add an unregistered transaction-local handle constructor: store.Open currently
70registers a handle and must not be used with tx. Discard this transaction handle
71on both success and failure; it retains tx and must never be cached even after
72commit. If needed, open a fresh canonical app-DB handle after commit. A rollback
73must not leave in-memory phantom cells.
74Reuse SetBatch's parser, calculator, shape limits and version assignment. All
75raw values, calculated strings, titles and tab names remain sealed on disk.
76
77Receipt coordinates use a purpose-separated HMAC over an unambiguous encoding
78of identity_issuer, delegation issuer, Home subject, OAuth client, selected team
79and UUID. Attribution uses the same authority namespace. Payload fingerprint uses
80a separate HMAC over canonical typed title/tab/cells, sorted by coordinate so
81cell ordering alone does not change meaning. Only digests and sheet ID enter
82receipts. Persist a keyed marker at first enablement and verify on startup and
83before each agent write; the marker also binds identity issuer, delegation
84issuer and configured team. A changed key or authority configuration refuses
85writes until explicit operator migration. Never reset the marker to make old retries appear new.
86
87Identical retries recheck current authority and return the existing sheet;
88changed input conflicts. A deleted sheet is never recreated. A retry after a
89browser cell edit returns the existing sheet without applying initial values
90again. Client/operator attribution identifies the existing member and sealed
91client label, and does not mint a local agent/person. Commit precedes any cache
92insertion or publish notification. New sheet creation needs no preexisting
93subscriber content broadcast.
94
95## Evidence and release
96
97Test linked Home identity, identity-issuer mismatch before local lookup,
98current team and sheet role enforcement, an authorized sheet paired with a
99foreign tab, authority storage failures, explicit guest grants, no provisioning,
100cookie-only refusal, lost authority, expired/revoked credentials, exact cursors,
101read bounds and coherent revision. Real SQLite and calculation fixtures cover
102Unicode, formulas, dependent values, concurrent retry, changed payload, deleted
103replay, browser edits before retry, restarted process, changed receipt key, and equal subject/client/team/UUID under a changed issuer
104namespace (refused without migration).
105Inject failure after cells and grant creation to prove the whole transaction
106rolls back and no cached handle survives. Inspect database/WAL/receipt/log bytes
107for title, tab-name, raw-value and calculated-string canaries. Exercise actual
108operations through the suite HTTP/MCP gateway. New gates must fail against
109material adverse mutations. Run complete CI, highest-capability branch review,
110and deployed canary verification before merge. Source/spec approval does not
111claim deployment.
112
113## Store foundation review (2026-10-25)
114
115GPT-6 Astra approved the first store slice after two calculation-completeness
116findings were fixed. ReadRange holds one handle lock for raw/calculated values
117and revision, refuses a tab with durable dirty markers, and refuses nonempty
118inputs with missing caches. Capped browser recalculation and unrecoverable
119corrupt cache states therefore produce explicit failure rather than old or
120empty values at a new revision. InitializeTab never registers its transaction
121handle and shares the caller's atomic commit/rollback. Focused race tests passed.
122Five effective mutations failed: cache transaction handle, remove range lock,
123remove initial-tab emptiness guard, ignore dirty markers, ignore missing cache.
124This is store-slice approval; app adapter, full CI, whole-branch review and
125deployed canary remain required.
126
127## Identifier and write-boundary amendment (2026-10-25)
128
129GPT-6 Astra approved correction of the original Sqid wording: this baseline's
130browser routes use decimal sheet/tab IDs. Expose IDs and cursors as JSON strings
131containing canonical positive decimals up to 9223372036854775807. Reject signs,
132leading zeroes, whitespace and overflow; omit the cursor for the first page.
133Do not introduce a second ID scheme.
134
135Contracts must be identical across teams; enforce the selected target team at
136invocation. Reject malformed Unicode before lossy decoding. Reverify delegation
137at the reserved writer boundary and before commit, preserving subject, client,
138grant, team and scope; failure rolls back creation. Keep those network checks
139separate from transaction-local identity queries. Validate the bounded create
140result before commit, and preserve recoverable client attribution sealed outside
141the digest-only receipt. These amendments are approved design, not source
142approval for the forthcoming app adapter.
143
144## Home roster compatibility (2026-10-30)
145
146In provisioned team mode the roster replaces stored team_role and the local
147allowlist as standing. Agent configuration must match the verified roster team.
148Resolve only an existing Home link, without the browser's Home-only fallback.
149Capture one Access for the verified Home subject and retain it through registry
150checks, the writer transaction, completed retries and every response chunk;
151Unknown is latched and never refreshed within a request. Creation requires
152Member. Read permissions retain explicit-grant precedence, including refusal of
153unknown roles: a creator's self-grant needs membership, an independent share
154survives removal. Filter these grants before pagination. Unknown full lists
155return unavailable even when independent shares remain; an exact shared item
156can still be read. Socket deadlines cannot exceed the captured membership lease
157or a shorter caller deadline. Non-team behavior is unchanged. GPT-6 Astra
158reviewed this compatibility plan; final source/evidence review is separate.
159