@within-7/minto 0.4.0 → 0.4.2
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/Tool.js +7 -0
- package/dist/Tool.js.map +2 -2
- package/dist/commands/agents/AgentsCommand.js +1 -1
- package/dist/commands/agents/AgentsCommand.js.map +2 -2
- package/dist/commands/agents/constants.js +2 -2
- package/dist/commands/agents/constants.js.map +2 -2
- package/dist/commands/clear.js +4 -3
- package/dist/commands/clear.js.map +2 -2
- package/dist/commands/compact.js +2 -2
- package/dist/commands/compact.js.map +1 -1
- package/dist/commands/context.js +3 -1
- package/dist/commands/context.js.map +2 -2
- package/dist/commands/login.js +128 -0
- package/dist/commands/login.js.map +7 -0
- package/dist/commands/memory.js +33 -82
- package/dist/commands/memory.js.map +2 -2
- package/dist/commands/quit.js +3 -1
- package/dist/commands/quit.js.map +2 -2
- package/dist/commands/resume.js +39 -239
- package/dist/commands/resume.js.map +2 -2
- package/dist/commands/tasks.js +1 -1
- package/dist/commands/tasks.js.map +2 -2
- package/dist/commands/terminalSetup.js +6 -2
- package/dist/commands/terminalSetup.js.map +2 -2
- package/dist/commands.js +2 -0
- package/dist/commands.js.map +2 -2
- package/dist/components/AgentDetailView.js +126 -0
- package/dist/components/AgentDetailView.js.map +7 -0
- package/dist/components/AgentThinkingBlock.js +1 -1
- package/dist/components/AgentThinkingBlock.js.map +2 -2
- package/dist/components/AgentViewBanner.js +22 -0
- package/dist/components/AgentViewBanner.js.map +7 -0
- package/dist/components/HeaderBar.js +1 -1
- package/dist/components/HeaderBar.js.map +2 -2
- package/dist/components/Help.js +8 -1
- package/dist/components/Help.js.map +2 -2
- package/dist/components/HotkeyHelpPanel.js +26 -8
- package/dist/components/HotkeyHelpPanel.js.map +2 -2
- package/dist/components/IdleNotificationBar.js +10 -0
- package/dist/components/IdleNotificationBar.js.map +7 -0
- package/dist/components/ModelSelector/ModelSelector.js +55 -20
- package/dist/components/ModelSelector/ModelSelector.js.map +2 -2
- package/dist/components/PromptInput.js +186 -115
- package/dist/components/PromptInput.js.map +2 -2
- package/dist/components/RewindPanel.js +272 -0
- package/dist/components/RewindPanel.js.map +7 -0
- package/dist/components/Spinner.js +10 -21
- package/dist/components/Spinner.js.map +2 -2
- package/dist/components/StreamingTextPreview.js +29 -0
- package/dist/components/StreamingTextPreview.js.map +7 -0
- package/dist/components/SubagentBlock.js +3 -2
- package/dist/components/SubagentBlock.js.map +2 -2
- package/dist/components/SubagentProgress.js +4 -4
- package/dist/components/SubagentProgress.js.map +2 -2
- package/dist/components/TabbedListView/SearchInput.js +1 -1
- package/dist/components/TabbedListView/SearchInput.js.map +2 -2
- package/dist/components/TabbedListView/TabbedListView.js +87 -41
- package/dist/components/TabbedListView/TabbedListView.js.map +2 -2
- package/dist/components/TaskCard.js +4 -4
- package/dist/components/TaskCard.js.map +2 -2
- package/dist/components/TeamMemberPanel.js +107 -0
- package/dist/components/TeamMemberPanel.js.map +7 -0
- package/dist/components/ThinkingSelector.js +84 -0
- package/dist/components/ThinkingSelector.js.map +7 -0
- package/dist/components/TitledDivider.js +26 -0
- package/dist/components/TitledDivider.js.map +7 -0
- package/dist/components/TodoPanel.js +31 -30
- package/dist/components/TodoPanel.js.map +2 -2
- package/dist/components/TokenWarning.js +28 -7
- package/dist/components/TokenWarning.js.map +2 -2
- package/dist/components/messages/AssistantTextMessage.js +5 -2
- package/dist/components/messages/AssistantTextMessage.js.map +2 -2
- package/dist/components/messages/AssistantToolUseMessage.js +9 -1
- package/dist/components/messages/AssistantToolUseMessage.js.map +2 -2
- package/dist/components/messages/DefaultToolResultFallback.js +11 -0
- package/dist/components/messages/DefaultToolResultFallback.js.map +7 -0
- package/dist/components/messages/ParallelTasksGroupView.js +14 -6
- package/dist/components/messages/ParallelTasksGroupView.js.map +2 -2
- package/dist/components/messages/TaskInModuleView.js +27 -27
- package/dist/components/messages/TaskInModuleView.js.map +2 -2
- package/dist/components/messages/UserGuidanceMessage.js +26 -0
- package/dist/components/messages/UserGuidanceMessage.js.map +7 -0
- package/dist/components/messages/UserPromptMessage.js +2 -1
- package/dist/components/messages/UserPromptMessage.js.map +2 -2
- package/dist/components/messages/UserTeamNotificationMessage.js +91 -0
- package/dist/components/messages/UserTeamNotificationMessage.js.map +7 -0
- package/dist/components/messages/UserTextMessage.js +8 -0
- package/dist/components/messages/UserTextMessage.js.map +2 -2
- package/dist/components/messages/UserToolResultMessage/UserToolRejectMessage.js +4 -2
- package/dist/components/messages/UserToolResultMessage/UserToolRejectMessage.js.map +2 -2
- package/dist/components/messages/UserToolResultMessage/UserToolResultMessage.js +18 -1
- package/dist/components/messages/UserToolResultMessage/UserToolResultMessage.js.map +2 -2
- package/dist/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +12 -1
- package/dist/components/messages/UserToolResultMessage/UserToolSuccessMessage.js.map +2 -2
- package/dist/components/permissions/PermissionRequest.js +4 -0
- package/dist/components/permissions/PermissionRequest.js.map +2 -2
- package/dist/components/permissions/PlanApprovalRequest.js +164 -0
- package/dist/components/permissions/PlanApprovalRequest.js.map +7 -0
- package/dist/constants/agentTeams.js +17 -0
- package/dist/constants/agentTeams.js.map +7 -0
- package/dist/constants/macros.js +2 -1
- package/dist/constants/macros.js.map +2 -2
- package/dist/constants/prompts/agentPrompt.js +1 -0
- package/dist/constants/prompts/agentPrompt.js.map +2 -2
- package/dist/constants/prompts/autoMemory.js +39 -0
- package/dist/constants/prompts/autoMemory.js.map +7 -0
- package/dist/constants/prompts/codeConventions.js +1 -13
- package/dist/constants/prompts/codeConventions.js.map +2 -2
- package/dist/constants/prompts/doingTasks.js +21 -2
- package/dist/constants/prompts/doingTasks.js.map +2 -2
- package/dist/constants/prompts/envInfo.js +6 -7
- package/dist/constants/prompts/envInfo.js.map +2 -2
- package/dist/constants/prompts/index.js +27 -5
- package/dist/constants/prompts/index.js.map +2 -2
- package/dist/constants/prompts/taskManagement.js +2 -43
- package/dist/constants/prompts/taskManagement.js.map +2 -2
- package/dist/constants/prompts/teamOverlays.js +50 -0
- package/dist/constants/prompts/teamOverlays.js.map +7 -0
- package/dist/constants/prompts/toneAndStyle.js +4 -29
- package/dist/constants/prompts/toneAndStyle.js.map +2 -2
- package/dist/constants/prompts/toolUsagePolicy.js +7 -22
- package/dist/constants/prompts/toolUsagePolicy.js.map +2 -2
- package/dist/constants/toolInputExamples.js +2 -2
- package/dist/constants/toolInputExamples.js.map +2 -2
- package/dist/context.js +39 -6
- package/dist/context.js.map +2 -2
- package/dist/core/backupManager.js +1 -1
- package/dist/core/backupManager.js.map +2 -2
- package/dist/core/permissions/rules/planModeRule.js +1 -1
- package/dist/core/permissions/rules/planModeRule.js.map +1 -1
- package/dist/core/permissions/rules/safeModeRule.js +1 -1
- package/dist/core/permissions/rules/safeModeRule.js.map +1 -1
- package/dist/engine/AgentEngine.js +902 -0
- package/dist/engine/AgentEngine.js.map +7 -0
- package/dist/engine/EngineRegistry.js +89 -0
- package/dist/engine/EngineRegistry.js.map +7 -0
- package/dist/engine/foregroundAdapter.js +191 -0
- package/dist/engine/foregroundAdapter.js.map +7 -0
- package/dist/engine/index.js +15 -0
- package/dist/engine/index.js.map +7 -0
- package/dist/engine/types.js +1 -0
- package/dist/engine/types.js.map +7 -0
- package/dist/entrypoints/cli.js +410 -79
- package/dist/entrypoints/cli.js.map +3 -3
- package/dist/hooks/useAgentEngine.js +129 -0
- package/dist/hooks/useAgentEngine.js.map +7 -0
- package/dist/hooks/useAgentTokenStats.js +0 -16
- package/dist/hooks/useAgentTokenStats.js.map +2 -2
- package/dist/hooks/useCanUseTool.js +47 -2
- package/dist/hooks/useCanUseTool.js.map +2 -2
- package/dist/hooks/useDeferredLoading.js +4 -1
- package/dist/hooks/useDeferredLoading.js.map +2 -2
- package/dist/hooks/useIdleNotifications.js +66 -0
- package/dist/hooks/useIdleNotifications.js.map +7 -0
- package/dist/hooks/useSessionTracking.js +9 -7
- package/dist/hooks/useSessionTracking.js.map +2 -2
- package/dist/hooks/useTeamMembers.js +51 -0
- package/dist/hooks/useTeamMembers.js.map +7 -0
- package/dist/i18n/locales/en.js +77 -12
- package/dist/i18n/locales/en.js.map +2 -2
- package/dist/i18n/locales/zh-CN.js +77 -12
- package/dist/i18n/locales/zh-CN.js.map +2 -2
- package/dist/i18n/types.js.map +1 -1
- package/dist/messages.js.map +2 -2
- package/dist/permissions.js +113 -7
- package/dist/permissions.js.map +2 -2
- package/dist/query.js +135 -37
- package/dist/query.js.map +2 -2
- package/dist/screens/REPL.js +504 -361
- package/dist/screens/REPL.js.map +3 -3
- package/dist/screens/ResumeConversation.js +199 -14
- package/dist/screens/ResumeConversation.js.map +2 -2
- package/dist/services/adapters/base.js.map +1 -1
- package/dist/services/agentTeams/backends/headless.js +108 -0
- package/dist/services/agentTeams/backends/headless.js.map +7 -0
- package/dist/services/agentTeams/backends/inProcess.js +102 -0
- package/dist/services/agentTeams/backends/inProcess.js.map +7 -0
- package/dist/services/agentTeams/backends/resolver.js +18 -0
- package/dist/services/agentTeams/backends/resolver.js.map +7 -0
- package/dist/services/agentTeams/backends/tmux.js +168 -0
- package/dist/services/agentTeams/backends/tmux.js.map +7 -0
- package/dist/services/agentTeams/backends/types.js +1 -0
- package/dist/services/agentTeams/backends/types.js.map +7 -0
- package/dist/services/agentTeams/heartbeat.js +88 -0
- package/dist/services/agentTeams/heartbeat.js.map +7 -0
- package/dist/services/agentTeams/index.js +42 -2
- package/dist/services/agentTeams/index.js.map +2 -2
- package/dist/services/agentTeams/injectionChannel.js +105 -0
- package/dist/services/agentTeams/injectionChannel.js.map +7 -0
- package/dist/services/agentTeams/mailbox.js +410 -30
- package/dist/services/agentTeams/mailbox.js.map +2 -2
- package/dist/services/agentTeams/messageFormatter.js +80 -0
- package/dist/services/agentTeams/messageFormatter.js.map +7 -0
- package/dist/services/agentTeams/permissionDelegation.js +71 -0
- package/dist/services/agentTeams/permissionDelegation.js.map +7 -0
- package/dist/services/agentTeams/teamEvents.js +45 -0
- package/dist/services/agentTeams/teamEvents.js.map +7 -0
- package/dist/services/agentTeams/teamManager.js +251 -34
- package/dist/services/agentTeams/teamManager.js.map +2 -2
- package/dist/services/agentTeams/teamTaskStore.js +290 -61
- package/dist/services/agentTeams/teamTaskStore.js.map +2 -2
- package/dist/services/agentTeams/teammateSpawner.js +99 -18
- package/dist/services/agentTeams/teammateSpawner.js.map +2 -2
- package/dist/services/hookExecutor.js +51 -8
- package/dist/services/hookExecutor.js.map +2 -2
- package/dist/services/llm/anthropicProvider.js +56 -59
- package/dist/services/llm/anthropicProvider.js.map +2 -2
- package/dist/services/llm/dispatch.js +24 -5
- package/dist/services/llm/dispatch.js.map +2 -2
- package/dist/services/llm/openaiProvider.js +115 -136
- package/dist/services/llm/openaiProvider.js.map +3 -3
- package/dist/services/llm/types.js +89 -15
- package/dist/services/llm/types.js.map +2 -2
- package/dist/services/mcpClient.js +80 -4
- package/dist/services/mcpClient.js.map +2 -2
- package/dist/services/mintoAuth.js +299 -0
- package/dist/services/mintoAuth.js.map +7 -0
- package/dist/services/oauth.js +3 -3
- package/dist/services/oauth.js.map +2 -2
- package/dist/services/openai.js +91 -20
- package/dist/services/openai.js.map +2 -2
- package/dist/services/plugins/pluginRuntime.js +11 -5
- package/dist/services/plugins/pluginRuntime.js.map +2 -2
- package/dist/services/plugins/pluginValidation.js +4 -2
- package/dist/services/plugins/pluginValidation.js.map +2 -2
- package/dist/services/sandbox/sandboxController.js +11 -3
- package/dist/services/sandbox/sandboxController.js.map +2 -2
- package/dist/services/sessionMemoryInjector.js +77 -0
- package/dist/services/sessionMemoryInjector.js.map +7 -0
- package/dist/services/systemReminder.js +130 -8
- package/dist/services/systemReminder.js.map +2 -2
- package/dist/services/taskStore.js +199 -8
- package/dist/services/taskStore.js.map +3 -3
- package/dist/services/topicDetector.js +169 -0
- package/dist/services/topicDetector.js.map +7 -0
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js +0 -13
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js.map +2 -2
- package/dist/tools/BashTool/BashTool.js +51 -28
- package/dist/tools/BashTool/BashTool.js.map +2 -2
- package/dist/tools/BashTool/prompt.js +95 -118
- package/dist/tools/BashTool/prompt.js.map +2 -2
- package/dist/tools/BashTool/utils.js +39 -1
- package/dist/tools/BashTool/utils.js.map +2 -2
- package/dist/tools/EnterWorktreeTool/EnterWorktreeTool.js +121 -0
- package/dist/tools/EnterWorktreeTool/EnterWorktreeTool.js.map +7 -0
- package/dist/tools/EnterWorktreeTool/prompt.js +22 -0
- package/dist/tools/EnterWorktreeTool/prompt.js.map +7 -0
- package/dist/tools/FileEditTool/FileEditTool.js +9 -4
- package/dist/tools/FileEditTool/FileEditTool.js.map +2 -2
- package/dist/tools/FileEditTool/prompt.js +3 -7
- package/dist/tools/FileEditTool/prompt.js.map +2 -2
- package/dist/tools/FileReadTool/FileReadTool.js +125 -3
- package/dist/tools/FileReadTool/FileReadTool.js.map +2 -2
- package/dist/tools/FileReadTool/prompt.js +1 -2
- package/dist/tools/FileReadTool/prompt.js.map +2 -2
- package/dist/tools/FileWriteTool/prompt.js +3 -5
- package/dist/tools/FileWriteTool/prompt.js.map +2 -2
- package/dist/tools/GlobTool/GlobTool.js +3 -2
- package/dist/tools/GlobTool/GlobTool.js.map +2 -2
- package/dist/tools/GrepTool/GrepTool.js +16 -5
- package/dist/tools/GrepTool/GrepTool.js.map +2 -2
- package/dist/tools/ListMcpResourcesTool/ListMcpResourcesTool.js.map +2 -2
- package/dist/tools/MCPSearchTool/MCPSearchTool.js +172 -0
- package/dist/tools/MCPSearchTool/MCPSearchTool.js.map +7 -0
- package/dist/tools/MCPSearchTool/prompt.js +77 -0
- package/dist/tools/MCPSearchTool/prompt.js.map +7 -0
- package/dist/tools/MultiEditTool/prompt.js +4 -7
- package/dist/tools/MultiEditTool/prompt.js.map +2 -2
- package/dist/tools/PlanModeTool/EnterPlanModeTool.js +12 -8
- package/dist/tools/PlanModeTool/EnterPlanModeTool.js.map +2 -2
- package/dist/tools/PlanModeTool/ExitPlanModeTool.js +54 -1
- package/dist/tools/PlanModeTool/ExitPlanModeTool.js.map +2 -2
- package/dist/tools/PlanModeTool/prompt.js +23 -74
- package/dist/tools/PlanModeTool/prompt.js.map +2 -2
- package/dist/tools/SendMessageTool/SendMessageTool.js +341 -0
- package/dist/tools/SendMessageTool/SendMessageTool.js.map +7 -0
- package/dist/tools/SendMessageTool/prompt.js +44 -0
- package/dist/tools/SendMessageTool/prompt.js.map +7 -0
- package/dist/tools/TaskCreateTool/prompt.js +15 -4
- package/dist/tools/TaskCreateTool/prompt.js.map +2 -2
- package/dist/tools/TaskListTool/prompt.js +18 -3
- package/dist/tools/TaskListTool/prompt.js.map +2 -2
- package/dist/tools/TaskOutputTool/prompt.js +4 -3
- package/dist/tools/TaskOutputTool/prompt.js.map +2 -2
- package/dist/tools/TaskTool/TaskTool.js +762 -98
- package/dist/tools/TaskTool/TaskTool.js.map +3 -3
- package/dist/tools/TaskTool/constants.js +8 -2
- package/dist/tools/TaskTool/constants.js.map +2 -2
- package/dist/tools/TaskTool/prompt.js +74 -70
- package/dist/tools/TaskTool/prompt.js.map +2 -2
- package/dist/tools/TaskUpdateTool/TaskUpdateTool.js +15 -1
- package/dist/tools/TaskUpdateTool/TaskUpdateTool.js.map +2 -2
- package/dist/tools/TeamCreateTool/TeamCreateTool.js +129 -0
- package/dist/tools/TeamCreateTool/TeamCreateTool.js.map +7 -0
- package/dist/tools/TeamCreateTool/prompt.js +58 -0
- package/dist/tools/TeamCreateTool/prompt.js.map +7 -0
- package/dist/tools/TeamDeleteTool/TeamDeleteTool.js +151 -0
- package/dist/tools/TeamDeleteTool/TeamDeleteTool.js.map +7 -0
- package/dist/tools/TeamDeleteTool/prompt.js +16 -0
- package/dist/tools/TeamDeleteTool/prompt.js.map +7 -0
- package/dist/tools/URLFetcherTool/URLFetcherTool.js +106 -15
- package/dist/tools/URLFetcherTool/URLFetcherTool.js.map +2 -2
- package/dist/tools/URLFetcherTool/prompt.js +3 -2
- package/dist/tools/URLFetcherTool/prompt.js.map +2 -2
- package/dist/tools/WebSearchTool/WebSearchTool.js +2 -1
- package/dist/tools/WebSearchTool/WebSearchTool.js.map +2 -2
- package/dist/tools/WebSearchTool/prompt.js +5 -4
- package/dist/tools/WebSearchTool/prompt.js.map +2 -2
- package/dist/tools.js +100 -20
- package/dist/tools.js.map +2 -2
- package/dist/types/PermissionMode.js +35 -6
- package/dist/types/PermissionMode.js.map +2 -2
- package/dist/types/hooks.js +2 -0
- package/dist/types/hooks.js.map +2 -2
- package/dist/types/plugin.js +2 -0
- package/dist/types/plugin.js.map +3 -3
- package/dist/utils/CircuitBreaker.js +15 -9
- package/dist/utils/CircuitBreaker.js.map +2 -2
- package/dist/utils/agentLoader.js +249 -112
- package/dist/utils/agentLoader.js.map +2 -2
- package/dist/utils/animationManager.js +40 -3
- package/dist/utils/animationManager.js.map +2 -2
- package/dist/utils/ask.js +7 -6
- package/dist/utils/ask.js.map +2 -2
- package/dist/utils/atomicWrite.js +23 -0
- package/dist/utils/atomicWrite.js.map +7 -0
- package/dist/utils/autoCompactCore.js +73 -56
- package/dist/utils/autoCompactCore.js.map +2 -2
- package/dist/utils/autoMemoryPaths.js +89 -0
- package/dist/utils/autoMemoryPaths.js.map +7 -0
- package/dist/utils/config.js +63 -38
- package/dist/utils/config.js.map +2 -2
- package/dist/utils/configSchema.js +13 -8
- package/dist/utils/configSchema.js.map +2 -2
- package/dist/utils/credentials/index.js +14 -0
- package/dist/utils/credentials/index.js.map +2 -2
- package/dist/utils/dualPath.js +24 -0
- package/dist/utils/dualPath.js.map +7 -0
- package/dist/utils/exit.js +66 -7
- package/dist/utils/exit.js.map +2 -2
- package/dist/utils/externalEditor.js +155 -0
- package/dist/utils/externalEditor.js.map +7 -0
- package/dist/utils/fileLock.js +67 -0
- package/dist/utils/fileLock.js.map +7 -0
- package/dist/utils/format.js +24 -14
- package/dist/utils/format.js.map +2 -2
- package/dist/utils/globalErrorHandler.js +5 -96
- package/dist/utils/globalErrorHandler.js.map +3 -3
- package/dist/utils/groupHandlers/parallelTasksHandler.js +5 -3
- package/dist/utils/groupHandlers/parallelTasksHandler.js.map +2 -2
- package/dist/utils/groupHandlers/taskHandler.js +2 -2
- package/dist/utils/groupHandlers/taskHandler.js.map +2 -2
- package/dist/utils/hookManager.js +64 -6
- package/dist/utils/hookManager.js.map +2 -2
- package/dist/utils/log.js +6 -2
- package/dist/utils/log.js.map +2 -2
- package/dist/utils/markdown.js +237 -19
- package/dist/utils/markdown.js.map +2 -2
- package/dist/utils/messageContextManager.js +18 -5
- package/dist/utils/messageContextManager.js.map +2 -2
- package/dist/utils/messageGroupManager.js +1 -1
- package/dist/utils/messageGroupManager.js.map +2 -2
- package/dist/utils/messages.js +104 -46
- package/dist/utils/messages.js.map +2 -2
- package/dist/utils/model.js +2 -2
- package/dist/utils/model.js.map +2 -2
- package/dist/utils/pasteCache.js +8 -4
- package/dist/utils/pasteCache.js.map +2 -2
- package/dist/utils/pluginLoader.js +18 -0
- package/dist/utils/pluginLoader.js.map +2 -2
- package/dist/utils/secureKeyStorage.js +36 -7
- package/dist/utils/secureKeyStorage.js.map +2 -2
- package/dist/utils/simpleMode.js +7 -0
- package/dist/utils/simpleMode.js.map +7 -0
- package/dist/utils/streamingState.js +11 -1
- package/dist/utils/streamingState.js.map +2 -2
- package/dist/utils/taskDisplayUtils.js +2 -1
- package/dist/utils/taskDisplayUtils.js.map +2 -2
- package/dist/utils/teamConfig.js +2 -2
- package/dist/utils/teamConfig.js.map +2 -2
- package/dist/utils/thinking.js +6 -2
- package/dist/utils/thinking.js.map +3 -3
- package/dist/utils/tokenProgress.js +55 -0
- package/dist/utils/tokenProgress.js.map +7 -0
- package/dist/utils/toolRiskClassification.js +26 -17
- package/dist/utils/toolRiskClassification.js.map +2 -2
- package/dist/utils/tooling/toolError.js +12 -0
- package/dist/utils/tooling/toolError.js.map +7 -0
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +10 -8
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { queryQuick } from "../../services/claude.js";
|
|
2
2
|
import { extractTag } from "../../utils/messages.js";
|
|
3
|
+
import { getGlobalConfig } from "../../utils/config.js";
|
|
3
4
|
import { MAX_OUTPUT_LENGTH } from "./prompt.js";
|
|
5
|
+
const BASH_SUMMARIZATION_THRESHOLD = 4e3;
|
|
4
6
|
function formatOutput(content) {
|
|
5
7
|
if (content.length <= MAX_OUTPUT_LENGTH) {
|
|
6
8
|
return {
|
|
@@ -21,6 +23,41 @@ ${end}`;
|
|
|
21
23
|
truncatedContent: truncated
|
|
22
24
|
};
|
|
23
25
|
}
|
|
26
|
+
async function summarizeBashOutput(command, stdout, stderr) {
|
|
27
|
+
try {
|
|
28
|
+
const config = getGlobalConfig();
|
|
29
|
+
if (!config.bashOutputSummarization && !process.env.MINTO_BASH_SUMMARIZATION) {
|
|
30
|
+
return { stdout, stderr, wasSummarized: false };
|
|
31
|
+
}
|
|
32
|
+
const combined = stdout + stderr;
|
|
33
|
+
if (combined.length < BASH_SUMMARIZATION_THRESHOLD) {
|
|
34
|
+
return { stdout, stderr, wasSummarized: false };
|
|
35
|
+
}
|
|
36
|
+
const response = await queryQuick({
|
|
37
|
+
systemPrompt: [
|
|
38
|
+
"You summarize bash command output concisely. Respond with ONLY the summary text, no preamble.",
|
|
39
|
+
"Focus on: key results, errors, warnings, counts, and actionable information.",
|
|
40
|
+
"Keep the summary under 5 lines. If the output is a list, mention the count and key items."
|
|
41
|
+
],
|
|
42
|
+
userPrompt: `Command: ${command}
|
|
43
|
+
|
|
44
|
+
Output (${combined.length} chars):
|
|
45
|
+
${combined.slice(0, 8e3)}`
|
|
46
|
+
});
|
|
47
|
+
const summaryText = response.message.content.filter((b) => b.type === "text").map((b) => b.text).join("").trim();
|
|
48
|
+
if (!summaryText) {
|
|
49
|
+
return { stdout, stderr, wasSummarized: false };
|
|
50
|
+
}
|
|
51
|
+
const summarizedStdout = `<output-summary>
|
|
52
|
+
${summaryText}
|
|
53
|
+
</output-summary>
|
|
54
|
+
|
|
55
|
+
${stdout}`;
|
|
56
|
+
return { stdout: summarizedStdout, stderr, wasSummarized: true };
|
|
57
|
+
} catch {
|
|
58
|
+
return { stdout, stderr, wasSummarized: false };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
24
61
|
async function getCommandFilePaths(command, output) {
|
|
25
62
|
const response = await queryQuick({
|
|
26
63
|
systemPrompt: [
|
|
@@ -46,6 +83,7 @@ Output: ${output}`,
|
|
|
46
83
|
}
|
|
47
84
|
export {
|
|
48
85
|
formatOutput,
|
|
49
|
-
getCommandFilePaths
|
|
86
|
+
getCommandFilePaths,
|
|
87
|
+
summarizeBashOutput
|
|
50
88
|
};
|
|
51
89
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/BashTool/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { queryQuick } from '@services/claude'\nimport { extractTag } from '@utils/messages'\nimport { MAX_OUTPUT_LENGTH } from './prompt'\n\nexport function formatOutput(content: string): {\n totalLines: number\n truncatedContent: string\n} {\n if (content.length <= MAX_OUTPUT_LENGTH) {\n return {\n totalLines: content.split('\\n').length,\n truncatedContent: content,\n }\n }\n const halfLength = MAX_OUTPUT_LENGTH / 2\n const start = content.slice(0, halfLength)\n const end = content.slice(-halfLength)\n const truncated = `${start}\\n\\n... [${content.slice(halfLength, -halfLength).split('\\n').length} lines truncated] ...\\n\\n${end}`\n\n return {\n totalLines: content.split('\\n').length,\n truncatedContent: truncated,\n }\n}\n\nexport async function getCommandFilePaths(\n command: string,\n output: string,\n): Promise<string[]> {\n const response = await queryQuick({\n systemPrompt: [\n `Extract any file paths that this command reads or modifies. For commands like \"git diff\" and \"cat\", include the paths of files being shown. Use paths verbatim -- don't add any slashes or try to resolve them. Do not try to infer paths that were not explicitly listed in the command output.\nFormat your response as:\n<filepaths>\npath/to/file1\npath/to/file2\n</filepaths>\n\nIf no files are read or modified, return empty filepaths tags:\n<filepaths>\n</filepaths>\n\nDo not include any other text in your response.`,\n ],\n userPrompt: `Command: ${command}\\nOutput: ${output}`,\n enablePromptCaching: true,\n })\n const content = response.message.content\n .filter(_ => _.type === 'text')\n .map(_ => _.text)\n .join('')\n\n return (\n extractTag(content, 'filepaths')?.trim().split('\\n').filter(Boolean) || []\n )\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;
|
|
4
|
+
"sourcesContent": ["import { queryQuick } from '@services/claude'\nimport { extractTag } from '@utils/messages'\nimport { getGlobalConfig } from '@utils/config'\nimport { MAX_OUTPUT_LENGTH } from './prompt'\n\n/** Threshold in characters above which bash output summarization kicks in */\nconst BASH_SUMMARIZATION_THRESHOLD = 4000\n\nexport function formatOutput(content: string): {\n totalLines: number\n truncatedContent: string\n} {\n if (content.length <= MAX_OUTPUT_LENGTH) {\n return {\n totalLines: content.split('\\n').length,\n truncatedContent: content,\n }\n }\n const halfLength = MAX_OUTPUT_LENGTH / 2\n const start = content.slice(0, halfLength)\n const end = content.slice(-halfLength)\n const truncated = `${start}\\n\\n... [${content.slice(halfLength, -halfLength).split('\\n').length} lines truncated] ...\\n\\n${end}`\n\n return {\n totalLines: content.split('\\n').length,\n truncatedContent: truncated,\n }\n}\n\n/**\n * Summarize large bash output using the quick model.\n * Returns the original output with a prefixed summary, or the original output\n * unchanged if summarization is disabled, not needed, or fails.\n */\nexport async function summarizeBashOutput(\n command: string,\n stdout: string,\n stderr: string,\n): Promise<{ stdout: string; stderr: string; wasSummarized: boolean }> {\n try {\n const config = getGlobalConfig()\n if (\n !config.bashOutputSummarization &&\n !process.env.MINTO_BASH_SUMMARIZATION\n ) {\n return { stdout, stderr, wasSummarized: false }\n }\n\n const combined = stdout + stderr\n if (combined.length < BASH_SUMMARIZATION_THRESHOLD) {\n return { stdout, stderr, wasSummarized: false }\n }\n\n const response = await queryQuick({\n systemPrompt: [\n 'You summarize bash command output concisely. Respond with ONLY the summary text, no preamble.',\n 'Focus on: key results, errors, warnings, counts, and actionable information.',\n 'Keep the summary under 5 lines. If the output is a list, mention the count and key items.',\n ],\n userPrompt: `Command: ${command}\\n\\nOutput (${combined.length} chars):\\n${combined.slice(0, 8000)}`,\n })\n\n const summaryText = response.message.content\n .filter(b => b.type === 'text')\n .map(b => (b as any).text)\n .join('')\n .trim()\n\n if (!summaryText) {\n return { stdout, stderr, wasSummarized: false }\n }\n\n const summarizedStdout = `<output-summary>\\n${summaryText}\\n</output-summary>\\n\\n${stdout}`\n return { stdout: summarizedStdout, stderr, wasSummarized: true }\n } catch {\n // Graceful degradation: return original output if summarization fails\n return { stdout, stderr, wasSummarized: false }\n }\n}\n\nexport async function getCommandFilePaths(\n command: string,\n output: string,\n): Promise<string[]> {\n const response = await queryQuick({\n systemPrompt: [\n `Extract any file paths that this command reads or modifies. For commands like \"git diff\" and \"cat\", include the paths of files being shown. Use paths verbatim -- don't add any slashes or try to resolve them. Do not try to infer paths that were not explicitly listed in the command output.\nFormat your response as:\n<filepaths>\npath/to/file1\npath/to/file2\n</filepaths>\n\nIf no files are read or modified, return empty filepaths tags:\n<filepaths>\n</filepaths>\n\nDo not include any other text in your response.`,\n ],\n userPrompt: `Command: ${command}\\nOutput: ${output}`,\n enablePromptCaching: true,\n })\n const content = response.message.content\n .filter(_ => _.type === 'text')\n .map(_ => _.text)\n .join('')\n\n return (\n extractTag(content, 'filepaths')?.trim().split('\\n').filter(Boolean) || []\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAGlC,MAAM,+BAA+B;AAE9B,SAAS,aAAa,SAG3B;AACA,MAAI,QAAQ,UAAU,mBAAmB;AACvC,WAAO;AAAA,MACL,YAAY,QAAQ,MAAM,IAAI,EAAE;AAAA,MAChC,kBAAkB;AAAA,IACpB;AAAA,EAC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,eAAe,MAAM;AAAA,EAChD;AACF;AAEA,eAAsB,oBACpB,SACA,QACmB;AACnB,QAAM,WAAW,MAAM,WAAW;AAAA,IAChC,cAAc;AAAA,MACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAYF;AAAA,IACA,YAAY,YAAY,OAAO;AAAA,UAAa,MAAM;AAAA,IAClD,qBAAqB;AAAA,EACvB,CAAC;AACD,QAAM,UAAU,SAAS,QAAQ,QAC9B,OAAO,OAAK,EAAE,SAAS,MAAM,EAC7B,IAAI,OAAK,EAAE,IAAI,EACf,KAAK,EAAE;AAEV,SACE,WAAW,SAAS,WAAW,GAAG,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,OAAO,KAAK,CAAC;AAE7E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Box, Text } from "ink";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { execFileSync } from "child_process";
|
|
5
|
+
import { existsSync, mkdirSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
import { FallbackToolUseRejectedMessage } from "../../components/FallbackToolUseRejectedMessage.js";
|
|
8
|
+
import { getCwd, setCwd } from "../../utils/state.js";
|
|
9
|
+
import { DESCRIPTION, PROMPT, TOOL_NAME } from "./prompt.js";
|
|
10
|
+
import { SEMANTIC_COLORS } from "../../constants/colors.js";
|
|
11
|
+
const inputSchema = z.strictObject({
|
|
12
|
+
name: z.string().optional().describe(
|
|
13
|
+
"A name for the worktree. If not provided, a random name is generated."
|
|
14
|
+
)
|
|
15
|
+
});
|
|
16
|
+
function generateWorktreeName() {
|
|
17
|
+
const ts = Date.now().toString(36);
|
|
18
|
+
const rand = Math.random().toString(36).slice(2, 6);
|
|
19
|
+
return `wt-${ts}-${rand}`;
|
|
20
|
+
}
|
|
21
|
+
function isGitRepo(cwd) {
|
|
22
|
+
try {
|
|
23
|
+
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
24
|
+
cwd,
|
|
25
|
+
stdio: "pipe"
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const EnterWorktreeTool = {
|
|
33
|
+
name: TOOL_NAME,
|
|
34
|
+
async description() {
|
|
35
|
+
return DESCRIPTION;
|
|
36
|
+
},
|
|
37
|
+
userFacingName() {
|
|
38
|
+
return "Enter Worktree";
|
|
39
|
+
},
|
|
40
|
+
inputSchema,
|
|
41
|
+
isReadOnly() {
|
|
42
|
+
return false;
|
|
43
|
+
},
|
|
44
|
+
isConcurrencySafe() {
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
async isEnabled() {
|
|
48
|
+
return true;
|
|
49
|
+
},
|
|
50
|
+
needsPermissions() {
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
async prompt() {
|
|
54
|
+
return PROMPT;
|
|
55
|
+
},
|
|
56
|
+
renderToolUseMessage(input) {
|
|
57
|
+
return input.name ? `name: "${input.name}"` : "(auto-generated name)";
|
|
58
|
+
},
|
|
59
|
+
renderToolUseRejectedMessage() {
|
|
60
|
+
return /* @__PURE__ */ React.createElement(FallbackToolUseRejectedMessage, null);
|
|
61
|
+
},
|
|
62
|
+
renderToolResultMessage(output) {
|
|
63
|
+
if (!output) {
|
|
64
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "row", marginTop: 1 }, /* @__PURE__ */ React.createElement(Text, { color: "red" }, "Failed to create worktree"));
|
|
65
|
+
}
|
|
66
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, { color: "cyan" }, "\u25CF"), /* @__PURE__ */ React.createElement(Text, null, " Entered worktree")), /* @__PURE__ */ React.createElement(Box, { paddingLeft: 2 }, /* @__PURE__ */ React.createElement(Text, { color: SEMANTIC_COLORS.dim }, "Branch: ", output.branch, " | Path: ", output.worktreePath)));
|
|
67
|
+
},
|
|
68
|
+
renderResultForAssistant(output) {
|
|
69
|
+
return `Switched to git worktree at: ${output.worktreePath}
|
|
70
|
+
Branch: ${output.branch}
|
|
71
|
+
Previous working directory: ${output.previousCwd}
|
|
72
|
+
|
|
73
|
+
You are now working in an isolated copy of the repository. Changes here do not affect the main working directory.`;
|
|
74
|
+
},
|
|
75
|
+
async *call(input) {
|
|
76
|
+
const cwd = getCwd();
|
|
77
|
+
if (!isGitRepo(cwd)) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
"EnterWorktree requires a git repository. The current directory is not inside a git repo."
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const wtName = input.name || generateWorktreeName();
|
|
83
|
+
const branchName = `minto-worktree-${wtName}`;
|
|
84
|
+
const worktreeBase = join(cwd, ".minto", "worktrees");
|
|
85
|
+
if (!existsSync(worktreeBase)) {
|
|
86
|
+
mkdirSync(worktreeBase, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
const worktreePath = join(worktreeBase, wtName);
|
|
89
|
+
if (existsSync(worktreePath)) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Worktree already exists at: ${worktreePath}. Use a different name.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
execFileSync(
|
|
96
|
+
"git",
|
|
97
|
+
["worktree", "add", "-b", branchName, worktreePath, "HEAD"],
|
|
98
|
+
{ cwd, stdio: "pipe" }
|
|
99
|
+
);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
const stderr = err?.stderr?.toString() || err.message;
|
|
102
|
+
throw new Error(`Failed to create git worktree: ${stderr}`);
|
|
103
|
+
}
|
|
104
|
+
const previousCwd = cwd;
|
|
105
|
+
await setCwd(worktreePath);
|
|
106
|
+
const output = {
|
|
107
|
+
worktreePath,
|
|
108
|
+
branch: branchName,
|
|
109
|
+
previousCwd
|
|
110
|
+
};
|
|
111
|
+
yield {
|
|
112
|
+
type: "result",
|
|
113
|
+
data: output,
|
|
114
|
+
resultForAssistant: this.renderResultForAssistant(output)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
export {
|
|
119
|
+
EnterWorktreeTool
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=EnterWorktreeTool.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tools/EnterWorktreeTool/EnterWorktreeTool.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * EnterWorktree Tool\n *\n * Creates a git worktree for session isolation.\n * CC-compatible: creates worktree under .minto/worktrees/ (reads .claude/worktrees/ too).\n */\n\nimport { Box, Text } from 'ink'\nimport React from 'react'\nimport { z } from 'zod'\nimport { execFileSync } from 'child_process'\nimport { existsSync, mkdirSync } from 'fs'\nimport { join } from 'path'\nimport { type Tool } from '@tool'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { getCwd, setCwd } from '@utils/state'\nimport { DESCRIPTION, PROMPT, TOOL_NAME } from './prompt'\nimport { SEMANTIC_COLORS } from '@constants/colors'\n\nconst inputSchema = z.strictObject({\n name: z\n .string()\n .optional()\n .describe(\n 'A name for the worktree. If not provided, a random name is generated.',\n ),\n})\n\ntype Input = z.infer<typeof inputSchema>\n\ntype Output = {\n worktreePath: string\n branch: string\n previousCwd: string\n}\n\nfunction generateWorktreeName(): string {\n const ts = Date.now().toString(36)\n const rand = Math.random().toString(36).slice(2, 6)\n return `wt-${ts}-${rand}`\n}\n\nfunction isGitRepo(cwd: string): boolean {\n try {\n execFileSync('git', ['rev-parse', '--is-inside-work-tree'], {\n cwd,\n stdio: 'pipe',\n })\n return true\n } catch {\n return false\n }\n}\n\nexport const EnterWorktreeTool = {\n name: TOOL_NAME,\n async description() {\n return DESCRIPTION\n },\n userFacingName() {\n return 'Enter Worktree'\n },\n inputSchema,\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false\n },\n async isEnabled() {\n return true\n },\n needsPermissions() {\n return true\n },\n async prompt() {\n return PROMPT\n },\n\n renderToolUseMessage(input: Input) {\n return input.name ? `name: \"${input.name}\"` : '(auto-generated name)'\n },\n\n renderToolUseRejectedMessage() {\n return <FallbackToolUseRejectedMessage />\n },\n\n renderToolResultMessage(output: Output) {\n if (!output) {\n return (\n <Box flexDirection=\"row\" marginTop={1}>\n <Text color=\"red\">Failed to create worktree</Text>\n </Box>\n )\n }\n\n return (\n <Box flexDirection=\"column\" marginTop={1}>\n <Box flexDirection=\"row\">\n <Text color=\"cyan\">\u25CF</Text>\n <Text> Entered worktree</Text>\n </Box>\n <Box paddingLeft={2}>\n <Text color={SEMANTIC_COLORS.dim}>\n Branch: {output.branch} | Path: {output.worktreePath}\n </Text>\n </Box>\n </Box>\n )\n },\n\n renderResultForAssistant(output: Output): string {\n return `Switched to git worktree at: ${output.worktreePath}\\nBranch: ${output.branch}\\nPrevious working directory: ${output.previousCwd}\\n\\nYou are now working in an isolated copy of the repository. Changes here do not affect the main working directory.`\n },\n\n async *call(input: Input) {\n const cwd = getCwd()\n\n if (!isGitRepo(cwd)) {\n throw new Error(\n 'EnterWorktree requires a git repository. The current directory is not inside a git repo.',\n )\n }\n\n const wtName = input.name || generateWorktreeName()\n const branchName = `minto-worktree-${wtName}`\n\n // Create worktree directory under .minto/worktrees/\n const worktreeBase = join(cwd, '.minto', 'worktrees')\n if (!existsSync(worktreeBase)) {\n mkdirSync(worktreeBase, { recursive: true })\n }\n\n const worktreePath = join(worktreeBase, wtName)\n\n if (existsSync(worktreePath)) {\n throw new Error(\n `Worktree already exists at: ${worktreePath}. Use a different name.`,\n )\n }\n\n // Create the worktree with a new branch from HEAD\n try {\n execFileSync(\n 'git',\n ['worktree', 'add', '-b', branchName, worktreePath, 'HEAD'],\n { cwd, stdio: 'pipe' },\n )\n } catch (err: any) {\n const stderr = err?.stderr?.toString() || err.message\n throw new Error(`Failed to create git worktree: ${stderr}`)\n }\n\n // Switch session working directory\n const previousCwd = cwd\n await setCwd(worktreePath)\n\n const output: Output = {\n worktreePath,\n branch: branchName,\n previousCwd,\n }\n\n yield {\n type: 'result' as const,\n data: output,\n resultForAssistant: this.renderResultForAssistant(output),\n }\n },\n} satisfies Tool\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,KAAK,YAAY;AAC1B,OAAO,WAAW;AAClB,SAAS,SAAS;AAClB,SAAS,oBAAoB;AAC7B,SAAS,YAAY,iBAAiB;AACtC,SAAS,YAAY;AAErB,SAAS,sCAAsC;AAC/C,SAAS,QAAQ,cAAc;AAC/B,SAAS,aAAa,QAAQ,iBAAiB;AAC/C,SAAS,uBAAuB;AAEhC,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,MAAM,EACH,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAUD,SAAS,uBAA+B;AACtC,QAAM,KAAK,KAAK,IAAI,EAAE,SAAS,EAAE;AACjC,QAAM,OAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC;AAClD,SAAO,MAAM,EAAE,IAAI,IAAI;AACzB;AAEA,SAAS,UAAU,KAAsB;AACvC,MAAI;AACF,iBAAa,OAAO,CAAC,aAAa,uBAAuB,GAAG;AAAA,MAC1D;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AACD,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,MAAM,oBAAoB;AAAA,EAC/B,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,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G;AAC5B,YAAM,IAAI;AAAA,QACR,+BAA+B,YAAY;AAAA,MAC7C;AAAA,IACF;AAGA,QAAI;AACF;AAAA,QACE;AAAA,QACA,CAAC,YAAY,OAAO,MAAM,YAAY,cAAc,MAAM;AAAA,QAC1D,EAAE,KAAK,OAAO,OAAO;AAAA,MACvB;AAAA,IACF,SAAS,KAAU;AACjB,YAAM,SAAS,KAAK,QAAQ,SAAS,KAAK,IAAI;AAC9C,YAAM,IAAI,MAAM,kCAAkC,MAAM,EAAE;AAAA,IAC5D;AAGA,UAAM,cAAc;AACpB,UAAM,OAAO,YAAY;AAEzB,UAAM,SAAiB;AAAA,MACrB;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IACF;AAEA,UAAM;AAAA,MACJ,MAAM;AAAA,MACN,MAAM;AAAA,MACN,oBAAoB,KAAK,yBAAyB,MAAM;AAAA,IAC1D;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const TOOL_NAME = "EnterWorktree";
|
|
2
|
+
const DESCRIPTION = "Create an isolated git worktree for the current session";
|
|
3
|
+
const PROMPT = `Use this tool to create a git worktree and switch the current session into it.
|
|
4
|
+
|
|
5
|
+
The worktree provides an isolated copy of the repository where you can make changes without affecting the main working directory. Useful for exploratory changes, parallel implementations, or when you want to preserve the main tree's state.
|
|
6
|
+
|
|
7
|
+
- Creates a new branch from HEAD and a worktree in \`.minto/worktrees/\`
|
|
8
|
+
- Switches the session's working directory to the new worktree
|
|
9
|
+
- The worktree persists until manually removed
|
|
10
|
+
|
|
11
|
+
**When to use:**
|
|
12
|
+
- User asks to work in isolation or "try something without affecting the main code"
|
|
13
|
+
- You need to make exploratory changes that might be discarded
|
|
14
|
+
- Working on a separate branch for a PR
|
|
15
|
+
|
|
16
|
+
**Requirements:** Must be in a git repository.`;
|
|
17
|
+
export {
|
|
18
|
+
DESCRIPTION,
|
|
19
|
+
PROMPT,
|
|
20
|
+
TOOL_NAME
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tools/EnterWorktreeTool/prompt.ts"],
|
|
4
|
+
"sourcesContent": ["export const TOOL_NAME = 'EnterWorktree'\n\nexport const DESCRIPTION =\n 'Create an isolated git worktree for the current session'\n\nexport const PROMPT = `Use this tool to create a git worktree and switch the current session into it.\n\nThe worktree provides an isolated copy of the repository where you can make changes without affecting the main working directory. Useful for exploratory changes, parallel implementations, or when you want to preserve the main tree's state.\n\n- Creates a new branch from HEAD and a worktree in \\`.minto/worktrees/\\`\n- Switches the session's working directory to the new worktree\n- The worktree persists until manually removed\n\n**When to use:**\n- User asks to work in isolation or \"try something without affecting the main code\"\n- You need to make exploratory changes that might be discarded\n- Working on a separate branch for a PR\n\n**Requirements:** Must be in a git repository.`\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,YAAY;AAElB,MAAM,cACX;AAEK,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, lstatSync, mkdirSync, readFileSync, statSync } from "fs";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
|
-
import { dirname, isAbsolute, relative, resolve
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve } from "path";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { FileEditToolUpdatedMessage } from "../../components/FileEditToolUpdatedMessage.js";
|
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
hasWritePermission,
|
|
28
28
|
pathInOriginalCwd
|
|
29
29
|
} from "../../utils/permissions/filesystem.js";
|
|
30
|
-
import { PROJECT_FILE } from "../../constants/product.js";
|
|
31
30
|
const inputSchema = z.strictObject({
|
|
32
31
|
file_path: z.string().describe("The absolute path to the file to modify"),
|
|
33
32
|
old_string: z.string().describe("The text to replace"),
|
|
@@ -212,6 +211,14 @@ const FileEditTool = {
|
|
|
212
211
|
const enc = existsSync(fullFilePath) ? detectFileEncoding(fullFilePath) : "utf8";
|
|
213
212
|
const endings = existsSync(fullFilePath) ? detectLineEndings(fullFilePath) : "LF";
|
|
214
213
|
const originalFile = existsSync(fullFilePath) ? readFileSync(fullFilePath, enc) : "";
|
|
214
|
+
const preWriteStats = lstatSync(fullFilePath, { throwIfNoEntry: false });
|
|
215
|
+
if (preWriteStats?.isSymbolicLink()) {
|
|
216
|
+
yield {
|
|
217
|
+
type: "result",
|
|
218
|
+
data: `Error: Cannot write to '${file_path}': file became a symlink`
|
|
219
|
+
};
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
215
222
|
writeTextContent(fullFilePath, updatedFile, enc, endings);
|
|
216
223
|
recordFileEdit(fullFilePath, updatedFile);
|
|
217
224
|
triggerBackup(
|
|
@@ -221,8 +228,6 @@ const FileEditTool = {
|
|
|
221
228
|
old_string === "" ? "create" : "update"
|
|
222
229
|
);
|
|
223
230
|
readFileTimestamps[fullFilePath] = statSync(fullFilePath).mtimeMs;
|
|
224
|
-
if (fullFilePath.endsWith(`${sep}${PROJECT_FILE}`) || fullFilePath.endsWith(`${sep}AGENTS.md`) || fullFilePath.endsWith(`${sep}CLAUDE.md`)) {
|
|
225
|
-
}
|
|
226
231
|
emitReminderEvent("file:edited", {
|
|
227
232
|
filePath: fullFilePath,
|
|
228
233
|
oldString: old_string,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/FileEditTool/FileEditTool.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Hunk } from 'diff'\nimport { existsSync, lstatSync, mkdirSync, readFileSync, statSync } from 'fs'\nimport { Box, Text } from 'ink'\nimport { dirname, isAbsolute, relative, resolve, sep } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FileEditToolUpdatedMessage } from '@components/FileEditToolUpdatedMessage'\nimport { StructuredDiff } from '@components/StructuredDiff'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool, ValidationResult } from '@tool'\nimport { intersperse } from '@utils/array'\nimport {\n addLineNumbers,\n detectFileEncoding,\n detectLineEndings,\n findSimilarFile,\n writeTextContent,\n} from '@utils/file'\nimport { logError } from '@utils/log'\nimport { getCwd } from '@utils/state'\nimport { getTheme } from '@utils/theme'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { recordFileEdit } from '@services/fileFreshness'\nimport { triggerBackup } from '@core/backupHook'\nimport { NotebookEditTool } from '@tools/NotebookEditTool/NotebookEditTool'\nimport { DESCRIPTION } from './prompt'\nimport { applyEdit } from './utils'\nimport {\n hasWritePermission,\n pathInOriginalCwd,\n} from '@utils/permissions/filesystem'\nimport { PROJECT_FILE } from '@constants/product'\n\nconst inputSchema = z.strictObject({\n file_path: z.string().describe('The absolute path to the file to modify'),\n old_string: z.string().describe('The text to replace'),\n new_string: z\n .string()\n .describe(\n 'The text to replace it with (must be different from old_string)',\n ),\n replace_all: z\n .boolean()\n .optional()\n .default(false)\n .describe('Replace all occurences of old_string (default false)'),\n})\n\nexport type In = typeof inputSchema\n\n// Number of lines of context to include before/after the change in our result message\nconst N_LINES_SNIPPET = 4\n\nexport const FileEditTool = {\n name: 'Edit',\n async description() {\n return 'A tool for editing files'\n },\n async prompt() {\n return DESCRIPTION\n },\n inputSchema,\n userFacingName() {\n return 'Edit'\n },\n async isEnabled() {\n return true\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // FileEdit modifies files, not safe for concurrent execution\n },\n needsPermissions({ file_path }) {\n return !hasWritePermission(file_path)\n },\n renderToolUseMessage(input, { verbose }) {\n const filePath = verbose\n ? input.file_path\n : relative(getCwd(), input.file_path)\n const replaceAllSuffix = input.replace_all ? ', replace_all: true' : ''\n return `file_path: ${filePath}${replaceAllSuffix}`\n },\n renderToolResultMessage(output, options?: { verbose?: boolean }) {\n const verbose = options?.verbose ?? false\n\n // Guard against undefined or null output\n if (!output) {\n return (\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Text color={getTheme().secondaryText}>Edit completed</Text>\n </Box>\n </Box>\n )\n }\n\n const { filePath, structuredPatch } = output\n return (\n <FileEditToolUpdatedMessage\n filePath={filePath}\n structuredPatch={structuredPatch}\n verbose={verbose}\n />\n )\n },\n renderToolUseRejectedMessage(\n { file_path, old_string, new_string, replace_all }: any = {},\n { columns, verbose }: any = {},\n ) {\n try {\n if (!file_path) {\n return <FallbackToolUseRejectedMessage />\n }\n const { patch } = applyEdit(\n file_path,\n old_string,\n new_string,\n replace_all,\n )\n return (\n <Box flexDirection=\"column\">\n <Text>\n {' '}\u23BF{' '}\n <Text color={getTheme().error}>\n User rejected {old_string === '' ? 'write' : 'update'} to{' '}\n </Text>\n <Text bold>\n {verbose ? file_path : relative(getCwd(), file_path)}\n </Text>\n </Text>\n {intersperse(\n patch.map(patch => (\n <Box flexDirection=\"column\" paddingLeft={5} key={patch.newStart}>\n <StructuredDiff patch={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 async validateInput(\n { file_path, old_string, new_string, replace_all },\n { readFileTimestamps },\n ) {\n if (old_string === new_string) {\n return {\n result: false,\n message:\n 'No changes to make: old_string and new_string are exactly the same.',\n meta: {\n old_string,\n },\n } as ValidationResult\n }\n\n const fullFilePath = isAbsolute(file_path)\n ? file_path\n : resolve(getCwd(), file_path)\n\n // Security check: Ensure path is within allowed directory\n if (!pathInOriginalCwd(fullFilePath) && !hasWritePermission(fullFilePath)) {\n return {\n result: false,\n message:\n 'Path traversal detected - file must be within the project directory or an allowed write location.',\n }\n }\n\n // Security check: Check for symlinks that could escape directory boundaries\n if (existsSync(fullFilePath)) {\n try {\n const lstats = lstatSync(fullFilePath)\n if (lstats.isSymbolicLink()) {\n return {\n result: false,\n message:\n 'Cannot edit symbolic links for security reasons. Edit the target file directly.',\n }\n }\n } catch {\n // If we can't stat the file, let other checks handle it\n }\n }\n\n if (existsSync(fullFilePath) && old_string === '') {\n return {\n result: false,\n message: 'Cannot create new file - file already exists.',\n }\n }\n\n if (!existsSync(fullFilePath) && old_string === '') {\n return {\n result: true,\n }\n }\n\n if (!existsSync(fullFilePath)) {\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 if (fullFilePath.endsWith('.ipynb')) {\n return {\n result: false,\n message: `File is a Jupyter Notebook. Use the ${NotebookEditTool.name} to edit this file.`,\n }\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 meta: {\n isFilePathAbsolute: String(isAbsolute(file_path)),\n },\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 const enc = detectFileEncoding(fullFilePath)\n const file = readFileSync(fullFilePath, enc)\n if (!file.includes(old_string)) {\n return {\n result: false,\n message: `String to replace not found in file.`,\n meta: {\n isFilePathAbsolute: String(isAbsolute(file_path)),\n },\n }\n }\n\n const matches = file.split(old_string).length - 1\n if (matches > 1 && !replace_all) {\n return {\n result: false,\n message: `Found ${matches} matches of the string to replace. For safety, this tool only supports replacing exactly one occurrence at a time. Add more lines of context to your edit and try again, or use replace_all to change every instance.`,\n meta: {\n isFilePathAbsolute: String(isAbsolute(file_path)),\n },\n }\n }\n\n return { result: true }\n },\n async *call(\n { file_path, old_string, new_string, replace_all },\n { readFileTimestamps },\n ) {\n const { patch, updatedFile } = applyEdit(\n file_path,\n old_string,\n new_string,\n replace_all,\n )\n\n const fullFilePath = isAbsolute(file_path)\n ? file_path\n : resolve(getCwd(), file_path)\n const dir = dirname(fullFilePath)\n mkdirSync(dir, { recursive: true })\n const enc = existsSync(fullFilePath)\n ? detectFileEncoding(fullFilePath)\n : 'utf8'\n const endings = existsSync(fullFilePath)\n ? detectLineEndings(fullFilePath)\n : 'LF'\n const originalFile = existsSync(fullFilePath)\n ? readFileSync(fullFilePath, enc)\n : ''\n writeTextContent(fullFilePath, updatedFile, enc, endings)\n\n // Record Agent edit operation for file freshness tracking\n recordFileEdit(fullFilePath, updatedFile)\n triggerBackup(\n fullFilePath,\n originalFile || null,\n updatedFile,\n old_string === '' ? 'create' : 'update',\n )\n\n // Update read timestamp, to invalidate stale writes\n readFileTimestamps[fullFilePath] = statSync(fullFilePath).mtimeMs\n\n // Log when editing project doc files\n if (\n fullFilePath.endsWith(`${sep}${PROJECT_FILE}`) ||\n fullFilePath.endsWith(`${sep}AGENTS.md`) ||\n fullFilePath.endsWith(`${sep}CLAUDE.md`)\n ) {\n }\n\n // Emit file edited event for system reminders\n emitReminderEvent('file:edited', {\n filePath: fullFilePath,\n oldString: old_string,\n newString: new_string,\n timestamp: Date.now(),\n operation:\n old_string === '' ? 'create' : new_string === '' ? 'delete' : 'update',\n })\n\n const data = {\n filePath: file_path,\n oldString: old_string,\n newString: new_string,\n originalFile,\n structuredPatch: patch,\n }\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n },\n renderResultForAssistant({ filePath, originalFile, oldString, newString }) {\n const { snippet, startLine } = getSnippet(\n originalFile || '',\n oldString,\n newString,\n )\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: snippet,\n startLine,\n})}`\n },\n} satisfies Tool\n\nexport function getSnippet(\n initialText: string,\n oldStr: string,\n newStr: string,\n): { snippet: string; startLine: number } {\n const before = initialText.split(oldStr)[0] ?? ''\n const replacementLine = before.split(/\\r?\\n/).length - 1\n const newFileLines = initialText.replace(oldStr, newStr).split(/\\r?\\n/)\n // Calculate the start and end line numbers for the snippet\n const startLine = Math.max(0, replacementLine - N_LINES_SNIPPET)\n const endLine =\n replacementLine + N_LINES_SNIPPET + newStr.split(/\\r?\\n/).length\n // Get snippet\n const snippetLines = newFileLines.slice(startLine, endLine + 1)\n const snippet = snippetLines.join('\\n')\n return { snippet, startLine: startLine + 1 }\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,YAAY,WAAW,WAAW,cAAc,gBAAgB;AACzE,SAAS,KAAK,YAAY;AAC1B,SAAS,SAAS,YAAY,UAAU,
|
|
4
|
+
"sourcesContent": ["import { Hunk } from 'diff'\nimport { existsSync, lstatSync, mkdirSync, readFileSync, statSync } from 'fs'\nimport { Box, Text } from 'ink'\nimport { dirname, isAbsolute, relative, resolve, sep } from 'path'\nimport * as React from 'react'\nimport { z } from 'zod'\nimport { FileEditToolUpdatedMessage } from '@components/FileEditToolUpdatedMessage'\nimport { StructuredDiff } from '@components/StructuredDiff'\nimport { FallbackToolUseRejectedMessage } from '@components/FallbackToolUseRejectedMessage'\nimport { Tool, ValidationResult } from '@tool'\nimport { intersperse } from '@utils/array'\nimport {\n addLineNumbers,\n detectFileEncoding,\n detectLineEndings,\n findSimilarFile,\n writeTextContent,\n} from '@utils/file'\nimport { logError } from '@utils/log'\nimport { getCwd } from '@utils/state'\nimport { getTheme } from '@utils/theme'\nimport { emitReminderEvent } from '@services/systemReminder'\nimport { recordFileEdit } from '@services/fileFreshness'\nimport { triggerBackup } from '@core/backupHook'\nimport { NotebookEditTool } from '@tools/NotebookEditTool/NotebookEditTool'\nimport { DESCRIPTION } from './prompt'\nimport { applyEdit } from './utils'\nimport {\n hasWritePermission,\n pathInOriginalCwd,\n} from '@utils/permissions/filesystem'\nimport { PROJECT_FILE } from '@constants/product'\n\nconst inputSchema = z.strictObject({\n file_path: z.string().describe('The absolute path to the file to modify'),\n old_string: z.string().describe('The text to replace'),\n new_string: z\n .string()\n .describe(\n 'The text to replace it with (must be different from old_string)',\n ),\n replace_all: z\n .boolean()\n .optional()\n .default(false)\n .describe('Replace all occurences of old_string (default false)'),\n})\n\nexport type In = typeof inputSchema\n\n// Number of lines of context to include before/after the change in our result message\nconst N_LINES_SNIPPET = 4\n\nexport const FileEditTool = {\n name: 'Edit',\n async description() {\n return 'A tool for editing files'\n },\n async prompt() {\n return DESCRIPTION\n },\n inputSchema,\n userFacingName() {\n return 'Edit'\n },\n async isEnabled() {\n return true\n },\n isReadOnly() {\n return false\n },\n isConcurrencySafe() {\n return false // FileEdit modifies files, not safe for concurrent execution\n },\n needsPermissions({ file_path }) {\n return !hasWritePermission(file_path)\n },\n renderToolUseMessage(input, { verbose }) {\n const filePath = verbose\n ? input.file_path\n : relative(getCwd(), input.file_path)\n const replaceAllSuffix = input.replace_all ? ', replace_all: true' : ''\n return `file_path: ${filePath}${replaceAllSuffix}`\n },\n renderToolResultMessage(output, options?: { verbose?: boolean }) {\n const verbose = options?.verbose ?? false\n\n // Guard against undefined or null output\n if (!output) {\n return (\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Text color={getTheme().secondaryText}>Edit completed</Text>\n </Box>\n </Box>\n )\n }\n\n const { filePath, structuredPatch } = output\n return (\n <FileEditToolUpdatedMessage\n filePath={filePath}\n structuredPatch={structuredPatch}\n verbose={verbose}\n />\n )\n },\n renderToolUseRejectedMessage(\n { file_path, old_string, new_string, replace_all }: any = {},\n { columns, verbose }: any = {},\n ) {\n try {\n if (!file_path) {\n return <FallbackToolUseRejectedMessage />\n }\n const { patch } = applyEdit(\n file_path,\n old_string,\n new_string,\n replace_all,\n )\n return (\n <Box flexDirection=\"column\">\n <Text>\n {' '}\u23BF{' '}\n <Text color={getTheme().error}>\n User rejected {old_string === '' ? 'write' : 'update'} to{' '}\n </Text>\n <Text bold>\n {verbose ? file_path : relative(getCwd(), file_path)}\n </Text>\n </Text>\n {intersperse(\n patch.map(patch => (\n <Box flexDirection=\"column\" paddingLeft={5} key={patch.newStart}>\n <StructuredDiff patch={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 async validateInput(\n { file_path, old_string, new_string, replace_all },\n { readFileTimestamps },\n ) {\n if (old_string === new_string) {\n return {\n result: false,\n message:\n 'No changes to make: old_string and new_string are exactly the same.',\n meta: {\n old_string,\n },\n } as ValidationResult\n }\n\n const fullFilePath = isAbsolute(file_path)\n ? file_path\n : resolve(getCwd(), file_path)\n\n // Security check: Ensure path is within allowed directory\n if (!pathInOriginalCwd(fullFilePath) && !hasWritePermission(fullFilePath)) {\n return {\n result: false,\n message:\n 'Path traversal detected - file must be within the project directory or an allowed write location.',\n }\n }\n\n // Security check: Check for symlinks that could escape directory boundaries\n if (existsSync(fullFilePath)) {\n try {\n const lstats = lstatSync(fullFilePath)\n if (lstats.isSymbolicLink()) {\n return {\n result: false,\n message:\n 'Cannot edit symbolic links for security reasons. Edit the target file directly.',\n }\n }\n } catch {\n // If we can't stat the file, let other checks handle it\n }\n }\n\n if (existsSync(fullFilePath) && old_string === '') {\n return {\n result: false,\n message: 'Cannot create new file - file already exists.',\n }\n }\n\n if (!existsSync(fullFilePath) && old_string === '') {\n return {\n result: true,\n }\n }\n\n if (!existsSync(fullFilePath)) {\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 if (fullFilePath.endsWith('.ipynb')) {\n return {\n result: false,\n message: `File is a Jupyter Notebook. Use the ${NotebookEditTool.name} to edit this file.`,\n }\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 meta: {\n isFilePathAbsolute: String(isAbsolute(file_path)),\n },\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 const enc = detectFileEncoding(fullFilePath)\n const file = readFileSync(fullFilePath, enc)\n if (!file.includes(old_string)) {\n return {\n result: false,\n message: `String to replace not found in file.`,\n meta: {\n isFilePathAbsolute: String(isAbsolute(file_path)),\n },\n }\n }\n\n const matches = file.split(old_string).length - 1\n if (matches > 1 && !replace_all) {\n return {\n result: false,\n message: `Found ${matches} matches of the string to replace. For safety, this tool only supports replacing exactly one occurrence at a time. Add more lines of context to your edit and try again, or use replace_all to change every instance.`,\n meta: {\n isFilePathAbsolute: String(isAbsolute(file_path)),\n },\n }\n }\n\n return { result: true }\n },\n async *call(\n { file_path, old_string, new_string, replace_all },\n { readFileTimestamps },\n ) {\n const { patch, updatedFile } = applyEdit(\n file_path,\n old_string,\n new_string,\n replace_all,\n )\n\n const fullFilePath = isAbsolute(file_path)\n ? file_path\n : resolve(getCwd(), file_path)\n const dir = dirname(fullFilePath)\n mkdirSync(dir, { recursive: true })\n const enc = existsSync(fullFilePath)\n ? detectFileEncoding(fullFilePath)\n : 'utf8'\n const endings = existsSync(fullFilePath)\n ? detectLineEndings(fullFilePath)\n : 'LF'\n const originalFile = existsSync(fullFilePath)\n ? readFileSync(fullFilePath, enc)\n : ''\n // TOCTOU: Re-check symlink status just before write to prevent race condition\n const preWriteStats = lstatSync(fullFilePath, { throwIfNoEntry: false })\n if (preWriteStats?.isSymbolicLink()) {\n yield {\n type: 'result',\n data: `Error: Cannot write to '${file_path}': file became a symlink`,\n }\n return\n }\n writeTextContent(fullFilePath, updatedFile, enc, endings)\n\n // Record Agent edit operation for file freshness tracking\n recordFileEdit(fullFilePath, updatedFile)\n triggerBackup(\n fullFilePath,\n originalFile || null,\n updatedFile,\n old_string === '' ? 'create' : 'update',\n )\n\n // Update read timestamp, to invalidate stale writes\n readFileTimestamps[fullFilePath] = statSync(fullFilePath).mtimeMs\n\n // Emit file edited event for system reminders\n emitReminderEvent('file:edited', {\n filePath: fullFilePath,\n oldString: old_string,\n newString: new_string,\n timestamp: Date.now(),\n operation:\n old_string === '' ? 'create' : new_string === '' ? 'delete' : 'update',\n })\n\n const data = {\n filePath: file_path,\n oldString: old_string,\n newString: new_string,\n originalFile,\n structuredPatch: patch,\n }\n yield {\n type: 'result',\n data,\n resultForAssistant: this.renderResultForAssistant(data),\n }\n },\n renderResultForAssistant({ filePath, originalFile, oldString, newString }) {\n const { snippet, startLine } = getSnippet(\n originalFile || '',\n oldString,\n newString,\n )\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: snippet,\n startLine,\n})}`\n },\n} satisfies Tool\n\nexport function getSnippet(\n initialText: string,\n oldStr: string,\n newStr: string,\n): { snippet: string; startLine: number } {\n const before = initialText.split(oldStr)[0] ?? ''\n const replacementLine = before.split(/\\r?\\n/).length - 1\n const newFileLines = initialText.replace(oldStr, newStr).split(/\\r?\\n/)\n // Calculate the start and end line numbers for the snippet\n const startLine = Math.max(0, replacementLine - N_LINES_SNIPPET)\n const endLine =\n replacementLine + N_LINES_SNIPPET + newStr.split(/\\r?\\n/).length\n // Get snippet\n const snippetLines = newFileLines.slice(startLine, endLine + 1)\n const snippet = snippetLines.join('\\n')\n return { snippet, startLine: startLine + 1 }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,YAAY,WAAW,WAAW,cAAc,gBAAgB;AACzE,SAAS,KAAK,YAAY;AAC1B,SAAS,SAAS,YAAY,UAAU,eAAoB;AAC5D,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,kCAAkC;AAC3C,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,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP,MAAM,cAAc,EAAE,aAAa;AAAA,EACjC,WAAW,EAAE,OAAO,EAAE,SAAS,yCAAyC;AAAA,EACxE,YAAY,EAAE,OAAO,EAAE,SAAS,qBAAqB;AAAA,EACrD,YAAY,EACT,OAAO,EACP;AAAA,IACC;AAAA,EACF;AAAA,EACF,aAAa,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,KAAK,EACb,SAAS,sDAAsD;AACpE,CAAC;AAKD,MAAM,kBAAkB;AAEjB,MAAM,eAAe;AAAA,EAC1B,MAAM;AAAA,EACN,MAAM,cAAc;AAClB,WAAO;AAAA,EACT;AAAA,EACA,MAAM,SAAS;AACb,WAAO;AAAA,EACT;AAAA,EACA;AAAA,EACA,iBAAiB;AAC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,MACX;AAAA,MACA,iBAAiB;AAAA,IACnB;AACA,UAAM;AAAA,MACJ,MAAM;AAAA,MACN;AAAA,MACA,oBAAoB,KAAK,yBAAyB,IAAI;AAAA,IACxD;AAAA,EACF;AAAA,EACA,yBAAyB,EAAE,UAAU,cAAc,WAAW,UAAU,GAAG;AACzE,UAAM,EAAE,SAAS,UAAU,IAAI;AAAA,MAC7B,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AACA,WAAO,YAAY,QAAQ;AAAA,EAC7B,eAAe;AAAA,MACf,SAAS;AAAA,MACT;AAAA,IACF,CAAC,CAAC;AAAA,EACA;AACF;AAEO,SAAS,WACd,aACA,QACA,QACwC;AACxC,QAAM,SAAS,YAAY,MAAM,MAAM,EAAE,CAAC,KAAK;AAC/C,QAAM,kBAAkB,OAAO,MAAM,OAAO,EAAE,SAAS;AACvD,QAAM,eAAe,YAAY,QAAQ,QAAQ,MAAM,EAAE,MAAM,OAAO;AAEtE,QAAM,YAAY,KAAK,IAAI,GAAG,kBAAkB,eAAe;AAC/D,QAAM,UACJ,kBAAkB,kBAAkB,OAAO,MAAM,OAAO,EAAE;AAE5D,QAAM,eAAe,aAAa,MAAM,WAAW,UAAU,CAAC;AAC9D,QAAM,UAAU,aAAa,KAAK,IAAI;AACtC,SAAO,EAAE,SAAS,WAAW,YAAY,EAAE;AAC7C;",
|
|
6
6
|
"names": ["patch"]
|
|
7
7
|
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { FileWriteTool } from "../FileWriteTool/FileWriteTool.js";
|
|
3
|
-
import { FileReadTool } from "../FileReadTool/FileReadTool.js";
|
|
4
|
-
import { LSTool } from "../lsTool/lsTool.js";
|
|
5
|
-
const DESCRIPTION = `This is a tool for editing files. For moving or renaming files, you should generally use the Bash tool with the 'mv' command instead. For larger edits, use the ${FileWriteTool.name} tool to overwrite files. For Jupyter notebooks (.ipynb files), use the ${NotebookEditTool.name} instead.
|
|
1
|
+
const DESCRIPTION = `This is a tool for editing files. For moving or renaming files, you should generally use the Bash tool with the 'mv' command instead. For larger edits, use the Write tool to overwrite files. For Jupyter notebooks (.ipynb files), use the NotebookEdit instead.
|
|
6
2
|
|
|
7
3
|
Before using this tool:
|
|
8
4
|
|
|
9
|
-
1. Use the
|
|
5
|
+
1. Use the Read tool to understand the file's contents and context
|
|
10
6
|
|
|
11
7
|
2. Verify the directory path is correct (only applicable when creating new files):
|
|
12
|
-
- Use the
|
|
8
|
+
- Use the LS tool to verify the parent directory exists and is the correct location
|
|
13
9
|
|
|
14
10
|
To make a file edit, provide the following:
|
|
15
11
|
1. file_path: The absolute path to the file to modify (must be absolute, not relative)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/tools/FileEditTool/prompt.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export const DESCRIPTION = `This is a tool for editing files. For moving or renaming files, you should generally use the Bash tool with the 'mv' command instead. For larger edits, use the Write tool to overwrite files. For Jupyter notebooks (.ipynb files), use the NotebookEdit instead.\n\nBefore using this tool:\n\n1. Use the Read tool to understand the file's contents and context\n\n2. Verify the directory path is correct (only applicable when creating new files):\n - Use the LS tool to verify the parent directory exists and is the correct location\n\nTo make a file edit, provide the following:\n1. file_path: The absolute path to the file to modify (must be absolute, not relative)\n2. old_string: The text to replace (must be unique within the file, and must match the file contents exactly, including all whitespace and indentation)\n3. new_string: The edited text to replace the old_string\n4. replace_all: Set to true to replace ALL occurrences of old_string (default is false, which replaces only the first occurrence). Use this for renaming variables or updating strings across the file.\n\nThe tool will replace ONE occurrence of old_string with new_string in the specified file (unless replace_all is true).\n\nIMPORTANT: When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.\n\nCRITICAL REQUIREMENTS FOR USING THIS TOOL:\n\n1. UNIQUENESS: The old_string MUST uniquely identify the specific instance you want to change. This means:\n - Include AT LEAST 3-5 lines of context BEFORE the change point\n - Include AT LEAST 3-5 lines of context AFTER the change point\n - Include all whitespace, indentation, and surrounding code exactly as it appears in the file\n\n2. SINGLE INSTANCE: This tool can only change ONE instance at a time. If you need to change multiple instances:\n - Make separate calls to this tool for each instance\n - Each call must uniquely identify its specific instance using extensive context\n\n3. VERIFICATION: Before using this tool:\n - Check how many instances of the target text exist in the file\n - If multiple instances exist, gather enough context to uniquely identify each one\n - Plan separate tool calls for each instance\n\nWARNING: If you do not follow these requirements:\n - The tool will fail if old_string matches multiple locations\n - The tool will fail if old_string doesn't match exactly (including whitespace)\n - You may change the wrong instance if you don't include enough context\n\nWhen making edits:\n - Ensure the edit results in idiomatic, correct code\n - Do not leave the code in a broken state\n - Always use absolute file paths (starting with /)\n\nIf you want to create a new file, use:\n - A new file path, including dir name if needed\n - An empty old_string\n - The new file's contents as new_string\n\nRemember: when making multiple file edits in a row to the same file, you should prefer to send all edits in a single message with multiple calls to this tool, rather than multiple messages with a single call each.\n`\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,cAAc;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -36,6 +36,7 @@ const IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
36
36
|
const MAX_WIDTH = 2e3;
|
|
37
37
|
const MAX_HEIGHT = 2e3;
|
|
38
38
|
const MAX_IMAGE_SIZE = 3.75 * 1024 * 1024;
|
|
39
|
+
const PDF_EXTENSION = ".pdf";
|
|
39
40
|
const inputSchema = z.strictObject({
|
|
40
41
|
file_path: z.string().describe("The absolute path to the file to read"),
|
|
41
42
|
offset: z.number().optional().describe(
|
|
@@ -43,6 +44,9 @@ const inputSchema = z.strictObject({
|
|
|
43
44
|
),
|
|
44
45
|
limit: z.number().optional().describe(
|
|
45
46
|
"The number of lines to read. Only provide if the file is too large to read at once."
|
|
47
|
+
),
|
|
48
|
+
pages: z.string().optional().describe(
|
|
49
|
+
'Page range for PDF files (e.g., "1-5", "3", "10-20"). Only applicable to PDF files. Maximum 20 pages per request.'
|
|
46
50
|
)
|
|
47
51
|
});
|
|
48
52
|
const FileReadTool = {
|
|
@@ -106,7 +110,7 @@ const FileReadTool = {
|
|
|
106
110
|
renderToolUseRejectedMessage() {
|
|
107
111
|
return /* @__PURE__ */ React.createElement(FallbackToolUseRejectedMessage, null);
|
|
108
112
|
},
|
|
109
|
-
async validateInput({ file_path, offset, limit }) {
|
|
113
|
+
async validateInput({ file_path, offset, limit, pages }) {
|
|
110
114
|
const fullFilePath = normalizeFilePath(file_path);
|
|
111
115
|
const fileCheck = secureFileService.safeGetFileInfo(fullFilePath);
|
|
112
116
|
if (!fileCheck.success) {
|
|
@@ -123,7 +127,7 @@ const FileReadTool = {
|
|
|
123
127
|
const stats = fileCheck.stats;
|
|
124
128
|
const fileSize = stats.size;
|
|
125
129
|
const ext = path.extname(fullFilePath).toLowerCase();
|
|
126
|
-
if (!IMAGE_EXTENSIONS.has(ext)) {
|
|
130
|
+
if (!IMAGE_EXTENSIONS.has(ext) && ext !== PDF_EXTENSION) {
|
|
127
131
|
if (fileSize > MAX_OUTPUT_SIZE && !offset && !limit) {
|
|
128
132
|
return {
|
|
129
133
|
result: false,
|
|
@@ -132,9 +136,21 @@ const FileReadTool = {
|
|
|
132
136
|
};
|
|
133
137
|
}
|
|
134
138
|
}
|
|
139
|
+
if (pages && ext !== PDF_EXTENSION) {
|
|
140
|
+
return {
|
|
141
|
+
result: false,
|
|
142
|
+
message: 'The "pages" parameter is only applicable to PDF files (.pdf).'
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (ext === PDF_EXTENSION && fileSize > MAX_OUTPUT_SIZE * 4 && !pages) {
|
|
146
|
+
return {
|
|
147
|
+
result: false,
|
|
148
|
+
message: `PDF file is large (${Math.round(fileSize / 1024)}KB). Please provide the "pages" parameter to read specific page ranges (e.g., pages: "1-5"). Maximum 20 pages per request.`
|
|
149
|
+
};
|
|
150
|
+
}
|
|
135
151
|
return { result: true };
|
|
136
152
|
},
|
|
137
|
-
async *call({ file_path, offset = 1, limit = void 0 }, { readFileTimestamps }) {
|
|
153
|
+
async *call({ file_path, offset = 1, limit = void 0, pages = void 0 }, { readFileTimestamps }) {
|
|
138
154
|
const ext = path.extname(file_path).toLowerCase();
|
|
139
155
|
const fullFilePath = normalizeFilePath(file_path);
|
|
140
156
|
recordFileRead(fullFilePath);
|
|
@@ -161,6 +177,25 @@ const FileReadTool = {
|
|
|
161
177
|
};
|
|
162
178
|
return;
|
|
163
179
|
}
|
|
180
|
+
if (ext === PDF_EXTENSION) {
|
|
181
|
+
const pdfContent = await readPdfContent(fullFilePath, pages);
|
|
182
|
+
const data2 = {
|
|
183
|
+
type: "text",
|
|
184
|
+
file: {
|
|
185
|
+
filePath: file_path,
|
|
186
|
+
content: pdfContent.text,
|
|
187
|
+
numLines: pdfContent.text.split("\n").length,
|
|
188
|
+
startLine: 1,
|
|
189
|
+
totalLines: pdfContent.text.split("\n").length
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
yield {
|
|
193
|
+
type: "result",
|
|
194
|
+
data: data2,
|
|
195
|
+
resultForAssistant: this.renderResultForAssistant(data2)
|
|
196
|
+
};
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
164
199
|
const lineOffset = offset === 0 ? 0 : offset - 1;
|
|
165
200
|
const { content, lineCount, totalLines } = readTextContent(
|
|
166
201
|
fullFilePath,
|
|
@@ -299,6 +334,93 @@ async function readImage(filePath, ext) {
|
|
|
299
334
|
return createImageResponse(fileReadResult.content, ext);
|
|
300
335
|
}
|
|
301
336
|
}
|
|
337
|
+
function parsePagesRange(pages) {
|
|
338
|
+
const trimmed = pages.trim();
|
|
339
|
+
const rangeMatch = trimmed.match(/^(\d+)\s*-\s*(\d+)$/);
|
|
340
|
+
if (rangeMatch) {
|
|
341
|
+
const start = parseInt(rangeMatch[1], 10);
|
|
342
|
+
const end = parseInt(rangeMatch[2], 10);
|
|
343
|
+
if (start < 1 || end < start) {
|
|
344
|
+
throw new Error(
|
|
345
|
+
`Invalid page range "${pages}": start must be >= 1 and end must be >= start`
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
if (end - start + 1 > 20) {
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Page range "${pages}" exceeds maximum of 20 pages per request`
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
return { start, end };
|
|
354
|
+
}
|
|
355
|
+
const singleMatch = trimmed.match(/^(\d+)$/);
|
|
356
|
+
if (singleMatch) {
|
|
357
|
+
const page = parseInt(singleMatch[1], 10);
|
|
358
|
+
if (page < 1) {
|
|
359
|
+
throw new Error(`Invalid page number "${pages}": must be >= 1`);
|
|
360
|
+
}
|
|
361
|
+
return { start: page, end: page };
|
|
362
|
+
}
|
|
363
|
+
throw new Error(
|
|
364
|
+
`Invalid pages format "${pages}". Use "N" for a single page or "N-M" for a range.`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
async function readPdfContent(filePath, pages) {
|
|
368
|
+
const pageRange = pages ? parsePagesRange(pages) : void 0;
|
|
369
|
+
try {
|
|
370
|
+
const pdfParseModule = await import("pdf-parse");
|
|
371
|
+
const pdfParse = pdfParseModule.default ?? pdfParseModule;
|
|
372
|
+
const fileReadResult = secureFileService.safeReadFile(filePath, {
|
|
373
|
+
encoding: "buffer",
|
|
374
|
+
maxFileSize: 50 * 1024 * 1024
|
|
375
|
+
// 50MB max for PDFs
|
|
376
|
+
});
|
|
377
|
+
if (!fileReadResult.success) {
|
|
378
|
+
throw new Error(`Failed to read PDF file: ${fileReadResult.error}`);
|
|
379
|
+
}
|
|
380
|
+
const options = {};
|
|
381
|
+
if (pageRange) {
|
|
382
|
+
options.pagerender = (pageData) => {
|
|
383
|
+
const pageNum = pageData.pageIndex + 1;
|
|
384
|
+
if (pageNum >= pageRange.start && pageNum <= pageRange.end) {
|
|
385
|
+
return pageData.getTextContent().then((textContent) => {
|
|
386
|
+
return textContent.items.map((item) => item.str).join(" ");
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
return Promise.resolve("");
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
const result = await pdfParse(fileReadResult.content, options);
|
|
393
|
+
let text = result.text || "";
|
|
394
|
+
const header = pageRange ? `[PDF: ${filePath} | Pages ${pageRange.start}-${pageRange.end} of ${result.numpages}]` : `[PDF: ${filePath} | ${result.numpages} pages]`;
|
|
395
|
+
text = `${header}
|
|
396
|
+
|
|
397
|
+
${text}`;
|
|
398
|
+
return { text, numPages: result.numpages };
|
|
399
|
+
} catch (importError) {
|
|
400
|
+
if (importError?.code === "MODULE_NOT_FOUND" || importError?.message?.includes("Cannot find module")) {
|
|
401
|
+
const { content, lineCount, totalLines } = readTextContent(
|
|
402
|
+
filePath,
|
|
403
|
+
0,
|
|
404
|
+
void 0
|
|
405
|
+
);
|
|
406
|
+
if (content.trim()) {
|
|
407
|
+
const header = `[PDF: ${filePath} | Raw text extraction (install pdf-parse for better results)]`;
|
|
408
|
+
return { text: `${header}
|
|
409
|
+
|
|
410
|
+
${content}` };
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
text: `[PDF file: ${filePath}]
|
|
414
|
+
|
|
415
|
+
PDF text extraction requires the pdf-parse package. Install it with:
|
|
416
|
+
bun add pdf-parse
|
|
417
|
+
|
|
418
|
+
Alternatively, convert the PDF to text before reading.`
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
throw importError;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
302
424
|
export {
|
|
303
425
|
FileReadTool
|
|
304
426
|
};
|