Skip to content

Commit 30a472b

Browse files
aworkicocosheng-ggsquared94
authored andcommitted
feat(cli): expose /tools desc as explicit subcommand for discoverability (google-gemini#21241)
Co-authored-by: Coco Sheng <cocosheng@google.com> Co-authored-by: Gaurav <39389231+gsquared94@users.noreply.github.com>
1 parent 89e013c commit 30a472b

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed

packages/cli/src/ui/commands/toolsCommand.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,28 @@ describe('toolsCommand', () => {
110110
);
111111
expect(message.tools[1].description).toBe('Edits code files.');
112112
});
113+
114+
it('should expose a desc subcommand for TUI discoverability', async () => {
115+
const descSubCommand = toolsCommand.subCommands?.find(
116+
(cmd) => cmd.name === 'desc',
117+
);
118+
expect(descSubCommand).toBeDefined();
119+
expect(descSubCommand?.description).toContain('descriptions');
120+
121+
const mockContext = createMockCommandContext({
122+
services: {
123+
config: {
124+
getToolRegistry: () => ({ getAllTools: () => mockTools }),
125+
},
126+
},
127+
});
128+
129+
if (!descSubCommand?.action) throw new Error('Action not defined');
130+
await descSubCommand.action(mockContext, '');
131+
132+
const [message] = (mockContext.ui.addItem as ReturnType<typeof vi.fn>).mock
133+
.calls[0];
134+
expect(message.type).toBe(MessageType.TOOLS_LIST);
135+
expect(message.showDescriptions).toBe(true);
136+
});
113137
});

packages/cli/src/ui/commands/toolsCommand.ts

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,60 @@ import {
1111
} from './types.js';
1212
import { MessageType, type HistoryItemToolsList } from '../types.js';
1313

14+
async function listTools(
15+
context: CommandContext,
16+
showDescriptions: boolean,
17+
): Promise<void> {
18+
const toolRegistry = context.services.config?.getToolRegistry();
19+
if (!toolRegistry) {
20+
context.ui.addItem({
21+
type: MessageType.ERROR,
22+
text: 'Could not retrieve tool registry.',
23+
});
24+
return;
25+
}
26+
27+
const tools = toolRegistry.getAllTools();
28+
// Filter out MCP tools by checking for the absence of a serverName property
29+
const geminiTools = tools.filter((tool) => !('serverName' in tool));
30+
31+
const toolsListItem: HistoryItemToolsList = {
32+
type: MessageType.TOOLS_LIST,
33+
tools: geminiTools.map((tool) => ({
34+
name: tool.name,
35+
displayName: tool.displayName,
36+
description: tool.description,
37+
})),
38+
showDescriptions,
39+
};
40+
41+
context.ui.addItem(toolsListItem);
42+
}
43+
44+
const toolsDescSubCommand: SlashCommand = {
45+
name: 'desc',
46+
altNames: ['descriptions'],
47+
description: 'List available Gemini CLI tools with descriptions.',
48+
kind: CommandKind.BUILT_IN,
49+
autoExecute: true,
50+
action: async (context: CommandContext): Promise<void> =>
51+
listTools(context, true),
52+
};
53+
1454
export const toolsCommand: SlashCommand = {
1555
name: 'tools',
16-
description: 'List available Gemini CLI tools. Usage: /tools [desc]',
56+
description:
57+
'List available Gemini CLI tools. Use /tools desc to include descriptions.',
1758
kind: CommandKind.BUILT_IN,
1859
autoExecute: false,
60+
subCommands: [toolsDescSubCommand],
1961
action: async (context: CommandContext, args?: string): Promise<void> => {
2062
const subCommand = args?.trim();
2163

22-
// Default to NOT showing descriptions. The user must opt in with an argument.
23-
let useShowDescriptions = false;
24-
if (subCommand === 'desc' || subCommand === 'descriptions') {
25-
useShowDescriptions = true;
26-
}
27-
28-
const toolRegistry = context.services.config?.getToolRegistry();
29-
if (!toolRegistry) {
30-
context.ui.addItem({
31-
type: MessageType.ERROR,
32-
text: 'Could not retrieve tool registry.',
33-
});
34-
return;
35-
}
36-
37-
const tools = toolRegistry.getAllTools();
38-
// Filter out MCP tools by checking for the absence of a serverName property
39-
const geminiTools = tools.filter((tool) => !('serverName' in tool));
40-
41-
const toolsListItem: HistoryItemToolsList = {
42-
type: MessageType.TOOLS_LIST,
43-
tools: geminiTools.map((tool) => ({
44-
name: tool.name,
45-
displayName: tool.displayName,
46-
description: tool.description,
47-
})),
48-
showDescriptions: useShowDescriptions,
49-
};
50-
51-
context.ui.addItem(toolsListItem);
64+
// Keep backward compatibility for typed arguments while exposing desc in TUI via subcommands.
65+
const useShowDescriptions =
66+
subCommand === 'desc' || subCommand === 'descriptions';
67+
68+
await listTools(context, useShowDescriptions);
5269
},
5370
};

0 commit comments

Comments
 (0)