Repository navigation
fix(pty): deliver multiline agent-launch prompts via bracketed paste - #7487
Conversation
Multiline agent-launch prompts (claude/codex/opencode argv injection) were mangled when Orca typed the startup command into the interactive shell. The command is single-quoted, but its literal embedded newlines survive quoting; bash readline / zsh zle read every raw LF as accept-line (Enter), so the first newline submits an unterminated single-quoted command, drops the shell into PS2 (>) continuation, and the rest executes piecemeal — backticks/$ evaluate, quotes go unbalanced, and the agent never receives the intact prompt. Short single-line prompts worked because they have no embedded newline. Fix: when a startup command contains a newline, wrap the payload in bracketed-paste markers (ESC[200~ … ESC[201~) before the trailing submit CR/LF so the line editor inserts the multiline text literally and only the trailing byte submits it. The single-line fast path is unchanged. Gated on the target line editor having bracketed-paste mode active (Orca-wrapped bash/zsh) so shells without it never echo the markers as garbage; Orca's bash rc wrappers now force `enable-bracketed-paste on` (zsh has it on by default). Applied consistently across every startup-command delivery path: - src/main/providers/local-pty-shell-ready.ts (in-process / degraded local) - src/main/daemon/terminal-host.ts (daemon host — primary local) - src/relay/pty-handler.ts (SSH relay, remote host) - src/renderer/src/lib/ssh-background-startup-delivery.ts (hidden SSH tab) All share src/shared/startup-command-submission.ts. Windows cmd.exe and other shells keep the current CR submit path (no regression); PSReadLine/POSIX bash/zsh get the fix.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds a shared Sequence Diagram(s)sequenceDiagram
participant Caller
participant buildStartupCommandSubmission
participant ShellSession
Caller->>buildStartupCommandSubmission: command, submit, bracketedPasteSafe
alt multiline and bracketedPasteSafe
buildStartupCommandSubmission->>buildStartupCommandSubmission: wrap in bracketed-paste markers
end
buildStartupCommandSubmission-->>Caller: formatted payload
Caller->>ShellSession: write(payload)
Compact MetadataType: Enhancement Related issues: None identified from provided data. Poem A startup line once split by newline spray, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
🧹 Nitpick comments (2)
src/main/providers/local-pty-shell-ready.ts (1)
122-126: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueDuplicate bracketed-paste rc snippet across main-bundle files.
This 5-line block (comment +
bindcommand) is identical tosrc/main/daemon/shell-ready.tslines 98-102. Unlike the relay wrapper (which must stay self-contained per the cross-bundle constraint), both this file anddaemon/shell-ready.tslive in the same main-process bundle, so a small shared helper (e.g. exporting the snippet string from a common module) would avoid the two copies drifting out of sync.src/main/providers/local-pty-provider.ts (1)
807-822: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMissing test coverage for the new shell-name-based
bracketedPasteSafebranch.This new logic (bash/zsh → true, everything else/win32 → false) isn't exercised by the tests in this cohort —
local-pty-shell-ready.test.tsonly testswriteStartupCommandWhenShellReadydirectly with an explicitbracketedPasteSafeoption, not this derivation inspawn().
[recommended_refactor]
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: ac05268f-6280-43db-a1ff-61bbd9a66a14
📒 Files selected for processing (10)
src/main/daemon/shell-ready.tssrc/main/daemon/terminal-host.tssrc/main/providers/local-pty-provider.tssrc/main/providers/local-pty-shell-ready.test.tssrc/main/providers/local-pty-shell-ready.tssrc/relay/pty-handler.tssrc/relay/pty-shell-launch.tssrc/renderer/src/lib/ssh-background-startup-delivery.tssrc/shared/startup-command-submission.test.tssrc/shared/startup-command-submission.ts
Strip the entire CRLF terminator (or lone CR/LF) from startup commands before checking if the body contains newline characters. Previously, slicing off only the last character of a CRLF-terminated command left a trailing CR in the body. This caused a single-line command to be incorrectly categorized as multiline and wrapped in bracketed paste.
…tablyai#7487) * fix(pty): deliver multiline agent-launch prompts via bracketed paste Multiline agent-launch prompts (claude/codex/opencode argv injection) were mangled when Orca typed the startup command into the interactive shell. The command is single-quoted, but its literal embedded newlines survive quoting; bash readline / zsh zle read every raw LF as accept-line (Enter), so the first newline submits an unterminated single-quoted command, drops the shell into PS2 (>) continuation, and the rest executes piecemeal — backticks/$ evaluate, quotes go unbalanced, and the agent never receives the intact prompt. Short single-line prompts worked because they have no embedded newline. Fix: when a startup command contains a newline, wrap the payload in bracketed-paste markers (ESC[200~ … ESC[201~) before the trailing submit CR/LF so the line editor inserts the multiline text literally and only the trailing byte submits it. The single-line fast path is unchanged. Gated on the target line editor having bracketed-paste mode active (Orca-wrapped bash/zsh) so shells without it never echo the markers as garbage; Orca's bash rc wrappers now force `enable-bracketed-paste on` (zsh has it on by default). Applied consistently across every startup-command delivery path: - src/main/providers/local-pty-shell-ready.ts (in-process / degraded local) - src/main/daemon/terminal-host.ts (daemon host — primary local) - src/relay/pty-handler.ts (SSH relay, remote host) - src/renderer/src/lib/ssh-background-startup-delivery.ts (hidden SSH tab) All share src/shared/startup-command-submission.ts. Windows cmd.exe and other shells keep the current CR submit path (no regression); PSReadLine/POSIX bash/zsh get the fix. * Fix multiline detection for CRLF-terminated startup commands Strip the entire CRLF terminator (or lone CR/LF) from startup commands before checking if the body contains newline characters. Previously, slicing off only the last character of a CRLF-terminated command left a trailing CR in the body. This caused a single-line command to be incorrectly categorized as multiline and wrapped in bracketed paste.
Bug
Multiline agent-launch prompts get mangled when Orca types the startup command into the interactive shell. Every argv / flag-prompt injection-mode agent (claude, codex, opencode, …) is affected whenever the launch prompt contains a newline. Short single-line prompts work.
Root cause
The startup command (e.g.
claude '--dangerously-skip-permissions' '<prompt>') was written to the PTY as raw bytes plus a trailing submit char (\nPOSIX /\rwin32). The prompt is single-quoted byquoteStartupArg, but its literal embedded newlines survive quoting. bash readline / zsh zle treat every embedded LF asaccept-line(Enter), so the first newline inside the prompt submits an incomplete command with an unterminated single quote and drops the shell into PS2 (>) continuation. Subsequent lines run piecemeal, backticks/$evaluate, quotes go unbalanced, and the agent never receives the intact prompt.Fix
When a startup command contains a newline, wrap the payload in bracketed-paste markers (
ESC[200~…ESC[201~) before the trailing submit CR/LF. The line editor then inserts the multiline text literally and only the trailing byte submits it. The single-line fast path is unchanged.Wrapping is gated on the target line editor having bracketed-paste mode active, so shells without it never echo the markers as literal garbage:
bind 'set enable-bracketed-paste on'(guarded to interactive shells); zsh has it on by default.cmd.exeand other/unknown shells keep the existing CR submit path — no regression to the win32 behavior. PSReadLine and POSIX bash/zsh get the fix.All delivery paths share a single helper,
src/shared/startup-command-submission.ts.Paths / platforms covered
src/main/providers/local-pty-shell-ready.ts(+ call site inlocal-pty-provider.ts)src/main/daemon/terminal-host.ts+shell-ready.tsbash wrappersrc/relay/pty-handler.ts+pty-shell-launch.tsbash wrappersrc/renderer/src/lib/ssh-background-startup-delivery.tsterminal.createTests
src/shared/startup-command-submission.test.ts— unit tests for the shared payload builder (single-line unchanged, multiline wrapped, trailing-submit handling, unsafe-shell raw fallback).src/main/providers/local-pty-shell-ready.test.ts— regression tests: a command containing a newline is written wrapped inESC[200~/ESC[201~with a trailing submit; a single-line command is written unchanged; multiline stays raw when bracketed paste is unsafe.typecheckand the touched test suites pass.Made with Orca 🐋