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:
- Run
claude doctor --output-format json (if available) or equivalent probe (a minimal one-shot invocation that exits quickly).
- Inspect output: presence of
apiKey / authenticated: true / absence of needs_setup.
- If OK → proceed with Dialogue start.
- 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
Relationships
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.startAgentfires for Dialogue:claude doctor --output-format json(if available) or equivalent probe (a minimal one-shot invocation that exits quickly).apiKey/authenticated: true/ absence ofneeds_setup._preflightFailed(reason)→ AgentSessionFeature sets Presentation to a.preflightError(PreflightErrorState)intermediary state.Error screen
A dedicated view in
AgentChatUI/Errors/PreflightErrorView.swift:[Open as Terminal]— opens a sibling.agentTerminalsession where the user can runclaudeinteractively and complete setup.[Retry]— re-runs the preflight check.Heuristics for common cases
ANTHROPIC_API_KEYmissing AND no keyring entry/loginIntegration
AgentSessionFeature.startAgentbefore.agentDialoguebranch..agentTerminal— not called (raw terminal handles its own interactive prompts).Acceptance Criteria
/loginneeded, missing plugins.Relationships