diff options
| author | Harold Mciver <[email protected]> | 2025-07-16 16:12:22 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-16 20:12:22 +0000 |
| commit | 21eb44b242e045cad957d21b049d00b55abf9489 (patch) | |
| tree | a6fdec98e5ea79285950978ad18960c504f4013c /packages/cli/src/ui/commands/toolsCommand.ts | |
| parent | e4ed1aabac10101a6ad6c25e46e84a3d2091bb88 (diff) | |
update `/tools` to new slash command arch (#4236)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: matt korwel <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/commands/toolsCommand.ts')
| -rw-r--r-- | packages/cli/src/ui/commands/toolsCommand.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/cli/src/ui/commands/toolsCommand.ts b/packages/cli/src/ui/commands/toolsCommand.ts new file mode 100644 index 00000000..f65edd07 --- /dev/null +++ b/packages/cli/src/ui/commands/toolsCommand.ts @@ -0,0 +1,66 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { type CommandContext, type SlashCommand } from './types.js'; +import { MessageType } from '../types.js'; + +export const toolsCommand: SlashCommand = { + name: 'tools', + description: 'list available Gemini CLI tools', + action: async (context: CommandContext, args?: string): Promise<void> => { + const subCommand = args?.trim(); + + // Default to NOT showing descriptions. The user must opt in with an argument. + let useShowDescriptions = false; + if (subCommand === 'desc' || subCommand === 'descriptions') { + useShowDescriptions = true; + } + + const toolRegistry = await context.services.config?.getToolRegistry(); + if (!toolRegistry) { + context.ui.addItem( + { + type: MessageType.ERROR, + text: 'Could not retrieve tool registry.', + }, + Date.now(), + ); + return; + } + + const tools = toolRegistry.getAllTools(); + // Filter out MCP tools by checking for the absence of a serverName property + const geminiTools = tools.filter((tool) => !('serverName' in tool)); + + let message = 'Available Gemini CLI tools:\n\n'; + + if (geminiTools.length > 0) { + geminiTools.forEach((tool) => { + if (useShowDescriptions && tool.description) { + message += ` - \u001b[36m${tool.displayName} (${tool.name})\u001b[0m:\n`; + + const greenColor = '\u001b[32m'; + const resetColor = '\u001b[0m'; + + // Handle multi-line descriptions + const descLines = tool.description.trim().split('\n'); + for (const descLine of descLines) { + message += ` ${greenColor}${descLine}${resetColor}\n`; + } + } else { + message += ` - \u001b[36m${tool.displayName}\u001b[0m\n`; + } + }); + } else { + message += ' No tools available\n'; + } + message += '\n'; + + message += '\u001b[0m'; + + context.ui.addItem({ type: MessageType.INFO, text: message }, Date.now()); + }, +}; |
