Replace text_editor_* tools with OpenCode-inspired alternatives (read/write/edit)

This commit is contained in:
Alex Gleason committed 2026-01-21 19:40:32 -06:00
1 parent 47a7835797
commit 765652ec67
13 files changed
+1585 -1210

No files matched your search

+13 -6
View File
@@ -18,9 +18,11 @@ import { useMCPTools } from '@/hooks/useMCPTools';
import { useQueryClient } from '@tanstack/react-query';
import { AIMessageItem } from '@/components/AIMessageItem';
import { ToolCallDisplay } from '@/components/ToolCallDisplay';
import { TextEditorViewTool } from '@/lib/tools/TextEditorViewTool';
import { TextEditorWriteTool } from '@/lib/tools/TextEditorWriteTool';
import { TextEditorStrReplaceTool } from '@/lib/tools/TextEditorStrReplaceTool';
import { ReadTool } from '@/lib/tools/ReadTool';
import { WriteTool } from '@/lib/tools/WriteTool';
import { EditTool } from '@/lib/tools/EditTool';
import { GlobTool } from '@/lib/tools/GlobTool';
import { GrepTool } from '@/lib/tools/GrepTool';
import { NpmAddPackageTool } from '@/lib/tools/NpmAddPackageTool';
import { NpmRemovePackageTool } from '@/lib/tools/NpmRemovePackageTool';
import { GitCommitTool } from '@/lib/tools/GitCommitTool';
@@ -174,10 +176,15 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
// Separate built-in tools from MCP tools for clarity
const builtInTools = useMemo(() => {
const tools: Record<string, Tool<unknown>> = {
// File operation tools (OpenCode-compatible API)
read: new ReadTool(fs, cwd, { projectsPath }),
write: new WriteTool(fs, cwd, { projectsPath, tmpPath, onFileChanged: handleFileChanged }),
edit: new EditTool(fs, cwd, { projectsPath, tmpPath, onFileChanged: handleFileChanged }),
glob: new GlobTool(fs, cwd),
grep: new GrepTool(fs, cwd),
// Other tools
git_commit: new GitCommitTool(fs, cwd, git, { onCommit: handleCommit }),
text_editor_view: new TextEditorViewTool(fs, cwd, { projectsPath }),
text_editor_write: new TextEditorWriteTool(fs, cwd, { projectsPath, tmpPath, onFileChanged: handleFileChanged }),
text_editor_str_replace: new TextEditorStrReplaceTool(fs, cwd, { projectsPath, tmpPath, onFileChanged: handleFileChanged }),
npm_add_package: new NpmAddPackageTool(fs, cwd),
npm_remove_package: new NpmRemovePackageTool(fs, cwd),
build_project: new BuildProjectTool(fs, cwd, esmUrlRef.current),
+62 -5
View File
@@ -90,6 +90,56 @@ function getToolInfo(toolName: string, args: Record<string, unknown>): ToolInfo
errorTitle: args.command ? `Failed: ${String(args.command)}` : 'Shell Command Failed',
};
// New tools (OpenCode-compatible names)
case 'read': {
const path = args.filePath ? String(args.filePath) : 'File';
const offset = typeof args.offset === 'number' ? args.offset : 0;
const limit = typeof args.limit === 'number' ? args.limit : 2000;
const hasLineRange = args.offset || args.limit;
const lineInfo = hasLineRange
? ` (lines ${offset}-${offset + limit})`
: '';
return {
icon: Eye,
title: `Read ${path}${lineInfo}`,
callingTitle: `Reading ${path}${lineInfo}`,
errorTitle: `Failed to read ${path}${lineInfo}`,
};
}
case 'write':
return {
icon: FileText,
title: args.filePath ? `Wrote ${args.filePath}` : 'Wrote File',
callingTitle: args.filePath ? `Writing ${args.filePath}` : 'Writing File',
errorTitle: args.filePath ? `Failed to write ${args.filePath}` : 'Failed to Write File',
};
case 'edit':
return {
icon: Edit,
title: args.filePath ? `Edited ${args.filePath}` : 'Edited File',
callingTitle: args.filePath ? `Editing ${args.filePath}` : 'Editing File',
errorTitle: args.filePath ? `Failed to edit ${args.filePath}` : 'Failed to Edit File',
};
case 'glob':
return {
icon: Eye,
title: args.pattern ? `Glob: ${args.pattern}` : 'File Pattern Search',
callingTitle: args.pattern ? `Searching: ${args.pattern}` : 'Searching Files',
errorTitle: args.pattern ? `Failed to search: ${args.pattern}` : 'Search Failed',
};
case 'grep':
return {
icon: Eye,
title: args.pattern ? `Grep: ${args.pattern}` : 'Content Search',
callingTitle: args.pattern ? `Searching: ${args.pattern}` : 'Searching Content',
errorTitle: args.pattern ? `Failed to search: ${args.pattern}` : 'Search Failed',
};
// Legacy tools (kept for old chat history)
case 'text_editor_view': {
const path = args.path ? String(args.path) : 'File';
const hasLineRange = args.start_line || args.end_line;
@@ -342,19 +392,26 @@ export function ToolCallDisplay({ toolName, toolArgs, state, result }: ToolCallD
);
}
if (toolName === 'text_editor_write' && typeof toolArgs.file_text === 'string') {
// Write tool expanded content (new and legacy)
if ((toolName === 'write' && typeof toolArgs.content === 'string') ||
(toolName === 'text_editor_write' && typeof toolArgs.file_text === 'string')) {
const content = toolName === 'write' ? String(toolArgs.content) : String(toolArgs.file_text);
return (
<div className="mt-1 p-3 bg-muted/30 rounded border text-xs">
<div className="whitespace-pre-wrap break-words font-mono">
{toolArgs.file_text}
{content}
</div>
</div>
);
}
if (toolName === 'text_editor_str_replace' && typeof toolArgs.old_str === 'string' && typeof toolArgs.new_str === 'string') {
const oldLines = String(toolArgs.old_str).split('\n');
const newLines = String(toolArgs.new_str).split('\n');
// Edit tool expanded content (new and legacy)
if ((toolName === 'edit' && typeof toolArgs.oldString === 'string' && typeof toolArgs.newString === 'string') ||
(toolName === 'text_editor_str_replace' && typeof toolArgs.old_str === 'string' && typeof toolArgs.new_str === 'string')) {
const oldStr = toolName === 'edit' ? String(toolArgs.oldString) : String(toolArgs.old_str);
const newStr = toolName === 'edit' ? String(toolArgs.newString) : String(toolArgs.new_str);
const oldLines = oldStr.split('\n');
const newLines = newStr.split('\n');
return (
<div className="mt-1 p-3 bg-muted/30 rounded border text-xs font-mono">