| 1 | # Oficina agent access |
| 2 | |
| 3 | One operation contract for Oficina HTTP APIs, the `oficina` CLI, and MCP. |
| 4 | The transport and credential interfaces are independent of the app operations |
| 5 | so they can be replaced by Rastrillo implementations later. |
| 6 | |
| 7 | Status: implementation in progress. Shared operations, HTTP/MCP adapters, the |
| 8 | CLI, browser consent with PKCE, rotating refresh tokens and revocation are |
| 9 | implemented. Tests exercise browser authorization through an HTTPS fixture, |
| 10 | including real loopback callbacks and the signed Home identity handoff. A runnable |
| 11 | connection service and reviewed adapters for Docs, Sheets, Memoria, Calendar, |
| 12 | Calls and Slides are on feature branches, exposing 27 app operations plus the |
| 13 | shared `calls_schedule` workflow (28 total). Live four-client |
| 14 | acceptance and deployment remain outstanding. No production endpoint is deployed. |
| 15 | |
| 16 | Each request supplies a verified person, client, grant, selected teams and |
| 17 | scopes. The registry rejects unauthorized team/scope combinations before calling |
| 18 | an app, validates inputs and outputs, and returns bounded JSON. The app remains |
| 19 | responsible for current local admission, resource access, data storage and edit |
| 20 | semantics. MCP uses the official Go SDK, with stateless requests to avoid retaining |
| 21 | one person's authorization in another request. |
| 22 | |
| 23 | Run `make ci` for formatting, vet, and tests. Integration tests drive the same |
| 24 | operation through HTTP and MCP and verify that grant revocation prevents writes |
| 25 | through an already connected MCP client. |
| 26 | |
| 27 | [Rastrillo coordination](https://amadan.net/rastrillo/rastrillo/-/discussion/116). |
| 28 | The JSON API framework landed at Rastrillo `2e833dd`; its MCP and OAuth packages |
| 29 | are separate ongoing work. This module will not wait on them, per Paul's |
| 30 | 2026-10-24 direction. |
| 31 | |
| 32 | The `grant` package is mounted by the connection service with verified browser |
| 33 | identity and current-team callbacks. The issuer and consent UI run separately |
| 34 | from Home's credential origin. App tokens are restricted to one audience, team |
| 35 | and scope set; `RemoteVerifier` checks them online before the app resolves the |
| 36 | Home subject to an existing local account. Revoking the parent grant also |
| 37 | invalidates every downstream token. |
| 38 | |
| 39 | `oficina auth login --server https://…` opens the system browser and stores the |
| 40 | connection in the OS credential store. `oficina tools` lists operations; |
| 41 | `oficina notes create --team acme --input note.json` calls one. `oficina mcp serve` |
| 42 | provides a local stdio adapter backed by the same API. The server must have this |
| 43 | integration mounted; these commands do not work against the current production |
| 44 | apps yet. `oficina auth logout` revokes the server-side connection and then removes local |
| 45 | credentials. If revocation fails it keeps the credential so you can retry. |
| 46 | `oficina teams list` and MCP `oficina_connection` discover currently permitted |
| 47 | team IDs; ordinary commands never open a browser implicitly. |
| 48 | |
| 49 | |
| 50 | ## Running the connection service |
| 51 | |
| 52 | For local development, build `go build ./cmd/oficina-connect` and `go build ./cmd/oficina`. |
| 53 | `oficina-connect -config connection.json -db /persistent/connect.db` listens on |
| 54 | 127.0.0.1:8080 behind an HTTPS reverse proxy preserving the public Host. Configure |
| 55 | an independent origin such as `https://connect.example.test`; this is separate |
| 56 | from both Home's credential and directory origins. Forwarding headers never |
| 57 | choose a trusted host or issuer. The service exposes `/mcp`, `/api/v1/operations`, |
| 58 | `/api/v1/connection`, OAuth metadata, and `/connections` for browser revocation. |
| 59 | |
| 60 | Configuration fields are `origin`, `home_issuer`, `consumer_id`, `home_keys` |
| 61 | (a key-ID to base64 Home signing-public-key map), `directory`, `clients`, and |
| 62 | `routes`. A route binds `team`, `resource` (the app HTTPS origin plus `/api/v1`), |
| 63 | and `operations` (the app's exported operation descriptors). Routes are operator |
| 64 | configuration, never tool arguments. Only current Home membership and live app |
| 65 | destinations matching those configured routes are eligible. Configure the Home |
| 66 | consumer with this origin and the `/auth/assertion` callback. Require an existing |
| 67 | admitted local app account linked to Home; the service does not provision one. |
| 68 | |
| 69 | Set `OFICINA_CONNECT_DEK` to a persistent, random 32-byte base64 encryption key |
| 70 | and `OFICINA_DIRECTORY_TOKEN` to a random service token of at least 32 bytes via |
| 71 | deployment secret configuration. Home's directory role stores only the SHA-256 |
| 72 | hex digest as `HOME_AGENT_DIRECTORY_TOKEN_SHA256`. That new Home endpoint is |
| 73 | currently on its feature branch and must be deployed before this service can |
| 74 | work. Rotation requires coordinated configuration and process restarts. Keep the |
| 75 | DEK stable across restarts; changing it invalidates pending identity/consent flows. |
| 76 | |
| 77 | `oficina-cli` is registered automatically for a random loopback callback port. |
| 78 | Remote MCP hosts must be registered in `clients`, with a unique `id`, a person- |
| 79 | readable `name`, and exact HTTPS `redirects`. There is no dynamic client |
| 80 | registration. Use authorization-code + S256 PKCE and the `/mcp` resource audience. |
| 81 | Registration and host interoperability must be verified before offering a host |
| 82 | as supported. |
| 83 | |
| 84 | Consent requires a Home authentication at most five minutes old. Connections |
| 85 | expire after 90 days; access tokens last five minutes, rotating refresh tokens |
| 86 | have a 30-day idle lifetime, and downstream app tokens last at most one minute. |
| 87 | Current membership is checked online. Reusing a consumed refresh token revokes |
| 88 | its whole connection. Cleanup retains refresh replay evidence until the parent |
| 89 | connection ends. A disconnected browser connection stops downstream tokens too. |
| 90 | |
| 91 | The service retains opaque identity, client, team, scope and grant metadata. It |
| 92 | never persists operation payloads or results. App implementations retain their |
| 93 | own content storage, permissions and retry receipts. JSON validation preserves |
| 94 | large integer IDs and decimal bounds and cannot fetch external schema references. |
| 95 | |
| 96 | ## Rastrillo convergence |
| 97 | |
| 98 | The agent on `docs-t1` confirmed explicit descriptors, shared policy checks and |
| 99 | verifier/actor interfaces as the intended integration boundary in discussion 116. |
| 100 | The Oficina `Operation`, `Verifier` and gateway contracts isolate the current |
| 101 | SDK/HTTP implementation. Memoria's handwritten operations are the first planned |
| 102 | interoperability fixture. Replacing these adapters requires parity, revocation |
| 103 | and numeric-fidelity tests; this branch does not claim upstream compatibility |
| 104 | until those tests run against the released Rastrillo implementation. |
| 105 | |
| 106 | |
| 107 | ## Initial client targets |
| 108 | |
| 109 | Paul selected all four: Oficina CLI, Paseo, ChatGPT and Claude (2026-10-25). |
| 110 | The CLI browser flow and SDK-level HTTP/MCP flow have automated TLS coverage. |
| 111 | Real hosted-client runs remain a release gate; none is claimed here as deployed. |
| 112 | |
| 113 | | Client | Initial connection | Verification still needed | |
| 114 | | --- | --- | --- | |
| 115 | | Oficina CLI | `oficina auth login --server <origin>`, OS credential store | Deployed Home/app flow with a real linked account | |
| 116 | | Paseo | Agent provider launches `oficina mcp serve` on the machine holding the CLI grant | Provider configuration, keychain availability, discovery and calls in an actual Paseo agent | |
| 117 | | ChatGPT | Remote `<origin>/mcp`, pre-registered public OAuth client | Exact redirect from its management page, browser consent, tool discovery/read/write, refresh, denial and revocation | |
| 118 | | Claude | Remote `<origin>/mcp`, own pre-registered public OAuth client | Exact redirect from its connector setup, browser consent, tool discovery/read/write, refresh, denial and revocation | |
| 119 | |
| 120 | Give each remote host its own client ID and exact redirect allowlist. The service |
| 121 | supports public-client `none` with S256 PKCE, not client secrets or client |
| 122 | assertions. Choose the host's predefined/own OAuth client option and use its |
| 123 | actual displayed callback. Do not enable automatic registration or published |
| 124 | identity/CIMD against this implementation: those paths are not implemented. |
| 125 | Remote-host support requires a public HTTPS endpoint reachable by that host. |
| 126 | A locally launched Paseo provider requires the CLI connection on that same |
| 127 | machine; credentials are not copied to another Paseo host automatically. |
| 128 | |
| 129 | ChatGPT supports predefined OAuth clients and Streamable HTTP, and requires the |
| 130 | advertised issuer to match authorization-response `iss`. This server advertises |
| 131 | and returns that value. Register the exact callback shown for the connection; |
| 132 | do not infer one from a hostname. See [OpenAI authentication](https://developers.openai.com/plugins/build/auth) |
| 133 | and [custom MCP setup](https://developers.openai.com/api/docs/guides/custom-mcp-server). |
| 134 | Claude exposes an own-OAuth-client configuration option; its remote connector |
| 135 | runs from Anthropic's cloud even on desktop. See [Claude custom connectors](https://support.claude.com/en/articles/11175166-get-started-with-custom-connectors-using-remote-mcp). |
| 136 | |
| 137 | For each host, record the tested host version/date, configured client ID (never |
| 138 | credentials), callback, consent scopes/teams, and results. Required exercises: |
| 139 | allow and deny; missing scope; wrong team; create and same-key retry; explicit |
| 140 | invitation-link permission where applicable; refresh; revoke in `/connections`; |
| 141 | then repeat a call in the already open host session and require refusal. |
| 142 | |
| 143 | Credential introspection includes `identity_issuer`, the fixed Home identity |
| 144 | namespace, distinct from the connection service issuer. Each app must supply its |
| 145 | configured Home issuer to `NewRemoteVerifier`; subjects are released only after |
| 146 | an exact match. A grant database binds that Home issuer persistently and refuses |
| 147 | a changed issuer or an unbound database already containing grants. Changing the |
| 148 | Home authority requires an explicit migration, not a configuration-only restart. |
| 149 | |
| 150 | ## Platform deployment |
| 151 | |
| 152 | `OFICINA_CONNECT_CONFIG_BASE64` selects the Rastrillo/CARLOS runtime before |
| 153 | standalone flag parsing. It contains the same strict public JSON as `-config`, |
| 154 | limited to 64 KiB decoded. Secrets remain separate. This mode accepts `serve`, |
| 155 | `-socket`, `-addr`, and `-db`; relative database paths resolve beneath |
| 156 | `STATE_DIRECTORY`. It provides framework health/version probes and graceful |
| 157 | shutdown. `-config` and `-listen` belong to standalone mode and are refused here. |
| 158 | See [the runtime contract](docs/platform-runtime.md) for limits and tests. |
| 159 | |
| 160 | Build committed release artifacts with `scripts/build-release.sh /absolute/output`. |
| 161 | The output includes Linux/arm64 service and CLI binaries, native equivalents, |
| 162 | `VERSION` (the full source SHA), and `SHA256SUMS`. Use exactly that `VERSION` as |
| 163 | `carlos deploy --version`; the service reports it from `/api/version`. |
| 164 | |
| 165 | Before publishing, run `scripts/vet-release.py /absolute/output --carlos /path/to/carlos`. |
| 166 | This uses a temporary local CARLOS store and a synthetic configuration; no upload |
| 167 | or infrastructure change occurs. It checks the native artifact through the real |
| 168 | `carlos vet --boot` contract. Repeat on Linux/arm64 with `--target linux-arm64` |
| 169 | for the deployment artifact. The generated fixture is only for boot verification, |
| 170 | never a production secret or a valid live app registration. |
| 171 | |
| 172 | |
| 173 | ## Editing and interoperability |
| 174 | |
| 175 | The [shared conventions](docs/api-conventions.md) define opaque IDs, resource |
| 176 | references, revision preconditions, immutable retry acknowledgements and stable |
| 177 | failure categories. Existing operation names and identifier types are retained. |
| 178 | |
| 179 | | App | Added operation | Supported editing | |
| 180 | | --- | --- | --- | |
| 181 | | Docs | `docs_update` | Bounded paragraph/heading splices; untouched rich content is preserved | |
| 182 | | Sheets | `sheets_set_range` | Atomic ordered cell inputs with native formula recalculation | |
| 183 | | Slides | `slides_update_deck` | Thirteen discoverable semantic operation variants | |
| 184 | | Memoria | `notes_get`, `notes_update` | Read/replace local notes with indexing; imported items remain read-only | |
| 185 | | Calendar | `calendar_update_event` | Patch single noncancelled events, preserving omitted fields and repairing reminders | |
| 186 | | Calls | `calls_reserve_schedule` | Bind a workflow UUID to a keyed request fingerprint | |
| 187 | |
| 188 | Each new edit requires the revision returned by its app's read operation and a |
| 189 | fresh UUID `client_id`. An exact retry returns its original acknowledgement; |
| 190 | a changed request with that UUID conflicts. Read again for the current content. |
| 191 | This is bounded editing support, not complete browser feature parity: Docs rich |
| 192 | formatting, Sheets tab/format management, and Calendar recurrence/cancellation |
| 193 | remain outside these new operations. |
| 194 | |
| 195 | `oficina calls schedule --team acme --input schedule.json` invokes |
| 196 | [resumable scheduling](docs/resumable-scheduling.md). It creates an optional Docs |
| 197 | agenda, a Calls meeting, and a Calendar event containing their member URLs. |
| 198 | The same operation is available through HTTP and MCP. It requires read and write |
| 199 | scopes in each selected app. No invitation is sent and a URL grants no access. |
| 200 | A partial result identifies confirmed and unconfirmed steps. Resume with the |
| 201 | same UUID and exact original JSON: a lost response may hide a committed write. |
| 202 | This is synchronous retry-based recovery, not a background job or a transaction |
| 203 | spanning apps. |
| 204 | |
| 205 | Run `python3 scripts/suite-interop.py --workspace /path/to/oficina` with sibling |
| 206 | `docs-agent-access`, `calls-agent-access` and `calendar-agent-access` worktrees. |
| 207 | It builds opt-in test binaries and uses temporary sealed app stores and private |
| 208 | HTTPS fixtures. The test exercises CLI creation, a lost committed response, |
| 209 | fresh-gateway MCP resumption, readable linked resources, exact retries, conflicting |
| 210 | retry arguments and revocation. No live account or production service is used. |
| 211 | |