Skip to content

feat: dual-mode sessions with prompt API (#52)#56

Open
paolino wants to merge 11 commits intomainfrom
003-dual-mode-sessions
Open

feat: dual-mode sessions with prompt API (#52)#56
paolino wants to merge 11 commits intomainfrom
003-dual-mode-sessions

Conversation

@paolino
Copy link
Copy Markdown
Contributor

@paolino paolino commented Mar 29, 2026

Summary

  • New SessionMode type (Terminal/Structured) with mode field on all sessions
  • AgentDaemon.Structured module manages claude CLI in stream-json mode via typed-process
  • POST /sessions/:id/mode switches between terminal and structured mode with --resume
  • POST /sessions/:id/prompt sends prompts to structured sessions, returns JSON events
  • --dangerously-skip-permissions bypasses permission prompts in structured mode

Test plan

Tested manually against a live daemon (--port 18080 --base-dir /code):

  • Create session defaults to terminal mode
  • POST /sessions/:id/mode {"mode":"structured"} switches mode, captures claude session UUID
  • GET /sessions shows mode field on all sessions
  • POST /sessions/:id/prompt returns JSON events (system, assistant, result)
  • Prompt rejected in terminal mode ("session must be in structured mode")
  • Same-mode switch is a no-op ("already in mode")
  • Switch back to terminal works
  • Resume preserves conversation history across mode switches (asked "What was my first question?" after switching modes twice — correctly recalled)
  • DELETE /sessions/:id cleans up structured process
  • Automated hspec tests (follow-up)

Closes #52

@paolino paolino force-pushed the 003-dual-mode-sessions branch 3 times, most recently from 7c24a00 to a9e4936 Compare March 29, 2026 20:35
@paolino paolino force-pushed the 003-dual-mode-sessions branch from cbc46a9 to 1eb0721 Compare March 29, 2026 21:00
paolino added 8 commits March 30, 2026 11:00
Add SessionMode (Terminal/Structured), StructuredProcess module for
managing claude CLI in stream-json mode, mode switch endpoint
(POST /sessions/:id/mode), and prompt endpoint
(POST /sessions/:id/prompt) that collects JSON events.
…ocol

- TypesSpec: 19 tests (SessionMode JSON, PromptRequest, ModeRequest,
  Session JSON with mode/claudeId fields)
- StructuredSpec: 14 tests (encodeUserMessage format, parseInitSessionId,
  isResultEvent detection)
- Fix ApiSpec for IO Application change
Skip Terminal relay test which needs a running tmux server.
- 4 integration tests: spawn/init, prompt/result, non-empty response,
  resume conversation history
- CI splits into: unit tests (always), integration (claude-tests env)
- Environment approval required before running claude API calls
- 4 integration tests: spawn/init, prompt/result, non-empty response,
  resume conversation history
- CI splits into: unit tests (always), integration (claude-tests env)
- Fixed stream-json init handshake: send control_request, wait for
  control_response, capture session_id from hook events
- PATH includes /run/current-system/sw/bin for claude CLI
@paolino paolino force-pushed the 003-dual-mode-sessions branch from 1eb0721 to 512522e Compare March 30, 2026 10:01
- readInitEvent skips to control_response (no hooks on runner)
- Resume test gracefully skips when session_id unavailable
- Remove stm test dependency (unused after refactor)
Runner overrides HOME to a temp dir, so claude can't find
credentials or session files for --resume. Export HOME=/home/paolino
in the integration test step.
The github-runner DynamicUser has no persistent HOME or claude
credentials. Basic prompts work (3 tests), but --resume needs
session files that claude writes to $HOME/.claude/ which doesn't
exist for the runner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: dual-mode sessions (TUI + stream-json) with prompt API

1 participant