# Delegated Sheets access

The Oficina connection exposes `sheets_list`, `sheets_list_tabs`,
`sheets_get_range`, `sheets_create` and `sheets_set_range`. CLI, Paseo, ChatGPT and Claude use the
same contracts. Existing Home links and current app permissions are required.

Set `SHEETS_AGENT_ISSUER` to the HTTPS connection-service origin and
`SHEETS_AGENT_TEAM` to this instance's team, alongside existing Home settings.
Both settings are required together. Credentials must target this app's exact
origin plus `/api/v1` and name the configured Home identity issuer.

Export contracts with `go run ./cmd/sheets-contract`. The bearer endpoints are
`GET /api/v1/operations` and `POST /api/v1/operations/{name}`. The connection
service obtains app credentials; browser cookies do not authenticate them.
Read operations require `sheets:read`; create requires `sheets:write` and current
team membership. Explicitly granted guests can read their permitted sheets. In roster team mode,
creation uses current Home membership; stored local roles do not grant standing.
The configured agent team must match the provisioned roster team. Full lists
return a retryable failure when roster authority is unavailable, while exact
items independently shared with the caller remain readable. This initial API
requires an existing Home-linked local account.

IDs, revisions and pagination cursors are decimal JSON strings. IDs must be
positive, canonical and at most 9223372036854775807. Omit the cursor on the first
page. Sheet listing descends by ID; tab listing ascends. Both default to 20
items and permit at most 100.

Create accepts a nonzero canonical UUID `client_id`, a title and `tab_name`
(up to 200 Unicode characters each), and `cells` containing up to 500 distinct
`row`, `column`, `raw` entries. Coordinates are zero-based: rows 0–4999 and
columns 0–599. Raw cell input is at most 8 KiB and uses the browser's formula
parser and calculator. The entire sheet, first tab, owner grant, initial cells,
sealed attribution and receipt commit together. Create returns sheet/tab IDs,
a browser URL and current revision; reuse the UUID only for an identical retry.
A retry preserves intervening browser edits and never recreates a deleted sheet.

Range reads return raw input, calculated value/type, default display text and a
coherent revision for at most 500 cells. Incomplete calculation is an explicit
failure. Inputs and encoded responses are capped at 1 MiB; oversized results
fail without truncation. Formula error values are returned as cell errors.
The revision is the store's next-stamp watermark, shared with range reads.

The receipt marker binds the Home key, Home issuer, connection issuer and team.
Changes require an explicit operator migration. Never delete the marker or
receipts to make old requests appear new. Creation does not send invitations.
Formatting, additional tabs, comments, sharing and import/export remain
separate capability slices.

See [the reviewed specification](superpowers/specs/2026-10-25-agent-access.md).
This branch does not claim deployment or live client certification.

`sheets_set_range` requires `team`, `sheet_id`, `tab_id`, `expected_revision`,
`client_id` and an ordered `cells` array of 1–500 `{row,column,raw}` entries.
Read a range first and copy its revision string into `expected_revision`.
The native batch updates exactly those cells, recalculates formulas atomically
and blanks a cell when raw is empty. Current editor permission is required;
an independent editor share works under the same roster rules as browser edits.

A stale revision returns `conflict` without changing cells. After an uncertain
response, repeat the same UUID, revision and ordered cell values. The response
contains sheet/tab IDs, URL and the original **applied** revision, even when
later edits advanced the tab. It never replays the cell writes; read again for
current values and revision. Choose a new UUID for a changed edit.
