Skip to content

fix(pty): deliver multiline agent-launch prompts via bracketed paste - #7487

Merged
AmethystLiang merged 2 commits into
mainfrom
fix-multiline-agent-prompt-delivery
Jul 6, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
fix-multiline-agent-prompt-delivery

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

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 (\n POSIX / \r win32). The prompt is single-quoted by quoteStartupArg, but its literal embedded newlines survive quoting. bash readline / zsh zle treat every embedded LF as accept-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:

  • Orca's bash rc wrappers now force bind 'set enable-bracketed-paste on' (guarded to interactive shells); zsh has it on by default.
  • Windows cmd.exe and 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

Path File
In-process / degraded local PTY src/main/providers/local-pty-shell-ready.ts (+ call site in local-pty-provider.ts)
Daemon host (primary local) src/main/daemon/terminal-host.ts + shell-ready.ts bash wrapper
SSH relay (remote host) src/relay/pty-handler.ts + pty-shell-launch.ts bash wrapper
Hidden SSH automation tab src/renderer/src/lib/ssh-background-startup-delivery.ts
Remote runtime terminal.create routed to daemon/local provider above (server-side)
  • POSIX bash/zsh: bracketed paste, gated on the Orca wrapper being active.
  • Windows: PSReadLine benefits where bracketed paste is honored; cmd.exe stays on CR (unchanged).
  • SSH / runtime: fixed consistently, gated on the shell-ready marker (Orca wrapper) being active.

Tests

  • 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 in ESC[200~/ESC[201~ with a trailing submit; a single-line command is written unchanged; multiline stays raw when bracketed paste is unsafe.

typecheck and the touched test suites pass.

Made with Orca 🐋

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

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c385dd26-e9b6-455b-9883-eab851c7a6f9

📥 Commits

Reviewing files that changed from the base of the PR and between 9a8f2fd and 8926cc9.

📒 Files selected for processing (2)
  • src/shared/startup-command-submission.test.ts
  • src/shared/startup-command-submission.ts

📝 Walkthrough

Walkthrough

This PR adds a shared buildStartupCommandSubmission helper for formatting startup-command bytes, including optional bracketed-paste wrapping for multiline input. The helper is used in daemon, local PTY, relay, and SSH background startup delivery paths, with bracketedPasteSafe derived from shell-ready support or shell type. Bash rc/wrapper content now enables bracketed paste for interactive shells. New tests cover the helper and updated local PTY write behavior.

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)
Loading

Compact Metadata

Type: Enhancement
Estimated review effort: Medium-High

Related issues: None identified from provided data.
Related PRs: None identified from provided data.
Suggested labels: enhancement, terminal, pty
Suggested reviewers: None identified from provided data.

Poem

A startup line once split by newline spray,
now wraps in paste and travels clean away.
The shell-ready path, the relay, daemon too,
all hand the same payload straight through.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix, but it does not use the required template sections for Summary, Screenshots, Testing, AI Review Report, Security Audit, or Notes. Rewrite the PR description to match the template and add the missing sections, including testing checklist, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing multiline agent-launch prompt delivery with bracketed paste.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

🧹 Nitpick comments (2)
src/main/providers/local-pty-shell-ready.ts (1)

122-126: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Duplicate bracketed-paste rc snippet across main-bundle files.

This 5-line block (comment + bind command) is identical to src/main/daemon/shell-ready.ts lines 98-102. Unlike the relay wrapper (which must stay self-contained per the cross-bundle constraint), both this file and daemon/shell-ready.ts live 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 win

Missing test coverage for the new shell-name-based bracketedPasteSafe branch.

This new logic (bash/zsh → true, everything else/win32 → false) isn't exercised by the tests in this cohort — local-pty-shell-ready.test.ts only tests writeStartupCommandWhenShellReady directly with an explicit bracketedPasteSafe option, not this derivation in spawn().
[recommended_refactor]


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ac05268f-6280-43db-a1ff-61bbd9a66a14

📥 Commits

Reviewing files that changed from the base of the PR and between 7c1d58e and 9a8f2fd.

📒 Files selected for processing (10)
  • src/main/daemon/shell-ready.ts
  • src/main/daemon/terminal-host.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/providers/local-pty-shell-ready.test.ts
  • src/main/providers/local-pty-shell-ready.ts
  • src/relay/pty-handler.ts
  • src/relay/pty-shell-launch.ts
  • src/renderer/src/lib/ssh-background-startup-delivery.ts
  • src/shared/startup-command-submission.test.ts
  • src/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.
@AmethystLiang
AmethystLiang merged commit 2f52f0d into main Jul 6, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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