Skip to content

fix(chat): send a menu-picked command without its trailing space - #3836

Merged
devswha merged 3 commits into
mainfrom
fix/chat-bare-command-space
Nov 14, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/chat-bare-command-space

Conversation

@devswha

@devswha devswha commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Fixes #3813. Thanks to @Ploppy3 for the report, the screenshot and the pointers into OpenCode's source.

src/ only: not held by the release freeze.

Cause

Picking a command from Chat's / menu inserts it with a space after it (slashCommandReplacement returns /new ), as a menu does so arguments can follow. Sent as it is, the message stays /new .

OpenCode 2.2.7's own menu (packages/tui/src/component/prompt/autocomplete.tsx, index.tsx) treats commands in two ways:

  • A built-in that takes no argument runs from the menu (onSelect: slash.arguments ? () => insertSlash(name) : command.run). On submit, only a built-in declared with arguments: true is matched (argumentSlash), so /new with its space goes as a prompt, and the agent answers it, as in the screenshot.
  • Its other commands, meaning the built-ins that take an argument (cd, rename, btw) and every custom, project or plugin command, are only inserted as /name by its menu. That space closes the menu, so Enter submits them and they run.

Change

The space a pick adds is dropped only for an OpenCode built-in that takes no argument, and only when the box still holds exactly that pick:

  • src/lib/compose.ts sendsBarePick(command, agent): true only for an OpenCode builtin row on / whose name is on an allow-list of the TUI's own built-ins that take no argument. The list is v2.2.7's slash entries without arguments: true, plus v1.19.5's slashName entries (v1 has no argument form; its move opens a dialog). Left out: cd, rename and btw, which v2 types with a space for an argument, and the server's commands, which its menu only types. Those include init and review, which Ovis's catalog lists as builtins, and a custom command folded into one of those rows.
  • src/components/Composer.tsx: selectCompletion remembers the text such a pick left, and any typing or paste in the box forgets it. send drops the trailing space only when the box still holds that pick, unchanged, with no comments attached. A remount forgets the pick too, and then it goes with its space, as on main.

Everything else goes as typed, exactly as on main: OpenCode's custom, project and plugin commands, its built-ins that take an argument, every other agent's picks (Codex's $skill too), a /new typed by hand, a pick edited afterwards, and the terminal input line. composerMessage is unchanged.

The first head of this PR stripped the space from every one-word / or $ message, and the second from every OpenCode builtin row. The merge pass's reviews found that this broke commands OpenCode's menu only types (custom ones, review, init). Both are replaced by the allow-list.

Validation

  • Reproduced live on origin/main (79420d0) against OpenCode 2.2.7 (the reporter's version, release binary) in an isolated herdr session with a scratch HOME. With a session open, the menu-picked text /new went through composerMessage and createSubmitText on the real herdr socket, and OpenCode answered it as a prompt ("I can't start a new session from here — /new is a TUI command…"). Sent bare, /new opened a new session.
  • The review's finding, checked live on 2.2.7 the same way through herdr's agent.prompt: a project command /hello with its space ran (the agent replied with the command's template answer). Bare /hello stayed in OpenCode's box and nothing ran. A bare /rename on the home screen was replaced by the menu's highlighted /review and nothing ran. So these keep their space.
  • src/components/ComposerBarePick.test.tsx (new): through the real Composer, typing then Enter on the menu row then Enter to send:
    • a picked OpenCode /new goes bare (fails with the send-side check switched off);
    • an OpenCode project command, /rename, and Claude Code's /new keep their space;
    • a pick edited afterwards and a hand-typed /new go as typed.
  • src/lib/compose.test.ts: sendsBarePick for OpenCode built-ins with and without an argument, init and review, user, project, plugin and skill rows, the @ skill, and other agents.
  • ComposerBarePick.test.tsx also covers a picked /review (a builtin row OpenCode's menu only types), which keeps its space, and a pick that was sent followed by /new typed by hand, which goes as typed. Each fails against the code it guards: the /review cases with the previous deny-list rule, and the hand-typed case without the clear on typing.
  • bun scripts/agent-skill-menu-demo-regression.ts (all 15 cases, OpenCode's included): pass (170 screenshots, no timeouts).
  • bun test src/lib/compose.test.ts src/components/ComposerBarePick.test.tsx src/components/ComposerPasteSend.test.tsx src/components/ComposerRestored.test.tsx src/components/ComposerCrossTab.test.tsx: all pass.
  • bun run check fast: all ok (typecheck, build, unit 17248 pass / 0 fail / 54 skip).
  • Skipped: browser regressions (no layout change; the composer's send text only), and a live Codex $skill check (no longer touched).

@coderabbitai

coderabbitai Bot commented Nov 14, 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
    • Bare slash and skill commands selected from the chat menu now run as commands when sent, even if the menu adds trailing spaces.
    • Trailing spaces in regular text are preserved, and text or newlines following a command remain unchanged.

composerMessage now removes trailing spaces from complete slash and dollar commands. Tests cover command messages and payloads, while confirming that prose and text after a command retain their trailing spaces. The changelog records the change.

Changes: Chat command whitespace

Layer / File(s) Summary
Command normalization and validation
src/lib/compose.ts, src/lib/compose.test.ts, changelog.d/chat-bare-command-space.md
composerMessage trims trailing spaces from complete slash and dollar commands. Tests cover bare commands, payloads, prose, and text after commands. The changelog documents the behavior.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: demrom, jpcarranza94

Merge Risk: Minimal · previous review 5a5e8

Menu-picked commands such as /new are now sent without the trailing space the menu adds, so they run instead of being treated as prompts. Text after a command keeps its spaces. No remaining merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: a menu-picked command is now sent without its trailing space, which matches the compose.ts change and the linked issue about /new opening a prompt instead of a session. It …
Linked Issues check Passed Issue #3813 asks that /new sent from Chat to an OpenCode pane run as a new session, or else show the "Runs in the terminal" outcome, and not be sent as a prompt. The diff adds one rule to `composerM…
Out of Scope Changes check Passed The only code change is in composerMessage in src/lib/compose.ts, the function that prepares the sent message. The change is directly tied to #3813. The changelog entry and tests support this chan…
Description check Passed The description follows the template's two sections: Change and Validation. The Change section explains the cause (Chat's menu inserts a trailing space, which OpenCode treats as a prompt), the allow-l…
Full details: Title check

Explanation

The title names the change: a menu-picked command is now sent without its trailing space, which matches the compose.ts change and the linked issue about /new opening a prompt instead of a session. It is specific and concise.

Full details: Linked Issues check

Explanation

Issue #3813 asks that /new sent from Chat to an OpenCode pane run as a new session, or else show the "Runs in the terminal" outcome, and not be sent as a prompt. The diff adds one rule to composerMessage in src/lib/compose.ts: /^[/$]\S+[ \t]+$/u matches a message that is one command followed only by spaces or tabs, and trimEnd() removes those characters. The menu-inserted /new is therefore sent as /new, which is the form OpenCode runs from its TUI. The root cause the PR describes (OpenCode runs a no-argument command only from its autocomplete, and the trailing space closes that popup) is consistent with the issue's report. The new-session outcome in OpenCode 2.2.7 is an external behavior. The PR author reports reproducing it, and I did not run it. The unit assertions in src/lib/compose.test.ts are described in the PR but were not inspected here. Coding requirement is met by the code change; runtime outcome rests on the author's reproduction.

Full details: Out of Scope Changes check

Explanation

The only code change is in composerMessage in src/lib/compose.ts, the function that prepares the sent message. The change is directly tied to #3813. The changelog entry and tests support this change. Text with arguments, multi-line text, and plain prose do not match the regex and keep their spaces, as the PR states. A minor side effect exists: a single slash- or dollar-prefixed token followed by a space (for example /usr/bin ) also loses the trailing space. This follows the stated rule for one command and is not an unrelated change.

Full details: Description check

Explanation

The description follows the template's two sections: Change and Validation. The Change section explains the cause (Chat's menu inserts a trailing space, which OpenCode treats as a prompt), the allow-list fix in compose.ts and Composer.tsx, and the cases left unchanged. The Validation section lists the live reproduction, new and existing tests, and the checks run (bun run check fast, bun test, a regression script), with browser regressions noted as skipped. The template's CONTRIBUTING.md reference and the changelog entry are not mentioned in the description, but the diff summary shows changelog.d/chat-bare-command-space.md was added. The description is thorough and specific, so it is mostly complete.

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 79420d0 and 5a5e878.

Files selected for processing: 3

  • changelog.d/chat-bare-command-space.md
  • src/lib/compose.test.ts
  • src/lib/compose.ts

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

devswha added a commit that referenced this pull request Nov 14, 2026
… the rows (#3844)

## Summary
A Settings row's sentence (#3758) can lie over a button outside the rows
and take its click. Two CI runs on unrelated PRs timed out on such a
click, 30 s each:

- #3836, run 43574490532: `scripts/settings-page.ts:21` in
`settings-segmented` (Japanese, 320 px, text size 20), the click on
設定に戻る (Back to settings).
- #3835, run 43574013739: `scripts/push-health-demo-regression.ts:248`
(Korean), the click on 알림 다시 켜기 (Turn alerts on again), twice.

In both, Playwright found the button visible, enabled and stable, but
`div.settings-help` intercepted pointer events. The test had left the
mouse resting on a row after a click, so that row's sentence opened, and
a long Japanese or Korean sentence reached the button.

`place()` cut the sentence out (#3810) only over the controls of other
`.settings-row`s: their children other than `.settings-row-text`. A
page's Back is in the dialog's header, and the Alerts repair button is
in a row's condition, inside `.settings-row-text`, so the sentence lay
on both, and the pointer there was the sentence's. A user moving the
mouse to either button met the same.

`sentenceControls(row)` now also counts every button, link and field in
the row's dialog that is outside this row and outside the sentence, so
the sentence is cut out over them as over another row's controls. This
follows the rule #3810 set for the sentence: where it lies on a control,
the pointer is the control's.

## Validation
- `bun scripts/settings-rows-demo-regression.ts`,
`settings-segmented-demo-regression.ts`,
`push-health-demo-regression.ts` and `settings-pages-demo-regression.ts`
pass with the change (after `bun run build`).
- `bun run check fast` passes, on main 6c64181.
- Not reproduced locally. Six regression designs, from 1440 px down to
320 px, in English and Japanese, with the mouse resting on rows and with
the keyboard on every control of Appearance and Alerts, found no
sentence lying on Back, on main or with the change, so this PR adds no
check that fails on main. The two CI logs above are the evidence for the
cause; the next run of those scripts under load is the check that it is
gone.
- Seen on the way, not changed here: at 320 px in Japanese at text size
20, the Theme file row's ファイル形式 link lies over the row's name.
@devswha
devswha merged commit 91f50d6 into main Nov 14, 2026
13 of 14 checks passed
@devswha

devswha commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head e85d10822879 as 91f50d6de792 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Two reviewers at this head: Claude (Opus) CLEAR, Codex Terra CLEAR. Three heads were reviewed. src/ only; outside the release freeze. Fixes #3813 (OpenCode /new sent as a prompt).

A command picked from Chat's / menu in an OpenCode pane is sent without its trailing space only when it is one of OpenCode's own built-ins that take no argument; every other pick (built-ins with arguments, /review and /init, which are server commands, and user, project and plugin commands) keeps the space, as on main. Closed in review: the second head sent /review and /init bare (Opus, reproduced).

Left (traced; both fail as a plain prompt or a rare second tab): a remounted composer forgets the pick, so the unchanged /new is sent with its space as on main; the pick marker is not cleared when a send settles, so a /new that reaches the box from another tab without an edit is sent bare; the client's allow-list is a second source of truth beside server/skills/opencode.ts.

@devswha
devswha deleted the fix/chat-bare-command-space branch November 14, 2026 18: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.

chat: /new on an OpenCode pane is sent as a prompt, not a new session

1 participant