Skip to content

fix(opencode): show the whole shell command on an OpenCode 2 permission card - #4533

Merged
devswha merged 3 commits into
mainfrom
fix/opencode-permission-full-command
Nov 23, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/opencode-permission-full-command

Conversation

@devswha

@devswha devswha commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

What

An OpenCode 2 permission card for a shell command now shows the whole command that will run, byte for byte, instead of the pieces OpenCode's permission rules match.

OpenCode 2.2.2 lists those pieces in resources. a > f && b >> f && c arrives as ["a > f", "b", "c"] (the second redirect is gone). A heredoc arrives as its first line plus the next command. The card (#4515) joined those pieces, so a long command, a heredoc or a quoted chain showed something other than what ran. In the approval-path measurement this happened in 10 of 25 approvals.

The request names its tool call: source: { type: "tool", messageID, id }. OpenCode's own TUI resolves the call through that field. It reads the call's input from the message (state.input.command, unless the input is still streaming) and shows $ <command>. Ovis now does the same:

  • server/opencode-service.ts: listPendingPermissions keeps source. readOpenCodeToolInput reads GET /api/session/{id}/message/{messageID} and takes the tool part with that call id. withShellInput attaches the command to the first pending shell request (the one the card shows). A later read of the same request reuses the command when the request still names the same message and call, because a running call's input does not change.
  • server/dialogs/opencode.ts: a shell card shows $ ${input.command}. A shell request whose call could not be read (message gone, input still streaming, an older 2.x without the route) gets no card and keeps the fallback card. An edit without its patch already works this way: the card never asks someone to allow something they cannot see in full.
  • server/prompt.ts: the OpenCode branch reads the call after the pending list.

The browser contract is unchanged: the same card, same options, same reply route. Only the body text is now correct.

Validation

  • Red first: 12 new or changed tests in server/dialogs/opencode.test.ts and server/opencode-answer.test.ts fail on main's code and pass with this change.
  • New fixture server/fixtures/opencode-permission-command-2.2.2.json: recorded from a real, isolated OpenCode 2.2.2 (opencode serve, own HOME/XDG, model dsapi/deepseek-v4.1-flash). It holds the short, long (&&, >>), heredoc and quoted (Korean, $, |, &) commands. Each case has the pending request, the message its call is in, and the bash -c script strace saw run. The directory is scrubbed.
  • End to end with this branch's own functions (listPendingPermissions → withShellInput → openCodePermissionPrompt → replyOpenCodePermission) against an isolated OpenCode 2.2.2 serve. These are the same five commands as the approval-path measurement, with ground truth from strace for shell commands and file bytes for writes:
    • 25 of 25 cards match exactly what ran (short 5, long 5, multi 5, quote 5, write 5; a 6th write was also exact). 15 of the 20 shell requests came in more than one piece.
    • 5 extra write turns got no write approval: the model first asked to run od -c on the input file, the driver denied it, and the prompt tells the model to stop on a denial. Those turns are left out, as in the original measurement.
    • Before this change, the same path gave 15 of 25.
  • bun run check fast: typecheck, build and generated files ok. Unit tests: 24382 pass, 1 fail. The failure is server/ssh-account-add.test.ts: its unix socket path goes over the length limit under this lane's long TMPDIR. It fails the same way without this change, and passes (3/3) with a short TMPDIR.
  • Not run: full check, browser regressions (the card component is unchanged).

…on card

OpenCode 2's permission request lists in `resources` what its permission rules
match: the pieces of a command. `a && b >> f` comes as `a` and `b` (the
redirect is gone), and a heredoc as its first line and the next command. The
card showed those pieces, so 10 of 25 measured approvals showed something other
than what ran.

The request names its tool call (`source`: assistant message id and call id).
OpenCode's TUI reads the command from that call's input in the message, and so
does Ovis now: GET /api/session/{id}/message/{messageID}, the tool part with
that id, `state.input.command`, read once per request. A shell request whose
call cannot be read gets no card and keeps the fallback card, as an edit
without its patch already does.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

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

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Shell permission cards now show the full executed command, including chained commands, redirections, heredocs, and special characters.
    • Shell cards are not shown when the command details are unavailable or incomplete, preventing misleading partial command displays. Other permission card details remain unchanged.

OpenCode now reads tool-call input for pending shell permissions and uses input.command in permission cards. Recorded command cases cover chained commands, heredocs, and quoted or special-character content. Requests without readable command input do not produce a shell card.

Changes: Shell Permission Command Display

Layer / File(s) Summary
Read tool-call input
server/opencode-service.ts, server/fixtures/opencode-permission-command-2.2.2.json, server/opencode-answer.test.ts
Permission requests retain tool-call provenance. The service reads the matching assistant message and returns tool input when available. Recorded command cases and message-read mock support validate the lookup.
Attach input to pending permissions
server/opencode-service.ts, server/prompt.ts, server/opencode-answer.test.ts
Prompt reads enrich pending permissions with shell input, using previously known input when it matches or reading the source tool call otherwise. Tests cover repeated reads and unavailable or streaming message details.
Render the executed shell command
server/dialogs/opencode.ts, server/dialogs/opencode.test.ts, changelog.d/opencode-permission-card.md
Shell cards display input.command as one command. Missing or empty command input produces no shell card. Tests cover recorded commands, and the changelog describes the displayed command contents.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • devswha/ovis#4515: Adds the OpenCode 2 approval-card path that this change uses to display shell command input.
Merge Risk: Minimal · previous review 569c9

Shell permission cards now show the full executed command, and requests whose input cannot be read keep the fallback card. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the OpenCode 2 shell-permission card now shows the full shell command. The summary and objectives confirm this as the primary change, and the title follows the fix(ope…
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.
Description check Passed The description follows the template's two sections, Change and Validation. The Change section explains the problem (shell permission cards show command pieces from resources instead of the full com…
Full details: Title check

Explanation

The title names the main change: the OpenCode 2 shell-permission card now shows the full shell command. The summary and objectives confirm this as the primary change, and the title follows the fix(opencode) convention. It is specific and concise.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section explains the problem (shell permission cards show command pieces from resources instead of the full command), the approach (reading the tool call input via source), and the resulting behavior (no card when the call cannot be read; browser contract unchanged). The Validation section lists the checks run (bun run check fast with typecheck, build, generated files, and unit test results including one failure in server/ssh-account-add.test.ts attributed to TMPDIR length), the new fixture and end-to-end measurements, and what was skipped (full check, browser regressions). It does not explicitly confirm contract-test coverage for the HTTP route, although the template asks for it when HTTP/WS changes are made. The changelog entry is not mentioned in the description, though the raw summary shows changelog.d/opencode-permission-card.md was added. The PR is substantially complete, so it passes.

Finishing Touches

Generate unit tests (beta)

  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 08d4578 and 569c962.

Files selected for processing: 7

  • changelog.d/opencode-permission-card.md
  • server/dialogs/opencode.test.ts
  • server/dialogs/opencode.ts
  • server/fixtures/opencode-permission-command-2.2.2.json
  • server/opencode-answer.test.ts
  • server/opencode-service.ts
  • server/prompt.ts

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

The command read for a pending request was reused by request id and session
alone. A request keeping its id while naming another tool call would have kept
the first call's command on the card. Reuse it only when the request names the
same message and call.
@devswha

devswha commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Gate review (one gate reviewer, at 569c962) and how each finding was resolved:

  • HIGH, reuse by request id only: withShellInput reused a command read earlier by request id and session alone, so a request that keeps its id but names another call would keep the old command (a constructed case, not seen from OpenCode). Fixed in the next commit: reuse now also requires the same source.messageID and source.callID. New test shows the command another call runs, though the request keeps its id fails on 569c962 and passes now.
  • MEDIUM, "read once per request": two reads that start at the same moment, before either has the command, each read the message. Only a later read reuses it. The wording is narrowed to that (comment and test name). No dedupe was added: an extra read of one message is harmless.
  • MEDIUM, review evidence at review time: CodeRabbit had not finished then. It has since reviewed 569c962 with no actionable comments.

Validation of the fix: bun run check fast all green (unit 24384 pass, 0 fail; short TMPDIR, so the earlier ssh-account-add socket-length failure does not occur).

…on-full-command

# Conflicts:
#	server/prompt.ts
@devswha
devswha merged commit 0b514e2 into main Nov 23, 2026
21 checks passed
@devswha

devswha commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 5653aa3bc. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit said it did not review (a limit or a skip) since this head.

CodeRabbit reviewed 569c962 (no actionable comments) and was rate-limited on the later heads. One gate reviewer (omo-native-gate-reviewer) reviewed 569c962: its HIGH (command reused by request id only) was fixed in 092ab41 with a test that fails before the fix; its two MEDIUMs were resolved as noted in the PR comment. 5653aa3 only merges main (import conflict in server/prompt.ts). Merged by the opencode-original-cmd lane per its brief.

@devswha
devswha deleted the fix/opencode-permission-full-command branch November 23, 2026 21:09
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