From 8062658e294cfec8a5f82214063221743f7db0b4 Mon Sep 17 00:00:00 2001 From: lee Date: Sat, 25 Apr 2026 16:31:00 +0800 Subject: [PATCH] fix(acp): dedupe slash command results [T-04-25-fix-slash-command-search] --- src/contexts/acp-connections-context.tsx | 25 ++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/contexts/acp-connections-context.tsx b/src/contexts/acp-connections-context.tsx index 6719728..cff4172 100644 --- a/src/contexts/acp-connections-context.tsx +++ b/src/contexts/acp-connections-context.tsx @@ -551,6 +551,26 @@ function sameCommands( return true } +function dedupeCommandsByName( + commands: AvailableCommandInfo[] +): AvailableCommandInfo[] { + const seen = new Set() + let deduped: AvailableCommandInfo[] | null = null + + for (let i = 0; i < commands.length; i += 1) { + const command = commands[i] + if (seen.has(command.name)) { + deduped ??= commands.slice(0, i) + continue + } + + seen.add(command.name) + deduped?.push(command) + } + + return deduped ?? commands +} + function applyStreamingAction( conn: ConnectionState, action: StreamingAction @@ -1194,11 +1214,12 @@ function connectionsReducer( case "AVAILABLE_COMMANDS": { const conn = state.get(action.contextKey) if (!conn) return state - if (sameCommands(conn.availableCommands, action.commands)) return state + const commands = dedupeCommandsByName(action.commands) + if (sameCommands(conn.availableCommands, commands)) return state const next = new Map(state) next.set(action.contextKey, { ...conn, - availableCommands: action.commands, + availableCommands: commands, }) return next }