From 01c76cb5ef87465260eafe15571ece96173b0103 Mon Sep 17 00:00:00 2001 From: NianJiuZst <3235467914@qq.com> Date: Tue, 12 May 2026 17:20:55 +0800 Subject: [PATCH] fix: preserve search shorthand with aliases --- src/registry.ts | 12 ++++++++++++ test/commands/aliases.test.ts | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/registry.ts b/src/registry.ts index cf6e67d..26ecddc 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -91,6 +91,18 @@ class CommandRegistry { } } + // Alias-only group: auto-forward when every child points to the same command. + // Example: `mmx search "query"` should work even when both `search query` + // and `search web` are registered as aliases for the same implementation. + if (matched.length > 0 && node.children.size > 1) { + const children = Array.from(node.children.values()); + const commands = children.map((child) => child.command); + const first = commands[0]; + if (first && commands.every((command) => command === first)) { + return { command: first, extra: commandPath.slice(matched.length) }; + } + } + // If we matched some path but no command, show help for that group if (matched.length > 0 && node.children.size > 0) { const subcommands = Array.from(node.children.entries()) diff --git a/test/commands/aliases.test.ts b/test/commands/aliases.test.ts index c0fdf9e..93416a2 100644 --- a/test/commands/aliases.test.ts +++ b/test/commands/aliases.test.ts @@ -8,6 +8,13 @@ describe('command aliases', () => { expect(web.command).toBe(query.command); }); + it('auto-forwards search shorthand when child commands are aliases', () => { + const shorthand = registry.resolve(['search', 'MiniMax AI latest news']); + const query = registry.resolve(['search', 'query']); + expect(shorthand.command).toBe(query.command); + expect(shorthand.extra).toEqual(['MiniMax AI latest news']); + }); + it('resolves "speech generate" same as "speech synthesize"', () => { const generate = registry.resolve(['speech', 'generate']); const synthesize = registry.resolve(['speech', 'synthesize']);