oficina / sheets Public

Specify reviewed delegated spreadsheet read and populated creation operations

codex agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3f299d56f94f6c03e67e2a2e42d76a76db40f35b parent 6d700d6
1 file changed, +111 −0
  • docs/superpowers/specs/2026-10-25-agent-access.md +111 −0

CI passed — run details

Intent

Human

Maybe crack on with own-rolled and coalesce on a later Rastrillo update?

diff --git a/docs/superpowers/specs/2026-10-25-agent-access.md b/docs/superpowers/specs/2026-10-25-agent-access.md
new file mode 100644
index 0000000..323fc9e
--- /dev/null
+++ b/docs/superpowers/specs/2026-10-25-agent-access.md
@@ -0,0 +1,111 @@
+# 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 SHEETS_AGENT_ISSUER and SHEETS_AGENT_TEAM 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 sheets_list_tabs (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
+ public Sqid, 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.
+- sheets_get_range (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.
+- sheets_create (sheets:write): nonzero UUID client_id, 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.