Skip to content

fix(mobile): use desktop's terminal paste, key and query-reply rules - #33957

Merged
AmoabaKelvin merged 8 commits into
mainfrom
mobile-terminal-input-parity
Oct 27, 2026
Merged

AmoabaKelvin merged 8 commits into
mainfrom
mobile-terminal-input-parity

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​139 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137
Prod 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251 $\color{#cf222e}{\Huge{\mathbf{−}}}$​100 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151

ELI5

When you paste into a terminal or press keys like Shift+Enter or the arrow keys on the phone, the phone now sends the same bytes the desktop app sends. Before, it had its own simpler rules, so a pasted prompt could submit early, Shift+Enter submitted instead of adding a newline, and arrow keys did nothing in some full-screen programs.

What Changed

  • Paste framing (terminal Add Shift+Enter to insert newline in terminal #3, session-shell Improve terminal font rendering, per-pane zoom, and UI zoom #7). The phone's text paste now uses desktop's shared wrapTerminalBracketedPasteText / normalizeTerminalPasteLineEndings (src/shared/terminal-bracketed-paste-text.ts), the same framing xterm's paste() does on desktop.
    • Before: no bracketing on the alternate screen, newlines sent as LF, and only the literal ESC[200~/ESC[201~ markers stripped. A multi-line paste into OpenCode, vim insert mode or another full-screen app arrived as separate lines, so each newline acted as Enter.
    • Now: framed whenever the app enabled bracketed paste, newlines become CR, and every ESC inside the frame becomes ␛.
  • Shift+Enter and Ctrl+Backspace (terminal Fix Ctrl+Backspace not deleting word in terminal #2). Desktop's Enter/Backspace encoding moved from terminal-shortcut-policy.ts into src/shared/terminal-modified-enter-encoding.ts; desktop calls it from the same place.
    • Ctrl+Backspace custom keys now send \x17 (delete word), not \b.
    • A Shift+Enter custom key is stored as the Kitty form and encoded when sent, using the pane's negotiated modes: CSI-u when the app pushed Kitty flags, CSI 27;2;13~ when it armed modifyOtherKeys (Pi), else ESC CR. Before, it sent \r, which submits.
    • To know those modes, the phone's xterm now runs desktop's shared TerminalKittyKeyboardModeTracker over its output. It is seeded from the host snapshot's kittyKeyboardFlags with the same rule desktop uses, now one shared adoptSnapshot method that both call. The phone reports the result in its existing modes message.
  • Arrow, Home and End keys follow DECCKM (terminal Improve terminal font rendering, per-pane zoom, and UI zoom #7). The modes message now carries applicationCursorKeysMode. Accessory keys, custom keys and hardware arrows send ESC O A etc. while it is set, as xterm does, and keep CSI when Kitty flags are active, as xterm's Kitty encoder does. Before, they always sent ESC [ A, which less, mc and keypad-mode curses apps ignore.
  • Query replies when the phone drives (terminal Fix MaxListenersExceededWarning with singleton PTY dispatcher #6, partial).
    • The phone's xterm now answers OSC 7501 (program status) with the shared responder desktop installs. The phone only sends it when the host advertises terminal.program-status.v1, as desktop gates it.
    • The host now applies its existing per-agent reply policy (shouldForwardHeadlessTerminalQueryReply: no OSC color replies for jcode, no XTVERSION for grok) to replies from the phone. Before, the phone answered jcode's color queries, which jcode can render as input ([Bug]: Raw OSC 10/11 color-query replies leak as text in Linux agent pane (opencode) #12112).

Why

The audit found the phone re-implementing these rules and drifting from desktop. Each rule now has one copy in src/shared (or on the host), and the phone calls it.

Linked Issue

Part of the mobile/desktop parity audit

Visual Proof

N/A: this adopts desktop's existing behavior. The rules are src/shared/terminal-bracketed-paste-text.ts, src/shared/terminal-modified-enter-encoding.ts, xterm's DECCKM key encoding, src/shared/program-status/query-responder.ts and src/main/runtime/headless-terminal-query-reply-policy.ts.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Focused tests: mobile src/session + src/terminal (377 files), desktop terminal-pane + terminal-send + kitty tracker. New tests cover the paste frame in an alt-screen app, Shift+Enter/Ctrl+Backspace bytes, DECCKM/Kitty cursor encoding, and the program-status capability gate. No device run for this fleet.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Mobile behaviors removed:

  • Skipping bracketed paste on the alternate screen.
  • Sending pasted newlines as LF, and passing other ESC bytes through a bracketed paste.
  • \b for Ctrl+Backspace and \r for Shift+Enter in custom keys. Custom keys saved before this change keep their old bytes until re-created.

Not done, and why:

  • Windows trusted Shift+Enter evidence. Desktop also sends CSI-u on Windows hosts when it sees a Droid/Pi foreground agent. The phone gets neither the host platform nor the foreground agent, so it falls back to the negotiated-mode rule.
  • Ctrl+Enter. Desktop sends CSI 13;5u except on local Windows ConPTY panes without evidence. A custom key is saved with no pane, and CSI-u would print as text in a Windows shell, so the phone keeps \r.
  • Kitty keyboard advertisement. The phone's xterm doesn't advertise it. The phone doesn't encode keys through xterm, so advertising it would promise encodings it doesn't send.
  • ConPTY DA1 variant. Not done: the phone doesn't know the host platform, and the daemon already answers spawn-time DA1.

Mixed versions:

  • An old host just doesn't send kittyKeyboardFlags, and the tracker keeps what it saw live.
  • An old phone ignores the new host-side reply filter.
  • The new modes fields stay inside the app.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 27, 2026 00:24
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eae49af0-9da3-4ef4-b9c0-78277f556323
Commits

Reviewing files that changed from the base of the PR and between 3fddecf and 075a59d.

Files selected for processing: 2
  • mobile/src/session/use-mobile-session-terminal-subscription.ts
  • mobile/src/terminal/document/mode-mirroring.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Walkthrough

The changes add terminal keyboard-mode tracking and propagation, then use those modes to encode mobile terminal input. They add program-status query-reply handling with host capability and runtime forwarding checks. Mobile clipboard paste now wraps text in bracketed-paste markers whenever bracketed-paste mode is enabled, including in alternate-screen mode.

Priority: Normal

Merge Risk: Minimal · up to 075a5

No actionable merge-blocking issue remains in the reviewed changes; normal checks should still run before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately summarizes the main mobile terminal parity changes for paste, key handling, and query replies.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, testing, limitations, compatibility, and checklist. The Linked Issue section does not contain an actual issue number …
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
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.
Full details: Description check

Explanation

The description is detailed and covers the user impact, implementation, rationale, testing, limitations, compatibility, and checklist. The Linked Issue section does not contain an actual issue number or link, and the full lint, typecheck, test, and build checks are not marked as passing, but the description is otherwise substantially complete.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e380ea00-ff07-4802-9658-a86a9378a6ce
Commits

Reviewing files that changed from the base of the PR and between 8851890 and 3fddecf.

Files selected for processing: 38
  • mobile/src/session/mobile-image-live-input-order.test.tsx
  • mobile/src/session/mobile-worker-takeover-send-sites.test.ts
  • mobile/src/session/terminal-field-submit-binding-send.test.tsx
  • mobile/src/session/use-mobile-session-tab-reconciliation.ts
  • mobile/src/session/use-mobile-session-terminal-input.ts
  • mobile/src/session/use-mobile-session-terminal-send-actions.ts
  • mobile/src/session/use-mobile-session-terminal-subscription.ts
  • mobile/src/session/use-mobile-terminal-paste.test.ts
  • mobile/src/session/use-mobile-terminal-paste.ts
  • mobile/src/terminal/document/document-scope.ts
  • mobile/src/terminal/document/document-terminal-shape.ts
  • mobile/src/terminal/document/host-message-router.ts
  • mobile/src/terminal/document/mode-mirroring.ts
  • mobile/src/terminal/document/query-reply.ts
  • mobile/src/terminal/document/terminal-init.ts
  • mobile/src/terminal/mobile-terminal-query-reply.test.ts
  • mobile/src/terminal/mobile-terminal-query-reply.ts
  • mobile/src/terminal/terminal-accessory-keys.test.ts
  • mobile/src/terminal/terminal-accessory-keys.ts
  • mobile/src/terminal/terminal-key-mode-encoding.test.ts
  • mobile/src/terminal/terminal-key-mode-encoding.ts
  • mobile/src/terminal/terminal-webview-contract.ts
  • mobile/src/terminal/terminal-webview-messages.ts
  • mobile/src/terminal/terminal-webview-notification-dispatch.ts
  • mobile/src/terminal/use-terminal-webview-controller.ts
  • mobile/src/test-support/rpc-recording/adapters/session-terminal-gesture-mount-adapters.ts
  • mobile/src/test-support/rpc-recording/adapters/session-terminal-input-mount-adapters.ts
  • mobile/src/test-support/rpc-recording/adapters/terminal-mount-adapters.ts
  • src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
  • src/main/runtime/rpc/terminal-send.test.ts
  • src/main/runtime/terminal/output/headless-terminal-state.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/terminal-keyboard-runtime.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts
  • src/shared/terminal-kitty-keyboard-mode-tracker.ts
  • src/shared/terminal-modified-enter-encoding.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@AmoabaKelvin
AmoabaKelvin force-pushed the mobile-terminal-input-parity branch from 3fddecf to 67f4ed6 Compare October 27, 2026 01:08
@AmoabaKelvin
AmoabaKelvin force-pushed the mobile-terminal-input-parity branch from 26a1e12 to bbd1b79 Compare October 27, 2026 02:58
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