fix: refactor display name for tools

This commit is contained in:
Nate 2025-07-13 18:26:02 -07:00
parent 2d4cf55c39
commit 837ac2d5c3
13 changed files with 43 additions and 56 deletions

View file

@ -21,10 +21,10 @@ export function introMessage(assistant: Assistant, mcpService: MCPService) {
console.info(chalk.cyan(CONTINUE_ASCII_ART)); console.info(chalk.cyan(CONTINUE_ASCII_ART));
console.info(`\n${chalk.bold.blue(`Assistant: ${assistantConfig.name}`)}`); console.info(`\n${chalk.bold.blue(`Agent: ${assistantConfig.name}\n`)}`);
console.info(`${chalk.blue(`Model: ${assistant.getModel()}`)}\n`); console.info(`${chalk.yellow("Model:")} ${assistant.getModel()}\n`);
console.info(chalk.yellow("Available tools:")); console.info(chalk.yellow("Tools:"));
getAllTools().forEach((tool) => { getAllTools().forEach((tool) => {
console.info( console.info(
`- ${chalk.green(tool.function.name)}: ${tool.function.description ?? ""}` `- ${chalk.green(tool.function.name)}: ${tool.function.description ?? ""}`
@ -35,14 +35,16 @@ export function introMessage(assistant: Assistant, mcpService: MCPService) {
}); });
console.info(""); console.info("");
console.info(chalk.yellow("\nAvailable slash commands:")); console.info(chalk.yellow("Slash commands:"));
console.info("- /exit: Exit the chat"); console.info(`- ${chalk.green("/exit")}: Exit the chat`);
console.info("- /clear: Clear the chat history"); console.info(`- ${chalk.green("/clear")}: Clear the chat history`);
console.info("- /help: Show help message"); console.info(`- ${chalk.green("/help")}: Show help message`);
console.info("- /models: Show available models"); console.info(`- ${chalk.green("/models")}: Show available models`);
console.info("- /login: Authenticate with your account"); console.info(`- ${chalk.green("/login")}: Authenticate with your account`);
console.info("- /logout: Sign out of your current session"); console.info(`- ${chalk.green("/logout")}: Sign out of your current session`);
console.info("- /whoami: Check who you're currently logged in as"); console.info(
`- ${chalk.green("/whoami")}: Check who you're currently logged in as`
);
for (const prompt of assistantConfig.prompts ?? []) { for (const prompt of assistantConfig.prompts ?? []) {
console.info(`- /${prompt?.name}: ${prompt?.description}`); console.info(`- /${prompt?.name}: ${prompt?.description}`);
} }

View file

@ -3,6 +3,7 @@ import {
executeToolCall, executeToolCall,
extractToolCalls, extractToolCalls,
getToolsDescription, getToolsDescription,
getToolDisplayName,
Tool, Tool,
} from "./tools/index.js"; } from "./tools/index.js";
@ -11,6 +12,7 @@ export {
executeToolCall, executeToolCall,
extractToolCalls, extractToolCalls,
getToolsDescription, getToolsDescription,
getToolDisplayName,
Tool, Tool,
BUILTIN_TOOLS as tools, BUILTIN_TOOLS as tools,
}; };

View file

@ -2,6 +2,7 @@ import { Tool } from "./types.js";
export const exitTool: Tool = { export const exitTool: Tool = {
name: "exit", name: "exit",
displayName: "Exit",
description: description:
"Exit the current process with status code 1, indicating a failure or error", "Exit the current process with status code 1, indicating a failure or error",
parameters: {}, parameters: {},

View file

@ -22,6 +22,11 @@ export const BUILTIN_TOOLS: Tool[] = [
...(parseArgs().isHeadless ? [exitTool] : []), ...(parseArgs().isHeadless ? [exitTool] : []),
]; ];
export function getToolDisplayName(toolName: string): string {
const tool = BUILTIN_TOOLS.find(t => t.name === toolName);
return tool?.displayName || toolName;
}
export function getToolsDescription(): string { export function getToolsDescription(): string {
return BUILTIN_TOOLS.map((tool) => { return BUILTIN_TOOLS.map((tool) => {
const params = Object.entries(tool.parameters) const params = Object.entries(tool.parameters)
@ -99,6 +104,7 @@ export async function executeToolCall(toolCall: {
?.getTools() ?.getTools()
.map((t) => ({ .map((t) => ({
name: t.name, name: t.name,
displayName: t.name.replace("mcp__", "").replace("ide__", ""),
description: t.description ?? "", description: t.description ?? "",
parameters: convertInputSchemaToParameters(t.inputSchema), parameters: convertInputSchemaToParameters(t.inputSchema),
run: async (args: any) => { run: async (args: any) => {

View file

@ -5,6 +5,7 @@ import { Tool } from "./types.js";
// List files in a directory // List files in a directory
export const listFilesTool: Tool = { export const listFilesTool: Tool = {
name: "list_files", name: "list_files",
displayName: "List",
description: "List files in a directory", description: "List files in a directory",
parameters: { parameters: {
dirpath: { dirpath: {

View file

@ -3,6 +3,7 @@ import { Tool } from "./types.js";
export const readFileTool: Tool = { export const readFileTool: Tool = {
name: "read_file", name: "read_file",
displayName: "Read",
description: "Read the contents of a file at the specified path", description: "Read the contents of a file at the specified path",
parameters: { parameters: {
filepath: { filepath: {

View file

@ -3,6 +3,7 @@ import { exec } from "child_process";
export const runTerminalCommandTool: Tool = { export const runTerminalCommandTool: Tool = {
name: "run_terminal_command", name: "run_terminal_command",
displayName: "Terminal",
description: "Executes a terminal command and returns the output.", description: "Executes a terminal command and returns the output.",
parameters: { parameters: {
command: { command: {

View file

@ -7,6 +7,7 @@ const execPromise = util.promisify(child_process.exec);
export const searchCodeTool: Tool = { export const searchCodeTool: Tool = {
name: "search_code", name: "search_code",
displayName: "Search",
description: "Search the codebase using ripgrep (rg) for a specific pattern", description: "Search the codebase using ripgrep (rg) for a specific pattern",
parameters: { parameters: {
pattern: { pattern: {

View file

@ -9,6 +9,7 @@ export type ToolParameters = Record<
export interface Tool { export interface Tool {
name: string; name: string;
displayName: string;
description: string; description: string;
parameters: ToolParameters; parameters: ToolParameters;
run: (args: any) => Promise<string>; run: (args: any) => Promise<string>;

View file

@ -7,6 +7,7 @@ const execPromise = util.promisify(child_process.exec);
export const viewDiffTool: Tool = { export const viewDiffTool: Tool = {
name: "view_diff", name: "view_diff",
displayName: "Diff",
description: "View all uncommitted changes in the git repository", description: "View all uncommitted changes in the git repository",
parameters: { parameters: {
path: { path: {

View file

@ -4,6 +4,7 @@ import { Tool } from "./types.js";
export const writeFileTool: Tool = { export const writeFileTool: Tool = {
name: "write_file", name: "write_file",
displayName: "Write",
description: "Write content to a file at the specified path", description: "Write content to a file at the specified path",
parameters: { parameters: {
filepath: { filepath: {

View file

@ -4,6 +4,7 @@ import { ChatCompletionMessageParam } from "openai/resources.mjs";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { handleSlashCommands } from "../slashCommands.js"; import { handleSlashCommands } from "../slashCommands.js";
import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js";
import { getToolDisplayName } from "../tools.js";
import ToolResultSummary from "./ToolResultSummary.js"; import ToolResultSummary from "./ToolResultSummary.js";
import UserInput from "./UserInput.js"; import UserInput from "./UserInput.js";
@ -119,35 +120,12 @@ const TUIChat: React.FC<TUIChatProps> = ({
}, },
onToolStart: (toolName: string, toolArgs?: any) => { onToolStart: (toolName: string, toolArgs?: any) => {
const formatToolCall = (name: string, args: any) => { const formatToolCall = (name: string, args: any) => {
if (!args) return name; const displayName = getToolDisplayName(name);
if (!args) return displayName;
switch (name) { // Get the first parameter value for display
// CLI Internal Tools (snake_case) const firstValue = Object.values(args)[0];
case "read_file": return `${displayName}(${firstValue || ""})`;
return `Read(${args.filepath || ""})`;
case "write_file":
return `Write(${args.filepath || ""})`;
case "list_files":
return `List(${args.dirpath || ""})`;
case "search_code":
return `Search(${args.pattern || ""})`;
case "run_terminal_command":
return `Terminal(${args.command || ""})`;
case "view_diff":
return `Diff(${args.path || "."})`;
default:
// Handle MCP tools or unknown tools
if (name.startsWith("mcp__")) {
const mcpToolName = name
.replace("mcp__", "")
.replace("ide__", "");
const firstParam = Object.values(args)[0];
return `${mcpToolName}(${firstParam || ""})`;
}
// For unknown tools, show first parameter value
const firstValue = Object.values(args)[0];
return `${name}(${firstValue || ""})`;
}
}; };
setMessages((prev) => [ setMessages((prev) => [

View file

@ -1,5 +1,6 @@
import { Box, Text } from "ink"; import { Box, Text } from "ink";
import React from "react"; import React from "react";
import { getToolDisplayName } from "../tools.js";
interface ToolResultSummaryProps { interface ToolResultSummaryProps {
toolName?: string; toolName?: string;
@ -15,18 +16,18 @@ const ToolResultSummary: React.FC<ToolResultSummaryProps> = ({
const lines = content.split("\n").length; const lines = content.split("\n").length;
const chars = content.length; const chars = content.length;
const displayName = toolName ? getToolDisplayName(toolName) : "Tool";
// Use exact tool name matching // Handle specific tool output formatting
switch (toolName) { switch (toolName) {
// CLI Internal Tools (snake_case)
case "read_file": case "read_file":
// Try to extract file path from content if it contains line numbers // Try to extract file path from content if it contains line numbers
if (content.includes("→")) { if (content.includes("→")) {
const pathMatch = content.match(/^(.+?):/); const pathMatch = content.match(/^(.+?):/);
const filePath = pathMatch ? pathMatch[1] : "file"; const filePath = pathMatch ? pathMatch[1] : "file";
return `Read ${filePath} (${lines} lines)`; return `${displayName} ${filePath} (${lines} lines)`;
} }
return `Read tool output (${lines} lines)`; return `${displayName} tool output (${lines} lines)`;
case "write_file": case "write_file":
return "File written successfully"; return "File written successfully";
@ -44,21 +45,11 @@ const ToolResultSummary: React.FC<ToolResultSummaryProps> = ({
return `Diff output (${lines} lines)`; return `Diff output (${lines} lines)`;
default: default:
// Handle MCP tools or unknown tools // Fallback for all tools using display name
if (toolName?.startsWith("mcp__")) {
const mcpToolName = toolName
.replace("mcp__", "")
.replace("ide__", "");
return `${mcpToolName} tool output (${lines} lines)`;
}
// Fallback for unknown tools
if (chars > 1000) { if (chars > 1000) {
return `${ return `${displayName} output: ${lines} lines, ${chars} characters`;
toolName || "Tool"
} output: ${lines} lines, ${chars} characters`;
} else if (lines > 10) { } else if (lines > 10) {
return `${toolName || "Tool"} output: ${lines} lines`; return `${displayName} output: ${lines} lines`;
} else { } else {
return content.slice(0, 100) + (content.length > 100 ? "..." : ""); return content.slice(0, 100) + (content.length > 100 ? "..." : "");
} }