Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
ADR 0095: Sign in with a vendor account instead of pasting an API key
- Status: Accepted for implementation
- Date: 2026-08-18
- Related: D237, D240, ADR 0098, D028, D031, ADR 0012, ADR 0020, ADR 0027
Context
A provider row could only be authenticated by pasting an API key, encrypted under
secret:provider:<id>:api_key and read back by Electron main at launch so the
sidecar could sign with a constant { auth: { apiKey } }. Subscribers to Claude
Pro/Max, ChatGPT Plus/Pro, or GitHub Copilot therefore had to buy separate API
credit. pi-ai already ships the OAuth flows, the CredentialStore contract, and
locked refresh, but explicitly leaves login and logout orchestration to the app,
and PI-Desktop had no such half. Vendor tokens expire in about an hour and a
refresh token mints credentials on demand, so a credential resolved once at
launch was neither fresh enough nor safe enough.
Decision
- The credential is a second secret on the same provider row. OAuth
credentials are stored through the existing encrypted secret store under
secret:provider:<id>:oauth, beside — never instead of —secret:provider:<id>:api_key;has_secretwidens to "either credential",has_oauthdistinguishes them, andauth_kindgainsoauth, so neither the host protocol version nor the storage schema changes. - Login orchestration lives in Electron main, in
oauth.ts. It implementsCredentialStoreover host-core'ssecrets.*RPC, serializingmodifyper provider so pi-ai's locked-refresh assumption holds, and bridgesAuthInteractionto the renderer overpi-desktop/providers/oauth/*channels, so the renderer renders whatever the vendor asked for rather than a per-vendor script. - The vendor list is derived, not enumerated. Cards come from
models.getProviders().filter(p => p.auth.oauth), and main callsregisterBunOAuthFlows()once at startup because pi-ai loads flows through a variable dynamic import that electron-vite cannot bundle. - The sidecar resolves auth per request and never sees a refresh token. An
OAuth row's launch payload carries
apiKey: ""; the runtime injects aresolveAuthcallback answered by a new host-proxy method,provider.resolveAuth, which main answers itself against the session binding table and refuses for anything else, replying with a short-livedModelAuthcarryingapiKey,headers, andbaseUrl. - A vendor row's identity stays stable across turns.
matches()compares the provider row, whoseapiKeyis permanently"", so an OAuth session reuses its warm runtime instead of rebuilding it once an hour. - Model discovery and connection tests go through the account. For an OAuth
row,
providers.listModelsreads the signed-in account's own model endpoint withmodels.getAvailableas fallback, the connection test proves the account by resolving auth, and the row'sapiStylefollows the selected model, addingopenai_codex_responsesandpi_messages. The one-row-per-vendor assumption is amended by ADR 0098: every login now creates an independent row and credential scope.
Consequences
- A subscriber signs in from Settings → Model configuration and needs no API credit for the supported vendors.
- The privilege boundary tightens: a vendor row now gives the sidecar a revocable hour-long token for its one bound provider, and no refresh token.
- Vendor logins depend on main answering
provider.resolveAuth, so a restart mid-turn fails the request instead of signing with a stale token; API-key rows keep the same storage, payload, and resolve path.
Alternatives
- Resolve the credential once at launch and put it in the payload — rejected:
tokens expire mid-session, and refreshing would change the payload, miss
matches(), and rebuild the runtime every turn. - Give the sidecar the credential store and let pi-ai refresh in process — rejected: it hands the durable secret to the least trusted process and breaks the host-proxy allowlist.