fix(registry): dedupe getAllCommands so aliased commands are not exported twice - #220
Conversation
Aliases register the same Command object under more than one path
('speech generate' -> speechSynthesize, 'search web' -> searchQuery), so the
traversal in getAllCommands returned it once per path.
config export-schema maps that list straight to tool schemas, so it emitted 19
entries with only 17 distinct names — mmx_speech_synthesize and mmx_search_query
each appeared twice. Duplicate function names are rejected by both the Anthropic
and OpenAI tool APIs, so the exported schema could not be used as-is.
Dedupe by object identity: callers of getAllCommands want the set of distinct
commands, not the set of invocation paths. Alias routing is unaffected.
There was a problem hiding this comment.
Thanks for the contribution! I verified the current head (8f352b6) against main: config export-schema changes from 19 entries with 17 unique names to 17/17, while the speech generate and search web aliases continue to resolve correctly.
The identity-based deduplication is narrowly scoped and matches the current use of getAllCommands(). The exact-head CI is green, and local validation passed all 449 tests, typecheck, and the development build; lint has no errors (only one unrelated existing warning).
I found no blocking issues, and this looks ready to merge. A direct regression assertion that exported schema names remain unique would be a nice follow-up, but I do not consider it blocking.
Thanks again for the clear explanation and focused fix!
config export-schemacurrently emits 19 tool schemas with only 17 distinct names:Duplicate function names are rejected by both the Anthropic and OpenAI tool APIs, so the exported schema cannot be handed to a model as-is without post-processing.
Cause. Two commands are registered under a second alias path:
CommandRegistry.getAllCommands()walks the path trie and pushesnode.commandat every node that has one — so an aliased command is pushed once per path, not once per command.export-schemamaps that list straight togenerateToolSchema, and the duplicates land in the output.Fix. Dedupe by object identity during the traversal. Callers of
getAllCommandswant the set of distinct commands, not the set of invocation paths.Verified locally (
bun run src/main.ts):Alias routing is untouched —
mmx speech generate --helpandmmx search web --helpboth still resolve and exit 0. Only enumeration changes.bun test: 385 pass / 8 fail, identical to the baseline on a clean checkout with this change stashed. Those 8 appear to be network-dependent (one logsDetecting region... failed) and are unrelated.Happy to add a regression test asserting
getAllCommands().length === new Set(getAllCommands()).sizeif you'd like one — I left it out because the repo's registry tests looked deliberately light, but say the word.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.