@within-7/minto 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/agents/AgentsCommand.js +2342 -0
- package/dist/commands/agents/AgentsCommand.js.map +7 -0
- package/dist/commands/agents/constants.js +58 -0
- package/dist/commands/agents/constants.js.map +7 -0
- package/dist/commands/agents/index.js +37 -0
- package/dist/commands/agents/index.js.map +7 -0
- package/dist/commands/agents/types.js +10 -0
- package/dist/commands/agents/types.js.map +7 -0
- package/dist/commands/agents/utils/fileOperations.js +185 -0
- package/dist/commands/agents/utils/fileOperations.js.map +7 -0
- package/dist/commands/agents/utils/index.js +21 -0
- package/dist/commands/agents/utils/index.js.map +7 -0
- package/dist/commands/bug.js +2 -2
- package/dist/commands/bug.js.map +2 -2
- package/dist/commands/compact.js +5 -5
- package/dist/commands/compact.js.map +2 -2
- package/dist/commands/ctx_viz.js +55 -22
- package/dist/commands/ctx_viz.js.map +2 -2
- package/dist/commands/mcp-interactive.js +11 -11
- package/dist/commands/mcp-interactive.js.map +2 -2
- package/dist/commands/model.js +94 -32
- package/dist/commands/model.js.map +3 -3
- package/dist/commands/plugin/AddMarketplaceForm.js +49 -21
- package/dist/commands/plugin/AddMarketplaceForm.js.map +2 -2
- package/dist/commands/plugin/ConfirmDialog.js +38 -26
- package/dist/commands/plugin/ConfirmDialog.js.map +2 -2
- package/dist/commands/plugin/InstalledPluginsByMarketplace.js +24 -8
- package/dist/commands/plugin/InstalledPluginsByMarketplace.js.map +2 -2
- package/dist/commands/plugin/InstalledPluginsManager.js +3 -1
- package/dist/commands/plugin/InstalledPluginsManager.js.map +2 -2
- package/dist/commands/plugin/MainMenu.js +16 -7
- package/dist/commands/plugin/MainMenu.js.map +2 -2
- package/dist/commands/plugin/MarketplaceManager.js +84 -39
- package/dist/commands/plugin/MarketplaceManager.js.map +2 -2
- package/dist/commands/plugin/MarketplaceSelector.js +7 -3
- package/dist/commands/plugin/MarketplaceSelector.js.map +2 -2
- package/dist/commands/plugin/PlaceholderScreen.js +16 -2
- package/dist/commands/plugin/PlaceholderScreen.js.map +2 -2
- package/dist/commands/plugin/PluginBrowser.js +4 -2
- package/dist/commands/plugin/PluginBrowser.js.map +2 -2
- package/dist/commands/plugin/PluginDetailsInstall.js +12 -6
- package/dist/commands/plugin/PluginDetailsInstall.js.map +2 -2
- package/dist/commands/plugin/PluginDetailsManage.js +14 -5
- package/dist/commands/plugin/PluginDetailsManage.js.map +2 -2
- package/dist/commands/plugin/example-usage.js.map +2 -2
- package/dist/commands/plugin/utils.js.map +2 -2
- package/dist/commands/plugin.js +226 -46
- package/dist/commands/plugin.js.map +2 -2
- package/dist/commands/refreshCommands.js +6 -3
- package/dist/commands/refreshCommands.js.map +2 -2
- package/dist/commands/resume.js +2 -1
- package/dist/commands/resume.js.map +2 -2
- package/dist/commands/setup.js +19 -5
- package/dist/commands/setup.js.map +2 -2
- package/dist/commands/terminalSetup.js +2 -2
- package/dist/commands/terminalSetup.js.map +1 -1
- package/dist/commands.js +14 -30
- package/dist/commands.js.map +2 -2
- package/dist/components/AskUserQuestionDialog/AskUserQuestionDialog.js.map +2 -2
- package/dist/components/AskUserQuestionDialog/QuestionView.js +10 -1
- package/dist/components/AskUserQuestionDialog/QuestionView.js.map +2 -2
- package/dist/components/BackgroundTasksPanel.js +5 -1
- package/dist/components/BackgroundTasksPanel.js.map +2 -2
- package/dist/components/Config.js +17 -4
- package/dist/components/Config.js.map +2 -2
- package/dist/components/ConsoleOAuthFlow.js.map +2 -2
- package/dist/components/CustomSelect/select-option.js +4 -1
- package/dist/components/CustomSelect/select-option.js.map +2 -2
- package/dist/components/Help.js +6 -8
- package/dist/components/Help.js.map +2 -2
- package/dist/components/Logo.js +1 -1
- package/dist/components/Logo.js.map +2 -2
- package/dist/components/ModelListManager.js.map +2 -2
- package/dist/components/ModelSelector/ModelSelector.js +2030 -0
- package/dist/components/ModelSelector/ModelSelector.js.map +7 -0
- package/dist/components/ModelSelector/ScreenContainer.js +27 -0
- package/dist/components/ModelSelector/ScreenContainer.js.map +7 -0
- package/dist/components/ModelSelector/constants.js +37 -0
- package/dist/components/ModelSelector/constants.js.map +7 -0
- package/dist/components/ModelSelector/hooks/index.js +5 -0
- package/dist/components/ModelSelector/hooks/index.js.map +7 -0
- package/dist/components/ModelSelector/hooks/useEscapeNavigation.js +21 -0
- package/dist/components/ModelSelector/hooks/useEscapeNavigation.js.map +7 -0
- package/dist/components/ModelSelector/index.js +17 -0
- package/dist/components/ModelSelector/index.js.map +7 -0
- package/dist/components/ModelSelector/types.js +1 -0
- package/dist/components/ModelSelector/types.js.map +7 -0
- package/dist/components/PressEnterToContinue.js +1 -1
- package/dist/components/PressEnterToContinue.js.map +2 -2
- package/dist/components/ProjectOnboarding.js +1 -1
- package/dist/components/ProjectOnboarding.js.map +2 -2
- package/dist/components/PromptInput.js +88 -37
- package/dist/components/PromptInput.js.map +2 -2
- package/dist/components/QuitSummary.js +17 -10
- package/dist/components/QuitSummary.js.map +2 -2
- package/dist/components/SentryErrorBoundary.js.map +2 -2
- package/dist/components/StreamingBashOutput.js.map +2 -2
- package/dist/components/StructuredDiff.js.map +2 -2
- package/dist/components/SubagentProgress.js.map +2 -2
- package/dist/components/TaskCard.js.map +2 -2
- package/dist/components/TextInput.js.map +1 -1
- package/dist/components/TodoItem.js.map +1 -1
- package/dist/components/binary-feedback/BinaryFeedbackOption.js +1 -3
- package/dist/components/binary-feedback/BinaryFeedbackOption.js.map +2 -2
- package/dist/components/messages/AssistantLocalCommandOutputMessage.js.map +1 -1
- package/dist/components/messages/AssistantToolUseMessage.js +3 -1
- package/dist/components/messages/AssistantToolUseMessage.js.map +2 -2
- package/dist/components/messages/TaskProgressMessage.js.map +2 -2
- package/dist/components/messages/TaskToolMessage.js.map +2 -2
- package/dist/components/messages/UserToolResultMessage/utils.js.map +2 -2
- package/dist/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js.map +2 -2
- package/dist/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js.map +2 -2
- package/dist/components/permissions/hooks.js.map +2 -2
- package/dist/constants/modelCapabilities.js +1 -1
- package/dist/constants/modelCapabilities.js.map +2 -2
- package/dist/constants/prompts.js.map +1 -1
- package/dist/constants/timing.js +34 -0
- package/dist/constants/timing.js.map +7 -0
- package/dist/entrypoints/cli.js +128 -33
- package/dist/entrypoints/cli.js.map +3 -3
- package/dist/entrypoints/mcp.js +13 -18
- package/dist/entrypoints/mcp.js.map +2 -2
- package/dist/hooks/useCanUseTool.js.map +2 -2
- package/dist/hooks/useCancelRequest.js.map +1 -1
- package/dist/hooks/useHistorySearch.js.map +2 -2
- package/dist/hooks/useLogStartupTime.js.map +2 -2
- package/dist/hooks/usePermissionRequestLogging.js.map +2 -2
- package/dist/hooks/useTextInput.js.map +1 -1
- package/dist/hooks/useUnifiedCompletion.js +493 -394
- package/dist/hooks/useUnifiedCompletion.js.map +2 -2
- package/dist/index.js.map +2 -2
- package/dist/permissions.js +4 -7
- package/dist/permissions.js.map +2 -2
- package/dist/query.js +6 -1
- package/dist/query.js.map +2 -2
- package/dist/screens/REPL.js +72 -36
- package/dist/screens/REPL.js.map +2 -2
- package/dist/screens/ResumeConversation.js +2 -1
- package/dist/screens/ResumeConversation.js.map +2 -2
- package/dist/services/adapters/base.js.map +2 -2
- package/dist/services/adapters/chatCompletions.js.map +2 -2
- package/dist/services/adapters/responsesAPI.js +3 -1
- package/dist/services/adapters/responsesAPI.js.map +2 -2
- package/dist/services/claude.js +327 -328
- package/dist/services/claude.js.map +2 -2
- package/dist/services/customCommands.js +6 -1
- package/dist/services/customCommands.js.map +2 -2
- package/dist/services/fileFreshness.js.map +2 -2
- package/dist/services/gpt5ConnectionTest.js +20 -7
- package/dist/services/gpt5ConnectionTest.js.map +2 -2
- package/dist/services/hookExecutor.js +6 -12
- package/dist/services/hookExecutor.js.map +2 -2
- package/dist/services/mcpClient.js +29 -2
- package/dist/services/mcpClient.js.map +2 -2
- package/dist/services/mentionProcessor.js +23 -10
- package/dist/services/mentionProcessor.js.map +2 -2
- package/dist/services/modelAdapterFactory.js.map +2 -2
- package/dist/services/oauth.js.map +2 -2
- package/dist/services/openai.js +109 -72
- package/dist/services/openai.js.map +3 -3
- package/dist/services/responseStateManager.js.map +2 -2
- package/dist/services/systemReminder.js.map +2 -2
- package/dist/tools/ArchitectTool/ArchitectTool.js.map +1 -1
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js +14 -8
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js.map +2 -2
- package/dist/tools/BashOutputTool/BashOutputTool.js.map +2 -2
- package/dist/tools/BashTool/BashTool.js.map +2 -2
- package/dist/tools/FileReadTool/FileReadTool.js.map +1 -1
- package/dist/tools/FileWriteTool/FileWriteTool.js.map +2 -2
- package/dist/tools/GrepTool/GrepTool.js +1 -4
- package/dist/tools/GrepTool/GrepTool.js.map +2 -2
- package/dist/tools/MultiEditTool/MultiEditTool.js +4 -1
- package/dist/tools/MultiEditTool/MultiEditTool.js.map +2 -2
- package/dist/tools/NotebookReadTool/NotebookReadTool.js +3 -1
- package/dist/tools/NotebookReadTool/NotebookReadTool.js.map +2 -2
- package/dist/tools/SkillTool/SkillTool.js +12 -6
- package/dist/tools/SkillTool/SkillTool.js.map +2 -2
- package/dist/tools/TaskTool/TaskTool.js +14 -5
- package/dist/tools/TaskTool/TaskTool.js.map +2 -2
- package/dist/tools/TaskTool/prompt.js.map +2 -2
- package/dist/tools/ThinkTool/ThinkTool.js +6 -1
- package/dist/tools/ThinkTool/ThinkTool.js.map +2 -2
- package/dist/tools/TodoWriteTool/TodoWriteTool.js +23 -3
- package/dist/tools/TodoWriteTool/TodoWriteTool.js.map +2 -2
- package/dist/tools/URLFetcherTool/URLFetcherTool.js +2 -2
- package/dist/tools/URLFetcherTool/URLFetcherTool.js.map +2 -2
- package/dist/tools/URLFetcherTool/cache.js +6 -3
- package/dist/tools/URLFetcherTool/cache.js.map +2 -2
- package/dist/tools/URLFetcherTool/htmlToMarkdown.js +3 -1
- package/dist/tools/URLFetcherTool/htmlToMarkdown.js.map +2 -2
- package/dist/tools/WebSearchTool/WebSearchTool.js.map +2 -2
- package/dist/tools/WebSearchTool/prompt.js.map +2 -2
- package/dist/tools/WebSearchTool/searchProviders.js +15 -6
- package/dist/tools/WebSearchTool/searchProviders.js.map +2 -2
- package/dist/tools.js +4 -1
- package/dist/tools.js.map +2 -2
- package/dist/types/core.js +1 -0
- package/dist/types/core.js.map +7 -0
- package/dist/types/hooks.js +1 -4
- package/dist/types/hooks.js.map +2 -2
- package/dist/types/marketplace.js +8 -2
- package/dist/types/marketplace.js.map +2 -2
- package/dist/types/plugin.js +9 -6
- package/dist/types/plugin.js.map +2 -2
- package/dist/utils/BackgroundShellManager.js +76 -10
- package/dist/utils/BackgroundShellManager.js.map +2 -2
- package/dist/utils/PersistentShell.js +7 -2
- package/dist/utils/PersistentShell.js.map +2 -2
- package/dist/utils/advancedFuzzyMatcher.js +4 -1
- package/dist/utils/advancedFuzzyMatcher.js.map +2 -2
- package/dist/utils/agentLoader.js +69 -35
- package/dist/utils/agentLoader.js.map +2 -2
- package/dist/utils/agentStorage.js.map +2 -2
- package/dist/utils/async.js +163 -0
- package/dist/utils/async.js.map +7 -0
- package/dist/utils/autoUpdater.js +8 -2
- package/dist/utils/autoUpdater.js.map +2 -2
- package/dist/utils/commands.js +23 -11
- package/dist/utils/commands.js.map +2 -2
- package/dist/utils/commonUnixCommands.js +3 -1
- package/dist/utils/commonUnixCommands.js.map +2 -2
- package/dist/utils/compressionMode.js.map +2 -2
- package/dist/utils/config.js +30 -14
- package/dist/utils/config.js.map +2 -2
- package/dist/utils/debugLogger.js.map +2 -2
- package/dist/utils/env.js.map +2 -2
- package/dist/utils/envConfig.js +82 -0
- package/dist/utils/envConfig.js.map +7 -0
- package/dist/utils/errorHandling.js +89 -0
- package/dist/utils/errorHandling.js.map +7 -0
- package/dist/utils/expertChatStorage.js.map +2 -2
- package/dist/utils/fuzzyMatcher.js +13 -7
- package/dist/utils/fuzzyMatcher.js.map +2 -2
- package/dist/utils/hookManager.js +14 -4
- package/dist/utils/hookManager.js.map +2 -2
- package/dist/utils/log.js.map +2 -2
- package/dist/utils/marketplaceManager.js +44 -9
- package/dist/utils/marketplaceManager.js.map +2 -2
- package/dist/utils/messageContextManager.js.map +1 -1
- package/dist/utils/messages.js +6 -3
- package/dist/utils/messages.js.map +2 -2
- package/dist/utils/model.js +3 -1
- package/dist/utils/model.js.map +2 -2
- package/dist/utils/pluginInstaller.js +3 -15
- package/dist/utils/pluginInstaller.js.map +2 -2
- package/dist/utils/pluginLoader.js +41 -13
- package/dist/utils/pluginLoader.js.map +2 -2
- package/dist/utils/pluginRegistry.js.map +2 -2
- package/dist/utils/pluginValidator.js +71 -49
- package/dist/utils/pluginValidator.js.map +2 -2
- package/dist/utils/ptyCompat.js.map +2 -2
- package/dist/utils/roundConverter.js.map +2 -2
- package/dist/utils/secureFile.js +43 -14
- package/dist/utils/secureFile.js.map +2 -2
- package/dist/utils/sessionState.js.map +2 -2
- package/dist/utils/skillLoader.js.map +2 -2
- package/dist/utils/teamConfig.js +7 -4
- package/dist/utils/teamConfig.js.map +2 -2
- package/dist/utils/theme.js.map +2 -2
- package/dist/utils/thinking.js.map +2 -2
- package/dist/utils/unaryLogging.js.map +2 -2
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/AskExpertModelTool/AskExpertModelTool.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react'\nimport { Box, Text } from 'ink'\nimport { z } from 'zod'\nimport { Tool, ValidationResult } from '@tool'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { getModelManager } from '@utils/model'\nimport { getTheme } from '@utils/theme'\nimport {\n createUserMessage,\n createAssistantMessage,\n INTERRUPT_MESSAGE,\n} from '@utils/messages'\nimport { logError } from '@utils/log'\nimport {\n createExpertChatSession,\n loadExpertChatSession,\n getSessionMessages,\n addMessageToSession,\n} from '@utils/expertChatStorage'\nimport { queryLLM } from '@services/claude'\nimport { debug as debugLogger } from '@utils/debugLogger'\nimport { applyMarkdown } from '@utils/markdown'\n\nexport const inputSchema = z.strictObject({\n question: z.string().describe(\n 'COMPLETE SELF-CONTAINED QUESTION: Must include full background context, relevant details, and a clear independent question. The expert model will receive ONLY this content with no access to previous conversation or external context. Structure as: 1) Background/Context 2) Specific situation/problem 3) Clear question. Ensure the expert can fully understand and respond without needing additional information.'\n ),\n expert_model: z\n .string()\n .describe(\n 'The expert model to use (e.g., gpt-5, claude-3-5-sonnet-20241022)',\n ),\n chat_session_id: z\n .string()\n .describe(\n 'Chat session ID: use \"new\" for new session or existing session ID',\n ),\n})\n\ntype In = typeof inputSchema\nexport type Out = {\n chatSessionId: string\n expertModelName: string\n expertAnswer: string\n}\n\nexport const AskExpertModelTool = {\n name: 'AskExpertModel',\n async description() {\n return \"Consult external AI models for expert opinions and analysis\"\n },\n async prompt() {\n return `Ask a question to a specific external AI model for expert analysis.\n\nThis tool allows you to consult different AI models for their unique perspectives and expertise.\n\nCRITICAL REQUIREMENT FOR QUESTION PARAMETER:\nThe question MUST be completely self-contained and include:\n1. FULL BACKGROUND CONTEXT - All relevant information the expert needs\n2. SPECIFIC SITUATION - Clear description of the current scenario/problem\n3. INDEPENDENT QUESTION - What exactly you want the expert to analyze/answer\n\nThe expert model receives ONLY your question content with NO access to:\n- Previous conversation history (unless using existing session) \n- Current codebase or file context\n- User's current task or project details\n\nIMPORTANT: This tool is for asking questions to models, not for task execution.\n- Use when you need a specific model's opinion or analysis\n- Use when you want to compare different models' responses\n- Use the @ask-[model] format when available\n\nThe expert_model parameter accepts:\n- OpenAI: gpt-4, gpt-5, o1-preview\n- Anthropic: claude-3-5-sonnet, claude-3-opus \n- Others: kimi, gemini-pro, mixtral\n\nExample of well-structured question:\n\"Background: I'm working on a React TypeScript application with performance issues. The app renders a large list of 10,000 items using a simple map() function, causing UI freezing.\n\nCurrent situation: Users report 3-5 second delays when scrolling through the list. The component re-renders the entire list on every state change.\n\nQuestion: What are the most effective React optimization techniques for handling large lists, and how should I prioritize implementing virtualization vs memoization vs other approaches?\"`\n },\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true\n },\n inputSchema,\n userFacingName() {\n return 'AskExpertModel'\n },\n async isEnabled() {\n return true\n },\n needsPermissions(): boolean {\n return false\n },\n async validateInput({\n question,\n expert_model,\n chat_session_id,\n }, context?: any): Promise<ValidationResult> {\n if (!question.trim()) {\n return { result: false, message: 'Question cannot be empty' }\n }\n\n\n if (!expert_model.trim()) {\n return { result: false, message: 'Expert model must be specified' }\n }\n\n if (!chat_session_id.trim()) {\n return {\n result: false,\n message:\n 'Chat session ID must be specified (use \"new\" for new session)',\n }\n }\n\n // Check if trying to consult the same model we're currently running\n try {\n const modelManager = getModelManager()\n \n // Get current model based on context\n let currentModel: string\n if (context?.agentId && context?.options?.model) {\n // In subagent context (Task tool)\n currentModel = context.options.model\n } else {\n // In main agent context or after model switch\n currentModel = modelManager.getModelName('main') || ''\n }\n \n // Normalize model names for comparison\n const normalizedExpert = expert_model.toLowerCase().replace(/[^a-z0-9]/g, '')\n const normalizedCurrent = currentModel.toLowerCase().replace(/[^a-z0-9]/g, '')\n \n if (normalizedExpert === normalizedCurrent) {\n return {\n result: false,\n message: `You are already running as ${currentModel}. Consulting the same model would be redundant. Please choose a different model or handle the task directly.`\n }\n }\n } catch (e) {\n // If we can't determine current model, allow the request\n debugLogger.error('AskExpertModel', { message: 'Could not determine current model', error: e })\n }\n\n // Validate that the model exists and is available\n try {\n const modelManager = getModelManager()\n const modelResolution = modelManager.resolveModelWithInfo(expert_model)\n\n if (!modelResolution.success) {\n const availableModels = modelManager.getAllAvailableModelNames()\n if (availableModels.length > 0) {\n return {\n result: false,\n message: `Model '${expert_model}' is not configured. Available models: ${availableModels.join(', ')}. Check if any available model closely matches the user's request (e.g., 'kimi' matches 'kimi-k2-0711-preview'). If there's a strong match, auto retry using the correct model name. If no close match exists, inform the user that '${expert_model}' needs to be configured using /model command.`,\n }\n } else {\n return {\n result: false,\n message: `Model '${expert_model}' not found and no models are currently configured in the system. Inform the user that models need to be configured first using the /model command.`,\n }\n }\n }\n } catch (error) {\n console.error('Model validation error in AskExpertModelTool:', error)\n logError(error)\n return {\n result: false,\n message: `Failed to validate expert model '${expert_model}'. Please check your model configuration.`,\n }\n }\n\n return { result: true }\n },\n\n renderToolUseMessage(\n { question, expert_model, chat_session_id },\n { verbose },\n ) {\n if (!question || !expert_model) return null\n const isNewSession = chat_session_id === 'new'\n const sessionDisplay = isNewSession ? 'new session' : `session ${chat_session_id.substring(0, 5)}...`\n const theme = getTheme()\n\n if (verbose) {\n return (\n <Box flexDirection=\"column\">\n <Text bold color=\"yellow\">{expert_model}</Text>\n <Text color={theme.secondaryText}>{sessionDisplay}</Text>\n <Box marginTop={1}>\n <Text color={theme.text}>\n {question.length > 300 ? question.substring(0, 300) + '...' : question}\n </Text>\n </Box>\n </Box>\n )\n }\n return (\n <Box flexDirection=\"column\">\n <Text bold color=\"yellow\">{expert_model} </Text>\n <Text color={theme.secondaryText} dimColor>({sessionDisplay})</Text>\n </Box>\n )\n },\n\n renderToolResultMessage(content) {\n const verbose = true // Show more content\n const theme = getTheme()\n\n if (typeof content === 'object' && content && 'expertAnswer' in content) {\n const expertResult = content as Out\n const isError = expertResult.expertAnswer.startsWith('Error') || expertResult.expertAnswer.includes('failed')\n const isInterrupted = expertResult.chatSessionId === 'interrupted'\n\n if (isInterrupted) {\n return (\n <Box flexDirection=\"row\">\n <Text color={theme.secondaryText}>Consultation interrupted</Text>\n </Box>\n )\n }\n\n const answerText = verbose \n ? expertResult.expertAnswer.trim()\n : expertResult.expertAnswer.length > 500\n ? expertResult.expertAnswer.substring(0, 500) + '...'\n : expertResult.expertAnswer.trim()\n\n if (isError) {\n return (\n <Box flexDirection=\"column\">\n <Text color=\"red\">{answerText}</Text>\n </Box>\n )\n }\n\n return (\n <Box flexDirection=\"column\">\n <Text bold color={theme.text}>Response from {expertResult.expertModelName}:</Text>\n <Box marginTop={1}>\n <Text color={theme.text}>\n {applyMarkdown(answerText)}\n </Text>\n </Box>\n <Box marginTop={1}>\n <Text color={theme.secondaryText} dimColor>\n Session: {expertResult.chatSessionId.substring(0, 8)}\n </Text>\n </Box>\n </Box>\n )\n }\n\n return (\n <Box flexDirection=\"row\">\n <Text color={theme.secondaryText}>Consultation completed</Text>\n </Box>\n )\n },\n\n renderResultForAssistant(output: Out): string {\n return `[Expert consultation completed]\nExpert Model: ${output.expertModelName}\nSession ID: ${output.chatSessionId}\nTo continue this conversation with context preservation, use this Session ID in your next AskExpertModel call to maintain the full conversation history and context.\n\n${output.expertAnswer}`\n },\n\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n\n async *call(\n { question, expert_model, chat_session_id },\n { abortController, readFileTimestamps },\n ) {\n const expertModel = expert_model\n\n let sessionId: string\n let isInterrupted = false\n\n // Set up abort listener (following TaskTool pattern)\n const abortListener = () => {\n isInterrupted = true\n }\n abortController.signal.addEventListener('abort', abortListener)\n\n try {\n // Initial abort check\n if (abortController.signal.aborted) {\n return yield* this.handleInterrupt()\n }\n // Session management with error handling\n if (chat_session_id === 'new') {\n try {\n const session = createExpertChatSession(expertModel)\n sessionId = session.sessionId\n } catch (error) {\n console.error('Failed to create new expert chat session:', error)\n logError(error)\n throw new Error('Failed to create new chat session')\n }\n } else {\n sessionId = chat_session_id\n try {\n const session = loadExpertChatSession(sessionId)\n if (!session) {\n // Session doesn't exist, create new one\n const newSession = createExpertChatSession(expertModel)\n sessionId = newSession.sessionId\n }\n } catch (error) {\n console.error('Failed to load expert chat session:', error)\n logError(error)\n // Fallback: create new session\n try {\n const newSession = createExpertChatSession(expertModel)\n sessionId = newSession.sessionId\n } catch (createError) {\n console.error('Failed to create fallback expert chat session:', createError)\n logError(createError)\n throw new Error('Unable to create or load chat session')\n }\n }\n }\n\n // Check for cancellation before loading history\n if (isInterrupted || abortController.signal.aborted) {\n return yield* this.handleInterrupt()\n }\n\n // Load history and prepare messages with error handling\n let historyMessages: Array<{ role: string; content: string }>\n try {\n historyMessages = getSessionMessages(sessionId)\n } catch (error) {\n console.error('Failed to load session messages:', error)\n logError(error)\n historyMessages = [] // Fallback to empty history\n }\n\n const messages = [...historyMessages, { role: 'user', content: question }]\n\n let systemMessages\n try {\n systemMessages = messages.map(msg =>\n msg.role === 'user'\n ? createUserMessage(msg.content)\n : createAssistantMessage(msg.content),\n )\n } catch (error) {\n console.error('Failed to create system messages:', error)\n logError(error)\n throw new Error('Failed to prepare conversation messages')\n }\n\n // Check for cancellation before model call\n if (isInterrupted || abortController.signal.aborted) {\n return yield* this.handleInterrupt()\n }\n\n // Yield progress message to show we're connecting\n yield {\n type: 'progress',\n content: createAssistantMessage(\n `Connecting to ${expertModel}... (timeout: 5 minutes)`\n ),\n }\n\n // Call model with comprehensive error handling and timeout\n let response\n try {\n // Debug: Log the model we're trying to use (using global debug logger)\n const modelManager = getModelManager()\n const modelResolution = modelManager.resolveModelWithInfo(expertModel)\n\n debugLogger.api('EXPERT_MODEL_RESOLUTION', {\n requestedModel: expertModel,\n success: modelResolution.success,\n profileName: modelResolution.profile?.name,\n profileModelName: modelResolution.profile?.modelName,\n provider: modelResolution.profile?.provider,\n isActive: modelResolution.profile?.isActive,\n error: modelResolution.error,\n })\n\n // Create a timeout promise to prevent hanging\n const timeoutMs = 300000 // 300 seconds (5 minutes) timeout for external models\n const timeoutPromise = new Promise((_, reject) => {\n setTimeout(() => {\n reject(new Error(`Expert model query timed out after ${timeoutMs/1000}s`))\n }, timeoutMs)\n })\n\n // Race between the query and timeout\n response = await Promise.race([\n queryLLM(\n systemMessages,\n [], // no system prompt - let expert model use its default behavior\n 0, // no thinking tokens needed\n [], // no tools needed\n abortController.signal,\n {\n safeMode: false,\n model: expertModel,\n prependCLISysprompt: false, // KEY: avoid injecting CLI context\n },\n ),\n timeoutPromise\n ])\n } catch (error: any) {\n console.error('Expert model query failed:', error)\n logError(error)\n\n // Check for specific error types\n if (\n error.name === 'AbortError' ||\n abortController.signal?.aborted ||\n isInterrupted\n ) {\n return yield* this.handleInterrupt()\n }\n\n if (error.message?.includes('timed out')) {\n throw new Error(\n `Expert model '${expertModel}' timed out after 5 minutes.\\n\\n` +\n `Suggestions:\\n` +\n ` - The model might be experiencing high load\\n` +\n ` - Try a different model or retry later\\n` +\n ` - Consider breaking down your question into smaller parts`,\n )\n }\n\n if (error.message?.includes('rate limit')) {\n throw new Error(\n `Rate limit exceeded for ${expertModel}.\\n\\n` +\n `Please wait a moment and try again, or use a different model.`,\n )\n }\n\n if (error.message?.includes('invalid api key')) {\n throw new Error(\n `Invalid API key for ${expertModel}.\\n\\n` +\n `Please check your model configuration with /model command.`,\n )\n }\n\n if (\n error.message?.includes('model not found') ||\n error.message?.includes('Failed to resolve model')\n ) {\n // Provide helpful model guidance in runtime errors too\n try {\n const modelManager = getModelManager()\n const availableModels = modelManager.getAllAvailableModelNames()\n if (availableModels.length > 0) {\n throw new Error(\n `Model '${expertModel}' is not configured. Available models: ${availableModels.join(', ')}. Check if any available model closely matches the user's request (e.g., 'kimi' matches 'kimi-k2-0711-preview'). If there's a strong match, auto retry using the correct model name. If no close match exists, inform the user that '${expertModel}' needs to be configured using /model command.`,\n )\n } else {\n throw new Error(\n `Model '${expertModel}' not found and no models are currently configured in the system. Inform the user that models need to be configured first using the /model command.`,\n )\n }\n } catch (modelError) {\n // If we can't get model list, fall back to simple error\n throw new Error(\n `Model '${expertModel}' not found. Please check model configuration or inform user about the issue.`,\n )\n }\n }\n\n // Generic fallback\n throw new Error(\n `Expert model query failed: ${error.message || 'Unknown error'}`,\n )\n }\n\n // Extract answer with error handling\n let expertAnswer: string\n try {\n if (!response?.message?.content) {\n throw new Error('No content in expert response')\n }\n\n expertAnswer = response.message.content\n .filter(block => block.type === 'text')\n .map(block => (block as any).text)\n .join('\\n')\n\n if (!expertAnswer.trim()) {\n throw new Error('Expert response was empty')\n }\n } catch (error) {\n console.error('Failed to extract expert answer:', error)\n logError(error)\n throw new Error('Failed to process expert response')\n }\n\n // Save conversation with error handling\n try {\n addMessageToSession(sessionId, 'user', question)\n addMessageToSession(sessionId, 'assistant', expertAnswer)\n } catch (error) {\n console.error('Failed to save conversation to session:', error)\n logError(error)\n // Don't throw here - we got a valid response, saving is non-critical\n }\n\n const result: Out = {\n chatSessionId: sessionId,\n expertModelName: expertModel,\n expertAnswer: expertAnswer,\n }\n\n yield {\n type: 'result',\n data: result,\n resultForAssistant: this.renderResultForAssistant(result),\n }\n } catch (error: any) {\n // Check if error is due to cancellation\n if (\n error.name === 'AbortError' ||\n abortController.signal?.aborted ||\n isInterrupted\n ) {\n return yield* this.handleInterrupt()\n }\n\n console.error('AskExpertModelTool execution failed:', error)\n logError(error)\n\n // Ensure we have a valid sessionId for error response\n const errorSessionId = sessionId || 'error-session'\n\n const errorMessage =\n error.message || 'Expert consultation failed with unknown error'\n const result: Out = {\n chatSessionId: errorSessionId,\n expertModelName: expertModel,\n expertAnswer: `\u274C ${errorMessage}`,\n }\n\n yield {\n type: 'result',\n data: result,\n resultForAssistant: this.renderResultForAssistant(result),\n }\n } finally {\n // Clean up event listener\n abortController.signal.removeEventListener('abort', abortListener)\n }\n },\n\n // Unified interrupt handling method (following TaskTool pattern)\n async *handleInterrupt() {\n yield {\n type: 'result',\n data: {\n chatSessionId: 'interrupted',\n expertModelName: 'cancelled',\n expertAnswer: INTERRUPT_MESSAGE,\n },\n resultForAssistant: INTERRUPT_MESSAGE,\n }\n },\n}\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;AACvB,SAAS,KAAK,YAAY;AAC1B,SAAS,SAAS;AAElB,SAAS,sCAAsC;AAC/C,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,SAAS,mBAAmB;AACrC,SAAS,qBAAqB;AAEvB,MAAM,cAAc,EAAE,aAAa;AAAA,EACxC,UAAU,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react'\nimport { Box, Text } from 'ink'\nimport { z } from 'zod'\nimport { Tool, ValidationResult } from '@tool'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { getModelManager } from '@utils/model'\nimport { getTheme } from '@utils/theme'\nimport {\n createUserMessage,\n createAssistantMessage,\n INTERRUPT_MESSAGE,\n} from '@utils/messages'\nimport { logError } from '@utils/log'\nimport {\n createExpertChatSession,\n loadExpertChatSession,\n getSessionMessages,\n addMessageToSession,\n} from '@utils/expertChatStorage'\nimport { queryLLM } from '@services/claude'\nimport { debug as debugLogger } from '@utils/debugLogger'\nimport { applyMarkdown } from '@utils/markdown'\n\nexport const inputSchema = z.strictObject({\n question: z\n .string()\n .describe(\n 'COMPLETE SELF-CONTAINED QUESTION: Must include full background context, relevant details, and a clear independent question. The expert model will receive ONLY this content with no access to previous conversation or external context. Structure as: 1) Background/Context 2) Specific situation/problem 3) Clear question. Ensure the expert can fully understand and respond without needing additional information.',\n ),\n expert_model: z\n .string()\n .describe(\n 'The expert model to use (e.g., gpt-5, claude-3-5-sonnet-20241022)',\n ),\n chat_session_id: z\n .string()\n .describe(\n 'Chat session ID: use \"new\" for new session or existing session ID',\n ),\n})\n\ntype In = typeof inputSchema\nexport type Out = {\n chatSessionId: string\n expertModelName: string\n expertAnswer: string\n}\n\nexport const AskExpertModelTool = {\n name: 'AskExpertModel',\n async description() {\n return 'Consult external AI models for expert opinions and analysis'\n },\n async prompt() {\n return `Ask a question to a specific external AI model for expert analysis.\n\nThis tool allows you to consult different AI models for their unique perspectives and expertise.\n\nCRITICAL REQUIREMENT FOR QUESTION PARAMETER:\nThe question MUST be completely self-contained and include:\n1. FULL BACKGROUND CONTEXT - All relevant information the expert needs\n2. SPECIFIC SITUATION - Clear description of the current scenario/problem\n3. INDEPENDENT QUESTION - What exactly you want the expert to analyze/answer\n\nThe expert model receives ONLY your question content with NO access to:\n- Previous conversation history (unless using existing session) \n- Current codebase or file context\n- User's current task or project details\n\nIMPORTANT: This tool is for asking questions to models, not for task execution.\n- Use when you need a specific model's opinion or analysis\n- Use when you want to compare different models' responses\n- Use the @ask-[model] format when available\n\nThe expert_model parameter accepts:\n- OpenAI: gpt-4, gpt-5, o1-preview\n- Anthropic: claude-3-5-sonnet, claude-3-opus \n- Others: kimi, gemini-pro, mixtral\n\nExample of well-structured question:\n\"Background: I'm working on a React TypeScript application with performance issues. The app renders a large list of 10,000 items using a simple map() function, causing UI freezing.\n\nCurrent situation: Users report 3-5 second delays when scrolling through the list. The component re-renders the entire list on every state change.\n\nQuestion: What are the most effective React optimization techniques for handling large lists, and how should I prioritize implementing virtualization vs memoization vs other approaches?\"`\n },\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true\n },\n inputSchema,\n userFacingName() {\n return 'AskExpertModel'\n },\n async isEnabled() {\n return true\n },\n needsPermissions(): boolean {\n return false\n },\n async validateInput(\n { question, expert_model, chat_session_id },\n context?: any,\n ): Promise<ValidationResult> {\n if (!question.trim()) {\n return { result: false, message: 'Question cannot be empty' }\n }\n\n if (!expert_model.trim()) {\n return { result: false, message: 'Expert model must be specified' }\n }\n\n if (!chat_session_id.trim()) {\n return {\n result: false,\n message:\n 'Chat session ID must be specified (use \"new\" for new session)',\n }\n }\n\n // Check if trying to consult the same model we're currently running\n try {\n const modelManager = getModelManager()\n\n // Get current model based on context\n let currentModel: string\n if (context?.agentId && context?.options?.model) {\n // In subagent context (Task tool)\n currentModel = context.options.model\n } else {\n // In main agent context or after model switch\n currentModel = modelManager.getModelName('main') || ''\n }\n\n // Normalize model names for comparison\n const normalizedExpert = expert_model\n .toLowerCase()\n .replace(/[^a-z0-9]/g, '')\n const normalizedCurrent = currentModel\n .toLowerCase()\n .replace(/[^a-z0-9]/g, '')\n\n if (normalizedExpert === normalizedCurrent) {\n return {\n result: false,\n message: `You are already running as ${currentModel}. Consulting the same model would be redundant. Please choose a different model or handle the task directly.`,\n }\n }\n } catch (e) {\n // If we can't determine current model, allow the request\n debugLogger.error('AskExpertModel', {\n message: 'Could not determine current model',\n error: e,\n })\n }\n\n // Validate that the model exists and is available\n try {\n const modelManager = getModelManager()\n const modelResolution = modelManager.resolveModelWithInfo(expert_model)\n\n if (!modelResolution.success) {\n const availableModels = modelManager.getAllAvailableModelNames()\n if (availableModels.length > 0) {\n return {\n result: false,\n message: `Model '${expert_model}' is not configured. Available models: ${availableModels.join(', ')}. Check if any available model closely matches the user's request (e.g., 'kimi' matches 'kimi-k2-0711-preview'). If there's a strong match, auto retry using the correct model name. If no close match exists, inform the user that '${expert_model}' needs to be configured using /model command.`,\n }\n } else {\n return {\n result: false,\n message: `Model '${expert_model}' not found and no models are currently configured in the system. Inform the user that models need to be configured first using the /model command.`,\n }\n }\n }\n } catch (error) {\n console.error('Model validation error in AskExpertModelTool:', error)\n logError(error)\n return {\n result: false,\n message: `Failed to validate expert model '${expert_model}'. Please check your model configuration.`,\n }\n }\n\n return { result: true }\n },\n\n renderToolUseMessage(\n { question, expert_model, chat_session_id },\n { verbose },\n ) {\n if (!question || !expert_model) return null\n const isNewSession = chat_session_id === 'new'\n const sessionDisplay = isNewSession\n ? 'new session'\n : `session ${chat_session_id.substring(0, 5)}...`\n const theme = getTheme()\n\n if (verbose) {\n return (\n <Box flexDirection=\"column\">\n <Text bold color=\"yellow\">\n {expert_model}\n </Text>\n <Text color={theme.secondaryText}>{sessionDisplay}</Text>\n <Box marginTop={1}>\n <Text color={theme.text}>\n {question.length > 300\n ? question.substring(0, 300) + '...'\n : question}\n </Text>\n </Box>\n </Box>\n )\n }\n return (\n <Box flexDirection=\"column\">\n <Text bold color=\"yellow\">\n {expert_model}{' '}\n </Text>\n <Text color={theme.secondaryText} dimColor>\n ({sessionDisplay})\n </Text>\n </Box>\n )\n },\n\n renderToolResultMessage(content) {\n const verbose = true // Show more content\n const theme = getTheme()\n\n if (typeof content === 'object' && content && 'expertAnswer' in content) {\n const expertResult = content as Out\n const isError =\n expertResult.expertAnswer.startsWith('Error') ||\n expertResult.expertAnswer.includes('failed')\n const isInterrupted = expertResult.chatSessionId === 'interrupted'\n\n if (isInterrupted) {\n return (\n <Box flexDirection=\"row\">\n <Text color={theme.secondaryText}>Consultation interrupted</Text>\n </Box>\n )\n }\n\n const answerText = verbose\n ? expertResult.expertAnswer.trim()\n : expertResult.expertAnswer.length > 500\n ? expertResult.expertAnswer.substring(0, 500) + '...'\n : expertResult.expertAnswer.trim()\n\n if (isError) {\n return (\n <Box flexDirection=\"column\">\n <Text color=\"red\">{answerText}</Text>\n </Box>\n )\n }\n\n return (\n <Box flexDirection=\"column\">\n <Text bold color={theme.text}>\n Response from {expertResult.expertModelName}:\n </Text>\n <Box marginTop={1}>\n <Text color={theme.text}>{applyMarkdown(answerText)}</Text>\n </Box>\n <Box marginTop={1}>\n <Text color={theme.secondaryText} dimColor>\n Session: {expertResult.chatSessionId.substring(0, 8)}\n </Text>\n </Box>\n </Box>\n )\n }\n\n return (\n <Box flexDirection=\"row\">\n <Text color={theme.secondaryText}>Consultation completed</Text>\n </Box>\n )\n },\n\n renderResultForAssistant(output: Out): string {\n return `[Expert consultation completed]\nExpert Model: ${output.expertModelName}\nSession ID: ${output.chatSessionId}\nTo continue this conversation with context preservation, use this Session ID in your next AskExpertModel call to maintain the full conversation history and context.\n\n${output.expertAnswer}`\n },\n\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n\n async *call(\n { question, expert_model, chat_session_id },\n { abortController, readFileTimestamps },\n ) {\n const expertModel = expert_model\n\n let sessionId: string\n let isInterrupted = false\n\n // Set up abort listener (following TaskTool pattern)\n const abortListener = () => {\n isInterrupted = true\n }\n abortController.signal.addEventListener('abort', abortListener)\n\n try {\n // Initial abort check\n if (abortController.signal.aborted) {\n return yield* this.handleInterrupt()\n }\n // Session management with error handling\n if (chat_session_id === 'new') {\n try {\n const session = createExpertChatSession(expertModel)\n sessionId = session.sessionId\n } catch (error) {\n console.error('Failed to create new expert chat session:', error)\n logError(error)\n throw new Error('Failed to create new chat session')\n }\n } else {\n sessionId = chat_session_id\n try {\n const session = loadExpertChatSession(sessionId)\n if (!session) {\n // Session doesn't exist, create new one\n const newSession = createExpertChatSession(expertModel)\n sessionId = newSession.sessionId\n }\n } catch (error) {\n console.error('Failed to load expert chat session:', error)\n logError(error)\n // Fallback: create new session\n try {\n const newSession = createExpertChatSession(expertModel)\n sessionId = newSession.sessionId\n } catch (createError) {\n console.error(\n 'Failed to create fallback expert chat session:',\n createError,\n )\n logError(createError)\n throw new Error('Unable to create or load chat session')\n }\n }\n }\n\n // Check for cancellation before loading history\n if (isInterrupted || abortController.signal.aborted) {\n return yield* this.handleInterrupt()\n }\n\n // Load history and prepare messages with error handling\n let historyMessages: Array<{ role: string; content: string }>\n try {\n historyMessages = getSessionMessages(sessionId)\n } catch (error) {\n console.error('Failed to load session messages:', error)\n logError(error)\n historyMessages = [] // Fallback to empty history\n }\n\n const messages = [...historyMessages, { role: 'user', content: question }]\n\n let systemMessages\n try {\n systemMessages = messages.map(msg =>\n msg.role === 'user'\n ? createUserMessage(msg.content)\n : createAssistantMessage(msg.content),\n )\n } catch (error) {\n console.error('Failed to create system messages:', error)\n logError(error)\n throw new Error('Failed to prepare conversation messages')\n }\n\n // Check for cancellation before model call\n if (isInterrupted || abortController.signal.aborted) {\n return yield* this.handleInterrupt()\n }\n\n // Yield progress message to show we're connecting\n yield {\n type: 'progress',\n content: createAssistantMessage(\n `Connecting to ${expertModel}... (timeout: 5 minutes)`,\n ),\n }\n\n // Call model with comprehensive error handling and timeout\n let response\n try {\n // Debug: Log the model we're trying to use (using global debug logger)\n const modelManager = getModelManager()\n const modelResolution = modelManager.resolveModelWithInfo(expertModel)\n\n debugLogger.api('EXPERT_MODEL_RESOLUTION', {\n requestedModel: expertModel,\n success: modelResolution.success,\n profileName: modelResolution.profile?.name,\n profileModelName: modelResolution.profile?.modelName,\n provider: modelResolution.profile?.provider,\n isActive: modelResolution.profile?.isActive,\n error: modelResolution.error,\n })\n\n // Create a timeout promise to prevent hanging\n const timeoutMs = 300000 // 300 seconds (5 minutes) timeout for external models\n const timeoutPromise = new Promise((_, reject) => {\n setTimeout(() => {\n reject(\n new Error(\n `Expert model query timed out after ${timeoutMs / 1000}s`,\n ),\n )\n }, timeoutMs)\n })\n\n // Race between the query and timeout\n response = await Promise.race([\n queryLLM(\n systemMessages,\n [], // no system prompt - let expert model use its default behavior\n 0, // no thinking tokens needed\n [], // no tools needed\n abortController.signal,\n {\n safeMode: false,\n model: expertModel,\n prependCLISysprompt: false, // KEY: avoid injecting CLI context\n },\n ),\n timeoutPromise,\n ])\n } catch (error: any) {\n console.error('Expert model query failed:', error)\n logError(error)\n\n // Check for specific error types\n if (\n error.name === 'AbortError' ||\n abortController.signal?.aborted ||\n isInterrupted\n ) {\n return yield* this.handleInterrupt()\n }\n\n if (error.message?.includes('timed out')) {\n throw new Error(\n `Expert model '${expertModel}' timed out after 5 minutes.\\n\\n` +\n `Suggestions:\\n` +\n ` - The model might be experiencing high load\\n` +\n ` - Try a different model or retry later\\n` +\n ` - Consider breaking down your question into smaller parts`,\n )\n }\n\n if (error.message?.includes('rate limit')) {\n throw new Error(\n `Rate limit exceeded for ${expertModel}.\\n\\n` +\n `Please wait a moment and try again, or use a different model.`,\n )\n }\n\n if (error.message?.includes('invalid api key')) {\n throw new Error(\n `Invalid API key for ${expertModel}.\\n\\n` +\n `Please check your model configuration with /model command.`,\n )\n }\n\n if (\n error.message?.includes('model not found') ||\n error.message?.includes('Failed to resolve model')\n ) {\n // Provide helpful model guidance in runtime errors too\n try {\n const modelManager = getModelManager()\n const availableModels = modelManager.getAllAvailableModelNames()\n if (availableModels.length > 0) {\n throw new Error(\n `Model '${expertModel}' is not configured. Available models: ${availableModels.join(', ')}. Check if any available model closely matches the user's request (e.g., 'kimi' matches 'kimi-k2-0711-preview'). If there's a strong match, auto retry using the correct model name. If no close match exists, inform the user that '${expertModel}' needs to be configured using /model command.`,\n )\n } else {\n throw new Error(\n `Model '${expertModel}' not found and no models are currently configured in the system. Inform the user that models need to be configured first using the /model command.`,\n )\n }\n } catch (modelError) {\n // If we can't get model list, fall back to simple error\n throw new Error(\n `Model '${expertModel}' not found. Please check model configuration or inform user about the issue.`,\n )\n }\n }\n\n // Generic fallback\n throw new Error(\n `Expert model query failed: ${error.message || 'Unknown error'}`,\n )\n }\n\n // Extract answer with error handling\n let expertAnswer: string\n try {\n if (!response?.message?.content) {\n throw new Error('No content in expert response')\n }\n\n expertAnswer = response.message.content\n .filter(block => block.type === 'text')\n .map(block => (block as any).text)\n .join('\\n')\n\n if (!expertAnswer.trim()) {\n throw new Error('Expert response was empty')\n }\n } catch (error) {\n console.error('Failed to extract expert answer:', error)\n logError(error)\n throw new Error('Failed to process expert response')\n }\n\n // Save conversation with error handling\n try {\n addMessageToSession(sessionId, 'user', question)\n addMessageToSession(sessionId, 'assistant', expertAnswer)\n } catch (error) {\n console.error('Failed to save conversation to session:', error)\n logError(error)\n // Don't throw here - we got a valid response, saving is non-critical\n }\n\n const result: Out = {\n chatSessionId: sessionId,\n expertModelName: expertModel,\n expertAnswer: expertAnswer,\n }\n\n yield {\n type: 'result',\n data: result,\n resultForAssistant: this.renderResultForAssistant(result),\n }\n } catch (error: any) {\n // Check if error is due to cancellation\n if (\n error.name === 'AbortError' ||\n abortController.signal?.aborted ||\n isInterrupted\n ) {\n return yield* this.handleInterrupt()\n }\n\n console.error('AskExpertModelTool execution failed:', error)\n logError(error)\n\n // Ensure we have a valid sessionId for error response\n const errorSessionId = sessionId || 'error-session'\n\n const errorMessage =\n error.message || 'Expert consultation failed with unknown error'\n const result: Out = {\n chatSessionId: errorSessionId,\n expertModelName: expertModel,\n expertAnswer: `\u274C ${errorMessage}`,\n }\n\n yield {\n type: 'result',\n data: result,\n resultForAssistant: this.renderResultForAssistant(result),\n }\n } finally {\n // Clean up event listener\n abortController.signal.removeEventListener('abort', abortListener)\n }\n },\n\n // Unified interrupt handling method (following TaskTool pattern)\n async *handleInterrupt() {\n yield {\n type: 'result',\n data: {\n chatSessionId: 'interrupted',\n expertModelName: 'cancelled',\n expertAnswer: INTERRUPT_MESSAGE,\n },\n resultForAssistant: INTERRUPT_MESSAGE,\n }\n },\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AACvB,SAAS,KAAK,YAAY;AAC1B,SAAS,SAAS;AAElB,SAAS,sCAAsC;AAC/C,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,SAAS,mBAAmB;AACrC,SAAS,qBAAqB;AAEvB,MAAM,cAAc,EAAE,aAAa;AAAA,EACxC,UAAU,EACP,OAAO,EACP;AAAA,IACC;AAAA,EACF;AAAA,EACF,cAAc,EACX,OAAO,EACP;AAAA,IACC;AAAA,EACF;AAAA,EACF,iBAAiB,EACd,OAAO,EACP;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AASM,MAAM,qBAAqB;AAAA,EAChC,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,SAAS;AACb,WAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA+BT;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,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MACJ,MAAM;AAAA,MACN,MAAM;AAAA,QACJ,eAAe;AAAA,QACf,iBAAiB;AAAA,QACjB,cAAc;AAAA,MAChB;AAAA,MACA,oBAAoB;AAAA,IACtB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/BashOutputTool/BashOutputTool.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport { BackgroundShellManager } from '@utils/BackgroundShellManager'\nimport { BashOutputToolResultMessage } from './BashOutputToolResultMessage'\nimport { PROMPT } from './prompt'\n\nexport const inputSchema = z.strictObject({\n bash_id: z.string().describe('The ID of the background shell to retrieve output from'),\n filter: z\n .string()\n .optional()\n .describe(\n 'Optional regular expression to filter the output lines. Only lines matching this regex will be included in the result.',\n ),\n})\n\ntype In = typeof inputSchema\nexport type Out = {\n stdout: string\n stderr: string\n status: string\n hasMore: boolean\n}\n\nexport const BashOutputTool = {\n name: 'BashOutput',\n async description() {\n return 'Retrieves output from a running or completed background bash shell'\n },\n async prompt() {\n return PROMPT\n },\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true\n },\n inputSchema,\n userFacingName() {\n return 'BashOutput'\n },\n async isEnabled() {\n return true\n },\n needsPermissions(): boolean {\n return false // Reading output doesn't require permissions\n },\n renderToolUseMessage({ bash_id, filter }) {\n return filter ? `${bash_id} (filter: ${filter})` : bash_id\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(content) {\n return <BashOutputToolResultMessage content={content} />\n },\n renderResultForAssistant({ stdout, stderr, status, hasMore }) {\n const parts: string[] = []\n\n if (status) {\n parts.push(`Status: ${status}`)\n }\n\n if (stdout) {\n parts.push(`Stdout:\\n${stdout}`)\n }\n\n if (stderr) {\n parts.push(`Stderr:\\n${stderr}`)\n }\n\n if (hasMore) {\n parts.push('(More output may be available - output is truncated)')\n }\n\n if (parts.length === 0) {\n return 'No new output available'\n }\n\n return parts.join('\\n\\n')\n },\n async *call({ bash_id, filter }, { abortController }) {\n const manager = BackgroundShellManager.getInstance()\n const shell = manager.get(bash_id)\n\n if (!shell) {\n const data: Out = {\n stdout: '',\n stderr: `Error: Background shell '${bash_id}' not found`,\n status: 'not_found',\n hasMore: false,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n return\n }\n\n // Get new output since last read\n const output = manager.getNewOutput(bash_id, filter)\n\n if (!output) {\n const data: Out = {\n stdout: '',\n stderr: `Error: Could not retrieve output for shell '${bash_id}'`,\n status: shell.status,\n hasMore: false,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n return\n }\n\n const MAX_LINES = 100\n const stdout = output.stdout.slice(0, MAX_LINES).join('\\n')\n const stderr = output.stderr.slice(0, MAX_LINES).join('\\n')\n const hasMore =\n output.stdout.length > MAX_LINES || output.stderr.length > MAX_LINES\n\n const data: Out = {\n stdout,\n stderr,\n status: shell.status,\n hasMore,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n },\n} satisfies Tool<In, Out>\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAE/C,SAAS,8BAA8B;AACvC,SAAS,mCAAmC;AAC5C,SAAS,cAAc;AAEhB,MAAM,cAAc,EAAE,aAAa;AAAA,EACxC,SAAS,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport { BackgroundShellManager } from '@utils/BackgroundShellManager'\nimport { BashOutputToolResultMessage } from './BashOutputToolResultMessage'\nimport { PROMPT } from './prompt'\n\nexport const inputSchema = z.strictObject({\n bash_id: z\n .string()\n .describe('The ID of the background shell to retrieve output from'),\n filter: z\n .string()\n .optional()\n .describe(\n 'Optional regular expression to filter the output lines. Only lines matching this regex will be included in the result.',\n ),\n})\n\ntype In = typeof inputSchema\nexport type Out = {\n stdout: string\n stderr: string\n status: string\n hasMore: boolean\n}\n\nexport const BashOutputTool = {\n name: 'BashOutput',\n async description() {\n return 'Retrieves output from a running or completed background bash shell'\n },\n async prompt() {\n return PROMPT\n },\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true\n },\n inputSchema,\n userFacingName() {\n return 'BashOutput'\n },\n async isEnabled() {\n return true\n },\n needsPermissions(): boolean {\n return false // Reading output doesn't require permissions\n },\n renderToolUseMessage({ bash_id, filter }) {\n return filter ? `${bash_id} (filter: ${filter})` : bash_id\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(content) {\n return <BashOutputToolResultMessage content={content} />\n },\n renderResultForAssistant({ stdout, stderr, status, hasMore }) {\n const parts: string[] = []\n\n if (status) {\n parts.push(`Status: ${status}`)\n }\n\n if (stdout) {\n parts.push(`Stdout:\\n${stdout}`)\n }\n\n if (stderr) {\n parts.push(`Stderr:\\n${stderr}`)\n }\n\n if (hasMore) {\n parts.push('(More output may be available - output is truncated)')\n }\n\n if (parts.length === 0) {\n return 'No new output available'\n }\n\n return parts.join('\\n\\n')\n },\n async *call({ bash_id, filter }, { abortController }) {\n const manager = BackgroundShellManager.getInstance()\n const shell = manager.get(bash_id)\n\n if (!shell) {\n const data: Out = {\n stdout: '',\n stderr: `Error: Background shell '${bash_id}' not found`,\n status: 'not_found',\n hasMore: false,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n return\n }\n\n // Get new output since last read\n const output = manager.getNewOutput(bash_id, filter)\n\n if (!output) {\n const data: Out = {\n stdout: '',\n stderr: `Error: Could not retrieve output for shell '${bash_id}'`,\n status: shell.status,\n hasMore: false,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n return\n }\n\n const MAX_LINES = 100\n const stdout = output.stdout.slice(0, MAX_LINES).join('\\n')\n const stderr = output.stderr.slice(0, MAX_LINES).join('\\n')\n const hasMore =\n output.stdout.length > MAX_LINES || output.stderr.length > MAX_LINES\n\n const data: Out = {\n stdout,\n stderr,\n status: shell.status,\n hasMore,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n },\n} satisfies Tool<In, Out>\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAE/C,SAAS,8BAA8B;AACvC,SAAS,mCAAmC;AAC5C,SAAS,cAAc;AAEhB,MAAM,cAAc,EAAE,aAAa;AAAA,EACxC,SAAS,EACN,OAAO,EACP,SAAS,wDAAwD;AAAA,EACpE,QAAQ,EACL,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAUM,MAAM,iBAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,SAAS;AACb,WAAO;AAAA,EACT;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB;AAClB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,iBAAiB;AACf,WAAO;AAAA,EACT;AAAA,EACA,MAAM,YAAY;AAChB,WAAO;AAAA,EACT;AAAA,EACA,mBAA4B;AAC1B,WAAO;AAAA,EACT;AAAA,EACA,qBAAqB,EAAE,SAAS,OAAO,GAAG;AACxC,WAAO,SAAS,GAAG,OAAO,aAAa,MAAM,MAAM;AAAA,EACrD;AAAA,EACA,+BAA+B;AAC7B,WAAO,oCAAC,oCAA+B;AAAA,EACzC;AAAA,EACA,wBAAwB,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AClB,UAAM,SAAS,OAAO,OAAO,MAAM,GAAG,SAAS,EAAE,KAAK,IAAI;AAC1D,UAAM,SAAS,OAAO,OAAO,MAAM,GAAG,SAAS,EAAE,KAAK,IAAI;AAC1D,UAAM,UACJ,OAAO,OAAO,SAAS,aAAa,OAAO,OAAO,SAAS;AAE7D,UAAM,OAAY;AAAA,MAChB;AAAA,MACA;AAAA,MACA,QAAQ,MAAM;AAAA,MACd;AAAA,IACF;AAEA,UAAM;AAAA,MACJ,MAAM;AAAA,MACN,oBAAoB,KAAK,yBAAyB,IAAI;AAAA,MACtD;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["data"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/BashTool/BashTool.tsx"],
|
|
4
|
-
"sourcesContent": ["import { statSync } from 'fs'\nimport { EOL } from 'os'\nimport { isAbsolute, relative, resolve } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { PRODUCT_NAME } from '@constants/product'\nimport { queryQuick } from '@services/claude'\nimport { Tool, ValidationResult } from '@tool'\nimport { splitCommand } from '@utils/commands'\nimport { isInDirectory } from '@utils/file'\nimport { logError } from '@utils/log'\nimport { PersistentShell } from '@utils/PersistentShell'\nimport { getCwd, getOriginalCwd } from '@utils/state'\nimport { getGlobalConfig } from '@utils/config'\nimport { getModelManager } from '@utils/model'\nimport { BackgroundShellManager } from '@utils/BackgroundShellManager'\nimport BashToolResultMessage from './BashToolResultMessage'\nimport { BANNED_COMMANDS, PROMPT } from './prompt'\nimport { formatOutput, getCommandFilePaths } from './utils'\n\nexport const inputSchema = z.strictObject({\n command: z.string().describe('The command to execute'),\n timeout: z\n .number()\n .optional()\n .describe('Optional timeout in milliseconds (max 600000)'),\n run_in_background: z\n .boolean()\n .optional()\n .describe('Set to true to run this command in the background'),\n})\n\ntype In = typeof inputSchema\nexport type Out = {\n stdout: string\n stdoutLines: number // Total number of lines in original stdout, even if `stdout` is now truncated\n stderr: string\n stderrLines: number // Total number of lines in original stderr, even if `stderr` is now truncated\n interrupted: boolean\n shellId?: string // Present if run_in_background is true\n}\n\nexport const BashTool = {\n name: 'Bash',\n async description() {\n return 'Executes shell commands on your computer'\n },\n async prompt() {\n const config = getGlobalConfig()\n // \uD83D\uDD27 Fix: Use ModelManager to get actual current model\n const modelManager = getModelManager()\n const modelName =\n modelManager.getModelName('main') || '<No Model Configured>'\n // Substitute the placeholder in the static PROMPT string\n return PROMPT.replace(/{MODEL_NAME}/g, modelName)\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // BashTool modifies state/files, not safe for concurrent execution\n },\n inputSchema,\n userFacingName() {\n return 'Bash'\n },\n async isEnabled() {\n return true\n },\n needsPermissions(): boolean {\n // Always check per-project permissions for BashTool\n return true\n },\n async validateInput({ command }): Promise<ValidationResult> {\n const commands = splitCommand(command)\n for (const cmd of commands) {\n const parts = cmd.split(' ')\n const baseCmd = parts[0]\n\n // Check if command is banned\n if (baseCmd && BANNED_COMMANDS.includes(baseCmd.toLowerCase())) {\n return {\n result: false,\n message: `Command '${baseCmd}' is not allowed for security reasons`,\n }\n }\n\n // Special handling for cd command\n if (baseCmd === 'cd' && parts[1]) {\n const targetDir = parts[1]!.replace(/^['\"]|['\"]$/g, '') // Remove quotes if present\n const fullTargetDir = isAbsolute(targetDir)\n ? targetDir\n : resolve(getCwd(), targetDir)\n if (\n !isInDirectory(\n relative(getOriginalCwd(), fullTargetDir),\n relative(getCwd(), getOriginalCwd()),\n )\n ) {\n return {\n result: false,\n message: `ERROR: cd to '${fullTargetDir}' was blocked. For security, ${PRODUCT_NAME} may only change directories to child directories of the original working directory (${getOriginalCwd()}) for this session.`,\n }\n }\n }\n }\n\n return { result: true }\n },\n renderToolUseMessage({ command }) {\n // Clean up any command that uses the quoted HEREDOC pattern\n if (command.includes(\"\\\"$(cat <<'EOF'\")) {\n const match = command.match(\n /^(.*?)\"?\\$\\(cat <<'EOF'\\n([\\s\\S]*?)\\n\\s*EOF\\n\\s*\\)\"(.*)$/,\n )\n if (match && match[1] && match[2]) {\n const prefix = match[1]\n const content = match[2]\n const suffix = match[3] || ''\n return `${prefix.trim()} \"${content.trim()}\"${suffix.trim()}`\n }\n }\n return command\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n\n renderToolResultMessage(content) {\n return <BashToolResultMessage content={content} verbose={false} />\n },\n renderResultForAssistant({ interrupted, stdout, stderr }) {\n let errorMessage = stderr.trim()\n if (interrupted) {\n if (stderr) errorMessage += EOL\n errorMessage += '<error>Command was aborted before completion</error>'\n }\n const hasBoth = stdout.trim() && errorMessage\n return `${stdout.trim()}${hasBoth ? '\\n' : ''}${errorMessage.trim()}`\n },\n async *call(\n { command, timeout = 120000, run_in_background = false },\n { abortController, readFileTimestamps },\n ) {\n // Handle background execution\n if (run_in_background) {\n const shellId = BackgroundShellManager.getInstance().create(\n command,\n getCwd(),\n )\n\n const data: Out = {\n stdout: `Background shell started with ID: ${shellId}`,\n stdoutLines: 1,\n stderr: '',\n stderrLines: 0,\n interrupted: false,\n shellId,\n }\n\n yield {\n type: 'result',\n resultForAssistant: `Started background shell: ${shellId}\\nCommand: ${command}`,\n data,\n }\n return\n }\n\n let stdout = ''\n let stderr = ''\n\n // \uD83D\uDD27 Check if already cancelled before starting execution\n if (abortController.signal.aborted) {\n const data: Out = {\n stdout: '',\n stdoutLines: 0,\n stderr: 'Command cancelled before execution',\n stderrLines: 1,\n interrupted: true,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n return\n }\n\n try {\n // Execute commands\n const result = await PersistentShell.getInstance().exec(\n command,\n abortController.signal,\n timeout,\n )\n stdout += (result.stdout || '').trim() + EOL\n stderr += (result.stderr || '').trim() + EOL\n if (result.code !== 0) {\n stderr += `Exit code ${result.code}`\n }\n\n if (!isInDirectory(getCwd(), getOriginalCwd())) {\n // Shell directory is outside original working directory, reset it\n await PersistentShell.getInstance().setCwd(getOriginalCwd())\n stderr = `${stderr.trim()}${EOL}Shell cwd was reset to ${getOriginalCwd()}`\n
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAW;AACpB,SAAS,YAAY,UAAU,eAAe;AAC9C,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAC/C,SAAS,oBAAoB;AAG7B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,QAAQ,sBAAsB;AACvC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AACvC,OAAO,2BAA2B;AAClC,SAAS,iBAAiB,cAAc;AACxC,SAAS,cAAc,2BAA2B;AAE3C,MAAM,cAAc,EAAE,aAAa;AAAA,EACxC,SAAS,EAAE,OAAO,EAAE,SAAS,wBAAwB;AAAA,EACrD,SAAS,EACN,OAAO,EACP,SAAS,EACT,SAAS,+CAA+C;AAAA,EAC3D,mBAAmB,EAChB,QAAQ,EACR,SAAS,EACT,SAAS,mDAAmD;AACjE,CAAC;AAYM,MAAM,WAAW;AAAA,EACtB,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,SAAS;AACb,UAAM,SAAS,gBAAgB;AAE/B,UAAM,eAAe,gBAAgB;AACrC,UAAM,YACJ,aAAa,aAAa,MAAM,KAAK;AAEvC,WAAO,OAAO,QAAQ,iBAAiB,SAAS;AAAA,EAClD;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB;AAClB,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,iBAAiB;AACf,WAAO;AAAA,EACT;AAAA,EACA,MAAM,YAAY;AAChB,WAAO;AAAA,EACT;A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,EAAE;AAAA,QACjD;AAAA,QACA,gBAAgB;AAAA,QAChB;AAAA,MACF;AACA,iBAAW,OAAO,UAAU,IAAI,KAAK,IAAI;AACzC,iBAAW,OAAO,UAAU,IAAI,KAAK,IAAI;AACzC,UAAI,OAAO,SAAS,GAAG;AACrB,kBAAU,aAAa,OAAO,IAAI;AAAA,MACpC;AAEA,UAAI,CAAC,cAAc,OAAO,GAAG,eAAe,CAAC,GAAG;AAE9C,cAAM,gBAAgB,YAAY,EAAE,OAAO,eAAe,CAAC;AAC3D,iBAAS,GAAG,OAAO,KAAK,CAAC,GAAG,GAAG,0BAA0B,eAAe,CAAC;AAAA,
|
|
4
|
+
"sourcesContent": ["import { statSync } from 'fs'\nimport { EOL } from 'os'\nimport { isAbsolute, relative, resolve } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { PRODUCT_NAME } from '@constants/product'\nimport { queryQuick } from '@services/claude'\nimport { Tool, ValidationResult } from '@tool'\nimport { splitCommand } from '@utils/commands'\nimport { isInDirectory } from '@utils/file'\nimport { logError } from '@utils/log'\nimport { PersistentShell } from '@utils/PersistentShell'\nimport { getCwd, getOriginalCwd } from '@utils/state'\nimport { getGlobalConfig } from '@utils/config'\nimport { getModelManager } from '@utils/model'\nimport { BackgroundShellManager } from '@utils/BackgroundShellManager'\nimport BashToolResultMessage from './BashToolResultMessage'\nimport { BANNED_COMMANDS, PROMPT } from './prompt'\nimport { formatOutput, getCommandFilePaths } from './utils'\n\nexport const inputSchema = z.strictObject({\n command: z.string().describe('The command to execute'),\n timeout: z\n .number()\n .optional()\n .describe('Optional timeout in milliseconds (max 600000)'),\n run_in_background: z\n .boolean()\n .optional()\n .describe('Set to true to run this command in the background'),\n})\n\ntype In = typeof inputSchema\nexport type Out = {\n stdout: string\n stdoutLines: number // Total number of lines in original stdout, even if `stdout` is now truncated\n stderr: string\n stderrLines: number // Total number of lines in original stderr, even if `stderr` is now truncated\n interrupted: boolean\n shellId?: string // Present if run_in_background is true\n}\n\nexport const BashTool = {\n name: 'Bash',\n async description() {\n return 'Executes shell commands on your computer'\n },\n async prompt() {\n const config = getGlobalConfig()\n // \uD83D\uDD27 Fix: Use ModelManager to get actual current model\n const modelManager = getModelManager()\n const modelName =\n modelManager.getModelName('main') || '<No Model Configured>'\n // Substitute the placeholder in the static PROMPT string\n return PROMPT.replace(/{MODEL_NAME}/g, modelName)\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // BashTool modifies state/files, not safe for concurrent execution\n },\n inputSchema,\n userFacingName() {\n return 'Bash'\n },\n async isEnabled() {\n return true\n },\n needsPermissions(): boolean {\n // Always check per-project permissions for BashTool\n return true\n },\n async validateInput({ command }): Promise<ValidationResult> {\n const commands = splitCommand(command)\n for (const cmd of commands) {\n const parts = cmd.split(' ')\n const baseCmd = parts[0]\n\n // Check if command is banned\n if (baseCmd && BANNED_COMMANDS.includes(baseCmd.toLowerCase())) {\n return {\n result: false,\n message: `Command '${baseCmd}' is not allowed for security reasons`,\n }\n }\n\n // Special handling for cd command\n if (baseCmd === 'cd' && parts[1]) {\n const targetDir = parts[1]!.replace(/^['\"]|['\"]$/g, '') // Remove quotes if present\n const fullTargetDir = isAbsolute(targetDir)\n ? targetDir\n : resolve(getCwd(), targetDir)\n if (\n !isInDirectory(\n relative(getOriginalCwd(), fullTargetDir),\n relative(getCwd(), getOriginalCwd()),\n )\n ) {\n return {\n result: false,\n message: `ERROR: cd to '${fullTargetDir}' was blocked. For security, ${PRODUCT_NAME} may only change directories to child directories of the original working directory (${getOriginalCwd()}) for this session.`,\n }\n }\n }\n }\n\n return { result: true }\n },\n renderToolUseMessage({ command }) {\n // Clean up any command that uses the quoted HEREDOC pattern\n if (command.includes(\"\\\"$(cat <<'EOF'\")) {\n const match = command.match(\n /^(.*?)\"?\\$\\(cat <<'EOF'\\n([\\s\\S]*?)\\n\\s*EOF\\n\\s*\\)\"(.*)$/,\n )\n if (match && match[1] && match[2]) {\n const prefix = match[1]\n const content = match[2]\n const suffix = match[3] || ''\n return `${prefix.trim()} \"${content.trim()}\"${suffix.trim()}`\n }\n }\n return command\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n\n renderToolResultMessage(content) {\n return <BashToolResultMessage content={content} verbose={false} />\n },\n renderResultForAssistant({ interrupted, stdout, stderr }) {\n let errorMessage = stderr.trim()\n if (interrupted) {\n if (stderr) errorMessage += EOL\n errorMessage += '<error>Command was aborted before completion</error>'\n }\n const hasBoth = stdout.trim() && errorMessage\n return `${stdout.trim()}${hasBoth ? '\\n' : ''}${errorMessage.trim()}`\n },\n async *call(\n { command, timeout = 120000, run_in_background = false },\n { abortController, readFileTimestamps },\n ) {\n // Handle background execution\n if (run_in_background) {\n const shellId = BackgroundShellManager.getInstance().create(\n command,\n getCwd(),\n )\n\n const data: Out = {\n stdout: `Background shell started with ID: ${shellId}`,\n stdoutLines: 1,\n stderr: '',\n stderrLines: 0,\n interrupted: false,\n shellId,\n }\n\n yield {\n type: 'result',\n resultForAssistant: `Started background shell: ${shellId}\\nCommand: ${command}`,\n data,\n }\n return\n }\n\n let stdout = ''\n let stderr = ''\n\n // \uD83D\uDD27 Check if already cancelled before starting execution\n if (abortController.signal.aborted) {\n const data: Out = {\n stdout: '',\n stdoutLines: 0,\n stderr: 'Command cancelled before execution',\n stderrLines: 1,\n interrupted: true,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n return\n }\n\n try {\n // Execute commands\n const result = await PersistentShell.getInstance().exec(\n command,\n abortController.signal,\n timeout,\n )\n stdout += (result.stdout || '').trim() + EOL\n stderr += (result.stderr || '').trim() + EOL\n if (result.code !== 0) {\n stderr += `Exit code ${result.code}`\n }\n\n if (!isInDirectory(getCwd(), getOriginalCwd())) {\n // Shell directory is outside original working directory, reset it\n await PersistentShell.getInstance().setCwd(getOriginalCwd())\n stderr = `${stderr.trim()}${EOL}Shell cwd was reset to ${getOriginalCwd()}`\n }\n\n // Update read timestamps for any files referenced by the command\n // Don't block the main thread!\n // Skip this in tests because it makes fixtures non-deterministic (they might not always get written),\n // so will be missing in CI.\n if (process.env.NODE_ENV !== 'test') {\n getCommandFilePaths(command, stdout).then(filePaths => {\n for (const filePath of filePaths) {\n const fullFilePath = isAbsolute(filePath)\n ? filePath\n : resolve(getCwd(), filePath)\n\n // Try/catch in case the file doesn't exist (because Haiku didn't properly extract it)\n try {\n readFileTimestamps[fullFilePath] = statSync(fullFilePath).mtimeMs\n } catch (e) {\n logError(e)\n }\n }\n })\n }\n\n const { totalLines: stdoutLines, truncatedContent: stdoutContent } =\n formatOutput(stdout.trim())\n const { totalLines: stderrLines, truncatedContent: stderrContent } =\n formatOutput(stderr.trim())\n\n const data: Out = {\n stdout: stdoutContent,\n stdoutLines,\n stderr: stderrContent,\n stderrLines,\n interrupted: result.interrupted,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n } catch (error) {\n // \uD83D\uDD27 Handle cancellation or other errors properly\n const isAborted = abortController.signal.aborted\n const errorMessage = isAborted\n ? 'Command was cancelled by user'\n : `Command failed: ${error instanceof Error ? error.message : String(error)}`\n\n const data: Out = {\n stdout: stdout.trim(),\n stdoutLines: stdout.split('\\n').length,\n stderr: errorMessage,\n stderrLines: 1,\n interrupted: isAborted,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(data),\n data,\n }\n }\n },\n} satisfies Tool<In, Out>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,WAAW;AACpB,SAAS,YAAY,UAAU,eAAe;AAC9C,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAC/C,SAAS,oBAAoB;AAG7B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,QAAQ,sBAAs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ourcesContent": ["import { ImageBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'\nimport { statSync } from 'node:fs'\nimport { Box, Text } from 'ink'\nimport * as path from 'node:path'\nimport { extname, relative } from 'node:path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { HighlightedCode } from '@components/HighlightedCode'\nimport type { Tool } from '@tool'\nimport { getCwd } from '@utils/state'\nimport {\n addLineNumbers,\n findSimilarFile,\n normalizeFilePath,\n readTextContent,\n} from '@utils/file'\nimport { logError } from '@utils/log'\nimport { getTheme } from '@utils/theme'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport {\n recordFileRead,\n generateFileModificationReminder,\n} from '@services/fileFreshness'\nimport { DESCRIPTION, PROMPT } from './prompt'\nimport { hasReadPermission } from '@utils/permissions/filesystem'\nimport { secureFileService } from '@utils/secureFile'\n\nconst MAX_LINES_TO_RENDER = 5\nconst MAX_OUTPUT_SIZE = 0.25 * 1024 * 1024 // 0.25MB in bytes\n\n// Common image extensions\nconst IMAGE_EXTENSIONS = new Set([\n '.png',\n '.jpg',\n '.jpeg',\n '.gif',\n '.bmp',\n '.webp',\n])\n\n// Maximum dimensions for images\nconst MAX_WIDTH = 2000\nconst MAX_HEIGHT = 2000\nconst MAX_IMAGE_SIZE = 3.75 * 1024 * 1024 // 5MB in bytes, with base64 encoding\n\nconst inputSchema = z.strictObject({\n file_path: z.string().describe('The absolute path to the file to read'),\n offset: z\n .number()\n .optional()\n .describe(\n 'The line number to start reading from. Only provide if the file is too large to read at once',\n ),\n limit: z\n .number()\n .optional()\n .describe(\n 'The number of lines to read. Only provide if the file is too large to read at once.',\n ),\n})\n\nexport const FileReadTool = {\n name: 'View',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n inputSchema,\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true // FileRead is read-only, safe for concurrent execution\n },\n userFacingName() {\n return 'Read'\n },\n async isEnabled() {\n return true\n },\n needsPermissions({ file_path }) {\n return !hasReadPermission(file_path || getCwd())\n },\n renderToolUseMessage(input, { verbose }) {\n const { file_path, ...rest } = input\n const entries = [\n ['file_path', verbose ? file_path : relative(getCwd(), file_path)],\n ...Object.entries(rest),\n ]\n return entries\n .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)\n .join(', ')\n },\n renderToolResultMessage(output) {\n const verbose = false // Set default value for verbose\n // TODO: Render recursively\n switch (output.type) {\n case 'image':\n return (\n <Box justifyContent=\"space-between\" overflowX=\"hidden\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Text>Read image</Text>\n </Box>\n </Box>\n )\n case 'text': {\n const { filePath, content, numLines } = output.file\n const contentWithFallback = content || '(No content)'\n return (\n <Box justifyContent=\"space-between\" overflowX=\"hidden\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Box flexDirection=\"column\">\n <HighlightedCode\n code={\n verbose\n ? contentWithFallback\n : contentWithFallback\n .split('\\n')\n .slice(0, MAX_LINES_TO_RENDER)\n .filter(_ => _.trim() !== '')\n .join('\\n')\n }\n language={extname(filePath).slice(1)}\n />\n {!verbose && numLines > MAX_LINES_TO_RENDER && (\n <Text color={getTheme().secondaryText}>\n ... (+{numLines - MAX_LINES_TO_RENDER} lines)\n </Text>\n )}\n </Box>\n </Box>\n </Box>\n )\n }\n }\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n async validateInput({ file_path, offset, limit }) {\n const fullFilePath = normalizeFilePath(file_path)\n\n // Use secure file service to check if file exists and get file info\n const fileCheck = secureFileService.safeGetFileInfo(fullFilePath)\n if (!fileCheck.success) {\n // Try to find a similar file with a different extension\n const similarFilename = findSimilarFile(fullFilePath)\n let message = 'File does not exist.'\n\n // If we found a similar file, suggest it to the assistant\n if (similarFilename) {\n message += ` Did you mean ${similarFilename}?`\n }\n\n return {\n result: false,\n message,\n }\n }\n\n const stats = fileCheck.stats!\n const fileSize = stats.size\n const ext = path.extname(fullFilePath).toLowerCase()\n\n // Skip size check for image files - they have their own size limits\n if (!IMAGE_EXTENSIONS.has(ext)) {\n // If file is too large and no offset/limit provided\n if (fileSize > MAX_OUTPUT_SIZE && !offset && !limit) {\n return {\n result: false,\n message: formatFileSizeError(fileSize),\n meta: { fileSize },\n }\n }\n }\n\n return { result: true }\n },\n async *call(\n { file_path, offset = 1, limit = undefined },\n { readFileTimestamps },\n ) {\n const ext = path.extname(file_path).toLowerCase()\n const fullFilePath = normalizeFilePath(file_path)\n\n // Record file read for freshness tracking\n recordFileRead(fullFilePath)\n\n // Emit file read event for system reminders\n emitReminderEvent('file:read', {\n filePath: fullFilePath,\n extension: ext,\n timestamp: Date.now(),\n })\n\n // Update read timestamp, to invalidate stale writes\n readFileTimestamps[fullFilePath] = Date.now()\n\n // Check for file modifications and generate reminder if needed\n const modificationReminder = generateFileModificationReminder(fullFilePath)\n if (modificationReminder) {\n emitReminderEvent('file:modified', {\n filePath: fullFilePath,\n reminder: modificationReminder,\n timestamp: Date.now(),\n })\n }\n\n // If it's an image file, process and return base64 encoded contents\n if (IMAGE_EXTENSIONS.has(ext)) {\n const data = await readImage(fullFilePath, ext)\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n return\n }\n\n // Handle offset properly - if offset is 0, don't subtract 1\n const lineOffset = offset === 0 ? 0 : offset - 1\n const { content, lineCount, totalLines } = readTextContent(\n fullFilePath,\n lineOffset,\n limit,\n )\n\n // Add size validation after reading for non-image files\n if (!IMAGE_EXTENSIONS.has(ext) && content.length > MAX_OUTPUT_SIZE) {\n throw new Error(formatFileSizeError(content.length))\n }\n\n const data = {\n type: 'text' as const,\n file: {\n filePath: file_path,\n content: content,\n numLines: lineCount,\n startLine: offset,\n totalLines,\n },\n }\n\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n },\n renderResultForAssistant(data) {\n switch (data.type) {\n case 'image':\n return [\n {\n type: 'image',\n source: {\n type: 'base64',\n data: data.file.base64,\n media_type: data.file.type,\n },\n },\n ]\n case 'text':\n return addLineNumbers(data.file)\n }\n },\n} satisfies Tool<\n typeof inputSchema,\n | {\n type: 'text'\n file: {\n filePath: string\n content: string\n numLines: number\n startLine: number\n totalLines: number\n }\n }\n | {\n type: 'image'\n file: { base64: string; type: ImageBlockParam.Source['media_type'] }\n }\n>\n\nconst formatFileSizeError = (sizeInBytes: number) =>\n `File content (${Math.round(sizeInBytes / 1024)}KB) exceeds maximum allowed size (${Math.round(MAX_OUTPUT_SIZE / 1024)}KB). Please use offset and limit parameters to read specific portions of the file, or use the GrepTool to search for specific content.`\n\nfunction createImageResponse(\n buffer: Buffer,\n ext: string,\n): {\n type: 'image'\n file: { base64: string; type: ImageBlockParam.Source['media_type'] }\n} {\n return {\n type: 'image',\n file: {\n base64: buffer.toString('base64'),\n type: `image/${ext.slice(1)}` as ImageBlockParam.Source['media_type'],\n },\n }\n}\n\nasync function readImage(\n filePath: string,\n ext: string,\n): Promise<{\n type: 'image'\n file: { base64: string; type: ImageBlockParam.Source['media_type'] }\n}> {\n try {\n const stats = statSync(filePath)\n const sharp = (\n (await import('sharp')) as unknown as { default: typeof import('sharp') }\n ).default\n \n // Use secure file service to read the file\n const fileReadResult = secureFileService.safeReadFile(filePath, {\n encoding: 'buffer' as BufferEncoding,\n maxFileSize: MAX_IMAGE_SIZE\n })\n \n if (!fileReadResult.success) {\n throw new Error(`Failed to read image file: ${fileReadResult.error}`)\n }\n \n const image = sharp(fileReadResult.content as Buffer)\n const metadata = await image.metadata()\n\n if (!metadata.width || !metadata.height) {\n if (stats.size > MAX_IMAGE_SIZE) {\n const compressedBuffer = await image.jpeg({ quality: 80 }).toBuffer()\n return createImageResponse(compressedBuffer, 'jpeg')\n }\n }\n\n // Calculate dimensions while maintaining aspect ratio\n let width = metadata.width || 0\n let height = metadata.height || 0\n\n // Check if the original file just works\n if (\n stats.size <= MAX_IMAGE_SIZE &&\n width <= MAX_WIDTH &&\n height <= MAX_HEIGHT\n ) {\n // Use secure file service to read the file\n const fileReadResult = secureFileService.safeReadFile(filePath, {\n encoding: 'buffer' as BufferEncoding,\n maxFileSize: MAX_IMAGE_SIZE\n })\n \n if (!fileReadResult.success) {\n throw new Error(`Failed to read image file: ${fileReadResult.error}`)\n }\n \n return createImageResponse(fileReadResult.content as Buffer, ext)\n }\n\n if (width > MAX_WIDTH) {\n height = Math.round((height * MAX_WIDTH) / width)\n width = MAX_WIDTH\n }\n\n if (height > MAX_HEIGHT) {\n width = Math.round((width * MAX_HEIGHT) / height)\n height = MAX_HEIGHT\n }\n\n // Resize image and convert to buffer\n const resizedImageBuffer = await image\n .resize(width, height, {\n fit: 'inside',\n withoutEnlargement: true,\n })\n .toBuffer()\n\n // If still too large after resize, compress quality\n if (resizedImageBuffer.length > MAX_IMAGE_SIZE) {\n const compressedBuffer = await image.jpeg({ quality: 80 }).toBuffer()\n return createImageResponse(compressedBuffer, 'jpeg')\n }\n\n return createImageResponse(resizedImageBuffer, ext)\n } catch (e) {\n logError(e)\n // If any error occurs during processing, return original image\n const fileReadResult = secureFileService.safeReadFile(filePath, {\n encoding: 'buffer' as BufferEncoding,\n maxFileSize: MAX_IMAGE_SIZE\n })\n \n if (!fileReadResult.success) {\n throw new Error(`Failed to read image file: ${fileReadResult.error}`)\n }\n \n return createImageResponse(fileReadResult.content as Buffer, ext)\n }\n}\n"],
|
|
4
|
+
"sourcesContent": ["import { ImageBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'\nimport { statSync } from 'node:fs'\nimport { Box, Text } from 'ink'\nimport * as path from 'node:path'\nimport { extname, relative } from 'node:path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { HighlightedCode } from '@components/HighlightedCode'\nimport type { Tool } from '@tool'\nimport { getCwd } from '@utils/state'\nimport {\n addLineNumbers,\n findSimilarFile,\n normalizeFilePath,\n readTextContent,\n} from '@utils/file'\nimport { logError } from '@utils/log'\nimport { getTheme } from '@utils/theme'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport {\n recordFileRead,\n generateFileModificationReminder,\n} from '@services/fileFreshness'\nimport { DESCRIPTION, PROMPT } from './prompt'\nimport { hasReadPermission } from '@utils/permissions/filesystem'\nimport { secureFileService } from '@utils/secureFile'\n\nconst MAX_LINES_TO_RENDER = 5\nconst MAX_OUTPUT_SIZE = 0.25 * 1024 * 1024 // 0.25MB in bytes\n\n// Common image extensions\nconst IMAGE_EXTENSIONS = new Set([\n '.png',\n '.jpg',\n '.jpeg',\n '.gif',\n '.bmp',\n '.webp',\n])\n\n// Maximum dimensions for images\nconst MAX_WIDTH = 2000\nconst MAX_HEIGHT = 2000\nconst MAX_IMAGE_SIZE = 3.75 * 1024 * 1024 // 5MB in bytes, with base64 encoding\n\nconst inputSchema = z.strictObject({\n file_path: z.string().describe('The absolute path to the file to read'),\n offset: z\n .number()\n .optional()\n .describe(\n 'The line number to start reading from. Only provide if the file is too large to read at once',\n ),\n limit: z\n .number()\n .optional()\n .describe(\n 'The number of lines to read. Only provide if the file is too large to read at once.',\n ),\n})\n\nexport const FileReadTool = {\n name: 'View',\n async description() {\n return DESCRIPTION\n },\n async prompt() {\n return PROMPT\n },\n inputSchema,\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true // FileRead is read-only, safe for concurrent execution\n },\n userFacingName() {\n return 'Read'\n },\n async isEnabled() {\n return true\n },\n needsPermissions({ file_path }) {\n return !hasReadPermission(file_path || getCwd())\n },\n renderToolUseMessage(input, { verbose }) {\n const { file_path, ...rest } = input\n const entries = [\n ['file_path', verbose ? file_path : relative(getCwd(), file_path)],\n ...Object.entries(rest),\n ]\n return entries\n .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)\n .join(', ')\n },\n renderToolResultMessage(output) {\n const verbose = false // Set default value for verbose\n // TODO: Render recursively\n switch (output.type) {\n case 'image':\n return (\n <Box justifyContent=\"space-between\" overflowX=\"hidden\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Text>Read image</Text>\n </Box>\n </Box>\n )\n case 'text': {\n const { filePath, content, numLines } = output.file\n const contentWithFallback = content || '(No content)'\n return (\n <Box justifyContent=\"space-between\" overflowX=\"hidden\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Box flexDirection=\"column\">\n <HighlightedCode\n code={\n verbose\n ? contentWithFallback\n : contentWithFallback\n .split('\\n')\n .slice(0, MAX_LINES_TO_RENDER)\n .filter(_ => _.trim() !== '')\n .join('\\n')\n }\n language={extname(filePath).slice(1)}\n />\n {!verbose && numLines > MAX_LINES_TO_RENDER && (\n <Text color={getTheme().secondaryText}>\n ... (+{numLines - MAX_LINES_TO_RENDER} lines)\n </Text>\n )}\n </Box>\n </Box>\n </Box>\n )\n }\n }\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n async validateInput({ file_path, offset, limit }) {\n const fullFilePath = normalizeFilePath(file_path)\n\n // Use secure file service to check if file exists and get file info\n const fileCheck = secureFileService.safeGetFileInfo(fullFilePath)\n if (!fileCheck.success) {\n // Try to find a similar file with a different extension\n const similarFilename = findSimilarFile(fullFilePath)\n let message = 'File does not exist.'\n\n // If we found a similar file, suggest it to the assistant\n if (similarFilename) {\n message += ` Did you mean ${similarFilename}?`\n }\n\n return {\n result: false,\n message,\n }\n }\n\n const stats = fileCheck.stats!\n const fileSize = stats.size\n const ext = path.extname(fullFilePath).toLowerCase()\n\n // Skip size check for image files - they have their own size limits\n if (!IMAGE_EXTENSIONS.has(ext)) {\n // If file is too large and no offset/limit provided\n if (fileSize > MAX_OUTPUT_SIZE && !offset && !limit) {\n return {\n result: false,\n message: formatFileSizeError(fileSize),\n meta: { fileSize },\n }\n }\n }\n\n return { result: true }\n },\n async *call(\n { file_path, offset = 1, limit = undefined },\n { readFileTimestamps },\n ) {\n const ext = path.extname(file_path).toLowerCase()\n const fullFilePath = normalizeFilePath(file_path)\n\n // Record file read for freshness tracking\n recordFileRead(fullFilePath)\n\n // Emit file read event for system reminders\n emitReminderEvent('file:read', {\n filePath: fullFilePath,\n extension: ext,\n timestamp: Date.now(),\n })\n\n // Update read timestamp, to invalidate stale writes\n readFileTimestamps[fullFilePath] = Date.now()\n\n // Check for file modifications and generate reminder if needed\n const modificationReminder = generateFileModificationReminder(fullFilePath)\n if (modificationReminder) {\n emitReminderEvent('file:modified', {\n filePath: fullFilePath,\n reminder: modificationReminder,\n timestamp: Date.now(),\n })\n }\n\n // If it's an image file, process and return base64 encoded contents\n if (IMAGE_EXTENSIONS.has(ext)) {\n const data = await readImage(fullFilePath, ext)\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n return\n }\n\n // Handle offset properly - if offset is 0, don't subtract 1\n const lineOffset = offset === 0 ? 0 : offset - 1\n const { content, lineCount, totalLines } = readTextContent(\n fullFilePath,\n lineOffset,\n limit,\n )\n\n // Add size validation after reading for non-image files\n if (!IMAGE_EXTENSIONS.has(ext) && content.length > MAX_OUTPUT_SIZE) {\n throw new Error(formatFileSizeError(content.length))\n }\n\n const data = {\n type: 'text' as const,\n file: {\n filePath: file_path,\n content: content,\n numLines: lineCount,\n startLine: offset,\n totalLines,\n },\n }\n\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n },\n renderResultForAssistant(data) {\n switch (data.type) {\n case 'image':\n return [\n {\n type: 'image',\n source: {\n type: 'base64',\n data: data.file.base64,\n media_type: data.file.type,\n },\n },\n ]\n case 'text':\n return addLineNumbers(data.file)\n }\n },\n} satisfies Tool<\n typeof inputSchema,\n | {\n type: 'text'\n file: {\n filePath: string\n content: string\n numLines: number\n startLine: number\n totalLines: number\n }\n }\n | {\n type: 'image'\n file: { base64: string; type: ImageBlockParam.Source['media_type'] }\n }\n>\n\nconst formatFileSizeError = (sizeInBytes: number) =>\n `File content (${Math.round(sizeInBytes / 1024)}KB) exceeds maximum allowed size (${Math.round(MAX_OUTPUT_SIZE / 1024)}KB). Please use offset and limit parameters to read specific portions of the file, or use the GrepTool to search for specific content.`\n\nfunction createImageResponse(\n buffer: Buffer,\n ext: string,\n): {\n type: 'image'\n file: { base64: string; type: ImageBlockParam.Source['media_type'] }\n} {\n return {\n type: 'image',\n file: {\n base64: buffer.toString('base64'),\n type: `image/${ext.slice(1)}` as ImageBlockParam.Source['media_type'],\n },\n }\n}\n\nasync function readImage(\n filePath: string,\n ext: string,\n): Promise<{\n type: 'image'\n file: { base64: string; type: ImageBlockParam.Source['media_type'] }\n}> {\n try {\n const stats = statSync(filePath)\n const sharp = (\n (await import('sharp')) as unknown as { default: typeof import('sharp') }\n ).default\n\n // Use secure file service to read the file\n const fileReadResult = secureFileService.safeReadFile(filePath, {\n encoding: 'buffer' as BufferEncoding,\n maxFileSize: MAX_IMAGE_SIZE,\n })\n\n if (!fileReadResult.success) {\n throw new Error(`Failed to read image file: ${fileReadResult.error}`)\n }\n\n const image = sharp(fileReadResult.content as Buffer)\n const metadata = await image.metadata()\n\n if (!metadata.width || !metadata.height) {\n if (stats.size > MAX_IMAGE_SIZE) {\n const compressedBuffer = await image.jpeg({ quality: 80 }).toBuffer()\n return createImageResponse(compressedBuffer, 'jpeg')\n }\n }\n\n // Calculate dimensions while maintaining aspect ratio\n let width = metadata.width || 0\n let height = metadata.height || 0\n\n // Check if the original file just works\n if (\n stats.size <= MAX_IMAGE_SIZE &&\n width <= MAX_WIDTH &&\n height <= MAX_HEIGHT\n ) {\n // Use secure file service to read the file\n const fileReadResult = secureFileService.safeReadFile(filePath, {\n encoding: 'buffer' as BufferEncoding,\n maxFileSize: MAX_IMAGE_SIZE,\n })\n\n if (!fileReadResult.success) {\n throw new Error(`Failed to read image file: ${fileReadResult.error}`)\n }\n\n return createImageResponse(fileReadResult.content as Buffer, ext)\n }\n\n if (width > MAX_WIDTH) {\n height = Math.round((height * MAX_WIDTH) / width)\n width = MAX_WIDTH\n }\n\n if (height > MAX_HEIGHT) {\n width = Math.round((width * MAX_HEIGHT) / height)\n height = MAX_HEIGHT\n }\n\n // Resize image and convert to buffer\n const resizedImageBuffer = await image\n .resize(width, height, {\n fit: 'inside',\n withoutEnlargement: true,\n })\n .toBuffer()\n\n // If still too large after resize, compress quality\n if (resizedImageBuffer.length > MAX_IMAGE_SIZE) {\n const compressedBuffer = await image.jpeg({ quality: 80 }).toBuffer()\n return createImageResponse(compressedBuffer, 'jpeg')\n }\n\n return createImageResponse(resizedImageBuffer, ext)\n } catch (e) {\n logError(e)\n // If any error occurs during processing, return original image\n const fileReadResult = secureFileService.safeReadFile(filePath, {\n encoding: 'buffer' as BufferEncoding,\n maxFileSize: MAX_IMAGE_SIZE,\n })\n\n if (!fileReadResult.success) {\n throw new Error(`Failed to read image file: ${fileReadResult.error}`)\n }\n\n return createImageResponse(fileReadResult.content as Buffer, ext)\n }\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,gBAAgB;AACzB,SAAS,KAAK,YAAY;AAC1B,YAAY,UAAU;AACtB,SAAS,SAAS,gBAAgB;AAClC,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,sCAAsC;AAC/C,SAAS,uBAAuB;AAEhC,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,cAAc;AACpC,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAElC,MAAM,sBAAsB;AAC5B,MAAM,kBAAkB,OAAO,OAAO;AAGtC,MAAM,mBAAmB,oBAAI,IAAI;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGD,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,iBAAiB,OAA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|
|
6
6
|
"names": ["data", "fileReadResult"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/FileWriteTool/FileWriteTool.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Hunk } from 'diff'\nimport { existsSync, mkdirSync, readFileSync, statSync } from 'fs'\nimport { Box, Text } from 'ink'\nimport { EOL } from 'os'\nimport { dirname, extname, isAbsolute, relative, resolve, sep } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FileEditToolUpdatedMessage } from '@components/FileEditToolUpdatedMessage'\nimport { HighlightedCode } from '@components/HighlightedCode'\nimport { StructuredDiff } from '@components/StructuredDiff'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport type { Tool } from '@tool'\nimport { intersperse } from '@utils/array'\nimport {\n addLineNumbers,\n detectFileEncoding,\n detectLineEndings,\n detectRepoLineEndings,\n writeTextContent,\n} from '@utils/file'\nimport { logError } from '@utils/log'\nimport { getCwd } from '@utils/state'\nimport { getTheme } from '@utils/theme'\nimport { PROMPT } from './prompt'\nimport { hasWritePermission } from '@utils/permissions/filesystem'\nimport { getPatch } from '@utils/diff'\nimport { PROJECT_FILE } from '@constants/product'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { recordFileEdit } from '@services/fileFreshness'\n\nconst MAX_LINES_TO_RENDER = 5\nconst MAX_LINES_TO_RENDER_FOR_ASSISTANT = 16000\nconst TRUNCATED_MESSAGE =\n '<response clipped><NOTE>To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with Grep in order to find the line numbers of what you are looking for.</NOTE>'\n\nconst inputSchema = z.strictObject({\n file_path: z\n .string()\n .describe(\n 'The absolute path to the file to write (must be absolute, not relative)',\n ),\n content: z.string().describe('The content to write to the file'),\n})\n\nexport const FileWriteTool = {\n name: 'Replace',\n async description() {\n return 'Write a file to the local filesystem.'\n },\n userFacingName: () => 'Write',\n async prompt() {\n return PROMPT\n },\n inputSchema,\n async isEnabled() {\n return true\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // FileWriteTool modifies state/files, not safe for concurrent execution\n },\n needsPermissions({ file_path }) {\n return !hasWritePermission(file_path)\n },\n renderToolUseMessage(input, { verbose }) {\n return `file_path: ${verbose ? input.file_path : relative(getCwd(), input.file_path)}`\n },\n renderToolUseRejectedMessage({ file_path, content }: any = {}
|
|
5
|
-
"mappings": "AACA,SAAS,YAAY,WAAW,cAAc,gBAAgB;AAC9D,SAAS,KAAK,YAAY;AAC1B,SAAS,WAAW;AACpB,SAAS,SAAS,SAAS,YAAY,UAAU,SAAS,WAAW;AACrE,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,kCAAkC;AAC3C,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,sCAAsC;AAE/C,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAE/B,MAAM,sBAAsB;AAC5B,MAAM,oCAAoC;AAC1C,MAAM,oBACJ;AAEF,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,WAAW,EACR,OAAO,EACP;AAAA,IACC;AAAA,EACF;AAAA,EACF,SAAS,EAAE,OAAO,EAAE,SAAS,kCAAkC;AACjE,CAAC;AAEM,MAAM,gBAAgB;AAAA,EAC3B,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,gBAAgB,MAAM;AAAA,EACtB,MAAM,SAAS;AACb,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,MAAM,YAAY;AAChB,WAAO;AAAA,EACT;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB;AAClB,WAAO;AAAA,EACT;AAAA,EACA,iBAAiB,EAAE,UAAU,GAAG;AAC9B,WAAO,CAAC,mBAAmB,SAAS;AAAA,EACtC;AAAA,EACA,qBAAqB,OAAO,EAAE,QAAQ,GAAG;AACvC,WAAO,cAAc,UAAU,MAAM,YAAY,SAAS,OAAO,GAAG,MAAM,SAAS,CAAC;AAAA,EACtF;AAAA,EACA,
|
|
4
|
+
"sourcesContent": ["import { Hunk } from 'diff'\nimport { existsSync, mkdirSync, readFileSync, statSync } from 'fs'\nimport { Box, Text } from 'ink'\nimport { EOL } from 'os'\nimport { dirname, extname, isAbsolute, relative, resolve, sep } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FileEditToolUpdatedMessage } from '@components/FileEditToolUpdatedMessage'\nimport { HighlightedCode } from '@components/HighlightedCode'\nimport { StructuredDiff } from '@components/StructuredDiff'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport type { Tool } from '@tool'\nimport { intersperse } from '@utils/array'\nimport {\n addLineNumbers,\n detectFileEncoding,\n detectLineEndings,\n detectRepoLineEndings,\n writeTextContent,\n} from '@utils/file'\nimport { logError } from '@utils/log'\nimport { getCwd } from '@utils/state'\nimport { getTheme } from '@utils/theme'\nimport { PROMPT } from './prompt'\nimport { hasWritePermission } from '@utils/permissions/filesystem'\nimport { getPatch } from '@utils/diff'\nimport { PROJECT_FILE } from '@constants/product'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { recordFileEdit } from '@services/fileFreshness'\n\nconst MAX_LINES_TO_RENDER = 5\nconst MAX_LINES_TO_RENDER_FOR_ASSISTANT = 16000\nconst TRUNCATED_MESSAGE =\n '<response clipped><NOTE>To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with Grep in order to find the line numbers of what you are looking for.</NOTE>'\n\nconst inputSchema = z.strictObject({\n file_path: z\n .string()\n .describe(\n 'The absolute path to the file to write (must be absolute, not relative)',\n ),\n content: z.string().describe('The content to write to the file'),\n})\n\nexport const FileWriteTool = {\n name: 'Replace',\n async description() {\n return 'Write a file to the local filesystem.'\n },\n userFacingName: () => 'Write',\n async prompt() {\n return PROMPT\n },\n inputSchema,\n async isEnabled() {\n return true\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // FileWriteTool modifies state/files, not safe for concurrent execution\n },\n needsPermissions({ file_path }) {\n return !hasWritePermission(file_path)\n },\n renderToolUseMessage(input, { verbose }) {\n return `file_path: ${verbose ? input.file_path : relative(getCwd(), input.file_path)}`\n },\n renderToolUseRejectedMessage(\n { file_path, content }: any = {},\n { columns, verbose }: any = {},\n ) {\n try {\n if (!file_path) {\n return <FallbackToolUseRejectedMessage />\n }\n const fullFilePath = isAbsolute(file_path)\n ? file_path\n : resolve(getCwd(), file_path)\n const oldFileExists = existsSync(fullFilePath)\n const enc = oldFileExists ? detectFileEncoding(fullFilePath) : 'utf-8'\n const oldContent = oldFileExists ? readFileSync(fullFilePath, enc) : null\n const type = oldContent ? 'update' : 'create'\n const patch = getPatch({\n filePath: file_path,\n fileContents: oldContent ?? '',\n oldStr: oldContent ?? '',\n newStr: content,\n })\n\n return (\n <Box flexDirection=\"column\">\n <Text>\n {' '}\u23BF{' '}\n <Text color={getTheme().error}>\n User rejected {type === 'update' ? 'update' : 'write'} to{' '}\n </Text>\n <Text bold>\n {verbose ? file_path : relative(getCwd(), file_path)}\n </Text>\n </Text>\n {intersperse(\n patch.map(_ => (\n <Box flexDirection=\"column\" paddingLeft={5} key={_.newStart}>\n <StructuredDiff patch={_} dim={true} width={columns - 12} />\n </Box>\n )),\n i => (\n <Box paddingLeft={5} key={`ellipsis-${i}`}>\n <Text color={getTheme().secondaryText}>...</Text>\n </Box>\n ),\n )}\n </Box>\n )\n } catch (e) {\n // Handle the case where while we were showing the diff, the user manually made the change.\n // TODO: Find a way to show the diff in this case\n logError(e)\n return (\n <Box flexDirection=\"column\">\n <Text>{' '}\u23BF (No changes)</Text>\n </Box>\n )\n }\n },\n renderToolResultMessage({ filePath, content, structuredPatch, type }) {\n const verbose = false // Default to false since verbose is no longer passed\n switch (type) {\n case 'create': {\n const contentWithFallback = content || '(No content)'\n const numLines = content.split(EOL).length\n\n return (\n <Box flexDirection=\"column\">\n <Text>\n {' '}\u23BF Wrote {numLines} lines to{' '}\n <Text bold>\n {verbose ? filePath : relative(getCwd(), filePath)}\n </Text>\n </Text>\n <Box flexDirection=\"column\" paddingLeft={5}>\n <HighlightedCode\n code={\n verbose\n ? contentWithFallback\n : contentWithFallback\n .split('\\n')\n .slice(0, MAX_LINES_TO_RENDER)\n .filter(_ => _.trim() !== '')\n .join('\\n')\n }\n language={extname(filePath).slice(1)}\n />\n {!verbose && numLines > MAX_LINES_TO_RENDER && (\n <Text color={getTheme().secondaryText}>\n ... (+{numLines - MAX_LINES_TO_RENDER} lines)\n </Text>\n )}\n </Box>\n </Box>\n )\n }\n case 'update':\n return (\n <FileEditToolUpdatedMessage\n filePath={filePath}\n structuredPatch={structuredPatch}\n verbose={verbose}\n />\n )\n }\n },\n async validateInput({ file_path }, { readFileTimestamps }) {\n const fullFilePath = isAbsolute(file_path)\n ? file_path\n : resolve(getCwd(), file_path)\n if (!existsSync(fullFilePath)) {\n return { result: true }\n }\n\n const readTimestamp = readFileTimestamps[fullFilePath]\n if (!readTimestamp) {\n return {\n result: false,\n message:\n 'File has not been read yet. Read it first before writing to it.',\n }\n }\n\n // Check if file exists and get its last modified time\n const stats = statSync(fullFilePath)\n const lastWriteTime = stats.mtimeMs\n if (lastWriteTime > readTimestamp) {\n return {\n result: false,\n message:\n 'File has been modified since read, either by the user or by a linter. Read it again before attempting to write it.',\n }\n }\n\n return { result: true }\n },\n async *call({ file_path, content }, { readFileTimestamps }) {\n const fullFilePath = isAbsolute(file_path)\n ? file_path\n : resolve(getCwd(), file_path)\n const dir = dirname(fullFilePath)\n const oldFileExists = existsSync(fullFilePath)\n const enc = oldFileExists ? detectFileEncoding(fullFilePath) : 'utf-8'\n const oldContent = oldFileExists ? readFileSync(fullFilePath, enc) : null\n\n const endings = oldFileExists\n ? detectLineEndings(fullFilePath)\n : await detectRepoLineEndings(getCwd())\n\n mkdirSync(dir, { recursive: true })\n writeTextContent(fullFilePath, content, enc, endings!)\n\n // Record Agent edit operation for file freshness tracking\n recordFileEdit(fullFilePath, content)\n\n // Update read timestamp, to invalidate stale writes\n readFileTimestamps[fullFilePath] = statSync(fullFilePath).mtimeMs\n\n // Log when writing to CLAUDE.md\n if (fullFilePath.endsWith(`${sep}${PROJECT_FILE}`)) {\n }\n\n // Emit file edited event for system reminders\n emitReminderEvent('file:edited', {\n filePath: fullFilePath,\n content,\n oldContent: oldContent || '',\n timestamp: Date.now(),\n operation: oldFileExists ? 'update' : 'create',\n })\n\n if (oldContent) {\n const patch = getPatch({\n filePath: file_path,\n fileContents: oldContent,\n oldStr: oldContent,\n newStr: content,\n })\n\n const data = {\n type: 'update' as const,\n filePath: file_path,\n content,\n structuredPatch: patch,\n }\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n return\n }\n\n const data = {\n type: 'create' as const,\n filePath: file_path,\n content,\n structuredPatch: [],\n }\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n },\n renderResultForAssistant({ filePath, content, type }) {\n switch (type) {\n case 'create':\n return `File created successfully at: ${filePath}`\n case 'update':\n return `The file ${filePath} has been updated. Here's the result of running \\`cat -n\\` on a snippet of the edited file:\n${addLineNumbers({\n content:\n content.split(/\\r?\\n/).length > MAX_LINES_TO_RENDER_FOR_ASSISTANT\n ? content\n .split(/\\r?\\n/)\n .slice(0, MAX_LINES_TO_RENDER_FOR_ASSISTANT)\n .join('\\n') + TRUNCATED_MESSAGE\n : content,\n startLine: 1,\n})}`\n }\n },\n} satisfies Tool<\n typeof inputSchema,\n {\n type: 'create' | 'update'\n filePath: string\n content: string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F;AAEA,UAAM,OAAO;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,MACV;AAAA,MACA,iBAAiB,CAAC;AAAA,IACpB;AACA,UAAM;AAAA,MACJ,MAAM;AAAA,MACN;AAAA,MACA,oBAAoB,KAAK,yBAAyB,IAAI;AAAA,IACxD;AAAA,EACF;AAAA,EACA,yBAAyB,EAAE,UAAU,SAAS,KAAK,GAAG;AACpD,YAAQ,MAAM;AAAA,MACZ,KAAK;AACH,eAAO,iCAAiC,QAAQ;AAAA,MAClD,KAAK;AACH,eAAO,YAAY,QAAQ;AAAA,EACjC,eAAe;AAAA,UACf,SACE,QAAQ,MAAM,OAAO,EAAE,SAAS,oCAC5B,QACG,MAAM,OAAO,EACb,MAAM,GAAG,iCAAiC,EAC1C,KAAK,IAAI,IAAI,oBAChB;AAAA,UACN,WAAW;AAAA,QACb,CAAC,CAAC;AAAA,IACE;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["data"]
|
|
7
7
|
}
|
|
@@ -5,10 +5,7 @@ import { z } from "zod";
|
|
|
5
5
|
import { Cost } from "../../components/Cost.js";
|
|
6
6
|
import { FallbackToolUseRejectedMessage } from "../../components/FallbackToolUseRejectedMessage.js";
|
|
7
7
|
import { getCwd } from "../../utils/state.js";
|
|
8
|
-
import {
|
|
9
|
-
getAbsolutePath,
|
|
10
|
-
getAbsoluteAndRelativePaths
|
|
11
|
-
} from "../../utils/file.js";
|
|
8
|
+
import { getAbsolutePath, getAbsoluteAndRelativePaths } from "../../utils/file.js";
|
|
12
9
|
import { ripGrep } from "../../utils/ripgrep.js";
|
|
13
10
|
import { DESCRIPTION, TOOL_NAME_FOR_PROMPT } from "./prompt.js";
|
|
14
11
|
import { hasReadPermission } from "../../utils/permissions/filesystem.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/GrepTool/GrepTool.tsx"],
|
|
4
|
-
"sourcesContent": ["import { stat } from 'fs/promises'\nimport { Box, Text } from 'ink'\nimport React from 'react'\nimport { z } from 'zod'\nimport { Cost } from '@components/Cost'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport { getCwd } from '@utils/state'\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY;AACrB,SAAS,KAAK,YAAY;AAC1B,OAAO,WAAW;AAClB,SAAS,SAAS;AAClB,SAAS,YAAY;AACrB,SAAS,sCAAsC;AAE/C,SAAS,cAAc;AACvB
|
|
4
|
+
"sourcesContent": ["import { stat } from 'fs/promises'\nimport { Box, Text } from 'ink'\nimport React from 'react'\nimport { z } from 'zod'\nimport { Cost } from '@components/Cost'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool } from '@tool'\nimport { getCwd } from '@utils/state'\nimport { getAbsolutePath, getAbsoluteAndRelativePaths } from '@utils/file'\nimport { ripGrep } from '@utils/ripgrep'\nimport { DESCRIPTION, TOOL_NAME_FOR_PROMPT } from './prompt'\nimport { hasReadPermission } from '@utils/permissions/filesystem'\n\nconst inputSchema = z.strictObject({\n pattern: z\n .string()\n .describe('The regular expression pattern to search for in file contents'),\n path: z\n .string()\n .optional()\n .describe(\n 'The directory to search in. Defaults to the current working directory.',\n ),\n include: z\n .string()\n .optional()\n .describe(\n 'File pattern to include in the search (e.g. \"*.js\", \"*.{ts,tsx}\")',\n ),\n})\n\nconst MAX_RESULTS = 100\n\ntype Input = typeof inputSchema\ntype Output = {\n durationMs: number\n numFiles: number\n filenames: string[]\n}\n\nexport const GrepTool = {\n name: TOOL_NAME_FOR_PROMPT,\n async description() {\n return DESCRIPTION\n },\n userFacingName() {\n return 'Search'\n },\n inputSchema,\n isReadOnly() {\n return true\n },\n isConcurrencySafe() {\n return true // GrepTool is read-only, safe for concurrent execution\n },\n async isEnabled() {\n return true\n },\n needsPermissions({ path }) {\n return !hasReadPermission(path || getCwd())\n },\n async prompt() {\n return DESCRIPTION\n },\n renderToolUseMessage({ pattern, path, include }, { verbose }) {\n const { absolutePath, relativePath } = getAbsoluteAndRelativePaths(path)\n return `pattern: \"${pattern}\"${relativePath || verbose ? `, path: \"${verbose ? absolutePath : relativePath}\"` : ''}${include ? `, include: \"${include}\"` : ''}`\n },\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n renderToolResultMessage(output) {\n // Handle string content for backward compatibility\n if (typeof output === 'string') {\n // Convert string to Output type using tmpDeserializeOldLogResult if needed\n output = output as unknown as Output\n }\n\n return (\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF Found </Text>\n <Text bold>{output.numFiles} </Text>\n <Text>\n {output.numFiles === 0 || output.numFiles > 1 ? 'files' : 'file'}\n </Text>\n </Box>\n <Cost costUSD={0} durationMs={output.durationMs} debug={false} />\n </Box>\n )\n },\n renderResultForAssistant({ numFiles, filenames }) {\n if (numFiles === 0) {\n return 'No files found'\n }\n let result = `Found ${numFiles} file${numFiles === 1 ? '' : 's'}\\n${filenames.slice(0, MAX_RESULTS).join('\\n')}`\n if (numFiles > MAX_RESULTS) {\n result +=\n '\\n(Results are truncated. Consider using a more specific path or pattern.)'\n }\n return result\n },\n async *call({ pattern, path, include }, { abortController }) {\n const start = Date.now()\n const absolutePath = getAbsolutePath(path) || getCwd()\n\n const args = ['-li', pattern]\n if (include) {\n args.push('--glob', include)\n }\n\n const results = await ripGrep(args, absolutePath, abortController.signal)\n\n const stats = await Promise.all(results.map(_ => stat(_)))\n const matches = results\n // Sort by modification time\n .map((_, i) => [_, stats[i]!] as const)\n .sort((a, b) => {\n if (process.env.NODE_ENV === 'test') {\n // In tests, we always want to sort by filename, so that results are deterministic\n return a[0].localeCompare(b[0])\n }\n const timeComparison = (b[1].mtimeMs ?? 0) - (a[1].mtimeMs ?? 0)\n if (timeComparison === 0) {\n // Sort by filename as a tiebreaker\n return a[0].localeCompare(b[0])\n }\n return timeComparison\n })\n .map(_ => _[0])\n\n const output = {\n filenames: matches,\n durationMs: Date.now() - start,\n numFiles: matches.length,\n }\n\n yield {\n type: 'result',\n resultForAssistant: this.renderResultForAssistant(output),\n data: output,\n }\n },\n} satisfies Tool<Input, Output>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY;AACrB,SAAS,KAAK,YAAY;AAC1B,OAAO,WAAW;AAClB,SAAS,SAAS;AAClB,SAAS,YAAY;AACrB,SAAS,sCAAsC;AAE/C,SAAS,cAAc;AACvB,SAAS,iBAAiB,mCAAmC;AAC7D,SAAS,eAAe;AACxB,SAAS,aAAa,4BAA4B;AAClD,SAAS,yBAAyB;AAElC,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,SAAS,EACN,OAAO,EACP,SAAS,+DAA+D;AAAA,EAC3E,MAAM,EACH,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AAAA,EACF,SAAS,EACN,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAED,MAAM,cAAc;AASb,MAAM,WAAW;AAAA,EACtB,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,iBAAiB;AACf,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,aAAa;AACX,WAAO;AAAA,EACT;AAAA,EACA,oBAAoB;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,YAAY;AAChB,WAAO;AAAA,EACT;AAAA,EACA,iBAAiB,EAAE,KAAK,GAAG;AACzB,WAAO,CAAC,kBAAkB,QAAQ,OAAO,CAAC;AAAA,EAC5C;AAAA,EACA,MAAM,SAAS;AACb,WAAO;AAAA,EACT;AAAA,EACA,qBAAqB,EAAE,SAAS,MAAM,QAAQ,GAAG,EAAE,QAAQ,GAAG;AAC5D,UAAM,EAAE,cAAc,aAAa,IAAI,4BAA4B,IAAI;AACvE,WAAO,aAAa,OAAO,IAAI,gBAAgB,UAAU,YAAY,UAAU,e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AM,CAAC,GAAG,MAAM,CAAC,CAAE,CAAU,EACrC,KAAK,CAAC,GAAG,MAAM;AACd,UAAI,QAAQ,IAAI,aAAa,QAAQ;AAEnC,eAAO,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC;AAAA,MAChC;AACA,YAAM,kBAAkB,EAAE,CAAC,EAAE,WAAW,MAAM,EAAE,CAAC,EAAE,WAAW;AAC9D,UAAI,mBAAmB,GAAG;AAExB,eAAO,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC;AAAA,MAChC;AACA,aAAO;AAAA,IACT,CAAC,EACA,IAAI,OAAK,EAAE,CAAC,CAAC;AAEhB,UAAM,SAAS;AAAA,MACb,WAAW;AAAA,MACX,YAAY,KAAK,IAAI,IAAI;AAAA,MACzB,UAAU,QAAQ;AAAA,IACpB;AAEA,UAAM;AAAA,MACJ,MAAM;AAAA,MACN,oBAAoB,KAAK,yBAAyB,MAAM;AAAA,MACxD,MAAM;AAAA,IACR;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,7 +15,10 @@ import { getTheme } from "../../utils/theme.js";
|
|
|
15
15
|
import { NotebookEditTool } from "../NotebookEditTool/NotebookEditTool.js";
|
|
16
16
|
function applyContentEdit(content, oldString, newString, replaceAll = false) {
|
|
17
17
|
if (replaceAll) {
|
|
18
|
-
const regex = new RegExp(
|
|
18
|
+
const regex = new RegExp(
|
|
19
|
+
oldString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
|
|
20
|
+
"g"
|
|
21
|
+
);
|
|
19
22
|
const matches = content.match(regex);
|
|
20
23
|
const occurrences = matches ? matches.length : 0;
|
|
21
24
|
const newContent = content.replace(regex, newString);
|