diff options
| author | Billy Biggs <[email protected]> | 2025-06-15 07:56:07 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-15 07:56:07 -0700 |
| commit | da09431be975e6ccc26db536a85313c0a6069360 (patch) | |
| tree | ae9619a564c1145c2ae97c3c8e3825dc6b8cc505 /packages/cli/src/ui/hooks/slashCommandProcessor.ts | |
| parent | 7352cb403c3ba0d70863f4daefefe0fddb56200e (diff) | |
Add support for showing descriptions of CLI tools (#1052)
Adds support for /tools desc to show the full description of tools as provided to the model.
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.ts | 59 |
1 files changed, 57 insertions, 2 deletions
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(), }); }, |
