@shareai-lab/kode 1.1.12 → 1.1.14
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/cli.js +83 -57
- package/dist/ProjectOnboarding.js +99 -0
- package/dist/ProjectOnboarding.js.map +7 -0
- package/dist/Tool.js +1 -0
- package/dist/Tool.js.map +7 -0
- package/dist/commands/agents.js +2087 -0
- package/dist/commands/agents.js.map +7 -0
- package/dist/commands/approvedTools.js +36 -0
- package/dist/commands/approvedTools.js.map +7 -0
- package/dist/commands/bug.js +21 -0
- package/dist/commands/bug.js.map +7 -0
- package/dist/commands/clear.js +37 -0
- package/dist/commands/clear.js.map +7 -0
- package/dist/commands/compact.js +104 -0
- package/dist/commands/compact.js.map +7 -0
- package/dist/commands/config.js +20 -0
- package/dist/commands/config.js.map +7 -0
- package/dist/commands/cost.js +19 -0
- package/dist/commands/cost.js.map +7 -0
- package/dist/commands/ctx_viz.js +152 -0
- package/dist/commands/ctx_viz.js.map +7 -0
- package/dist/commands/doctor.js +25 -0
- package/dist/commands/doctor.js.map +7 -0
- package/dist/commands/help.js +20 -0
- package/dist/commands/help.js.map +7 -0
- package/dist/commands/init.js +38 -0
- package/dist/commands/init.js.map +7 -0
- package/dist/commands/listen.js +37 -0
- package/dist/commands/listen.js.map +7 -0
- package/dist/commands/login.js +37 -0
- package/dist/commands/login.js.map +7 -0
- package/dist/commands/logout.js +33 -0
- package/dist/commands/logout.js.map +7 -0
- package/dist/commands/mcp.js +34 -0
- package/dist/commands/mcp.js.map +7 -0
- package/dist/commands/model.js +41 -0
- package/dist/commands/model.js.map +7 -0
- package/dist/commands/modelstatus.js +21 -0
- package/dist/commands/modelstatus.js.map +7 -0
- package/dist/commands/onboarding.js +36 -0
- package/dist/commands/onboarding.js.map +7 -0
- package/dist/commands/pr_comments.js +61 -0
- package/dist/commands/pr_comments.js.map +7 -0
- package/dist/commands/refreshCommands.js +37 -0
- package/dist/commands/refreshCommands.js.map +7 -0
- package/dist/commands/release-notes.js +30 -0
- package/dist/commands/release-notes.js.map +7 -0
- package/dist/commands/resume.js +35 -0
- package/dist/commands/resume.js.map +7 -0
- package/dist/commands/review.js +51 -0
- package/dist/commands/review.js.map +7 -0
- package/dist/commands/terminalSetup.js +163 -0
- package/dist/commands/terminalSetup.js.map +7 -0
- package/dist/commands.js +84 -0
- package/dist/commands.js.map +7 -0
- package/dist/components/ApproveApiKey.js +74 -0
- package/dist/components/ApproveApiKey.js.map +7 -0
- package/dist/components/AsciiLogo.js +12 -0
- package/dist/components/AsciiLogo.js.map +7 -0
- package/dist/components/AutoUpdater.js +74 -0
- package/dist/components/AutoUpdater.js.map +7 -0
- package/dist/components/Bug.js +147 -0
- package/dist/components/Bug.js.map +7 -0
- package/dist/components/Config.js +166 -0
- package/dist/components/Config.js.map +7 -0
- package/dist/components/ConsoleOAuthFlow.js +188 -0
- package/dist/components/ConsoleOAuthFlow.js.map +7 -0
- package/dist/components/Cost.js +13 -0
- package/dist/components/Cost.js.map +7 -0
- package/dist/components/CostThresholdDialog.js +38 -0
- package/dist/components/CostThresholdDialog.js.map +7 -0
- package/dist/components/CustomSelect/option-map.js +32 -0
- package/dist/components/CustomSelect/option-map.js.map +7 -0
- package/dist/components/CustomSelect/select-option.js +34 -0
- package/dist/components/CustomSelect/select-option.js.map +7 -0
- package/dist/components/CustomSelect/select.js +64 -0
- package/dist/components/CustomSelect/select.js.map +7 -0
- package/dist/components/CustomSelect/theme.js +1 -0
- package/dist/components/CustomSelect/theme.js.map +7 -0
- package/dist/components/CustomSelect/use-select-state.js +220 -0
- package/dist/components/CustomSelect/use-select-state.js.map +7 -0
- package/dist/components/CustomSelect/use-select.js +21 -0
- package/dist/components/CustomSelect/use-select.js.map +7 -0
- package/dist/components/FallbackToolUseRejectedMessage.js +11 -0
- package/dist/components/FallbackToolUseRejectedMessage.js.map +7 -0
- package/dist/components/FileEditToolUpdatedMessage.js +31 -0
- package/dist/components/FileEditToolUpdatedMessage.js.map +7 -0
- package/dist/components/Help.js +41 -0
- package/dist/components/Help.js.map +7 -0
- package/dist/components/HighlightedCode.js +30 -0
- package/dist/components/HighlightedCode.js.map +7 -0
- package/dist/components/InvalidConfigDialog.js +83 -0
- package/dist/components/InvalidConfigDialog.js.map +7 -0
- package/dist/components/Link.js +18 -0
- package/dist/components/Link.js.map +7 -0
- package/dist/components/LogSelector.js +50 -0
- package/dist/components/LogSelector.js.map +7 -0
- package/dist/components/Logo.js +89 -0
- package/dist/components/Logo.js.map +7 -0
- package/dist/components/MCPServerApprovalDialog.js +79 -0
- package/dist/components/MCPServerApprovalDialog.js.map +7 -0
- package/dist/components/MCPServerDialogCopy.js +11 -0
- package/dist/components/MCPServerDialogCopy.js.map +7 -0
- package/dist/components/MCPServerMultiselectDialog.js +80 -0
- package/dist/components/MCPServerMultiselectDialog.js.map +7 -0
- package/dist/components/Message.js +146 -0
- package/dist/components/Message.js.map +7 -0
- package/dist/components/MessageResponse.js +9 -0
- package/dist/components/MessageResponse.js.map +7 -0
- package/dist/components/MessageSelector.js +133 -0
- package/dist/components/MessageSelector.js.map +7 -0
- package/dist/components/ModeIndicator.js +38 -0
- package/dist/components/ModeIndicator.js.map +7 -0
- package/dist/components/ModelConfig.js +208 -0
- package/dist/components/ModelConfig.js.map +7 -0
- package/dist/components/ModelListManager.js +140 -0
- package/dist/components/ModelListManager.js.map +7 -0
- package/dist/components/ModelSelector.js +1985 -0
- package/dist/components/ModelSelector.js.map +7 -0
- package/dist/components/ModelStatusDisplay.js +87 -0
- package/dist/components/ModelStatusDisplay.js.map +7 -0
- package/dist/components/Onboarding.js +153 -0
- package/dist/components/Onboarding.js.map +7 -0
- package/dist/components/PressEnterToContinue.js +10 -0
- package/dist/components/PressEnterToContinue.js.map +7 -0
- package/dist/components/PromptInput.js +501 -0
- package/dist/components/PromptInput.js.map +7 -0
- package/dist/components/SentryErrorBoundary.js +27 -0
- package/dist/components/SentryErrorBoundary.js.map +7 -0
- package/dist/components/Spinner.js +101 -0
- package/dist/components/Spinner.js.map +7 -0
- package/dist/components/StickerRequestForm.js +7 -0
- package/dist/components/StickerRequestForm.js.map +7 -0
- package/dist/components/StructuredDiff.js +148 -0
- package/dist/components/StructuredDiff.js.map +7 -0
- package/dist/components/TextInput.js +100 -0
- package/dist/components/TextInput.js.map +7 -0
- package/dist/components/TodoItem.js +35 -0
- package/dist/components/TodoItem.js.map +7 -0
- package/dist/components/TokenWarning.js +19 -0
- package/dist/components/TokenWarning.js.map +7 -0
- package/dist/components/ToolUseLoader.js +24 -0
- package/dist/components/ToolUseLoader.js.map +7 -0
- package/dist/components/TrustDialog.js +76 -0
- package/dist/components/TrustDialog.js.map +7 -0
- package/dist/components/binary-feedback/BinaryFeedback.js +50 -0
- package/dist/components/binary-feedback/BinaryFeedback.js.map +7 -0
- package/dist/components/binary-feedback/BinaryFeedbackOption.js +94 -0
- package/dist/components/binary-feedback/BinaryFeedbackOption.js.map +7 -0
- package/dist/components/binary-feedback/BinaryFeedbackView.js +139 -0
- package/dist/components/binary-feedback/BinaryFeedbackView.js.map +7 -0
- package/dist/components/binary-feedback/utils.js +161 -0
- package/dist/components/binary-feedback/utils.js.map +7 -0
- package/dist/components/messages/AssistantBashOutputMessage.js +23 -0
- package/dist/components/messages/AssistantBashOutputMessage.js.map +7 -0
- package/dist/components/messages/AssistantLocalCommandOutputMessage.js +36 -0
- package/dist/components/messages/AssistantLocalCommandOutputMessage.js.map +7 -0
- package/dist/components/messages/AssistantRedactedThinkingMessage.js +12 -0
- package/dist/components/messages/AssistantRedactedThinkingMessage.js.map +7 -0
- package/dist/components/messages/AssistantTextMessage.js +78 -0
- package/dist/components/messages/AssistantTextMessage.js.map +7 -0
- package/dist/components/messages/AssistantThinkingMessage.js +27 -0
- package/dist/components/messages/AssistantThinkingMessage.js.map +7 -0
- package/dist/components/messages/AssistantToolUseMessage.js +91 -0
- package/dist/components/messages/AssistantToolUseMessage.js.map +7 -0
- package/dist/components/messages/TaskProgressMessage.js +11 -0
- package/dist/components/messages/TaskProgressMessage.js.map +7 -0
- package/dist/components/messages/TaskToolMessage.js +39 -0
- package/dist/components/messages/TaskToolMessage.js.map +7 -0
- package/dist/components/messages/UserBashInputMessage.js +18 -0
- package/dist/components/messages/UserBashInputMessage.js.map +7 -0
- package/dist/components/messages/UserCommandMessage.js +20 -0
- package/dist/components/messages/UserCommandMessage.js.map +7 -0
- package/dist/components/messages/UserKodingInputMessage.js +18 -0
- package/dist/components/messages/UserKodingInputMessage.js.map +7 -0
- package/dist/components/messages/UserPromptMessage.js +20 -0
- package/dist/components/messages/UserPromptMessage.js.map +7 -0
- package/dist/components/messages/UserTextMessage.js +25 -0
- package/dist/components/messages/UserTextMessage.js.map +7 -0
- package/dist/components/messages/UserToolResultMessage/UserToolCanceledMessage.js +10 -0
- package/dist/components/messages/UserToolResultMessage/UserToolCanceledMessage.js.map +7 -0
- package/dist/components/messages/UserToolResultMessage/UserToolErrorMessage.js +15 -0
- package/dist/components/messages/UserToolResultMessage/UserToolErrorMessage.js.map +7 -0
- package/dist/components/messages/UserToolResultMessage/UserToolRejectMessage.js +25 -0
- package/dist/components/messages/UserToolResultMessage/UserToolRejectMessage.js.map +7 -0
- package/dist/components/messages/UserToolResultMessage/UserToolResultMessage.js +47 -0
- package/dist/components/messages/UserToolResultMessage/UserToolResultMessage.js.map +7 -0
- package/dist/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +23 -0
- package/dist/components/messages/UserToolResultMessage/UserToolSuccessMessage.js.map +7 -0
- package/dist/components/messages/UserToolResultMessage/utils.js +42 -0
- package/dist/components/messages/UserToolResultMessage/utils.js.map +7 -0
- package/dist/components/permissions/BashPermissionRequest/BashPermissionRequest.js +112 -0
- package/dist/components/permissions/BashPermissionRequest/BashPermissionRequest.js.map +7 -0
- package/dist/components/permissions/FallbackPermissionRequest.js +131 -0
- package/dist/components/permissions/FallbackPermissionRequest.js.map +7 -0
- package/dist/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +159 -0
- package/dist/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js.map +7 -0
- package/dist/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js +58 -0
- package/dist/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js.map +7 -0
- package/dist/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +153 -0
- package/dist/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js.map +7 -0
- package/dist/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +70 -0
- package/dist/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js.map +7 -0
- package/dist/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +212 -0
- package/dist/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js.map +7 -0
- package/dist/components/permissions/PermissionRequest.js +70 -0
- package/dist/components/permissions/PermissionRequest.js.map +7 -0
- package/dist/components/permissions/PermissionRequestTitle.js +52 -0
- package/dist/components/permissions/PermissionRequestTitle.js.map +7 -0
- package/dist/components/permissions/hooks.js +28 -0
- package/dist/components/permissions/hooks.js.map +7 -0
- package/dist/components/permissions/toolUseOptions.js +46 -0
- package/dist/components/permissions/toolUseOptions.js.map +7 -0
- package/dist/components/permissions/utils.js +21 -0
- package/dist/components/permissions/utils.js.map +7 -0
- package/dist/constants/betas.js +11 -0
- package/dist/constants/betas.js.map +7 -0
- package/dist/constants/claude-asterisk-ascii-art.js +242 -0
- package/dist/constants/claude-asterisk-ascii-art.js.map +7 -0
- package/dist/constants/figures.js +6 -0
- package/dist/constants/figures.js.map +7 -0
- package/dist/constants/keys.js +7 -0
- package/dist/constants/keys.js.map +7 -0
- package/dist/constants/macros.js +13 -0
- package/dist/constants/macros.js.map +7 -0
- package/dist/constants/modelCapabilities.js +154 -0
- package/dist/constants/modelCapabilities.js.map +7 -0
- package/dist/constants/models.js +1029 -0
- package/dist/constants/models.js.map +7 -0
- package/dist/constants/oauth.js +18 -0
- package/dist/constants/oauth.js.map +7 -0
- package/dist/constants/product.js +26 -0
- package/dist/constants/product.js.map +7 -0
- package/dist/constants/prompts.js +168 -0
- package/dist/constants/prompts.js.map +7 -0
- package/dist/constants/releaseNotes.js +9 -0
- package/dist/constants/releaseNotes.js.map +7 -0
- package/dist/context/PermissionContext.js +111 -0
- package/dist/context/PermissionContext.js.map +7 -0
- package/dist/context.js +259 -0
- package/dist/context.js.map +7 -0
- package/dist/cost-tracker.js +76 -0
- package/dist/cost-tracker.js.map +7 -0
- package/dist/entrypoints/cli.js +1101 -0
- package/dist/entrypoints/cli.js.map +7 -0
- package/dist/entrypoints/mcp.js +150 -0
- package/dist/entrypoints/mcp.js.map +7 -0
- package/dist/history.js +25 -0
- package/dist/history.js.map +7 -0
- package/dist/hooks/useApiKeyVerification.js +12 -0
- package/dist/hooks/useApiKeyVerification.js.map +7 -0
- package/dist/hooks/useArrowKeyHistory.js +50 -0
- package/dist/hooks/useArrowKeyHistory.js.map +7 -0
- package/dist/hooks/useCanUseTool.js +112 -0
- package/dist/hooks/useCanUseTool.js.map +7 -0
- package/dist/hooks/useCancelRequest.js +30 -0
- package/dist/hooks/useCancelRequest.js.map +7 -0
- package/dist/hooks/useDoublePress.js +31 -0
- package/dist/hooks/useDoublePress.js.map +7 -0
- package/dist/hooks/useExitOnCtrlCD.js +26 -0
- package/dist/hooks/useExitOnCtrlCD.js.map +7 -0
- package/dist/hooks/useInterval.js +18 -0
- package/dist/hooks/useInterval.js.map +7 -0
- package/dist/hooks/useLogMessages.js +14 -0
- package/dist/hooks/useLogMessages.js.map +7 -0
- package/dist/hooks/useLogStartupTime.js +15 -0
- package/dist/hooks/useLogStartupTime.js.map +7 -0
- package/dist/hooks/useNotifyAfterTimeout.js +42 -0
- package/dist/hooks/useNotifyAfterTimeout.js.map +7 -0
- package/dist/hooks/usePermissionRequestLogging.js +28 -0
- package/dist/hooks/usePermissionRequestLogging.js.map +7 -0
- package/dist/hooks/useTerminalSize.js +38 -0
- package/dist/hooks/useTerminalSize.js.map +7 -0
- package/dist/hooks/useTextInput.js +250 -0
- package/dist/hooks/useTextInput.js.map +7 -0
- package/dist/hooks/useUnifiedCompletion.js +929 -0
- package/dist/hooks/useUnifiedCompletion.js.map +7 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +7 -0
- package/dist/messages.js +33 -0
- package/dist/messages.js.map +7 -0
- package/dist/package.json +1 -0
- package/dist/permissions.js +194 -0
- package/dist/permissions.js.map +7 -0
- package/dist/query.js +492 -0
- package/dist/query.js.map +7 -0
- package/dist/screens/ConfigureNpmPrefix.js +128 -0
- package/dist/screens/ConfigureNpmPrefix.js.map +7 -0
- package/dist/screens/Doctor.js +143 -0
- package/dist/screens/Doctor.js.map +7 -0
- package/dist/screens/LogList.js +55 -0
- package/dist/screens/LogList.js.map +7 -0
- package/dist/screens/REPL.js +596 -0
- package/dist/screens/REPL.js.map +7 -0
- package/dist/screens/ResumeConversation.js +56 -0
- package/dist/screens/ResumeConversation.js.map +7 -0
- package/dist/services/adapters/base.js +29 -0
- package/dist/services/adapters/base.js.map +7 -0
- package/dist/services/adapters/chatCompletions.js +69 -0
- package/dist/services/adapters/chatCompletions.js.map +7 -0
- package/dist/services/adapters/responsesAPI.js +126 -0
- package/dist/services/adapters/responsesAPI.js.map +7 -0
- package/dist/services/browserMocks.js +48 -0
- package/dist/services/browserMocks.js.map +7 -0
- package/dist/services/claude.js +1605 -0
- package/dist/services/claude.js.map +7 -0
- package/dist/services/customCommands.js +359 -0
- package/dist/services/customCommands.js.map +7 -0
- package/dist/services/fileFreshness.js +280 -0
- package/dist/services/fileFreshness.js.map +7 -0
- package/dist/services/gpt5ConnectionTest.js +248 -0
- package/dist/services/gpt5ConnectionTest.js.map +7 -0
- package/dist/services/mcpClient.js +435 -0
- package/dist/services/mcpClient.js.map +7 -0
- package/dist/services/mcpServerApproval.js +55 -0
- package/dist/services/mcpServerApproval.js.map +7 -0
- package/dist/services/mentionProcessor.js +200 -0
- package/dist/services/mentionProcessor.js.map +7 -0
- package/dist/services/modelAdapterFactory.js +47 -0
- package/dist/services/modelAdapterFactory.js.map +7 -0
- package/dist/services/notifier.js +35 -0
- package/dist/services/notifier.js.map +7 -0
- package/dist/services/oauth.js +259 -0
- package/dist/services/oauth.js.map +7 -0
- package/dist/services/openai.js +998 -0
- package/dist/services/openai.js.map +7 -0
- package/dist/services/responseStateManager.js +68 -0
- package/dist/services/responseStateManager.js.map +7 -0
- package/dist/services/sentry.js +9 -0
- package/dist/services/sentry.js.map +7 -0
- package/dist/services/statsig.js +112 -0
- package/dist/services/statsig.js.map +7 -0
- package/dist/services/statsigStorage.js +75 -0
- package/dist/services/statsigStorage.js.map +7 -0
- package/dist/services/systemReminder.js +353 -0
- package/dist/services/systemReminder.js.map +7 -0
- package/dist/services/vcr.js +133 -0
- package/dist/services/vcr.js.map +7 -0
- package/dist/test/testAdapters.js +88 -0
- package/dist/test/testAdapters.js.map +1 -0
- package/dist/tools/ArchitectTool/ArchitectTool.js +119 -0
- package/dist/tools/ArchitectTool/ArchitectTool.js.map +7 -0
- package/dist/tools/ArchitectTool/prompt.js +18 -0
- package/dist/tools/ArchitectTool/prompt.js.map +7 -0
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js +423 -0
- package/dist/tools/AskExpertModelTool/AskExpertModelTool.js.map +7 -0
- package/dist/tools/BashTool/BashTool.js +188 -0
- package/dist/tools/BashTool/BashTool.js.map +7 -0
- package/dist/tools/BashTool/BashToolResultMessage.js +21 -0
- package/dist/tools/BashTool/BashToolResultMessage.js.map +7 -0
- package/dist/tools/BashTool/OutputLine.js +30 -0
- package/dist/tools/BashTool/OutputLine.js.map +7 -0
- package/dist/tools/BashTool/prompt.js +179 -0
- package/dist/tools/BashTool/prompt.js.map +7 -0
- package/dist/tools/BashTool/utils.js +51 -0
- package/dist/tools/BashTool/utils.js.map +7 -0
- package/dist/tools/FileEditTool/FileEditTool.js +228 -0
- package/dist/tools/FileEditTool/FileEditTool.js.map +7 -0
- package/dist/tools/FileEditTool/prompt.js +54 -0
- package/dist/tools/FileEditTool/prompt.js.map +7 -0
- package/dist/tools/FileEditTool/utils.js +42 -0
- package/dist/tools/FileEditTool/utils.js.map +7 -0
- package/dist/tools/FileReadTool/FileReadTool.js +272 -0
- package/dist/tools/FileReadTool/FileReadTool.js.map +7 -0
- package/dist/tools/FileReadTool/prompt.js +10 -0
- package/dist/tools/FileReadTool/prompt.js.map +7 -0
- package/dist/tools/FileWriteTool/FileWriteTool.js +204 -0
- package/dist/tools/FileWriteTool/FileWriteTool.js.map +7 -0
- package/dist/tools/FileWriteTool/prompt.js +14 -0
- package/dist/tools/FileWriteTool/prompt.js.map +7 -0
- package/dist/tools/GlobTool/GlobTool.js +88 -0
- package/dist/tools/GlobTool/GlobTool.js.map +7 -0
- package/dist/tools/GlobTool/prompt.js +12 -0
- package/dist/tools/GlobTool/prompt.js.map +7 -0
- package/dist/tools/GrepTool/GrepTool.js +107 -0
- package/dist/tools/GrepTool/GrepTool.js.map +7 -0
- package/dist/tools/GrepTool/prompt.js +15 -0
- package/dist/tools/GrepTool/prompt.js.map +7 -0
- package/dist/tools/MCPTool/MCPTool.js +90 -0
- package/dist/tools/MCPTool/MCPTool.js.map +7 -0
- package/dist/tools/MCPTool/prompt.js +7 -0
- package/dist/tools/MCPTool/prompt.js.map +7 -0
- package/dist/tools/MemoryReadTool/MemoryReadTool.js +103 -0
- package/dist/tools/MemoryReadTool/MemoryReadTool.js.map +7 -0
- package/dist/tools/MemoryReadTool/prompt.js +7 -0
- package/dist/tools/MemoryReadTool/prompt.js.map +7 -0
- package/dist/tools/MemoryWriteTool/MemoryWriteTool.js +77 -0
- package/dist/tools/MemoryWriteTool/MemoryWriteTool.js.map +7 -0
- package/dist/tools/MemoryWriteTool/prompt.js +7 -0
- package/dist/tools/MemoryWriteTool/prompt.js.map +7 -0
- package/dist/tools/MultiEditTool/MultiEditTool.js +293 -0
- package/dist/tools/MultiEditTool/MultiEditTool.js.map +7 -0
- package/dist/tools/MultiEditTool/prompt.js +48 -0
- package/dist/tools/MultiEditTool/prompt.js.map +7 -0
- package/dist/tools/NotebookEditTool/NotebookEditTool.js +238 -0
- package/dist/tools/NotebookEditTool/NotebookEditTool.js.map +7 -0
- package/dist/tools/NotebookEditTool/prompt.js +7 -0
- package/dist/tools/NotebookEditTool/prompt.js.map +7 -0
- package/dist/tools/NotebookReadTool/NotebookReadTool.js +212 -0
- package/dist/tools/NotebookReadTool/NotebookReadTool.js.map +7 -0
- package/dist/tools/NotebookReadTool/prompt.js +7 -0
- package/dist/tools/NotebookReadTool/prompt.js.map +7 -0
- package/dist/tools/StickerRequestTool/StickerRequestTool.js +86 -0
- package/dist/tools/StickerRequestTool/StickerRequestTool.js.map +7 -0
- package/dist/tools/StickerRequestTool/prompt.js +23 -0
- package/dist/tools/StickerRequestTool/prompt.js.map +7 -0
- package/dist/tools/TaskTool/TaskTool.js +308 -0
- package/dist/tools/TaskTool/TaskTool.js.map +7 -0
- package/dist/tools/TaskTool/constants.js +5 -0
- package/dist/tools/TaskTool/constants.js.map +7 -0
- package/dist/tools/TaskTool/prompt.js +82 -0
- package/dist/tools/TaskTool/prompt.js.map +7 -0
- package/dist/tools/ThinkTool/ThinkTool.js +48 -0
- package/dist/tools/ThinkTool/ThinkTool.js.map +7 -0
- package/dist/tools/ThinkTool/prompt.js +16 -0
- package/dist/tools/ThinkTool/prompt.js.map +7 -0
- package/dist/tools/TodoWriteTool/TodoWriteTool.js +216 -0
- package/dist/tools/TodoWriteTool/TodoWriteTool.js.map +7 -0
- package/dist/tools/TodoWriteTool/prompt.js +66 -0
- package/dist/tools/TodoWriteTool/prompt.js.map +7 -0
- package/dist/tools/URLFetcherTool/URLFetcherTool.js +137 -0
- package/dist/tools/URLFetcherTool/URLFetcherTool.js.map +7 -0
- package/dist/tools/URLFetcherTool/cache.js +45 -0
- package/dist/tools/URLFetcherTool/cache.js.map +7 -0
- package/dist/tools/URLFetcherTool/htmlToMarkdown.js +42 -0
- package/dist/tools/URLFetcherTool/htmlToMarkdown.js.map +7 -0
- package/dist/tools/URLFetcherTool/prompt.js +22 -0
- package/dist/tools/URLFetcherTool/prompt.js.map +7 -0
- package/dist/tools/WebSearchTool/WebSearchTool.js +86 -0
- package/dist/tools/WebSearchTool/WebSearchTool.js.map +7 -0
- package/dist/tools/WebSearchTool/prompt.js +17 -0
- package/dist/tools/WebSearchTool/prompt.js.map +7 -0
- package/dist/tools/WebSearchTool/searchProviders.js +48 -0
- package/dist/tools/WebSearchTool/searchProviders.js.map +7 -0
- package/dist/tools/lsTool/lsTool.js +201 -0
- package/dist/tools/lsTool/lsTool.js.map +7 -0
- package/dist/tools/lsTool/prompt.js +5 -0
- package/dist/tools/lsTool/prompt.js.map +7 -0
- package/dist/tools.js +64 -0
- package/dist/tools.js.map +7 -0
- package/dist/types/PermissionMode.js +82 -0
- package/dist/types/PermissionMode.js.map +7 -0
- package/dist/types/RequestContext.js +47 -0
- package/dist/types/RequestContext.js.map +7 -0
- package/dist/types/common.d.js +1 -0
- package/dist/types/common.d.js.map +7 -0
- package/dist/types/conversation.js +1 -0
- package/dist/types/conversation.js.map +7 -0
- package/dist/types/logs.js +1 -0
- package/dist/types/logs.js.map +7 -0
- package/dist/types/modelCapabilities.js +1 -0
- package/dist/types/modelCapabilities.js.map +7 -0
- package/dist/types/notebook.js +1 -0
- package/dist/types/notebook.js.map +7 -0
- package/dist/utils/Cursor.js +313 -0
- package/dist/utils/Cursor.js.map +7 -0
- package/dist/utils/PersistentShell.js +382 -0
- package/dist/utils/PersistentShell.js.map +7 -0
- package/dist/utils/advancedFuzzyMatcher.js +206 -0
- package/dist/utils/advancedFuzzyMatcher.js.map +7 -0
- package/dist/utils/agentLoader.js +199 -0
- package/dist/utils/agentLoader.js.map +7 -0
- package/dist/utils/agentStorage.js +59 -0
- package/dist/utils/agentStorage.js.map +7 -0
- package/dist/utils/array.js +7 -0
- package/dist/utils/array.js.map +7 -0
- package/dist/utils/ask.js +77 -0
- package/dist/utils/ask.js.map +7 -0
- package/dist/utils/auth.js +11 -0
- package/dist/utils/auth.js.map +7 -0
- package/dist/utils/autoCompactCore.js +149 -0
- package/dist/utils/autoCompactCore.js.map +7 -0
- package/dist/utils/autoUpdater.js +362 -0
- package/dist/utils/autoUpdater.js.map +7 -0
- package/dist/utils/betas.js +21 -0
- package/dist/utils/betas.js.map +7 -0
- package/dist/utils/browser.js +15 -0
- package/dist/utils/browser.js.map +7 -0
- package/dist/utils/cleanup.js +54 -0
- package/dist/utils/cleanup.js.map +7 -0
- package/dist/utils/commands.js +207 -0
- package/dist/utils/commands.js.map +7 -0
- package/dist/utils/commonUnixCommands.js +687 -0
- package/dist/utils/commonUnixCommands.js.map +7 -0
- package/dist/utils/config.js +655 -0
- package/dist/utils/config.js.map +7 -0
- package/dist/utils/conversationRecovery.js +35 -0
- package/dist/utils/conversationRecovery.js.map +7 -0
- package/dist/utils/debugLogger.js +891 -0
- package/dist/utils/debugLogger.js.map +7 -0
- package/dist/utils/diff.js +32 -0
- package/dist/utils/diff.js.map +7 -0
- package/dist/utils/env.js +44 -0
- package/dist/utils/env.js.map +7 -0
- package/dist/utils/errors.js +23 -0
- package/dist/utils/errors.js.map +7 -0
- package/dist/utils/exampleCommands.js +80 -0
- package/dist/utils/exampleCommands.js.map +7 -0
- package/dist/utils/execFileNoThrow.js +44 -0
- package/dist/utils/execFileNoThrow.js.map +7 -0
- package/dist/utils/expertChatStorage.js +78 -0
- package/dist/utils/expertChatStorage.js.map +7 -0
- package/dist/utils/file.js +282 -0
- package/dist/utils/file.js.map +7 -0
- package/dist/utils/fileRecoveryCore.js +41 -0
- package/dist/utils/fileRecoveryCore.js.map +7 -0
- package/dist/utils/format.js +41 -0
- package/dist/utils/format.js.map +7 -0
- package/dist/utils/fuzzyMatcher.js +252 -0
- package/dist/utils/fuzzyMatcher.js.map +7 -0
- package/dist/utils/generators.js +46 -0
- package/dist/utils/generators.js.map +7 -0
- package/dist/utils/git.js +83 -0
- package/dist/utils/git.js.map +7 -0
- package/dist/utils/globalLogger.js +54 -0
- package/dist/utils/globalLogger.js.map +7 -0
- package/dist/utils/http.js +7 -0
- package/dist/utils/http.js.map +7 -0
- package/dist/utils/imagePaste.js +29 -0
- package/dist/utils/imagePaste.js.map +7 -0
- package/dist/utils/json.js +16 -0
- package/dist/utils/json.js.map +7 -0
- package/dist/utils/log.js +298 -0
- package/dist/utils/log.js.map +7 -0
- package/dist/utils/markdown.js +187 -0
- package/dist/utils/markdown.js.map +7 -0
- package/dist/utils/messageContextManager.js +195 -0
- package/dist/utils/messageContextManager.js.map +7 -0
- package/dist/utils/messages.js +633 -0
- package/dist/utils/messages.js.map +7 -0
- package/dist/utils/model.js +687 -0
- package/dist/utils/model.js.map +7 -0
- package/dist/utils/permissions/filesystem.js +80 -0
- package/dist/utils/permissions/filesystem.js.map +7 -0
- package/dist/utils/responseState.js +20 -0
- package/dist/utils/responseState.js.map +7 -0
- package/dist/utils/ripgrep.js +131 -0
- package/dist/utils/ripgrep.js.map +7 -0
- package/dist/utils/secureFile.js +483 -0
- package/dist/utils/secureFile.js.map +7 -0
- package/dist/utils/sessionState.js +31 -0
- package/dist/utils/sessionState.js.map +7 -0
- package/dist/utils/state.js +24 -0
- package/dist/utils/state.js.map +7 -0
- package/dist/utils/style.js +31 -0
- package/dist/utils/style.js.map +7 -0
- package/dist/utils/terminal.js +43 -0
- package/dist/utils/terminal.js.map +7 -0
- package/dist/utils/theme.js +102 -0
- package/dist/utils/theme.js.map +7 -0
- package/dist/utils/thinking.js +103 -0
- package/dist/utils/thinking.js.map +7 -0
- package/dist/utils/todoStorage.js +291 -0
- package/dist/utils/todoStorage.js.map +7 -0
- package/dist/utils/tokens.js +30 -0
- package/dist/utils/tokens.js.map +7 -0
- package/dist/utils/toolExecutionController.js +109 -0
- package/dist/utils/toolExecutionController.js.map +7 -0
- package/dist/utils/unaryLogging.js +14 -0
- package/dist/utils/unaryLogging.js.map +7 -0
- package/dist/utils/user.js +40 -0
- package/dist/utils/user.js.map +7 -0
- package/dist/utils/validate.js +132 -0
- package/dist/utils/validate.js.map +7 -0
- package/dist/yoga.wasm +0 -0
- package/package.json +28 -7
- package/src/Tool.ts +4 -3
- package/src/commands/agents.tsx +10 -4
- package/src/components/messages/AssistantToolUseMessage.tsx +5 -6
- package/src/constants/macros.ts +5 -2
- package/src/entrypoints/cli.tsx +38 -19
- package/src/entrypoints/mcp.ts +1 -2
- package/src/hooks/useDoublePress.ts +0 -1
- package/src/hooks/useTextInput.ts +4 -5
- package/src/hooks/useUnifiedCompletion.ts +2 -2
- package/src/index.ts +34 -0
- package/src/query.ts +13 -8
- package/src/screens/Doctor.tsx +1 -1
- package/src/screens/REPL.tsx +13 -9
- package/src/services/openai.ts +25 -4
- package/src/tools/ArchitectTool/ArchitectTool.tsx +18 -5
- package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +21 -14
- package/src/tools/FileEditTool/FileEditTool.tsx +6 -2
- package/src/tools/FileWriteTool/FileWriteTool.tsx +7 -3
- package/src/tools/MultiEditTool/MultiEditTool.tsx +26 -4
- package/src/tools/NotebookReadTool/NotebookReadTool.tsx +1 -1
- package/src/tools/StickerRequestTool/StickerRequestTool.tsx +28 -14
- package/src/tools/TaskTool/TaskTool.tsx +8 -36
- package/src/types/common.d.ts +2 -0
- package/src/utils/generators.ts +1 -1
- package/src/utils/messageContextManager.ts +5 -0
- package/src/utils/messages.tsx +8 -2
- package/src/utils/thinking.ts +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,gB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f,iBAAiB;AAAA,QACjB;AAAA,MACF;AAEA,YAAM;AAAA,QACJ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,oBAAoB,KAAK,yBAAyB,MAAM;AAAA,MAC1D;AAAA,IACF,SAAS,OAAY;AAEnB,UACE,MAAM,SAAS,gBACf,gBAAgB,QAAQ,WACxB,eACA;AACA,eAAO,OAAO,KAAK,gBAAgB;AAAA,MACrC;AAEA,cAAQ,MAAM,wCAAwC,KAAK;AAC3D,eAAS,KAAK;AAGd,YAAM,iBAAiB,aAAa;AAEpC,YAAM,eACJ,MAAM,WAAW;AACnB,YAAM,SAAc;AAAA,QAClB,eAAe;AAAA,QACf,iBAAiB;AAAA,QACjB,cAAc,UAAK,YAAY;AAAA,MACjC;AAEA,YAAM;AAAA,QACJ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,oBAAoB,KAAK,yBAAyB,MAAM;AAAA,MAC1D;AAAA,IACF,UAAE;AAEA,sBAAgB,OAAO,oBAAoB,SAAS,aAAa;AAAA,IACnE;AAAA,EACF;AAAA;AAAA,EAGA,OAAO,kBAAkB;AACvB,UAAM;AAAA,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { statSync } from "fs";
|
|
2
|
+
import { EOL } from "os";
|
|
3
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { FallbackToolUseRejectedMessage } from "../../components/FallbackToolUseRejectedMessage.js";
|
|
7
|
+
import { PRODUCT_NAME } from "../../constants/product.js";
|
|
8
|
+
import { splitCommand } from "../../utils/commands.js";
|
|
9
|
+
import { isInDirectory } from "../../utils/file.js";
|
|
10
|
+
import { logError } from "../../utils/log.js";
|
|
11
|
+
import { PersistentShell } from "../../utils/PersistentShell.js";
|
|
12
|
+
import { getCwd, getOriginalCwd } from "../../utils/state.js";
|
|
13
|
+
import { getGlobalConfig } from "../../utils/config.js";
|
|
14
|
+
import { getModelManager } from "../../utils/model.js";
|
|
15
|
+
import BashToolResultMessage from "./BashToolResultMessage.js";
|
|
16
|
+
import { BANNED_COMMANDS, PROMPT } from "./prompt.js";
|
|
17
|
+
import { formatOutput, getCommandFilePaths } from "./utils.js";
|
|
18
|
+
import { logEvent } from "../../services/statsig.js";
|
|
19
|
+
const inputSchema = z.strictObject({
|
|
20
|
+
command: z.string().describe("The command to execute"),
|
|
21
|
+
timeout: z.number().optional().describe("Optional timeout in milliseconds (max 600000)")
|
|
22
|
+
});
|
|
23
|
+
const BashTool = {
|
|
24
|
+
name: "Bash",
|
|
25
|
+
async description() {
|
|
26
|
+
return "Executes shell commands on your computer";
|
|
27
|
+
},
|
|
28
|
+
async prompt() {
|
|
29
|
+
const config = getGlobalConfig();
|
|
30
|
+
const modelManager = getModelManager();
|
|
31
|
+
const modelName = modelManager.getModelName("main") || "<No Model Configured>";
|
|
32
|
+
return PROMPT.replace(/{MODEL_NAME}/g, modelName);
|
|
33
|
+
},
|
|
34
|
+
isReadOnly() {
|
|
35
|
+
return false;
|
|
36
|
+
},
|
|
37
|
+
isConcurrencySafe() {
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
inputSchema,
|
|
41
|
+
userFacingName() {
|
|
42
|
+
return "Bash";
|
|
43
|
+
},
|
|
44
|
+
async isEnabled() {
|
|
45
|
+
return true;
|
|
46
|
+
},
|
|
47
|
+
needsPermissions() {
|
|
48
|
+
return true;
|
|
49
|
+
},
|
|
50
|
+
async validateInput({ command }) {
|
|
51
|
+
const commands = splitCommand(command);
|
|
52
|
+
for (const cmd of commands) {
|
|
53
|
+
const parts = cmd.split(" ");
|
|
54
|
+
const baseCmd = parts[0];
|
|
55
|
+
if (baseCmd && BANNED_COMMANDS.includes(baseCmd.toLowerCase())) {
|
|
56
|
+
return {
|
|
57
|
+
result: false,
|
|
58
|
+
message: `Command '${baseCmd}' is not allowed for security reasons`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (baseCmd === "cd" && parts[1]) {
|
|
62
|
+
const targetDir = parts[1].replace(/^['"]|['"]$/g, "");
|
|
63
|
+
const fullTargetDir = isAbsolute(targetDir) ? targetDir : resolve(getCwd(), targetDir);
|
|
64
|
+
if (!isInDirectory(
|
|
65
|
+
relative(getOriginalCwd(), fullTargetDir),
|
|
66
|
+
relative(getCwd(), getOriginalCwd())
|
|
67
|
+
)) {
|
|
68
|
+
return {
|
|
69
|
+
result: false,
|
|
70
|
+
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.`
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { result: true };
|
|
76
|
+
},
|
|
77
|
+
renderToolUseMessage({ command }) {
|
|
78
|
+
if (command.includes(`"$(cat <<'EOF'`)) {
|
|
79
|
+
const match = command.match(
|
|
80
|
+
/^(.*?)"?\$\(cat <<'EOF'\n([\s\S]*?)\n\s*EOF\n\s*\)"(.*)$/
|
|
81
|
+
);
|
|
82
|
+
if (match && match[1] && match[2]) {
|
|
83
|
+
const prefix = match[1];
|
|
84
|
+
const content = match[2];
|
|
85
|
+
const suffix = match[3] || "";
|
|
86
|
+
return `${prefix.trim()} "${content.trim()}"${suffix.trim()}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return command;
|
|
90
|
+
},
|
|
91
|
+
renderToolUseRejectedMessage() {
|
|
92
|
+
return /* @__PURE__ */ React.createElement(FallbackToolUseRejectedMessage, null);
|
|
93
|
+
},
|
|
94
|
+
renderToolResultMessage(content) {
|
|
95
|
+
return /* @__PURE__ */ React.createElement(BashToolResultMessage, { content, verbose: false });
|
|
96
|
+
},
|
|
97
|
+
renderResultForAssistant({ interrupted, stdout, stderr }) {
|
|
98
|
+
let errorMessage = stderr.trim();
|
|
99
|
+
if (interrupted) {
|
|
100
|
+
if (stderr) errorMessage += EOL;
|
|
101
|
+
errorMessage += "<error>Command was aborted before completion</error>";
|
|
102
|
+
}
|
|
103
|
+
const hasBoth = stdout.trim() && errorMessage;
|
|
104
|
+
return `${stdout.trim()}${hasBoth ? "\n" : ""}${errorMessage.trim()}`;
|
|
105
|
+
},
|
|
106
|
+
async *call({ command, timeout = 12e4 }, { abortController, readFileTimestamps }) {
|
|
107
|
+
let stdout = "";
|
|
108
|
+
let stderr = "";
|
|
109
|
+
if (abortController.signal.aborted) {
|
|
110
|
+
const data = {
|
|
111
|
+
stdout: "",
|
|
112
|
+
stdoutLines: 0,
|
|
113
|
+
stderr: "Command cancelled before execution",
|
|
114
|
+
stderrLines: 1,
|
|
115
|
+
interrupted: true
|
|
116
|
+
};
|
|
117
|
+
yield {
|
|
118
|
+
type: "result",
|
|
119
|
+
resultForAssistant: this.renderResultForAssistant(data),
|
|
120
|
+
data
|
|
121
|
+
};
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const result = await PersistentShell.getInstance().exec(
|
|
126
|
+
command,
|
|
127
|
+
abortController.signal,
|
|
128
|
+
timeout
|
|
129
|
+
);
|
|
130
|
+
stdout += (result.stdout || "").trim() + EOL;
|
|
131
|
+
stderr += (result.stderr || "").trim() + EOL;
|
|
132
|
+
if (result.code !== 0) {
|
|
133
|
+
stderr += `Exit code ${result.code}`;
|
|
134
|
+
}
|
|
135
|
+
if (!isInDirectory(getCwd(), getOriginalCwd())) {
|
|
136
|
+
await PersistentShell.getInstance().setCwd(getOriginalCwd());
|
|
137
|
+
stderr = `${stderr.trim()}${EOL}Shell cwd was reset to ${getOriginalCwd()}`;
|
|
138
|
+
logEvent("bash_tool_reset_to_original_dir", {});
|
|
139
|
+
}
|
|
140
|
+
if (process.env.NODE_ENV !== "test") {
|
|
141
|
+
getCommandFilePaths(command, stdout).then((filePaths) => {
|
|
142
|
+
for (const filePath of filePaths) {
|
|
143
|
+
const fullFilePath = isAbsolute(filePath) ? filePath : resolve(getCwd(), filePath);
|
|
144
|
+
try {
|
|
145
|
+
readFileTimestamps[fullFilePath] = statSync(fullFilePath).mtimeMs;
|
|
146
|
+
} catch (e) {
|
|
147
|
+
logError(e);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const { totalLines: stdoutLines, truncatedContent: stdoutContent } = formatOutput(stdout.trim());
|
|
153
|
+
const { totalLines: stderrLines, truncatedContent: stderrContent } = formatOutput(stderr.trim());
|
|
154
|
+
const data = {
|
|
155
|
+
stdout: stdoutContent,
|
|
156
|
+
stdoutLines,
|
|
157
|
+
stderr: stderrContent,
|
|
158
|
+
stderrLines,
|
|
159
|
+
interrupted: result.interrupted
|
|
160
|
+
};
|
|
161
|
+
yield {
|
|
162
|
+
type: "result",
|
|
163
|
+
resultForAssistant: this.renderResultForAssistant(data),
|
|
164
|
+
data
|
|
165
|
+
};
|
|
166
|
+
} catch (error) {
|
|
167
|
+
const isAborted = abortController.signal.aborted;
|
|
168
|
+
const errorMessage = isAborted ? "Command was cancelled by user" : `Command failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
169
|
+
const data = {
|
|
170
|
+
stdout: stdout.trim(),
|
|
171
|
+
stdoutLines: stdout.split("\n").length,
|
|
172
|
+
stderr: errorMessage,
|
|
173
|
+
stderrLines: 1,
|
|
174
|
+
interrupted: isAborted
|
|
175
|
+
};
|
|
176
|
+
yield {
|
|
177
|
+
type: "result",
|
|
178
|
+
resultForAssistant: this.renderResultForAssistant(data),
|
|
179
|
+
data
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
export {
|
|
185
|
+
BashTool,
|
|
186
|
+
inputSchema
|
|
187
|
+
};
|
|
188
|
+
//# sourceMappingURL=BashTool.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 BashToolResultMessage from './BashToolResultMessage'\nimport { BANNED_COMMANDS, PROMPT } from './prompt'\nimport { formatOutput, getCommandFilePaths } from './utils'\nimport { logEvent } from '../../services/statsig'\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})\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}\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 },\n { abortController, readFileTimestamps },\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 logEvent('bash_tool_reset_to_original_dir', {})\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,sBAAsB;AACvC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,OAAO,2BAA2B;AAClC,SAAS,iBAAiB,cAAc;AACxC,SAAS,cAAc,2BAA2B;AAClD,SAAS,gBAAgB;AAElB,MAAM,cAAc,EAAE,aAAa;AAAA,EACxC,SAAS,EAAE,OAAO,EAAE,SAAS,wBAAwB;AAAA,EACrD,SAAS,EACN,OAAO,EACP,SAAS,EACT,SAAS,+CAA+C;AAC7D,CAAC;AAWM,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;AA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,QACN,oBAAoB,KAAK,yBAAyB,IAAI;AAAA,QACtD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Box, Text } from "ink";
|
|
2
|
+
import { OutputLine } from "./OutputLine.js";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { getTheme } from "../../utils/theme.js";
|
|
5
|
+
function BashToolResultMessage({ content, verbose }) {
|
|
6
|
+
const { stdout, stdoutLines, stderr, stderrLines } = content;
|
|
7
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, stdout !== "" ? /* @__PURE__ */ React.createElement(OutputLine, { content: stdout, lines: stdoutLines, verbose }) : null, stderr !== "" ? /* @__PURE__ */ React.createElement(
|
|
8
|
+
OutputLine,
|
|
9
|
+
{
|
|
10
|
+
content: stderr,
|
|
11
|
+
lines: stderrLines,
|
|
12
|
+
verbose,
|
|
13
|
+
isError: true
|
|
14
|
+
}
|
|
15
|
+
) : null, stdout === "" && stderr === "" ? /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Text, { color: getTheme().secondaryText }, "(No content)")) : null);
|
|
16
|
+
}
|
|
17
|
+
var BashToolResultMessage_default = BashToolResultMessage;
|
|
18
|
+
export {
|
|
19
|
+
BashToolResultMessage_default as default
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=BashToolResultMessage.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tools/BashTool/BashToolResultMessage.tsx"],
|
|
4
|
+
"sourcesContent": ["import { Box, Text } from 'ink'\nimport { OutputLine } from './OutputLine'\nimport React from 'react'\nimport { getTheme } from '../../utils/theme'\nimport { Out as BashOut } from './BashTool'\n\ntype Props = {\n content: Omit<BashOut, 'interrupted'>\n verbose: boolean\n}\n\nfunction BashToolResultMessage({ content, verbose }: Props): React.JSX.Element {\n const { stdout, stdoutLines, stderr, stderrLines } = content\n\n return (\n <Box flexDirection=\"column\">\n {stdout !== '' ? (\n <OutputLine content={stdout} lines={stdoutLines} verbose={verbose} />\n ) : null}\n {stderr !== '' ? (\n <OutputLine\n content={stderr}\n lines={stderrLines}\n verbose={verbose}\n isError\n />\n ) : null}\n {stdout === '' && stderr === '' ? (\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Text color={getTheme().secondaryText}>(No content)</Text>\n </Box>\n ) : null}\n </Box>\n )\n}\n\nexport default BashToolResultMessage\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,SAAS,kBAAkB;AAC3B,OAAO,WAAW;AAClB,SAAS,gBAAgB;AAQzB,SAAS,sBAAsB,EAAE,SAAS,QAAQ,GAA6B;AAC7E,QAAM,EAAE,QAAQ,aAAa,QAAQ,YAAY,IAAI;AAErD,SACE,oCAAC,OAAI,eAAc,YAChB,WAAW,KACV,oCAAC,cAAW,SAAS,QAAQ,OAAO,aAAa,SAAkB,IACjE,MACH,WAAW,KACV;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,OAAO;AAAA,MACP;AAAA,MACA,SAAO;AAAA;AAAA,EACT,IACE,MACH,WAAW,MAAM,WAAW,KAC3B,oCAAC,OAAI,eAAc,SACjB,oCAAC,YAAK,qBAAoB,GAC1B,oCAAC,QAAK,OAAO,SAAS,EAAE,iBAAe,cAAY,CACrD,IACE,IACN;AAEJ;AAEA,IAAO,gCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Box, Text } from "ink";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { getTheme } from "../../utils/theme.js";
|
|
4
|
+
import { MAX_RENDERED_LINES } from "./prompt.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
function renderTruncatedContent(content, totalLines) {
|
|
7
|
+
const allLines = content.split("\n");
|
|
8
|
+
if (allLines.length <= MAX_RENDERED_LINES) {
|
|
9
|
+
return allLines.join("\n");
|
|
10
|
+
}
|
|
11
|
+
const lastLines = allLines.slice(-MAX_RENDERED_LINES);
|
|
12
|
+
return [
|
|
13
|
+
chalk.grey(
|
|
14
|
+
`Showing last ${MAX_RENDERED_LINES} lines of ${totalLines} total lines`
|
|
15
|
+
),
|
|
16
|
+
...lastLines
|
|
17
|
+
].join("\n");
|
|
18
|
+
}
|
|
19
|
+
function OutputLine({
|
|
20
|
+
content,
|
|
21
|
+
lines,
|
|
22
|
+
verbose,
|
|
23
|
+
isError
|
|
24
|
+
}) {
|
|
25
|
+
return /* @__PURE__ */ React.createElement(Box, { justifyContent: "space-between", width: "100%" }, /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\u23BF \xA0"), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { color: isError ? getTheme().error : void 0 }, verbose ? content.trim() : renderTruncatedContent(content.trim(), lines)))));
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
OutputLine
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=OutputLine.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tools/BashTool/OutputLine.tsx"],
|
|
4
|
+
"sourcesContent": ["import { Box, Text } from 'ink'\nimport * as React from 'react'\nimport { getTheme } from '../../utils/theme'\nimport { MAX_RENDERED_LINES } from './prompt'\nimport chalk from 'chalk'\n\nfunction renderTruncatedContent(content: string, totalLines: number): string {\n const allLines = content.split('\\n')\n if (allLines.length <= MAX_RENDERED_LINES) {\n return allLines.join('\\n')\n }\n\n // Show last 5 lines of output by default (matching reference implementation)\n const lastLines = allLines.slice(-MAX_RENDERED_LINES)\n return [\n chalk.grey(\n `Showing last ${MAX_RENDERED_LINES} lines of ${totalLines} total lines`,\n ),\n ...lastLines,\n ].join('\\n')\n}\n\nexport function OutputLine({\n content,\n lines,\n verbose,\n isError,\n}: {\n content: string\n lines: number\n verbose: boolean\n isError?: boolean\n key?: React.Key\n}) {\n return (\n <Box justifyContent=\"space-between\" width=\"100%\">\n <Box flexDirection=\"row\">\n <Text> \u23BF </Text>\n <Box flexDirection=\"column\">\n <Text color={isError ? getTheme().error : undefined}>\n {verbose\n ? content.trim()\n : renderTruncatedContent(content.trim(), lines)}\n </Text>\n </Box>\n </Box>\n </Box>\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,KAAK,YAAY;AAC1B,YAAY,WAAW;AACvB,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AACnC,OAAO,WAAW;AAElB,SAAS,uBAAuB,SAAiB,YAA4B;AAC3E,QAAM,WAAW,QAAQ,MAAM,IAAI;AACnC,MAAI,SAAS,UAAU,oBAAoB;AACzC,WAAO,SAAS,KAAK,IAAI;AAAA,EAC3B;AAGA,QAAM,YAAY,SAAS,MAAM,CAAC,kBAAkB;AACpD,SAAO;AAAA,IACL,MAAM;AAAA,MACJ,gBAAgB,kBAAkB,aAAa,UAAU;AAAA,IAC3D;AAAA,IACA,GAAG;AAAA,EACL,EAAE,KAAK,IAAI;AACb;AAEO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAMG;AACD,SACE,oCAAC,OAAI,gBAAe,iBAAgB,OAAM,UACxC,oCAAC,OAAI,eAAc,SACjB,oCAAC,YAAK,qBAAoB,GAC1B,oCAAC,OAAI,eAAc,YACjB,oCAAC,QAAK,OAAO,UAAU,SAAS,EAAE,QAAQ,UACvC,UACG,QAAQ,KAAK,IACb,uBAAuB,QAAQ,KAAK,GAAG,KAAK,CAClD,CACF,CACF,CACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { PRODUCT_NAME, PRODUCT_URL } from "../../constants/product.js";
|
|
2
|
+
import { TOOL_NAME as TASK_TOOL_NAME } from "../TaskTool/constants.js";
|
|
3
|
+
import { FileReadTool } from "../FileReadTool/FileReadTool.js";
|
|
4
|
+
import { TOOL_NAME_FOR_PROMPT as GLOB_TOOL_NAME } from "../GlobTool/prompt.js";
|
|
5
|
+
import { TOOL_NAME_FOR_PROMPT as GREP_TOOL_NAME } from "../GrepTool/prompt.js";
|
|
6
|
+
import { LSTool } from "../lsTool/lsTool.js";
|
|
7
|
+
const MAX_OUTPUT_LENGTH = 3e4;
|
|
8
|
+
const MAX_RENDERED_LINES = 5;
|
|
9
|
+
const BANNED_COMMANDS = [
|
|
10
|
+
"alias",
|
|
11
|
+
"curl",
|
|
12
|
+
"curlie",
|
|
13
|
+
"wget",
|
|
14
|
+
"axel",
|
|
15
|
+
"aria2c",
|
|
16
|
+
"nc",
|
|
17
|
+
"telnet",
|
|
18
|
+
"lynx",
|
|
19
|
+
"w3m",
|
|
20
|
+
"links",
|
|
21
|
+
"httpie",
|
|
22
|
+
"xh",
|
|
23
|
+
"http-prompt",
|
|
24
|
+
"chrome",
|
|
25
|
+
"firefox",
|
|
26
|
+
"safari"
|
|
27
|
+
];
|
|
28
|
+
const PROMPT = `Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
|
|
29
|
+
|
|
30
|
+
Before executing the command, please follow these steps:
|
|
31
|
+
|
|
32
|
+
1. Directory Verification:
|
|
33
|
+
- If the command will create new directories or files, first use the LS tool to verify the parent directory exists and is the correct location
|
|
34
|
+
- For example, before running "mkdir foo/bar", first use LS to check that "foo" exists and is the intended parent directory
|
|
35
|
+
|
|
36
|
+
2. Security Check:
|
|
37
|
+
- For security and to limit the threat of a prompt injection attack, some commands are limited or banned. If you use a disallowed command, you will receive an error message explaining the restriction. Explain the error to the User.
|
|
38
|
+
- Verify that the command is not one of the banned commands: ${BANNED_COMMANDS.join(", ")}.
|
|
39
|
+
|
|
40
|
+
3. Command Execution:
|
|
41
|
+
- After ensuring proper quoting, execute the command.
|
|
42
|
+
- Capture the output of the command.
|
|
43
|
+
|
|
44
|
+
4. Output Processing:
|
|
45
|
+
- If the output exceeds ${MAX_OUTPUT_LENGTH} characters, output will be truncated before being returned to you.
|
|
46
|
+
- Prepare the output for display to the user.
|
|
47
|
+
|
|
48
|
+
5. Return Result:
|
|
49
|
+
- Provide the processed output of the command.
|
|
50
|
+
- If any errors occurred during execution, include those in the output.
|
|
51
|
+
|
|
52
|
+
Usage notes:
|
|
53
|
+
- The command argument is required.
|
|
54
|
+
- You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will timeout after 30 minutes.
|
|
55
|
+
- VERY IMPORTANT: You MUST avoid using search commands like \`find\` and \`grep\`. Instead use ${GREP_TOOL_NAME}, ${GLOB_TOOL_NAME}, or ${TASK_TOOL_NAME} to search. You MUST avoid read tools like \`cat\`, \`head\`, \`tail\`, and \`ls\`, and use ${FileReadTool.name} and ${LSTool.name} to read files.
|
|
56
|
+
- When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).
|
|
57
|
+
- IMPORTANT: All commands share the same shell session. Shell state (environment variables, virtual environments, current directory, etc.) persist between commands. For example, if you set an environment variable as part of a command, the environment variable will persist for subsequent commands.
|
|
58
|
+
- Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of \`cd\`. You may use \`cd\` if the User explicitly requests it.
|
|
59
|
+
<good-example>
|
|
60
|
+
pytest /foo/bar/tests
|
|
61
|
+
</good-example>
|
|
62
|
+
<bad-example>
|
|
63
|
+
cd /foo/bar && pytest tests
|
|
64
|
+
</bad-example>
|
|
65
|
+
|
|
66
|
+
# Committing changes with git
|
|
67
|
+
|
|
68
|
+
When the user asks you to create a new git commit, follow these steps carefully:
|
|
69
|
+
|
|
70
|
+
1. Start with a single message that contains exactly three tool_use blocks that do the following (it is VERY IMPORTANT that you send these tool_use blocks in a single message, otherwise it will feel slow to the user!):
|
|
71
|
+
- Run a git status command to see all untracked files.
|
|
72
|
+
- Run a git diff command to see both staged and unstaged changes that will be committed.
|
|
73
|
+
- Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
|
|
74
|
+
|
|
75
|
+
2. Use the git context at the start of this conversation to determine which files are relevant to your commit. Add relevant untracked files to the staging area. Do not commit files that were already modified at the start of this conversation, if they are not relevant to your commit.
|
|
76
|
+
|
|
77
|
+
3. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:
|
|
78
|
+
|
|
79
|
+
<commit_analysis>
|
|
80
|
+
- List the files that have been changed or added
|
|
81
|
+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
|
|
82
|
+
- Brainstorm the purpose or motivation behind these changes
|
|
83
|
+
- Do not use tools to explore code, beyond what is available in the git context
|
|
84
|
+
- Assess the impact of these changes on the overall project
|
|
85
|
+
- Check for any sensitive information that shouldn't be committed
|
|
86
|
+
- Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
|
|
87
|
+
- Ensure your language is clear, concise, and to the point
|
|
88
|
+
- Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
|
|
89
|
+
- Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
|
|
90
|
+
- Review the draft message to ensure it accurately reflects the changes and their purpose
|
|
91
|
+
</commit_analysis>
|
|
92
|
+
|
|
93
|
+
4. Create the commit with a message ending with:
|
|
94
|
+
\u{1F916} Generated with ${PRODUCT_NAME} & {MODEL_NAME}
|
|
95
|
+
Co-Authored-By: ${PRODUCT_NAME} <noreply@${PRODUCT_NAME}.com>
|
|
96
|
+
|
|
97
|
+
- In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example:
|
|
98
|
+
<example>
|
|
99
|
+
git commit -m "$(cat <<'EOF'
|
|
100
|
+
Commit message here.
|
|
101
|
+
|
|
102
|
+
\u{1F916} Generated with ${PRODUCT_NAME} & {MODEL_NAME}
|
|
103
|
+
Co-Authored-By: ${PRODUCT_NAME} <noreply@${PRODUCT_NAME}.com>
|
|
104
|
+
EOF
|
|
105
|
+
)"
|
|
106
|
+
</example>
|
|
107
|
+
|
|
108
|
+
5. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.
|
|
109
|
+
|
|
110
|
+
6. Finally, run git status to make sure the commit succeeded.
|
|
111
|
+
|
|
112
|
+
Important notes:
|
|
113
|
+
- When possible, combine the "git add" and "git commit" commands into a single "git commit -am" command, to speed things up
|
|
114
|
+
- However, be careful not to stage files (e.g. with \`git add .\`) for commits that aren't part of the change, they may have untracked files they want to keep around, but not commit.
|
|
115
|
+
- NEVER update the git config
|
|
116
|
+
- DO NOT push to the remote repository
|
|
117
|
+
- IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
|
|
118
|
+
- If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
|
|
119
|
+
- Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
|
|
120
|
+
- Return an empty response - the user will see the git output directly
|
|
121
|
+
|
|
122
|
+
# Creating pull requests
|
|
123
|
+
Use the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.
|
|
124
|
+
|
|
125
|
+
IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
|
|
126
|
+
|
|
127
|
+
1. Understand the current state of the branch. Remember to send a single message that contains multiple tool_use blocks (it is VERY IMPORTANT that you do this in a single message, otherwise it will feel slow to the user!):
|
|
128
|
+
- Run a git status command to see all untracked files.
|
|
129
|
+
- Run a git diff command to see both staged and unstaged changes that will be committed.
|
|
130
|
+
- Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote
|
|
131
|
+
- Run a git log command and \`git diff main...HEAD\` to understand the full commit history for the current branch (from the time it diverged from the \`main\` branch.)
|
|
132
|
+
|
|
133
|
+
2. Create new branch if needed
|
|
134
|
+
|
|
135
|
+
3. Commit changes if needed
|
|
136
|
+
|
|
137
|
+
4. Push to remote with -u flag if needed
|
|
138
|
+
|
|
139
|
+
5. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (not just the latest commit, but all commits that will be included in the pull request!), and draft a pull request summary. Wrap your analysis process in <pr_analysis> tags:
|
|
140
|
+
|
|
141
|
+
<pr_analysis>
|
|
142
|
+
- List the commits since diverging from the main branch
|
|
143
|
+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
|
|
144
|
+
- Brainstorm the purpose or motivation behind these changes
|
|
145
|
+
- Assess the impact of these changes on the overall project
|
|
146
|
+
- Do not use tools to explore code, beyond what is available in the git context
|
|
147
|
+
- Check for any sensitive information that shouldn't be committed
|
|
148
|
+
- Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
|
|
149
|
+
- Ensure the summary accurately reflects all changes since diverging from the main branch
|
|
150
|
+
- Ensure your language is clear, concise, and to the point
|
|
151
|
+
- Ensure the summary accurately reflects the changes and their purpose (ie. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
|
|
152
|
+
- Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
|
|
153
|
+
- Review the draft summary to ensure it accurately reflects the changes and their purpose
|
|
154
|
+
</pr_analysis>
|
|
155
|
+
|
|
156
|
+
6. Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
|
|
157
|
+
<example>
|
|
158
|
+
gh pr create --title "the pr title" --body "$(cat <<'EOF'
|
|
159
|
+
## Summary
|
|
160
|
+
<1-3 bullet points>
|
|
161
|
+
|
|
162
|
+
## Test plan
|
|
163
|
+
[Checklist of TODOs for testing the pull request...]
|
|
164
|
+
|
|
165
|
+
\u{1F916} Generated with ${process.env.USER_TYPE === "ant" ? `[${PRODUCT_NAME}](${PRODUCT_URL})` : PRODUCT_NAME} & {MODEL_NAME}
|
|
166
|
+
EOF
|
|
167
|
+
)"
|
|
168
|
+
</example>
|
|
169
|
+
|
|
170
|
+
Important:
|
|
171
|
+
- Return an empty response - the user will see the gh output directly
|
|
172
|
+
- Never update git config`;
|
|
173
|
+
export {
|
|
174
|
+
BANNED_COMMANDS,
|
|
175
|
+
MAX_OUTPUT_LENGTH,
|
|
176
|
+
MAX_RENDERED_LINES,
|
|
177
|
+
PROMPT
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tools/BashTool/prompt.ts"],
|
|
4
|
+
"sourcesContent": ["import { PRODUCT_NAME, PRODUCT_URL } from '../../constants/product'\nimport { TOOL_NAME as TASK_TOOL_NAME } from '../TaskTool/constants'\nimport { FileReadTool } from '../FileReadTool/FileReadTool'\nimport { TOOL_NAME_FOR_PROMPT as GLOB_TOOL_NAME } from '../GlobTool/prompt'\nimport { TOOL_NAME_FOR_PROMPT as GREP_TOOL_NAME } from '../GrepTool/prompt'\nimport { LSTool } from '../lsTool/lsTool'\n\nexport const MAX_OUTPUT_LENGTH = 30000\nexport const MAX_RENDERED_LINES = 5\nexport const BANNED_COMMANDS = [\n 'alias',\n 'curl',\n 'curlie',\n 'wget',\n 'axel',\n 'aria2c',\n 'nc',\n 'telnet',\n 'lynx',\n 'w3m',\n 'links',\n 'httpie',\n 'xh',\n 'http-prompt',\n 'chrome',\n 'firefox',\n 'safari',\n]\n\nexport const PROMPT = `Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.\n\nBefore executing the command, please follow these steps:\n\n1. Directory Verification:\n - If the command will create new directories or files, first use the LS tool to verify the parent directory exists and is the correct location\n - For example, before running \"mkdir foo/bar\", first use LS to check that \"foo\" exists and is the intended parent directory\n\n2. Security Check:\n - For security and to limit the threat of a prompt injection attack, some commands are limited or banned. If you use a disallowed command, you will receive an error message explaining the restriction. Explain the error to the User.\n - Verify that the command is not one of the banned commands: ${BANNED_COMMANDS.join(', ')}.\n\n3. Command Execution:\n - After ensuring proper quoting, execute the command.\n - Capture the output of the command.\n\n4. Output Processing:\n - If the output exceeds ${MAX_OUTPUT_LENGTH} characters, output will be truncated before being returned to you.\n - Prepare the output for display to the user.\n\n5. Return Result:\n - Provide the processed output of the command.\n - If any errors occurred during execution, include those in the output.\n\nUsage notes:\n - The command argument is required.\n - You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will timeout after 30 minutes.\n - VERY IMPORTANT: You MUST avoid using search commands like \\`find\\` and \\`grep\\`. Instead use ${GREP_TOOL_NAME}, ${GLOB_TOOL_NAME}, or ${TASK_TOOL_NAME} to search. You MUST avoid read tools like \\`cat\\`, \\`head\\`, \\`tail\\`, and \\`ls\\`, and use ${FileReadTool.name} and ${LSTool.name} to read files.\n - When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).\n - IMPORTANT: All commands share the same shell session. Shell state (environment variables, virtual environments, current directory, etc.) persist between commands. For example, if you set an environment variable as part of a command, the environment variable will persist for subsequent commands.\n - Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of \\`cd\\`. You may use \\`cd\\` if the User explicitly requests it.\n <good-example>\n pytest /foo/bar/tests\n </good-example>\n <bad-example>\n cd /foo/bar && pytest tests\n </bad-example>\n\n# Committing changes with git\n\nWhen the user asks you to create a new git commit, follow these steps carefully:\n\n1. Start with a single message that contains exactly three tool_use blocks that do the following (it is VERY IMPORTANT that you send these tool_use blocks in a single message, otherwise it will feel slow to the user!):\n - Run a git status command to see all untracked files.\n - Run a git diff command to see both staged and unstaged changes that will be committed.\n - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.\n\n2. Use the git context at the start of this conversation to determine which files are relevant to your commit. Add relevant untracked files to the staging area. Do not commit files that were already modified at the start of this conversation, if they are not relevant to your commit.\n\n3. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:\n\n<commit_analysis>\n- List the files that have been changed or added\n- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)\n- Brainstorm the purpose or motivation behind these changes\n- Do not use tools to explore code, beyond what is available in the git context\n- Assess the impact of these changes on the overall project\n- Check for any sensitive information that shouldn't be committed\n- Draft a concise (1-2 sentences) commit message that focuses on the \"why\" rather than the \"what\"\n- Ensure your language is clear, concise, and to the point\n- Ensure the message accurately reflects the changes and their purpose (i.e. \"add\" means a wholly new feature, \"update\" means an enhancement to an existing feature, \"fix\" means a bug fix, etc.)\n- Ensure the message is not generic (avoid words like \"Update\" or \"Fix\" without context)\n- Review the draft message to ensure it accurately reflects the changes and their purpose\n</commit_analysis>\n\n4. Create the commit with a message ending with:\n\uD83E\uDD16 Generated with ${PRODUCT_NAME} & {MODEL_NAME}\nCo-Authored-By: ${PRODUCT_NAME} <noreply@${PRODUCT_NAME}.com>\n\n- In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example:\n<example>\ngit commit -m \"$(cat <<'EOF'\n Commit message here.\n\n \uD83E\uDD16 Generated with ${PRODUCT_NAME} & {MODEL_NAME}\n Co-Authored-By: ${PRODUCT_NAME} <noreply@${PRODUCT_NAME}.com>\n EOF\n )\"\n</example>\n\n5. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.\n\n6. Finally, run git status to make sure the commit succeeded.\n\nImportant notes:\n- When possible, combine the \"git add\" and \"git commit\" commands into a single \"git commit -am\" command, to speed things up\n- However, be careful not to stage files (e.g. with \\`git add .\\`) for commits that aren't part of the change, they may have untracked files they want to keep around, but not commit.\n- NEVER update the git config\n- DO NOT push to the remote repository\n- IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.\n- If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit\n- Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.\n- Return an empty response - the user will see the git output directly\n\n# Creating pull requests\nUse the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.\n\nIMPORTANT: When the user asks you to create a pull request, follow these steps carefully:\n\n1. Understand the current state of the branch. Remember to send a single message that contains multiple tool_use blocks (it is VERY IMPORTANT that you do this in a single message, otherwise it will feel slow to the user!):\n - Run a git status command to see all untracked files.\n - Run a git diff command to see both staged and unstaged changes that will be committed.\n - Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote\n - Run a git log command and \\`git diff main...HEAD\\` to understand the full commit history for the current branch (from the time it diverged from the \\`main\\` branch.)\n\n2. Create new branch if needed\n\n3. Commit changes if needed\n\n4. Push to remote with -u flag if needed\n\n5. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (not just the latest commit, but all commits that will be included in the pull request!), and draft a pull request summary. Wrap your analysis process in <pr_analysis> tags:\n\n<pr_analysis>\n- List the commits since diverging from the main branch\n- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)\n- Brainstorm the purpose or motivation behind these changes\n- Assess the impact of these changes on the overall project\n- Do not use tools to explore code, beyond what is available in the git context\n- Check for any sensitive information that shouldn't be committed\n- Draft a concise (1-2 bullet points) pull request summary that focuses on the \"why\" rather than the \"what\"\n- Ensure the summary accurately reflects all changes since diverging from the main branch\n- Ensure your language is clear, concise, and to the point\n- Ensure the summary accurately reflects the changes and their purpose (ie. \"add\" means a wholly new feature, \"update\" means an enhancement to an existing feature, \"fix\" means a bug fix, etc.)\n- Ensure the summary is not generic (avoid words like \"Update\" or \"Fix\" without context)\n- Review the draft summary to ensure it accurately reflects the changes and their purpose\n</pr_analysis>\n\n6. Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.\n<example>\ngh pr create --title \"the pr title\" --body \"$(cat <<'EOF'\n## Summary\n<1-3 bullet points>\n\n## Test plan\n[Checklist of TODOs for testing the pull request...]\n\n\uD83E\uDD16 Generated with ${process.env.USER_TYPE === 'ant' ? `[${PRODUCT_NAME}](${PRODUCT_URL})` : PRODUCT_NAME} & {MODEL_NAME}\nEOF\n)\"\n</example>\n\nImportant:\n- Return an empty response - the user will see the gh output directly\n- Never update git config`\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc,mBAAmB;AAC1C,SAAS,aAAa,sBAAsB;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB,sBAAsB;AACvD,SAAS,wBAAwB,sBAAsB;AACvD,SAAS,cAAc;AAEhB,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kEAU4C,gBAAgB,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAO/D,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mGAUqD,cAAc,KAAK,cAAc,QAAQ,cAAc,+FAA+F,aAAa,IAAI,QAAQ,OAAO,IAAI;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,2BAuCzQ,YAAY;AAAA,kBACd,YAAY,aAAa,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAOhC,YAAY;AAAA,qBACd,YAAY,aAAa,YAAY;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BA8DtC,QAAQ,IAAI,cAAc,QAAQ,IAAI,YAAY,KAAK,WAAW,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { queryQuick } from "../../services/claude.js";
|
|
2
|
+
import { extractTag } from "../../utils/messages.js";
|
|
3
|
+
import { MAX_OUTPUT_LENGTH } from "./prompt.js";
|
|
4
|
+
function formatOutput(content) {
|
|
5
|
+
if (content.length <= MAX_OUTPUT_LENGTH) {
|
|
6
|
+
return {
|
|
7
|
+
totalLines: content.split("\n").length,
|
|
8
|
+
truncatedContent: content
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const halfLength = MAX_OUTPUT_LENGTH / 2;
|
|
12
|
+
const start = content.slice(0, halfLength);
|
|
13
|
+
const end = content.slice(-halfLength);
|
|
14
|
+
const truncated = `${start}
|
|
15
|
+
|
|
16
|
+
... [${content.slice(halfLength, -halfLength).split("\n").length} lines truncated] ...
|
|
17
|
+
|
|
18
|
+
${end}`;
|
|
19
|
+
return {
|
|
20
|
+
totalLines: content.split("\n").length,
|
|
21
|
+
truncatedContent: truncated
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function getCommandFilePaths(command, output) {
|
|
25
|
+
const response = await queryQuick({
|
|
26
|
+
systemPrompt: [
|
|
27
|
+
`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.
|
|
28
|
+
Format your response as:
|
|
29
|
+
<filepaths>
|
|
30
|
+
path/to/file1
|
|
31
|
+
path/to/file2
|
|
32
|
+
</filepaths>
|
|
33
|
+
|
|
34
|
+
If no files are read or modified, return empty filepaths tags:
|
|
35
|
+
<filepaths>
|
|
36
|
+
</filepaths>
|
|
37
|
+
|
|
38
|
+
Do not include any other text in your response.`
|
|
39
|
+
],
|
|
40
|
+
userPrompt: `Command: ${command}
|
|
41
|
+
Output: ${output}`,
|
|
42
|
+
enablePromptCaching: true
|
|
43
|
+
});
|
|
44
|
+
const content = response.message.content.filter((_) => _.type === "text").map((_) => _.text).join("");
|
|
45
|
+
return extractTag(content, "filepaths")?.trim().split("\n").filter(Boolean) || [];
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
formatOutput,
|
|
49
|
+
getCommandFilePaths
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|