Skip to content

Commit 2f829ae

Browse files
authored
Merge pull request #220 from shoemoney/fix/dedupe-getallcommands
fix(registry): dedupe getAllCommands so aliased commands are not exported twice
2 parents 7ba4460 + 8f352b6 commit 2f829ae

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/registry.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,17 @@ class CommandRegistry {
5858
}
5959

6060
getAllCommands(): Command[] {
61+
// Aliases register the same Command object under more than one path
62+
// ('speech generate' -> speechSynthesize, 'search web' -> searchQuery), so
63+
// a plain traversal yields it once per alias. Dedupe by identity: callers
64+
// want the set of distinct commands, not the set of invocation paths.
65+
const seen = new Set<Command>();
6166
const commands: Command[] = [];
6267
const traverse = (node: CommandNode) => {
63-
if (node.command) commands.push(node.command);
68+
if (node.command && !seen.has(node.command)) {
69+
seen.add(node.command);
70+
commands.push(node.command);
71+
}
6472
for (const child of node.children.values()) {
6573
traverse(child);
6674
}

0 commit comments

Comments
 (0)