Skip to content

AI-Chat model selector never offers the PTY (agent-CLI) option, leaving provider:'pty' unreachable #1489

Closed

Description

@malibio

Overview

Per ADR-034, ai-chat is a single node type discriminated by provider, and a PTY agent session (Claude Code / Codex / Gemini CLI / etc. running in an embedded terminal) IS an ai-chat node with provider: 'pty'. The rendering and launch/capture side of this mode is fully built, but there is no UI entry point to create a pty chat: the header model selector never offers a PTY option, so nothing ever writes provider: 'pty' onto a node and the entire mode is unreachable.

Problem Statement

User Experience:

  1. User opens a new /ai-chat node.
  2. The header model selector (AiChatModelSelector) lists only Local (native GGUF), Ollama, and Custom endpoints (OpenAI-compat), plus a "Set up…" action.
  3. There is no way to choose "launch an agent CLI session" — the PTY / terminal mode.
  4. Expected: the selector offers a PTY option (e.g. an "Agent CLI" group or a "Launch agent session…" action) that sets provider: 'pty' and routes the node to the embedded-terminal view.

Evidence — the mode is built but dead-ended:

  • AiChatProvider includes 'pty': packages/desktop-app/src/lib/types/ai-chat-node.ts:4
  • The viewer dispatches on it: packages/desktop-app/src/lib/components/viewers/ai-chat-node-viewer.svelte:414 — {:else if provider === 'pty'} → <AiChatPtySession {nodeId} />
  • AiChatPtySession is complete: harness picker, availability checks (ptyCheckAgentAvailability), launch (ptyLaunchSession), capture backfill, ended-session summary — packages/desktop-app/src/lib/components/viewers/ai-chat-pty-session.svelte
  • But the selector's ModelSelection type omits 'pty' and no optgroup/option emits it: packages/desktop-app/src/lib/components/viewers/ai-chat-model-selector.svelte:16-20, 237-301
  • Consequently handleModelSelect only ever writes native / ollama / openai-compat: ai-chat-node-viewer.svelte:144-190

Design Intent (confirmed)

This stays a single ai-chat node type — no separate PtyChatNode. provider is the discriminant. A PTY node legitimately stores no messages (messages: []); the conversation lives in the external harness's own PTY. What NodeSpace persists instead are capture references on the node's properties: capture:session_id (reference to the external session), capture:agent_type, optional capture:summary / capture:transcript backfilled at session end, and status (active → archived). Same schema, different fill: native/ollama nodes hold the full message log; PTY nodes hold a thin reference to an external session plus optional captured summary/transcript.

Root Cause

Location: packages/desktop-app/src/lib/components/viewers/ai-chat-model-selector.svelte

  • The module-level ModelSelection interface (lines 16-20) constrains provider to 'native' | 'ollama' | 'openai-compat', so the selector cannot express a PTY selection.
  • The <select> template (lines 237-301) builds only Local / Ollama / Custom-endpoints optgroups plus the "Set up…" sentinel — no PTY entry.
  • Therefore handleModelSelect in ai-chat-node-viewer.svelte (lines 144-190) is never invoked with a PTY selection, and no code path sets provider: 'pty' on a node. The {:else if provider === 'pty'} branch is unreachable from the UI.

Proposed Solution

  1. Extend ModelSelection.provider in ai-chat-model-selector.svelte to include 'pty'.
  2. Add a PTY entry to the selector — an "Agent CLI" optgroup (or a single "Launch agent session…" action-style entry) — whose option value maps to a { provider: 'pty', modelId: '' } selection via onSelect. A PTY node needs no model, so modelId is empty and the specific harness (claude-code / codex / gemini-cli / …) is chosen later inside AiChatPtySession.
  3. Handle selection.provider === 'pty' in handleModelSelect (ai-chat-node-viewer.svelte): write provider: 'pty' (and appropriate status) to the node via sharedNodeStore.updateNode, with no model, so the viewer routes to AiChatPtySession.
  4. While in the viewer, verify the provider === 'pty' branch at ai-chat-node-viewer.svelte:414-420 is clean — it appears to render <AiChatPtySession> immediately followed by a provider-prompt "Choose a model" block, which looks like a possible merge artifact. Confirm the branch renders only the PTY session.

Acceptance Criteria

  • The AI-Chat header model selector shows a PTY entry (e.g. an "Agent CLI" group or "Launch agent session…" action).
  • Selecting it sets provider: 'pty' on the node (no model) and the viewer renders AiChatPtySession.
  • The launched node remains an ai-chat node with an empty messages array; session state is stored via the capture:* properties.
  • ModelSelection.provider includes 'pty'; no any casts or type suppression introduced.
  • The provider === 'pty' branch in ai-chat-node-viewer.svelte renders only the PTY session (no stray "Choose a model" block).
  • Existing native / ollama / openai-compat selection flows are unchanged.
  • Tests pass (bun run test:all), including a test asserting a PTY selection sets provider: 'pty'.
  • Code passes bun run quality:fix.

Technical Specifications

Files to Modify

  • ai-chat-model-selector.svelte: packages/desktop-app/src/lib/components/viewers/ai-chat-model-selector.svelte — extend ModelSelection (lines 16-20) and add the PTY option to the <select> (lines 237-301) + a branch in handleChange (lines 185-221).
  • ai-chat-node-viewer.svelte: packages/desktop-app/src/lib/components/viewers/ai-chat-node-viewer.svelte — handle provider === 'pty' in handleModelSelect (lines 144-190); verify the pty render branch (lines 392-420).

Reference Files (no change expected)

  • ai-chat-pty-session.svelte: packages/desktop-app/src/lib/components/viewers/ai-chat-pty-session.svelte — the target view; already handles harness selection, launch, capture, and ended state.
  • ai-chat-node.ts: packages/desktop-app/src/lib/types/ai-chat-node.ts — AiChatProvider already includes 'pty'; messages defaults to [].

Test Requirements

  • Unit test (Happy-DOM, bun run test): selecting the PTY option invokes onSelect with { provider: 'pty' } and handleModelSelect writes provider: 'pty' (no model) to the node.

Non-Goals

  • No changes to the daemon-side PTY launch/capture pipeline (ptyLaunchSession, ptyCheckAgentAvailability) — already implemented.
  • No new harness integrations beyond the agents AiChatPtySession already offers.
  • No separate node type for PTY sessions — this remains one ai-chat type discriminated by provider.

Activity

  1. added
    bug
    on Jul 4, 2026
  2. malibio commented on Jul 11, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 158 test files passed, 4019 tests passed.

  3. self-assigned this
    on Jul 11, 2026
  4. added 2 commits that reference this issue on Jul 11, 2026
    cb54374
    02350a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

aibugfrontendui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions