@within-7/minto 0.3.9 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Tool.js.map +2 -2
- package/dist/commands/agents/AgentsCommand.js +461 -657
- package/dist/commands/agents/AgentsCommand.js.map +2 -2
- package/dist/commands/agents/types.js +1 -0
- package/dist/commands/agents/types.js.map +2 -2
- package/dist/commands/agents/utils/fileOperations.js +96 -36
- package/dist/commands/agents/utils/fileOperations.js.map +3 -3
- package/dist/commands/agents/utils/index.js +3 -1
- package/dist/commands/agents/utils/index.js.map +2 -2
- package/dist/commands/context.js +54 -23
- package/dist/commands/context.js.map +2 -2
- package/dist/commands/ctx_viz.js +1 -1
- package/dist/commands/effort.js +87 -0
- package/dist/commands/effort.js.map +7 -0
- package/dist/commands/export.js +684 -94
- package/dist/commands/export.js.map +2 -2
- package/dist/commands/ide.js +18 -0
- package/dist/commands/ide.js.map +7 -0
- package/dist/commands/language.js +19 -46
- package/dist/commands/language.js.map +2 -2
- package/dist/commands/mcp-interactive.js +425 -217
- package/dist/commands/mcp-interactive.js.map +2 -2
- package/dist/commands/memory.js +168 -0
- package/dist/commands/memory.js.map +7 -0
- package/dist/commands/model.js +457 -65
- package/dist/commands/model.js.map +2 -2
- package/dist/commands/outputStyle.js +64 -0
- package/dist/commands/outputStyle.js.map +7 -0
- package/dist/commands/permissions.js +75 -49
- package/dist/commands/permissions.js.map +2 -2
- package/dist/commands/plugin/utils.js +33 -1
- package/dist/commands/plugin/utils.js.map +2 -2
- package/dist/commands/plugin.js +891 -185
- package/dist/commands/plugin.js.map +3 -3
- package/dist/commands/refreshCommands.js +2 -0
- package/dist/commands/refreshCommands.js.map +2 -2
- package/dist/commands/resume.js +1 -1
- package/dist/commands/resume.js.map +1 -1
- package/dist/commands/review.js +51 -0
- package/dist/commands/review.js.map +7 -0
- package/dist/commands/sandbox.js +168 -70
- package/dist/commands/sandbox.js.map +2 -2
- package/dist/commands/setup.js +593 -107
- package/dist/commands/setup.js.map +2 -2
- package/dist/commands/stats.js +188 -131
- package/dist/commands/stats.js.map +2 -2
- package/dist/commands/status.js +75 -13
- package/dist/commands/status.js.map +2 -2
- package/dist/commands/terminalSetup.js +6 -0
- package/dist/commands/terminalSetup.js.map +2 -2
- package/dist/commands/undo.js +146 -174
- package/dist/commands/undo.js.map +2 -2
- package/dist/commands/vim.js +22 -0
- package/dist/commands/vim.js.map +7 -0
- package/dist/commands.js +12 -0
- package/dist/commands.js.map +2 -2
- package/dist/components/Help.js +165 -32
- package/dist/components/Help.js.map +2 -2
- package/dist/components/HighlightedCode.js +1 -0
- package/dist/components/HighlightedCode.js.map +2 -2
- package/dist/components/InfoPanel/InfoPanel.js +123 -0
- package/dist/components/InfoPanel/InfoPanel.js.map +7 -0
- package/dist/components/InfoPanel/index.js +5 -0
- package/dist/components/InfoPanel/index.js.map +7 -0
- package/dist/components/InfoPanel/types.js +1 -0
- package/dist/components/InfoPanel/types.js.map +7 -0
- package/dist/components/ModelSelector/BrandTextInput.js +43 -0
- package/dist/components/ModelSelector/BrandTextInput.js.map +7 -0
- package/dist/components/ModelSelector/ModelSelector.js +590 -565
- package/dist/components/ModelSelector/ModelSelector.js.map +2 -2
- package/dist/components/ModelSelector/WizardContainer.js +45 -0
- package/dist/components/ModelSelector/WizardContainer.js.map +7 -0
- package/dist/components/ModelSelector/index.js +1 -3
- package/dist/components/ModelSelector/index.js.map +2 -2
- package/dist/components/PromptInput.js +26 -11
- package/dist/components/PromptInput.js.map +2 -2
- package/dist/components/PulseLabel.js +44 -0
- package/dist/components/PulseLabel.js.map +7 -0
- package/dist/components/RequestStatusIndicator.js +1 -1
- package/dist/components/RequestStatusIndicator.js.map +1 -1
- package/dist/components/SimpleSelector/SimpleSelector.js +154 -0
- package/dist/components/SimpleSelector/SimpleSelector.js.map +7 -0
- package/dist/components/SimpleSelector/index.js +5 -0
- package/dist/components/SimpleSelector/index.js.map +7 -0
- package/dist/components/SimpleSelector/types.js +1 -0
- package/dist/components/SimpleSelector/types.js.map +7 -0
- package/dist/components/Spinner.js +12 -42
- package/dist/components/Spinner.js.map +3 -3
- package/dist/components/StartupStatus.js +57 -0
- package/dist/components/StartupStatus.js.map +7 -0
- package/dist/components/StatusOverlayContent.js +21 -0
- package/dist/components/StatusOverlayContent.js.map +7 -0
- package/dist/components/SubagentBlock.js +43 -6
- package/dist/components/SubagentBlock.js.map +2 -2
- package/dist/components/TabbedListView/ScrollableList.js +31 -5
- package/dist/components/TabbedListView/ScrollableList.js.map +2 -2
- package/dist/components/TabbedListView/TabBar.js +13 -8
- package/dist/components/TabbedListView/TabBar.js.map +2 -2
- package/dist/components/TabbedListView/TabbedListView.js +123 -48
- package/dist/components/TabbedListView/TabbedListView.js.map +2 -2
- package/dist/components/TodoPanel.js +1 -1
- package/dist/components/TodoPanel.js.map +1 -1
- package/dist/components/ToolUseLoader.js +5 -0
- package/dist/components/ToolUseLoader.js.map +2 -2
- package/dist/components/TrustDialog.js +0 -2
- package/dist/components/TrustDialog.js.map +2 -2
- package/dist/components/messages/TaskInModuleView.js +1 -1
- package/dist/components/messages/TaskInModuleView.js.map +2 -2
- package/dist/components/messages/TaskToolMessage.js +1 -1
- package/dist/components/messages/TaskToolMessage.js.map +2 -2
- package/dist/components/messages/UserPromptMessage.js +6 -1
- package/dist/components/messages/UserPromptMessage.js.map +2 -2
- package/dist/constants/modelCapabilities.js +103 -18
- package/dist/constants/modelCapabilities.js.map +2 -2
- package/dist/constants/product.js +2 -0
- package/dist/constants/product.js.map +2 -2
- package/dist/constants/prompts/agentPrompt.js +30 -0
- package/dist/constants/prompts/agentPrompt.js.map +7 -0
- package/dist/constants/prompts/codeConventions.js +27 -0
- package/dist/constants/prompts/codeConventions.js.map +7 -0
- package/dist/constants/prompts/doingTasks.js +15 -0
- package/dist/constants/prompts/doingTasks.js.map +7 -0
- package/dist/constants/prompts/envInfo.js +17 -0
- package/dist/constants/prompts/envInfo.js.map +7 -0
- package/dist/constants/prompts/executingWithCare.js +17 -0
- package/dist/constants/prompts/executingWithCare.js.map +7 -0
- package/dist/constants/prompts/identity.js +10 -0
- package/dist/constants/prompts/identity.js.map +7 -0
- package/dist/constants/prompts/index.js +78 -0
- package/dist/constants/prompts/index.js.map +7 -0
- package/dist/constants/prompts/taskManagement.js +60 -0
- package/dist/constants/prompts/taskManagement.js.map +7 -0
- package/dist/constants/prompts/toneAndStyle.js +62 -0
- package/dist/constants/prompts/toneAndStyle.js.map +7 -0
- package/dist/constants/prompts/toolUsagePolicy.js +38 -0
- package/dist/constants/prompts/toolUsagePolicy.js.map +7 -0
- package/dist/constants/prompts.js +5 -176
- package/dist/constants/prompts.js.map +2 -2
- package/dist/constants/providerRegistry.js +235 -0
- package/dist/constants/providerRegistry.js.map +7 -0
- package/dist/constants/providers.js +35 -0
- package/dist/constants/providers.js.map +7 -0
- package/dist/context/PermissionContext.js +0 -1
- package/dist/context/PermissionContext.js.map +2 -2
- package/dist/context.js +87 -31
- package/dist/context.js.map +2 -2
- package/dist/core/backupHook.js +29 -0
- package/dist/core/backupHook.js.map +7 -0
- package/dist/core/config/defaults.js +11 -2
- package/dist/core/config/defaults.js.map +2 -2
- package/dist/core/config/schema.js +21 -3
- package/dist/core/config/schema.js.map +2 -2
- package/dist/core/costTracker.js +18 -16
- package/dist/core/costTracker.js.map +2 -2
- package/dist/core/index.js +0 -1
- package/dist/core/index.js.map +2 -2
- package/dist/core/tokenStatsManager.js +22 -4
- package/dist/core/tokenStatsManager.js.map +2 -2
- package/dist/cost-tracker.js +0 -16
- package/dist/cost-tracker.js.map +2 -2
- package/dist/entrypoints/bootstrap.js +3 -1
- package/dist/entrypoints/bootstrap.js.map +2 -2
- package/dist/entrypoints/cli.js +81 -68
- package/dist/entrypoints/cli.js.map +2 -2
- package/dist/hooks/useAgentTokenStats.js +1 -1
- package/dist/hooks/useAgentTokenStats.js.map +2 -2
- package/dist/hooks/useAgentTranscripts.js +2 -1
- package/dist/hooks/useAgentTranscripts.js.map +2 -2
- package/dist/hooks/useBackgroundShells.js +29 -0
- package/dist/hooks/useBackgroundShells.js.map +7 -0
- package/dist/hooks/useCanUseTool.js +1 -1
- package/dist/hooks/useCanUseTool.js.map +2 -2
- package/dist/hooks/useDeferredLoading.js +64 -0
- package/dist/hooks/useDeferredLoading.js.map +7 -0
- package/dist/hooks/useHookStatus.js +1 -1
- package/dist/hooks/useHookStatus.js.map +2 -2
- package/dist/hooks/useSessionTracking.js +55 -0
- package/dist/hooks/useSessionTracking.js.map +7 -0
- package/dist/hooks/useTerminalSize.js +21 -0
- package/dist/hooks/useTerminalSize.js.map +2 -2
- package/dist/hooks/useTextInput.js +1 -0
- package/dist/hooks/useTextInput.js.map +2 -2
- package/dist/hooks/useUnifiedCompletion.js +3 -2
- package/dist/hooks/useUnifiedCompletion.js.map +2 -2
- package/dist/i18n/locales/en.js +299 -1
- package/dist/i18n/locales/en.js.map +2 -2
- package/dist/i18n/locales/zh-CN.js +300 -2
- package/dist/i18n/locales/zh-CN.js.map +2 -2
- package/dist/i18n/types.js.map +1 -1
- package/dist/messages.js +41 -17
- package/dist/messages.js.map +2 -2
- package/dist/permissions.js +94 -1
- package/dist/permissions.js.map +2 -2
- package/dist/query.js +27 -19
- package/dist/query.js.map +2 -2
- package/dist/screens/REPL.js +83 -74
- package/dist/screens/REPL.js.map +2 -2
- package/dist/services/adapters/responsesAPI.js +6 -0
- package/dist/services/adapters/responsesAPI.js.map +2 -2
- package/dist/services/agentTeams/index.js +35 -0
- package/dist/services/agentTeams/index.js.map +7 -0
- package/dist/services/agentTeams/mailbox.js +114 -0
- package/dist/services/agentTeams/mailbox.js.map +7 -0
- package/dist/services/agentTeams/teamManager.js +149 -0
- package/dist/services/agentTeams/teamManager.js.map +7 -0
- package/dist/services/agentTeams/teamTaskStore.js +114 -0
- package/dist/services/agentTeams/teamTaskStore.js.map +7 -0
- package/dist/services/agentTeams/teammateSpawner.js +80 -0
- package/dist/services/agentTeams/teammateSpawner.js.map +7 -0
- package/dist/services/checkpointManager.js +16 -3
- package/dist/services/checkpointManager.js.map +2 -2
- package/dist/services/claude.js +19 -1728
- package/dist/services/claude.js.map +3 -3
- package/dist/services/customCommands.js +30 -8
- package/dist/services/customCommands.js.map +2 -2
- package/dist/services/gpt5ConnectionTest.js +4 -2
- package/dist/services/gpt5ConnectionTest.js.map +2 -2
- package/dist/services/hookExecutor.js +411 -127
- package/dist/services/hookExecutor.js.map +2 -2
- package/dist/services/llm/anthropicProvider.js +807 -0
- package/dist/services/llm/anthropicProvider.js.map +7 -0
- package/dist/services/llm/dispatch.js +218 -0
- package/dist/services/llm/dispatch.js.map +7 -0
- package/dist/services/llm/index.js +44 -0
- package/dist/services/llm/index.js.map +7 -0
- package/dist/services/llm/mintoContext.js +69 -0
- package/dist/services/llm/mintoContext.js.map +7 -0
- package/dist/services/llm/openaiProvider.js +622 -0
- package/dist/services/llm/openaiProvider.js.map +7 -0
- package/dist/services/llm/types.js +157 -0
- package/dist/services/llm/types.js.map +7 -0
- package/dist/services/mcpClient.js +183 -33
- package/dist/services/mcpClient.js.map +2 -2
- package/dist/services/notifier.js +14 -0
- package/dist/services/notifier.js.map +2 -2
- package/dist/services/oauth.js +4 -2
- package/dist/services/oauth.js.map +2 -2
- package/dist/services/openai.js +66 -56
- package/dist/services/openai.js.map +3 -3
- package/dist/services/outputStyles.js +102 -21
- package/dist/services/outputStyles.js.map +2 -2
- package/dist/services/plugins/lspServers.js +1 -1
- package/dist/services/plugins/lspServers.js.map +2 -2
- package/dist/services/plugins/pluginRuntime.js +2 -1
- package/dist/services/plugins/pluginRuntime.js.map +2 -2
- package/dist/services/plugins/pluginValidation.js +10 -3
- package/dist/services/plugins/pluginValidation.js.map +2 -2
- package/dist/services/plugins/skillMarketplace.js +20 -9
- package/dist/services/plugins/skillMarketplace.js.map +2 -2
- package/dist/services/sentry.js +1 -1
- package/dist/services/sentry.js.map +2 -2
- package/dist/services/sessionMemory.js +16 -3
- package/dist/services/sessionMemory.js.map +2 -2
- package/dist/services/systemReminder.js +367 -9
- package/dist/services/systemReminder.js.map +2 -2
- package/dist/services/taskStore.js +19 -0
- package/dist/services/taskStore.js.map +2 -2
- package/dist/tools/ArchitectTool/ArchitectTool.js.map +1 -1
- package/dist/tools/AskUserQuestionTool/AskUserQuestionTool.js.map +1 -1
- package/dist/tools/BashOutputTool/BashOutputTool.js.map +1 -1
- package/dist/tools/BashTool/BashTool.js +28 -0
- package/dist/tools/BashTool/BashTool.js.map +2 -2
- package/dist/tools/FileEditTool/FileEditTool.js +8 -1
- package/dist/tools/FileEditTool/FileEditTool.js.map +2 -2
- package/dist/tools/FileReadTool/FileReadTool.js +14 -0
- package/dist/tools/FileReadTool/FileReadTool.js.map +2 -2
- package/dist/tools/FileWriteTool/FileWriteTool.js +10 -1
- package/dist/tools/FileWriteTool/FileWriteTool.js.map +2 -2
- package/dist/tools/GlobTool/GlobTool.js.map +1 -1
- package/dist/tools/GrepTool/GrepTool.js.map +1 -1
- package/dist/tools/KillShellTool/KillShellTool.js.map +1 -1
- package/dist/tools/ListMcpResourcesTool/ListMcpResourcesTool.js.map +2 -2
- package/dist/tools/LspTool/LspTool.js +11 -2
- package/dist/tools/LspTool/LspTool.js.map +2 -2
- package/dist/tools/MCPTool/MCPTool.js.map +1 -1
- package/dist/tools/MemoryReadTool/MemoryReadTool.js +2 -1
- package/dist/tools/MemoryReadTool/MemoryReadTool.js.map +2 -2
- package/dist/tools/MemoryWriteTool/MemoryWriteTool.js +2 -1
- package/dist/tools/MemoryWriteTool/MemoryWriteTool.js.map +2 -2
- package/dist/tools/MultiEditTool/MultiEditTool.js +7 -0
- package/dist/tools/MultiEditTool/MultiEditTool.js.map +2 -2
- package/dist/tools/NotebookEditTool/NotebookEditTool.js +2 -0
- package/dist/tools/NotebookEditTool/NotebookEditTool.js.map +2 -2
- package/dist/tools/NotebookReadTool/NotebookReadTool.js.map +1 -1
- package/dist/tools/PlanModeTool/EnterPlanModeTool.js +8 -2
- package/dist/tools/PlanModeTool/EnterPlanModeTool.js.map +2 -2
- package/dist/tools/PlanModeTool/ExitPlanModeTool.js +2 -0
- package/dist/tools/PlanModeTool/ExitPlanModeTool.js.map +2 -2
- package/dist/tools/ReadMcpResourceTool/ReadMcpResourceTool.js.map +1 -1
- package/dist/tools/SlashCommandTool/SlashCommandTool.js +174 -18
- package/dist/tools/SlashCommandTool/SlashCommandTool.js.map +3 -3
- package/dist/tools/TaskCreateTool/TaskCreateTool.js.map +1 -1
- package/dist/tools/TaskGetTool/TaskGetTool.js.map +1 -1
- package/dist/tools/TaskListTool/TaskListTool.js.map +1 -1
- package/dist/tools/TaskOutputTool/TaskOutputTool.js.map +1 -1
- package/dist/tools/TaskStopTool/TaskStopTool.js.map +1 -1
- package/dist/tools/TaskTool/TaskTool.js +84 -11
- package/dist/tools/TaskTool/TaskTool.js.map +2 -2
- package/dist/tools/TaskTool/prompt.js +12 -6
- package/dist/tools/TaskTool/prompt.js.map +2 -2
- package/dist/tools/TaskUpdateTool/TaskUpdateTool.js.map +1 -1
- package/dist/tools/ThinkTool/ThinkTool.js.map +1 -1
- package/dist/tools/TodoWriteTool/TodoWriteTool.js.map +1 -1
- package/dist/tools/URLFetcherTool/URLFetcherTool.js.map +1 -1
- package/dist/tools/WebSearchTool/WebSearchTool.js.map +1 -1
- package/dist/tools/WebSearchTool/searchProviders.js +2 -1
- package/dist/tools/WebSearchTool/searchProviders.js.map +2 -2
- package/dist/tools/lsTool/lsTool.js.map +2 -2
- package/dist/tools/lsTool/prompt.js.map +1 -1
- package/dist/tools.js +14 -3
- package/dist/tools.js.map +2 -2
- package/dist/types/PermissionMode.js +21 -1
- package/dist/types/PermissionMode.js.map +2 -2
- package/dist/types/agentTeams.js +1 -0
- package/dist/types/agentTeams.js.map +7 -0
- package/dist/types/hooks.js +8 -2
- package/dist/types/hooks.js.map +2 -2
- package/dist/types/plugin.js +3 -5
- package/dist/types/plugin.js.map +2 -2
- package/dist/utils/agentHookExecutor.js +1 -4
- package/dist/utils/agentHookExecutor.js.map +2 -2
- package/dist/utils/agentLoader.js +91 -15
- package/dist/utils/agentLoader.js.map +2 -2
- package/dist/utils/agentMemory.js.map +2 -2
- package/dist/utils/animationManager.js +1 -1
- package/dist/utils/animationManager.js.map +2 -2
- package/dist/utils/ask.js +1 -1
- package/dist/utils/async.js +5 -1
- package/dist/utils/async.js.map +2 -2
- package/dist/utils/autoCompactCore.js +60 -0
- package/dist/utils/autoCompactCore.js.map +2 -2
- package/dist/utils/claudeCodeSync.js +439 -0
- package/dist/utils/claudeCodeSync.js.map +7 -0
- package/dist/utils/config.js +27 -151
- package/dist/utils/config.js.map +2 -2
- package/dist/utils/configSchema.js +227 -0
- package/dist/utils/configSchema.js.map +7 -0
- package/dist/utils/debugLogger.js.map +2 -2
- package/dist/utils/env.js +4 -3
- package/dist/utils/env.js.map +2 -2
- package/dist/utils/envConfig.js +34 -0
- package/dist/utils/envConfig.js.map +3 -3
- package/dist/utils/execFileNoThrow.js +2 -1
- package/dist/utils/execFileNoThrow.js.map +2 -2
- package/dist/utils/gpt5.js +146 -0
- package/dist/utils/gpt5.js.map +7 -0
- package/dist/utils/hookManager.js +374 -140
- package/dist/utils/hookManager.js.map +2 -2
- package/dist/utils/markdown.js +47 -0
- package/dist/utils/markdown.js.map +2 -2
- package/dist/utils/marketplaceManager.js +80 -43
- package/dist/utils/marketplaceManager.js.map +2 -2
- package/dist/utils/memoizeWithTTL.js +25 -0
- package/dist/utils/memoizeWithTTL.js.map +7 -0
- package/dist/utils/messages.js +2 -2
- package/dist/utils/messages.js.map +2 -2
- package/dist/utils/model.js +34 -9
- package/dist/utils/model.js.map +2 -2
- package/dist/utils/pluginInstaller.js +68 -29
- package/dist/utils/pluginInstaller.js.map +2 -2
- package/dist/utils/pluginLoader.js +249 -57
- package/dist/utils/pluginLoader.js.map +2 -2
- package/dist/utils/repoFetcher.js +110 -0
- package/dist/utils/repoFetcher.js.map +7 -0
- package/dist/utils/safeFetch.js +45 -0
- package/dist/utils/safeFetch.js.map +7 -0
- package/dist/utils/skillLoader.js +77 -12
- package/dist/utils/skillLoader.js.map +2 -2
- package/dist/utils/streamingState.js +52 -0
- package/dist/utils/streamingState.js.map +7 -0
- package/dist/utils/stringSubstitution.js +4 -5
- package/dist/utils/stringSubstitution.js.map +2 -2
- package/dist/utils/style.js +6 -3
- package/dist/utils/style.js.map +2 -2
- package/dist/utils/teamConfig.js +162 -16
- package/dist/utils/teamConfig.js.map +2 -2
- package/dist/utils/terminal.js +1 -1
- package/dist/utils/terminal.js.map +2 -2
- package/dist/utils/toolRiskClassification.js +0 -6
- package/dist/utils/toolRiskClassification.js.map +2 -2
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +7 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/services/claude.ts"],
|
|
4
|
-
"sourcesContent": ["import '@anthropic-ai/sdk/shims/node'\nimport Anthropic, { APIConnectionError, APIError } from '@anthropic-ai/sdk'\nimport { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk'\nimport { AnthropicVertex } from '@anthropic-ai/vertex-sdk'\nimport chalk from 'chalk'\nimport { randomUUID, UUID } from 'crypto'\nimport 'dotenv/config'\n\nimport { addToTotalCost } from '@costTracker'\nimport { recordTokenUsage } from '@core/tokenStatsManager'\nimport type { TokenTrackingContext } from '@core/tokenStats'\nimport models from '@constants/models'\nimport type { AssistantMessage, UserMessage } from '@query'\nimport { Tool, getToolDescriptionAsync } from '@tool'\nimport {\n getAnthropicApiKey,\n getOrCreateUserID,\n getGlobalConfig,\n ModelProfile,\n} from '@utils/config'\nimport { getProjectDocs } from '@context'\nimport { logError, SESSION_ID } from '@utils/log'\nimport { abortableDelay } from '@utils/async'\nimport { USER_AGENT } from '@utils/http'\nimport {\n createAssistantAPIErrorMessage,\n normalizeContentFromAPI,\n} from '@utils/messages'\nimport { withVCR } from './vcr'\nimport {\n debug as debugLogger,\n markPhase,\n getCurrentRequest,\n logLLMInteraction,\n logSystemPromptConstruction,\n logErrorWithDiagnosis,\n} from '@utils/debugLogger'\nimport { getModelManager } from '@utils/model'\nimport { zodToJsonSchema } from 'zod-to-json-schema'\nimport { ModelAdapterFactory } from './modelAdapterFactory'\nimport { UnifiedRequestParams } from '@minto-types/modelCapabilities'\nimport { responseStateManager, getConversationId } from './responseStateManager'\nimport type { ToolUseContext } from '@tool'\nimport type {\n MessageParam,\n TextBlockParam,\n} from '@anthropic-ai/sdk/resources/index.mjs'\nimport { USE_BEDROCK, USE_VERTEX } from '@utils/model'\nimport { getCLISyspromptPrefix } from '@constants/prompts'\nimport { getVertexRegionForModel } from '@utils/model'\nimport OpenAI from 'openai'\nimport type { ChatCompletionStream } from 'openai/lib/ChatCompletionStream'\nimport { ContentBlock } from '@anthropic-ai/sdk/resources/messages/messages'\nimport { nanoid } from 'nanoid'\nimport {\n getCompletionWithProfile,\n getGPT5CompletionWithProfile,\n} from './openai'\nimport { getReasoningEffort } from '@utils/thinking'\nimport { generateSystemReminders } from './systemReminder'\nimport { addRetryEventToTranscript } from '@utils/agentTranscripts'\nimport { setStreamingState, getStreamingState } from '@components/Spinner'\nimport type { ThinkingMetadata } from '@minto-types/thinking'\n\n// Helper function to check if a model is GPT-5\nfunction isGPT5Model(modelName: string): boolean {\n return modelName.startsWith('gpt-5')\n}\n\n// MintoContext\u7BA1\u7406\u5668 - \u7528\u4E8E\u9879\u76EE\u6587\u6863\u7684\u540C\u6B65\u7F13\u5B58\u548C\u8BBF\u95EE\nclass MintoContextManager {\n private static instance: MintoContextManager\n private projectDocsCache: string = ''\n private cacheInitialized: boolean = false\n private initPromise: Promise<void> | null = null\n\n private constructor() {}\n\n public static getInstance(): MintoContextManager {\n if (!MintoContextManager.instance) {\n MintoContextManager.instance = new MintoContextManager()\n }\n return MintoContextManager.instance\n }\n\n public async initialize(): Promise<void> {\n if (this.cacheInitialized) return\n\n if (this.initPromise) {\n return this.initPromise\n }\n\n this.initPromise = this.loadProjectDocs()\n await this.initPromise\n }\n\n private async loadProjectDocs(): Promise<void> {\n try {\n const projectDocs = await getProjectDocs()\n this.projectDocsCache = projectDocs || ''\n this.cacheInitialized = true\n\n // \u5728\u8C03\u8BD5\u6A21\u5F0F\u4E0B\u8BB0\u5F55\u52A0\u8F7D\u7ED3\u679C\n if (process.env.NODE_ENV === 'development') {\n debugLogger.info('MINTO_CONTEXT_LOADED', {\n characters: this.projectDocsCache.length,\n })\n }\n } catch (error) {\n debugLogger.warn('MINTO_CONTEXT_LOAD_FAILED', { error: String(error) })\n this.projectDocsCache = ''\n this.cacheInitialized = true\n }\n }\n\n public getMintoContext(): string {\n if (!this.cacheInitialized) {\n // \u5982\u679C\u672A\u521D\u59CB\u5316\uFF0C\u5F02\u6B65\u521D\u59CB\u5316\u4F46\u7ACB\u5373\u8FD4\u56DE\u7A7A\u5B57\u7B26\u4E32\n this.initialize().catch(error => {\n debugLogger.warn('MINTO_CONTEXT_INIT_FAILED', { error: String(error) })\n })\n return ''\n }\n return this.projectDocsCache\n }\n\n public async refreshCache(): Promise<void> {\n this.cacheInitialized = false\n this.initPromise = null\n await this.initialize()\n }\n}\n\n// \u5BFC\u51FA\u51FD\u6570\u4FDD\u6301\u5411\u540E\u517C\u5BB9\nconst mintoContextManager = MintoContextManager.getInstance()\n\n// \u5728\u6A21\u5757\u52A0\u8F7D\u65F6\u5F02\u6B65\u521D\u59CB\u5316\nmintoContextManager.initialize().catch(error => {\n debugLogger.warn('MINTO_CONTEXT_MODULE_INIT_FAILED', { error: String(error) })\n})\n\nexport const generateMintoContext = (): string => {\n return mintoContextManager.getMintoContext()\n}\n\nexport const refreshMintoContext = async (): Promise<void> => {\n await mintoContextManager.refreshCache()\n}\n\nexport const API_ERROR_MESSAGE_PREFIX = 'API Error'\nexport const PROMPT_TOO_LONG_ERROR_MESSAGE = 'Prompt is too long'\nexport const CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE = 'Credit balance is too low'\nexport const INVALID_API_KEY_ERROR_MESSAGE =\n 'Invalid API key \u00B7 Please run /login'\nexport const NO_CONTENT_MESSAGE = '(no content)'\nconst PROMPT_CACHING_ENABLED = !process.env.DISABLE_PROMPT_CACHING\n\n// @see https://docs.anthropic.com/en/docs/about-claude/models#model-comparison-table\nconst SONNET_COST_PER_MILLION_INPUT_TOKENS = 3\nconst SONNET_COST_PER_MILLION_OUTPUT_TOKENS = 15\nconst SONNET_COST_PER_MILLION_PROMPT_CACHE_WRITE_TOKENS = 3.75\nconst SONNET_COST_PER_MILLION_PROMPT_CACHE_READ_TOKENS = 0.3\n\nexport const MAIN_QUERY_TEMPERATURE = 1 // to get more variation for binary feedback\n\nfunction getMetadata() {\n return {\n user_id: `${getOrCreateUserID()}_${SESSION_ID}`,\n }\n}\n\nconst MAX_RETRIES = process.env.USER_TYPE === 'SWE_BENCH' ? 100 : 10\nconst BASE_DELAY_MS = 500\n\ninterface RetryOptions {\n maxRetries?: number\n signal?: AbortSignal\n /** Callback for retry events. If provided, suppresses console.log output. */\n onRetry?: (info: {\n attempt: number\n maxRetries: number\n error: Error\n delayMs: number\n }) => void\n}\n\nfunction getRetryDelay(\n attempt: number,\n retryAfterHeader?: string | null,\n): number {\n if (retryAfterHeader) {\n const seconds = parseInt(retryAfterHeader, 10)\n if (!isNaN(seconds)) {\n return seconds * 1000\n }\n }\n return Math.min(BASE_DELAY_MS * Math.pow(2, attempt - 1), 32000) // Max 32s delay\n}\n\nfunction shouldRetry(error: APIError): boolean {\n // Check for overloaded errors first and only retry for SWE_BENCH\n if (error.message?.includes('\"type\":\"overloaded_error\"')) {\n return process.env.USER_TYPE === 'SWE_BENCH'\n }\n\n // Note this is not a standard header.\n const shouldRetryHeader = error.headers?.['x-should-retry']\n\n // If the server explicitly says whether or not to retry, obey.\n if (shouldRetryHeader === 'true') return true\n if (shouldRetryHeader === 'false') return false\n\n if (error instanceof APIConnectionError) {\n return true\n }\n\n if (!error.status) return false\n\n // Retry on request timeouts.\n if (error.status === 408) return true\n\n // Retry on lock timeouts.\n if (error.status === 409) return true\n\n // Retry on rate limits.\n if (error.status === 429) return true\n\n // Retry internal errors.\n if (error.status && error.status >= 500) return true\n\n return false\n}\n\nasync function withRetry<T>(\n operation: (attempt: number) => Promise<T>,\n options: RetryOptions = {},\n): Promise<T> {\n const maxRetries = options.maxRetries ?? MAX_RETRIES\n let lastError: unknown\n\n for (let attempt = 1; attempt <= maxRetries + 1; attempt++) {\n try {\n return await operation(attempt)\n } catch (error) {\n lastError = error\n // Only retry if the error indicates we should\n if (\n attempt > maxRetries ||\n !(error instanceof APIError) ||\n !shouldRetry(error)\n ) {\n throw error\n }\n\n if (options.signal?.aborted) {\n throw new Error('Request cancelled by user')\n }\n\n // Get retry-after header if available\n const retryAfter = error.headers?.['retry-after'] ?? null\n const delayMs = getRetryDelay(attempt, retryAfter)\n\n // \u2705 P1 FIX: Update streaming state to show retry in UI\n setStreamingState({\n phase: 'retrying',\n retryCount: attempt,\n maxRetries: maxRetries,\n errorName: error.name,\n })\n\n debugLogger.flow('API_RETRY_ATTEMPT', {\n attempt,\n maxRetries,\n errorName: error.name,\n errorMessage: error.message,\n delayMs,\n })\n\n // Use callback if provided, otherwise fallback to console.log\n if (options.onRetry) {\n options.onRetry({\n attempt,\n maxRetries,\n error,\n delayMs,\n })\n } else {\n console.log(\n ` \u23BF ${chalk.red(`API ${error.name} (${error.message}) \u00B7 Retrying in ${Math.round(delayMs / 1000)} seconds\u2026 (attempt ${attempt}/${maxRetries})`)}`,\n )\n }\n\n try {\n await abortableDelay(delayMs, options.signal)\n } catch (delayError) {\n // If aborted during delay, throw the error to stop retrying\n if (delayError.message === 'Request was aborted') {\n throw new Error('Request cancelled by user')\n }\n throw delayError\n }\n }\n }\n\n throw lastError\n}\n\n/**\n * Fetch available models from Anthropic API\n */\nexport async function fetchAnthropicModels(\n baseURL: string,\n apiKey: string,\n): Promise<any[]> {\n try {\n // Use provided baseURL or default to official Anthropic API\n const modelsURL = baseURL\n ? `${baseURL.replace(/\\/+$/, '')}/v1/models`\n : 'https://api.anthropic.com/v1/models'\n\n const response = await fetch(modelsURL, {\n method: 'GET',\n headers: {\n 'x-api-key': apiKey,\n 'anthropic-version': '2023-06-01',\n 'User-Agent': USER_AGENT,\n },\n })\n\n if (!response.ok) {\n // Provide user-friendly error messages based on status code\n if (response.status === 401) {\n throw new Error(\n 'Invalid API key. Please check your Anthropic API key and try again.',\n )\n } else if (response.status === 403) {\n throw new Error(\n 'API key does not have permission to access models. Please check your API key permissions.',\n )\n } else if (response.status === 429) {\n throw new Error(\n 'Too many requests. Please wait a moment and try again.',\n )\n } else if (response.status >= 500) {\n throw new Error(\n 'Anthropic service is temporarily unavailable. Please try again later.',\n )\n } else {\n throw new Error(\n `Unable to connect to Anthropic API (${response.status}). Please check your internet connection and API key.`,\n )\n }\n }\n\n const data = await response.json()\n return data.data || []\n } catch (error) {\n // If it's already our custom error, pass it through\n if (\n (error instanceof Error && error.message.includes('API key')) ||\n (error instanceof Error && error.message.includes('Anthropic'))\n ) {\n throw error\n }\n\n // For network errors or other issues\n logError(error)\n throw new Error(\n 'Unable to connect to Anthropic API. Please check your internet connection and try again.',\n )\n }\n}\n\nexport async function verifyApiKey(\n apiKey: string,\n baseURL?: string,\n provider?: string,\n): Promise<boolean> {\n if (!apiKey) {\n return false\n }\n\n // For non-Anthropic providers, use OpenAI-compatible verification\n if (provider && provider !== 'anthropic') {\n try {\n const headers: Record<string, string> = {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n }\n\n if (!baseURL) {\n debugLogger.warn('API_VERIFY', {\n error: 'No baseURL provided for non-Anthropic provider',\n })\n return false\n }\n\n const modelsURL = `${baseURL.replace(/\\/+$/, '')}/models`\n\n const response = await fetch(modelsURL, {\n method: 'GET',\n headers,\n })\n\n return response.ok\n } catch (error) {\n debugLogger.warn('API_VERIFY', {\n error: 'non-Anthropic provider verification failed',\n details: String(error),\n })\n return false\n }\n }\n\n // For Anthropic and Anthropic-compatible APIs\n const clientConfig: any = {\n apiKey,\n dangerouslyAllowBrowser: true,\n maxRetries: 3,\n defaultHeaders: {\n 'User-Agent': USER_AGENT,\n },\n }\n\n // Only add baseURL for true Anthropic-compatible APIs\n if (\n baseURL &&\n (provider === 'anthropic' ||\n provider === 'bigdream' ||\n provider === 'opendev')\n ) {\n clientConfig.baseURL = baseURL\n }\n\n const anthropic = new Anthropic(clientConfig)\n\n try {\n await withRetry(\n async () => {\n const model = 'claude-sonnet-4-20250514'\n const messages: MessageParam[] = [{ role: 'user', content: 'test' }]\n await anthropic.messages.create({\n model,\n max_tokens: 1000, // Simple test token limit for API verification\n messages,\n temperature: 0,\n metadata: getMetadata(),\n })\n return true\n },\n { maxRetries: 2 }, // Use fewer retries for API key verification\n )\n return true\n } catch (error) {\n logError(error)\n // Check for authentication error\n if (\n error instanceof Error &&\n error.message.includes(\n '{\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"invalid x-api-key\"}}',\n )\n ) {\n return false\n }\n throw error\n }\n}\n\nfunction convertAnthropicMessagesToOpenAIMessages(\n messages: (UserMessage | AssistantMessage)[],\n): (\n | OpenAI.ChatCompletionMessageParam\n | OpenAI.ChatCompletionToolMessageParam\n)[] {\n const openaiMessages: (\n | OpenAI.ChatCompletionMessageParam\n | OpenAI.ChatCompletionToolMessageParam\n )[] = []\n\n const toolResults: Record<string, OpenAI.ChatCompletionToolMessageParam> = {}\n\n for (const message of messages) {\n let contentBlocks = []\n if (typeof message.message.content === 'string') {\n contentBlocks = [\n {\n type: 'text',\n text: message.message.content,\n },\n ]\n } else if (!Array.isArray(message.message.content)) {\n contentBlocks = [message.message.content]\n } else {\n contentBlocks = message.message.content\n }\n\n for (const block of contentBlocks) {\n if (block.type === 'text') {\n openaiMessages.push({\n role: message.message.role,\n content: block.text,\n })\n } else if (block.type === 'tool_use') {\n openaiMessages.push({\n role: 'assistant',\n content: undefined,\n tool_calls: [\n {\n type: 'function',\n function: {\n name: block.name,\n arguments: JSON.stringify(block.input),\n },\n id: block.id,\n },\n ],\n })\n } else if (block.type === 'tool_result') {\n // Ensure content is always a string for role:tool messages\n let toolContent = block.content\n if (typeof toolContent !== 'string') {\n // Convert content to string if it's not already\n toolContent = JSON.stringify(toolContent)\n }\n\n toolResults[block.tool_use_id] = {\n role: 'tool',\n content: toolContent,\n tool_call_id: block.tool_use_id,\n }\n }\n }\n }\n\n const finalMessages: (\n | OpenAI.ChatCompletionMessageParam\n | OpenAI.ChatCompletionToolMessageParam\n )[] = []\n\n for (const message of openaiMessages) {\n finalMessages.push(message)\n\n if ('tool_calls' in message && message.tool_calls) {\n for (const toolCall of message.tool_calls) {\n if (toolResults[toolCall.id]) {\n finalMessages.push(toolResults[toolCall.id])\n }\n }\n }\n }\n\n return finalMessages\n}\n\nfunction messageReducer(\n previous: OpenAI.ChatCompletionMessage,\n item: OpenAI.ChatCompletionChunk,\n): OpenAI.ChatCompletionMessage {\n const reduce = (acc: any, delta: OpenAI.ChatCompletionChunk.Choice.Delta) => {\n acc = { ...acc }\n for (const [key, value] of Object.entries(delta)) {\n if (acc[key] === undefined || acc[key] === null) {\n acc[key] = value\n // OpenAI.Chat.Completions.ChatCompletionMessageToolCall does not have a key, .index\n if (Array.isArray(acc[key])) {\n for (const arr of acc[key]) {\n delete arr.index\n }\n }\n } else if (typeof acc[key] === 'string' && typeof value === 'string') {\n acc[key] += value\n } else if (typeof acc[key] === 'number' && typeof value === 'number') {\n acc[key] = value\n } else if (Array.isArray(acc[key]) && Array.isArray(value)) {\n const accArray = acc[key]\n for (let i = 0; i < value.length; i++) {\n const { index, ...chunkTool } = value[i]\n if (index - accArray.length > 1) {\n throw new Error(\n `Error: An array has an empty value when tool_calls are constructed. tool_calls: ${accArray}; tool: ${value}`,\n )\n }\n accArray[index] = reduce(accArray[index], chunkTool)\n }\n } else if (typeof acc[key] === 'object' && typeof value === 'object') {\n acc[key] = reduce(acc[key], value)\n }\n }\n return acc\n }\n\n const choice = item.choices?.[0]\n if (!choice) {\n // chunk contains information about usage and token counts\n return previous\n }\n return reduce(previous, choice.delta) as OpenAI.ChatCompletionMessage\n}\nasync function handleMessageStream(\n stream: ChatCompletionStream,\n signal?: AbortSignal,\n): Promise<OpenAI.ChatCompletion> {\n const streamStartTime = Date.now()\n let ttftMs: number | undefined\n let chunkCount = 0\n let errorCount = 0\n\n debugLogger.api('OPENAI_STREAM_START', {\n streamStartTime: String(streamStartTime),\n })\n\n let message = {} as OpenAI.ChatCompletionMessage\n\n let id, model, created, object, usage\n try {\n for await (const chunk of stream) {\n if (signal?.aborted) {\n debugLogger.flow('OPENAI_STREAM_ABORTED', {\n chunkCount,\n timestamp: Date.now(),\n })\n throw new Error('Request was cancelled')\n }\n\n chunkCount++\n\n try {\n if (!id) {\n id = chunk.id\n debugLogger.api('OPENAI_STREAM_ID_RECEIVED', {\n id,\n chunkNumber: String(chunkCount),\n })\n }\n if (!model) {\n model = chunk.model\n debugLogger.api('OPENAI_STREAM_MODEL_RECEIVED', {\n model,\n chunkNumber: String(chunkCount),\n })\n }\n if (!created) {\n created = chunk.created\n }\n if (!object) {\n object = chunk.object\n }\n if (!usage && chunk.usage) {\n usage = chunk.usage\n // Update streaming state with token usage (OpenAI provides usage in final chunk)\n setStreamingState({\n inputTokens: chunk.usage.prompt_tokens,\n outputTokens: chunk.usage.completion_tokens,\n })\n }\n\n message = messageReducer(message, chunk)\n\n if (chunk?.choices?.[0]?.delta?.content) {\n if (!ttftMs) {\n ttftMs = Date.now() - streamStartTime\n debugLogger.api('OPENAI_STREAM_FIRST_TOKEN', {\n ttftMs: String(ttftMs),\n chunkNumber: String(chunkCount),\n })\n }\n }\n } catch (chunkError) {\n errorCount++\n debugLogger.error('OPENAI_STREAM_CHUNK_ERROR', {\n chunkNumber: String(chunkCount),\n errorMessage:\n chunkError instanceof Error\n ? chunkError.message\n : String(chunkError),\n errorType:\n chunkError instanceof Error\n ? chunkError.constructor.name\n : typeof chunkError,\n })\n // Continue processing other chunks\n }\n }\n\n debugLogger.api('OPENAI_STREAM_COMPLETE', {\n totalChunks: String(chunkCount),\n errorCount: String(errorCount),\n totalDuration: String(Date.now() - streamStartTime),\n ttftMs: String(ttftMs || 0),\n finalMessageId: id || 'undefined',\n })\n } catch (streamError) {\n debugLogger.error('OPENAI_STREAM_FATAL_ERROR', {\n totalChunks: String(chunkCount),\n errorCount: String(errorCount),\n errorMessage:\n streamError instanceof Error\n ? streamError.message\n : String(streamError),\n errorType:\n streamError instanceof Error\n ? streamError.constructor.name\n : typeof streamError,\n })\n throw streamError\n }\n return {\n id,\n created,\n model,\n object,\n choices: [\n {\n index: 0,\n message,\n finish_reason: 'stop',\n logprobs: undefined,\n },\n ],\n usage,\n }\n}\n\nfunction convertOpenAIResponseToAnthropic(\n response: OpenAI.ChatCompletion,\n _tools?: Tool[],\n) {\n let contentBlocks: ContentBlock[] = []\n const message = response.choices?.[0]?.message\n if (!message) {\n return {\n role: 'assistant',\n content: [],\n stop_reason: response.choices?.[0]?.finish_reason,\n type: 'message',\n usage: response.usage,\n }\n }\n\n if (message?.tool_calls) {\n for (const toolCall of message.tool_calls) {\n const tool = toolCall.function\n const toolName = tool?.name\n let toolArgs = {}\n let parseError: string | null = null\n try {\n toolArgs = tool?.arguments ? JSON.parse(tool.arguments) : {}\n } catch (e) {\n // Invalid JSON in tool arguments - log for debugging\n parseError = e instanceof Error ? e.message : String(e)\n debugLogger.warn('TOOL_ARGUMENTS_PARSE_ERROR', {\n toolName,\n rawArguments: tool?.arguments?.substring(0, 200), // Limit log size\n errorMessage: parseError,\n })\n }\n\n // If parsing failed and we have empty args, add context about the parse failure\n if (parseError && Object.keys(toolArgs).length === 0) {\n debugLogger.error('TOOL_CALL_EMPTY_ARGUMENTS', {\n toolName,\n parseError,\n suggestion:\n 'Model may have sent malformed JSON. The tool call will likely fail validation.',\n })\n }\n\n contentBlocks.push({\n type: 'tool_use',\n input: toolArgs,\n name: toolName,\n id: toolCall.id?.length > 0 ? toolCall.id : nanoid(),\n })\n }\n }\n\n if ((message as any).reasoning) {\n contentBlocks.push({\n type: 'thinking',\n thinking: (message as any).reasoning,\n signature: '',\n })\n }\n\n // NOTE: For deepseek api, the key for its returned reasoning process is reasoning_content\n if ((message as any).reasoning_content) {\n contentBlocks.push({\n type: 'thinking',\n thinking: (message as any).reasoning_content,\n signature: '',\n })\n }\n\n if (message.content) {\n contentBlocks.push({\n type: 'text',\n text: message?.content,\n citations: [],\n })\n }\n\n const finalMessage = {\n role: 'assistant',\n content: contentBlocks,\n stop_reason: response.choices?.[0]?.finish_reason,\n type: 'message',\n usage: response.usage,\n }\n\n return finalMessage\n}\n\nlet anthropicClient: Anthropic | AnthropicBedrock | AnthropicVertex | null =\n null\n\n/**\n * Get the Anthropic client, creating it if it doesn't exist\n */\nexport function getAnthropicClient(\n model?: string,\n): Anthropic | AnthropicBedrock | AnthropicVertex {\n const config = getGlobalConfig()\n const provider = config.primaryProvider\n\n // Reset client if provider has changed to ensure correct configuration\n if (anthropicClient && provider) {\n // Always recreate client for provider-specific configurations\n anthropicClient = null\n }\n\n if (anthropicClient) {\n return anthropicClient\n }\n\n const region = getVertexRegionForModel(model)\n\n const defaultHeaders: { [key: string]: string } = {\n 'x-app': 'cli',\n 'User-Agent': USER_AGENT,\n }\n if (process.env.ANTHROPIC_AUTH_TOKEN) {\n defaultHeaders['Authorization'] =\n `Bearer ${process.env.ANTHROPIC_AUTH_TOKEN}`\n }\n\n const ARGS = {\n defaultHeaders,\n maxRetries: 0, // Disabled auto-retry in favor of manual implementation\n timeout: parseInt(process.env.API_TIMEOUT_MS || String(60 * 1000), 10),\n }\n if (USE_BEDROCK) {\n const client = new AnthropicBedrock(ARGS)\n anthropicClient = client\n return client\n }\n if (USE_VERTEX) {\n const vertexArgs = {\n ...ARGS,\n region: region || process.env.CLOUD_ML_REGION || 'us-east5',\n }\n const client = new AnthropicVertex(vertexArgs)\n anthropicClient = client\n return client\n }\n\n // Get appropriate API key and baseURL from ModelProfile\n const modelManager = getModelManager()\n const modelProfile = modelManager.getModel('main')\n\n let apiKey: string\n let baseURL: string | undefined\n\n if (modelProfile) {\n apiKey = modelProfile.apiKey || ''\n baseURL = modelProfile.baseURL\n } else {\n // Fallback to default anthropic if no ModelProfile\n apiKey = getAnthropicApiKey()\n baseURL = undefined\n }\n\n if (process.env.USER_TYPE === 'ant' && !apiKey && provider === 'anthropic') {\n console.error(\n chalk.red(\n '[ANT-ONLY] Please set the ANTHROPIC_API_KEY environment variable to use the CLI. To create a new key, go to https://console.anthropic.com/settings/keys.',\n ),\n )\n }\n\n // Create client with custom baseURL for BigDream/OpenDev\n // Anthropic SDK will append the appropriate paths (like /v1/messages)\n const clientConfig = {\n apiKey,\n dangerouslyAllowBrowser: true,\n ...ARGS,\n ...(baseURL && { baseURL }), // Use baseURL directly, SDK will handle API versioning\n }\n\n anthropicClient = new Anthropic(clientConfig)\n return anthropicClient\n}\n\n/**\n * Reset the Anthropic client to null, forcing a new client to be created on next use\n */\nexport function resetAnthropicClient(): void {\n anthropicClient = null\n}\n\n/**\n * Environment variables for different client types:\n *\n * Direct API:\n * - ANTHROPIC_API_KEY: Required for direct API access\n *\n * AWS Bedrock:\n * - AWS credentials configured via aws-sdk defaults\n *\n * Vertex AI:\n * - Model-specific region variables (highest priority):\n * - VERTEX_REGION_CLAUDE_3_5_HAIKU: Region for Claude 3.5 Haiku model\n * - VERTEX_REGION_CLAUDE_3_5_SONNET: Region for Claude 3.5 Sonnet model\n * - VERTEX_REGION_CLAUDE_3_7_SONNET: Region for Claude 3.7 Sonnet model\n * - CLOUD_ML_REGION: Optional. The default GCP region to use for all models\n * If specific model region not specified above\n * - ANTHROPIC_VERTEX_PROJECT_ID: Required. Your GCP project ID\n * - Standard GCP credentials configured via google-auth-library\n *\n * Priority for determining region:\n * 1. Hardcoded model-specific environment variables\n * 2. Global CLOUD_ML_REGION variable\n * 3. Default region from config\n * 4. Fallback region (us-east5)\n */\n\n/**\n * Manage cache control to ensure it doesn't exceed Claude's 4 cache block limit\n * Priority:\n * 1. System prompts (high priority)\n * 2. Long documents or reference materials (high priority)\n * 3. Reusable context (medium priority)\n * 4. Short messages or one-time content (no caching)\n */\nfunction applyCacheControlWithLimits(\n systemBlocks: TextBlockParam[],\n messageParams: MessageParam[],\n): { systemBlocks: TextBlockParam[]; messageParams: MessageParam[] } {\n if (!PROMPT_CACHING_ENABLED) {\n return { systemBlocks, messageParams }\n }\n\n const maxCacheBlocks = 4\n let usedCacheBlocks = 0\n\n // 1. Prioritize adding cache to system prompts (highest priority)\n const processedSystemBlocks = systemBlocks.map((block, _index) => {\n if (usedCacheBlocks < maxCacheBlocks && block.text.length > 1000) {\n usedCacheBlocks++\n return {\n ...block,\n cache_control: { type: 'ephemeral' as const },\n }\n }\n const { cache_control, ...blockWithoutCache } = block\n return blockWithoutCache\n })\n\n // 2. Add cache to message content based on priority\n const processedMessageParams = messageParams.map((message, messageIndex) => {\n if (Array.isArray(message.content)) {\n const processedContent = message.content.map(\n (contentBlock, blockIndex) => {\n // Determine whether this content block should be cached\n const shouldCache =\n usedCacheBlocks < maxCacheBlocks &&\n contentBlock.type === 'text' &&\n typeof contentBlock.text === 'string' &&\n // Long documents (over 2000 characters)\n (contentBlock.text.length > 2000 ||\n // Last content block of the last message (may be important context)\n (messageIndex === messageParams.length - 1 &&\n blockIndex === message.content.length - 1 &&\n contentBlock.text.length > 500))\n\n if (shouldCache) {\n usedCacheBlocks++\n return {\n ...contentBlock,\n cache_control: { type: 'ephemeral' as const },\n }\n }\n\n // Remove existing cache_control\n const { cache_control, ...blockWithoutCache } = contentBlock as any\n return blockWithoutCache\n },\n )\n\n return {\n ...message,\n content: processedContent,\n }\n }\n\n return message\n })\n\n return {\n systemBlocks: processedSystemBlocks,\n messageParams: processedMessageParams,\n }\n}\n\nexport function userMessageToMessageParam(\n message: UserMessage,\n addCache = false,\n): MessageParam {\n if (addCache) {\n if (typeof message.message.content === 'string') {\n return {\n role: 'user',\n content: [\n {\n type: 'text',\n text: message.message.content,\n },\n ],\n }\n } else {\n return {\n role: 'user',\n content: message.message.content.map(_ => ({ ..._ })),\n }\n }\n }\n return {\n role: 'user',\n content: message.message.content,\n }\n}\n\nexport function assistantMessageToMessageParam(\n message: AssistantMessage,\n addCache = false,\n): MessageParam {\n if (addCache) {\n if (typeof message.message.content === 'string') {\n return {\n role: 'assistant',\n content: [\n {\n type: 'text',\n text: message.message.content,\n },\n ],\n }\n } else {\n return {\n role: 'assistant',\n content: message.message.content.map(_ => ({ ..._ })),\n }\n }\n }\n return {\n role: 'assistant',\n content: message.message.content,\n }\n}\n\nfunction splitSysPromptPrefix(systemPrompt: string[]): string[] {\n // split out the first block of the system prompt as the \"prefix\" for API\n\n const systemPromptFirstBlock = systemPrompt[0] || ''\n const systemPromptRest = systemPrompt.slice(1)\n return [systemPromptFirstBlock, systemPromptRest.join('\\n')].filter(Boolean)\n}\n\nexport async function queryLLM(\n messages: (UserMessage | AssistantMessage)[],\n systemPrompt: string[],\n maxThinkingTokens: number,\n tools: Tool[],\n signal: AbortSignal,\n options: {\n safeMode: boolean\n model: string | import('@utils/config').ModelPointerType\n prependCLISysprompt: boolean\n toolUseContext?: ToolUseContext\n },\n): Promise<AssistantMessage> {\n const modelManager = getModelManager()\n const modelResolution = modelManager.resolveModelWithInfo(options.model)\n\n if (!modelResolution.success || !modelResolution.profile) {\n throw new Error(\n modelResolution.error || `Failed to resolve model: ${options.model}`,\n )\n }\n\n const modelProfile = modelResolution.profile\n const resolvedModel = modelProfile.modelName\n\n // Initialize response state if toolUseContext is provided\n const toolUseContext = options.toolUseContext\n if (toolUseContext && !toolUseContext.responseState) {\n const conversationId = getConversationId(\n toolUseContext.agentId,\n toolUseContext.messageId,\n )\n const previousResponseId =\n responseStateManager.getPreviousResponseId(conversationId)\n\n toolUseContext.responseState = {\n previousResponseId,\n conversationId,\n }\n }\n\n debugLogger.api('MODEL_RESOLVED', {\n inputParam: options.model,\n resolvedModelName: resolvedModel,\n provider: modelProfile.provider,\n isPointer: ['main', 'task', 'reasoning', 'quick'].includes(options.model),\n hasResponseState: !!toolUseContext?.responseState,\n conversationId: toolUseContext?.responseState?.conversationId,\n requestId: getCurrentRequest()?.id,\n })\n\n const currentRequest = getCurrentRequest()\n debugLogger.api('LLM_REQUEST_START', {\n messageCount: messages.length,\n systemPromptLength: systemPrompt.join(' ').length,\n toolCount: tools.length,\n model: resolvedModel,\n originalModelParam: options.model,\n requestId: getCurrentRequest()?.id,\n })\n\n markPhase('LLM_CALL')\n\n try {\n const result = await withVCR(messages, () =>\n queryLLMWithPromptCaching(\n messages,\n systemPrompt,\n maxThinkingTokens,\n tools,\n signal,\n { ...options, model: resolvedModel, modelProfile, toolUseContext }, // Pass resolved ModelProfile and toolUseContext\n ),\n )\n\n debugLogger.api('LLM_REQUEST_SUCCESS', {\n costUSD: result.costUSD,\n durationMs: result.durationMs,\n responseLength: result.message.content?.length || 0,\n requestId: getCurrentRequest()?.id,\n })\n\n // Update response state for GPT-5 Responses API continuation\n if (toolUseContext?.responseState?.conversationId && result.responseId) {\n responseStateManager.setPreviousResponseId(\n toolUseContext.responseState.conversationId,\n result.responseId,\n )\n\n debugLogger.api('RESPONSE_STATE_UPDATED', {\n conversationId: toolUseContext.responseState.conversationId,\n responseId: result.responseId,\n requestId: getCurrentRequest()?.id,\n })\n }\n\n return result\n } catch (error) {\n // \u4F7F\u7528\u9519\u8BEF\u8BCA\u65AD\u7CFB\u7EDF\u8BB0\u5F55 LLM \u76F8\u5173\u9519\u8BEF\n logErrorWithDiagnosis(\n error,\n {\n messageCount: messages.length,\n systemPromptLength: systemPrompt.join(' ').length,\n model: options.model,\n toolCount: tools.length,\n phase: 'LLM_CALL',\n },\n currentRequest?.id,\n )\n\n throw error\n }\n}\n\nexport function formatSystemPromptWithContext(\n systemPrompt: string[],\n context: { [k: string]: string },\n agentId?: string,\n skipContextReminders = false, // Parameter kept for API compatibility but not used anymore\n): { systemPrompt: string[]; reminders: string } {\n // \u6784\u5EFA\u589E\u5F3A\u7684\u7CFB\u7EDF\u63D0\u793A\uFF0C\u4FDD\u6301\u4E0E\u539F\u5148\u76F4\u63A5\u6CE8\u5165\u65B9\u5F0F\u7684\u517C\u5BB9\n const enhancedPrompt = [...systemPrompt]\n let reminders = ''\n\n // Step 0: Add GPT-5 Agent persistence support for coding tasks\n const modelManager = getModelManager()\n const modelProfile = modelManager.getModel('main')\n if (modelProfile && isGPT5Model(modelProfile.modelName)) {\n // Add coding-specific persistence instructions based on GPT-5 documentation\n const persistencePrompts = [\n '\\n# Agent Persistence for Long-Running Coding Tasks',\n 'You are working on a coding project that may involve multiple steps and iterations. Please maintain context and continuity throughout the session:',\n '- Remember architectural decisions and design patterns established earlier',\n '- Keep track of file modifications and their relationships',\n '- Maintain awareness of the overall project structure and goals',\n '- Reference previous implementations when making related changes',\n '- Ensure consistency with existing code style and conventions',\n '- Build incrementally on previous work rather than starting from scratch',\n ]\n enhancedPrompt.push(...persistencePrompts)\n }\n\n // \u53EA\u6709\u5F53\u4E0A\u4E0B\u6587\u5B58\u5728\u65F6\u624D\u5904\u7406\n const hasContext = Object.entries(context).length > 0\n\n if (hasContext) {\n // \u6B65\u9AA41: \u76F4\u63A5\u6CE8\u5165 Minto \u4E0A\u4E0B\u6587\u5230\u7CFB\u7EDF\u63D0\u793A - \u5BF9\u9F50\u5B98\u65B9\u8BBE\u8BA1\n if (!skipContextReminders) {\n const mintoContext = generateMintoContext()\n if (mintoContext) {\n // \u6DFB\u52A0\u5206\u9694\u7B26\u548C\u6807\u8BC6\uFF0C\u4F7F\u9879\u76EE\u6587\u6863\u5728\u7CFB\u7EDF\u63D0\u793A\u4E2D\u66F4\u6E05\u6670\n enhancedPrompt.push('\\n---\\n# \u9879\u76EE\u4E0A\u4E0B\u6587\\n')\n enhancedPrompt.push(mintoContext)\n enhancedPrompt.push('\\n---\\n')\n }\n }\n\n // \u6B65\u9AA42: \u751F\u6210\u5176\u4ED6\u52A8\u6001\u63D0\u9192\u8FD4\u56DE\u7ED9\u8C03\u7528\u65B9 - \u4FDD\u6301\u73B0\u6709\u52A8\u6001\u63D0\u9192\u529F\u80FD\n const reminderMessages = generateSystemReminders(hasContext, agentId)\n if (reminderMessages.length > 0) {\n reminders = reminderMessages.map(r => r.content).join('\\n') + '\\n'\n }\n\n // \u6B65\u9AA43: \u6DFB\u52A0\u5176\u4ED6\u4E0A\u4E0B\u6587\u5230\u7CFB\u7EDF\u63D0\u793A\n enhancedPrompt.push(\n `\\nAs you answer the user's questions, you can use the following context:\\n`,\n )\n\n // \u8FC7\u6EE4\u6389\u5DF2\u7ECF\u7531 Minto \u4E0A\u4E0B\u6587\u5904\u7406\u7684\u9879\u76EE\u6587\u6863\uFF08\u907F\u514D\u91CD\u590D\uFF09\n const filteredContext = Object.fromEntries(\n Object.entries(context).filter(\n ([key]) => key !== 'projectDocs' && key !== 'userDocs',\n ),\n )\n\n enhancedPrompt.push(\n ...Object.entries(filteredContext).map(\n ([key, value]) => `<context name=\"${key}\">${value}</context>`,\n ),\n )\n }\n\n return { systemPrompt: enhancedPrompt, reminders }\n}\n\nasync function queryLLMWithPromptCaching(\n messages: (UserMessage | AssistantMessage)[],\n systemPrompt: string[],\n maxThinkingTokens: number,\n tools: Tool[],\n signal: AbortSignal,\n options: {\n safeMode: boolean\n model: string\n prependCLISysprompt: boolean\n modelProfile?: ModelProfile | null\n toolUseContext?: ToolUseContext\n },\n): Promise<AssistantMessage> {\n const config = getGlobalConfig()\n const modelManager = getModelManager()\n const toolUseContext = options.toolUseContext\n\n const modelProfile = options.modelProfile || modelManager.getModel('main')\n let provider: string\n\n if (modelProfile) {\n provider = modelProfile.provider || config.primaryProvider || 'anthropic'\n } else {\n provider = config.primaryProvider || 'anthropic'\n }\n\n // Use native Anthropic SDK for Anthropic and some Anthropic-compatible providers\n if (\n provider === 'anthropic' ||\n provider === 'bigdream' ||\n provider === 'opendev'\n ) {\n return queryAnthropicNative(\n messages,\n systemPrompt,\n maxThinkingTokens,\n tools,\n signal,\n { ...options, modelProfile, toolUseContext },\n )\n }\n\n // Use OpenAI-compatible interface for all other providers\n return queryOpenAI(messages, systemPrompt, maxThinkingTokens, tools, signal, {\n ...options,\n modelProfile,\n toolUseContext,\n })\n}\n\nasync function queryAnthropicNative(\n messages: (UserMessage | AssistantMessage)[],\n systemPrompt: string[],\n maxThinkingTokens: number,\n tools: Tool[],\n signal: AbortSignal,\n options?: {\n safeMode: boolean\n model: string\n prependCLISysprompt: boolean\n modelProfile?: ModelProfile | null\n toolUseContext?: ToolUseContext\n },\n): Promise<AssistantMessage> {\n const config = getGlobalConfig()\n const modelManager = getModelManager()\n const toolUseContext = options?.toolUseContext\n\n const modelProfile = options?.modelProfile || modelManager.getModel('main')\n let anthropic: Anthropic | AnthropicBedrock | AnthropicVertex\n let model: string\n let provider: string\n\n // \uD83D\uDD0D Debug: \u8BB0\u5F55\u6A21\u578B\u914D\u7F6E\u8BE6\u60C5\n debugLogger.api('MODEL_CONFIG_ANTHROPIC', {\n modelProfileFound: !!modelProfile,\n modelProfileId: modelProfile?.modelName,\n modelProfileName: modelProfile?.name,\n modelProfileModelName: modelProfile?.modelName,\n modelProfileProvider: modelProfile?.provider,\n modelProfileBaseURL: modelProfile?.baseURL,\n modelProfileApiKeyExists: !!modelProfile?.apiKey,\n optionsModel: options?.model,\n requestId: getCurrentRequest()?.id,\n })\n\n if (modelProfile) {\n // \u4F7F\u7528ModelProfile\u7684\u5B8C\u6574\u914D\u7F6E\n model = modelProfile.modelName\n provider = modelProfile.provider || config.primaryProvider || 'anthropic'\n\n // \u57FA\u4E8EModelProfile\u521B\u5EFA\u4E13\u7528\u7684API\u5BA2\u6237\u7AEF\n if (\n modelProfile.provider === 'anthropic' ||\n modelProfile.provider === 'bigdream' ||\n modelProfile.provider === 'opendev'\n ) {\n const clientConfig: any = {\n apiKey: modelProfile.apiKey,\n dangerouslyAllowBrowser: true,\n maxRetries: 0,\n timeout: parseInt(process.env.API_TIMEOUT_MS || String(60 * 1000), 10),\n defaultHeaders: {\n 'x-app': 'cli',\n 'User-Agent': USER_AGENT,\n },\n }\n\n // \u4F7F\u7528ModelProfile\u7684baseURL\u800C\u4E0D\u662F\u5168\u5C40\u914D\u7F6E\n if (modelProfile.baseURL) {\n clientConfig.baseURL = modelProfile.baseURL\n }\n\n anthropic = new Anthropic(clientConfig)\n } else {\n // \u5176\u4ED6\u63D0\u4F9B\u5546\u7684\u5904\u7406\u903B\u8F91\n anthropic = getAnthropicClient(model)\n }\n } else {\n // \uD83D\uDEA8 \u964D\u7EA7\uFF1A\u6CA1\u6709\u6709\u6548\u7684ModelProfile\u65F6\uFF0C\u5E94\u8BE5\u629B\u51FA\u9519\u8BEF\n const errorDetails = {\n modelProfileExists: !!modelProfile,\n modelProfileModelName: modelProfile?.modelName,\n requestedModel: options?.model,\n requestId: getCurrentRequest()?.id,\n }\n debugLogger.error('ANTHROPIC_FALLBACK_ERROR', errorDetails)\n throw new Error(\n `No valid ModelProfile available for Anthropic provider. Please configure model through /model command. Debug: ${JSON.stringify(errorDetails)}`,\n )\n }\n\n // Prepend system prompt block for easy API identification\n if (options?.prependCLISysprompt) {\n // Log stats about first block for analyzing prefix matching config\n const [firstSyspromptBlock] = splitSysPromptPrefix(systemPrompt)\n\n systemPrompt = [getCLISyspromptPrefix(), ...systemPrompt]\n }\n\n const system: TextBlockParam[] = splitSysPromptPrefix(systemPrompt).map(\n _ => ({\n text: _,\n type: 'text',\n }),\n )\n\n const toolSchemas = await Promise.all(\n tools.map(\n async tool =>\n ({\n name: tool.name,\n // Use getToolDescriptionAsync for consistent async access\n description: await getToolDescriptionAsync(tool),\n input_schema:\n 'inputJSONSchema' in tool && tool.inputJSONSchema\n ? tool.inputJSONSchema\n : zodToJsonSchema(tool.inputSchema),\n }) as unknown as Anthropic.Beta.Messages.BetaTool,\n ),\n )\n\n const anthropicMessages = addCacheBreakpoints(messages)\n\n // apply cache control\n const { systemBlocks: processedSystem, messageParams: processedMessages } =\n applyCacheControlWithLimits(system, anthropicMessages)\n const startIncludingRetries = Date.now()\n\n // \u8BB0\u5F55\u7CFB\u7EDF\u63D0\u793A\u6784\u5EFA\u8FC7\u7A0B\n logSystemPromptConstruction({\n basePrompt: systemPrompt.join('\\n'),\n mintoContext: generateMintoContext() || '',\n reminders: [], // \u8FD9\u91CC\u53EF\u4EE5\u4ECE generateSystemReminders \u83B7\u53D6\n finalPrompt: systemPrompt.join('\\n'),\n })\n\n let start = Date.now()\n let attemptNumber = 0\n let response\n\n try {\n response = await withRetry(\n async attempt => {\n attemptNumber = attempt\n start = Date.now()\n\n const params: Anthropic.Beta.Messages.MessageCreateParams = {\n model,\n max_tokens: getMaxTokensFromProfile(modelProfile),\n messages: processedMessages,\n system: processedSystem,\n tools: toolSchemas.length > 0 ? toolSchemas : undefined,\n tool_choice: toolSchemas.length > 0 ? { type: 'auto' } : undefined,\n }\n\n if (maxThinkingTokens > 0) {\n ;(params as any).extra_headers = {\n 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15',\n }\n ;(params as any).thinking = { max_tokens: maxThinkingTokens }\n }\n\n // \uD83D\uDD25 REAL-TIME API CALL DEBUG - \u4F7F\u7528\u5168\u5C40\u65E5\u5FD7\u7CFB\u7EDF (Anthropic Streaming)\n debugLogger.api('ANTHROPIC_API_CALL_START_STREAMING', {\n endpoint: modelProfile?.baseURL || 'DEFAULT_ANTHROPIC',\n model,\n provider,\n apiKeyConfigured: !!modelProfile?.apiKey,\n apiKeyPrefix: modelProfile?.apiKey\n ? modelProfile.apiKey.substring(0, 8)\n : null,\n maxTokens: params.max_tokens,\n temperature: MAIN_QUERY_TEMPERATURE,\n params: params,\n messageCount: params.messages?.length || 0,\n streamMode: true,\n toolsCount: toolSchemas.length,\n thinkingTokens: maxThinkingTokens,\n timestamp: new Date().toISOString(),\n modelProfileId: modelProfile?.modelName,\n modelProfileName: modelProfile?.name,\n })\n\n if (config.stream) {\n const stream = await anthropic.beta.messages.create(\n {\n ...params,\n stream: true,\n },\n {\n signal: signal, // \u2190 CRITICAL: Connect the AbortSignal to API call\n },\n )\n\n let finalResponse: any | null = null\n let messageStartEvent: any = null\n const contentBlocks: any[] = []\n const inputJSONBuffers = new Map<number, string>()\n let usage: any = null\n let stopReason: string | null = null\n let stopSequence: string | null = null\n\n for await (const event of stream) {\n if (signal.aborted) {\n debugLogger.flow('STREAM_ABORTED', {\n eventType: event.type,\n timestamp: Date.now(),\n })\n throw new Error('Request was cancelled')\n }\n\n switch (event.type) {\n case 'message_start':\n messageStartEvent = event\n finalResponse = {\n ...event.message,\n content: [], // Will be populated from content blocks\n }\n // NEW: Set initial input tokens from message_start and reset receivedChars\n setStreamingState({\n inputTokens: event.message.usage?.input_tokens,\n receivedChars: 0, // Reset for new request\n })\n break\n\n case 'content_block_start':\n contentBlocks[event.index] = { ...event.content_block }\n // Initialize JSON buffer for tool_use blocks\n if (event.content_block.type === 'tool_use') {\n inputJSONBuffers.set(event.index, '')\n }\n // \u2705 P0 FIX: Detect thinking block start and update UI\n if (event.content_block.type === 'thinking') {\n const thinkingStartTime = Date.now()\n setStreamingState({\n phase: 'deep_thinking',\n tokenCount: 0,\n thinkingMaxTokens: maxThinkingTokens,\n thinkingStartTime, // NEW: Record start time for duration tracking\n })\n debugLogger.flow('THINKING_BLOCK_START', {\n index: event.index,\n maxTokens: maxThinkingTokens,\n startTime: thinkingStartTime,\n })\n }\n break\n\n case 'content_block_delta':\n const blockIndex = event.index\n\n // Ensure content block exists\n if (!contentBlocks[blockIndex]) {\n contentBlocks[blockIndex] = {\n type:\n event.delta.type === 'text_delta' ? 'text' : 'tool_use',\n text: event.delta.type === 'text_delta' ? '' : undefined,\n }\n if (event.delta.type === 'input_json_delta') {\n inputJSONBuffers.set(blockIndex, '')\n }\n }\n\n if (event.delta.type === 'text_delta') {\n contentBlocks[blockIndex].text += event.delta.text\n // Update received chars for approximate token display\n const currentState = getStreamingState()\n setStreamingState({\n receivedChars:\n (currentState.receivedChars || 0) +\n event.delta.text.length,\n })\n } else if (event.delta.type === 'input_json_delta') {\n const currentBuffer = inputJSONBuffers.get(blockIndex) || ''\n inputJSONBuffers.set(\n blockIndex,\n currentBuffer + event.delta.partial_json,\n )\n }\n // \u2705 P0 FIX: Handle thinking_delta events to update token count\n else if (event.delta.type === 'thinking_delta') {\n const currentThinking =\n contentBlocks[blockIndex].thinking || ''\n const updatedThinking =\n currentThinking + (event.delta.thinking || '')\n contentBlocks[blockIndex] = {\n ...contentBlocks[blockIndex],\n thinking: updatedThinking,\n }\n\n // Update UI with current thinking token count\n setStreamingState({\n phase: 'deep_thinking',\n tokenCount: updatedThinking.length,\n thinkingMaxTokens: maxThinkingTokens,\n })\n\n debugLogger.trace('THINKING_DELTA', {\n index: blockIndex,\n tokenCount: updatedThinking.length,\n })\n }\n break\n\n case 'message_delta':\n if (event.delta.stop_reason)\n stopReason = event.delta.stop_reason\n if (event.delta.stop_sequence)\n stopSequence = event.delta.stop_sequence\n if (event.usage) {\n usage = { ...usage, ...event.usage }\n // NEW: Update UI with real-time output token count\n // Note: message_delta only provides output_tokens, not input_tokens\n setStreamingState({\n outputTokens: event.usage.output_tokens,\n })\n }\n break\n\n case 'content_block_stop':\n const stopIndex = event.index\n const block = contentBlocks[stopIndex]\n\n // \u2705 P0 FIX: Handle thinking block completion\n if (block?.type === 'thinking') {\n const streamState = getStreamingState()\n const thinkingDurationMs = streamState.thinkingStartTime\n ? Date.now() - streamState.thinkingStartTime\n : 0\n setStreamingState({\n phase: 'generating',\n thinkingDurationMs, // NEW: Store duration for display\n })\n debugLogger.flow('THINKING_BLOCK_COMPLETE', {\n index: stopIndex,\n finalTokenCount: block.thinking?.length || 0,\n durationMs: thinkingDurationMs,\n })\n }\n\n if (\n block?.type === 'tool_use' &&\n inputJSONBuffers.has(stopIndex)\n ) {\n const jsonStr = inputJSONBuffers.get(stopIndex)\n if (jsonStr) {\n try {\n block.input = JSON.parse(jsonStr)\n } catch (error) {\n const errorMsg =\n error instanceof Error ? error.message : String(error)\n debugLogger.error('JSON_PARSE_ERROR', {\n blockIndex: stopIndex,\n jsonStr:\n jsonStr.length > 500\n ? jsonStr.slice(0, 500) + '...'\n : jsonStr,\n error: errorMsg,\n })\n // Preserve parse error info for downstream error handling\n // Instead of empty {}, provide error context that query.ts can detect\n block.input = {\n __parse_error__: true,\n __error_message__: `JSON parse failed: ${errorMsg}`,\n __raw_json_preview__:\n jsonStr.length > 200\n ? jsonStr.slice(0, 200) + '...'\n : jsonStr,\n }\n }\n inputJSONBuffers.delete(stopIndex)\n }\n }\n break\n\n case 'message_stop':\n // Clear any remaining buffers\n inputJSONBuffers.clear()\n break\n }\n\n if (event.type === 'message_stop') {\n break\n }\n }\n\n if (!finalResponse || !messageStartEvent) {\n throw new Error('Stream ended without proper message structure')\n }\n\n // Construct the final response\n finalResponse = {\n ...messageStartEvent.message,\n content: contentBlocks.filter(Boolean),\n stop_reason: stopReason,\n stop_sequence: stopSequence,\n usage: {\n ...messageStartEvent.message.usage,\n ...usage,\n },\n }\n\n return finalResponse\n } else {\n // \uD83D\uDD25 REAL-TIME API CALL DEBUG - \u4F7F\u7528\u5168\u5C40\u65E5\u5FD7\u7CFB\u7EDF (Anthropic Non-Streaming)\n debugLogger.api('ANTHROPIC_API_CALL_START_NON_STREAMING', {\n endpoint: modelProfile?.baseURL || 'DEFAULT_ANTHROPIC',\n model,\n provider,\n apiKeyConfigured: !!modelProfile?.apiKey,\n apiKeyPrefix: modelProfile?.apiKey\n ? modelProfile.apiKey.substring(0, 8)\n : null,\n maxTokens: params.max_tokens,\n temperature: MAIN_QUERY_TEMPERATURE,\n messageCount: params.messages?.length || 0,\n streamMode: false,\n toolsCount: toolSchemas.length,\n thinkingTokens: maxThinkingTokens,\n timestamp: new Date().toISOString(),\n modelProfileId: modelProfile?.modelName,\n modelProfileName: modelProfile?.name,\n })\n\n return await anthropic.beta.messages.create(params, {\n signal: signal, // \u2190 CRITICAL: Connect the AbortSignal to API call\n })\n }\n },\n {\n signal,\n // Pass retry events to agent transcript for UI display\n onRetry: toolUseContext?.agentId\n ? ({ attempt, maxRetries, error, delayMs }) => {\n addRetryEventToTranscript(toolUseContext.agentId!, {\n attempt,\n maxRetries,\n errorMessage: error.message,\n delayMs,\n })\n }\n : undefined,\n },\n )\n\n debugLogger.api('ANTHROPIC_API_CALL_SUCCESS', {\n content: response.content,\n })\n\n const ttftMs = start - Date.now()\n const durationMs = Date.now() - startIncludingRetries\n\n const content = response.content.map((block: ContentBlock) => {\n if (block.type === 'text') {\n return {\n type: 'text' as const,\n text: block.text,\n }\n } else if (block.type === 'tool_use') {\n return {\n type: 'tool_use' as const,\n id: block.id,\n name: block.name,\n input: block.input,\n }\n }\n return block\n })\n\n // Build thinking metadata if thinking blocks are present\n const thinkingBlocks = content.filter(\n (block): block is ContentBlock & { type: 'thinking'; thinking: string } =>\n block.type === 'thinking',\n )\n const streamState = getStreamingState()\n const thinkingMetadata: ThinkingMetadata | undefined =\n thinkingBlocks.length > 0\n ? {\n charCount: thinkingBlocks.reduce(\n (sum, b) => sum + (b.thinking?.length || 0),\n 0,\n ),\n durationMs: streamState.thinkingDurationMs || 0,\n startTime: streamState.thinkingStartTime || Date.now(),\n isComplete: true,\n }\n : undefined\n\n const assistantMessage: AssistantMessage = {\n message: {\n id: response.id,\n content,\n model: response.model,\n role: 'assistant',\n stop_reason: response.stop_reason,\n stop_sequence: response.stop_sequence,\n type: 'message',\n usage: response.usage,\n },\n type: 'assistant',\n uuid: nanoid() as UUID,\n durationMs,\n costUSD: 0, // Will be calculated below\n thinkingMetadata,\n }\n\n // \u8BB0\u5F55\u5B8C\u6574\u7684 LLM \u4EA4\u4E92\u8C03\u8BD5\u4FE1\u606F (Anthropic path)\n // \u6CE8\u610F\uFF1AAnthropic API\u5C06system prompt\u548Cmessages\u5206\u5F00\uFF0C\u8FD9\u91CC\u91CD\u6784\u4E3A\u5B8C\u6574\u7684API\u8C03\u7528\u89C6\u56FE\n const systemMessages = system.map(block => ({\n role: 'system',\n content: block.text,\n }))\n\n logLLMInteraction({\n systemPrompt: systemPrompt.join('\\n'),\n messages: [...systemMessages, ...anthropicMessages],\n response: response,\n usage: response.usage\n ? {\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n }\n : undefined,\n timing: {\n start: start,\n end: Date.now(),\n },\n apiFormat: 'anthropic',\n })\n\n // Calculate cost using native Anthropic usage data\n const inputTokens = response.usage.input_tokens\n const outputTokens = response.usage.output_tokens\n const cacheCreationInputTokens =\n response.usage.cache_creation_input_tokens ?? 0\n const cacheReadInputTokens = response.usage.cache_read_input_tokens ?? 0\n\n const costUSD =\n (inputTokens / 1_000_000) * getModelInputTokenCostUSD(model) +\n (outputTokens / 1_000_000) * getModelOutputTokenCostUSD(model) +\n (cacheCreationInputTokens / 1_000_000) *\n getModelInputTokenCostUSD(model) +\n (cacheReadInputTokens / 1_000_000) *\n (getModelInputTokenCostUSD(model) * 0.1) // Cache reads are 10% of input cost\n\n assistantMessage.costUSD = costUSD\n addToTotalCost(costUSD, durationMs)\n\n // Record token usage to unified stats manager\n recordTokenUsage(\n {\n inputTokens,\n outputTokens,\n cacheCreationTokens: cacheCreationInputTokens,\n cacheReadTokens: cacheReadInputTokens,\n },\n costUSD,\n model,\n toolUseContext\n ? ({\n agentId: toolUseContext.agentId,\n toolUseId: toolUseContext.toolUseId,\n model,\n } as TokenTrackingContext)\n : undefined,\n )\n\n return assistantMessage\n } catch (error) {\n return getAssistantMessageFromError(error)\n }\n}\n\nfunction getAssistantMessageFromError(error: unknown): AssistantMessage {\n if (error instanceof Error && error.message.includes('prompt is too long')) {\n return createAssistantAPIErrorMessage(PROMPT_TOO_LONG_ERROR_MESSAGE)\n }\n if (\n error instanceof Error &&\n error.message.includes('Your credit balance is too low')\n ) {\n return createAssistantAPIErrorMessage(CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE)\n }\n if (\n error instanceof Error &&\n error.message.toLowerCase().includes('x-api-key')\n ) {\n return createAssistantAPIErrorMessage(INVALID_API_KEY_ERROR_MESSAGE)\n }\n if (error instanceof Error) {\n if (process.env.NODE_ENV === 'development') {\n debugLogger.error('ANTHROPIC_API_ERROR', {\n message: error.message,\n stack: error.stack,\n })\n }\n return createAssistantAPIErrorMessage(\n `${API_ERROR_MESSAGE_PREFIX}: ${error.message}`,\n )\n }\n return createAssistantAPIErrorMessage(API_ERROR_MESSAGE_PREFIX)\n}\n\nfunction addCacheBreakpoints(\n messages: (UserMessage | AssistantMessage)[],\n): MessageParam[] {\n return messages.map((msg, index) => {\n return msg.type === 'user'\n ? userMessageToMessageParam(msg, index > messages.length - 3)\n : assistantMessageToMessageParam(msg, index > messages.length - 3)\n })\n}\n\nasync function queryOpenAI(\n messages: (UserMessage | AssistantMessage)[],\n systemPrompt: string[],\n maxThinkingTokens: number,\n tools: Tool[],\n signal: AbortSignal,\n options?: {\n safeMode: boolean\n model: string\n prependCLISysprompt: boolean\n modelProfile?: ModelProfile | null\n toolUseContext?: ToolUseContext\n },\n): Promise<AssistantMessage> {\n const config = getGlobalConfig()\n const modelManager = getModelManager()\n const toolUseContext = options?.toolUseContext\n\n const modelProfile = options?.modelProfile || modelManager.getModel('main')\n let model: string\n\n // \uD83D\uDD0D Debug: \u8BB0\u5F55\u6A21\u578B\u914D\u7F6E\u8BE6\u60C5\n const currentRequest = getCurrentRequest()\n debugLogger.api('MODEL_CONFIG_OPENAI', {\n modelProfileFound: !!modelProfile,\n modelProfileId: modelProfile?.modelName,\n modelProfileName: modelProfile?.name,\n modelProfileModelName: modelProfile?.modelName,\n modelProfileProvider: modelProfile?.provider,\n modelProfileBaseURL: modelProfile?.baseURL,\n modelProfileApiKeyExists: !!modelProfile?.apiKey,\n optionsModel: options?.model,\n requestId: getCurrentRequest()?.id,\n })\n\n if (modelProfile) {\n model = modelProfile.modelName\n } else {\n model = options?.model || modelProfile?.modelName || ''\n }\n // Prepend system prompt block for easy API identification\n if (options?.prependCLISysprompt) {\n const [firstSyspromptBlock] = splitSysPromptPrefix(systemPrompt)\n\n systemPrompt = [getCLISyspromptPrefix() + systemPrompt] // some openai-like providers need the entire system prompt as a single block\n }\n\n const system: TextBlockParam[] = splitSysPromptPrefix(systemPrompt).map(\n _ => ({\n ...(PROMPT_CACHING_ENABLED\n ? { cache_control: { type: 'ephemeral' } }\n : {}),\n text: _,\n type: 'text',\n }),\n )\n\n const toolSchemas = await Promise.all(\n tools.map(\n async _ =>\n ({\n type: 'function',\n function: {\n name: _.name,\n description: await _.prompt({\n safeMode: options?.safeMode,\n }),\n // Use tool's JSON schema directly if provided, otherwise convert Zod schema\n parameters:\n 'inputJSONSchema' in _ && _.inputJSONSchema\n ? _.inputJSONSchema\n : zodToJsonSchema(_.inputSchema),\n },\n }) as OpenAI.ChatCompletionTool,\n ),\n )\n\n const openaiSystem = system.map(\n s =>\n ({\n role: 'system',\n content: s.text,\n }) as OpenAI.ChatCompletionMessageParam,\n )\n\n const openaiMessages = convertAnthropicMessagesToOpenAIMessages(messages)\n const startIncludingRetries = Date.now()\n\n // \u8BB0\u5F55\u7CFB\u7EDF\u63D0\u793A\u6784\u5EFA\u8FC7\u7A0B (OpenAI path)\n logSystemPromptConstruction({\n basePrompt: systemPrompt.join('\\n'),\n mintoContext: generateMintoContext() || '',\n reminders: [], // \u8FD9\u91CC\u53EF\u4EE5\u4ECE generateSystemReminders \u83B7\u53D6\n finalPrompt: systemPrompt.join('\\n'),\n })\n\n let start = Date.now()\n let attemptNumber = 0\n let response\n\n try {\n response = await withRetry(\n async attempt => {\n attemptNumber = attempt\n start = Date.now()\n // \uD83D\uDD25 GPT-5 Enhanced Parameter Construction\n const maxTokens = getMaxTokensFromProfile(modelProfile)\n const isGPT5 = isGPT5Model(model)\n\n const opts: OpenAI.ChatCompletionCreateParams = {\n model,\n\n ...(isGPT5\n ? { max_completion_tokens: maxTokens }\n : { max_tokens: maxTokens }),\n messages: [...openaiSystem, ...openaiMessages],\n\n temperature: isGPT5 ? 1 : MAIN_QUERY_TEMPERATURE,\n }\n if (config.stream) {\n ;(opts as OpenAI.ChatCompletionCreateParams).stream = true\n opts.stream_options = {\n include_usage: true,\n }\n }\n\n if (toolSchemas.length > 0) {\n opts.tools = toolSchemas\n opts.tool_choice = 'auto'\n }\n const reasoningEffort = await getReasoningEffort(modelProfile, messages)\n if (reasoningEffort) {\n opts.reasoning_effort = reasoningEffort\n }\n\n if (modelProfile && modelProfile.modelName) {\n debugLogger.api('USING_MODEL_PROFILE_PATH', {\n modelProfileName: modelProfile.modelName,\n modelName: modelProfile.modelName,\n provider: modelProfile.provider,\n baseURL: modelProfile.baseURL,\n apiKeyExists: !!modelProfile.apiKey,\n requestId: getCurrentRequest()?.id,\n })\n\n // Enable new adapter system with environment variable\n const USE_NEW_ADAPTER_SYSTEM =\n process.env.USE_NEW_ADAPTERS !== 'false'\n\n if (USE_NEW_ADAPTER_SYSTEM) {\n // New adapter system\n const adapter = ModelAdapterFactory.createAdapter(modelProfile)\n\n // Build unified request parameters\n const unifiedParams: UnifiedRequestParams = {\n messages: openaiMessages,\n systemPrompt: openaiSystem.map(s => s.content as string),\n tools: tools,\n maxTokens: getMaxTokensFromProfile(modelProfile),\n stream: config.stream,\n reasoningEffort: reasoningEffort as any,\n temperature: isGPT5Model(model) ? 1 : MAIN_QUERY_TEMPERATURE,\n previousResponseId:\n toolUseContext?.responseState?.previousResponseId,\n verbosity: 'high', // High verbosity for coding tasks\n }\n\n // Create request using adapter\n const request = adapter.createRequest(unifiedParams)\n\n // Determine which API to use\n if (ModelAdapterFactory.shouldUseResponsesAPI(modelProfile)) {\n // Use Responses API for GPT-5 and similar models\n const { callGPT5ResponsesAPI } = await import('./openai')\n const response = await callGPT5ResponsesAPI(\n modelProfile,\n request,\n signal,\n )\n const unifiedResponse = adapter.parseResponse(response)\n\n // Convert unified response back to Anthropic format\n const apiMessage = {\n role: 'assistant' as const,\n content: unifiedResponse.content,\n tool_calls: unifiedResponse.toolCalls,\n usage: {\n prompt_tokens: unifiedResponse.usage.promptTokens,\n completion_tokens: unifiedResponse.usage.completionTokens,\n },\n }\n const assistantMsg: AssistantMessage = {\n type: 'assistant',\n message: apiMessage as any,\n costUSD: 0, // Will be calculated later\n durationMs: Date.now() - start,\n uuid: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}` as any,\n responseId: unifiedResponse.responseId, // For state management\n }\n return assistantMsg\n } else {\n // Use existing Chat Completions flow\n const s = await getCompletionWithProfile(\n modelProfile,\n request,\n 0,\n 10,\n signal,\n )\n let finalResponse\n if (config.stream) {\n finalResponse = await handleMessageStream(\n s as ChatCompletionStream,\n signal,\n )\n } else {\n finalResponse = s\n }\n const r = convertOpenAIResponseToAnthropic(finalResponse, tools)\n return r\n }\n } else {\n // Legacy system (preserved for fallback)\n const completionFunction = isGPT5Model(modelProfile.modelName)\n ? getGPT5CompletionWithProfile\n : getCompletionWithProfile\n const s = await completionFunction(\n modelProfile,\n opts,\n 0,\n 10,\n signal,\n )\n let finalResponse\n if (opts.stream) {\n finalResponse = await handleMessageStream(\n s as ChatCompletionStream,\n signal,\n )\n } else {\n finalResponse = s\n }\n const r = convertOpenAIResponseToAnthropic(finalResponse, tools)\n return r\n }\n } else {\n // \uD83D\uDEA8 \u8B66\u544A\uFF1AModelProfile\u4E0D\u53EF\u7528\uFF0C\u4F7F\u7528\u65E7\u903B\u8F91\u8DEF\u5F84\n debugLogger.api('USING_LEGACY_PATH', {\n modelProfileExists: !!modelProfile,\n modelProfileId: modelProfile?.modelName,\n modelNameExists: !!modelProfile?.modelName,\n fallbackModel: 'main',\n actualModel: model,\n requestId: getCurrentRequest()?.id,\n })\n\n // \uD83D\uDEA8 FALLBACK: \u6CA1\u6709\u6709\u6548\u7684ModelProfile\u65F6\uFF0C\u5E94\u8BE5\u629B\u51FA\u9519\u8BEF\u800C\u4E0D\u662F\u4F7F\u7528\u9057\u7559\u7CFB\u7EDF\n const errorDetails = {\n modelProfileExists: !!modelProfile,\n modelProfileId: modelProfile?.modelName,\n modelNameExists: !!modelProfile?.modelName,\n requestedModel: model,\n requestId: getCurrentRequest()?.id,\n }\n debugLogger.error('NO_VALID_MODEL_PROFILE', errorDetails)\n throw new Error(\n `No valid ModelProfile available for model: ${model}. Please configure model through /model command. Debug: ${JSON.stringify(errorDetails)}`,\n )\n }\n },\n {\n signal,\n // Pass retry events to agent transcript for UI display\n onRetry: toolUseContext?.agentId\n ? ({ attempt, maxRetries, error, delayMs }) => {\n addRetryEventToTranscript(toolUseContext.agentId!, {\n attempt,\n maxRetries,\n errorMessage: error.message,\n delayMs,\n })\n }\n : undefined,\n },\n )\n } catch (error) {\n logError(error)\n return getAssistantMessageFromError(error)\n }\n const durationMs = Date.now() - start\n const durationMsIncludingRetries = Date.now() - startIncludingRetries\n\n const inputTokens = response.usage?.prompt_tokens ?? 0\n const outputTokens = response.usage?.completion_tokens ?? 0\n const cacheReadInputTokens =\n response.usage?.prompt_token_details?.cached_tokens ?? 0\n const cacheCreationInputTokens =\n response.usage?.prompt_token_details?.cached_tokens ?? 0\n const costUSD =\n (inputTokens / 1_000_000) * SONNET_COST_PER_MILLION_INPUT_TOKENS +\n (outputTokens / 1_000_000) * SONNET_COST_PER_MILLION_OUTPUT_TOKENS +\n (cacheReadInputTokens / 1_000_000) *\n SONNET_COST_PER_MILLION_PROMPT_CACHE_READ_TOKENS +\n (cacheCreationInputTokens / 1_000_000) *\n SONNET_COST_PER_MILLION_PROMPT_CACHE_WRITE_TOKENS\n\n addToTotalCost(costUSD, durationMsIncludingRetries)\n\n // Record token usage to unified stats manager\n recordTokenUsage(\n {\n inputTokens,\n outputTokens,\n cacheCreationTokens: cacheCreationInputTokens,\n cacheReadTokens: cacheReadInputTokens,\n },\n costUSD,\n model,\n toolUseContext\n ? ({\n agentId: toolUseContext.agentId,\n toolUseId: toolUseContext.toolUseId,\n model,\n } as TokenTrackingContext)\n : undefined,\n )\n\n // \u8BB0\u5F55\u5B8C\u6574\u7684 LLM \u4EA4\u4E92\u8C03\u8BD5\u4FE1\u606F (OpenAI path)\n logLLMInteraction({\n systemPrompt: systemPrompt.join('\\n'),\n messages: [...openaiSystem, ...openaiMessages],\n response: response,\n usage: {\n inputTokens: inputTokens,\n outputTokens: outputTokens,\n },\n timing: {\n start: start,\n end: Date.now(),\n },\n apiFormat: 'openai',\n })\n\n return {\n message: {\n ...response,\n content: normalizeContentFromAPI(response.content),\n usage: {\n input_tokens: inputTokens,\n output_tokens: outputTokens,\n cache_read_input_tokens: cacheReadInputTokens,\n cache_creation_input_tokens: 0,\n },\n },\n costUSD,\n durationMs,\n type: 'assistant',\n uuid: randomUUID(),\n }\n}\n\nfunction getMaxTokensFromProfile(modelProfile: any): number {\n // Use ModelProfile maxTokens or reasonable default\n return modelProfile?.maxTokens || 8000\n}\n\nfunction getModelInputTokenCostUSD(model: string): number {\n // Find the model in the models object\n for (const providerModels of Object.values(models)) {\n const modelInfo = providerModels.find((m: any) => m.model === model)\n if (modelInfo) {\n return modelInfo.input_cost_per_token || 0\n }\n }\n // Default fallback cost for unknown models\n return 0.000003 // Default to Claude 3 Haiku cost\n}\n\nfunction getModelOutputTokenCostUSD(model: string): number {\n // Find the model in the models object\n for (const providerModels of Object.values(models)) {\n const modelInfo = providerModels.find((m: any) => m.model === model)\n if (modelInfo) {\n return modelInfo.output_cost_per_token || 0\n }\n }\n // Default fallback cost for unknown models\n return 0.000015 // Default to Claude 3 Haiku cost\n}\n\n// New unified query functions for model pointer system\nexport async function queryModel(\n modelPointer: import('@utils/config').ModelPointerType,\n messages: (UserMessage | AssistantMessage)[],\n systemPrompt: string[] = [],\n signal?: AbortSignal,\n): Promise<AssistantMessage> {\n // Use queryLLM with the pointer directly\n return queryLLM(\n messages,\n systemPrompt,\n 0, // maxThinkingTokens\n [], // tools\n signal || new AbortController().signal,\n {\n safeMode: false,\n model: modelPointer,\n prependCLISysprompt: true,\n },\n )\n}\n\n// Note: Use queryModel(pointer, ...) directly instead of these convenience functions\n\n// Simplified query function using quick model pointer\nexport async function queryQuick({\n systemPrompt = [],\n userPrompt,\n assistantPrompt,\n enablePromptCaching = false,\n signal,\n}: {\n systemPrompt?: string[]\n userPrompt: string\n assistantPrompt?: string\n enablePromptCaching?: boolean\n signal?: AbortSignal\n}): Promise<AssistantMessage> {\n const messages = [\n {\n message: { role: 'user', content: userPrompt },\n type: 'user',\n uuid: randomUUID(),\n },\n ] as (UserMessage | AssistantMessage)[]\n\n return queryModel('quick', messages, systemPrompt, signal)\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO;AACP,OAAO,aAAa,oBAAoB,gBAAgB;AACxD,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,OAAO,WAAW;AAClB,SAAS,kBAAwB;AACjC,OAAO;AAEP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAEjC,OAAO,YAAY;AAEnB,SAAe,+BAA+B;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,sBAAsB;AAC/B,SAAS,UAAU,kBAAkB;AACrC,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe;AACxB;AAAA,EACE,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AAEpC,SAAS,sBAAsB,yBAAyB;AAMxD,SAAS,aAAa,kBAAkB;AACxC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AAIxC,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB,yBAAyB;AAIrD,SAAS,YAAY,WAA4B;AAC/C,SAAO,UAAU,WAAW,OAAO;AACrC;AAGA,MAAM,oBAAoB;AAAA,EACxB,OAAe;AAAA,EACP,mBAA2B;AAAA,EAC3B,mBAA4B;AAAA,EAC5B,cAAoC;AAAA,EAEpC,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAc,cAAmC;AAC/C,QAAI,CAAC,oBAAoB,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AA,IACf;AAAA,MACE,SAAS,EAAE,MAAM,QAAQ,SAAS,WAAW;AAAA,MAC7C,MAAM;AAAA,MACN,MAAM,WAAW;AAAA,IACnB;AAAA,EACF;AAEA,SAAO,WAAW,SAAS,UAAU,cAAc,MAAM;AAC3D;",
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["/**\n * LLM service facade \u2014 thin re-export from decomposed modules in ./llm/.\n *\n * All public API is preserved for backward compatibility with existing importers.\n * New code should import from '@services/llm' (or the specific submodule) directly.\n */\nexport {\n // Constants\n API_ERROR_MESSAGE_PREFIX,\n PROMPT_TOO_LONG_ERROR_MESSAGE,\n CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE,\n INVALID_API_KEY_ERROR_MESSAGE,\n NO_CONTENT_MESSAGE,\n MAIN_QUERY_TEMPERATURE,\n\n // MintoContext\n generateMintoContext,\n refreshMintoContext,\n\n // Anthropic provider\n fetchAnthropicModels,\n verifyApiKey,\n getAnthropicClient,\n resetAnthropicClient,\n userMessageToMessageParam,\n assistantMessageToMessageParam,\n\n // Dispatch\n queryLLM,\n formatSystemPromptWithContext,\n queryModel,\n queryQuick,\n} from './llm'\n"],
|
|
5
|
+
"mappings": "AAMA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -196,7 +196,8 @@ function createCustomCommand(frontmatter, content, filePath, baseDir) {
|
|
|
196
196
|
const pathParts = relativePath.split("/");
|
|
197
197
|
const fileName = pathParts[pathParts.length - 1].replace(".md", "");
|
|
198
198
|
const userMintoDir = join(homedir(), ".minto", "commands");
|
|
199
|
-
const
|
|
199
|
+
const userClaudeDir = join(homedir(), ".claude", "commands");
|
|
200
|
+
const scope = baseDir === userMintoDir || baseDir === userClaudeDir ? "user" : "project";
|
|
200
201
|
const prefix = scope === "user" ? "user" : "project";
|
|
201
202
|
let finalName;
|
|
202
203
|
if (frontmatter.name) {
|
|
@@ -270,26 +271,43 @@ IMPORTANT: You are restricted to using only these tools: ${allowedToolsStr}. Do
|
|
|
270
271
|
}
|
|
271
272
|
const loadCustomCommands = memoize(
|
|
272
273
|
async () => {
|
|
274
|
+
const userClaudeDir = join(homedir(), ".claude", "commands");
|
|
273
275
|
const userMintoDir = join(homedir(), ".minto", "commands");
|
|
276
|
+
const projectClaudeDir = join(getCwd(), ".claude", "commands");
|
|
274
277
|
const projectMintoDir = join(getCwd(), ".minto", "commands");
|
|
275
278
|
const abortController = new AbortController();
|
|
276
279
|
const timeout = setTimeout(() => abortController.abort(), 3e3);
|
|
277
280
|
try {
|
|
278
281
|
const startTime = Date.now();
|
|
279
|
-
const [
|
|
282
|
+
const [
|
|
283
|
+
projectClaudeFiles,
|
|
284
|
+
projectMintoFiles,
|
|
285
|
+
userClaudeFiles,
|
|
286
|
+
userMintoFiles
|
|
287
|
+
] = await Promise.all([
|
|
288
|
+
existsSync(projectClaudeDir) ? scanMarkdownFiles(
|
|
289
|
+
["--files", "--hidden", "--glob", "*.md"],
|
|
290
|
+
projectClaudeDir,
|
|
291
|
+
abortController.signal
|
|
292
|
+
) : Promise.resolve([]),
|
|
280
293
|
existsSync(projectMintoDir) ? scanMarkdownFiles(
|
|
281
294
|
["--files", "--hidden", "--glob", "*.md"],
|
|
282
295
|
projectMintoDir,
|
|
283
296
|
abortController.signal
|
|
284
297
|
) : Promise.resolve([]),
|
|
298
|
+
existsSync(userClaudeDir) ? scanMarkdownFiles(
|
|
299
|
+
["--files", "--glob", "*.md"],
|
|
300
|
+
userClaudeDir,
|
|
301
|
+
abortController.signal
|
|
302
|
+
) : Promise.resolve([]),
|
|
285
303
|
existsSync(userMintoDir) ? scanMarkdownFiles(
|
|
286
304
|
["--files", "--glob", "*.md"],
|
|
287
305
|
userMintoDir,
|
|
288
306
|
abortController.signal
|
|
289
307
|
) : Promise.resolve([])
|
|
290
308
|
]);
|
|
291
|
-
const projectFiles = [...projectMintoFiles];
|
|
292
|
-
const userFiles = [...userMintoFiles];
|
|
309
|
+
const projectFiles = [...projectClaudeFiles, ...projectMintoFiles];
|
|
310
|
+
const userFiles = [...userClaudeFiles, ...userMintoFiles];
|
|
293
311
|
const allFiles = [...projectFiles, ...userFiles];
|
|
294
312
|
const duration = Date.now() - startTime;
|
|
295
313
|
const commands = [];
|
|
@@ -341,8 +359,10 @@ const loadCustomCommands = memoize(
|
|
|
341
359
|
() => {
|
|
342
360
|
const cwd = getCwd();
|
|
343
361
|
const userMintoDir = join(homedir(), ".minto", "commands");
|
|
362
|
+
const userClaudeDir = join(homedir(), ".claude", "commands");
|
|
344
363
|
const projectMintoDir = join(cwd, ".minto", "commands");
|
|
345
|
-
|
|
364
|
+
const projectClaudeDir = join(cwd, ".claude", "commands");
|
|
365
|
+
return `${cwd}:${existsSync(userMintoDir)}:${existsSync(userClaudeDir)}:${existsSync(projectMintoDir)}:${existsSync(projectClaudeDir)}:${Math.floor(Date.now() / 6e4)}`;
|
|
346
366
|
}
|
|
347
367
|
);
|
|
348
368
|
const reloadCustomCommands = () => {
|
|
@@ -351,12 +371,14 @@ const reloadCustomCommands = () => {
|
|
|
351
371
|
function getCustomCommandDirectories() {
|
|
352
372
|
return {
|
|
353
373
|
user: join(homedir(), ".minto", "commands"),
|
|
354
|
-
|
|
374
|
+
userClaude: join(homedir(), ".claude", "commands"),
|
|
375
|
+
project: join(getCwd(), ".minto", "commands"),
|
|
376
|
+
projectClaude: join(getCwd(), ".claude", "commands")
|
|
355
377
|
};
|
|
356
378
|
}
|
|
357
379
|
function hasCustomCommands() {
|
|
358
|
-
const { user, project } = getCustomCommandDirectories();
|
|
359
|
-
return existsSync(user) || existsSync(project);
|
|
380
|
+
const { user, userClaude, project, projectClaude } = getCustomCommandDirectories();
|
|
381
|
+
return existsSync(user) || existsSync(userClaude) || existsSync(project) || existsSync(projectClaude);
|
|
360
382
|
}
|
|
361
383
|
const loadPluginCommands = memoize(
|
|
362
384
|
async () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/services/customCommands.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync, readFileSync } from 'fs'\nimport { join } from 'path'\nimport { homedir } from 'os'\nimport { memoize } from 'lodash-es'\nimport type { MessageParam } from '@anthropic-ai/sdk/resources/index.mjs'\nimport type { Command } from '@commands'\nimport { getCwd } from '@utils/state'\nimport { execFile } from 'child_process'\nimport { promisify } from 'util'\nimport { loadAllPlugins } from '@utils/pluginLoader'\nimport type { LoadedPlugin, LoadedCommand } from '../types/plugin'\nimport {\n getCurrentProjectConfig,\n saveCurrentProjectConfig,\n} from '@utils/config'\nimport { substituteVariables } from '@utils/stringSubstitution'\n\nconst execFileAsync = promisify(execFile)\n\n/**\n * Check if a bash command is allowed based on project config permissions\n * This integrates with the same permission system used by BashTool\n */\nfunction isBashCommandAllowed(command: string): boolean {\n const projectConfig = getCurrentProjectConfig()\n const allowedTools = projectConfig?.allowedTools || []\n\n // Check if the command or its prefix is in allowed tools\n const parts = command.split(/\\s+/)\n const baseCommand = parts[0]\n\n // Check exact match\n if (allowedTools.includes(`Bash(${command})`)) {\n return true\n }\n\n // Check base command prefix match\n if (allowedTools.includes(`Bash(${baseCommand}:*)`)) {\n return true\n }\n\n // Safe commands that don't need permission\n const safeCommands = new Set([\n 'git',\n 'ls',\n 'pwd',\n 'date',\n 'which',\n 'echo',\n 'cat',\n 'head',\n 'tail',\n 'wc',\n 'sort',\n 'uniq',\n 'grep',\n 'find',\n 'dirname',\n 'basename',\n ])\n\n if (safeCommands.has(baseCommand)) {\n return true\n }\n\n return false\n}\n\n/**\n * Check if file read is allowed based on project config permissions\n * This integrates with the same permission system used by FileReadTool\n */\nfunction isFileReadAllowed(filePath: string): boolean {\n const projectConfig = getCurrentProjectConfig()\n const allowedTools = projectConfig?.allowedTools || []\n\n // File read is generally allowed - FileReadTool doesn't require permission\n // But we log it for audit purposes\n return true\n}\n\n/**\n * Execute bash commands found in custom command content using !`command` syntax\n *\n * This function processes dynamic command execution within custom commands,\n * following the same security model as the main BashTool but with restricted scope.\n * Commands are executed in the current working directory with a timeout.\n *\n * Security: Commands are checked against the permission system before execution.\n * Only safe commands (git, ls, etc.) or explicitly allowed commands will execute.\n *\n * @param content - The custom command content to process\n * @returns Promise<string> - Content with bash commands replaced by their output\n */\nexport async function executeBashCommands(content: string): Promise<string> {\n // Match patterns like !`git status` or !`command here`\n const bashCommandRegex = /!\\`([^`]+)\\`/g\n const matches = [...content.matchAll(bashCommandRegex)]\n\n if (matches.length === 0) {\n return content\n }\n\n let result = content\n\n for (const match of matches) {\n const fullMatch = match[0]\n const command = match[1].trim()\n\n // Security check: verify command is allowed\n if (!isBashCommandAllowed(command)) {\n console.warn(\n `Custom command bash execution denied: \"${command}\" - not in allowed list`,\n )\n result = result.replace(fullMatch, `(permission denied: ${command})`)\n continue\n }\n\n try {\n // Parse command and args using simple shell parsing\n // This mirrors the approach used in the main BashTool but with stricter limits\n const parts = command.split(/\\s+/)\n const cmd = parts[0]\n const args = parts.slice(1)\n\n // Execute with conservative timeout (5s vs BashTool's 2min default)\n const { stdout, stderr } = await execFileAsync(cmd, args, {\n timeout: 5000,\n encoding: 'utf8',\n cwd: getCwd(), // Use current working directory for consistency\n })\n\n // Replace the bash command with its output, preferring stdout\n const output = stdout.trim() || stderr.trim() || '(no output)'\n result = result.replace(fullMatch, output)\n } catch (error) {\n console.warn(`Failed to execute bash command \"${command}\":`, error)\n result = result.replace(fullMatch, `(error executing: ${command})`)\n }\n }\n\n return result\n}\n\n/**\n * Resolve file references using @filepath syntax within custom commands\n *\n * This function implements file inclusion for custom commands, similar to how\n * the FileReadTool works but with inline processing. Files are read from the\n * current working directory and formatted as markdown code blocks.\n *\n * Security note: Files are read with the same permissions as the main process,\n * following the same security model as other file operations in the system.\n *\n * @param content - The custom command content to process\n * @returns Promise<string> - Content with file references replaced by file contents\n */\nexport async function resolveFileReferences(content: string): Promise<string> {\n // Match patterns like @src/file.js or @path/to/file.txt\n // Use consistent file mention pattern from mentionProcessor\n // Exclude agent and ask-model patterns to avoid conflicts\n const fileRefRegex = /@([a-zA-Z0-9/._-]+(?:\\.[a-zA-Z0-9]+)?)/g\n const matches = [...content.matchAll(fileRefRegex)]\n\n if (matches.length === 0) {\n return content\n }\n\n let result = content\n\n for (const match of matches) {\n const fullMatch = match[0]\n const filePath = match[1]\n\n // Skip agent mentions - these are handled by the mention processor\n if (filePath.startsWith('agent-')) {\n continue\n }\n\n try {\n // Resolve relative to current working directory\n // This maintains consistency with how other file operations work\n const fullPath = join(getCwd(), filePath)\n\n if (existsSync(fullPath)) {\n const fileContent = readFileSync(fullPath, { encoding: 'utf-8' })\n\n // Format file content with filename header for clarity\n // This matches the format used by FileReadTool for consistency\n const formattedContent = `\\n\\n## File: ${filePath}\\n\\`\\`\\`\\n${fileContent}\\n\\`\\`\\`\\n`\n result = result.replace(fullMatch, formattedContent)\n } else {\n result = result.replace(fullMatch, `(file not found: ${filePath})`)\n }\n } catch (error) {\n console.warn(`Failed to read file \"${filePath}\":`, error)\n result = result.replace(fullMatch, `(error reading: ${filePath})`)\n }\n }\n\n return result\n}\n\n/**\n * Validate and process allowed-tools specification from frontmatter\n *\n * This function handles tool restriction specifications in custom commands.\n * When allowed-tools is specified, it adds instructions to the prompt to\n * restrict the assistant to only using those tools.\n *\n * Note: The actual enforcement happens at the prompt level - we instruct the\n * assistant to only use specific tools. This is consistent with how Claude Code\n * handles tool restrictions in agent configurations.\n *\n * @param allowedTools - Array of tool names from frontmatter\n * @returns boolean - True if validation passes\n */\nfunction validateAllowedTools(allowedTools: string[] | undefined): boolean {\n // Validation is always true - the restriction is enforced via prompt injection\n // in getPromptForCommand() which adds the tool restriction text\n return true\n}\n\n/**\n * Frontmatter configuration for custom commands\n *\n * This interface defines the YAML frontmatter structure that can be used\n * to configure custom commands. It mirrors the Claude Desktop custom command\n * system for compatibility while adding Minto-specific enhancements.\n */\nexport interface CustomCommandFrontmatter {\n /** Display name for the command (overrides filename-based naming) */\n name?: string\n /** Brief description of what the command does */\n description?: string\n /** Alternative names that can be used to invoke this command */\n aliases?: string[]\n /** Whether this command is active and can be executed */\n enabled?: boolean\n /** Whether this command should be hidden from help output */\n hidden?: boolean\n /** Message to display while the command is running */\n progressMessage?: string\n /** Named arguments for legacy {arg} placeholder support */\n argNames?: string[]\n /** Tools that this command is restricted to use */\n 'allowed-tools'?: string[]\n}\n\n/**\n * Extended Command interface with scope information\n *\n * This extends the base Command interface to include scope metadata\n * for distinguishing between user-level and project-level commands.\n */\nexport interface CustomCommandWithScope {\n /** Command type - matches PromptCommand */\n type: 'prompt'\n /** Command name */\n name: string\n /** Command description */\n description: string\n /** Whether command is enabled */\n isEnabled: boolean\n /** Whether command is hidden */\n isHidden: boolean\n /** Command aliases */\n aliases?: string[]\n /** Progress message */\n progressMessage: string\n /** Argument names for legacy support */\n argNames?: string[]\n /** User-facing name function */\n userFacingName(): string\n /** Prompt generation function */\n getPromptForCommand(args: string): Promise<MessageParam[]>\n /** Scope indicates whether this is a user or project command */\n scope?: 'user' | 'project'\n}\n\n/**\n * Parsed custom command file representation\n *\n * This interface represents a fully parsed custom command file with\n * separated frontmatter and content sections.\n */\nexport interface CustomCommandFile {\n /** Parsed frontmatter configuration */\n frontmatter: CustomCommandFrontmatter\n /** Markdown content (without frontmatter) */\n content: string\n /** Absolute path to the source file */\n filePath: string\n}\n\n/**\n * Parse YAML frontmatter from markdown content\n *\n * This function extracts and parses YAML frontmatter from markdown files,\n * supporting the same syntax as Jekyll and other static site generators.\n * It handles basic YAML constructs including strings, booleans, and arrays.\n *\n * The parser is intentionally simple and focused on the specific needs of\n * custom commands rather than being a full YAML parser. Complex YAML features\n * like nested objects, multi-line strings, and advanced syntax are not supported.\n *\n * @param content - Raw markdown content with optional frontmatter\n * @returns Object containing parsed frontmatter and remaining content\n */\nexport function parseFrontmatter(content: string): {\n frontmatter: CustomCommandFrontmatter\n content: string\n} {\n const frontmatterRegex = /^---\\s*\\n([\\s\\S]*?)---\\s*\\n?/\n const match = content.match(frontmatterRegex)\n\n if (!match) {\n return { frontmatter: {}, content }\n }\n\n const yamlContent = match[1] || ''\n const markdownContent = content.slice(match[0].length)\n const frontmatter: CustomCommandFrontmatter = {}\n\n // Simple YAML parser for basic key-value pairs and arrays\n // This handles the subset of YAML needed for custom command configuration\n const lines = yamlContent.split('\\n')\n let currentKey: string | null = null\n let arrayItems: string[] = []\n let inArray = false\n\n for (const line of lines) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('#')) continue\n\n // Handle array item continuation (- item)\n if (inArray && trimmed.startsWith('-')) {\n const item = trimmed.slice(1).trim().replace(/['\"]/g, '')\n arrayItems.push(item)\n continue\n }\n\n // End array processing when we hit a new key\n if (inArray && trimmed.includes(':')) {\n if (currentKey) {\n ;(frontmatter as any)[currentKey] = arrayItems\n }\n inArray = false\n arrayItems = []\n currentKey = null\n }\n\n const colonIndex = trimmed.indexOf(':')\n if (colonIndex === -1) continue\n\n const key = trimmed.slice(0, colonIndex).trim()\n const value = trimmed.slice(colonIndex + 1).trim()\n\n // Handle inline arrays [item1, item2]\n if (value.startsWith('[') && value.endsWith(']')) {\n const items = value\n .slice(1, -1)\n .split(',')\n .map(s => s.trim().replace(/['\"]/g, ''))\n .filter(s => s.length > 0)\n ;(frontmatter as any)[key] = items\n }\n // Handle multi-line arrays (value is empty or [])\n else if (value === '' || value === '[]') {\n currentKey = key\n inArray = true\n arrayItems = []\n }\n // Handle boolean values\n else if (value === 'true' || value === 'false') {\n ;(frontmatter as any)[key] = value === 'true'\n }\n // Handle string values (remove quotes)\n else {\n ;(frontmatter as any)[key] = value.replace(/['\"]/g, '')\n }\n }\n\n // Handle final array if we ended in array mode\n if (inArray && currentKey) {\n ;(frontmatter as any)[currentKey] = arrayItems\n }\n\n return { frontmatter, content: markdownContent }\n}\n\n/**\n * Scan directory for markdown files using find command\n *\n * This function discovers .md files in the specified directory using the\n * system's find command. It's designed as a fallback when ripgrep is not\n * available, providing the same functionality with broader compatibility.\n *\n * The function includes timeout and signal handling for robustness,\n * especially important when scanning large directory trees.\n *\n * @param args - Legacy parameter for ripgrep compatibility (ignored)\n * @param directory - Directory to scan for markdown files\n * @param signal - AbortSignal for cancellation support\n * @returns Promise<string[]> - Array of absolute paths to .md files\n */\nasync function scanMarkdownFiles(\n args: string[], // Legacy parameter for ripgrep compatibility\n directory: string,\n signal: AbortSignal,\n): Promise<string[]> {\n try {\n // Use find command as fallback since ripgrep may not be available\n // This provides broader compatibility across different systems\n const { stdout } = await execFileAsync(\n 'find',\n [directory, '-name', '*.md', '-type', 'f'],\n { signal, timeout: 3000 },\n )\n return stdout\n .trim()\n .split('\\n')\n .filter(line => line.length > 0)\n } catch (error) {\n // If find fails or directory doesn't exist, return empty array\n // This ensures graceful degradation when directories are missing\n return []\n }\n}\n\n/**\n * Create a Command object from custom command file data\n *\n * This function transforms parsed custom command data into a Command object\n * that integrates with the main command system. It handles naming, scoping,\n * and prompt generation according to the project's command patterns.\n *\n * Command naming follows a hierarchical structure:\n * - Project commands: \"project:namespace:command\"\n * - User commands: \"user:namespace:command\"\n * - Namespace is derived from directory structure\n *\n * @param frontmatter - Parsed frontmatter configuration\n * @param content - Markdown content of the command\n * @param filePath - Absolute path to the command file\n * @param baseDir - Base directory for scope determination\n * @returns CustomCommandWithScope | null - Processed command or null if invalid\n */\nfunction createCustomCommand(\n frontmatter: CustomCommandFrontmatter,\n content: string,\n filePath: string,\n baseDir: string,\n): CustomCommandWithScope | null {\n // Extract command name with namespace support\n const relativePath = filePath.replace(baseDir + '/', '')\n const pathParts = relativePath.split('/')\n const fileName = pathParts[pathParts.length - 1].replace('.md', '')\n\n // Determine scope based on directory location\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const scope: 'user' | 'project' =\n baseDir === userMintoDir ? 'user' : 'project'\n const prefix = scope === 'user' ? 'user' : 'project'\n\n // Create proper command name with prefix and namespace\n let finalName: string\n if (frontmatter.name) {\n // If frontmatter specifies name, use it but ensure proper prefix\n finalName = frontmatter.name.startsWith(`${prefix}:`)\n ? frontmatter.name\n : `${prefix}:${frontmatter.name}`\n } else {\n // Generate name from file path, supporting directory-based namespacing\n if (pathParts.length > 1) {\n const namespace = pathParts.slice(0, -1).join(':')\n finalName = `${prefix}:${namespace}:${fileName}`\n } else {\n finalName = `${prefix}:${fileName}`\n }\n }\n\n // Extract configuration with sensible defaults\n const description = frontmatter.description || `Custom command: ${finalName}`\n const enabled = frontmatter.enabled !== false // Default to true\n const hidden = frontmatter.hidden === true // Default to false\n const aliases = frontmatter.aliases || []\n const progressMessage =\n frontmatter.progressMessage || `Running ${finalName}...`\n const argNames = frontmatter.argNames\n\n // Validate required fields\n if (!finalName) {\n console.warn(`Custom command file ${filePath} has no name, skipping`)\n return null\n }\n\n // Create the command object following the project's Command interface\n const command: CustomCommandWithScope = {\n type: 'prompt',\n name: finalName,\n description,\n isEnabled: enabled,\n isHidden: hidden,\n aliases,\n progressMessage,\n argNames,\n scope,\n userFacingName(): string {\n return finalName\n },\n async getPromptForCommand(args: string): Promise<MessageParam[]> {\n let prompt = content.trim()\n\n // Use Claude Code spec string substitution engine\n // Supports: $ARGUMENTS, $ARGUMENTS[N], $N, ${VAR}, !`command`\n prompt = await substituteVariables(prompt, args || '', {\n cwd: getCwd(),\n allowDynamicCommands: false, // Security: disable !`command` by default\n })\n\n // Legacy support for named argument placeholders\n if (argNames && argNames.length > 0) {\n const argValues = args.trim().split(/\\s+/)\n argNames.forEach((argName, index) => {\n const value = argValues[index] || ''\n prompt = prompt.replace(new RegExp(`\\\\{${argName}\\\\}`, 'g'), value)\n })\n }\n\n // If args are provided but no placeholders used, append to prompt\n if (\n args.trim() &&\n !content.includes('$ARGUMENTS') &&\n !content.includes('$0') &&\n (!argNames || argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Add tool restrictions if specified\n const allowedTools = frontmatter['allowed-tools']\n if (\n allowedTools &&\n Array.isArray(allowedTools) &&\n allowedTools.length > 0\n ) {\n const allowedToolsStr = allowedTools.join(', ')\n prompt += `\\n\\nIMPORTANT: You are restricted to using only these tools: ${allowedToolsStr}. Do not use any other tools even if they might be helpful for the task.`\n }\n\n return [\n {\n role: 'user',\n content: prompt,\n },\n ]\n },\n }\n\n return command\n}\n\n/**\n * Load custom commands from .minto/commands/ directories\n *\n * This function scans both user-level and project-level command directories\n * for markdown files and processes them into Command objects.\n *\n * Directory structure:\n * - User commands: ~/.minto/commands/\n * - Project commands: {project}/.minto/commands/\n *\n * The function is memoized for performance but includes cache invalidation\n * based on directory contents and timestamps.\n *\n * @returns Promise<CustomCommandWithScope[]> - Array of loaded and enabled commands\n */\nexport const loadCustomCommands = memoize(\n async (): Promise<CustomCommandWithScope[]> => {\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const projectMintoDir = join(getCwd(), '.minto', 'commands')\n\n // Set up abort controller for timeout handling\n const abortController = new AbortController()\n const timeout = setTimeout(() => abortController.abort(), 3000)\n\n try {\n const startTime = Date.now()\n\n // Scan directories for .md files concurrently\n const [projectMintoFiles, userMintoFiles] = await Promise.all([\n existsSync(projectMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--hidden', '--glob', '*.md'],\n projectMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(userMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--glob', '*.md'],\n userMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n ])\n\n // Combine files with priority: project > user\n const projectFiles = [...projectMintoFiles]\n const userFiles = [...userMintoFiles]\n const allFiles = [...projectFiles, ...userFiles]\n const duration = Date.now() - startTime\n\n // Log performance metrics for monitoring\n // This follows the same pattern as other performance-sensitive operations\n\n // Parse files and create command objects\n const commands: CustomCommandWithScope[] = []\n\n // Process project files first (higher priority)\n for (const filePath of projectFiles) {\n try {\n const content = readFileSync(filePath, { encoding: 'utf-8' })\n const { frontmatter, content: commandContent } =\n parseFrontmatter(content)\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n projectMintoDir,\n )\n\n if (command) {\n commands.push(command)\n }\n } catch (error) {\n console.warn(`Failed to load custom command from ${filePath}:`, error)\n }\n }\n\n // Process user files second (lower priority)\n for (const filePath of userFiles) {\n try {\n const content = readFileSync(filePath, { encoding: 'utf-8' })\n const { frontmatter, content: commandContent } =\n parseFrontmatter(content)\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n userMintoDir,\n )\n\n if (command) {\n commands.push(command)\n }\n } catch (error) {\n console.warn(`Failed to load custom command from ${filePath}:`, error)\n }\n }\n\n // Filter enabled commands and log results\n const enabledCommands = commands.filter(cmd => cmd.isEnabled)\n\n // Log loading results for debugging and monitoring\n\n return enabledCommands\n } catch (error) {\n console.warn('Failed to load custom commands:', error)\n return []\n } finally {\n clearTimeout(timeout)\n }\n },\n // Memoization resolver based on current working directory and directory state\n // This ensures cache invalidation when directories change\n () => {\n const cwd = getCwd()\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const projectMintoDir = join(cwd, '.minto', 'commands')\n\n // Create cache key that includes directory existence and timestamp\n // This provides reasonable cache invalidation without excessive file system checks\n return `${cwd}:${existsSync(userMintoDir)}:${existsSync(projectMintoDir)}:${Math.floor(Date.now() / 60000)}`\n },\n)\n\n/**\n * Clear the custom commands cache to force reload\n *\n * This function invalidates the memoized cache for custom commands,\n * forcing the next invocation to re-scan the filesystem. It's useful\n * when commands are added, removed, or modified during runtime.\n *\n * This follows the same pattern as other cache invalidation functions\n * in the project, such as getCommands.cache.clear().\n */\nexport const reloadCustomCommands = (): void => {\n loadCustomCommands.cache.clear()\n}\n\n/**\n * Get custom command directories for help and diagnostic purposes\n *\n * This function returns the standard directory paths where custom commands\n * are expected to be found. It's used by help systems and diagnostic tools\n * to inform users about the proper directory structure.\n *\n * @returns Object containing user and project command directory paths\n */\nexport function getCustomCommandDirectories(): {\n user: string\n project: string\n} {\n return {\n user: join(homedir(), '.minto', 'commands'),\n project: join(getCwd(), '.minto', 'commands'),\n }\n}\n\n/**\n * Check if custom commands are available in either directory\n *\n * This function provides a quick way to determine if custom commands\n * are configured without actually loading them. It's useful for conditional\n * UI elements and feature detection.\n *\n * @returns boolean - True if at least one command directory exists\n */\nexport function hasCustomCommands(): boolean {\n const { user, project } = getCustomCommandDirectories()\n return existsSync(user) || existsSync(project)\n}\n\n/**\n * Load commands from installed plugins\n *\n * This function integrates the plugin system with the custom commands system\n * by loading all commands from installed plugins and converting them to the\n * standard Command interface used throughout the application.\n *\n * Commands from plugins are treated similarly to custom commands but with\n * additional metadata to track their source plugin. This enables proper\n * attribution and conflict resolution.\n *\n * Command naming follows the pattern:\n * - Plugin commands: \"plugin:plugin-name:command-name\"\n * - This prevents conflicts with user/project commands\n *\n * @returns Promise<CustomCommandWithScope[]> - Array of loaded plugin commands\n */\nexport const loadPluginCommands = memoize(\n async (): Promise<CustomCommandWithScope[]> => {\n try {\n const startTime = Date.now()\n const plugins = loadAllPlugins()\n const commands: CustomCommandWithScope[] = []\n\n // Process each plugin's commands\n for (const plugin of plugins) {\n if (!plugin.enabled) continue\n\n for (const pluginCommand of plugin.commands) {\n try {\n // Skip disabled commands\n if (pluginCommand.config.enabled === false) continue\n\n // Create fully qualified command name\n const commandName = pluginCommand.config.name || pluginCommand.name\n const qualifiedName = commandName.startsWith('plugin:')\n ? commandName\n : `plugin:${plugin.manifest.name}:${commandName}`\n\n // Convert LoadedCommand to CustomCommandWithScope\n const command: CustomCommandWithScope = {\n type: 'prompt',\n name: qualifiedName,\n description:\n pluginCommand.config.description ||\n `Plugin command from ${plugin.manifest.displayName || plugin.manifest.name}`,\n isEnabled: pluginCommand.config.enabled ?? true,\n isHidden: pluginCommand.config.hidden ?? false,\n aliases: pluginCommand.config.aliases || [],\n progressMessage:\n pluginCommand.config.progressMessage ||\n `Running ${commandName}...`,\n argNames: pluginCommand.config.argNames,\n scope: 'user', // Plugin commands are treated as user-scoped\n userFacingName(): string {\n return qualifiedName\n },\n async getPromptForCommand(args: string): Promise<MessageParam[]> {\n let prompt = pluginCommand.config.content.trim()\n\n // Use Claude Code spec string substitution engine\n // Supports: $ARGUMENTS, $ARGUMENTS[N], $N, ${VAR}, !`command`\n prompt = await substituteVariables(prompt, args || '', {\n cwd: getCwd(),\n allowDynamicCommands: false, // Security: disable !`command` by default\n })\n\n // Legacy support for named argument placeholders\n if (\n pluginCommand.config.argNames &&\n pluginCommand.config.argNames.length > 0\n ) {\n const argValues = args.trim().split(/\\s+/)\n pluginCommand.config.argNames.forEach((argName, index) => {\n const value = argValues[index] || ''\n prompt = prompt.replace(\n new RegExp(`\\\\{${argName}\\\\}`, 'g'),\n value,\n )\n })\n }\n\n // If args provided but no placeholders, append to prompt\n const originalContent = pluginCommand.config.content\n if (\n args.trim() &&\n !originalContent.includes('$ARGUMENTS') &&\n !originalContent.includes('$0') &&\n (!pluginCommand.config.argNames ||\n pluginCommand.config.argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Add tool restrictions if specified\n const allowedTools = pluginCommand.config['allowed-tools']\n if (\n allowedTools &&\n Array.isArray(allowedTools) &&\n allowedTools.length > 0\n ) {\n const allowedToolsStr = allowedTools.join(', ')\n prompt += `\\n\\nIMPORTANT: You are restricted to using only these tools: ${allowedToolsStr}. Do not use any other tools even if they might be helpful for the task.`\n }\n\n // Add plugin attribution\n prompt += `\\n\\n---\\n_Command provided by plugin: ${plugin.manifest.displayName || plugin.manifest.name} (${plugin.manifest.version})_`\n\n return [\n {\n role: 'user',\n content: prompt,\n },\n ]\n },\n }\n\n commands.push(command)\n } catch (error) {\n console.warn(\n `Failed to load command ${pluginCommand.name} from plugin ${plugin.manifest.name}:`,\n error,\n )\n }\n }\n }\n\n const duration = Date.now() - startTime\n\n // Log loading results for debugging and monitoring\n\n return commands\n } catch (error) {\n console.warn('Failed to load plugin commands:', error)\n return []\n }\n },\n // Memoization resolver based on current working directory\n // This ensures cache invalidation when plugins might change\n () => {\n const cwd = getCwd()\n // Cache key includes timestamp for periodic refresh (every minute)\n return `${cwd}:${Math.floor(Date.now() / 60000)}`\n },\n)\n\n/**\n * Clear the plugin commands cache to force reload\n *\n * This function invalidates the memoized cache for plugin commands,\n * forcing the next invocation to re-scan installed plugins. It's useful\n * when plugins are installed, removed, or modified during runtime.\n */\nexport const reloadPluginCommands = (): void => {\n loadPluginCommands.cache.clear()\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,eAAe;AAGxB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAE/B;AAAA,EACE;AAAA,OAEK;AACP,SAAS,2BAA2B;AAEpC,MAAM,gBAAgB,UAAU,QAAQ;AAMxC,SAAS,qBAAqB,SAA0B;AACtD,QAAM,gBAAgB,wBAAwB;AAC9C,QAAM,eAAe,eAAe,gBAAgB,CAAC;AAGrD,QAAM,QAAQ,QAAQ,MAAM,KAAK;AACjC,QAAM,cAAc,MAAM,CAAC;AAG3B,MAAI,aAAa,SAAS,QAAQ,OAAO,GAAG,GAAG;AAC7C,WAAO;AAAA,EACT;AAGA,MAAI,aAAa,SAAS,QAAQ,WAAW,KAAK,GAAG;AACnD,WAAO;AAAA,EACT;AAGA,QAAM,eAAe,oBAAI,IAAI;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,aAAa,IAAI,WAAW,GAAG;AACjC,WAAO;AAAA,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MAC7B,CAAC,cAAc,OAAO,YACrB,cAAc,OAAO,SAAS,WAAW,IAC3C;AACA,4BAAU;AAAA;AAAA,sBAA2B,IAAI;AAAA,gBAC3C;AAGA,sBAAM,eAAe,cAAc,OAAO,eAAe;AACzD,oBACE,gBACA,MAAM,QAAQ,YAAY,KAC1B,aAAa,SAAS,GACtB;AACA,wBAAM,kBAAkB,aAAa,KAAK,IAAI;AAC9C,4BAAU;AAAA;AAAA,2DAAgE,eAAe;AAAA,gBAC3F;AAGA,0BAAU;AAAA;AAAA;AAAA,+BAAyC,OAAO,SAAS,eAAe,OAAO,SAAS,IAAI,KAAK,OAAO,SAAS,OAAO;AAElI,uBAAO;AAAA,kBACL;AAAA,oBACE,MAAM;AAAA,oBACN,SAAS;AAAA,kBACX;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAEA,qBAAS,KAAK,OAAO;AAAA,UACvB,SAAS,OAAO;AACd,oBAAQ;AAAA,cACN,0BAA0B,cAAc,IAAI,gBAAgB,OAAO,SAAS,IAAI;AAAA,cAChF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,YAAM,WAAW,KAAK,IAAI,IAAI;AAI9B,aAAO;AAAA,IACT,SAAS,OAAO;AACd,cAAQ,KAAK,mCAAmC,KAAK;AACrD,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAAA;AAAA;AAAA,EAGA,MAAM;AACJ,UAAM,MAAM,OAAO;AAEnB,WAAO,GAAG,GAAG,IAAI,KAAK,MAAM,KAAK,IAAI,IAAI,GAAK,CAAC;AAAA,EACjD;AACF;AASO,MAAM,uBAAuB,MAAY;AAC9C,qBAAmB,MAAM,MAAM;AACjC;",
|
|
4
|
+
"sourcesContent": ["import { existsSync, readFileSync } from 'fs'\nimport { join } from 'path'\nimport { homedir } from 'os'\nimport { memoize } from 'lodash-es'\nimport type { MessageParam } from '@anthropic-ai/sdk/resources/index.mjs'\nimport type { Command } from '@commands'\nimport { getCwd } from '@utils/state'\nimport { execFile } from 'child_process'\nimport { promisify } from 'util'\nimport { loadAllPlugins } from '@utils/pluginLoader'\nimport type { LoadedPlugin, LoadedCommand } from '../types/plugin'\nimport {\n getCurrentProjectConfig,\n saveCurrentProjectConfig,\n} from '@utils/config'\nimport { substituteVariables } from '@utils/stringSubstitution'\n\nconst execFileAsync = promisify(execFile)\n\n/**\n * Check if a bash command is allowed based on project config permissions\n * This integrates with the same permission system used by BashTool\n */\nfunction isBashCommandAllowed(command: string): boolean {\n const projectConfig = getCurrentProjectConfig()\n const allowedTools = projectConfig?.allowedTools || []\n\n // Check if the command or its prefix is in allowed tools\n const parts = command.split(/\\s+/)\n const baseCommand = parts[0]\n\n // Check exact match\n if (allowedTools.includes(`Bash(${command})`)) {\n return true\n }\n\n // Check base command prefix match\n if (allowedTools.includes(`Bash(${baseCommand}:*)`)) {\n return true\n }\n\n // Safe commands that don't need permission\n const safeCommands = new Set([\n 'git',\n 'ls',\n 'pwd',\n 'date',\n 'which',\n 'echo',\n 'cat',\n 'head',\n 'tail',\n 'wc',\n 'sort',\n 'uniq',\n 'grep',\n 'find',\n 'dirname',\n 'basename',\n ])\n\n if (safeCommands.has(baseCommand)) {\n return true\n }\n\n return false\n}\n\n/**\n * Check if file read is allowed based on project config permissions\n * This integrates with the same permission system used by FileReadTool\n */\nfunction isFileReadAllowed(filePath: string): boolean {\n const projectConfig = getCurrentProjectConfig()\n const allowedTools = projectConfig?.allowedTools || []\n\n // File read is generally allowed - FileReadTool doesn't require permission\n // But we log it for audit purposes\n return true\n}\n\n/**\n * Execute bash commands found in custom command content using !`command` syntax\n *\n * This function processes dynamic command execution within custom commands,\n * following the same security model as the main BashTool but with restricted scope.\n * Commands are executed in the current working directory with a timeout.\n *\n * Security: Commands are checked against the permission system before execution.\n * Only safe commands (git, ls, etc.) or explicitly allowed commands will execute.\n *\n * @param content - The custom command content to process\n * @returns Promise<string> - Content with bash commands replaced by their output\n */\nexport async function executeBashCommands(content: string): Promise<string> {\n // Match patterns like !`git status` or !`command here`\n const bashCommandRegex = /!\\`([^`]+)\\`/g\n const matches = [...content.matchAll(bashCommandRegex)]\n\n if (matches.length === 0) {\n return content\n }\n\n let result = content\n\n for (const match of matches) {\n const fullMatch = match[0]\n const command = match[1].trim()\n\n // Security check: verify command is allowed\n if (!isBashCommandAllowed(command)) {\n console.warn(\n `Custom command bash execution denied: \"${command}\" - not in allowed list`,\n )\n result = result.replace(fullMatch, `(permission denied: ${command})`)\n continue\n }\n\n try {\n // Parse command and args using simple shell parsing\n // This mirrors the approach used in the main BashTool but with stricter limits\n const parts = command.split(/\\s+/)\n const cmd = parts[0]\n const args = parts.slice(1)\n\n // Execute with conservative timeout (5s vs BashTool's 2min default)\n const { stdout, stderr } = await execFileAsync(cmd, args, {\n timeout: 5000,\n encoding: 'utf8',\n cwd: getCwd(), // Use current working directory for consistency\n })\n\n // Replace the bash command with its output, preferring stdout\n const output = stdout.trim() || stderr.trim() || '(no output)'\n result = result.replace(fullMatch, output)\n } catch (error) {\n console.warn(`Failed to execute bash command \"${command}\":`, error)\n result = result.replace(fullMatch, `(error executing: ${command})`)\n }\n }\n\n return result\n}\n\n/**\n * Resolve file references using @filepath syntax within custom commands\n *\n * This function implements file inclusion for custom commands, similar to how\n * the FileReadTool works but with inline processing. Files are read from the\n * current working directory and formatted as markdown code blocks.\n *\n * Security note: Files are read with the same permissions as the main process,\n * following the same security model as other file operations in the system.\n *\n * @param content - The custom command content to process\n * @returns Promise<string> - Content with file references replaced by file contents\n */\nexport async function resolveFileReferences(content: string): Promise<string> {\n // Match patterns like @src/file.js or @path/to/file.txt\n // Use consistent file mention pattern from mentionProcessor\n // Exclude agent and ask-model patterns to avoid conflicts\n const fileRefRegex = /@([a-zA-Z0-9/._-]+(?:\\.[a-zA-Z0-9]+)?)/g\n const matches = [...content.matchAll(fileRefRegex)]\n\n if (matches.length === 0) {\n return content\n }\n\n let result = content\n\n for (const match of matches) {\n const fullMatch = match[0]\n const filePath = match[1]\n\n // Skip agent mentions - these are handled by the mention processor\n if (filePath.startsWith('agent-')) {\n continue\n }\n\n try {\n // Resolve relative to current working directory\n // This maintains consistency with how other file operations work\n const fullPath = join(getCwd(), filePath)\n\n if (existsSync(fullPath)) {\n const fileContent = readFileSync(fullPath, { encoding: 'utf-8' })\n\n // Format file content with filename header for clarity\n // This matches the format used by FileReadTool for consistency\n const formattedContent = `\\n\\n## File: ${filePath}\\n\\`\\`\\`\\n${fileContent}\\n\\`\\`\\`\\n`\n result = result.replace(fullMatch, formattedContent)\n } else {\n result = result.replace(fullMatch, `(file not found: ${filePath})`)\n }\n } catch (error) {\n console.warn(`Failed to read file \"${filePath}\":`, error)\n result = result.replace(fullMatch, `(error reading: ${filePath})`)\n }\n }\n\n return result\n}\n\n/**\n * Validate and process allowed-tools specification from frontmatter\n *\n * This function handles tool restriction specifications in custom commands.\n * When allowed-tools is specified, it adds instructions to the prompt to\n * restrict the assistant to only using those tools.\n *\n * Note: The actual enforcement happens at the prompt level - we instruct the\n * assistant to only use specific tools. This is consistent with how Claude Code\n * handles tool restrictions in agent configurations.\n *\n * @param allowedTools - Array of tool names from frontmatter\n * @returns boolean - True if validation passes\n */\nfunction validateAllowedTools(allowedTools: string[] | undefined): boolean {\n // Validation is always true - the restriction is enforced via prompt injection\n // in getPromptForCommand() which adds the tool restriction text\n return true\n}\n\n/**\n * Frontmatter configuration for custom commands\n *\n * This interface defines the YAML frontmatter structure that can be used\n * to configure custom commands. It mirrors the Claude Desktop custom command\n * system for compatibility while adding Minto-specific enhancements.\n */\nexport interface CustomCommandFrontmatter {\n /** Display name for the command (overrides filename-based naming) */\n name?: string\n /** Brief description of what the command does */\n description?: string\n /** Alternative names that can be used to invoke this command */\n aliases?: string[]\n /** Whether this command is active and can be executed */\n enabled?: boolean\n /** Whether this command should be hidden from help output */\n hidden?: boolean\n /** Message to display while the command is running */\n progressMessage?: string\n /** Named arguments for legacy {arg} placeholder support */\n argNames?: string[]\n /** Tools that this command is restricted to use */\n 'allowed-tools'?: string[]\n}\n\n/**\n * Extended Command interface with scope information\n *\n * This extends the base Command interface to include scope metadata\n * for distinguishing between user-level and project-level commands.\n */\nexport interface CustomCommandWithScope {\n /** Command type - matches PromptCommand */\n type: 'prompt'\n /** Command name */\n name: string\n /** Command description */\n description: string\n /** Whether command is enabled */\n isEnabled: boolean\n /** Whether command is hidden */\n isHidden: boolean\n /** Command aliases */\n aliases?: string[]\n /** Progress message */\n progressMessage: string\n /** Argument names for legacy support */\n argNames?: string[]\n /** User-facing name function */\n userFacingName(): string\n /** Prompt generation function */\n getPromptForCommand(args: string): Promise<MessageParam[]>\n /** Scope indicates whether this is a user or project command */\n scope?: 'user' | 'project'\n}\n\n/**\n * Parsed custom command file representation\n *\n * This interface represents a fully parsed custom command file with\n * separated frontmatter and content sections.\n */\nexport interface CustomCommandFile {\n /** Parsed frontmatter configuration */\n frontmatter: CustomCommandFrontmatter\n /** Markdown content (without frontmatter) */\n content: string\n /** Absolute path to the source file */\n filePath: string\n}\n\n/**\n * Parse YAML frontmatter from markdown content\n *\n * This function extracts and parses YAML frontmatter from markdown files,\n * supporting the same syntax as Jekyll and other static site generators.\n * It handles basic YAML constructs including strings, booleans, and arrays.\n *\n * The parser is intentionally simple and focused on the specific needs of\n * custom commands rather than being a full YAML parser. Complex YAML features\n * like nested objects, multi-line strings, and advanced syntax are not supported.\n *\n * @param content - Raw markdown content with optional frontmatter\n * @returns Object containing parsed frontmatter and remaining content\n */\nexport function parseFrontmatter(content: string): {\n frontmatter: CustomCommandFrontmatter\n content: string\n} {\n const frontmatterRegex = /^---\\s*\\n([\\s\\S]*?)---\\s*\\n?/\n const match = content.match(frontmatterRegex)\n\n if (!match) {\n return { frontmatter: {}, content }\n }\n\n const yamlContent = match[1] || ''\n const markdownContent = content.slice(match[0].length)\n const frontmatter: CustomCommandFrontmatter = {}\n\n // Simple YAML parser for basic key-value pairs and arrays\n // This handles the subset of YAML needed for custom command configuration\n const lines = yamlContent.split('\\n')\n let currentKey: string | null = null\n let arrayItems: string[] = []\n let inArray = false\n\n for (const line of lines) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('#')) continue\n\n // Handle array item continuation (- item)\n if (inArray && trimmed.startsWith('-')) {\n const item = trimmed.slice(1).trim().replace(/['\"]/g, '')\n arrayItems.push(item)\n continue\n }\n\n // End array processing when we hit a new key\n if (inArray && trimmed.includes(':')) {\n if (currentKey) {\n ;(frontmatter as any)[currentKey] = arrayItems\n }\n inArray = false\n arrayItems = []\n currentKey = null\n }\n\n const colonIndex = trimmed.indexOf(':')\n if (colonIndex === -1) continue\n\n const key = trimmed.slice(0, colonIndex).trim()\n const value = trimmed.slice(colonIndex + 1).trim()\n\n // Handle inline arrays [item1, item2]\n if (value.startsWith('[') && value.endsWith(']')) {\n const items = value\n .slice(1, -1)\n .split(',')\n .map(s => s.trim().replace(/['\"]/g, ''))\n .filter(s => s.length > 0)\n ;(frontmatter as any)[key] = items\n }\n // Handle multi-line arrays (value is empty or [])\n else if (value === '' || value === '[]') {\n currentKey = key\n inArray = true\n arrayItems = []\n }\n // Handle boolean values\n else if (value === 'true' || value === 'false') {\n ;(frontmatter as any)[key] = value === 'true'\n }\n // Handle string values (remove quotes)\n else {\n ;(frontmatter as any)[key] = value.replace(/['\"]/g, '')\n }\n }\n\n // Handle final array if we ended in array mode\n if (inArray && currentKey) {\n ;(frontmatter as any)[currentKey] = arrayItems\n }\n\n return { frontmatter, content: markdownContent }\n}\n\n/**\n * Scan directory for markdown files using find command\n *\n * This function discovers .md files in the specified directory using the\n * system's find command. It's designed as a fallback when ripgrep is not\n * available, providing the same functionality with broader compatibility.\n *\n * The function includes timeout and signal handling for robustness,\n * especially important when scanning large directory trees.\n *\n * @param args - Legacy parameter for ripgrep compatibility (ignored)\n * @param directory - Directory to scan for markdown files\n * @param signal - AbortSignal for cancellation support\n * @returns Promise<string[]> - Array of absolute paths to .md files\n */\nasync function scanMarkdownFiles(\n args: string[], // Legacy parameter for ripgrep compatibility\n directory: string,\n signal: AbortSignal,\n): Promise<string[]> {\n try {\n // Use find command as fallback since ripgrep may not be available\n // This provides broader compatibility across different systems\n const { stdout } = await execFileAsync(\n 'find',\n [directory, '-name', '*.md', '-type', 'f'],\n { signal, timeout: 3000 },\n )\n return stdout\n .trim()\n .split('\\n')\n .filter(line => line.length > 0)\n } catch (error) {\n // If find fails or directory doesn't exist, return empty array\n // This ensures graceful degradation when directories are missing\n return []\n }\n}\n\n/**\n * Create a Command object from custom command file data\n *\n * This function transforms parsed custom command data into a Command object\n * that integrates with the main command system. It handles naming, scoping,\n * and prompt generation according to the project's command patterns.\n *\n * Command naming follows a hierarchical structure:\n * - Project commands: \"project:namespace:command\"\n * - User commands: \"user:namespace:command\"\n * - Namespace is derived from directory structure\n *\n * @param frontmatter - Parsed frontmatter configuration\n * @param content - Markdown content of the command\n * @param filePath - Absolute path to the command file\n * @param baseDir - Base directory for scope determination\n * @returns CustomCommandWithScope | null - Processed command or null if invalid\n */\nfunction createCustomCommand(\n frontmatter: CustomCommandFrontmatter,\n content: string,\n filePath: string,\n baseDir: string,\n): CustomCommandWithScope | null {\n // Extract command name with namespace support\n const relativePath = filePath.replace(baseDir + '/', '')\n const pathParts = relativePath.split('/')\n const fileName = pathParts[pathParts.length - 1].replace('.md', '')\n\n // Determine scope based on directory location\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const userClaudeDir = join(homedir(), '.claude', 'commands')\n const scope: 'user' | 'project' =\n baseDir === userMintoDir || baseDir === userClaudeDir ? 'user' : 'project'\n const prefix = scope === 'user' ? 'user' : 'project'\n\n // Create proper command name with prefix and namespace\n let finalName: string\n if (frontmatter.name) {\n // If frontmatter specifies name, use it but ensure proper prefix\n finalName = frontmatter.name.startsWith(`${prefix}:`)\n ? frontmatter.name\n : `${prefix}:${frontmatter.name}`\n } else {\n // Generate name from file path, supporting directory-based namespacing\n if (pathParts.length > 1) {\n const namespace = pathParts.slice(0, -1).join(':')\n finalName = `${prefix}:${namespace}:${fileName}`\n } else {\n finalName = `${prefix}:${fileName}`\n }\n }\n\n // Extract configuration with sensible defaults\n const description = frontmatter.description || `Custom command: ${finalName}`\n const enabled = frontmatter.enabled !== false // Default to true\n const hidden = frontmatter.hidden === true // Default to false\n const aliases = frontmatter.aliases || []\n const progressMessage =\n frontmatter.progressMessage || `Running ${finalName}...`\n const argNames = frontmatter.argNames\n\n // Validate required fields\n if (!finalName) {\n console.warn(`Custom command file ${filePath} has no name, skipping`)\n return null\n }\n\n // Create the command object following the project's Command interface\n const command: CustomCommandWithScope = {\n type: 'prompt',\n name: finalName,\n description,\n isEnabled: enabled,\n isHidden: hidden,\n aliases,\n progressMessage,\n argNames,\n scope,\n userFacingName(): string {\n return finalName\n },\n async getPromptForCommand(args: string): Promise<MessageParam[]> {\n let prompt = content.trim()\n\n // Use Claude Code spec string substitution engine\n // Supports: $ARGUMENTS, $ARGUMENTS[N], $N, ${VAR}, !`command`\n prompt = await substituteVariables(prompt, args || '', {\n cwd: getCwd(),\n allowDynamicCommands: false, // Security: disable !`command` by default\n })\n\n // Legacy support for named argument placeholders\n if (argNames && argNames.length > 0) {\n const argValues = args.trim().split(/\\s+/)\n argNames.forEach((argName, index) => {\n const value = argValues[index] || ''\n prompt = prompt.replace(new RegExp(`\\\\{${argName}\\\\}`, 'g'), value)\n })\n }\n\n // If args are provided but no placeholders used, append to prompt\n if (\n args.trim() &&\n !content.includes('$ARGUMENTS') &&\n !content.includes('$0') &&\n (!argNames || argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Add tool restrictions if specified\n const allowedTools = frontmatter['allowed-tools']\n if (\n allowedTools &&\n Array.isArray(allowedTools) &&\n allowedTools.length > 0\n ) {\n const allowedToolsStr = allowedTools.join(', ')\n prompt += `\\n\\nIMPORTANT: You are restricted to using only these tools: ${allowedToolsStr}. Do not use any other tools even if they might be helpful for the task.`\n }\n\n return [\n {\n role: 'user',\n content: prompt,\n },\n ]\n },\n }\n\n return command\n}\n\n/**\n * Load custom commands from .minto/commands/ directories\n *\n * This function scans both user-level and project-level command directories\n * for markdown files and processes them into Command objects.\n *\n * Directory structure:\n * - User commands: ~/.minto/commands/\n * - Project commands: {project}/.minto/commands/\n *\n * The function is memoized for performance but includes cache invalidation\n * based on directory contents and timestamps.\n *\n * @returns Promise<CustomCommandWithScope[]> - Array of loaded and enabled commands\n */\nexport const loadCustomCommands = memoize(\n async (): Promise<CustomCommandWithScope[]> => {\n // .claude/ dirs are legacy fallbacks, .minto/ dirs take precedence\n const userClaudeDir = join(homedir(), '.claude', 'commands')\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const projectClaudeDir = join(getCwd(), '.claude', 'commands')\n const projectMintoDir = join(getCwd(), '.minto', 'commands')\n\n // Set up abort controller for timeout handling\n const abortController = new AbortController()\n const timeout = setTimeout(() => abortController.abort(), 3000)\n\n try {\n const startTime = Date.now()\n\n // Scan directories for .md files concurrently\n const [\n projectClaudeFiles,\n projectMintoFiles,\n userClaudeFiles,\n userMintoFiles,\n ] = await Promise.all([\n existsSync(projectClaudeDir)\n ? scanMarkdownFiles(\n ['--files', '--hidden', '--glob', '*.md'],\n projectClaudeDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(projectMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--hidden', '--glob', '*.md'],\n projectMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(userClaudeDir)\n ? scanMarkdownFiles(\n ['--files', '--glob', '*.md'],\n userClaudeDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(userMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--glob', '*.md'],\n userMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n ])\n\n // Combine files with priority: project/.minto > project/.claude > user/.minto > user/.claude\n const projectFiles = [...projectClaudeFiles, ...projectMintoFiles]\n const userFiles = [...userClaudeFiles, ...userMintoFiles]\n const allFiles = [...projectFiles, ...userFiles]\n const duration = Date.now() - startTime\n\n // Log performance metrics for monitoring\n // This follows the same pattern as other performance-sensitive operations\n\n // Parse files and create command objects\n const commands: CustomCommandWithScope[] = []\n\n // Process project files first (higher priority)\n for (const filePath of projectFiles) {\n try {\n const content = readFileSync(filePath, { encoding: 'utf-8' })\n const { frontmatter, content: commandContent } =\n parseFrontmatter(content)\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n projectMintoDir,\n )\n\n if (command) {\n commands.push(command)\n }\n } catch (error) {\n console.warn(`Failed to load custom command from ${filePath}:`, error)\n }\n }\n\n // Process user files second (lower priority)\n for (const filePath of userFiles) {\n try {\n const content = readFileSync(filePath, { encoding: 'utf-8' })\n const { frontmatter, content: commandContent } =\n parseFrontmatter(content)\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n userMintoDir,\n )\n\n if (command) {\n commands.push(command)\n }\n } catch (error) {\n console.warn(`Failed to load custom command from ${filePath}:`, error)\n }\n }\n\n // Filter enabled commands and log results\n const enabledCommands = commands.filter(cmd => cmd.isEnabled)\n\n // Log loading results for debugging and monitoring\n\n return enabledCommands\n } catch (error) {\n console.warn('Failed to load custom commands:', error)\n return []\n } finally {\n clearTimeout(timeout)\n }\n },\n // Memoization resolver based on current working directory and directory state\n // This ensures cache invalidation when directories change\n () => {\n const cwd = getCwd()\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const userClaudeDir = join(homedir(), '.claude', 'commands')\n const projectMintoDir = join(cwd, '.minto', 'commands')\n const projectClaudeDir = join(cwd, '.claude', 'commands')\n\n // Create cache key that includes directory existence and timestamp\n // This provides reasonable cache invalidation without excessive file system checks\n return `${cwd}:${existsSync(userMintoDir)}:${existsSync(userClaudeDir)}:${existsSync(projectMintoDir)}:${existsSync(projectClaudeDir)}:${Math.floor(Date.now() / 60000)}`\n },\n)\n\n/**\n * Clear the custom commands cache to force reload\n *\n * This function invalidates the memoized cache for custom commands,\n * forcing the next invocation to re-scan the filesystem. It's useful\n * when commands are added, removed, or modified during runtime.\n *\n * This follows the same pattern as other cache invalidation functions\n * in the project, such as getCommands.cache.clear().\n */\nexport const reloadCustomCommands = (): void => {\n loadCustomCommands.cache.clear()\n}\n\n/**\n * Get custom command directories for help and diagnostic purposes\n *\n * This function returns the standard directory paths where custom commands\n * are expected to be found. It's used by help systems and diagnostic tools\n * to inform users about the proper directory structure.\n *\n * @returns Object containing user and project command directory paths\n */\nexport function getCustomCommandDirectories(): {\n user: string\n project: string\n userClaude: string\n projectClaude: string\n} {\n return {\n user: join(homedir(), '.minto', 'commands'),\n userClaude: join(homedir(), '.claude', 'commands'),\n project: join(getCwd(), '.minto', 'commands'),\n projectClaude: join(getCwd(), '.claude', 'commands'),\n }\n}\n\n/**\n * Check if custom commands are available in either directory\n *\n * This function provides a quick way to determine if custom commands\n * are configured without actually loading them. It's useful for conditional\n * UI elements and feature detection.\n *\n * @returns boolean - True if at least one command directory exists\n */\nexport function hasCustomCommands(): boolean {\n const { user, userClaude, project, projectClaude } =\n getCustomCommandDirectories()\n return (\n existsSync(user) ||\n existsSync(userClaude) ||\n existsSync(project) ||\n existsSync(projectClaude)\n )\n}\n\n/**\n * Load commands from installed plugins\n *\n * This function integrates the plugin system with the custom commands system\n * by loading all commands from installed plugins and converting them to the\n * standard Command interface used throughout the application.\n *\n * Commands from plugins are treated similarly to custom commands but with\n * additional metadata to track their source plugin. This enables proper\n * attribution and conflict resolution.\n *\n * Command naming follows the pattern:\n * - Plugin commands: \"plugin:plugin-name:command-name\"\n * - This prevents conflicts with user/project commands\n *\n * @returns Promise<CustomCommandWithScope[]> - Array of loaded plugin commands\n */\nexport const loadPluginCommands = memoize(\n async (): Promise<CustomCommandWithScope[]> => {\n try {\n const startTime = Date.now()\n const plugins = loadAllPlugins()\n const commands: CustomCommandWithScope[] = []\n\n // Process each plugin's commands\n for (const plugin of plugins) {\n if (!plugin.enabled) continue\n\n for (const pluginCommand of plugin.commands) {\n try {\n // Skip disabled commands\n if (pluginCommand.config.enabled === false) continue\n\n // Create fully qualified command name\n const commandName = pluginCommand.config.name || pluginCommand.name\n const qualifiedName = commandName.startsWith('plugin:')\n ? commandName\n : `plugin:${plugin.manifest.name}:${commandName}`\n\n // Convert LoadedCommand to CustomCommandWithScope\n const command: CustomCommandWithScope = {\n type: 'prompt',\n name: qualifiedName,\n description:\n pluginCommand.config.description ||\n `Plugin command from ${plugin.manifest.displayName || plugin.manifest.name}`,\n isEnabled: pluginCommand.config.enabled ?? true,\n isHidden: pluginCommand.config.hidden ?? false,\n aliases: pluginCommand.config.aliases || [],\n progressMessage:\n pluginCommand.config.progressMessage ||\n `Running ${commandName}...`,\n argNames: pluginCommand.config.argNames,\n scope: 'user', // Plugin commands are treated as user-scoped\n userFacingName(): string {\n return qualifiedName\n },\n async getPromptForCommand(args: string): Promise<MessageParam[]> {\n let prompt = pluginCommand.config.content.trim()\n\n // Use Claude Code spec string substitution engine\n // Supports: $ARGUMENTS, $ARGUMENTS[N], $N, ${VAR}, !`command`\n prompt = await substituteVariables(prompt, args || '', {\n cwd: getCwd(),\n allowDynamicCommands: false, // Security: disable !`command` by default\n })\n\n // Legacy support for named argument placeholders\n if (\n pluginCommand.config.argNames &&\n pluginCommand.config.argNames.length > 0\n ) {\n const argValues = args.trim().split(/\\s+/)\n pluginCommand.config.argNames.forEach((argName, index) => {\n const value = argValues[index] || ''\n prompt = prompt.replace(\n new RegExp(`\\\\{${argName}\\\\}`, 'g'),\n value,\n )\n })\n }\n\n // If args provided but no placeholders, append to prompt\n const originalContent = pluginCommand.config.content\n if (\n args.trim() &&\n !originalContent.includes('$ARGUMENTS') &&\n !originalContent.includes('$0') &&\n (!pluginCommand.config.argNames ||\n pluginCommand.config.argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Add tool restrictions if specified\n const allowedTools = pluginCommand.config['allowed-tools']\n if (\n allowedTools &&\n Array.isArray(allowedTools) &&\n allowedTools.length > 0\n ) {\n const allowedToolsStr = allowedTools.join(', ')\n prompt += `\\n\\nIMPORTANT: You are restricted to using only these tools: ${allowedToolsStr}. Do not use any other tools even if they might be helpful for the task.`\n }\n\n // Add plugin attribution\n prompt += `\\n\\n---\\n_Command provided by plugin: ${plugin.manifest.displayName || plugin.manifest.name} (${plugin.manifest.version})_`\n\n return [\n {\n role: 'user',\n content: prompt,\n },\n ]\n },\n }\n\n commands.push(command)\n } catch (error) {\n console.warn(\n `Failed to load command ${pluginCommand.name} from plugin ${plugin.manifest.name}:`,\n error,\n )\n }\n }\n }\n\n const duration = Date.now() - startTime\n\n // Log loading results for debugging and monitoring\n\n return commands\n } catch (error) {\n console.warn('Failed to load plugin commands:', error)\n return []\n }\n },\n // Memoization resolver based on current working directory\n // This ensures cache invalidation when plugins might change\n () => {\n const cwd = getCwd()\n // Cache key includes timestamp for periodic refresh (every minute)\n return `${cwd}:${Math.floor(Date.now() / 60000)}`\n },\n)\n\n/**\n * Clear the plugin commands cache to force reload\n *\n * This function invalidates the memoized cache for plugin commands,\n * forcing the next invocation to re-scan installed plugins. It's useful\n * when plugins are installed, removed, or modified during runtime.\n */\nexport const reloadPluginCommands = (): void => {\n loadPluginCommands.cache.clear()\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,eAAe;AAGxB,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAE/B;AAAA,EACE;AAAA,OAEK;AACP,SAAS,2BAA2B;AAEpC,MAAM,gBAAgB,UAAU,QAAQ;AAMxC,SAAS,qBAAqB,SAA0B;AACtD,QAAM,gBAAgB,wBAAwB;AAC9C,QAAM,eAAe,eAAe,gBAAgB,CAAC;AAGrD,QAAM,QAAQ,QAAQ,MAAM,KAAK;AACjC,QAAM,cAAc,MAAM,CAAC;AAG3B,MAAI,aAAa,SAAS,QAAQ,OAAO,GAAG,GAAG;AAC7C,WAAO;AAAA,EACT;AAGA,MAAI,aAAa,SAAS,QAAQ,WAAW,KAAK,GAAG;AACnD,W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