Skip to content

[feat:global] terminal mode and unit testing#3

Merged
adeotek merged 25 commits into
mainfrom
feat/terminal
May 13, 2026
Merged

[feat:global] terminal mode and unit testing#3
adeotek merged 25 commits into
mainfrom
feat/terminal

Conversation

@adeotek
Copy link
Copy Markdown
Owner

@adeotek adeotek commented May 13, 2026

No description provided.

adeotek and others added 25 commits May 12, 2026 23:09
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Store spawn errors and deliver them to the first attaching socket, rather than broadcasting to an empty set
- Remove dead sessions from TerminalManager on natural PTY exit via onCleanup callback
- Reset idle timer on socket reconnect in attach()
- Narrow broadcast() parameter to a typed TerminalServerMessage union

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…smatch

The PTY was spawned with hardcoded cols=220 rows=50. The claude CLI reads
terminal dimensions at startup via TIOCGWINSZ and draws its TUI at those
dimensions. xterm.js renders at the actual container width (~120 cols),
causing line wrapping and scrambled display.

Two-part fix:
- Backend: PTY now spawns lazily on the first resize message, using the
  exact dimensions measured by the browser. Reconnecting clients skip the
  wait and receive connected immediately.
- Frontend: useTerminalSession accepts an onConnect callback fired on
  ws.onopen. TerminalSession uses it to call fit.fit(), which sends the
  resize through the now-open WebSocket before the PTY starts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PTY exit/kill now closes WebSocket connections so the frontend reconnect
loop fires and spawns a fresh PTY automatically on reconnect.

Session resume now uses the current global session_mode setting instead
of the stored session mode, so switching modes in Settings takes effect
immediately when opening any existing session.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
xterm.js only fires onResize when cols/rows actually change. On reconnect
the terminal is already at the correct size, so fit.fit() was a no-op,
no resize message was sent, and the PTY never spawned.

onConnect now explicitly sends the post-fit dimensions via a stable ref,
guaranteeing the spawn-triggering resize message is delivered on every
connection, including reconnects.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ation

TerminalSession was unmounting when navigating to the sessions list
(SESSION_CLEARED sets sessionId=null), destroying the xterm instance and
losing all scrollback. On resume the fresh xterm showed blank because
the running PTY was idle and sent no new output.

Fix matches the TerminalDrawer pattern: keep TerminalSession always
mounted, CSS-hide its wrapper when not in an active terminal session.
The xterm instance and scroll buffer survive the trip to the list and back.

Also: clear the terminal when switching to a different session (not same
session resume), and guard ResizeObserver against zero-size callbacks
from hidden containers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Backend accumulates up to 256 KB of PTY output per session in a circular
scrollback buffer. On reconnect (existing PTY), it sends the buffer as a
{type: 'history'} message before {type: 'status', state: 'connected'}.

Frontend clears the xterm viewport and replays the history on receipt,
restoring the terminal state after a page refresh. Works in tandem with
the CSS-toggle approach: navigation-within-app uses the preserved xterm
instance; page refresh uses history replay from the backend buffer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adeotek adeotek merged commit edb454a into main May 13, 2026
2 checks passed
@adeotek adeotek deleted the feat/terminal branch May 13, 2026 11:52
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