Skip to content

Run provider sign-in inside settings with auto-captured setup token - #108

Merged
badcuban merged 2 commits into
mainfrom
provider-auth-inline-flow
Aug 4, 2026
Merged

Run provider sign-in inside settings with auto-captured setup token#108
badcuban merged 2 commits into
mainfrom
provider-auth-inline-flow

Conversation

@badcuban

@badcuban badcuban commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

What

Provider sign-in (codex login, claude auth login, claude setup-token) now runs entirely inside Settings → Providers. Clicking Sign in no longer teleports the user into their last chat thread's terminal drawer.

  • New providerAuth.* RPC family (start/write/resize/stop/subscribe) routed in ws.ts, driving a new ProviderAuthSessions service: one ephemeral PTY per provider instance, command derived server-side from instance config, no scrollback persisted to disk (chat-thread terminals persist history; auth output contains credentials).
  • Settings-owned ProviderConnectFlow panel: status chips with an inline action (quiet "Sign in again" when healthy, solid "Reconnect" when signed out), plain-language status line, last-output-line preview, and a Show-details interactive terminal that auto-expands when the CLI waits for input (~15s) or fails, and closes on success. Server replays command/output/status on subscribe, so a running flow survives tab switches and remounts.
  • Auto-captured setup token: the server captures the printed token, saves it as the sensitive CLAUDE_CODE_OAUTH_TOKEN instance variable through the normal settings path, and masks it before fanout — the raw token never reaches the browser. Manual paste stays as a fallback and the field remains write-only.
  • Auth PTYs strip CLAUDE_CODE_OAUTH_TOKEN / ANTHROPIC_* so a stale credential can't turn the interactive sign-in into a no-op.
  • Command builders moved to @threadlines/shared/providerAuthCommands (shared by server spawn + web copy-fallback). The jump-to-chat runner and its terminal-store plumbing are removed.

Wrap-truncation fix (found in live testing)

The CLI hard-wraps output at PTY width; a ~103-char token wrapped at 100 cols was captured truncated (a dead credential) with its tail leaking past the mask. The setup-token PTY now spawns 512 columns wide and ignores resize, so the token can never wrap (xterm still soft-wraps the display); capture is decoupled from output flushing and only accepts a match confirmed complete. A regression test replays the wrapped-token scenario.

Testing

  • vp fmt, vp lint, vp run typecheck clean
  • Server: ProviderAuthSessions behaviour tests (fake PTY): chunk-split capture + masking, wrap regression, exit-code handling, per-instance session replacement; full server.test suite green
  • Web: flow-logic unit tests, SettingsPanels browser test for the in-settings sign-in path; full test:browser suite green (355)
  • Live-verified on macOS: Codex + Claude sign-in, setup-token capture (stored token verified complete on disk), running-flow replay after tab switch

Provider auth no longer jumps to a chat-thread terminal. A new
providerAuth.* RPC family drives ephemeral server-side PTY sessions
(ProviderAuthSessions): the command is derived server-side from the
instance config, nothing is persisted to disk, and the settings page
hosts the whole flow in an inline panel with a collapsible terminal.

For claude setup-token, the server captures the printed token, saves it
as the sensitive CLAUDE_CODE_OAUTH_TOKEN instance variable, and masks it
before fanout so the browser never receives it. The setup-token PTY is
spawned 512 columns wide and never resized: the CLI hard-wraps at PTY
width, and a wrapped token was previously captured truncated with its
tail leaking past the mask. Capture is decoupled from output flushing
and only accepts a terminated match.

Auth PTYs strip CLAUDE_CODE_OAUTH_TOKEN/ANTHROPIC_* so stale credentials
cannot no-op an interactive sign-in. Command builders move to
@threadlines/shared/providerAuthCommands, shared by server and web. The
old jump-to-chat runner and its terminal-store plumbing are removed, and
the account section renders status chips with an inline action instead
of a detached button.
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
threadlines Skipped Skipped Aug 4, 2026 4:48am

Request Review

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels Aug 4, 2026
Comment thread packages/shared/src/providerAuthCommands.ts Fixed
Omit<> flattened the ProviderAuthEvent union in the flow-logic test
helper; distribute it over the variants instead. The failure never
surfaced locally because vp served a stale typecheck cache hit.

Parse the pasted CLAUDE_CODE_OAUTH_TOKEN=... assignment without a
regex: the \s*=\s*(.+)$ pattern backtracks polynomially on adversarial
whitespace (CodeQL js/polynomial-redos).
@badcuban
badcuban merged commit ec7d3d3 into main Aug 4, 2026
15 checks passed
@badcuban
badcuban deleted the provider-auth-inline-flow branch August 4, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants