Repository navigation
feat(native): thread terminal drawer - #25
Merged
Merged
Conversation
rynfar
added a commit
that referenced
this pull request
Nov 2, 2026
The workspace draws the transcript .cached() since #25, but a markdown state's background reparse notifies only that state, which the cached view does not observe, so a streamed block could stay stale until another transcript update. Each state now re-notifies the transcript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The native client had no terminal. The web's thread terminal drawer (ledger
PN-TERMINAL) is one of the most-used surfaces: a bottom drawer under the chat with one or more shells per thread, shared live with every other client attached to the same PTY.Approach
Ported from
ThreadTerminalDrawer.tsx,PersistentThreadTerminals.tsx,useThreadTerminalActions.ts,useChatTerminalActions.ts,terminalUiStateStore.ts,terminalCloseConfirm.ts, andclient-runtime/src/state/{terminal,terminalSession}.ts, against the unmodified server protocol (terminal.open/attach/observe/write/resize/close,subscribeTerminalMetadata).crates/core/src/terminal*(pure, tested)Unknown).BufferState: the attach-event reducer (applyTerminalAttachStreamEvent), reportingReset(history)/Append(data)instead of retaining text, because the emulator owns scrollback.Lifecycle:transitionTerminalLifecycle. A shell that exits while attached is closed and dropped from the drawer. An ended shell found on an explicit visit is reopened. Read-only viewers never touch history.TerminalLayouts: a full port ofterminalUiStateStore(open, height, ids, split groups, active terminal and group, close suppression, server reconcile), persisted asterminal-statethroughstore::save_ui_state, with each thread decoded on its own.getTerminalLabel,nextTerminalId), launch location and env (projectScriptCwd/RuntimeEnv), drawer height clamp, close-confirmation copy.emulator:alacritty_terminal0.26 (Apache-2.0) wrapped as bytes in, snapshot out. It answers DSR/DA/OSC 10/11/4 and size queries. It drops replies while replaying history (as the web'sresetAndWritedetaches the PTY writer), so a replay never types garbage into the shell. It flushes stalled synchronized updates and maps the wheel to SGR mouse reports or alternate-screen arrows.crates/client:ClientHandle::request(from #18) now queues the request before returning, so calls made in order reach the server in order. Terminal input depends on this, and the change is signature-compatible. AddedClientHandle::streamnext to it.crates/app/src/terminalsession: one network task per terminal. It attaches (or falls back toterminal.observe, read-only, onEnvironmentAuthorizationError), resumes after reconnects withresume: true, and parses output into the emulator on the tokio runtime behind aFairMutex. It signals the pane with one pending notification at a time, and the pane repaints at most once per 16 ms. Idle cost is zero.element: paints only visible rows. It merges background and selection runs into quads and shapes each row as a few text runs pinned to the cell grid (force_width), splitting only at wide characters. Metrics follow the web's ghostty surface: 12px mono,round(12 * 1.35)line, 4px padding, grid anchored to the bottom once there is scrollback. The cursor is steady (no blink): a block when focused, hollow when not.pane: keyboard, IME (EntityInputHandler, preedit drawn at the cursor), drag/word/line selection with a 2px threshold, shift-click extend, wheel scrollback, focus reports, and the web's context menu (Copy, Paste, Select all, Jump to latest).drawer/drawer_view: a 280px default drawer (min 180, max 75% of the window) with a 6px resize strip that persists height per thread. The active group's panes sit side by side or stacked. The UI is either the floating action group (one terminal) or the 144px session list with group headers (several). The empty state matches the web. Closing asks first with the web's copy; a failed close falls back to typingexit. Opening an empty drawer reuses a terminal the server already runs for the thread before starting a new one.terminal.toggle,terminal.split,terminal.splitVertical,terminal.new, andterminal.closenow map to the drawer's actions inkeymap::action_for, so the web's default keys and the user's keybindings apply.mod+jworks everywhere; the rest work while a terminal is focused, via the keymap'sterminalFocus→Terminalcontext, which the pane carries. Copy, paste, select all, andcmd-kclear (keys the web's surface handles itself) are bound in theTerminalcontext, so they beat the palette'smod+k, as the web's!terminalFocusrule intends. There is also a Terminal toggle in the header's right cluster (design-system §7.4). Tooltips take their shortcuts fromkeymap::label.icons::Iconin the same format.workspace.rs: the drawer sits under the composer. The thread view is now.cached(), so terminal output repaints don't re-render the transcript. (ThreadViewalready notifies itself, so this is safe.)Ledger
PN-TERMINAL:todo→partial, Nativecrates/app/src/terminal, crates/core/src/terminal.rs. Web sources now also cover the files this ports.Verification
cargo test -p t3-core -p t3-client: pass, including 33 new terminal tests (reducers, lifecycle, layouts, labels, payloads, key and paste encoding, emulator replies and replay, selection, wheel, hit testing).cargo clippy --workspace --all-targets -- -D warnings: clean.node scripts/gen-theme.ts --checkandnode --test parity/sync.test.ts: pass.cargo run -p t3-client --example terminal_probe -- --seconds 8):term-1with no window frame drawn yet (sessions don't wait for paint). A second client (terminal_probe --observe term-1 --run …) typedprintf '\033[6n'; read -rs -t 2 -d R pos && echo dsr-reply-ok || echo dsr-timeoutand gotdsr-reply-ok. Only the attached app could answer that query, so it parsed live output and replied overterminal.write.seqflood into that terminal (about 1.3 MB), app CPU peaked around 13% (with temporary debug logging on) and returned to 0.0% as soon as output stopped. Idle is 0.0%.[terminal] Terminal closed, dropped the terminal, and closed the drawer, as the web does.Gaps
test-t3-native.terminal-links.ts), "Add to chat" from a selection and the selection action popover, terminal font family and size settings, mouse click/drag reporting (only the wheel is reported), and dragging the scrollbar thumb.terminal.attachfails authorization.Ported by Claude (Opus 5.5) in Claude Code, as factory worker W5.