Skip to content

Commit 9b523aa

Browse files
authored
Merge pull request #137 from NianJiuZst/codex/fix-search-shorthand
fix: preserve search shorthand with aliases
2 parents 02fbdfb + 01c76cb commit 9b523aa

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/registry.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ class CommandRegistry {
9191
}
9292
}
9393

94+
// Alias-only group: auto-forward when every child points to the same command.
95+
// Example: `mmx search "query"` should work even when both `search query`
96+
// and `search web` are registered as aliases for the same implementation.
97+
if (matched.length > 0 && node.children.size > 1) {
98+
const children = Array.from(node.children.values());
99+
const commands = children.map((child) => child.command);
100+
const first = commands[0];
101+
if (first && commands.every((command) => command === first)) {
102+
return { command: first, extra: commandPath.slice(matched.length) };
103+
}
104+
}
105+
94106
// If we matched some path but no command, show help for that group
95107
if (matched.length > 0 && node.children.size > 0) {
96108
const subcommands = Array.from(node.children.entries())

test/commands/aliases.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ describe('command aliases', () => {
88
expect(web.command).toBe(query.command);
99
});
1010

11+
it('auto-forwards search shorthand when child commands are aliases', () => {
12+
const shorthand = registry.resolve(['search', 'MiniMax AI latest news']);
13+
const query = registry.resolve(['search', 'query']);
14+
expect(shorthand.command).toBe(query.command);
15+
expect(shorthand.extra).toEqual(['MiniMax AI latest news']);
16+
});
17+
1118
it('resolves "speech generate" same as "speech synthesize"', () => {
1219
const generate = registry.resolve(['speech', 'generate']);
1320
const synthesize = registry.resolve(['speech', 'synthesize']);

0 commit comments

Comments
 (0)