Skip to content

Feat/interactive terminal impl#161

Open
mikeangstadt wants to merge 17 commits intomainfrom
feat/interactive-terminal-impl
Open

Feat/interactive terminal impl#161
mikeangstadt wants to merge 17 commits intomainfrom
feat/interactive-terminal-impl

Conversation

@mikeangstadt
Copy link
Copy Markdown
Contributor

Added clickable interactive mode to drop into a terminal window running ClaudeCode from the electron app.

mikeangstadt and others added 6 commits April 22, 2026 15:03
- Spawn claude via node-pty instead of child_process.spawn so jobs
  run inside a real PTY that users can attach to
- All commands spawn claude directly in interactive mode (no -p,
  no bash pipeline wrapper, no run-loop.sh)
- JSONL extraction moved to PTY onData handler (replaces grep|tee)
- New WebSocket endpoint /api/engineer/jobs/:jobId/terminal for
  streaming PTY I/O to an xterm.js frontend
- Click a running job card in the Electron UI to open an interactive
  terminal window attached to that job's live Claude session
- User can type, interrupt (Escape), and steer the session mid-run

New files:
- pty-session-store.ts: PTY session lifecycle + output buffer
- terminal-attach.ts: WebSocket bridge between PTY and xterm.js
- terminal.html: xterm.js terminal rendered in BrowserWindow

Testing: manual — spawn job, click card, interact with Claude session

Risks: All commands now interactive (no -p). Output-tailer JSONL
capture changes from grep|tee pipeline to PTY onData extraction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add gateway auth to WebSocket terminal upgrade handler (BLOCKING)
- Fix getById → getByLoopId in open-job-terminal IPC handler
- Pass auth token to terminal.html via query param
- Make sweepOrphanedTokens public, call during boot
- Guard against invalid signedUrlExpiresAt (NaN bypass)
- Fix postLoopEventBounded timeout detection (dead catch)
- Consistent exit code default in persistFinalJobStatus
- Replace socket.destroy() with return on upgrade mismatch
- Schedule removeSession(loopId) after process completion
- Log errors in boot-recovery trackBackgroundTask catch

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Include terminal.html in electron-builder files for packaged builds
- Extract and clear auth token from URL before CDN scripts load
- Remove stale run-loop.sh preflight check (PLAN/EXECUTE spawn
  claude directly via PTY now)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Restore run-loop.sh for PLAN/EXECUTE (multi-iteration execution)
- Restore run-loop.sh preflight check for PLAN/EXECUTE commands
- Keep interactive mode (no -p/stream-json) for all other commands
- Quote workdir in /code:amend-plan invocation (spaces in paths)
- Validate log file writable before PTY spawn (fail-fast on EISDIR)
- Close terminal window 2s after process exits
- Fix missing getGatewayId in telemetry test constructors

Tests: 908 total, 907 pass, 1 env-dependent skip (pre-existing)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On PTY exit, do a full re-extraction of JSON lines from the session
log (symphony-loop.log) into claude-output.jsonl. The real-time JSONL
extractor can miss data due to PTY chunking or ANSI interleaving in
interactive mode. This post-exit sweep strips ANSI sequences, validates
each candidate line as JSON, and overwrites the JSONL file with the
complete set — ensuring parseTokenUsage, output-tailer, and error
detection have all available structured data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dead code after PTY migration — all commands now spawn via
spawnPtySession directly. Fixes CI lint failure (no-unused-vars).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mikeangstadt mikeangstadt requested a review from a team May 7, 2026 15:25
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a4e7ff832

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/desktop/src/server/operations/symphony-loop.ts Outdated
Comment thread apps/desktop/src/main/pty-session-store.ts Outdated
mikeangstadt and others added 7 commits May 7, 2026 11:39
…inal-impl

# Conflicts:
#	apps/desktop/src/main/app.ts
#	apps/desktop/src/main/loop-finalizer.ts
#	apps/desktop/src/server/operations/symphony-loop.ts
- Restore -p (print mode) for direct claude invocations (DECOMPOSE,
  EVALUATE_*, REQUEST_CHANGES, GENERATE_PRD/REQUEST_PRD_CHANGES) so
  unattended commands exit after completing the query instead of
  hanging in interactive mode
- Reorder CLI args to place flags before the prompt positional arg
- Defer exit listener notification until extractJsonlFromLog completes,
  so handleProcessCompletion reads the final JSONL content

Testing: Verified no conflict markers remain, no broken references
Risks: Low — restores main's -p behavior for direct invocations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- [P0] terminal.html: Add SRI integrity hashes to CDN scripts, pass auth
  token via CustomEvent instead of window global so CDN scripts never see it
- [P1] package.json: Bump version 0.14.22 → 0.14.23
- [P1] pty-session-store: Wrap pty.spawn() in try/catch to destroy
  logStream/jsonlStream on failure, preventing FD leaks
- [P1] pty-session-store: Change extractJsonlFromLog to append-only
  (appendFileSync) with dedup, preserving output-tailer byte offsets
- [P2] pty-session-store: Import shared stripAnsi from diagnostics-helpers
  instead of duplicating it
- [P2] pty-session-store: Add duplicate session guard (throw on existing
  loopId) to prevent silent overwrites
- [P2] terminal-attach: Fix double exit message by returning early when
  session.exited is true before registering exit listener
- [P2] terminal-attach/router: Extract safeEqualToken to shared
  auth-utils.ts module
- [P2] app.ts: Add monorepo-root CWD fallback for terminal.html path,
  matching window.ts two-probe pattern

Testing: Manual verification of all changed files
Risks: Low — focused fixes addressing review feedback

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…inal-impl

# Conflicts:
#	apps/desktop/package.json
#	apps/desktop/src/server/router.ts
Adds a fail-closed feature flag (default: false) that hides the
interactive terminal functionality until explicitly enabled:
- WebSocket terminal attach endpoint only initialized when enabled
- IPC handler for opening terminal windows rejects when disabled
- PTY-based spawning remains active (functionally equivalent to
  prior spawn behavior with -p flag)

To enable: set interactiveTerminal to true in desktop settings.

Testing: Setting defaults to false; all existing behavior unchanged
Risks: None — purely additive gating with fail-closed default

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…inal-impl

# Conflicts:
#	apps/desktop/package.json
#	apps/desktop/src/server/operations/symphony-loop.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mikeangstadt mikeangstadt requested review from shafty023 and thadeusb May 8, 2026 15:50
mikeangstadt and others added 4 commits May 8, 2026 10:56
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant