Skip to content

The agent that grows with you

fix(desktop): skill pill stops re-firing on slash commands mid-message (#91626)

Brooklyn Nicholson64d38a1790d6
diff --git a/apps/desktop/src/store/suggestion-providers/skill.test.ts b/apps/desktop/src/store/suggestion-providers/skill.test.ts
index f85c29675b8..649567f4d32 100644
--- a/apps/desktop/src/store/suggestion-providers/skill.test.ts
+++ b/apps/desktop/src/store/suggestion-providers/skill.test.ts
@@ -2,12 +2,16 @@ import { describe, expect, it } from 'vitest'
import type { ChatMessage } from '@/lib/chat-messages'
-import { collidesWithWorkspace, skillHit, skillPattern, skillTouchedInMessages } from './skill'
+import { collidesWithWorkspace, skillHit, skillPattern, skillTouchedInMessages, stripSlashTokens } from './skill'
// skillHit is the provider's real predicate: a whole-word match that the user
// has finished typing (at least one character follows it).
const hits = (name: string, draft: string) => skillHit(skillPattern(name), draft.toLowerCase())
+// Exercises the provider's real haystack sanitizer, not a copy of it.
+const hitsAfterSanitize = (name: string, draft: string) =>
+ skillHit(skillPattern(name), stripSlashTokens(draft).toLowerCase())
+
describe('skillPattern + skillHit', () => {
it('matches the exact name as a completed whole word', () => {
expect(hits('perf', 'run the perf loop')).toBe(true)
@@ -125,3 +129,25 @@ describe('skillTouchedInMessages', () => {
expect(skillTouchedInMessages('pr-ready', [])).toBe(false)
})
})
+
+describe('draft haystack sanitization (slash-prefixed skills, #91626)', () => {
+ it('strips slash commands mid-message before scanning', () => {
+ // The bug: "please run /github-auth on this" re-fired the "Use skill:
+ // github-auth" pill because skillHit matched "github-auth" inside the
+ // slash command the user had already typed.
+ expect(hitsAfterSanitize('github-auth', 'please run /github-auth on this')).toBe(false)
+ expect(hitsAfterSanitize('vault', 'When I trigger /vault and /github-auth please')).toBe(false)
+ })
+
+ it('preserves URL fragments mid-prose (no leading whitespace)', () => {
+ // https://example.com/api/v1 is not stripped: the regex only removes
+ // whitespace-bounded slash tokens.
+ expect(hitsAfterSanitize('api', 'visit https://example.com/api/v1 for api docs ')).toBe(true)
+ })
+
+ it('a real prose mention after a slash command still hits', () => {
+ // Stripping the slash token must not blind the provider to a genuine
+ // prose mention elsewhere in the draft.
+ expect(hitsAfterSanitize('github-auth', '/github-auth loaded. Is github-auth any good? ')).toBe(true)
+ })
+})
diff --git a/apps/desktop/src/store/suggestion-providers/skill.ts b/apps/desktop/src/store/suggestion-providers/skill.ts
index 6b203aad55b..d845a2680a3 100644
--- a/apps/desktop/src/store/suggestion-providers/skill.ts
+++ b/apps/desktop/src/store/suggestion-providers/skill.ts
@@ -64,6 +64,15 @@ export function skillHit(pattern: RegExp, haystack: string): boolean {
return false
}
+/** Strip whitespace-bounded /<token> slash commands the user authored, so a
+ * skill name inside a command ("run /github-auth") does not self-trigger the
+ * prose suggestion pill (#91626). Whitespace-bounded on purpose: a URL like
+ * /api/v1 mid-prose has no leading whitespace and is left intact. Exported so
+ * the provider and its tests exercise the same sanitizer instead of a copy. */
+export function stripSlashTokens(text: string): string {
+ return text.replace(/\s\/[\w-]+/g, ' ')
+}
+
/** Workspace homonym guard, exported for tests: a skill named like the
* working directory is the project's name, not a request for the skill.
* Working in `~/www/hermes-agent`, the draft says "hermes-agent" constantly
@@ -219,7 +228,7 @@ registerDraftProvider('skill', async ({ sessionId, text }) => {
return []
}
- const haystack = text.toLowerCase()
+ const haystack = stripSlashTokens(text).toLowerCase()
const cwd = $currentCwd.get()
const skills = await loadIndex()
const matched = skills.filter(skill => skillHit(skill.pattern, haystack) && !collidesWithWorkspace(skill.name, cwd))