Summary #
The Owner signs in to Claude and OpenAI from Settings. Free Chats then run on a real model, with no API key (ADR-0001).
daemon/src/
├── model-access.ts # new deep module: models, sign-ins (pilot_credentials), browser sign-in flow, check every 10 min
├── providers.ts # real adapters: Claude (pi-anthropic-auth OAuth transport) and OpenAI (pi-ai openai-codex)
├── chats.ts # a new free Chat needs a signed-in subscription
└── daemon.ts # opens model access before Pi Durable, so resumed Chats have their sign-ins
app/settings.tsx # one row for each subscription: badge, Sign in / Sign in again / Sign out / Cancel, pasted code
startChat
check repo and clone
+ model = access.chatModel() // Claude if signed in, else OpenAI. Ticket 14 replaces this rule
+ if none: "Pilot cannot start the Chat: it is not signed in to Claude or OpenAI. ..."
host.startChat(model)
- pi-ai refreshes a token when a request needs it, under the credential store's lock. Pilot also checks each sign-in when it starts and every 10 minutes. A refresh that fails shows "Sign-in expired" in Settings.
- Each provider keeps only its OAuth sign-in. An API key in the environment never reaches a model.
- Pilot imports only
src/oauth-transport.tsfrom@gotgenes/pi-anthropic-auth, throughjiti. Node does not run TypeScript from node_modules.daemon/.npmrcsetslegacy-peer-deps, so the Pi coding agent is not installed.
Evidence #
- Before: Settings said "No subscription is connected." Every free Chat failed with "Pilot is not signed in to Claude or OpenAI yet."
After:
just test: Daemon 38/38, App 24/24, gallery 15/15.just lintandjust checkpass.
subscriptions.test.ts (real Daemon, fake sign-ins, scripted models, real Pi Durable)
✔ Sign in gives the page before the reply, the browser finishes it, and it survives a restart
✔ a pasted code works, a wrong code says why
✔ Cancel keeps what Pilot held
✔ an expired token is refreshed before the model call: the model gets access-2, not access-1
✔ a free Chat runs on OpenAI when only OpenAI is signed in
✔ Sign out: the Chat says to sign in again, and new Chats are refused
✔ a refresh that fails shows the sign-in as expired until the Owner signs in again
providers.test.ts (real Claude provider, fake Anthropic)
✔ an OAuth request carries Claude Code's billing header and Pilot's prompt
(it fails with pi-ai's plain anthropicProvider)
boundary.test.ts
✔ only providers.ts takes code from pi-anthropic-auth, and nothing loads the Pi coding agent
Settings.test.tsx (scripted Daemon)
✔ Sign in opens the page in the browser, then takes a pasted code
✔ a failed or expired sign-in says why. Cancel and Sign out send their commands
- By hand on the scratch Daemon:
signIngives the realhttps://claude.ai/oauth/authorize?...andhttps://auth.openai.com/oauth/authorize?...pages. Settings at 1240 and 760 pt shows the "Signing in" row with the code field and "Open the page again". - Not checked: no real sign-in was finished. Before you merge, sign in once on the dev profile and run a free Chat on each subscription.
Merge Danger #
Door: two-way
The new pilot_credentials table holds the OAuth tokens in plain text in the Daemon's SQLite file, as pi's auth.json does. A revert leaves the table there, unused.
Blast Radius: Chats
A new free Chat now needs a signed-in subscription. If pi-anthropic-auth moves src/oauth-transport.ts in a later version, the Daemon fails at start. The version is pinned to 3.6.0, and providers.test.ts catches it. deploy.sh now copies daemon/.npmrc.