Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/renderer/src/screens/Chat/slash/commandCatalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,22 @@ describe("slash command catalog", () => {
}),
).toThrow("Duplicate slash command: /inspect");
});

it("ignores alias entries that duplicate an already-registered command", () => {
const upstream = agentCommandsFromCatalog({
pairs: [
["/compact", "Compact and summarize the conversation"],
["/compress", "Compress conversation with optional focus topic"],
],
canon: { compact: "compress" },
});

const catalog = createSlashCatalog({
agentCommands: upstream.commands,
aliases: upstream.aliases,
});

expect(catalog.resolve("/compact")?.name).toBe("compact");
expect(catalog.resolve("/compress")?.name).toBe("compress");
});
});
2 changes: 1 addition & 1 deletion src/renderer/src/screens/Chat/slash/commandCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function registerAlias(
);
}
if (byName.has(aliasKey) || aliases.has(aliasKey)) {
throw new Error(`Duplicate slash command alias: /${aliasKey}`);
return;
}
Comment on lines 45 to 47

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silent alias-vs-alias conflict silently drops second mapping

The early return now fires both when the alias key collides with a canonical command (the intended fix) and when it collides with an already-registered alias pointing to a different target. In the second case — e.g., if agent commands and desktop commands each define "/r" → different targets — the second registration silently loses with no observable feedback. The upstream agentCommandsFromCatalog protects against this today because Object.entries de-dupes object keys, but future callers that supply aliases from two independent sources could hit it and get the wrong resolution without any warning. A dev-mode console.warn on the aliases.has(aliasKey) branch would make this detectable.

aliases.set(aliasKey, targetKey);
}
Expand Down