summaryrefslogtreecommitdiff
path: root/packages/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src')
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.test.ts54
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.ts59
2 files changed, 96 insertions, 17 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
index 3e0a768c..845cbe92 100644
--- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
+++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
@@ -595,14 +595,9 @@ Add any other context about the problem here.
});
// Should only show tool1 and tool2, not the MCP tools
- expect(mockAddItem).toHaveBeenNthCalledWith(
- 2,
- expect.objectContaining({
- type: MessageType.INFO,
- text: 'Available Gemini CLI tools:\n\nTool1\nTool2',
- }),
- expect.any(Number),
- );
+ const message = mockAddItem.mock.calls[1][0].text;
+ expect(message).toContain('\u001b[36mTool1\u001b[0m');
+ expect(message).toContain('\u001b[36mTool2\u001b[0m');
expect(commandResult).toBe(true);
});
@@ -626,14 +621,43 @@ Add any other context about the problem here.
commandResult = await handleSlashCommand('/tools');
});
- expect(mockAddItem).toHaveBeenNthCalledWith(
- 2,
- expect.objectContaining({
- type: MessageType.INFO,
- text: 'Available Gemini CLI tools:\n\n',
+ const message = mockAddItem.mock.calls[1][0].text;
+ expect(message).toContain('No tools available');
+ expect(commandResult).toBe(true);
+ });
+
+ it('should display tool descriptions when /tools desc is used', async () => {
+ const mockTools = [
+ {
+ name: 'tool1',
+ displayName: 'Tool1',
+ description: 'Description for Tool1',
+ },
+ {
+ name: 'tool2',
+ displayName: 'Tool2',
+ description: 'Description for Tool2',
+ },
+ ];
+
+ mockConfig = {
+ ...mockConfig,
+ getToolRegistry: vi.fn().mockResolvedValue({
+ getAllTools: vi.fn().mockReturnValue(mockTools),
}),
- expect.any(Number),
- );
+ } as unknown as Config;
+
+ const { handleSlashCommand } = getProcessor();
+ let commandResult: SlashCommandActionReturn | boolean = false;
+ await act(async () => {
+ commandResult = await handleSlashCommand('/tools desc');
+ });
+
+ const message = mockAddItem.mock.calls[1][0].text;
+ expect(message).toContain('\u001b[36mTool1\u001b[0m');
+ expect(message).toContain('Description for Tool1');
+ expect(message).toContain('\u001b[36mTool2\u001b[0m');
+ expect(message).toContain('Description for Tool2');
expect(commandResult).toBe(true);
});
});
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
index 9a9b7596..f03761ff 100644
--- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts
+++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts
@@ -419,6 +419,21 @@ export const useSlashCommandProcessor = (
name: 'tools',
description: 'list available Gemini CLI tools',
action: async (_mainCommand, _subCommand, _args) => {
+ // Check if the _subCommand includes a specific flag to control description visibility
+ let useShowDescriptions = showToolDescriptions;
+ if (_subCommand === 'desc' || _subCommand === 'descriptions') {
+ useShowDescriptions = true;
+ } else if (
+ _subCommand === 'nodesc' ||
+ _subCommand === 'nodescriptions'
+ ) {
+ useShowDescriptions = false;
+ } else if (_args === 'desc' || _args === 'descriptions') {
+ useShowDescriptions = true;
+ } else if (_args === 'nodesc' || _args === 'nodescriptions') {
+ useShowDescriptions = false;
+ }
+
const toolRegistry = await config?.getToolRegistry();
const tools = toolRegistry?.getAllTools();
if (!tools) {
@@ -432,11 +447,51 @@ export const useSlashCommandProcessor = (
// Filter out MCP tools by checking if they have a serverName property
const geminiTools = tools.filter((tool) => !('serverName' in tool));
- const geminiToolList = geminiTools.map((tool) => tool.displayName);
+
+ let message = 'Available Gemini CLI tools:\n\n';
+
+ if (geminiTools.length > 0) {
+ geminiTools.forEach((tool) => {
+ if (useShowDescriptions && tool.description) {
+ // Format tool name in cyan using simple ANSI cyan color
+ message += ` - \u001b[36m${tool.displayName}\u001b[0m: `;
+
+ // Apply green color to the description text
+ const greenColor = '\u001b[32m';
+ const resetColor = '\u001b[0m';
+
+ // Handle multi-line descriptions by properly indenting and preserving formatting
+ const descLines = tool.description.split('\n');
+ message += `${greenColor}${descLines[0]}${resetColor}\n`;
+
+ // If there are multiple lines, add proper indentation for each line
+ if (descLines.length > 1) {
+ for (let i = 1; i < descLines.length; i++) {
+ // Skip empty lines at the end
+ if (
+ i === descLines.length - 1 &&
+ descLines[i].trim() === ''
+ )
+ continue;
+ message += ` ${greenColor}${descLines[i]}${resetColor}\n`;
+ }
+ }
+ } else {
+ // Use cyan color for the tool name even when not showing descriptions
+ message += ` - \u001b[36m${tool.displayName}\u001b[0m\n`;
+ }
+ });
+ } else {
+ message += ' No tools available\n';
+ }
+ message += '\n';
+
+ // Make sure to reset any ANSI formatting at the end to prevent it from affecting the terminal
+ message += '\u001b[0m';
addMessage({
type: MessageType.INFO,
- content: `Available Gemini CLI tools:\n\n${geminiToolList.join('\n')}`,
+ content: message,
timestamp: new Date(),
});
},