Skip to content

feat(app): support slash commands mid-prompt#16263

Open
luisfelipesena wants to merge 4 commits intoanomalyco:devfrom
luisfelipesena:feat/slash-mid-prompt
Open

feat(app): support slash commands mid-prompt#16263
luisfelipesena wants to merge 4 commits intoanomalyco:devfrom
luisfelipesena:feat/slash-mid-prompt

Conversation

@luisfelipesena
Copy link
Contributor

@luisfelipesena luisfelipesena commented Mar 6, 2026

Issue for this PR

Closes #16262

Type of change

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

What does this PR do?

Slash commands (/undo, /new, custom commands) only worked when typed at the start of an empty prompt. The detection regex was rawText.match(/^\/(\S*)$/) which required the entire input to be just the slash command.

This changes three things:

  1. Detection regex: textBeforeCursor.match(/(^|\s)\/(\S*)$/) — detects / after any whitespace, matching how @ mentions already work mid-prompt.
  2. Position tracking: stores slashStart so we know exactly which text fragment to replace.
  3. Selection with context: when a slash command is selected mid-prompt, only the /trigger fragment is replaced (custom commands) or removed (builtin commands), keeping surrounding text and cursor position intact.

Original behavior is preserved: typing /cmd alone in an empty prompt works exactly as before.

How did you verify your code works?

  • 266 existing tests pass
  • Typecheck passes across all 13 packages
  • Manual testing:
    • explain auth /undo — triggers undo, keeps "explain auth " in prompt
    • /new alone — clears and triggers new session (original behavior)
    • fix bug /compact — triggers compact, text preserved
    • URLs like https://example.com/path — no false trigger (/ not preceded by whitespace)
    • Custom slash commands mid-prompt — /trigger replaced inline, cursor positioned correctly

Screenshots / recordings

after-2

Checklist

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

Previously, slash commands only triggered when / was the entire input
(regex: /^\/(\S*)$/). Now they trigger after any whitespace boundary,
matching the @mention behavior.

Changes:
- Regex now matches (^|\s)/command at cursor position
- Track slashStart position in store to know where / was typed
- handleSlashSelect replaces only the /command fragment, preserving
  surrounding text for custom commands
- Builtin commands remove the /trigger fragment and execute normally
- Backward compatible: / at start of empty input still works
luisfelipesena and others added 3 commits March 6, 2026 13:49
Upstream removed pendingAutoAccept from store. Keep slashStart
(added by this branch) and drop pendingAutoAccept.
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.

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

1 participant