Skip to content

feat(desktop): add headless terminal for backend PTY state persistence#66

Merged
oxwen11 merged 1 commit intomainfrom
feat/headless-terminal
Feb 8, 2026
Merged

feat(desktop): add headless terminal for backend PTY state persistence#66
oxwen11 merged 1 commit intomainfrom
feat/headless-terminal

Conversation

@oxwen11
Copy link
Member

@oxwen11 oxwen11 commented Feb 8, 2026

Summary

Add backend PTY state persistence using @xterm/headless and @xterm/addon-serialize. This enables seamless terminal state restoration during tab switching.

Changes

New Files

  • apps/desktop/src/main/terminal/headless-terminal.ts — HeadlessTerminal class with mode tracking (DECSET/DECRST), OSC-7 CWD parsing, and snapshot serialization
  • apps/desktop/src/main/terminal/types.ts — TerminalModes and TerminalSnapshot type definitions
  • docs/plans/2026-02-05-feat-backend-pty-persistence-plan.md
  • docs/plans/2026-02-05-feat-rust-pty-daemon-plan.md

Modified Files

  • apps/desktop/src/main/terminal/terminal-manager.ts — Integrate HeadlessTerminal into TerminalInstance, mirror PTY output to headless for state tracking
  • apps/desktop/src/shared/contract/terminal.ts — Add TerminalSnapshotSchema and terminal.snapshot RPC endpoint
  • apps/desktop/src/main/ipc/router/terminal.ts — Add snapshot handler
  • apps/desktop/src/main/terminal/index.ts — Export new types
  • apps/desktop/package.json — Add @xterm/headless, @xterm/addon-serialize deps

How It Works

PTY Output → HeadlessTerminal.write() → [state captured]
                    ↓
            DirectPublisher.write() → Stream to Frontend

Tab Switch → terminal.snapshot({ terminalId })
          → HeadlessTerminal.getSnapshot()
          → { snapshotAnsi, rehydrateSequences, modes, cwd }

Note

typecheck:web failures are pre-existing on main (store naming mismatch: currentTaskId vs selectedTaskId), unrelated to this PR.

@oxwen11 oxwen11 self-assigned this Feb 8, 2026
@oxwen11 oxwen11 force-pushed the feat/headless-terminal branch from 29a609d to 9e6fd45 Compare February 8, 2026 05:24
- Add HeadlessTerminal class wrapping @xterm/headless with mode tracking
  (DECSET/DECRST), OSC-7 CWD parsing, and snapshot serialization
- Integrate headless terminal into TerminalManager for state mirroring
- Add terminal.snapshot RPC endpoint for frontend state sync
- Add @xterm/headless and @xterm/addon-serialize dependencies
- Add planning docs for PTY persistence approaches

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c3ba0-841a-74ee-bc0f-57c5e59fda40
@oxwen11 oxwen11 force-pushed the feat/headless-terminal branch from 9e6fd45 to 2a23eda Compare February 8, 2026 05:36
@oxwen11 oxwen11 merged commit f9019bc into main Feb 8, 2026
1 check passed
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