diff --git a/extensions/cli/src/tools/ToolCallTitle.tsx b/extensions/cli/src/tools/ToolCallTitle.tsx new file mode 100644 index 000000000..90c5dea3f --- /dev/null +++ b/extensions/cli/src/tools/ToolCallTitle.tsx @@ -0,0 +1,50 @@ +import { Text } from "ink"; +import React from "react"; + +import { formatToolArgument } from "./formatters.js"; + +import { getToolDisplayName } from "./index.js"; + +/** + * Formats a tool call with its arguments for display + * @param toolName The name of the tool + * @param args The tool arguments + * @returns A React node with bolded tool name like "ToolName(arg)" or just "ToolName" if no args + */ +export function ToolCallTitle(props: { toolName: string; args?: any }) { + const { toolName, args } = props; + + const displayName = getToolDisplayName(toolName); + + if (!args || Object.keys(args).length === 0) { + return {displayName}; + } + + // Get the first argument value if it's a simple one + let formattedValue = ""; + const [key, value] = Object.entries(args)[0]; + if ( + key.toLowerCase().includes("path") || + typeof value === "number" || + typeof value === "boolean" + ) { + formattedValue = formatToolArgument(value); + } else if (typeof value === "string") { + const valueLines = value.split("\n"); + if (valueLines.length === 1) { + formattedValue = formatToolArgument(value); + } else { + // For multi-line strings, show first line with ellipsis + const firstLine = valueLines[0].trim(); + formattedValue = firstLine + ? `${formatToolArgument(firstLine)}...` + : "..."; + } + } + + return ( + + {displayName}({formattedValue}) + + ); +} diff --git a/extensions/cli/src/tools/index.tsx b/extensions/cli/src/tools/index.tsx index 76027adcd..a4cb3dcb7 100644 --- a/extensions/cli/src/tools/index.tsx +++ b/extensions/cli/src/tools/index.tsx @@ -1,7 +1,4 @@ // @ts-ignore -import { Text } from "ink"; -import * as React from "react"; - import { getServiceSync, MCPServiceState, @@ -15,7 +12,6 @@ import { logger } from "../util/logger.js"; import { editTool } from "./edit.js"; import { exitTool } from "./exit.js"; import { fetchTool } from "./fetch.js"; -import { formatToolArgument } from "./formatters.js"; import { listFilesTool } from "./listFiles.js"; import { multiEditTool } from "./multiEdit.js"; import { readFileTool } from "./readFile.js"; @@ -206,45 +202,3 @@ export function validateToolCallArgsPresent(toolCall: ToolCall, tool: Tool) { } } } - -/** - * Formats a tool call with its arguments for display - * @param toolName The name of the tool - * @param args The tool arguments - * @returns A React node with bolded tool name like "ToolName(arg)" or just "ToolName" if no args - */ -export function formatToolCall(toolName: string, args?: any): React.ReactNode { - const displayName = getToolDisplayName(toolName); - - if (!args || Object.keys(args).length === 0) { - return {displayName}; - } - - // Get the first argument value if it's a simple one - let formattedValue = ""; - const [key, value] = Object.entries(args)[0]; - if ( - key.toLowerCase().includes("path") || - typeof value === "number" || - typeof value === "boolean" - ) { - formattedValue = formatToolArgument(value); - } else if (typeof value === "string") { - const valueLines = value.split("\n"); - if (valueLines.length === 1) { - formattedValue = formatToolArgument(value); - } else { - // For multi-line strings, show first line with ellipsis - const firstLine = valueLines[0].trim(); - formattedValue = firstLine - ? `${formatToolArgument(firstLine)}...` - : "..."; - } - } - - return ( - - {displayName}({formattedValue}) - - ); -} diff --git a/extensions/cli/src/ui/components/MemoizedMessage.tsx b/extensions/cli/src/ui/components/MemoizedMessage.tsx index 43ef4f98f..58a95616d 100644 --- a/extensions/cli/src/ui/components/MemoizedMessage.tsx +++ b/extensions/cli/src/ui/components/MemoizedMessage.tsx @@ -1,7 +1,7 @@ import { Box, Text } from "ink"; import React, { memo } from "react"; -import { formatToolCall } from "src/tools/index.js"; +import { ToolCallTitle } from "src/tools/ToolCallTitle.js"; import type { ChatHistoryItem } from "../../../../../core/index.js"; import { MarkdownRenderer } from "../MarkdownRenderer.js"; @@ -93,7 +93,7 @@ export const MemoizedMessage = memo( {" "} - {formatToolCall(toolName, toolArgs)} + diff --git a/extensions/cli/src/ui/components/ToolPermissionSelector.tsx b/extensions/cli/src/ui/components/ToolPermissionSelector.tsx index e5e9da0ca..46abde7d2 100644 --- a/extensions/cli/src/ui/components/ToolPermissionSelector.tsx +++ b/extensions/cli/src/ui/components/ToolPermissionSelector.tsx @@ -1,7 +1,8 @@ import { Box, Text, useInput } from "ink"; import React, { useState } from "react"; -import { formatToolCall } from "../../tools/index.js"; +import { ToolCallTitle } from "src/tools/ToolCallTitle.js"; + import { ToolCallPreview } from "../../tools/types.js"; import { ToolPreview } from "./ToolPreview.js"; @@ -101,8 +102,6 @@ export const ToolPermissionSelector: React.FC = ({ } }); - const toolCallDisplay = formatToolCall(toolName, toolArgs); - return ( = ({ borderColor="magenta" > - {toolCallDisplay} + {/* Show preview of what the tool will do */}