Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 7 additions & 0 deletions test/commands/aliases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Loading