From 5643a53b5a3440d1e3e2ee41df08524289ad94b2 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:49:38 -0700 Subject: [PATCH 01/18] feat: esc to interrupt --- src/streamChatResponse.ts | 10 +++++++++- src/ui/TUIChat.tsx | 17 ++++++++++++++++- src/ui/UserInput.tsx | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/streamChatResponse.ts b/src/streamChatResponse.ts index ad1b73b90..68d4288f7 100644 --- a/src/streamChatResponse.ts +++ b/src/streamChatResponse.ts @@ -62,7 +62,8 @@ export async function streamChatResponse( chatHistory: ChatCompletionMessageParam[], assistant: ContinueClient["assistant"], client: ContinueClient["client"], - callbacks?: StreamCallbacks + callbacks?: StreamCallbacks, + abortController?: AbortController ) { // Prepare tools for the API call const toolsForRequest = getAllTools(); @@ -84,6 +85,8 @@ export async function streamChatResponse( messages: chatHistory, stream: true, tools: toolsForRequest, + }, { + signal: abortController?.signal, }); } catch (error: any) { console.error( @@ -99,6 +102,11 @@ export async function streamChatResponse( let toolArguments = ""; for await (const chunk of stream) { + // Check if we should abort + if (abortController?.signal.aborted) { + break; + } + // Handle regular content if (chunk.choices[0].delta.content) { const content = chunk.choices[0].delta.content; diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 550cd7c1f..91500b8c0 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -37,6 +37,7 @@ const TUIChat: React.FC = ({ const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); const [messages, setMessages] = useState([]); const [inputMode, setInputMode] = useState(true); + const [abortController, setAbortController] = useState(null); const { exit } = useApp(); // Handle initial prompt @@ -79,6 +80,8 @@ const TUIChat: React.FC = ({ setMessages((prev) => [...prev, { role: "user", content: message }]); // Start streaming response + const controller = new AbortController(); + setAbortController(controller); setIsWaitingForResponse(true); setInputMode(false); @@ -122,7 +125,7 @@ const TUIChat: React.FC = ({ }, }; - await streamChatResponse(newHistory, assistant, client, streamCallbacks); + await streamChatResponse(newHistory, assistant, client, streamCallbacks, controller); // Finalize the assistant message const finalAssistantMessage: ChatCompletionMessageParam = { @@ -147,11 +150,22 @@ const TUIChat: React.FC = ({ { role: "system", content: errorMessage }, ]); } finally { + setAbortController(null); setIsWaitingForResponse(false); setInputMode(true); } }; + const handleInterrupt = () => { + if (abortController && isWaitingForResponse) { + abortController.abort(); + setMessages((prev) => [ + ...prev, + { role: "system", content: "[Interrupted by user]" }, + ]); + } + }; + const renderMessage = (message: DisplayMessage, index: number) => { const isUser = message.role === "user"; const isSystem = message.role === "system"; @@ -198,6 +212,7 @@ const TUIChat: React.FC = ({ onSubmit={handleUserMessage} isWaitingForResponse={isWaitingForResponse} inputMode={inputMode} + onInterrupt={handleInterrupt} /> diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx index 00496634c..7578a058f 100644 --- a/src/ui/UserInput.tsx +++ b/src/ui/UserInput.tsx @@ -6,12 +6,14 @@ interface UserInputProps { onSubmit: (message: string) => void; isWaitingForResponse: boolean; inputMode: boolean; + onInterrupt?: () => void; } const UserInput: React.FC = ({ onSubmit, isWaitingForResponse, inputMode, + onInterrupt, }) => { const [textBuffer] = useState(() => new TextBuffer()); const [inputText, setInputText] = useState(""); @@ -24,6 +26,12 @@ const UserInput: React.FC = ({ return; } + // Handle escape key to interrupt streaming + if (key.escape && isWaitingForResponse && onInterrupt) { + onInterrupt(); + return; + } + if (!inputMode) { return; } From 6749e10daad3fc9238dce6bf5c7309dd610cad2a Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 16:57:02 -0700 Subject: [PATCH 02/18] fix: nicer tool display --- src/ui/TUIChat.tsx | 108 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 15 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 91500b8c0..7ba3dd546 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -16,6 +16,8 @@ interface DisplayMessage { role: string; content: string; isStreaming?: boolean; + messageType?: "tool-start" | "tool-result" | "tool-error" | "system"; + toolName?: string; } const TUIChat: React.FC = ({ @@ -37,7 +39,8 @@ const TUIChat: React.FC = ({ const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); const [messages, setMessages] = useState([]); const [inputMode, setInputMode] = useState(true); - const [abortController, setAbortController] = useState(null); + const [abortController, setAbortController] = + useState(null); const { exit } = useApp(); // Handle initial prompt @@ -60,7 +63,11 @@ const TUIChat: React.FC = ({ if (commandResult.output) { setMessages((prev) => [ ...prev, - { role: "system", content: commandResult.output! }, + { + role: "system", + content: commandResult.output!, + messageType: "system", + }, ]); } @@ -111,21 +118,43 @@ const TUIChat: React.FC = ({ onToolStart: (toolName: string) => { setMessages((prev) => [ ...prev, - { role: "system", content: `[Using tool: ${toolName}]` }, + { + role: "system", + content: `Using ${toolName}...`, + messageType: "tool-start", + toolName, + }, ]); }, onToolResult: (result: string) => { - setMessages((prev) => [...prev, { role: "system", content: result }]); + setMessages((prev) => [ + ...prev, + { + role: "system", + content: result, + messageType: "tool-result", + }, + ]); }, onToolError: (error: string) => { setMessages((prev) => [ ...prev, - { role: "system", content: `[Tool error: ${error}]` }, + { + role: "system", + content: error, + messageType: "tool-error", + }, ]); }, }; - await streamChatResponse(newHistory, assistant, client, streamCallbacks, controller); + await streamChatResponse( + newHistory, + assistant, + client, + streamCallbacks, + controller + ); // Finalize the assistant message const finalAssistantMessage: ChatCompletionMessageParam = { @@ -147,7 +176,7 @@ const TUIChat: React.FC = ({ const errorMessage = `Error: ${error.message}`; setMessages((prev) => [ ...prev, - { role: "system", content: errorMessage }, + { role: "system", content: errorMessage, messageType: "system" }, ]); } finally { setAbortController(null); @@ -161,7 +190,11 @@ const TUIChat: React.FC = ({ abortController.abort(); setMessages((prev) => [ ...prev, - { role: "system", content: "[Interrupted by user]" }, + { + role: "system", + content: "[Interrupted by user]", + messageType: "system", + }, ]); } }; @@ -171,13 +204,58 @@ const TUIChat: React.FC = ({ const isSystem = message.role === "system"; if (isSystem) { - return ( - - - {message.content} - - - ); + // Handle different types of system messages + switch (message.messageType) { + case "tool-start": + return ( + + + 🔧{" "} + + {message.content} + + ); + + case "tool-result": + return ( + + + + ✓{" "} + + Tool completed + + + {message.content} + + + ); + + case "tool-error": + return ( + + + ✗{" "} + + Tool error: {message.content} + + ); + + default: + // Regular system messages + return ( + + + {message.content} + + + ); + } } return ( From fa4b98f455db6fe48b4c5810327d0222fade7902 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 17:03:17 -0700 Subject: [PATCH 03/18] fix: tool call custom UI --- src/streamChatResponse.ts | 8 ++-- src/ui/TUIChat.tsx | 12 +++-- src/ui/ToolResultSummary.tsx | 93 ++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 src/ui/ToolResultSummary.tsx diff --git a/src/streamChatResponse.ts b/src/streamChatResponse.ts index 68d4288f7..ec0a0d475 100644 --- a/src/streamChatResponse.ts +++ b/src/streamChatResponse.ts @@ -53,8 +53,8 @@ type TODO = any; export interface StreamCallbacks { onContent?: (content: string) => void; onToolStart?: (toolName: string) => void; - onToolResult?: (result: string) => void; - onToolError?: (error: string) => void; + onToolResult?: (result: string, toolName: string) => void; + onToolError?: (error: string, toolName?: string) => void; } // Define a function to handle streaming responses with tool calling @@ -220,7 +220,7 @@ export async function streamChatResponse( }); if (callbacks?.onToolResult) { - callbacks.onToolResult(toolResult); + callbacks.onToolResult(toolResult, toolCall.name); } else { console.info(chalk.green(toolResult) + "\n"); } @@ -234,7 +234,7 @@ export async function streamChatResponse( content: errorMessage, }); if (callbacks?.onToolError) { - callbacks.onToolError(errorMessage); + callbacks.onToolError(errorMessage, toolCall.name); } else { console.info( `${chalk.red("[Tool error:")} ${chalk.red(errorMessage)}${chalk.red( diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 7ba3dd546..5e44dcbc3 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -5,6 +5,7 @@ import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; import UserInput from "./UserInput.js"; +import ToolResultSummary from "./ToolResultSummary.js"; interface TUIChatProps { assistant: ContinueClient["assistant"]; @@ -126,23 +127,25 @@ const TUIChat: React.FC = ({ }, ]); }, - onToolResult: (result: string) => { + onToolResult: (result: string, toolName: string) => { setMessages((prev) => [ ...prev, { role: "system", content: result, messageType: "tool-result", + toolName, }, ]); }, - onToolError: (error: string) => { + onToolError: (error: string, toolName?: string) => { setMessages((prev) => [ ...prev, { role: "system", content: error, messageType: "tool-error", + toolName, }, ]); }, @@ -231,7 +234,10 @@ const TUIChat: React.FC = ({ Tool completed - {message.content} + ); diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx new file mode 100644 index 000000000..416fb2f03 --- /dev/null +++ b/src/ui/ToolResultSummary.tsx @@ -0,0 +1,93 @@ +import { Text, Box } from "ink"; +import React from "react"; + +interface ToolResultSummaryProps { + toolName?: string; + content: string; +} + +const ToolResultSummary: React.FC = ({ + toolName, + content, +}) => { + const getSummary = () => { + if (!content) return "No output"; + + const lines = content.split('\n').length; + const chars = content.length; + + // Use exact tool name matching + switch (toolName) { + case "Read": + // Try to extract file path from content if it contains line numbers + if (content.includes("→")) { + const pathMatch = content.match(/^(.+?):/); + const filePath = pathMatch ? pathMatch[1] : "file"; + return `Read ${filePath} (${lines} lines)`; + } + return `Read tool output (${lines} lines)`; + + case "Bash": + return `Command output (${lines} lines)`; + + case "Glob": + const fileCount = lines; + return `Found ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`; + + case "Grep": + return `Found ${lines} ${lines === 1 ? 'match' : 'matches'}`; + + case "LS": + return `Listed ${lines} ${lines === 1 ? 'item' : 'items'}`; + + case "Write": + return "File written successfully"; + + case "Edit": + case "MultiEdit": + return "File edited successfully"; + + case "NotebookRead": + return `Read notebook (${lines} lines)`; + + case "NotebookEdit": + return "Notebook edited successfully"; + + case "WebFetch": + return `Fetched web content (${lines} lines)`; + + case "WebSearch": + return `Search results (${lines} lines)`; + + case "TodoWrite": + return "Todo list updated"; + + case "Task": + return `Task completed (${lines} lines)`; + + default: + // Handle MCP tools or unknown tools + if (toolName?.startsWith("mcp__")) { + const mcpToolName = toolName.replace("mcp__", ""); + return `${mcpToolName} tool output (${lines} lines)`; + } + + // Fallback for unknown tools + if (chars > 1000) { + return `${toolName || 'Tool'} output: ${lines} lines, ${chars} characters`; + } else if (lines > 10) { + return `${toolName || 'Tool'} output: ${lines} lines`; + } else { + return content.slice(0, 100) + (content.length > 100 ? "..." : ""); + } + } + }; + + return ( + + {getSummary()} + + ); +}; + +export default ToolResultSummary; \ No newline at end of file From 3716ebcdd73a23e021e59a9d162d61915ce31184 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 17:06:51 -0700 Subject: [PATCH 04/18] fix: even nicer tool UI --- src/ui/TUIChat.tsx | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 5e44dcbc3..503fe7c3e 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -128,15 +128,21 @@ const TUIChat: React.FC = ({ ]); }, onToolResult: (result: string, toolName: string) => { - setMessages((prev) => [ - ...prev, - { - role: "system", - content: result, - messageType: "tool-result", - toolName, - }, - ]); + setMessages((prev) => { + const newMessages = [...prev]; + // Find the last tool-start message for this tool and replace it + for (let i = newMessages.length - 1; i >= 0; i--) { + if (newMessages[i].messageType === "tool-start" && newMessages[i].toolName === toolName) { + newMessages[i] = { + ...newMessages[i], + content: result, + messageType: "tool-result", + }; + break; + } + } + return newMessages; + }); }, onToolError: (error: string, toolName?: string) => { setMessages((prev) => [ @@ -212,10 +218,9 @@ const TUIChat: React.FC = ({ case "tool-start": return ( - - 🔧{" "} + + ○ {message.content} - {message.content} ); @@ -228,10 +233,9 @@ const TUIChat: React.FC = ({ flexDirection="column" > - - ✓{" "} + + ✓ Completed {message.toolName} - Tool completed Date: Sun, 13 Jul 2025 17:17:21 -0700 Subject: [PATCH 05/18] fix: tool ui again --- src/streamChatResponse.ts | 27 +++++++++------ src/ui/TUIChat.tsx | 72 +++++++++++++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 24 deletions(-) diff --git a/src/streamChatResponse.ts b/src/streamChatResponse.ts index ec0a0d475..3ac1e5649 100644 --- a/src/streamChatResponse.ts +++ b/src/streamChatResponse.ts @@ -52,7 +52,7 @@ type TODO = any; export interface StreamCallbacks { onContent?: (content: string) => void; - onToolStart?: (toolName: string) => void; + onToolStart?: (toolName: string, toolArgs?: any) => void; onToolResult?: (result: string, toolName: string) => void; onToolError?: (error: string, toolName?: string) => void; } @@ -128,6 +128,7 @@ export async function streamChatResponse( id: toolCallDelta.id, name: "", arguments: {}, + startNotified: false, }; } currentToolCallId = toolCallDelta.id; @@ -141,15 +142,7 @@ export async function streamChatResponse( if (toolCall) { if (!toolCall.name) { toolCall.name = toolCallDelta.function.name; - if (callbacks?.onToolStart) { - callbacks.onToolStart(toolCall.name); - } else { - process.stdout.write( - `\n${chalk.yellow("[Using tool:")} ${chalk.yellow.bold( - toolCall.name - )}${chalk.yellow("]")}` - ); - } + toolCall.startNotified = false; } } } @@ -167,6 +160,20 @@ export async function streamChatResponse( // Try to parse complete JSON const parsed = JSON.parse(toolArguments); toolCall.arguments = parsed; + + // Notify start if we haven't already and have both name and args + if (toolCall.name && !toolCall.startNotified) { + toolCall.startNotified = true; + if (callbacks?.onToolStart) { + callbacks.onToolStart(toolCall.name, toolCall.arguments); + } else { + process.stdout.write( + `\n${chalk.yellow("[Using tool:")} ${chalk.yellow.bold( + toolCall.name + )}${chalk.yellow("]")}` + ); + } + } } catch (e) { // Not complete JSON yet, continue collecting } diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 503fe7c3e..813ff1eda 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -4,8 +4,8 @@ import { ChatCompletionMessageParam } from "openai/resources.mjs"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; -import UserInput from "./UserInput.js"; import ToolResultSummary from "./ToolResultSummary.js"; +import UserInput from "./UserInput.js"; interface TUIChatProps { assistant: ContinueClient["assistant"]; @@ -19,6 +19,7 @@ interface DisplayMessage { isStreaming?: boolean; messageType?: "tool-start" | "tool-result" | "tool-error" | "system"; toolName?: string; + toolResult?: string; } const TUIChat: React.FC = ({ @@ -116,12 +117,56 @@ const TUIChat: React.FC = ({ return newMessages; }); }, - onToolStart: (toolName: string) => { + onToolStart: (toolName: string, toolArgs?: any) => { + const formatToolCall = (name: string, args: any) => { + if (!args) return name; + + switch (name) { + case "Read": + return `Read(${args.file_path || args.path || ""})`; + case "Write": + return `Write(${args.file_path || ""})`; + case "Edit": + case "MultiEdit": + return `Edit(${args.file_path || ""})`; + case "Bash": + return `Bash(${args.command || ""})`; + case "Glob": + return `Glob(${args.pattern || ""})`; + case "Grep": + return `Grep(${args.pattern || ""})`; + case "LS": + return `LS(${args.path || ""})`; + case "NotebookRead": + return `NotebookRead(${args.notebook_path || ""})`; + case "NotebookEdit": + return `NotebookEdit(${args.notebook_path || ""})`; + case "WebFetch": + return `WebFetch(${args.url || ""})`; + case "WebSearch": + return `WebSearch(${args.query || ""})`; + case "TodoWrite": + return `TodoWrite(${args.todos?.length || 0} items)`; + case "Task": + return `Task(${args.description || ""})`; + default: + // Handle MCP tools or unknown tools + if (name.startsWith("mcp__")) { + const mcpToolName = name.replace("mcp__", ""); + 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) => [ ...prev, { role: "system", - content: `Using ${toolName}...`, + content: formatToolCall(toolName, toolArgs), messageType: "tool-start", toolName, }, @@ -132,11 +177,14 @@ const TUIChat: React.FC = ({ const newMessages = [...prev]; // Find the last tool-start message for this tool and replace it for (let i = newMessages.length - 1; i >= 0; i--) { - if (newMessages[i].messageType === "tool-start" && newMessages[i].toolName === toolName) { + if ( + newMessages[i].messageType === "tool-start" && + newMessages[i].toolName === toolName + ) { newMessages[i] = { ...newMessages[i], - content: result, messageType: "tool-result", + toolResult: result, // Store the actual result separately }; break; } @@ -218,9 +266,7 @@ const TUIChat: React.FC = ({ case "tool-start": return ( - - ○ {message.content} - + ○ {message.content} ); @@ -233,14 +279,12 @@ const TUIChat: React.FC = ({ flexDirection="column" > - - ✓ Completed {message.toolName} - + ● {message.content} - From 9792b1411f713c2615c0d3b82df2c7032d434205 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 17:24:54 -0700 Subject: [PATCH 06/18] fix: tool name matching --- src/ui/TUIChat.tsx | 35 +++++++++++++++++++++++++---------- src/ui/ToolResultSummary.tsx | 28 +++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 813ff1eda..55fd02d0f 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -122,6 +122,21 @@ const TUIChat: React.FC = ({ if (!args) return name; switch (name) { + // CLI Internal Tools (snake_case) + case "read_file": + 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 || "."})`; + + // External Claude Code Tools (PascalCase) case "Read": return `Read(${args.file_path || args.path || ""})`; case "Write": @@ -130,29 +145,29 @@ const TUIChat: React.FC = ({ case "MultiEdit": return `Edit(${args.file_path || ""})`; case "Bash": - return `Bash(${args.command || ""})`; + return `Terminal(${args.command || ""})`; case "Glob": - return `Glob(${args.pattern || ""})`; + return `Find(${args.pattern || ""})`; case "Grep": - return `Grep(${args.pattern || ""})`; + return `Search(${args.pattern || ""})`; case "LS": - return `LS(${args.path || ""})`; + return `List(${args.path || ""})`; case "NotebookRead": - return `NotebookRead(${args.notebook_path || ""})`; + return `Notebook(${args.notebook_path || ""})`; case "NotebookEdit": - return `NotebookEdit(${args.notebook_path || ""})`; + return `Notebook(${args.notebook_path || ""})`; case "WebFetch": - return `WebFetch(${args.url || ""})`; + return `Web(${args.url || ""})`; case "WebSearch": - return `WebSearch(${args.query || ""})`; + return `Search(${args.query || ""})`; case "TodoWrite": - return `TodoWrite(${args.todos?.length || 0} items)`; + return `Todo(${args.todos?.length || 0} items)`; case "Task": return `Task(${args.description || ""})`; default: // Handle MCP tools or unknown tools if (name.startsWith("mcp__")) { - const mcpToolName = name.replace("mcp__", ""); + const mcpToolName = name.replace("mcp__", "").replace("ide__", ""); const firstParam = Object.values(args)[0]; return `${mcpToolName}(${firstParam || ""})`; } diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx index 416fb2f03..bc3d75a43 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -18,6 +18,32 @@ const ToolResultSummary: React.FC = ({ // Use exact tool name matching switch (toolName) { + // CLI Internal Tools (snake_case) + case "read_file": + // Try to extract file path from content if it contains line numbers + if (content.includes("→")) { + const pathMatch = content.match(/^(.+?):/); + const filePath = pathMatch ? pathMatch[1] : "file"; + return `Read ${filePath} (${lines} lines)`; + } + return `Read tool output (${lines} lines)`; + + case "write_file": + return "File written successfully"; + + case "list_files": + return `Listed ${lines} ${lines === 1 ? 'item' : 'items'}`; + + case "search_code": + return `Found ${lines} ${lines === 1 ? 'match' : 'matches'}`; + + case "run_terminal_command": + return `Command output (${lines} lines)`; + + case "view_diff": + return `Diff output (${lines} lines)`; + + // External Claude Code Tools (PascalCase) case "Read": // Try to extract file path from content if it contains line numbers if (content.includes("→")) { @@ -68,7 +94,7 @@ const ToolResultSummary: React.FC = ({ default: // Handle MCP tools or unknown tools if (toolName?.startsWith("mcp__")) { - const mcpToolName = toolName.replace("mcp__", ""); + const mcpToolName = toolName.replace("mcp__", "").replace("ide__", ""); return `${mcpToolName} tool output (${lines} lines)`; } From 8f6ec398ff23ec1d59567cb5b2de92dabd58ab4b Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:05:23 -0700 Subject: [PATCH 07/18] fix: dot shade of green --- src/ui/TUIChat.tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 55fd02d0f..59528a8b8 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -135,7 +135,7 @@ const TUIChat: React.FC = ({ return `Terminal(${args.command || ""})`; case "view_diff": return `Diff(${args.path || "."})`; - + // External Claude Code Tools (PascalCase) case "Read": return `Read(${args.file_path || args.path || ""})`; @@ -167,7 +167,9 @@ const TUIChat: React.FC = ({ default: // Handle MCP tools or unknown tools if (name.startsWith("mcp__")) { - const mcpToolName = name.replace("mcp__", "").replace("ide__", ""); + const mcpToolName = name + .replace("mcp__", "") + .replace("ide__", ""); const firstParam = Object.values(args)[0]; return `${mcpToolName}(${firstParam || ""})`; } @@ -280,21 +282,17 @@ const TUIChat: React.FC = ({ switch (message.messageType) { case "tool-start": return ( - + ○ {message.content} ); case "tool-result": return ( - + - ● {message.content} + ● + {message.content} = ({ case "tool-error": return ( - + ✗{" "} @@ -329,7 +327,7 @@ const TUIChat: React.FC = ({ return ( - + ● {message.content} From 9d4ea20deb278a7c8d427647b5c1d5cf4d333352 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:13:21 -0700 Subject: [PATCH 08/18] fix: tool UI again --- src/ui/TUIChat.tsx | 6 ++---- src/ui/ToolResultSummary.tsx | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 59528a8b8..b570f0807 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -294,7 +294,7 @@ const TUIChat: React.FC = ({ ● {message.content} - + = ({ return ( - - ● - + ● {message.content} {message.isStreaming && ▋} diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx index bc3d75a43..7ae6646ac 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -1,4 +1,4 @@ -import { Text, Box } from "ink"; +import { Box, Text } from "ink"; import React from "react"; interface ToolResultSummaryProps { @@ -13,7 +13,7 @@ const ToolResultSummary: React.FC = ({ const getSummary = () => { if (!content) return "No output"; - const lines = content.split('\n').length; + const lines = content.split("\n").length; const chars = content.length; // Use exact tool name matching @@ -32,10 +32,10 @@ const ToolResultSummary: React.FC = ({ return "File written successfully"; case "list_files": - return `Listed ${lines} ${lines === 1 ? 'item' : 'items'}`; + return `Listed ${lines} ${lines === 1 ? "item" : "items"}`; case "search_code": - return `Found ${lines} ${lines === 1 ? 'match' : 'matches'}`; + return `Found ${lines} ${lines === 1 ? "match" : "matches"}`; case "run_terminal_command": return `Command output (${lines} lines)`; @@ -58,13 +58,13 @@ const ToolResultSummary: React.FC = ({ case "Glob": const fileCount = lines; - return `Found ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`; + return `Found ${fileCount} ${fileCount === 1 ? "file" : "files"}`; case "Grep": - return `Found ${lines} ${lines === 1 ? 'match' : 'matches'}`; + return `Found ${lines} ${lines === 1 ? "match" : "matches"}`; case "LS": - return `Listed ${lines} ${lines === 1 ? 'item' : 'items'}`; + return `Listed ${lines} ${lines === 1 ? "item" : "items"}`; case "Write": return "File written successfully"; @@ -94,15 +94,19 @@ const ToolResultSummary: React.FC = ({ default: // Handle MCP tools or unknown tools if (toolName?.startsWith("mcp__")) { - const mcpToolName = toolName.replace("mcp__", "").replace("ide__", ""); + const mcpToolName = toolName + .replace("mcp__", "") + .replace("ide__", ""); return `${mcpToolName} tool output (${lines} lines)`; } // Fallback for unknown tools if (chars > 1000) { - return `${toolName || 'Tool'} output: ${lines} lines, ${chars} characters`; + return `${ + toolName || "Tool" + } output: ${lines} lines, ${chars} characters`; } else if (lines > 10) { - return `${toolName || 'Tool'} output: ${lines} lines`; + return `${toolName || "Tool"} output: ${lines} lines`; } else { return content.slice(0, 100) + (content.length > 100 ? "..." : ""); } @@ -111,9 +115,10 @@ const ToolResultSummary: React.FC = ({ return ( - {getSummary()} + ⎿ + {getSummary()} ); }; -export default ToolResultSummary; \ No newline at end of file +export default ToolResultSummary; From 2d4cf55c393121570ff2c4459c6942e124bc88dd Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:14:43 -0700 Subject: [PATCH 09/18] fix: delete hallucinated tools --- src/intro.ts | 3 +-- src/ui/TUIChat.tsx | 29 ---------------------- src/ui/ToolResultSummary.tsx | 48 ------------------------------------ 3 files changed, 1 insertion(+), 79 deletions(-) diff --git a/src/intro.ts b/src/intro.ts index 44fc37f81..74cda0e5f 100644 --- a/src/intro.ts +++ b/src/intro.ts @@ -1,9 +1,8 @@ +import { Assistant, type AssistantConfig } from "@continuedev/sdk"; import chalk from "chalk"; -import * as fs from "fs"; import { CONTINUE_ASCII_ART } from "./asciiArt.js"; import { MCPService } from "./mcp.js"; import { getAllTools } from "./streamChatResponse.js"; -import { Assistant, type AssistantConfig } from "@continuedev/sdk"; export function loadSystemMessage( assistant: AssistantConfig diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index b570f0807..90e753e13 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -135,35 +135,6 @@ const TUIChat: React.FC = ({ return `Terminal(${args.command || ""})`; case "view_diff": return `Diff(${args.path || "."})`; - - // External Claude Code Tools (PascalCase) - case "Read": - return `Read(${args.file_path || args.path || ""})`; - case "Write": - return `Write(${args.file_path || ""})`; - case "Edit": - case "MultiEdit": - return `Edit(${args.file_path || ""})`; - case "Bash": - return `Terminal(${args.command || ""})`; - case "Glob": - return `Find(${args.pattern || ""})`; - case "Grep": - return `Search(${args.pattern || ""})`; - case "LS": - return `List(${args.path || ""})`; - case "NotebookRead": - return `Notebook(${args.notebook_path || ""})`; - case "NotebookEdit": - return `Notebook(${args.notebook_path || ""})`; - case "WebFetch": - return `Web(${args.url || ""})`; - case "WebSearch": - return `Search(${args.query || ""})`; - case "TodoWrite": - return `Todo(${args.todos?.length || 0} items)`; - case "Task": - return `Task(${args.description || ""})`; default: // Handle MCP tools or unknown tools if (name.startsWith("mcp__")) { diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx index 7ae6646ac..0605d1144 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -43,54 +43,6 @@ const ToolResultSummary: React.FC = ({ case "view_diff": return `Diff output (${lines} lines)`; - // External Claude Code Tools (PascalCase) - case "Read": - // Try to extract file path from content if it contains line numbers - if (content.includes("→")) { - const pathMatch = content.match(/^(.+?):/); - const filePath = pathMatch ? pathMatch[1] : "file"; - return `Read ${filePath} (${lines} lines)`; - } - return `Read tool output (${lines} lines)`; - - case "Bash": - return `Command output (${lines} lines)`; - - case "Glob": - const fileCount = lines; - return `Found ${fileCount} ${fileCount === 1 ? "file" : "files"}`; - - case "Grep": - return `Found ${lines} ${lines === 1 ? "match" : "matches"}`; - - case "LS": - return `Listed ${lines} ${lines === 1 ? "item" : "items"}`; - - case "Write": - return "File written successfully"; - - case "Edit": - case "MultiEdit": - return "File edited successfully"; - - case "NotebookRead": - return `Read notebook (${lines} lines)`; - - case "NotebookEdit": - return "Notebook edited successfully"; - - case "WebFetch": - return `Fetched web content (${lines} lines)`; - - case "WebSearch": - return `Search results (${lines} lines)`; - - case "TodoWrite": - return "Todo list updated"; - - case "Task": - return `Task completed (${lines} lines)`; - default: // Handle MCP tools or unknown tools if (toolName?.startsWith("mcp__")) { From 837ac2d5c33ad0ef6482f8216dd7b3a8ec852fe3 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:26:02 -0700 Subject: [PATCH 10/18] fix: refactor display name for tools --- src/intro.ts | 24 ++++++++++++----------- src/tools.ts | 2 ++ src/tools/exit.ts | 1 + src/tools/index.ts | 6 ++++++ src/tools/listFiles.ts | 1 + src/tools/readFile.ts | 1 + src/tools/runTerminalCommand.ts | 1 + src/tools/searchCode.ts | 1 + src/tools/types.ts | 1 + src/tools/viewDiff.ts | 1 + src/tools/writeFile.ts | 1 + src/ui/TUIChat.tsx | 34 ++++++--------------------------- src/ui/ToolResultSummary.tsx | 25 ++++++++---------------- 13 files changed, 43 insertions(+), 56 deletions(-) diff --git a/src/intro.ts b/src/intro.ts index 74cda0e5f..5a08117ab 100644 --- a/src/intro.ts +++ b/src/intro.ts @@ -21,10 +21,10 @@ export function introMessage(assistant: Assistant, mcpService: MCPService) { console.info(chalk.cyan(CONTINUE_ASCII_ART)); - console.info(`\n${chalk.bold.blue(`Assistant: ${assistantConfig.name}`)}`); - console.info(`${chalk.blue(`Model: ${assistant.getModel()}`)}\n`); + console.info(`\n${chalk.bold.blue(`Agent: ${assistantConfig.name}\n`)}`); + console.info(`${chalk.yellow("Model:")} ${assistant.getModel()}\n`); - console.info(chalk.yellow("Available tools:")); + console.info(chalk.yellow("Tools:")); getAllTools().forEach((tool) => { console.info( `- ${chalk.green(tool.function.name)}: ${tool.function.description ?? ""}` @@ -35,14 +35,16 @@ export function introMessage(assistant: Assistant, mcpService: MCPService) { }); console.info(""); - console.info(chalk.yellow("\nAvailable slash commands:")); - console.info("- /exit: Exit the chat"); - console.info("- /clear: Clear the chat history"); - console.info("- /help: Show help message"); - console.info("- /models: Show available models"); - console.info("- /login: Authenticate with your account"); - console.info("- /logout: Sign out of your current session"); - console.info("- /whoami: Check who you're currently logged in as"); + console.info(chalk.yellow("Slash commands:")); + console.info(`- ${chalk.green("/exit")}: Exit the chat`); + console.info(`- ${chalk.green("/clear")}: Clear the chat history`); + console.info(`- ${chalk.green("/help")}: Show help message`); + console.info(`- ${chalk.green("/models")}: Show available models`); + console.info(`- ${chalk.green("/login")}: Authenticate with your account`); + console.info(`- ${chalk.green("/logout")}: Sign out of your current session`); + console.info( + `- ${chalk.green("/whoami")}: Check who you're currently logged in as` + ); for (const prompt of assistantConfig.prompts ?? []) { console.info(`- /${prompt?.name}: ${prompt?.description}`); } diff --git a/src/tools.ts b/src/tools.ts index a9b7a7b5e..f2aeb341e 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -3,6 +3,7 @@ import { executeToolCall, extractToolCalls, getToolsDescription, + getToolDisplayName, Tool, } from "./tools/index.js"; @@ -11,6 +12,7 @@ export { executeToolCall, extractToolCalls, getToolsDescription, + getToolDisplayName, Tool, BUILTIN_TOOLS as tools, }; diff --git a/src/tools/exit.ts b/src/tools/exit.ts index 5f884a919..999600d6a 100644 --- a/src/tools/exit.ts +++ b/src/tools/exit.ts @@ -2,6 +2,7 @@ import { Tool } from "./types.js"; export const exitTool: Tool = { name: "exit", + displayName: "Exit", description: "Exit the current process with status code 1, indicating a failure or error", parameters: {}, diff --git a/src/tools/index.ts b/src/tools/index.ts index 3ee6972c2..2340b6db3 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -22,6 +22,11 @@ export const BUILTIN_TOOLS: Tool[] = [ ...(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 { return BUILTIN_TOOLS.map((tool) => { const params = Object.entries(tool.parameters) @@ -99,6 +104,7 @@ export async function executeToolCall(toolCall: { ?.getTools() .map((t) => ({ name: t.name, + displayName: t.name.replace("mcp__", "").replace("ide__", ""), description: t.description ?? "", parameters: convertInputSchemaToParameters(t.inputSchema), run: async (args: any) => { diff --git a/src/tools/listFiles.ts b/src/tools/listFiles.ts index bcd6df4d2..80010e58d 100644 --- a/src/tools/listFiles.ts +++ b/src/tools/listFiles.ts @@ -5,6 +5,7 @@ import { Tool } from "./types.js"; // List files in a directory export const listFilesTool: Tool = { name: "list_files", + displayName: "List", description: "List files in a directory", parameters: { dirpath: { diff --git a/src/tools/readFile.ts b/src/tools/readFile.ts index 2ea6bf5de..45ed8aa5b 100644 --- a/src/tools/readFile.ts +++ b/src/tools/readFile.ts @@ -3,6 +3,7 @@ import { Tool } from "./types.js"; export const readFileTool: Tool = { name: "read_file", + displayName: "Read", description: "Read the contents of a file at the specified path", parameters: { filepath: { diff --git a/src/tools/runTerminalCommand.ts b/src/tools/runTerminalCommand.ts index 176f669e8..e753e8a31 100644 --- a/src/tools/runTerminalCommand.ts +++ b/src/tools/runTerminalCommand.ts @@ -3,6 +3,7 @@ import { exec } from "child_process"; export const runTerminalCommandTool: Tool = { name: "run_terminal_command", + displayName: "Terminal", description: "Executes a terminal command and returns the output.", parameters: { command: { diff --git a/src/tools/searchCode.ts b/src/tools/searchCode.ts index 1b53b0c3f..fe6073203 100644 --- a/src/tools/searchCode.ts +++ b/src/tools/searchCode.ts @@ -7,6 +7,7 @@ const execPromise = util.promisify(child_process.exec); export const searchCodeTool: Tool = { name: "search_code", + displayName: "Search", description: "Search the codebase using ripgrep (rg) for a specific pattern", parameters: { pattern: { diff --git a/src/tools/types.ts b/src/tools/types.ts index 45ca005a3..86074f13b 100644 --- a/src/tools/types.ts +++ b/src/tools/types.ts @@ -9,6 +9,7 @@ export type ToolParameters = Record< export interface Tool { name: string; + displayName: string; description: string; parameters: ToolParameters; run: (args: any) => Promise; diff --git a/src/tools/viewDiff.ts b/src/tools/viewDiff.ts index b16eb861b..ebc9abab2 100644 --- a/src/tools/viewDiff.ts +++ b/src/tools/viewDiff.ts @@ -7,6 +7,7 @@ const execPromise = util.promisify(child_process.exec); export const viewDiffTool: Tool = { name: "view_diff", + displayName: "Diff", description: "View all uncommitted changes in the git repository", parameters: { path: { diff --git a/src/tools/writeFile.ts b/src/tools/writeFile.ts index 54c1bc221..2ab64799f 100644 --- a/src/tools/writeFile.ts +++ b/src/tools/writeFile.ts @@ -4,6 +4,7 @@ import { Tool } from "./types.js"; export const writeFileTool: Tool = { name: "write_file", + displayName: "Write", description: "Write content to a file at the specified path", parameters: { filepath: { diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 90e753e13..f6a0a19df 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -4,6 +4,7 @@ import { ChatCompletionMessageParam } from "openai/resources.mjs"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; +import { getToolDisplayName } from "../tools.js"; import ToolResultSummary from "./ToolResultSummary.js"; import UserInput from "./UserInput.js"; @@ -119,35 +120,12 @@ const TUIChat: React.FC = ({ }, onToolStart: (toolName: string, toolArgs?: any) => { const formatToolCall = (name: string, args: any) => { - if (!args) return name; + const displayName = getToolDisplayName(name); + if (!args) return displayName; - switch (name) { - // CLI Internal Tools (snake_case) - case "read_file": - 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 || ""})`; - } + // Get the first parameter value for display + const firstValue = Object.values(args)[0]; + return `${displayName}(${firstValue || ""})`; }; setMessages((prev) => [ diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx index 0605d1144..c360f9f0b 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -1,5 +1,6 @@ import { Box, Text } from "ink"; import React from "react"; +import { getToolDisplayName } from "../tools.js"; interface ToolResultSummaryProps { toolName?: string; @@ -15,18 +16,18 @@ const ToolResultSummary: React.FC = ({ const lines = content.split("\n").length; const chars = content.length; + const displayName = toolName ? getToolDisplayName(toolName) : "Tool"; - // Use exact tool name matching + // Handle specific tool output formatting switch (toolName) { - // CLI Internal Tools (snake_case) case "read_file": // Try to extract file path from content if it contains line numbers if (content.includes("→")) { const pathMatch = content.match(/^(.+?):/); 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": return "File written successfully"; @@ -44,21 +45,11 @@ const ToolResultSummary: React.FC = ({ return `Diff output (${lines} lines)`; default: - // Handle MCP tools or unknown tools - if (toolName?.startsWith("mcp__")) { - const mcpToolName = toolName - .replace("mcp__", "") - .replace("ide__", ""); - return `${mcpToolName} tool output (${lines} lines)`; - } - - // Fallback for unknown tools + // Fallback for all tools using display name if (chars > 1000) { - return `${ - toolName || "Tool" - } output: ${lines} lines, ${chars} characters`; + return `${displayName} output: ${lines} lines, ${chars} characters`; } else if (lines > 10) { - return `${toolName || "Tool"} output: ${lines} lines`; + return `${displayName} output: ${lines} lines`; } else { return content.slice(0, 100) + (content.length > 100 ? "..." : ""); } From 94e6f12924ff5ee429a43c53d1810d5519f026bb Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:28:45 -0700 Subject: [PATCH 11/18] fix: adjust placeholder --- src/ui/UserInput.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx index 7578a058f..fc46fd8b8 100644 --- a/src/ui/UserInput.tsx +++ b/src/ui/UserInput.tsx @@ -68,14 +68,15 @@ const UserInput: React.FC = ({ }); const renderInputText = () => { + const placeholderText = "Ask anything, @ for context, / for slash commands"; if (inputText.length === 0) { return ( <> {inputMode && !isWaitingForResponse && ( - ▋Type your message... + ▋{placeholderText} )} {(!inputMode || isWaitingForResponse) && ( - Type your message... + {placeholderText} )} ); @@ -149,4 +150,4 @@ const UserInput: React.FC = ({ ); }; -export default UserInput; \ No newline at end of file +export default UserInput; From 863b156e63f471513556904092201a5af510caee Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:34:46 -0700 Subject: [PATCH 12/18] footer --- src/ui/TUIChat.tsx | 3 +++ src/ui/UserInput.tsx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index f6a0a19df..bcc94f57d 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -306,6 +306,9 @@ const TUIChat: React.FC = ({ inputMode={inputMode} onInterrupt={handleInterrupt} /> + + ● Continue CLI + ); diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx index fc46fd8b8..075a02bc3 100644 --- a/src/ui/UserInput.tsx +++ b/src/ui/UserInput.tsx @@ -141,7 +141,7 @@ const UserInput: React.FC = ({ }; return ( - + ●{" "} From 7eefce2de39fca9ab51b2d2fb1d0b24286c09404 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:45:52 -0700 Subject: [PATCH 13/18] feat: slash command UI and ASCII spinner --- src/ui/LoadingAnimation.tsx | 31 +++++++ src/ui/SlashCommandUI.tsx | 110 +++++++++++++++++++++++++ src/ui/TUIChat.tsx | 7 +- src/ui/UserInput.tsx | 159 ++++++++++++++++++++++++++++++++++-- 4 files changed, 296 insertions(+), 11 deletions(-) create mode 100644 src/ui/LoadingAnimation.tsx create mode 100644 src/ui/SlashCommandUI.tsx diff --git a/src/ui/LoadingAnimation.tsx b/src/ui/LoadingAnimation.tsx new file mode 100644 index 000000000..e0747d12c --- /dev/null +++ b/src/ui/LoadingAnimation.tsx @@ -0,0 +1,31 @@ +import { Text } from "ink"; +import React, { useEffect, useState } from "react"; + +interface LoadingAnimationProps { + visible?: boolean; + color?: string; +} + +const LoadingAnimation: React.FC = ({ + visible = true, + color = "gray", +}) => { + const [currentIndex, setCurrentIndex] = useState(0); + const animationChars = ["-", "/", "|", "\\", "-", "/"]; + + useEffect(() => { + if (!visible) return; + + const interval = setInterval(() => { + setCurrentIndex((prev) => (prev + 1) % animationChars.length); + }, 150); + + return () => clearInterval(interval); + }, [visible, animationChars.length]); + + if (!visible) return null; + + return {animationChars[currentIndex]}; +}; + +export default LoadingAnimation; diff --git a/src/ui/SlashCommandUI.tsx b/src/ui/SlashCommandUI.tsx new file mode 100644 index 000000000..a18914ac1 --- /dev/null +++ b/src/ui/SlashCommandUI.tsx @@ -0,0 +1,110 @@ +import { Box, Text } from "ink"; +import React from "react"; +import { type AssistantConfig } from "@continuedev/sdk"; + +interface SlashCommandUIProps { + assistant: AssistantConfig; + filter: string; + selectedIndex: number; + onSelect: (command: string) => void; +} + +interface SlashCommand { + name: string; + description: string; + category: "system" | "assistant"; +} + +const SlashCommandUI: React.FC = ({ + assistant, + filter, + selectedIndex, + onSelect, +}) => { + // Get all available slash commands + const getSlashCommands = (): SlashCommand[] => { + const systemCommands: SlashCommand[] = [ + { name: "help", description: "Show help message", category: "system" }, + { name: "exit", description: "Exit the chat", category: "system" }, + { name: "login", description: "Authenticate with your account", category: "system" }, + { name: "logout", description: "Sign out of your current session", category: "system" }, + { name: "whoami", description: "Check who you're currently logged in as", category: "system" }, + { name: "models", description: "List available AI models", category: "system" }, + ]; + + const assistantCommands: SlashCommand[] = assistant.prompts?.map( + (prompt) => ({ + name: prompt?.name || "", + description: prompt?.description || "", + category: "assistant" as const, + }) + ) || []; + + return [...systemCommands, ...assistantCommands]; + }; + + const allCommands = getSlashCommands(); + + // Filter commands based on the current filter + const filteredCommands = allCommands.filter( + (cmd) => cmd.name.toLowerCase().includes(filter.toLowerCase()) + ); + + if (filteredCommands.length === 0) { + return ( + + No matching commands found + + ); + } + + return ( + + + + Slash Commands + + + + {filteredCommands.map((command, index) => { + const isSelected = index === selectedIndex; + const categoryColor = command.category === "system" ? "cyan" : "yellow"; + + return ( + + + {isSelected ? "▶ " : " "} + /{command.name} + - {command.description} + + + ); + })} + + + + Use ↑/↓ to navigate, Enter to select, Tab to complete + + + + ); +}; + +export default SlashCommandUI; \ No newline at end of file diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index bcc94f57d..60d579dd2 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -5,6 +5,7 @@ import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; import { getToolDisplayName } from "../tools.js"; +import LoadingAnimation from "./LoadingAnimation.js"; import ToolResultSummary from "./ToolResultSummary.js"; import UserInput from "./UserInput.js"; @@ -294,7 +295,8 @@ const TUIChat: React.FC = ({ {/* Status */} {isWaitingForResponse && ( - + + esc to interrupt )} @@ -305,6 +307,7 @@ const TUIChat: React.FC = ({ isWaitingForResponse={isWaitingForResponse} inputMode={inputMode} onInterrupt={handleInterrupt} + assistant={assistant.config} /> ● Continue CLI @@ -314,4 +317,4 @@ const TUIChat: React.FC = ({ ); }; -export default TUIChat; +export default TUIChat; \ No newline at end of file diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx index 075a02bc3..8601f5a0e 100644 --- a/src/ui/UserInput.tsx +++ b/src/ui/UserInput.tsx @@ -1,5 +1,7 @@ +import { type AssistantConfig } from "@continuedev/sdk"; import { Box, Text, useApp, useInput } from "ink"; import React, { useState } from "react"; +import SlashCommandUI from "./SlashCommandUI.js"; import { TextBuffer } from "./TextBuffer.js"; interface UserInputProps { @@ -7,6 +9,7 @@ interface UserInputProps { isWaitingForResponse: boolean; inputMode: boolean; onInterrupt?: () => void; + assistant: AssistantConfig; } const UserInput: React.FC = ({ @@ -14,12 +17,91 @@ const UserInput: React.FC = ({ isWaitingForResponse, inputMode, onInterrupt, + assistant, }) => { const [textBuffer] = useState(() => new TextBuffer()); const [inputText, setInputText] = useState(""); const [cursorPosition, setCursorPosition] = useState(0); + const [showSlashCommands, setShowSlashCommands] = useState(false); + const [slashCommandFilter, setSlashCommandFilter] = useState(""); + const [selectedCommandIndex, setSelectedCommandIndex] = useState(0); const { exit } = useApp(); + // Get all available slash commands + const getSlashCommands = () => { + const systemCommands = [ + { name: "help", description: "Show help message" }, + { name: "exit", description: "Exit the chat" }, + { name: "login", description: "Authenticate with your account" }, + { name: "logout", description: "Sign out of your current session" }, + { + name: "whoami", + description: "Check who you're currently logged in as", + }, + { name: "models", description: "List available AI models" }, + ]; + + const assistantCommands = + assistant.prompts?.map((prompt) => ({ + name: prompt?.name || "", + description: prompt?.description || "", + })) || []; + + return [...systemCommands, ...assistantCommands]; + }; + + // Update slash command UI state based on input + const updateSlashCommandState = (text: string, cursor: number) => { + // Check if we're in a slash command context + const beforeCursor = text.slice(0, cursor); + const lastSlashIndex = beforeCursor.lastIndexOf("/"); + + if (lastSlashIndex !== -1) { + // Check if there's any whitespace between the last slash and cursor + const afterSlash = beforeCursor.slice(lastSlashIndex + 1); + + if (!afterSlash.includes(" ") && !afterSlash.includes("\n")) { + // We're in a slash command context + setShowSlashCommands(true); + setSlashCommandFilter(afterSlash); + setSelectedCommandIndex(0); + } else { + setShowSlashCommands(false); + } + } else { + setShowSlashCommands(false); + } + }; + + // Get filtered commands for navigation + const getFilteredCommands = () => { + const allCommands = getSlashCommands(); + return allCommands.filter((cmd) => + cmd.name.toLowerCase().includes(slashCommandFilter.toLowerCase()) + ); + }; + + // Handle slash command selection + const selectSlashCommand = (commandName: string) => { + const beforeCursor = inputText.slice(0, cursorPosition); + const lastSlashIndex = beforeCursor.lastIndexOf("/"); + + if (lastSlashIndex !== -1) { + const beforeSlash = inputText.slice(0, lastSlashIndex); + const afterCursor = inputText.slice(cursorPosition); + + // Replace the partial command with the full command + const newText = beforeSlash + "/" + commandName + " " + afterCursor; + const newCursorPos = lastSlashIndex + 1 + commandName.length + 1; + + textBuffer.setText(newText); + textBuffer.setCursor(newCursorPos); + setInputText(newText); + setCursorPosition(newCursorPos); + setShowSlashCommands(false); + } + }; + useInput((input, key) => { if (key.ctrl && (input === "c" || input === "d")) { exit(); @@ -32,10 +114,49 @@ const UserInput: React.FC = ({ return; } + // Handle escape key to close slash command UI + if (key.escape && showSlashCommands && inputMode) { + setShowSlashCommands(false); + return; + } + if (!inputMode) { return; } + // Handle slash command navigation + if (showSlashCommands) { + const filteredCommands = getFilteredCommands(); + + if (key.upArrow) { + setSelectedCommandIndex((prev) => + prev > 0 ? prev - 1 : filteredCommands.length - 1 + ); + return; + } + + if (key.downArrow) { + setSelectedCommandIndex((prev) => + prev < filteredCommands.length - 1 ? prev + 1 : 0 + ); + return; + } + + if (key.return && !key.shift) { + if (filteredCommands.length > 0) { + selectSlashCommand(filteredCommands[selectedCommandIndex].name); + } + return; + } + + if (key.tab) { + if (filteredCommands.length > 0) { + selectSlashCommand(filteredCommands[selectedCommandIndex].name); + } + return; + } + } + // Handle Enter key (regular enter for submit) if (key.return && !key.shift) { if (textBuffer.text.trim() && !isWaitingForResponse) { @@ -43,6 +164,7 @@ const UserInput: React.FC = ({ textBuffer.clear(); setInputText(""); setCursorPosition(0); + setShowSlashCommands(false); } return; } @@ -51,8 +173,11 @@ const UserInput: React.FC = ({ if (input === "\r" || input === "\\\r") { const handled = textBuffer.handleInput("\n", key); if (handled) { - setInputText(textBuffer.text); - setCursorPosition(textBuffer.cursor); + const newText = textBuffer.text; + const newCursor = textBuffer.cursor; + setInputText(newText); + setCursorPosition(newCursor); + updateSlashCommandState(newText, newCursor); } return; } @@ -62,8 +187,11 @@ const UserInput: React.FC = ({ // Update React state to trigger re-render if (handled) { - setInputText(textBuffer.text); - setCursorPosition(textBuffer.cursor); + const newText = textBuffer.text; + const newCursor = textBuffer.cursor; + setInputText(newText); + setCursorPosition(newCursor); + updateSlashCommandState(newText, newCursor); } }); @@ -141,11 +269,24 @@ const UserInput: React.FC = ({ }; return ( - - - ●{" "} - - {renderInputText()} + + {/* Input box */} + + + ●{" "} + + {renderInputText()} + + + {/* Slash command UI */} + {showSlashCommands && inputMode && ( + + )} ); }; From dccb31106a43f2c295da3f8a4225a44969cb3ef7 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:52:35 -0700 Subject: [PATCH 14/18] feat: more spinners --- src/ui/LoadingAnimation.tsx | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ui/LoadingAnimation.tsx b/src/ui/LoadingAnimation.tsx index e0747d12c..dc19f6da4 100644 --- a/src/ui/LoadingAnimation.tsx +++ b/src/ui/LoadingAnimation.tsx @@ -1,6 +1,37 @@ import { Text } from "ink"; import React, { useEffect, useState } from "react"; +const SPINNER_BARS = "▁▂▃▄▅▆▇█▇▆▅▄▃▁"; +const SPINNER_BLOCKS = "▉▊▋▌▍▎▏▎▍▌▋▊▉"; +const SPINNER_CORNERS = "▖▘▝▗"; +const SPINNER_CLASSIC = "-/|\\-/|"; +const SPINNER_BOX = "┤┘┴└├┌┬┐"; +const SPINNER_DOUBLE_BARS = [ + "▁▁", + "▁▂", + "▁▃", + "▁▄", + "▁▅", + "▁▆", + "▁▇", + "▁█", + "▂▇", + "▃▆", + "▄▅", + "▅▄", + "▆▃", + "▇▂", + "█▁", + "▇▁", + "▆▁", + "▅▁", + "▄▁", + "▃▁", + "▂▁", +]; + +const SPINNER: string | string[] = SPINNER_CORNERS; + interface LoadingAnimationProps { visible?: boolean; color?: string; @@ -8,10 +39,11 @@ interface LoadingAnimationProps { const LoadingAnimation: React.FC = ({ visible = true, - color = "gray", + color = "blue", }) => { const [currentIndex, setCurrentIndex] = useState(0); - const animationChars = ["-", "/", "|", "\\", "-", "/"]; + const animationChars = + typeof SPINNER === "string" ? (SPINNER as string).split("") : SPINNER; useEffect(() => { if (!visible) return; From c62cbdc21e6e93788d8e01c0a97c17ef0c036261 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:57:57 -0700 Subject: [PATCH 15/18] feat: better slash command UI --- src/ui/SlashCommandUI.tsx | 73 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/ui/SlashCommandUI.tsx b/src/ui/SlashCommandUI.tsx index a18914ac1..dfef5ce06 100644 --- a/src/ui/SlashCommandUI.tsx +++ b/src/ui/SlashCommandUI.tsx @@ -1,6 +1,6 @@ +import { type AssistantConfig } from "@continuedev/sdk"; import { Box, Text } from "ink"; import React from "react"; -import { type AssistantConfig } from "@continuedev/sdk"; interface SlashCommandUIProps { assistant: AssistantConfig; @@ -26,28 +26,43 @@ const SlashCommandUI: React.FC = ({ const systemCommands: SlashCommand[] = [ { name: "help", description: "Show help message", category: "system" }, { name: "exit", description: "Exit the chat", category: "system" }, - { name: "login", description: "Authenticate with your account", category: "system" }, - { name: "logout", description: "Sign out of your current session", category: "system" }, - { name: "whoami", description: "Check who you're currently logged in as", category: "system" }, - { name: "models", description: "List available AI models", category: "system" }, + { + name: "login", + description: "Authenticate with your account", + category: "system", + }, + { + name: "logout", + description: "Sign out of your current session", + category: "system", + }, + { + name: "whoami", + description: "Check who you're currently logged in as", + category: "system", + }, + { + name: "models", + description: "List available AI models", + category: "system", + }, ]; - const assistantCommands: SlashCommand[] = assistant.prompts?.map( - (prompt) => ({ + const assistantCommands: SlashCommand[] = + assistant.prompts?.map((prompt) => ({ name: prompt?.name || "", description: prompt?.description || "", category: "assistant" as const, - }) - ) || []; + })) || []; return [...systemCommands, ...assistantCommands]; }; const allCommands = getSlashCommands(); - + // Filter commands based on the current filter - const filteredCommands = allCommands.filter( - (cmd) => cmd.name.toLowerCase().includes(filter.toLowerCase()) + const filteredCommands = allCommands.filter((cmd) => + cmd.name.toLowerCase().includes(filter.toLowerCase()) ); if (filteredCommands.length === 0) { @@ -65,39 +80,21 @@ const SlashCommandUI: React.FC = ({ } return ( - - - - Slash Commands - - - + {filteredCommands.map((command, index) => { const isSelected = index === selectedIndex; - const categoryColor = command.category === "system" ? "cyan" : "yellow"; - + return ( - - - {isSelected ? "▶ " : " "} - /{command.name} + + + {" "} + /{command.name} - {command.description} ); })} - + Use ↑/↓ to navigate, Enter to select, Tab to complete @@ -107,4 +104,4 @@ const SlashCommandUI: React.FC = ({ ); }; -export default SlashCommandUI; \ No newline at end of file +export default SlashCommandUI; From 0a402010d9ae98a6913b7ceb68b97dfd9772754e Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 18:59:31 -0700 Subject: [PATCH 16/18] fix: slash command prefix matching --- src/ui/SlashCommandUI.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ui/SlashCommandUI.tsx b/src/ui/SlashCommandUI.tsx index dfef5ce06..27508a738 100644 --- a/src/ui/SlashCommandUI.tsx +++ b/src/ui/SlashCommandUI.tsx @@ -61,10 +61,17 @@ const SlashCommandUI: React.FC = ({ const allCommands = getSlashCommands(); // Filter commands based on the current filter - const filteredCommands = allCommands.filter((cmd) => - cmd.name.toLowerCase().includes(filter.toLowerCase()) - ); + const filteredCommands = allCommands + .filter((cmd) => cmd.name.toLowerCase().includes(filter.toLowerCase())) + .sort((a, b) => { + const aStartsWith = a.name.toLowerCase().startsWith(filter.toLowerCase()); + const bStartsWith = b.name.toLowerCase().startsWith(filter.toLowerCase()); + if (aStartsWith && !bStartsWith) return -1; + if (!aStartsWith && bStartsWith) return 1; + + return a.name.localeCompare(b.name); + }); if (filteredCommands.length === 0) { return ( Date: Sun, 13 Jul 2025 19:02:12 -0700 Subject: [PATCH 17/18] fix: more slashcommand UI --- src/ui/SlashCommandUI.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/ui/SlashCommandUI.tsx b/src/ui/SlashCommandUI.tsx index 27508a738..3f03bf8fb 100644 --- a/src/ui/SlashCommandUI.tsx +++ b/src/ui/SlashCommandUI.tsx @@ -74,13 +74,7 @@ const SlashCommandUI: React.FC = ({ }); if (filteredCommands.length === 0) { return ( - + No matching commands found ); From ee40d8bbb48d502055cad1e811e973598b0bf9bd Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 13 Jul 2025 19:04:36 -0700 Subject: [PATCH 18/18] fix: slash command tab --- src/ui/UserInput.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx index 8601f5a0e..d05a4c54c 100644 --- a/src/ui/UserInput.tsx +++ b/src/ui/UserInput.tsx @@ -73,12 +73,22 @@ const UserInput: React.FC = ({ } }; - // Get filtered commands for navigation + // Get filtered commands for navigation - using the same sorting logic as SlashCommandUI const getFilteredCommands = () => { const allCommands = getSlashCommands(); - return allCommands.filter((cmd) => - cmd.name.toLowerCase().includes(slashCommandFilter.toLowerCase()) - ); + return allCommands + .filter((cmd) => + cmd.name.toLowerCase().includes(slashCommandFilter.toLowerCase()) + ) + .sort((a, b) => { + const aStartsWith = a.name.toLowerCase().startsWith(slashCommandFilter.toLowerCase()); + const bStartsWith = b.name.toLowerCase().startsWith(slashCommandFilter.toLowerCase()); + + if (aStartsWith && !bStartsWith) return -1; + if (!aStartsWith && bStartsWith) return 1; + + return a.name.localeCompare(b.name); + }); }; // Handle slash command selection @@ -291,4 +301,4 @@ const UserInput: React.FC = ({ ); }; -export default UserInput; +export default UserInput; \ No newline at end of file