Repository navigation
Conversation
Slash command completion previously only opened when the slash was the very first character of the prompt. Detect the slash token immediately before the cursor instead, guarded by a start-or-space boundary so file paths and URLs do not trigger it (mirroring @-mention detection). Selecting a custom command mid-prompt now splices its name in place, preserving the surrounding text and anchoring the cursor after the inserted name. Built-in commands are offered only at prompt-start and in the command menu, so their execution behaviour is unchanged.
Port the mid-prompt slash behaviour to the terminal TUI. The autocomplete now opens the command popover for a slash token anywhere before the cursor (via a new slashTriggerIndex, the slash analogue of mentionTriggerIndex), guarded by a start-or-space boundary so in-word paths and URLs don't trigger it. Selecting a custom command splices its name in place of the typed token instead of clearing everything before the cursor, and anchors the cursor after the inserted name. Built-in slash commands are offered only when the slash starts the prompt, leaving their execution behaviour unchanged. Also fixes a misleading session-ui test whose path/URL assertions only passed because the cursor was at position 0.
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search across multiple relevant keywords (slash commands, mid-prompt custom commands, session-ui interaction state machine, autocomplete popover triggers, and the issue number), the only PR that appears is PR #47450 itself (the current PR). No duplicate PRs found |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #16262
Type of change
What does this PR do?
Slash commands only opened the command popover when the
/was the first character of an empty prompt. This makes them fire anywhere in the input.There are two independent prompt editors, so the change is made in both:
session-ui) — the detection in the interaction state machine wasvalue.match(/^\/(\S*)$/). Changed it to look at the token immediately before the cursor with a start-or-space boundary:value.slice(0, cursor).match(/(?:^|\s)\/(\S*)$/)— the same shape the@-mention branch right above it already uses. On select, a custom command now splices its name in place of the typed token (preserving surrounding text and anchoring the cursor after the inserted name) instead of overwriting the whole buffer.tui) — the autocomplete had the same start-of-prompt-only limitation. AddedslashTriggerIndex(the slash analogue of the existingmentionTriggerIndex) and rewired the custom-command select to delete only the/…token instead of everything before the cursor.Key decision: built-in commands (
/undo,/compact,/model, …) execute actions, so they're only offered when the slash starts the prompt. Mid-prompt completion lists custom commands only (the ones that expand to prompt text). This is why the built-in execution path is untouched — I explicitly did not want a/compacttyped mid-sentence to either run or wipe the text.The
(?:^|\s)boundary is what keeps in-word paths (src/app.tsx) and URLs (https://…) from opening the popover. One honest caveat: an absolute path typed after a space (cat /usr/local) will open the popover while typing, same as@already does — it just shows no matching command.How did you verify your code works?
session-uiinteraction machine + store (mid-prompt open, path/URL non-trigger, in-place splice with correct cursor, "complete the token at the cursor, not the first slash"), and TUIslashTriggerIndexindisplay.test.ts. All green;bun typecheckclean in both packages.session-uitest whose path/URL assertions only passed because its cursor was 0 (so it wasn't actually testing the boundary).explain the auth flow /opens the popover mid-prompt, it lists only custom commands, and selecting/truthseekerproducesexplain the auth flow /truthseekerwith the leading text preserved.Screenshots / recordings
Checklist