import { useState, useCallback } from 'react'; import { createLogger } from '@automaker/utils/logger'; import { useAppStore } from '@/store/app-store'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { FileText, FolderOpen, Terminal, CheckCircle, XCircle, Loader2, Play, File, Pencil, Wrench, } from 'lucide-react'; import { cn } from '@/lib/utils'; import { getElectronAPI } from '@/lib/electron'; const logger = createLogger('AgentToolsView'); interface ToolResult { success: boolean; output?: string; error?: string; timestamp: Date; } interface ToolExecution { tool: string; input: string; result: ToolResult | null; isRunning: boolean; } export function AgentToolsView() { const { currentProject } = useAppStore(); const api = getElectronAPI(); // Read File Tool State const [readFilePath, setReadFilePath] = useState(''); const [readFileResult, setReadFileResult] = useState(null); const [isReadingFile, setIsReadingFile] = useState(false); // Write File Tool State const [writeFilePath, setWriteFilePath] = useState(''); const [writeFileContent, setWriteFileContent] = useState(''); const [writeFileResult, setWriteFileResult] = useState(null); const [isWritingFile, setIsWritingFile] = useState(false); // Terminal Tool State const [terminalCommand, setTerminalCommand] = useState('ls'); const [terminalResult, setTerminalResult] = useState(null); const [isRunningCommand, setIsRunningCommand] = useState(false); // Execute Read File const handleReadFile = useCallback(async () => { if (!readFilePath.trim()) return; setIsReadingFile(true); setReadFileResult(null); try { // Simulate agent requesting file read logger.info(`[Agent Tool] Requesting to read file: ${readFilePath}`); const result = await api.readFile(readFilePath); if (result.success) { setReadFileResult({ success: true, output: result.content, timestamp: new Date(), }); logger.info(`[Agent Tool] File read successful: ${readFilePath}`); } else { setReadFileResult({ success: false, error: result.error || 'Failed to read file', timestamp: new Date(), }); logger.info(`[Agent Tool] File read failed: ${result.error}`); } } catch (error) { setReadFileResult({ success: false, error: error instanceof Error ? error.message : 'Unknown error', timestamp: new Date(), }); } finally { setIsReadingFile(false); } }, [readFilePath, api]); // Execute Write File const handleWriteFile = useCallback(async () => { if (!writeFilePath.trim() || !writeFileContent.trim()) return; setIsWritingFile(true); setWriteFileResult(null); try { // Simulate agent requesting file write logger.info(`[Agent Tool] Requesting to write file: ${writeFilePath}`); const result = await api.writeFile(writeFilePath, writeFileContent); if (result.success) { setWriteFileResult({ success: true, output: `File written successfully: ${writeFilePath}`, timestamp: new Date(), }); logger.info(`[Agent Tool] File write successful: ${writeFilePath}`); } else { setWriteFileResult({ success: false, error: result.error || 'Failed to write file', timestamp: new Date(), }); logger.info(`[Agent Tool] File write failed: ${result.error}`); } } catch (error) { setWriteFileResult({ success: false, error: error instanceof Error ? error.message : 'Unknown error', timestamp: new Date(), }); } finally { setIsWritingFile(false); } }, [writeFilePath, writeFileContent, api]); // Execute Terminal Command const handleRunCommand = useCallback(async () => { if (!terminalCommand.trim()) return; setIsRunningCommand(true); setTerminalResult(null); try { // Terminal command simulation for demonstration purposes logger.info(`[Agent Tool] Simulating command: ${terminalCommand}`); // Simulated outputs for common commands (preview mode) // In production, the agent executes commands via Claude SDK const simulatedOutputs: Record = { ls: 'app_spec.txt\nfeatures\nnode_modules\npackage.json\nsrc\ntests\ntsconfig.json', pwd: currentProject?.path || '/Users/demo/project', 'echo hello': 'hello', whoami: 'automaker-agent', date: new Date().toString(), 'cat package.json': '{\n "name": "demo-project",\n "version": "1.0.0"\n}', }; // Simulate command execution delay await new Promise((resolve) => setTimeout(resolve, 500)); const output = simulatedOutputs[terminalCommand.toLowerCase()] || `[Preview] ${terminalCommand}\n(Terminal commands are executed by the agent during feature implementation)`; setTerminalResult({ success: true, output: output, timestamp: new Date(), }); logger.info(`[Agent Tool] Command executed successfully: ${terminalCommand}`); } catch (error) { setTerminalResult({ success: false, error: error instanceof Error ? error.message : 'Unknown error', timestamp: new Date(), }); } finally { setIsRunningCommand(false); } }, [terminalCommand, currentProject]); if (!currentProject) { return (

No Project Selected

Open or create a project to test agent tools.

); } return (
{/* Header */}

Agent Tools

Test file system and terminal tools for {currentProject.name}

{/* Tools Grid */}
{/* Read File Tool */}
Read File
Agent requests to read a file from the filesystem
setReadFilePath(e.target.value)} data-testid="read-file-path-input" />
{/* Result */} {readFileResult && (
{readFileResult.success ? ( ) : ( )} {readFileResult.success ? 'Success' : 'Failed'}
                    {readFileResult.success ? readFileResult.output : readFileResult.error}
                  
)}
{/* Write File Tool */}
Write File
Agent requests to write content to a file
setWriteFilePath(e.target.value)} data-testid="write-file-path-input" />