Skip to content

feat(terminal): real PTY with xterm.js, splits and persisted scrollback (#1493 F) - #1499

Merged
currentbits merged 3 commits into
mainfrom
coder/1493-f-real-terminal-pty-xterm-2acb4f
Oct 6, 2026
Merged

currentbits merged 3 commits into
mainfrom
coder/1493-f-real-terminal-pty-xterm-2acb4f

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Item F of #1493. It covers part of #1183 (the "Restart to move" warning when the thread changes checkout) and #1184 (SSH projects show an explicit not-available message).

What changed

  • Backend: electron/terminal.js now runs each shell in a PTY via @lydell/node-pty (prebuilt binaries for each platform, so no Electron rebuild), with resize. Several terminals per thread are allowed, scrollback is capped at 5,000 lines, and output streams through a new batched terminal:data push instead of 250 ms polling. Scrollback is saved under <userData>/terminals/ and replays after a restart.
  • Pane: xterm.js, lazy-loaded as its own 333 kB chunk, so the main bundle is unchanged. Copy/paste, links, fit-on-resize, theme colours that follow light/dark, and up to 4 side-by-side splits.
  • Pipe fallback: used wherever the native module can't load, with a warning in the pane.
  • Platforms:
    • macOS arm64: PTY, verified in a signed packaged app (verify-package.sh opens a PTY).
    • Linux x64 and Windows x64 (ConPTY): binaries ship in the cross archives, but neither was run on its OS.
  • Packaging:
    • pty.node and spawn-helper are signed by the existing per-file walk in codesign-app.sh (no --deep). I checked both: Developer ID, hardened runtime flag, and codesign --verify --deep --strict on the bundle passes.
    • Notarization runs only for tagged builds, so the next nightly is its first real test.
    • package-cross.sh downloads the Linux and Windows prebuilds from npm at the pinned version.

Verified independently, on main merged with this branch and #1498:

  • typecheck exits 0 and vite build passes.
  • test:renderer passes 2776 of 2776.
  • test:electron passes 4190 of 4190. The new tests open real PTYs and cover size, resize, Ctrl-C keeping the shell, kill on close, the fallback, the line cap, replay and the safety cases.
  • Web: the web bridge already exposed the terminal IPC to authenticated clients, so adding terminal:data to the push allowlist opens no new channel; it just makes the pane work in Solenta Web.

Risks and follow-ups

🤖 Generated with Claude Code

Willem and others added 3 commits October 6, 2026 15:15
@lydell/node-pty is an N-API prebuild per platform, so no Electron ABI
rebuild. package-app.sh copies the darwin-arm64 binary (signed by the
existing nested Mach-O walk); package-cross.sh fetches the linux-x64 and
win32-x64 (ConPTY) packages with npm pack. verify-package.sh now forks a
PTY under the packaged, signed binary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… scrollback (#1493)

electron/terminal.js now runs each shell in a PTY (pipe fallback with a
small cooked-mode editor when the addon does not load), keyed by
(thread, terminal) so a thread can have several. Output stays raw for
xterm, is capped at 5k lines, pushed in ~16 ms batches on terminal:data,
and flushed to <userData>/terminals so it replays after a restart.

New IPC: terminal.resize and terminal.list; write is raw keystrokes.
A live shell whose thread moved to another checkout is flagged
staleRoot (#1183), and SSH projects get an explicit unsupported message
instead of a local shell (#1184).

TerminalPane lazy-loads xterm (fit, web links, theme from CSS tokens,
Cmd/Ctrl+Shift+C copy) and renders up to four side-by-side splits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
terminal:data joins the web wire push list (wireClient.on throws for
unlisted channels, which would crash the pane on Solenta Web). A pending
flush no longer recreates a closed terminal's log, and reopening an
exited shell carries its scrollback over. Packaging comment no longer
names the signing script before the speech step (ordering test).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T13:51:17.580134Z 16dc49e PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 16dc49eb14

ℹ️ 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 on lines +178 to +180
t.onData((data) => {
void api.write({ threadId, termId, data }).catch(() => {});
}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Prevent offline raw keystrokes from being deduplicated

In Solenta Web, each xterm input event is now a separate terminal:write invocation, but createWireCoder queues calls while disconnected and deduplicates identical channel/argument signatures when reconnecting (src/wireClient.ts:65-87). Consequently, repeated keystrokes entered during an outage are collapsed—for example, typing hello can replay as helo—and an Enter key may later execute the corrupted command. Terminal input needs ordered, non-deduplicated buffering or terminal:write must bypass the generic offline queue.

Useful? React with 👍 / 👎.

Comment on lines +160 to +164
const offPush = api.onData((p) => {
if (!live || p.threadId !== threadId || p.termId !== termId || cursor < 0) return;
setRunning(p.running);
if (p.cursor <= cursor || !term) return;
if (p.from > cursor) return resync();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resync terminal state after WebSocket reconnection

For Solenta Web, this pane now reads only when a later push exposes a cursor gap, while the reconnect path in src/wireClient.ts:156-163 resynchronizes threads only. If output is produced—or the shell exits—while the WebSocket is disconnected and the terminal is quiet afterward, no later push arrives to trigger resync(), so the pane permanently omits that output and can continue showing the shell as running. Reconnect should explicitly re-read active terminals or emit a terminal resync signal.

Useful? React with 👍 / 👎.

@currentbits
currentbits merged commit 4bcba42 into main Oct 6, 2026
6 checks 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