feat(tui): `/logout` signs out of the provider behind the current model

Merged
SA
3d ago
+422-9

What

/logout signed out of the Altimate LLM Gateway only. Anyone signed in with ChatGPT, Claude or an API key had to leave the TUI and run altimate auth logout <provider>, and a running TUI kept showing the provider until it reloaded.

/logout now signs out of the provider behind the current model, and its title names it:

Current model's provider/logout titleWhat it does
Altimate LLM GatewayLog out of Altimate LLM GatewayExisting gateway sign-out (key file, MCP servers, skills)
Altimate BaseLog out of Altimate BaseFreeTier.logout(), as altimate auth logout altimate-free does
Saved API keyLog out of OpenAI (API key)auth.remove, then reload
Saved subscription sign-inLog out of OpenAI (ChatGPT subscription)auth.remove, then reload
Claude AgentLog out of Claude Agent (Claude Code connection)Removes the /connect marker; the Claude Code sign-in stays with claude
OpenCode free modelsOpenCode free models need no loginToast: nothing to log out of
Set by an env varOpenAI is set by OPENAI_API_KEYToast: unset it and restart
Set in config / by another tool… is set in your config / connected outside Altimate CodeToast explaining where to remove it

After confirming:

  • the provider list reloads, and the toast names the model now in use;
  • if an env key or config entry keeps the provider connected, a warning says so;
  • if nothing is left, /connect opens;
  • if the reload hasn't landed after 10 s, a warning says to run /logout again or restart.

How

  • Server: Provider.Info gains an optional auth: "api" | "oauth" | "wellknown", the saved login type. source can't carry this: a config entry or env key overrides it, and a subscription loads as custom. The SDK type is edited by hand (one line), because a full regen pulls in ~18k lines of unrelated drift that CI regenerates at release anyway.
  • TUI: packages/tui/src/util/logout-target.ts picks the target and title. app.tsx runs it. The gateway and Base sign-outs stay in the opencode-side plugin (provider-credentials.tsx), because they need AltimateApi / FreeTier.
  • Docs: new "Signing out of a provider" section in configure/providers.md.

Testing

  • Unit: packages/tui/test/util/logout-target.test.ts (15 cases, including several saved logins where only the current model's provider is picked). Three server cases in test/provider/provider.test.ts: a saved key reports auth: "api" under a config entry, a saved sign-in reports auth: "oauth", and an env-only provider has no auth.
  • bun test in packages/tui (379 pass), test/provider (887 pass), typecheck for tui and opencode, the marker guard, and markers checked by hand in app.tsx and provider.ts.
  • Mutations: picking the first saved provider instead of the current model's, and a server that reports only API keys, each fail a test.
  • E2E: the real TUI in tmux with isolated XDG_* / OPENCODE_TEST_HOME:
    • Saved OpenAI API key: title "Log out of OpenAI (API key)"; confirming empties auth.json and the toast says "Now using Tidepool Alpha Free".
    • ChatGPT OAuth login: title "Log out of OpenAI (ChatGPT subscription)"; confirming removes it.
    • Saved key plus OPENAI_API_KEY: after logout the warning reads "Removed the saved login. OpenAI is set by OPENAI_API_KEY…", and the title changes to "OpenAI is set by OPENAI_API_KEY". Running it shows the hint with no confirm dialog.
    • Gateway (fake key file): title "Log out of Altimate LLM Gateway"; confirming deletes ~/.altimate/altimate.json, shows "Signed out of Altimate LLM Gateway", and falls back to another model.
  • Review follow-ups (second commit), E2E again with isolated HOME and fake credentials:
    • Claude Agent plus a saved OpenAI key, Claude Agent current: title "Log out of Claude Agent (Claude Code connection)"; confirming removes only claude-agent from auth.json, and the toast says "Now using GPT-5.6 Terra".
    • Free model current: title "OpenCode free models need no login"; running it shows the hint and removes nothing.
    • Saved OpenAI key, saved key plus OPENAI_API_KEY, and the gateway: same results as above.
  • Not exercised E2E: the 10 s reload warning (the reload took about 8 s each time), and Altimate Base, because registering needs the live service. Its path is the same steps as the CLI's altimate auth logout altimate-free.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XM3J9koiiw5bTqfbB6xaMU


Summary by cubic

Makes /logout in the TUI sign out of the provider behind the current model. Previously it only signed out of the Altimate LLM Gateway; ChatGPT, Claude, and API-key logins had to be removed with altimate auth logout from a terminal.

  • The /logout title names the provider and sign-in type, e.g. "Log out of OpenAI (ChatGPT subscription)".
  • Providers set by an environment variable, config, or another tool show an explanation instead of a confirm dialog.
  • After logout, the provider list reloads; the toast names the model now in use, warns when an env key keeps the provider connected, and reopens /connect when nothing is left.
  • Gateway and Altimate Base keep their own opencode-side sign-outs; other saved logins go through auth.remove.
  • Provider.Info gains an optional auth field so the TUI can tell an API key from a subscription; the SDK type is edited by hand to avoid unrelated regeneration drift.
  • Docs: new "Signing out of a provider" section in configure/providers.md.

Summary by CodeRabbit

  • New Features
    • Added /logout for the provider associated with the current model. Saved credentials require confirmation, and the app reports the logout status.
    • Added logout support for Altimate Base. For externally managed connections, including Claude Agent, the app explains that they must be disconnected elsewhere.
    • After logout, the app can switch to another connected model or open the provider picker when none is available.
  • Documentation
    • Clarified that /logout removes the Altimate gateway credential only when a gateway model is selected. Documented provider logout behavior, cases where a connection cannot be removed, and terminal logout with an optional provider name.