2025-07-16 16:12:22 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-20 16:57:34 -04:00
|
|
|
import {
|
|
|
|
|
type CommandContext,
|
|
|
|
|
type SlashCommand,
|
|
|
|
|
CommandKind,
|
|
|
|
|
} from './types.js';
|
2025-09-29 14:27:06 -07:00
|
|
|
import { MessageType, type HistoryItemToolsList } from '../types.js';
|
2025-07-16 16:12:22 -04:00
|
|
|
|
2026-03-09 23:31:05 +08:00
|
|
|
async function listTools(
|
|
|
|
|
context: CommandContext,
|
|
|
|
|
showDescriptions: boolean,
|
|
|
|
|
): Promise<void> {
|
2026-03-19 09:02:13 -07:00
|
|
|
const toolRegistry = context.services.agentContext?.toolRegistry;
|
2026-03-09 23:31:05 +08:00
|
|
|
if (!toolRegistry) {
|
|
|
|
|
context.ui.addItem({
|
|
|
|
|
type: MessageType.ERROR,
|
|
|
|
|
text: 'Could not retrieve tool registry.',
|
|
|
|
|
});
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
const toolsListItem: HistoryItemToolsList = {
|
|
|
|
|
type: MessageType.TOOLS_LIST,
|
|
|
|
|
tools: geminiTools.map((tool) => ({
|
|
|
|
|
name: tool.name,
|
|
|
|
|
displayName: tool.displayName,
|
|
|
|
|
description: tool.description,
|
|
|
|
|
})),
|
|
|
|
|
showDescriptions,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
context.ui.addItem(toolsListItem);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-10 22:06:12 +05:30
|
|
|
const listSubCommand: SlashCommand = {
|
|
|
|
|
name: 'list',
|
|
|
|
|
description: 'List available Gemini CLI tools.',
|
|
|
|
|
kind: CommandKind.BUILT_IN,
|
|
|
|
|
autoExecute: true,
|
|
|
|
|
action: async (context: CommandContext): Promise<void> =>
|
|
|
|
|
listTools(context, false),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const descSubCommand: SlashCommand = {
|
2026-03-09 23:31:05 +08:00
|
|
|
name: 'desc',
|
|
|
|
|
altNames: ['descriptions'],
|
|
|
|
|
description: 'List available Gemini CLI tools with descriptions.',
|
|
|
|
|
kind: CommandKind.BUILT_IN,
|
|
|
|
|
autoExecute: true,
|
|
|
|
|
action: async (context: CommandContext): Promise<void> =>
|
|
|
|
|
listTools(context, true),
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-16 16:12:22 -04:00
|
|
|
export const toolsCommand: SlashCommand = {
|
|
|
|
|
name: 'tools',
|
2026-03-09 23:31:05 +08:00
|
|
|
description:
|
|
|
|
|
'List available Gemini CLI tools. Use /tools desc to include descriptions.',
|
2025-07-20 16:57:34 -04:00
|
|
|
kind: CommandKind.BUILT_IN,
|
2025-12-01 12:29:03 -05:00
|
|
|
autoExecute: false,
|
2026-03-10 22:06:12 +05:30
|
|
|
subCommands: [listSubCommand, descSubCommand],
|
2025-07-16 16:12:22 -04:00
|
|
|
action: async (context: CommandContext, args?: string): Promise<void> => {
|
|
|
|
|
const subCommand = args?.trim();
|
|
|
|
|
|
2026-03-10 22:06:12 +05:30
|
|
|
// Keep backward compatibility for typed arguments while exposing subcommands in TUI.
|
2026-03-09 23:31:05 +08:00
|
|
|
const useShowDescriptions =
|
|
|
|
|
subCommand === 'desc' || subCommand === 'descriptions';
|
|
|
|
|
|
|
|
|
|
await listTools(context, useShowDescriptions);
|
2025-07-16 16:12:22 -04:00
|
|
|
},
|
|
|
|
|
};
|