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
19 changes: 15 additions & 4 deletions src/cli/agent-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,24 @@ function formatForAgent(meta: AgentCommandMeta) {
return result;
}

/** Maps deprecated command paths to their current canonical equivalents. */
const commandAliases: Record<string, string> = {
'workspace status': 'status',
};

function resolveAlias(commandPath: string): string {
return commandAliases[commandPath] ?? commandPath;
}

/**
* Look up a meta by the runtime command path (e.g. "skills list").
* Resolves deprecated aliases (e.g. "workspace status" -> "status").
* Used by index.ts to validate `--json=<fields>` against the per-command
* allowlist before dispatching.
*/
export function findMetaByCommand(commandPath: string): AgentCommandMeta | undefined {
if (!commandPath) return undefined;
return allCommands.find((c) => c.command === commandPath);
return allCommands.find((c) => c.command === resolveAlias(commandPath));
}

export function printAgentHelp(args: string[], version: string): void {
Expand All @@ -98,16 +108,17 @@ export function printAgentHelp(args: string[], version: string): void {
};
console.log(JSON.stringify(tree, null, 2));
} else {
const resolved = resolveAlias(commandPath);
// Find exact matching command
const match = allCommands.find(c => c.command === commandPath);
const match = allCommands.find(c => c.command === resolved);
if (match) {
console.log(JSON.stringify(formatForAgent(match), null, 2));
} else {
// Try prefix match for subcommand groups
const matches = allCommands.filter(c => c.command.startsWith(`${commandPath} `));
const matches = allCommands.filter(c => c.command.startsWith(`${resolved} `));
if (matches.length > 0) {
const group = {
name: commandPath,
name: resolved,
commands: matches.map(formatForAgent),
};
console.log(JSON.stringify(group, null, 2));
Expand Down
24 changes: 23 additions & 1 deletion tests/unit/cli/agent-help.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, expect } from 'bun:test';
import { extractAgentHelpFlag } from '../../../src/cli/agent-help.js';
import { extractAgentHelpFlag, findMetaByCommand } from '../../../src/cli/agent-help.js';
import { initMeta, syncMeta, statusMeta } from '../../../src/cli/metadata/workspace.js';
import {
marketplaceListMeta,
Expand Down Expand Up @@ -137,3 +137,25 @@ describe('agent command metadata', () => {
expect(statusCmd.options).toBeUndefined();
});
});

describe('findMetaByCommand', () => {
test('resolves canonical "status" path', () => {
const meta = findMetaByCommand('status');
expect(meta).toBeDefined();
expect(meta!.command).toBe('status');
});

test('resolves deprecated "workspace status" alias to status meta', () => {
const meta = findMetaByCommand('workspace status');
expect(meta).toBeDefined();
expect(meta!.command).toBe('status');
});

test('returns undefined for unknown command', () => {
expect(findMetaByCommand('workspace frobnicate')).toBeUndefined();
});

test('returns undefined for empty string', () => {
expect(findMetaByCommand('')).toBeUndefined();
});
});