Repository navigation
fix(terminal): send CSI-u Shift+Enter to Droid on Windows (#7620) - #7668
Conversation
#7620) On Windows, Shift+Enter was always sent as the Alt+Enter byte ESC+CR (added in #2418 for Codex, which reads win32-input-mode and ignores CSI-u). droid speaks the kitty keyboard protocol, parses CSI-u directly, and treats ESC+CR as a plain Enter — so Shift+Enter SUBMITTED the message instead of inserting a newline. droid works in other terminals (Windows Terminal, Warp) because those honor win32-input-mode / kitty; Orca (xterm.js) withholds kitty from local Windows ConPTY panes and emits neither. Make the Windows Shift+Enter byte pane-aware: latch whether a pane's program advertised the kitty keyboard protocol (query CSI ? u, push CSI > .. u, or set CSI = .. u) and send CSI-u (\x1b[13;2u) to those panes, keeping the Codex-compatible ESC+CR for win32-input-mode-only TUIs. Non-Windows is unchanged (always CSI-u). Verified end-to-end against the real droid and Codex CLIs through the actual production functions: droid now newlines, Codex still newlines.
nwparker
left a comment
There was a problem hiding this comment.
Thanks for identifying the Droid-specific Windows encoding mismatch. I took over the implementation and replaced the sticky terminal-output heuristic with current-process, exact-ConPTY confirmation.
- CSI-u is limited to freshly confirmed Droid in the active native Windows ConPTY.
- Codex, Antigravity, shells, WSL, SSH, and remote runtimes keep legacy routing.
- Stale launch, exit, rebind, detach, and delayed-scan authority now fail closed.
- The focused reliability gate passes 1,215 tests on the final rebased tree.
- Security and hot-path audits are clean; native Windows execution remains the explicit evidence gap.
📝 WalkthroughWalkthroughThe change adds a daemon foreground-confirmation protocol and propagates validated launch-agent identity through daemon, PTY, IPC, preload, and renderer layers. Foreground resolution now supports fresh availability-aware scans and Windows ConPTY membership validation. Renderer tracking records trusted routing evidence, performs reconfirmation after relevant input boundaries, and selects Windows Shift+Enter bytes per pane. Pane detach logic transfers agent state by pane identity, while tests and reliability-gate metadata cover protocol, process, routing, state, and end-to-end behavior. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9cee1927-45eb-415a-b2b0-97b6cbc8fce5
📒 Files selected for processing (59)
config/reliability-gates.jsoncsrc/main/daemon/daemon-errors.tssrc/main/daemon/daemon-foreground-confirmation-protocol.test.tssrc/main/daemon/daemon-foreground-process-protocol.tssrc/main/daemon/daemon-pty-adapter.test.tssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/daemon-pty-router.test.tssrc/main/daemon/daemon-pty-router.tssrc/main/daemon/daemon-server.test.tssrc/main/daemon/daemon-server.tssrc/main/daemon/degraded-daemon-pty-provider.test.tssrc/main/daemon/degraded-daemon-pty-provider.tssrc/main/daemon/pty-subprocess-foreground-scan-cadence.test.tssrc/main/daemon/pty-subprocess.test.tssrc/main/daemon/pty-subprocess.tssrc/main/daemon/session.tssrc/main/daemon/terminal-host-create-contract.tssrc/main/daemon/terminal-host.tssrc/main/daemon/types.tssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/providers/agent-foreground-process.test.tssrc/main/providers/agent-foreground-process.tssrc/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/providers/types.tssrc/main/providers/windows-agent-foreground-process.tssrc/main/providers/windows-conpty-process-membership.test.tssrc/main/providers/windows-conpty-process-membership.tssrc/main/providers/windows-foreground-process-rows.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/keyboard-handlers.tssrc/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.test.tssrc/renderer/src/components/terminal-pane/pane-foreground-agent-tracker.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/renderer/src/components/terminal-pane/terminal-pane-tab-detach.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-tab-detach.tssrc/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.tssrc/renderer/src/components/terminal-pane/terminal-shortcut-policy.tssrc/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.tssrc/renderer/src/components/terminal-pane/terminal-windows-shift-enter.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/store/slices/pane-foreground-agent.tssrc/renderer/src/store/slices/store-cascades.test.tssrc/renderer/src/store/slices/terminal-pane-detach-agent-identity.test.tssrc/renderer/src/store/slices/terminals.tssrc/renderer/src/web/web-preload-api.tssrc/shared/agent-process-recognition.test.tssrc/shared/process-table-snapshot.test.tssrc/shared/process-table-snapshot.tssrc/shared/tui-agent-config.tstests/e2e/terminal-foreground-confirmation.unit.test.tstests/e2e/terminal-shortcuts.spec.ts
💤 Files with no reviewable changes (1)
- src/main/daemon/daemon-errors.ts
| execFileMock.mockImplementation( | ||
| (_cmd: string, _args: string[], _opts: unknown, cb: unknown) => { | ||
| const callback = cb as (err: unknown, result: { stdout: string; stderr: string }) => void | ||
| callback(new Error('ps unavailable'), { stdout: '', stderr: '' }) | ||
| } | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Remove the duplicate callback declarations.
Each mock callback declares const callback twice in the same scope, causing a TypeScript redeclaration error and preventing the test file from compiling.
Proposed fix
const callback = cb as (err: unknown, result: { stdout: string; stderr: string }) => void
-const callback = cb as (err: unknown, result: { stdout: string; stderr: string }) => void
callback(...)Also applies to: 300-304, 320-327, 339-353, 384-398
* fix(terminal): trust Pi CSI-u Shift+Enter on Windows (#9703) Pi enables the Kitty keyboard protocol at startup and decodes CSI-u, but TUI_AGENT_CONFIG['pi'] never set windowsShiftEnterEncoding, so on Windows Pi could only get CSI-u via the flaky live-KKP-flag path (isKittyKeyboardActivePane). After a tool ran a subprocess that emitted a reset sequence, the KKP flags dropped to 0, Orca sent Esc+CR, and Pi read it as plain Enter -> submit. It recovered on the next pane refocus. Set windowsShiftEnterEncoding: 'csi-u' for pi, mirroring the Droid fix (#7668), so the trusted CSI-u route covers Pi reliably independent of KKP-flag churn from tool subprocesses. * fix(terminal): complete Pi Windows CSI-u trust lifecycle * test(terminal): name foreground retry timing * test(git): accept bounded SSH remote probes --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
) (stablyai#7668) * fix(terminal): send CSI-u Shift+Enter to kitty TUIs (droid) on Windows (stablyai#7620) On Windows, Shift+Enter was always sent as the Alt+Enter byte ESC+CR (added in stablyai#2418 for Codex, which reads win32-input-mode and ignores CSI-u). droid speaks the kitty keyboard protocol, parses CSI-u directly, and treats ESC+CR as a plain Enter — so Shift+Enter SUBMITTED the message instead of inserting a newline. droid works in other terminals (Windows Terminal, Warp) because those honor win32-input-mode / kitty; Orca (xterm.js) withholds kitty from local Windows ConPTY panes and emits neither. Make the Windows Shift+Enter byte pane-aware: latch whether a pane's program advertised the kitty keyboard protocol (query CSI ? u, push CSI > .. u, or set CSI = .. u) and send CSI-u (\x1b[13;2u) to those panes, keeping the Codex-compatible ESC+CR for win32-input-mode-only TUIs. Non-Windows is unchanged (always CSI-u). Verified end-to-end against the real droid and Codex CLIs through the actual production functions: droid now newlines, Codex still newlines. * fix(terminal): route Windows Shift+Enter safely for Droid --------- Co-authored-by: Neil <neil@stably.ai> Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
…tablyai#11769) * fix(terminal): trust Pi CSI-u Shift+Enter on Windows (stablyai#9703) Pi enables the Kitty keyboard protocol at startup and decodes CSI-u, but TUI_AGENT_CONFIG['pi'] never set windowsShiftEnterEncoding, so on Windows Pi could only get CSI-u via the flaky live-KKP-flag path (isKittyKeyboardActivePane). After a tool ran a subprocess that emitted a reset sequence, the KKP flags dropped to 0, Orca sent Esc+CR, and Pi read it as plain Enter -> submit. It recovered on the next pane refocus. Set windowsShiftEnterEncoding: 'csi-u' for pi, mirroring the Droid fix (stablyai#7668), so the trusted CSI-u route covers Pi reliably independent of KKP-flag churn from tool subprocesses. * fix(terminal): complete Pi Windows CSI-u trust lifecycle * test(terminal): name foreground retry timing * test(git): accept bounded SSH remote probes --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
Summary
Fixes #7620. On native Windows ConPTY panes, Shift+Enter now sends Droid's CSI-u newline sequence only while the current PTY process is freshly confirmed as Droid. Codex, Antigravity, shells, WSL, SSH, paired web, and remote runtimes retain the legacy Windows sequence; macOS and Linux behavior is unchanged.
Reliability proof
Reliability invariant:
terminal-input.windows-modified-enter-routing— CSI-u may be routed only to a currently confirmed Droid process belonging to the active local Windows ConPTY. New commands, PTY replacement, exit evidence, focus/visibility recovery, and unavailable inspection revoke or fail closed to legacy routing.Product change type: Runtime hardening plus experimental reliability-gate coverage.
Correctness evidence:
Performance evidence: Ordinary keys and fast shell completion perform no process scan. Routing recovery uses cancellable one-shot reads on the existing 350 ms / 1.2 s / 6 s ladder; process snapshots are deduplicated, and the bounded ConPTY helper starts only after a recognized candidate exists. WSL/SSH/remote paths perform zero confirmation scans. No polling, provider fanout, hidden-pane wake loop, telemetry, or raw terminal logging was added.
Validation:
pnpm typecheckpnpm lintProvider/platform coverage:
Promotion status: Experimental / partial. The deterministic gate is active, but native Windows ConPTY evidence is not yet blocking CI.
Rollback/demotion rule: Demote if any non-Droid/remote pane receives CSI-u, the Windows byte test flakes or silently skips on Windows, or routing adds polling, ordinary-key scans, provider fanout, or unbounded subprocess work.
Security audit
No dependency, credential, network, workflow, telemetry, raw-output logging, dynamic-evaluation, or arbitrary-filesystem behavior was added. The only new subprocess path is a fixed node-pty ConPTY membership helper with validated integer input, bounded output, a three-second timeout, and fail-closed cleanup.
Residual gap
Native Windows ConPTY was unavailable during maintainer takeover. The Windows-specific Electron assertion and deterministic process/membership suites cover the contract, but a live Windows Droid artifact remains follow-up evidence.