Repository navigation
fix(terminal): trust Pi CSI-u Shift+Enter on Windows (#9703) - #11769
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe change recognizes supported Pi Node entrypoints and configures Pi to use CSI-u encoding on Windows. Terminal reconfirmation APIs now use Windows Shift+Enter terminology. PTY routing invalidates trusted CSI-u agent state and re-samples foreground ownership during input, exit, visibility, and focus events. Tests cover Pi foreground detection, encoding selection, binding behavior, routing transitions, stale-state cleanup, and SSH provider 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
Greptile SummaryThis PR fixes Shift+Enter submitting messages in Pi on Windows (Git Bash) after a tool run spawns a child process. The root cause was that Pi's
Confidence Score: 5/5Safe to merge; the change is a narrow, well-tested config addition that mirrors an already-proven pattern for Droid. The fix is a single config property on Pi's entry, matching the existing Droid config exactly. The accompanying generalization in pty-connection.ts replaces a hardcoded agent name check with a config-driven one, reducing future divergence risk. New and updated tests cover the trusted/untrusted foreground distinction, the no-OSC lifecycle, and the stale-routing revocation on focus. macOS and Linux are unaffected by the Windows-specific code path, and agents without windowsShiftEnterEncoding keep the unchanged legacy fallback. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/shared/tui-agent-config.ts | Adds windowsShiftEnterEncoding: 'csi-u' to Pi's config, mirroring the existing Droid entry; this is the core one-line fix for the bug. |
| src/shared/agent-process-recognition.ts | Adds PI_AGENT_NODE_ENTRYPOINT_RE regex to recognize Pi's npm shim (@earendil-works or @mariozechner scopes only) from the Windows process command line, paralleling the existing Cursor entrypoint pattern. |
| src/renderer/src/components/terminal-pane/pty-connection.ts | Renames requestKnownDroidReconfirmation to requestKnownWindowsShiftEnterReconfirmation and generalizes the guard from a hardcoded agent !== 'droid' check to a config-driven windowsShiftEnterEncoding !== 'csi-u' check, covering Pi and any future CSI-u agents. |
| src/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.ts | Renames requestDroidReconfirmation to requestWindowsShiftEnterReconfirmation on the exported TerminalReconfirmationBinding type and its call site. |
| src/renderer/src/components/terminal-pane/keyboard-handlers.ts | Single rename: updates the inline binding cast from requestDroidReconfirmation? to requestWindowsShiftEnterReconfirmation? to match the new type. |
| src/renderer/src/components/terminal-pane/pty-connection.test.ts | Adds two new test cases for Pi (no-OSC lifecycle + focus-after-exit revocation), renames requestDroidReconfirmation references, and extracts timing constants to a shared scope. |
| src/main/providers/agent-foreground-process-pi.test.ts | New test file verifying that the Pi npm entrypoint is correctly resolved to { available: true, processName: 'pi' } when the process appears in the Windows ConPTY set. |
Reviews (4): Last reviewed commit: "test(git): accept bounded SSH remote pro..." | Re-trigger Greptile
|
@nwparker is reviewing now |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)
2947-2952: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUpdate the stale "Droid" reference in this comment.
This comment still says the seeded command-start confirmation "authorizes Droid's Windows Shift+Enter CSI-u routing." After this PR's generalization,
requestKnownWindowsShiftEnterReconfirmationgates on any agent withwindowsShiftEnterEncoding: 'csi-u'inTUI_AGENT_CONFIG, not only Droid. Pi now shares this path. Update the wording to describe the general CSI-u mechanism instead of naming Droid specifically, so future readers do not assume the seeding is Droid-only.📝 Suggested comment wording
- // one would never gain the fresh process evidence that authorizes Droid's - // Windows Shift+Enter CSI-u routing — leaving Shift+Enter to submit (`#7620`). + // one would never gain the fresh process evidence that authorizes CSI-u + // Windows Shift+Enter routing for the launched agent — leaving Shift+Enter + // to submit (`#7620`).src/renderer/src/components/terminal-pane/pty-connection.test.ts (1)
7093-7093: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse the named retry-ladder constants for consistency.
This line hardcodes
350 + 1200 + 6000for the confirmation retry wait. The later test in this same file (lines 22873-22875) waits on the same retry ladder using named constants (VISIBLE_PTY_SETTLE_MS,WRAPPER_RESOLVE_RETRY_MS,SECOND_WRAPPER_RETRY_MS). Use the same constants here so a future change to the retry timing does not silently desync this test from the implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 165ab672-e0ad-4438-929f-97958aa095b7
📒 Files selected for processing (10)
src/main/providers/agent-foreground-process-pi.test.tssrc/renderer/src/components/terminal-pane/keyboard-handlers.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.test.tssrc/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.tssrc/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.tssrc/shared/agent-process-recognition.test.tssrc/shared/agent-process-recognition.tssrc/shared/tui-agent-config.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/shared/tui-agent-config.ts
- src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.ts
…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 #9703 — on Windows + Git Bash, Shift+Enter in Pi inserts a newline right after start/refocus but submits the message immediately after Pi runs a tool that spawns a child process, then recovers on the next pane refocus.
Root cause
Pi enables the Kitty keyboard protocol at startup and decodes CSI-u, but
TUI_AGENT_CONFIG['pi']never setwindowsShiftEnterEncoding. So on Windows, Pi could only get CSI-u via the flaky live-KKP-flag path (isKittyKeyboardActivePane). During a tool run, something in Pi's re-render/tool path emits a reset sequence (RIS / DECSTR / alt-screen swap /CSI < upop), theTerminalKittyKeyboardModeTrackerflags drop to 0, Orca sendsEsc+CR, and Pi reads it as plain Enter → submit. On refocus,scanReplayre-applies Pi's startup KKP push → flags > 0 → Shift+Enter works again. This matches the observed “works after start/refocus, breaks after a tool run” pattern.Fix
Set
windowsShiftEnterEncoding: 'csi-u'forpi, mirroring the existing Droid fix (#7668). This routes Shift+Enter through the trusted CSI-u path (hasTrustedWindowsCsiU) independently of the live KKP-flag churn from tool subprocesses, so a newline stays a newline for the life of the pane.The same class of issue was already fixed for Droid (#7620 / #7668 / #8948) and Grok (#8385); Pi was simply never given the config those fixes introduced.
Test
New case in
terminal-windows-shift-enter.test.ts: trusted Pi foreground evidence resolves to'csi-u'; launch-only evidence (no trusted foreground) stays'alt-enter'.Verification
pnpm typecheck— clean.pnpm exec vitest runon the changed suites — 74/74 pass.pnpm exec oxlint+pnpm exec oxfmt --checkon changed files — clean.Cross-platform / compatibility notes
windowsShiftEnterEncodingkeep the legacyEsc+CRfallback unchanged.Relationship to #10511
This is the Shift+Enter half of #10511, split out and rebased onto current
main. The OpenCode Windows-data-dir half of #10511 (#10332) was fixed upstream independently in #10362, which is why #10511 now conflicts. #10511 can be closed in favor of this Pi-only PR.Closes #9703
X handle: @itisvincent