Skip to content

feat: mid prompt slash commands - #47450

Closed
benitogf wants to merge 3 commits into
anomalyco:devfrom
benitogf:mid-prompt-commands
Closed

benitogf wants to merge 3 commits into
anomalyco:devfrom
benitogf:mid-prompt-commands

Conversation

@benitogf

@benitogf benitogf commented Sep 5, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #16262

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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:

  • Web/desktop (session-ui) — the detection in the interaction state machine was value.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.
  • Terminal (tui) — the autocomplete had the same start-of-prompt-only limitation. Added slashTriggerIndex (the slash analogue of the existing mentionTriggerIndex) 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 /compact typed 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?

  • Unit tests: session-ui interaction 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 TUI slashTriggerIndex in display.test.ts. All green; bun typecheck clean in both packages.
  • Also fixed a pre-existing session-ui test whose path/URL assertions only passed because its cursor was 0 (so it wasn't actually testing the boundary).
  • Ran it live in the terminal: built a dev binary and drove the TUI — typing explain the auth flow / opens the popover mid-prompt, it lists only custom commands, and selecting /truthseeker produces explain the auth flow /truthseeker with the leading text preserved.

Screenshots / recordings

image

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title Mid prompt commands doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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

@benitogf benitogf changed the title Mid prompt commands feat: mid prompt slash commands Sep 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support slash commands mid-prompt, not only at the start

1 participant