Skip to content

D-26: Pre-flight check — interactive TUI prompts detection (missing auth / /login) #276

@kirich1409

Description

@kirich1409

Description

Detect when Claude Code in Dialogue mode can't function because the CLI will drop to an interactive TUI (missing API key, needs /login, OAuth flow, first-run setup) — show an explicit fallback screen instead of a broken-looking empty Dialogue.

Spec: Epic #250 §11 Risks row 2; docs/architecture/dialogue.md §2 pre-flight section.

Scope

Detection logic

Before AgentSessionFeature.startAgent fires for Dialogue:

  1. Run claude doctor --output-format json (if available) or equivalent probe (a minimal one-shot invocation that exits quickly).
  2. Inspect output: presence of apiKey / authenticated: true / absence of needs_setup.
  3. If OK → proceed with Dialogue start.
  4. If not OK → dispatch _preflightFailed(reason) → AgentSessionFeature sets Presentation to a .preflightError(PreflightErrorState) intermediary state.

Error screen

A dedicated view in AgentChatUI/Errors/PreflightErrorView.swift:

  • Explicit headline: "Claude Code needs interactive setup".
  • Details: what's missing (API key / login / plugins / etc.).
  • Primary CTA: [Open as Terminal] — opens a sibling .agentTerminal session where the user can run claude interactively and complete setup.
  • Secondary CTA: [Retry] — re-runs the preflight check.
  • Link: "Learn more" → opens Claude Code docs.

Heuristics for common cases

Detected Message CTA
ANTHROPIC_API_KEY missing AND no keyring entry "Claude is not authenticated. Set your API key or sign in." Open as Terminal → run /login
MCP server fails to connect "One or more plugins failed to start." Continue (but show in session_init chip)
CLI version < minimum required for stream-json "Your Claude Code version is too old. Upgrade to N.N+." Open docs
Unknown error Generic "Setup needed" Open as Terminal

Integration

  • Called from AgentSessionFeature.startAgent before .agentDialogue branch.
  • For .agentTerminal — not called (raw terminal handles its own interactive prompts).

Acceptance Criteria

  • Preflight check runs before Dialogue session start.
  • Correct detection of: missing API key, /login needed, missing plugins.
  • PreflightErrorView renders with correct reason + CTA.
  • "Open as Terminal" CTA creates a sibling terminal tab and focuses it.
  • Retry re-runs preflight.
  • Detection runs in < 2 seconds (spinner shown during check).
  • No false positives on a valid Claude setup.

Relationships

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions