Skip to content

fix(terminal): trust Pi CSI-u Shift+Enter on Windows (#9703) - #11769

Merged
OrcaWin merged 5 commits into
stablyai:mainfrom
itisvincent:fix/pi-windows-shift-enter-csi-u
Aug 2, 2026
Merged

OrcaWin merged 5 commits into
stablyai:mainfrom
itisvincent:fix/pi-windows-shift-enter-csi-u

Conversation

@itisvincent

Copy link
Copy Markdown
Contributor

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 set windowsShiftEnterEncoding. 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 < u pop), the TerminalKittyKeyboardModeTracker flags drop to 0, Orca sends Esc+CR, and Pi reads it as plain Enter → submit. On refocus, scanReplay re-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' for pi, 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 run on the changed suites — 74/74 pass.
  • pnpm exec oxlint + pnpm exec oxfmt --check on changed files — clean.

Cross-platform / compatibility notes

  • Only affects Windows hosts where Pi is the trusted foreground agent. macOS/Linux already send CSI-u and are unaffected.
  • Other agents without windowsShiftEnterEncoding keep the legacy Esc+CR fallback unchanged.
  • No UI/visual change. No perf impact (a record property read).

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

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.
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 11a4af58-ec88-4835-9c62-2ce53cd82a57

📥 Commits

Reviewing files that changed from the base of the PR and between 904f7c9 and cb4cdb8.

📒 Files selected for processing (3)
  • src/main/azure-devops/pull-request-creation.test.ts
  • src/main/azure-devops/repository-ref.test.ts
  • src/main/bitbucket/repository-ref.test.ts

📝 Walkthrough

Walkthrough

The 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 AbortSignal options.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix, root cause, testing, compatibility, and notes but omits the required AI Review Report and Security Audit sections. Add the AI Review Report and Security Audit sections, and update the testing checklist to reflect the completed checks.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Pi Windows Shift+Enter CSI-u trust fix.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

This 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 TUI_AGENT_CONFIG entry lacked windowsShiftEnterEncoding: 'csi-u', so after a tool subprocess reset the live KKP flag state, Orca fell back to Esc+CR which Pi reads as plain Enter.

  • Core fix (tui-agent-config.ts): adds windowsShiftEnterEncoding: 'csi-u' to Pi's config, identical to the existing Droid entry.
  • Generalization (pty-connection.ts): the reconfirmation guard is widened from a hardcoded agent !== 'droid' check to a config-driven windowsShiftEnterEncoding !== 'csi-u' check, so any future CSI-u agent automatically benefits.
  • Process recognition (agent-process-recognition.ts): adds PI_AGENT_NODE_ENTRYPOINT_RE to identify Pi from the Windows process command line via its exact npm package path, scoped to the two known publishers.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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

@AmethystLiang
AmethystLiang requested a review from OrcaWin July 31, 2026 16:49
@AmethystLiang
AmethystLiang requested review from nwparker and removed request for OrcaWin August 2, 2026 06:54
@AmethystLiang

Copy link
Copy Markdown
Contributor

@nwparker is reviewing now

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/renderer/src/components/terminal-pane/pty-connection.ts (1)

2947-2952: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update 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, requestKnownWindowsShiftEnterReconfirmation gates on any agent with windowsShiftEnterEncoding: 'csi-u' in TUI_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 value

Use the named retry-ladder constants for consistency.

This line hardcodes 350 + 1200 + 6000 for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 50a4107 and d87647d.

📒 Files selected for processing (10)
  • src/main/providers/agent-foreground-process-pi.test.ts
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.test.ts
  • src/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.ts
  • src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.ts
  • src/shared/agent-process-recognition.test.ts
  • src/shared/agent-process-recognition.ts
  • src/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

@OrcaWin
OrcaWin merged commit e58c051 into stablyai:main Aug 2, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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>
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.

[Bug] Shift+Enter submits instead of newline in Pi after running a tool (Windows + Git Bash) — Pi missing windowsShiftEnterEncoding

3 participants