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.
This commit is contained in:
parent
7352cb403c
commit
da09431be9
|
@ -61,6 +61,13 @@ Slash commands provide meta-level control over the CLI itself. They can typicall
|
||||||
|
|
||||||
- **Description:** Displays a list of all the tools that are currently available to the model.
|
- **Description:** Displays a list of all the tools that are currently available to the model.
|
||||||
- **Action:** Outputs a list of the available tools.
|
- **Action:** Outputs a list of the available tools.
|
||||||
|
- **Sub-commands:**
|
||||||
|
- **`desc`** or **`descriptions`**:
|
||||||
|
- **Description:** Shows detailed descriptions of each tool.
|
||||||
|
- **Action:** Displays each tool's name with its full description as provided to the model.
|
||||||
|
- **`nodesc`** or **`nodescriptions`**:
|
||||||
|
- **Description:** Hides tool descriptions, showing only the tool names.
|
||||||
|
- **Action:** Displays a compact list with only tool names.
|
||||||
|
|
||||||
- **`/compress`**
|
- **`/compress`**
|
||||||
|
|
||||||
|
|
|
@ -595,14 +595,9 @@ Add any other context about the problem here.
|
||||||
});
|
});
|
||||||
|
|
||||||
// Should only show tool1 and tool2, not the MCP tools
|
// Should only show tool1 and tool2, not the MCP tools
|
||||||
expect(mockAddItem).toHaveBeenNthCalledWith(
|
const message = mockAddItem.mock.calls[1][0].text;
|
||||||
2,
|
expect(message).toContain('\u001b[36mTool1\u001b[0m');
|
||||||
expect.objectContaining({
|
expect(message).toContain('\u001b[36mTool2\u001b[0m');
|
||||||
type: MessageType.INFO,
|
|
||||||
text: 'Available Gemini CLI tools:\n\nTool1\nTool2',
|
|
||||||
}),
|
|
||||||
expect.any(Number),
|
|
||||||
);
|
|
||||||
expect(commandResult).toBe(true);
|
expect(commandResult).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -626,14 +621,43 @@ Add any other context about the problem here.
|
||||||
commandResult = await handleSlashCommand('/tools');
|
commandResult = await handleSlashCommand('/tools');
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(mockAddItem).toHaveBeenNthCalledWith(
|
const message = mockAddItem.mock.calls[1][0].text;
|
||||||
2,
|
expect(message).toContain('No tools available');
|
||||||
expect.objectContaining({
|
expect(commandResult).toBe(true);
|
||||||
type: MessageType.INFO,
|
});
|
||||||
text: 'Available Gemini CLI tools:\n\n',
|
|
||||||
|
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);
|
expect(commandResult).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -419,6 +419,21 @@ export const useSlashCommandProcessor = (
|
||||||
name: 'tools',
|
name: 'tools',
|
||||||
description: 'list available Gemini CLI tools',
|
description: 'list available Gemini CLI tools',
|
||||||
action: async (_mainCommand, _subCommand, _args) => {
|
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 toolRegistry = await config?.getToolRegistry();
|
||||||
const tools = toolRegistry?.getAllTools();
|
const tools = toolRegistry?.getAllTools();
|
||||||
if (!tools) {
|
if (!tools) {
|
||||||
|
@ -432,11 +447,51 @@ export const useSlashCommandProcessor = (
|
||||||
|
|
||||||
// Filter out MCP tools by checking if they have a serverName property
|
// Filter out MCP tools by checking if they have a serverName property
|
||||||
const geminiTools = tools.filter((tool) => !('serverName' in tool));
|
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({
|
addMessage({
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
content: `Available Gemini CLI tools:\n\n${geminiToolList.join('\n')}`,
|
content: message,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue