Skip to content

feat(cli): accept terminal send text from stdin - #12239

Open
logii wants to merge 6 commits into
stablyai:mainfrom
logii:feat/terminal-send-text-stdin
Open

logii wants to merge 6 commits into
stablyai:mainfrom
logii:feat/terminal-send-text-stdin

Conversation

@logii

@logii logii commented Aug 3, 2026 •

Copy link
Copy Markdown

ELI5

Terminal text can now come from a pipe, so generated multiline text can use the
same stdin route that computer actions already support.

What Changed

Previously, terminal send --text-stdin was rejected as an unknown flag. It now
accepts UTF-8 stdin through the existing computer-action reader, with a
terminal-only raw input bound of 16 MiB. Conflicting text sources and invalid
wait/retry flags fail before reading stdin; the resolved text then follows the
current prompt preflight, request identity, wait, receipt and refusal behavior.
Empty stdin remains legal, including bare Enter, while empty prompt retries and
computer type/paste text remain invalid.

Why

This adapts logii's original reader-extraction approach from #12239 to the current
extracted CLI modules. Sharing the reader gives stdin parity without a file or
base64 mode, streamed terminal writes, a new RPC shape or a launcher redesign.
It does not claim to fix shell expansion or a native bridge defect.

Linked Issue

Fixes #16113

Visual Proof

N/A — no rendered UI or native focus change. The actual freshly built CLI was
run on macOS arm64 with a finite stdin pipe into an owned, bounded local JSON RPC
fixture; no app or user terminal received input. The complete raw CLI receipts
and readable before/after evidence
include argv/help/empty-Enter controls, separate Enter flags, exact retry identity,
and cleanup. Public artifact links expire November 1, 2026; the essential actual
outputs are retained below in this PR.

The same 89-byte valid UTF-8 input contains quotes, backticks, dollar syntax,
CRLF, slash commands, multibyte characters and a trailing newline. Captured text
SHA256: c66430f590ee0c28f45d7abfb0e9174ed2ced1d903d6afc07259de3b9dda1dd9.
This proves the CLI pipe/payload boundary, not native PTY input, host deduplication,
Windows/WSL/PowerShell/MSYS launcher forwarding, SSH or remote delivery.

Before: unknown flag, exit 1, zero RPC requests

Recorded at main 1fc24d311481a85d5b4ae596898ee072389f040c for
terminal send --terminal term-disposable-fixture --text-stdin --json,
with the finite fixture pipe:

{
  "id": "local",
  "ok": false,
  "error": {
    "code": "invalid_argument",
    "message": "Unknown flag --text-stdin for command: terminal send",
    "data": {
      "validFlags": [
        "enter",
        "environment",
        "help",
        "interrupt",
        "json",
        "pairing-code",
        "retry-request",
        "terminal",
        "text",
        "wait-submit"
      ],
      "suggestions": [],
      "nextSteps": [
        "Valid flags: --enter, --environment, --help, --interrupt, --json, --pairing-code, --retry-request, --terminal, --text, --wait-submit"
      ]
    }
  },
  "_meta": {
    "runtimeId": null
  }
}
After: exit 0, one terminal.send request, exact text length/hash

Recorded at 1ceed3b5b80da10e856a350183a245dc70ec5762 for the same
invocation and finite input:

{
  "id": "84e8be30-86a0-475a-bd57-975f449a39df",
  "ok": true,
  "result": {
    "send": {
      "handle": "term-disposable-fixture",
      "accepted": true,
      "bytesWritten": 89
    }
  },
  "_meta": {
    "runtimeId": "stdin-fixture"
  }
}

Captured text is exactly the 89-byte input; enter is false. The separate
--enter case keeps the same text/hash and sends enter: true. Repeating the
same retry ID sends identical parameters; the fixture's own replay table records
one unique capture, which is not proof of native execution-host deduplication.

Raw before receipt SHA256: ec72025f81d63bd39505e6864a56c23e433c8df5aea9fc29e1372ddc438c2b82.
Raw after receipt SHA256: dfbb6cbc3aca4c60f2379750d4a18a335130cac07053bd4cda1c2b2c38a26dee.

Testing

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

macOS arm64, Node 24: 153 focused tests, CLI and node/application typechecks,
formatting, changed-code quality, generated-guide freshness and a freshly built
local CLI with an owned bounded local RPC fixture. A separate temporary
combination with five concurrent CLI changes passed 305 tests, CLI typecheck/build,
guide freshness and unique registration/flag preservation; source and index were
restored before the final focused build. Exact-limit unit controls
prove reader/handler acceptance, not 16 MiB transport delivery. Windows, Linux,
native PTY, WSL/PowerShell/MSYS launchers and SSH/remote were not tested; the
existing text field, selectors and host delivery mechanisms are unchanged.

Review

Independent review: CLEAN for commit
1ceed3b5b80da10e856a350183a245dc70ec5762, tree
bffe9094143bb9d54a778615190ed80b22334c9e, against named main
1fc24d311481a85d5b4ae596898ee072389f040c.
The verbatim independent verdict, ten-file manifest, ancestry and complete patch
are bound to full-diff SHA256
1d7d7faf6e22911b2bb2c0cbbe0b2e33fa9ab1ec555787eb6560609f35ac76ac.
The reviewer independently reran all 153 focused tests, CLI typecheck, changed-code
quality, formatting and guide checks, then verified the source remained unchanged.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Credit: rajpopat27 reported #16113; logii authored the original #12239 commit
dfc937d3eda7ed079901cd9252faf86410f8ec13. That commit and its Claude coauthor
are preserved in the branch ancestry. brynnclaw also supplied issue context and
pointed to the original PR. Current main remains the first-parent
source authority; old terminal.ts and core.ts changes were adapted to the
current extracted modules rather than replayed.

Introduced behavior: stdin waits for EOF, refuses a TTY, decodes UTF-8 and rejects
raw terminal input over 16 MiB without truncation. Malformed UTF-8 retains the
existing replacement-character behavior. Unchanged constraints: the local JSON
RPC cap is 1 MiB including envelope and escaping, so 16 MiB input is not guaranteed
deliverable; newlines/CRLF are neither added nor stripped, a newline can affect
the target program, and --enter is a separate submit action. Producer/launcher
evaluation or encoding is not undone. Remote servers receive the existing text
shape and retain their capability negotiation; folder workspaces and Git
providers retain the existing terminal selectors. Generated guides are refreshed, and the separate compatibility check preserved
concurrent CLI additions. This PR contains only the stdin feature, with no
dependency on those unmerged changes. Merge risk is concentrated in the shared
reader extraction and earlier flag validation; the computer empty/TTY policies,
existing terminal actions and prompt receipts have regression coverage.

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)

`orca terminal send --text` is the highest-volume payload path in the CLI, and on
WSL argv cannot carry it. The bridge hands the string to `orca.exe` through Windows
PowerShell 5.1, which never escapes an embedded double quote when it builds a native
command line, so `--text 'say "hello" now'` returns ok:true and delivers
`say hello now`, while `--text 'tell me "whats next"'` splits into two arguments and
exits 1 on the stray positional. Details and the localization harness are in stablyai#12231.

That defect deserves its own fix in the bridge; this change is the orthogonal half —
the payload never has to touch a command line in the first place:

    printf %s "$NOTE" | orca terminal send --terminal <handle> --text-stdin --enter

The flag mirrors `computer type-text` / `paste-text` / `set-value`, which already
accept --text-stdin / --value-stdin, so the reader moves to src/cli/stdin-payload.ts
and both call sites share one implementation. Passing --text and --text-stdin
together is an invalid_argument, matching computer-use.

One deliberate difference from computer-use: empty stdin stays a legal payload here.
`--text-stdin --enter` with no bytes is a bare newline, which is a real thing to send
to a terminal; in computer-use an empty type-text is a mistake.

Tests cover the stdin route with a quote-bearing payload, a multi-line payload, the
mutual exclusion, the untouched --text path, and the help output. The four that
assert new behavior fail without this change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The CLI adds shared asynchronous stdin payload reading with TTY validation and UTF-8 decoding. orca terminal send now accepts --text-stdin, rejects simultaneous --text and --text-stdin, and preserves existing interrupt behavior. Tests cover quoted, multiline, inline, and stdin payloads. Command help and skill guides document quote-safe stdin usage, including WSL PowerShell limitations.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Title check ✅ Passed The title clearly and concisely describes the main change: adding stdin support for terminal send text.
Description check ✅ Passed The description is complete and follows the repository template. It explains the user-facing change, implementation, rationale, linked issue, visual proof, testing, review, compatibility consideration…

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: 2

🧹 Nitpick comments (1)
src/cli/handlers/terminal.test.ts (1)

99-120: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test an empty stdin payload.

The handler must preserve empty stdin as text: '', but these tests cover only non-empty stdin. Add a --text-stdin --enter case with an empty stream. Assert that terminal.send receives text: ''.

Proposed test
+  it('preserves an empty stdin payload', async () => {
+    stubStdin('')
+
+    const call = await send(['terminal', 'send', '--terminal', 'term-1', '--text-stdin', '--enter'])
+
+    expect(call).toHaveBeenCalledWith(
+      'terminal.send',
+      expect.objectContaining({ text: '', enter: true })
+    )
+  })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8de2d17d-d62f-49b6-8cc5-417f3475cc25

📥 Commits

Reviewing files that changed from the base of the PR and between d48cac7 and dfc937d.

📒 Files selected for processing (7)
  • skill-guides/orca-cli.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/computer-action-flags.ts
  • src/cli/handlers/terminal.test.ts
  • src/cli/handlers/terminal.ts
  • src/cli/specs/core.ts
  • src/cli/stdin-payload.ts

Comment thread skill-guides/orca-cli.md Resolved
Comment thread src/cli/stdin-payload.ts Resolved
@brynnclaw

Copy link
Copy Markdown
Contributor

I tried this branch against current main (27b823f) on Linux, because #16113 asks for the same stdin transport. Here is what I measured.

It no longer applies cleanly

git merge-tree against main reports conflicts in three files:

  • src/cli/specs/core.ts
  • src/cli/handlers/terminal.ts
  • src/cli/bundled-skill-guides.ts (generated)

Since this branch's base, main has moved terminal send into its own modules, src/cli/specs/terminal-send.ts and src/cli/handlers/terminal-send.ts, and added --wait-submit / --retry-request there. The new file stdin-payload.ts, the computer-action-flags.ts change, the two guide lines and the tests all merge without conflict.

For a local check I kept main's side of the three conflicts and moved your getSendText and the spec additions (flag, usage, note, examples) unchanged into the two new terminal-send.ts files. I regenerated the bundled guide with pnpm run generate:bundled-skill-guides. That port is about 24 lines in those two files, and I can share the diff.

Results on that port

  • Your six tests: five pass. takes the payload from stdin, quotes intact fails with TypeError: client.getCliStatus is not a function. On main, any text-plus---enter send calls client.getCliStatus() first to check prompt-delivery support, and the test's mock client only stubs call. The stub in src/cli/retry-request-flag.test.ts shows the shape it needs.
  • Lint: main's terminal.test.ts already has a describe('terminal send CLI') block, so the added block with the same title fails audit:code-quality:native (vitest(no-identical-title) under --deny-warnings). After renaming it locally, 15 of the 16 pnpm lint steps pass. The type-aware step and the full pnpm typecheck / pnpm test didn't fit in the memory and time limits of the machine I used, so I ran narrower versions:
    • type-aware oxlint on the 6 changed files: 0 warnings, 0 errors
    • pnpm run typecheck:cli (its tsconfig includes all of src/cli; the node and web projects include none of the changed files): passes
    • vitest run src/cli plus the two bundled-guide tests in config/scripts, including the 17 local tests below: about 1,460 tests, all passing except 4 skipped and 1 failed (the getCliStatus test above)

Payloads that Git Bash or a shell can rewrite in argv

I added 17 local tests (not part of this PR). One checks that --text-stdin passes validateCommandAndFlags for terminal send. The rest feed bytes through a stubbed stdin, then parseArgs and the handler. Most compare the text in the terminal.send params to the input bytes; the exclusivity and TTY tests check the error instead. The payloads:

  • /exit, /clear now: with path conversion on, Git Bash (MSYS2) turns /clear into C:/Program Files/Git/clear (measured separately on Windows 11, Git for Windows MSYS runtime 3.6.6)
  • /usr/bin:/bin:C:/x: with conversion on, the same runtime rewrote this POSIX path list into a ;-separated Windows list
  • a:b, a plain colon
  • backticks, $(whoami), ${HOME}
  • quotes and backslash
  • unicode
  • a trailing \n, and CRLF with a tab
  • a multi-byte character split across two stdin chunks

Other cases covered: --enter keeping the agent-prompt path, empty stdin, --text plus --text-stdin, and a TTY stdin.

On the port all 17 pass. On unmodified main all 17 fail.

What this does not show

  • The run was on Linux only, where MSYS2 path conversion never happens. It shows the stdin route delivers those bytes to the RPC unchanged. Avoiding the Git Bash rewrite depends on MSYS2 converting only command-line arguments (and environment variables), not piped data, and I did not measure that on Windows.
  • Nothing ran end to end into a live pane, so host-side delivery of the prompt was not exercised.
  • Invalid UTF-8 on stdin becomes U+FFFD, so the route is lossless for valid UTF-8 only.
  • readStdinPayload() reads all of stdin before the host applies its input size limit, as the CodeRabbit review on this PR points out. I didn't look into that. The existing computer-use --text-stdin path buffers the same way.
  • From reading the code, not tested: after a port, the error text in src/cli/handlers/terminal-send.ts ("--retry-request and --wait-submit require --text with --enter ...") would also apply to --text-stdin with --enter, so it may need to name both flags.
  • The new help note names only the WSL double-quote case. [CLI] Add shell-safe transport for terminal prompt text #16113 adds two more reasons for the same flag: the Git Bash leading / and shell expansion of backticks and $(...).

Checked with the help of an AI coding agent (Claude Opus 5.5).

Adapt logii’s original PR stablyai#12239 reader extraction to the current terminal-send modules. Reuse the computer reader, bound terminal accumulation, and preserve prompt delivery and empty-input policies. Reported by rajpopat27 in stablyai#16113.
The pinned contributor head is a shallow imported history. Keep the current named main and adapted implementation as first-parent source authority; preserve original PR stablyai#12239 and its Claude coauthor without replaying its old terminal/core files.
Add the focused stdin route to command discovery, canonical guide and public reference, including EOF, UTF-8/newline behavior and the unchanged RPC limit. Regenerate only the guide bundle after the explicit shared-file lease.
@nwparker nwparker changed the title feat(cli): give terminal send a lossless payload route with --text-stdin feat(cli): accept terminal send text from stdin Oct 2, 2026

This branch has not been deployed

No deployments
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.

[CLI] Add shell-safe transport for terminal prompt text

5 participants