oficina / sheets Public

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

Plain git — no account needed to clone.

Download

Download this file

Delegated spreadsheet operations

Status: approved by GPT-6 Astra after independent design review against baseline 6d700d6. Source review, tests, CI and deployed verification remain separate gates. Paul requested suite-wide API, CLI and MCP access after browser permission, authorized a transport owned by Oficina until Rastrillo converges, and selected CLI, Paseo, ChatGPT and Claude as the first clients.

Authority and transport

Opt in with SHEETSAGENTISSUER and SHEETSAGENTTEAM alongside Home. Validate complete configuration before storage. An online verifier checks a short-lived app-audience credential for this exact origin plus /api/v1. Introspection's identity_issuer must exactly match configured Home.Issuer before resolving its opaque subject through the existing connection bridge to an existing member. No EnsureMember, address matching, synthetic browser cookie or local agent key. Recheck current admission and sheet grants for every operation. Grant admission alone never grants create authority. Existing explicit-grant/team-role semantics remain authoritative; preserve roleFor precedence in new error-returning authority and tab-ownership helpers, and use grant-scoped queries, never scope.Owned. The existing boolean helpers erase storage errors and cannot satisfy the unavailable contract. Revoked delegation, unlinked identities and lost applicable permission refuse.

The shared Oficina registry defines identical HTTP, CLI and MCP contracts. Bearer routes are separate from browser CSRF/session routes. Sanitized errors contain no values, formulas, sheet titles or tab names. Unknown or inaccessible items both return 404; infrastructure failure returns unavailable, not empty results. Request bodies are at most 1 MiB; every encoded result is at most 1 MiB, with an explicit oversize failure and no partial success. Metadata enumeration is bounded before decryption/materialization: list returns sheet metadata only; tab discovery is a separate bounded sheetslisttabs (sheets:read) operation (default 20, maximum 100, ascending exact ID cursor) on one currently readable sheet.

First operations

  • sheets_list (sheets:read): live/non-filling permitted sheets, default 20 and maximum 100 per page, descending numeric ID cursor decoded exactly. Return canonical decimal ID strings, title and URL. Decode sealed titles/names through store helpers and fail if opening fails. A grant join filters before pagination; guests see only explicitly granted sheets.
  • sheetsgetrange (sheets:read): one tab, integer start row/column and height/ width, at most 500 cells. Return coordinates, raw input, calculated display value/error, and the tab revision as a decimal string. Read from a single current handle while its mutex is held so values and revision are coherent. A content-bearing result larger than 1 MiB fails explicitly without truncation.
  • sheetscreate (sheets:write): nonzero UUID clientid, title, first tab name, and up to 500 unique cell coordinates/raw inputs, within existing row/column, raw-input, total-cell and calculation limits. Accept the same formulas and value rules as the browser. The response contains the sheet/tab identifiers, member URL, and a current coherent snapshot revision. This is Handle.Version's next-stamp watermark, matching range reads, not SetBatch.Report.Version's last assigned stamp; a retry after a browser edit returns the current watermark. It sends no invitation.

This initial creation path supports a populated budget or table directly. Editing existing sheets, formatting, extra tabs, comments, sharing and import/ export are later capability slices. Editing will require a reviewed revision precondition and guarded SetBatch transaction, rather than optimistic read then unconditional write. These omissions remain visible in the capability matrix.

Atomic creation and retries

Refactor the existing newSheet creation service only as needed to reuse its sealed title/tab name and owner grant invariants inside an outer transaction. A receipt insertion first takes SQLite's writer reservation. Recheck the existing local operator and current create membership inside that transaction. Create metadata, first tab, owner grant, cells through the existing parser/ calculation/store machinery, attribution and receipt in that same transaction. Add an unregistered transaction-local handle constructor: store.Open currently registers a handle and must not be used with tx. Discard this transaction handle on both success and failure; it retains tx and must never be cached even after commit. If needed, open a fresh canonical app-DB handle after commit. A rollback must not leave in-memory phantom cells. Reuse SetBatch's parser, calculator, shape limits and version assignment. All raw values, calculated strings, titles and tab names remain sealed on disk.

Receipt coordinates use a purpose-separated HMAC over an unambiguous encoding of identity_issuer, delegation issuer, Home subject, OAuth client, selected team and UUID. Attribution uses the same authority namespace. Payload fingerprint uses a separate HMAC over canonical typed title/tab/cells, sorted by coordinate so cell ordering alone does not change meaning. Only digests and sheet ID enter receipts. Persist a keyed marker at first enablement and verify on startup and before each agent write; the marker also binds identity issuer, delegation issuer and configured team. A changed key or authority configuration refuses writes until explicit operator migration. Never reset the marker to make old retries appear new.

Identical retries recheck current authority and return the existing sheet; changed input conflicts. A deleted sheet is never recreated. A retry after a browser cell edit returns the existing sheet without applying initial values again. Client/operator attribution identifies the existing member and sealed client label, and does not mint a local agent/person. Commit precedes any cache insertion or publish notification. New sheet creation needs no preexisting subscriber content broadcast.

Evidence and release

Test linked Home identity, identity-issuer mismatch before local lookup, current team and sheet role enforcement, an authorized sheet paired with a foreign tab, authority storage failures, explicit guest grants, no provisioning, cookie-only refusal, lost authority, expired/revoked credentials, exact cursors, read bounds and coherent revision. Real SQLite and calculation fixtures cover Unicode, formulas, dependent values, concurrent retry, changed payload, deleted replay, browser edits before retry, restarted process, changed receipt key, and equal subject/client/team/UUID under a changed issuer namespace (refused without migration). Inject failure after cells and grant creation to prove the whole transaction rolls back and no cached handle survives. Inspect database/WAL/receipt/log bytes for title, tab-name, raw-value and calculated-string canaries. Exercise actual operations through the suite HTTP/MCP gateway. New gates must fail against material adverse mutations. Run complete CI, highest-capability branch review, and deployed canary verification before merge. Source/spec approval does not claim deployment.

Store foundation review (2026-10-25)

GPT-6 Astra approved the first store slice after two calculation-completeness findings were fixed. ReadRange holds one handle lock for raw/calculated values and revision, refuses a tab with durable dirty markers, and refuses nonempty inputs with missing caches. Capped browser recalculation and unrecoverable corrupt cache states therefore produce explicit failure rather than old or empty values at a new revision. InitializeTab never registers its transaction handle and shares the caller's atomic commit/rollback. Focused race tests passed. Five effective mutations failed: cache transaction handle, remove range lock, remove initial-tab emptiness guard, ignore dirty markers, ignore missing cache. This is store-slice approval; app adapter, full CI, whole-branch review and deployed canary remain required.

Identifier and write-boundary amendment (2026-10-25)

GPT-6 Astra approved correction of the original Sqid wording: this baseline's browser routes use decimal sheet/tab IDs. Expose IDs and cursors as JSON strings containing canonical positive decimals up to 9223372036854775807. Reject signs, leading zeroes, whitespace and overflow; omit the cursor for the first page. Do not introduce a second ID scheme.

Contracts must be identical across teams; enforce the selected target team at invocation. Reject malformed Unicode before lossy decoding. Reverify delegation at the reserved writer boundary and before commit, preserving subject, client, grant, team and scope; failure rolls back creation. Keep those network checks separate from transaction-local identity queries. Validate the bounded create result before commit, and preserve recoverable client attribution sealed outside the digest-only receipt. These amendments are approved design, not source approval for the forthcoming app adapter.

Home roster compatibility (2026-10-30)

In provisioned team mode the roster replaces stored team_role and the local allowlist as standing. Agent configuration must match the verified roster team. Resolve only an existing Home link, without the browser's Home-only fallback. Capture one Access for the verified Home subject and retain it through registry checks, the writer transaction, completed retries and every response chunk; Unknown is latched and never refreshed within a request. Creation requires Member. Read permissions retain explicit-grant precedence, including refusal of unknown roles: a creator's self-grant needs membership, an independent share survives removal. Filter these grants before pagination. Unknown full lists return unavailable even when independent shares remain; an exact shared item can still be read. Socket deadlines cannot exceed the captured membership lease or a shorter caller deadline. Non-team behavior is unchanged. GPT-6 Astra reviewed this compatibility plan; final source/evidence review is separate.