diff --git a/src/features/chat/composer/suggestions.ts b/src/features/chat/composer/suggestions.ts index dd2d04a2..71cfb0a9 100644 --- a/src/features/chat/composer/suggestions.ts +++ b/src/features/chat/composer/suggestions.ts @@ -158,7 +158,7 @@ function compareWikiLinkSuggestionTiebreakers(a: NoteCandidateMatch, b: NoteCand } export function activeSlashCommandSuggestions(beforeCursor: string): ComposerSuggestion[] | null { - const match = /(?:^|\n)(\/[A-Za-z-]*)$/.exec(beforeCursor); + const match = /^(\/[A-Za-z-]*)$/.exec(beforeCursor); if (match?.index === undefined) return null; const rawQuery = match[1]; @@ -178,7 +178,7 @@ export function activeSlashCommandSuggestions(beforeCursor: string): ComposerSug } export function activeThreadCommandSuggestions(beforeCursor: string, threads: readonly Thread[]): ComposerSuggestion[] | null { - const match = /(?:^|\n)\/(?:resume|refer|archive)\s+([^\s\n]{0,120})$/.exec(beforeCursor); + const match = /^\/(?:resume|refer|archive)\s+([^\s\n]{0,120})$/.exec(beforeCursor); if (match?.index === undefined) return null; const rawQuery = match[1]; @@ -208,7 +208,7 @@ export function activeThreadCommandSuggestions(beforeCursor: string, threads: re } export function activeModelOverrideSuggestions(beforeCursor: string, models: readonly Model[]): ComposerSuggestion[] | null { - const match = /(?:^|\n)\/model\s+([^\n]{0,120})$/.exec(beforeCursor); + const match = /^\/model\s+([^\n]{0,120})$/.exec(beforeCursor); if (match?.index === undefined) return null; const rawQuery = match[1]; @@ -255,7 +255,7 @@ export function activeReasoningEffortSuggestions( models: readonly Model[], currentModel: string | null, ): ComposerSuggestion[] | null { - const match = /(?:^|\n)\/effort\s+([^\n]{0,120})$/.exec(beforeCursor); + const match = /^\/effort\s+([^\n]{0,120})$/.exec(beforeCursor); if (match?.index === undefined) return null; const rawQuery = match[1]; diff --git a/tests/features/chat/composer/composer-suggestions.test.ts b/tests/features/chat/composer/composer-suggestions.test.ts index 681b5719..5e6bfe72 100644 --- a/tests/features/chat/composer/composer-suggestions.test.ts +++ b/tests/features/chat/composer/composer-suggestions.test.ts @@ -175,6 +175,16 @@ describe("composer suggestions", () => { expect(activeComposerSuggestions("/help", notes, [])).toEqual([]); }); + it("limits slash command suggestions to the start of the composer", () => { + const threads = [thread({ id: "019abcde-0000-7000-8000-000000000001", name: "Codex Panel実装" })]; + const models = [model("gpt-5.5", ["low", "medium", "high"])]; + + expect(activeComposerSuggestions("please\n/sta", notes, [])).toEqual([]); + expect(activeComposerSuggestions("please\n/resume codex", notes, [], threads)).toEqual([]); + expect(activeComposerSuggestions("please\n/model gpt", notes, [], [], models)).toEqual([]); + expect(activeComposerSuggestions("please\n/effort h", notes, [], [], models, "gpt-5.5")).toEqual([]); + }); + it("suggests recent threads for /resume, /refer, and /archive arguments", () => { const threads = [ thread({ id: "019abcde-0000-7000-8000-000000000001", name: "Codex Panel実装" }),