Compare commits

...
Author SHA1 Message Date
Mohamed Boudra 78eb6aa770 chore(app): tag app-side command deduplication as a COMPAT shim 2026-11-20 07:57:49 +01:00
Mohamed Boudra 6ff1c4deca refactor(commands): enforce unique command names at daemon and app boundaries
Move slash-command deduplication from six per-provider and per-consumer copies to the two single boundaries: handleListCommandsRequest in packages/server/src/server/session.ts (covering live agents and drafts for every provider) and fetchAgentCommands in packages/app/src/agent-commands/use-query.ts (covering all app consumers, including against older daemons).
2026-11-20 07:50:19 +01:00
Mohamed Boudra 91fac29fae fix(commands): deduplicate provider slash commands by name
Antigravity ACP emits both its built-in slash commands and discovered skills in one available_commands_update without deduplicating colliding names (such as a local plan skill alongside built-in /plan). Both entries flowed through plugin ACP, plugin-provider, and mergeSlashCommandSources into Autocomplete's FlatList, triggering React's duplicate key error on .$plan.

Enforce unique command names (first-wins) at the plugin ACP, plugin provider, core ACP, and Codex boundaries so every daemon consumer gets a valid catalog, and claim provider command names in mergeSlashCommandSources and inline skill filtering so the app stays safe against older daemons.
2026-11-20 07:05:22 +01:00
4 changed files with 121 additions and 3 deletions
@@ -66,4 +66,23 @@ describe("fetchAgentCommands", () => {
expect(client.calls).toEqual([{ agentId: "agent-1", draftConfig: undefined }]);
});
it("deduplicates duplicate command names from the daemon, keeping the first entry", async () => {
const client = createClient(
commandsPayload([
{ name: "goal", description: "Run until goal is finished", argumentHint: "" },
{ name: "plan", description: "Plan carefully before executing a task.", argumentHint: "" },
{ name: "plan", description: "Local plan skill description", argumentHint: "" },
{ name: "review", description: "Review changes", argumentHint: "" },
]),
);
const commands = await fetchAgentCommands({ client, agentId: "agent-1" });
expect(commands).toEqual([
{ name: "goal", description: "Run until goal is finished", argumentHint: "" },
{ name: "plan", description: "Plan carefully before executing a task.", argumentHint: "" },
{ name: "review", description: "Review changes", argumentHint: "" },
]);
});
});
+13 -1
View File
@@ -37,6 +37,18 @@ export interface AgentCommandsClient {
listCommands(options: ListAgentCommandsOptions): ReturnType<DaemonClient["listCommands"]>;
}
// COMPAT(dedupeListCommands): added in v0.17.0, remove after 2027-05-20 once daemon floor >= v0.17.0.
function dedupeSlashCommands(commands: readonly AgentSlashCommand[]): AgentSlashCommand[] {
const seen = new Set<string>();
const unique: AgentSlashCommand[] = [];
for (const command of commands) {
if (seen.has(command.name)) continue;
seen.add(command.name);
unique.push(command);
}
return unique;
}
export async function fetchAgentCommands(input: {
client: AgentCommandsClient;
agentId: string;
@@ -47,7 +59,7 @@ export async function fetchAgentCommands(input: {
draftConfig: input.draftConfig,
});
if (response.error) throw new Error(response.error);
return response.commands as AgentSlashCommand[];
return dedupeSlashCommands(response.commands as AgentSlashCommand[]);
}
interface UseAgentCommandsQueryOptions {
@@ -6661,3 +6661,77 @@ test("does not publish internal agents' background work to subscribed clients",
await new Promise<void>((resolve) => setImmediate(resolve));
expect(messages.some((message) => message.type === "agent.background_work.update")).toBe(false);
});
test("deduplicates repeated command names in list_commands_response for live agents and drafts", async () => {
const duplicateCommands = [
{
name: "goal",
description: "Run until goal is finished",
argumentHint: "",
kind: "command" as const,
},
{
name: "plan",
description: "Plan carefully before executing a task.",
argumentHint: "",
kind: "command" as const,
},
{
name: "plan",
description: "Local plan skill description",
argumentHint: "",
kind: "skill" as const,
},
];
const expected = [duplicateCommands[0], duplicateCommands[1]];
const liveMessages: SessionOutboundMessage[] = [];
const liveSession = createSessionForTest({
messages: liveMessages,
agentManager: {
waitForAgentClose: async () => undefined,
getAgent: () =>
({
id: "agent-1",
session: { listCommands: async () => duplicateCommands },
}) as never,
},
});
await liveSession.handleMessage({
type: "list_commands_request",
agentId: "agent-1",
requestId: "req-live",
});
expect(findByType(liveMessages, "list_commands_response")).toMatchObject({
payload: {
agentId: "agent-1",
requestId: "req-live",
error: null,
commands: expected,
},
});
const draftMessages: SessionOutboundMessage[] = [];
const draftSession = createSessionForTest({
messages: draftMessages,
agentManager: {
getAgent: () => undefined,
listDraftCommands: async () => duplicateCommands,
},
agentStorage: { get: async () => null },
});
await draftSession.handleMessage({
type: "list_commands_request",
agentId: "draft-1",
requestId: "req-draft",
draftConfig: { provider: "antigravity", cwd: "/tmp/repo" },
});
expect(findByType(draftMessages, "list_commands_response")).toMatchObject({
payload: {
agentId: "draft-1",
requestId: "req-draft",
error: null,
commands: expected,
},
});
});
+15 -2
View File
@@ -5603,7 +5603,7 @@ export class Session {
: null;
if (agent?.session?.listCommands) {
const commands = await agent.session.listCommands();
const commands = dedupeSlashCommands(await agent.session.listCommands());
this.emit({
type: "list_commands_response",
payload: {
@@ -5627,7 +5627,9 @@ export class Session {
: {}),
};
const commands = await this.agentManager.listDraftCommands(sessionConfig);
const commands = dedupeSlashCommands(
await this.agentManager.listDraftCommands(sessionConfig),
);
this.emit({
type: "list_commands_response",
payload: {
@@ -9614,3 +9616,14 @@ function createHostSession(options: SessionOptions, session: Session): Connected
function hostSource(options: SessionOptions): string {
return options.sourceId ?? "owner";
}
function dedupeSlashCommands<T extends { name: string }>(commands: readonly T[]): T[] {
const seen = new Set<string>();
const unique: T[] = [];
for (const command of commands) {
if (seen.has(command.name)) continue;
seen.add(command.name);
unique.push(command);
}
return unique;
}