Skip to content

#750 Run shell commands (!cmd) from the composer - #769

Merged
ivanfenenko merged 5 commits into
mainfrom
feature/750-composer-shell-commands
Oct 20, 2026
Merged

ivanfenenko merged 5 commits into
mainfrom
feature/750-composer-shell-commands

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Shell mode in the composer (iOS + Android). A draft whose first character is ! is a shell command: the ! is highlighted, a selected Shell badge replaces the model/agent chips (tap it to drop the !), attachments are disabled, and Send (labelled "Run shell command") runs the command instead of sending a prompt. Leading whitespace ( !ls) or a ! later in the text stays a prompt; a bare ! sends nothing; multi-line drafts run as one script. In shell mode the text field turns off autocorrect, auto-capitalization and smart quotes/dashes, so --oneline is not turned into —oneline.
  • Requests, behind the protocol-selected message remote. v1: POST /session/{id}/shell {agent, command, model}. v2: POST /api/session/{id}/shell {command}, without switching the session agent or model first (as the TUI does). Both servers hold the request open until the command ends, so both use the long prompt-send timeout. The composer doesn't wait for the response, so you can keep typing while a long command runs.
  • Errors work like failed prompts. A failed request restores the draft (unless you've edited it since) and shows the same error snackbar. On v1, a second command while one is still running gets 409 SessionBusyError and shows "Session is busy". On v2 the server runs shell commands alongside the agent, so there is no busy error. If you've set Queue as the follow-up mode and the session is busy, the app refuses the command with a message, because shell commands can't be queued (same rule as the web app and TUI).
  • v2 shell output now shows live. The adapters only handled a flat session.shell.* shape that no server sends. Real v2 events (beta and dev) carry {shell: Info} and no message id. So a v2 shell run never appeared live, and it left behind a fake busy status that nothing cleared. shell.started now produces the same items as the REST shell message (the command, then a Shell row under <id>:assistant, keyed by the started envelope id). shell.ended adds the output and exit code, and the session status is left alone. The REST projection now also includes the command as tool input and the exit code, so a failed command shows "Exited with code N" on both paths.
  • No more empty "steer" banner. After a shell run, v2 puts a synthetic inbox item with the output in the queue (it's delivered with your next prompt). That item showed up as an empty pending steer prompt. Synthetic inbox items are no longer marked as waiting or queued.
  • iOS text highlighting fix. Typed text no longer picks up the color of the highlighted character before the cursor. Before this, everything typed after ! (or right after a mention) turned the highlight color.
  • Staged revert (Commit staged revert on OpenCode 2.x #751 / #751 Commit staged revert before sending a prompt on v2 #757 overlap): a ! command does not commit a staged revert. This matches the TUI (prompt/index.tsx commits only on the prompt path) and the web app (composer/submit.ts sends shell without revert.commit). The shell branch returns before #751 Commit staged revert before sending a prompt on v2 #757's beforePrompt hook, and a test on each platform pins this. On v1 the server cleans up the revert itself when a shell runs.

Checks

  • Android: ./gradlew :app:testDebugUnitTest passes on the merged tree (2,315 tests, 0 failures, 1 skipped as before). :app:assembleDebug and :app:assembleDebugAndroidTest build. ktlintCheck: no violations on lines this PR adds (existing violations elsewhere are unchanged).
  • iOS: full OpenCode MobileTests target on a dedicated iPhone 17 / iOS 26.5 simulator passes on the merged tree (2,225 Swift Testing tests in 220 suites + 76 XCTest, 0 failures).
  • New tests on both platforms:
    • ! parsing (bare !, whitespace-only, leading whitespace, ! later in the text, multi-line, !!, leaving shell mode)
    • v1 and v2 request shapes (path, method, exact JSON body, no agent/model switch on v2)
    • Screen Model: shell instead of prompt, no optimistic row, bare !, prompt with leading space, busy error restores the draft and shows the snackbar, leaving shell mode, staged revert left alone
    • event adapter: v2 shell.started/ended projection, ended without a started event, synthetic inbox item not waiting
    • REST shell projection; send-button label
  • Real app runs against real servers through the scenario harness (opencode v1 1.19.1 and v2 dev bc5ebf00a4), on the iOS simulator and the Android emulator. All four combinations: shell mode, run + live output, output sheet, v1 busy 409 → snackbar + restored draft, v2 non-zero exit, leaving shell mode, v2 reopen from history.

Evidence

iOS · v1
# iOS app, opencode v1 1.19.1
+  0.00s  APP  POST /session/ses_ea5f0d579ffeElAdQTcmvhNfTJ/shell?directory=<project> -> 200 after 882 ms
+  0.01s  SSE  v1 /event  session.status busy
+  0.02s  SSE  v1 /event  message.updated role=user id=msg_15a0f5464001C2YXBnaDCB4Ml2
+  0.02s  SSE  v1 /event  message.updated role=assistant id=msg_15a0f5469001Fff6jxNgFL31M6
+  0.02s  SSE  v1 /event  message.part.updated tool=bash status=running command="git log --oneline -3 && ls"
+  0.88s  SSE  v1 /event  message.part.updated tool=bash status=running command="git log --oneline -3 && ls"
+  0.88s  SSE  v1 /event  message.updated role=assistant id=msg_15a0f5469001Fff6jxNgFL31M6
+  0.88s  SSE  v1 /event  message.part.updated tool=bash status=completed command="git log --oneline -3 && ls"
+  0.88s  SSE  v1 /event  session.status idle
+ 28.20s  APP  POST /session/ses_ea5f0d579ffeElAdQTcmvhNfTJ/shell?directory=<project> -> 200 after 8769 ms
+ 28.23s  SSE  v1 /event  session.status busy
+ 28.24s  SSE  v1 /event  message.updated role=user id=msg_15a0fc2a0001jRx8FRplOWVme3
+ 28.24s  SSE  v1 /event  message.updated role=assistant id=msg_15a0fc2a5001C7HyeqszUbU34y
+ 28.24s  SSE  v1 /event  message.part.updated tool=bash status=running command="sleep 8 && echo slow done"
+ 35.03s  APP  POST /session/ses_ea5f0d579ffeElAdQTcmvhNfTJ/shell?directory=<project> -> 409 after 16 ms
+ 36.96s  SSE  v1 /event  message.part.updated tool=bash status=running command="sleep 8 && echo slow done"
+ 36.97s  SSE  v1 /event  message.updated role=assistant id=msg_15a0fc2a5001C7HyeqszUbU34y
+ 36.97s  SSE  v1 /event  message.part.updated tool=bash status=completed command="sleep 8 && echo slow done"
+ 36.97s  SSE  v1 /event  session.status idle
iOS · v2
# iOS app, opencode v2 (dev bc5ebf00a4)
+  0.00s  APP  POST /api/session/ses_ea5e7371effe4i1xeQXizcr2wJ/shell -> 204 after 40 ms
+  0.02s  SSE  v2 /api/event  session.shell.started shell=sh_15a1915fd0019VsXHGPanVcfpA command="git log --oneline -3 && ls" status=running
+  0.04s  SSE  v2 /api/event  session.shell.ended shell=sh_15a1915fd0019VsXHGPanVcfpA command="git log --oneline -3 && ls" status=exited exit=0 output="75cb3f9 Initial import\nREADME.md\ndist\nopencode.jsonc\npackage"
+  0.04s  SSE  v2 /api/event  session.inbox.enqueued item=synthetic source=shell delivery=steer
+ 22.90s  APP  POST /api/session/ses_ea5e7371effe4i1xeQXizcr2wJ/shell -> 204 after 24 ms
+ 22.91s  SSE  v2 /api/event  session.shell.started shell=sh_15a196f6b001WEj16phnEzvX09 command="ls does-not-exist" status=running
+ 22.92s  SSE  v2 /api/event  session.shell.ended shell=sh_15a196f6b001WEj16phnEzvX09 command="ls does-not-exist" status=exited exit=1 output="ls: does-not-exist: No such file or directory\n"
+ 22.92s  SSE  v2 /api/event  session.inbox.enqueued item=synthetic source=shell delivery=steer
Android · v1
# Android app, opencode v1 1.19.1
# Note: the two plain prompts at +31s and +78s (message.updated only, no /shell request) are test-driver mistakes where the emulator dropped the leading ! keystroke; they went out as ordinary prompts.
+  0.00s  APP  POST /session/ses_ea5e49683ffe84iA61VNBKkG1o/shell?directory=<project> -> 200 after 1885 ms
+  0.08s  SSE  v1 /event  session.status busy
+  0.10s  SSE  v1 /event  message.updated role=user id=msg_15a1c1f410013VXVaZWa4E2eUH
+  0.10s  SSE  v1 /event  message.updated role=assistant id=msg_15a1c1f53001jKcW5gVrH4dvDg
+  0.10s  SSE  v1 /event  message.part.updated tool=bash status=running command="git log --oneline -3 && ls"
+  1.88s  SSE  v1 /event  message.part.updated tool=bash status=running command="git log --oneline -3 && ls"
+  1.89s  SSE  v1 /event  message.updated role=assistant id=msg_15a1c1f53001jKcW5gVrH4dvDg
+  1.89s  SSE  v1 /event  message.part.updated tool=bash status=completed command="git log --oneline -3 && ls"
+  1.89s  SSE  v1 /event  session.status idle
+ 31.11s  SSE  v1 /event  message.updated role=user id=msg_15a1c987b001UEkZkmD1qT3J5o
+ 31.12s  SSE  v1 /event  session.status busy
+ 31.12s  SSE  v1 /event  message.updated role=assistant id=msg_15a1c9891001bRR5K5ldoBJgil
+ 31.44s  SSE  v1 /event  message.updated role=user id=msg_15a1c987b001UEkZkmD1qT3J5o
+ 32.27s  SSE  v1 /event  session.status busy
+ 32.35s  SSE  v1 /event  message.updated role=assistant id=msg_15a1c9891001bRR5K5ldoBJgil
+ 32.41s  SSE  v1 /event  session.status busy
+ 32.41s  SSE  v1 /event  session.status idle
+ 32.45s  SSE  v1 /event  message.updated role=user id=msg_15a1c987b001UEkZkmD1qT3J5o
+ 73.51s  APP  POST /session/ses_ea5e49683ffe84iA61VNBKkG1o/shell?directory=<project> -> 200 after 9451 ms
+ 73.54s  SSE  v1 /event  session.status busy
+ 73.54s  SSE  v1 /event  message.updated role=user id=msg_15a1d3e40001qV0t2Sv5jNM4pd
+ 73.54s  SSE  v1 /event  message.updated role=assistant id=msg_15a1d3e49001mfm7VHue5FaudO
+ 73.54s  SSE  v1 /event  message.part.updated tool=bash status=running command="sleep 8 && echo slow done"
+ 78.35s  SSE  v1 /event  message.updated role=user id=msg_15a1d5117001rhZQ8ctpc30dJm
+ 82.96s  SSE  v1 /event  message.part.updated tool=bash status=running command="sleep 8 && echo slow done"
+ 82.97s  SSE  v1 /event  message.updated role=assistant id=msg_15a1d3e49001mfm7VHue5FaudO
+ 82.97s  SSE  v1 /event  message.part.updated tool=bash status=completed command="sleep 8 && echo slow done"
+ 82.97s  SSE  v1 /event  session.status busy
+ 82.97s  SSE  v1 /event  message.updated role=assistant id=msg_15a1d6326001nzphCKwgCbParR
+ 83.07s  SSE  v1 /event  message.updated role=user id=msg_15a1d5117001rhZQ8ctpc30dJm
+ 83.08s  SSE  v1 /event  session.status busy
+ 83.20s  SSE  v1 /event  message.updated role=assistant id=msg_15a1d6326001nzphCKwgCbParR
+ 83.28s  SSE  v1 /event  session.status busy
+ 83.28s  SSE  v1 /event  session.status idle
+ 83.31s  SSE  v1 /event  message.updated role=user id=msg_15a1d5117001rhZQ8ctpc30dJm
+200.06s  APP  POST /session/ses_ea5e49683ffe84iA61VNBKkG1o/shell?directory=<project> -> 200 after 9468 ms
+200.10s  SSE  v1 /event  session.status busy
+200.10s  SSE  v1 /event  message.updated role=user id=msg_15a1f2c9b001CIQQfnshwZbmrG
+200.10s  SSE  v1 /event  message.updated role=assistant id=msg_15a1f2ca40011OI9ErvOtQX6Kx
+200.10s  SSE  v1 /event  message.part.updated tool=bash status=running command="sleep 8 && echo slow done"
+204.69s  APP  POST /session/ses_ea5e49683ffe84iA61VNBKkG1o/shell?directory=<project> -> 409 after 4 ms
+209.53s  SSE  v1 /event  message.part.updated tool=bash status=running command="sleep 8 && echo slow done"
+209.53s  SSE  v1 /event  message.updated role=assistant id=msg_15a1f2ca40011OI9ErvOtQX6Kx
+209.53s  SSE  v1 /event  message.part.updated tool=bash status=completed command="sleep 8 && echo slow done"
+209.53s  SSE  v1 /event  session.status idle
Android · v2
# Android app, opencode v2 (dev bc5ebf00a4)
+  0.00s  APP  POST /api/session/ses_ea5e00a30ffePFbY5p3pJgpz03/shell -> 204 after 48 ms
+  0.03s  SSE  v2 /api/event  session.shell.started shell=sh_15a2039810013vI9C2NNwvyxm5 command="git log --oneline -3 && ls" status=running
+  0.05s  SSE  v2 /api/event  session.shell.ended shell=sh_15a2039810013vI9C2NNwvyxm5 command="git log --oneline -3 && ls" status=exited exit=0 output="75cb3f9 Initial import\nREADME.md\ndist\nopencode.jsonc\npackage"
+  0.05s  SSE  v2 /api/event  session.inbox.enqueued item=synthetic source=shell delivery=steer
+ 12.51s  APP  POST /api/session/ses_ea5e00a30ffePFbY5p3pJgpz03/shell -> 204 after 26 ms
+ 12.53s  SSE  v2 /api/event  session.shell.started shell=sh_15a206a59001Cg04kIWRlFTIQ4 command="ls does-not-exist" status=running
+ 12.53s  SSE  v2 /api/event  session.shell.ended shell=sh_15a206a59001Cg04kIWRlFTIQ4 command="ls does-not-exist" status=exited exit=1 output="ls: does-not-exist: No such file or directory\n"
+ 12.53s  SSE  v2 /api/event  session.inbox.enqueued item=synthetic source=shell delivery=steer

Issue

Risks / Follow-ups

  • The v2 live check ran on dev bc5ebf00a4. Beta uses the same {shell: Info} event schema (checked in the source), but I didn't run it live.
  • In v2 the server delivers the synthetic shell-result item with your next prompt, so it appears in history after that prompt is sent. How it renders then is unchanged by this PR.
  • On v2, Send keeps the Steer arrow icon in shell mode (its accessibility label says "Run shell command"). Small visual difference from the web app; left as is.
  • The harness proxy logs request paths only, not bodies. The request bodies are covered by the unit tests.
  • Standalone /api/shell* commands are out of scope, as the issue says.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith with what you need.


Note

Medium Risk
Touches composer submit paths, protocol-specific HTTP, and event projection for session timelines on both platforms; incorrect shell or inbox handling could mis-render live chat or run commands unexpectedly, though behavior is heavily unit-tested.

Overview
Adds shell mode to the session composer on iOS and Android: a draft that starts with ! runs the remainder as a session shell command instead of a prompt. The UI highlights the prefix, shows a Shell badge (tap to exit shell mode), disables attachments, uses literal keyboard input, and labels Send as Run shell command. Submit routing calls new runShellCommand APIs—v1 POST …/shell with agent/command/model and v2 with command only (no agent/model switch)—using long-lived request handling like prompt send; failures restore the draft like a failed prompt, and queued follow-up while busy is blocked for shell.

Live timeline and history are updated for real v2 {shell: Info} events: shell.started/ended project user command + bash tool rows (with output and exit code) without spurious session busy; REST shell items gain command input and exit metadata. Synthetic inbox items from shell output no longer show as waiting steer prompts.

iOS also fixes mention/shell highlight bleed when typing after a highlighted character.

Reviewed by Cursor Bugbot for commit c571b21. Bugbot is set up for automated code reviews on this repo. Configure here.

ivanfenenko and others added 5 commits October 20, 2026 17:59
A draft whose first character is ! enters shell mode: the ! is highlighted,
a selected Shell badge replaces the model and agent chips (tap to leave),
and Send runs the command through POST /session/{id}/shell (v1, with agent
and model) or POST /api/session/{id}/shell (v2, command only) instead of
sending a prompt. Output arrives through the existing shell rendering.
Failures restore the draft and show the error like a failed prompt; shell
commands are never queued.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Real v2 servers send session.shell.started/ended as {shell: Info}; the
adapters only understood a flat shape no server sends, so a v2 shell never
appeared live and left a synthetic busy status behind. Project the nested
shape like the REST shell item (user command + Shell row keyed by the
started envelope id), with output and exit code on end, and leave the
session status alone. A synthetic inbox item (the server's shell-result
notification) no longer shows as a waiting steer prompt.

Shell mode turns off autocorrect, smart dashes/quotes and capitalization,
and typed text no longer inherits the highlight of the ! before it (iOS).
Both protocols hold the shell request until the command ends, so v2 also
uses the long request path on iOS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko marked this pull request as ready for review October 20, 2026 18:17
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c571b21. Configure here.

@ivanfenenko
ivanfenenko merged commit d585602 into main Oct 20, 2026
@ivanfenenko
ivanfenenko deleted the feature/750-composer-shell-commands branch October 20, 2026 19:02
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.

Run shell commands (!cmd) from the composer

1 participant