@within-7/minto 0.1.5 → 0.1.7

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.
Files changed (273) hide show
  1. package/dist/commands/agents/AgentsCommand.js +2342 -0
  2. package/dist/commands/agents/AgentsCommand.js.map +7 -0
  3. package/dist/commands/agents/constants.js +58 -0
  4. package/dist/commands/agents/constants.js.map +7 -0
  5. package/dist/commands/agents/index.js +37 -0
  6. package/dist/commands/agents/index.js.map +7 -0
  7. package/dist/commands/agents/types.js +10 -0
  8. package/dist/commands/agents/types.js.map +7 -0
  9. package/dist/commands/agents/utils/fileOperations.js +185 -0
  10. package/dist/commands/agents/utils/fileOperations.js.map +7 -0
  11. package/dist/commands/agents/utils/index.js +21 -0
  12. package/dist/commands/agents/utils/index.js.map +7 -0
  13. package/dist/commands/bug.js +2 -2
  14. package/dist/commands/bug.js.map +2 -2
  15. package/dist/commands/compact.js +5 -5
  16. package/dist/commands/compact.js.map +2 -2
  17. package/dist/commands/ctx_viz.js +55 -22
  18. package/dist/commands/ctx_viz.js.map +2 -2
  19. package/dist/commands/mcp-interactive.js +11 -11
  20. package/dist/commands/mcp-interactive.js.map +2 -2
  21. package/dist/commands/model.js +94 -32
  22. package/dist/commands/model.js.map +3 -3
  23. package/dist/commands/plugin/AddMarketplaceForm.js +49 -21
  24. package/dist/commands/plugin/AddMarketplaceForm.js.map +2 -2
  25. package/dist/commands/plugin/ConfirmDialog.js +38 -26
  26. package/dist/commands/plugin/ConfirmDialog.js.map +2 -2
  27. package/dist/commands/plugin/InstalledPluginsByMarketplace.js +24 -8
  28. package/dist/commands/plugin/InstalledPluginsByMarketplace.js.map +2 -2
  29. package/dist/commands/plugin/InstalledPluginsManager.js +3 -1
  30. package/dist/commands/plugin/InstalledPluginsManager.js.map +2 -2
  31. package/dist/commands/plugin/MainMenu.js +16 -7
  32. package/dist/commands/plugin/MainMenu.js.map +2 -2
  33. package/dist/commands/plugin/MarketplaceManager.js +84 -39
  34. package/dist/commands/plugin/MarketplaceManager.js.map +2 -2
  35. package/dist/commands/plugin/MarketplaceSelector.js +7 -3
  36. package/dist/commands/plugin/MarketplaceSelector.js.map +2 -2
  37. package/dist/commands/plugin/PlaceholderScreen.js +16 -2
  38. package/dist/commands/plugin/PlaceholderScreen.js.map +2 -2
  39. package/dist/commands/plugin/PluginBrowser.js +4 -2
  40. package/dist/commands/plugin/PluginBrowser.js.map +2 -2
  41. package/dist/commands/plugin/PluginDetailsInstall.js +12 -6
  42. package/dist/commands/plugin/PluginDetailsInstall.js.map +2 -2
  43. package/dist/commands/plugin/PluginDetailsManage.js +14 -5
  44. package/dist/commands/plugin/PluginDetailsManage.js.map +2 -2
  45. package/dist/commands/plugin/example-usage.js.map +2 -2
  46. package/dist/commands/plugin/utils.js.map +2 -2
  47. package/dist/commands/plugin.js +226 -46
  48. package/dist/commands/plugin.js.map +2 -2
  49. package/dist/commands/refreshCommands.js +6 -3
  50. package/dist/commands/refreshCommands.js.map +2 -2
  51. package/dist/commands/resume.js +2 -1
  52. package/dist/commands/resume.js.map +2 -2
  53. package/dist/commands/setup.js +19 -5
  54. package/dist/commands/setup.js.map +2 -2
  55. package/dist/commands/terminalSetup.js +2 -2
  56. package/dist/commands/terminalSetup.js.map +1 -1
  57. package/dist/commands.js +14 -30
  58. package/dist/commands.js.map +2 -2
  59. package/dist/components/AskUserQuestionDialog/AskUserQuestionDialog.js.map +2 -2
  60. package/dist/components/AskUserQuestionDialog/QuestionView.js +10 -1
  61. package/dist/components/AskUserQuestionDialog/QuestionView.js.map +2 -2
  62. package/dist/components/BackgroundTasksPanel.js +5 -1
  63. package/dist/components/BackgroundTasksPanel.js.map +2 -2
  64. package/dist/components/Config.js +17 -4
  65. package/dist/components/Config.js.map +2 -2
  66. package/dist/components/ConsoleOAuthFlow.js.map +2 -2
  67. package/dist/components/CustomSelect/select-option.js +4 -1
  68. package/dist/components/CustomSelect/select-option.js.map +2 -2
  69. package/dist/components/Help.js +6 -8
  70. package/dist/components/Help.js.map +2 -2
  71. package/dist/components/Logo.js +1 -1
  72. package/dist/components/Logo.js.map +2 -2
  73. package/dist/components/ModelListManager.js.map +2 -2
  74. package/dist/components/ModelSelector/ModelSelector.js +2030 -0
  75. package/dist/components/ModelSelector/ModelSelector.js.map +7 -0
  76. package/dist/components/ModelSelector/ScreenContainer.js +27 -0
  77. package/dist/components/ModelSelector/ScreenContainer.js.map +7 -0
  78. package/dist/components/ModelSelector/constants.js +37 -0
  79. package/dist/components/ModelSelector/constants.js.map +7 -0
  80. package/dist/components/ModelSelector/hooks/index.js +5 -0
  81. package/dist/components/ModelSelector/hooks/index.js.map +7 -0
  82. package/dist/components/ModelSelector/hooks/useEscapeNavigation.js +21 -0
  83. package/dist/components/ModelSelector/hooks/useEscapeNavigation.js.map +7 -0
  84. package/dist/components/ModelSelector/index.js +17 -0
  85. package/dist/components/ModelSelector/index.js.map +7 -0
  86. package/dist/components/ModelSelector/types.js +1 -0
  87. package/dist/components/ModelSelector/types.js.map +7 -0
  88. package/dist/components/PressEnterToContinue.js +1 -1
  89. package/dist/components/PressEnterToContinue.js.map +2 -2
  90. package/dist/components/ProjectOnboarding.js +1 -1
  91. package/dist/components/ProjectOnboarding.js.map +2 -2
  92. package/dist/components/PromptInput.js +88 -37
  93. package/dist/components/PromptInput.js.map +2 -2
  94. package/dist/components/QuitSummary.js +17 -10
  95. package/dist/components/QuitSummary.js.map +2 -2
  96. package/dist/components/SentryErrorBoundary.js.map +2 -2
  97. package/dist/components/StreamingBashOutput.js.map +2 -2
  98. package/dist/components/StructuredDiff.js.map +2 -2
  99. package/dist/components/SubagentProgress.js.map +2 -2
  100. package/dist/components/TaskCard.js.map +2 -2
  101. package/dist/components/TextInput.js.map +1 -1
  102. package/dist/components/TodoItem.js.map +1 -1
  103. package/dist/components/binary-feedback/BinaryFeedbackOption.js +1 -3
  104. package/dist/components/binary-feedback/BinaryFeedbackOption.js.map +2 -2
  105. package/dist/components/messages/AssistantLocalCommandOutputMessage.js.map +1 -1
  106. package/dist/components/messages/AssistantToolUseMessage.js +3 -1
  107. package/dist/components/messages/AssistantToolUseMessage.js.map +2 -2
  108. package/dist/components/messages/TaskProgressMessage.js.map +2 -2
  109. package/dist/components/messages/TaskToolMessage.js.map +2 -2
  110. package/dist/components/messages/UserToolResultMessage/utils.js.map +2 -2
  111. package/dist/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js.map +2 -2
  112. package/dist/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js.map +2 -2
  113. package/dist/components/permissions/hooks.js.map +2 -2
  114. package/dist/constants/modelCapabilities.js +1 -1
  115. package/dist/constants/modelCapabilities.js.map +2 -2
  116. package/dist/constants/prompts.js.map +1 -1
  117. package/dist/constants/timing.js +34 -0
  118. package/dist/constants/timing.js.map +7 -0
  119. package/dist/entrypoints/cli.js +128 -33
  120. package/dist/entrypoints/cli.js.map +3 -3
  121. package/dist/entrypoints/mcp.js +13 -18
  122. package/dist/entrypoints/mcp.js.map +2 -2
  123. package/dist/hooks/useCanUseTool.js.map +2 -2
  124. package/dist/hooks/useCancelRequest.js.map +1 -1
  125. package/dist/hooks/useHistorySearch.js.map +2 -2
  126. package/dist/hooks/useLogStartupTime.js.map +2 -2
  127. package/dist/hooks/usePermissionRequestLogging.js.map +2 -2
  128. package/dist/hooks/useTextInput.js.map +1 -1
  129. package/dist/hooks/useUnifiedCompletion.js +493 -394
  130. package/dist/hooks/useUnifiedCompletion.js.map +2 -2
  131. package/dist/index.js.map +2 -2
  132. package/dist/permissions.js +4 -7
  133. package/dist/permissions.js.map +2 -2
  134. package/dist/query.js +6 -1
  135. package/dist/query.js.map +2 -2
  136. package/dist/screens/REPL.js +72 -36
  137. package/dist/screens/REPL.js.map +2 -2
  138. package/dist/screens/ResumeConversation.js +2 -1
  139. package/dist/screens/ResumeConversation.js.map +2 -2
  140. package/dist/services/adapters/base.js.map +2 -2
  141. package/dist/services/adapters/chatCompletions.js.map +2 -2
  142. package/dist/services/adapters/responsesAPI.js +3 -1
  143. package/dist/services/adapters/responsesAPI.js.map +2 -2
  144. package/dist/services/claude.js +327 -328
  145. package/dist/services/claude.js.map +2 -2
  146. package/dist/services/customCommands.js +6 -1
  147. package/dist/services/customCommands.js.map +2 -2
  148. package/dist/services/fileFreshness.js.map +2 -2
  149. package/dist/services/gpt5ConnectionTest.js +20 -7
  150. package/dist/services/gpt5ConnectionTest.js.map +2 -2
  151. package/dist/services/hookExecutor.js +6 -12
  152. package/dist/services/hookExecutor.js.map +2 -2
  153. package/dist/services/mcpClient.js +29 -2
  154. package/dist/services/mcpClient.js.map +2 -2
  155. package/dist/services/mentionProcessor.js +23 -10
  156. package/dist/services/mentionProcessor.js.map +2 -2
  157. package/dist/services/modelAdapterFactory.js.map +2 -2
  158. package/dist/services/oauth.js.map +2 -2
  159. package/dist/services/openai.js +109 -72
  160. package/dist/services/openai.js.map +3 -3
  161. package/dist/services/responseStateManager.js.map +2 -2
  162. package/dist/services/systemReminder.js.map +2 -2
  163. package/dist/tools/ArchitectTool/ArchitectTool.js +10 -9
  164. package/dist/tools/ArchitectTool/ArchitectTool.js.map +2 -2
  165. package/dist/tools/AskExpertModelTool/AskExpertModelTool.js +14 -8
  166. package/dist/tools/AskExpertModelTool/AskExpertModelTool.js.map +2 -2
  167. package/dist/tools/AskUserQuestionTool/AskUserQuestionTool.js +8 -1
  168. package/dist/tools/AskUserQuestionTool/AskUserQuestionTool.js.map +2 -2
  169. package/dist/tools/BashOutputTool/BashOutputTool.js.map +2 -2
  170. package/dist/tools/BashTool/BashTool.js.map +2 -2
  171. package/dist/tools/FileReadTool/FileReadTool.js +23 -4
  172. package/dist/tools/FileReadTool/FileReadTool.js.map +2 -2
  173. package/dist/tools/FileWriteTool/FileWriteTool.js.map +2 -2
  174. package/dist/tools/GlobTool/GlobTool.js +11 -2
  175. package/dist/tools/GlobTool/GlobTool.js.map +2 -2
  176. package/dist/tools/GrepTool/GrepTool.js +7 -5
  177. package/dist/tools/GrepTool/GrepTool.js.map +2 -2
  178. package/dist/tools/MCPTool/MCPTool.js +11 -12
  179. package/dist/tools/MCPTool/MCPTool.js.map +2 -2
  180. package/dist/tools/MultiEditTool/MultiEditTool.js +4 -1
  181. package/dist/tools/MultiEditTool/MultiEditTool.js.map +2 -2
  182. package/dist/tools/NotebookReadTool/NotebookReadTool.js +11 -5
  183. package/dist/tools/NotebookReadTool/NotebookReadTool.js.map +2 -2
  184. package/dist/tools/SkillTool/SkillTool.js +18 -6
  185. package/dist/tools/SkillTool/SkillTool.js.map +2 -2
  186. package/dist/tools/TaskTool/TaskTool.js +37 -51
  187. package/dist/tools/TaskTool/TaskTool.js.map +2 -2
  188. package/dist/tools/TaskTool/prompt.js.map +2 -2
  189. package/dist/tools/ThinkTool/ThinkTool.js +6 -1
  190. package/dist/tools/ThinkTool/ThinkTool.js.map +2 -2
  191. package/dist/tools/TodoWriteTool/TodoWriteTool.js +29 -5
  192. package/dist/tools/TodoWriteTool/TodoWriteTool.js.map +2 -2
  193. package/dist/tools/URLFetcherTool/URLFetcherTool.js +5 -2
  194. package/dist/tools/URLFetcherTool/URLFetcherTool.js.map +2 -2
  195. package/dist/tools/URLFetcherTool/cache.js +6 -3
  196. package/dist/tools/URLFetcherTool/cache.js.map +2 -2
  197. package/dist/tools/URLFetcherTool/htmlToMarkdown.js +3 -1
  198. package/dist/tools/URLFetcherTool/htmlToMarkdown.js.map +2 -2
  199. package/dist/tools/WebSearchTool/WebSearchTool.js +6 -1
  200. package/dist/tools/WebSearchTool/WebSearchTool.js.map +2 -2
  201. package/dist/tools/WebSearchTool/prompt.js.map +2 -2
  202. package/dist/tools/WebSearchTool/searchProviders.js +15 -6
  203. package/dist/tools/WebSearchTool/searchProviders.js.map +2 -2
  204. package/dist/tools.js +4 -1
  205. package/dist/tools.js.map +2 -2
  206. package/dist/types/core.js +1 -0
  207. package/dist/types/core.js.map +7 -0
  208. package/dist/types/hooks.js +1 -4
  209. package/dist/types/hooks.js.map +2 -2
  210. package/dist/types/marketplace.js +8 -2
  211. package/dist/types/marketplace.js.map +2 -2
  212. package/dist/types/plugin.js +9 -6
  213. package/dist/types/plugin.js.map +2 -2
  214. package/dist/utils/BackgroundShellManager.js +76 -10
  215. package/dist/utils/BackgroundShellManager.js.map +2 -2
  216. package/dist/utils/PersistentShell.js +7 -2
  217. package/dist/utils/PersistentShell.js.map +2 -2
  218. package/dist/utils/advancedFuzzyMatcher.js +4 -1
  219. package/dist/utils/advancedFuzzyMatcher.js.map +2 -2
  220. package/dist/utils/agentLoader.js +69 -35
  221. package/dist/utils/agentLoader.js.map +2 -2
  222. package/dist/utils/agentStorage.js.map +2 -2
  223. package/dist/utils/async.js +163 -0
  224. package/dist/utils/async.js.map +7 -0
  225. package/dist/utils/autoUpdater.js +8 -2
  226. package/dist/utils/autoUpdater.js.map +2 -2
  227. package/dist/utils/commands.js +23 -11
  228. package/dist/utils/commands.js.map +2 -2
  229. package/dist/utils/commonUnixCommands.js +3 -1
  230. package/dist/utils/commonUnixCommands.js.map +2 -2
  231. package/dist/utils/compressionMode.js.map +2 -2
  232. package/dist/utils/config.js +30 -14
  233. package/dist/utils/config.js.map +2 -2
  234. package/dist/utils/debugLogger.js.map +2 -2
  235. package/dist/utils/env.js.map +2 -2
  236. package/dist/utils/envConfig.js +82 -0
  237. package/dist/utils/envConfig.js.map +7 -0
  238. package/dist/utils/errorHandling.js +89 -0
  239. package/dist/utils/errorHandling.js.map +7 -0
  240. package/dist/utils/expertChatStorage.js.map +2 -2
  241. package/dist/utils/fuzzyMatcher.js +13 -7
  242. package/dist/utils/fuzzyMatcher.js.map +2 -2
  243. package/dist/utils/hookManager.js +14 -4
  244. package/dist/utils/hookManager.js.map +2 -2
  245. package/dist/utils/log.js.map +2 -2
  246. package/dist/utils/marketplaceManager.js +44 -9
  247. package/dist/utils/marketplaceManager.js.map +2 -2
  248. package/dist/utils/messageContextManager.js.map +1 -1
  249. package/dist/utils/messages.js +6 -3
  250. package/dist/utils/messages.js.map +2 -2
  251. package/dist/utils/model.js +3 -1
  252. package/dist/utils/model.js.map +2 -2
  253. package/dist/utils/pluginInstaller.js +3 -15
  254. package/dist/utils/pluginInstaller.js.map +2 -2
  255. package/dist/utils/pluginLoader.js +41 -13
  256. package/dist/utils/pluginLoader.js.map +2 -2
  257. package/dist/utils/pluginRegistry.js.map +2 -2
  258. package/dist/utils/pluginValidator.js +71 -49
  259. package/dist/utils/pluginValidator.js.map +2 -2
  260. package/dist/utils/ptyCompat.js.map +2 -2
  261. package/dist/utils/roundConverter.js.map +2 -2
  262. package/dist/utils/secureFile.js +43 -14
  263. package/dist/utils/secureFile.js.map +2 -2
  264. package/dist/utils/sessionState.js.map +2 -2
  265. package/dist/utils/skillLoader.js.map +2 -2
  266. package/dist/utils/teamConfig.js +7 -4
  267. package/dist/utils/teamConfig.js.map +2 -2
  268. package/dist/utils/theme.js.map +2 -2
  269. package/dist/utils/thinking.js.map +2 -2
  270. package/dist/utils/unaryLogging.js.map +2 -2
  271. package/dist/version.js +2 -2
  272. package/dist/version.js.map +1 -1
  273. package/package.json +5 -5
@@ -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'\n\nconst execFileAsync = promisify(execFile)\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 * @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 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 * Currently it provides logging and validation structure - full enforcement\n * would require deep integration with the tool permission system.\n *\n * Future implementation should connect to src/permissions.ts and the\n * tool execution pipeline to enforce these restrictions.\n *\n * @param allowedTools - Array of tool names from frontmatter\n * @returns boolean - Currently always true, future will return actual validation result\n */\nfunction validateAllowedTools(allowedTools: string[] | undefined): boolean {\n // Log allowed tools for debugging and future integration\n if (allowedTools && allowedTools.length > 0) {\n // TODO: Integrate with src/permissions.ts tool permission system\n // TODO: Connect to Tool.tsx needsPermissions() mechanism\n }\n return true // Allow execution for now - future versions will enforce restrictions\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 // This follows the same pattern as Claude Desktop's command system\n const userClaudeDir = join(homedir(), '.claude', 'commands')\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const scope: 'user' | 'project' =\n (baseDir === userClaudeDir || 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 // Process argument substitution following legacy conventions\n // This supports both the official $ARGUMENTS format and legacy {arg} format\n\n // Step 1: Handle $ARGUMENTS placeholder (legacy command format)\n if (prompt.includes('$ARGUMENTS')) {\n prompt = prompt.replace(/\\$ARGUMENTS/g, args || '')\n }\n\n // Step 2: 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 // Step 3: If args are provided but no placeholders used, append to prompt\n if (\n args.trim() &&\n !prompt.includes('$ARGUMENTS') &&\n (!argNames || argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Step 4: 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 .claude/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. It follows the\n * same discovery pattern as Claude Desktop but with additional performance\n * optimizations and error handling.\n *\n * Directory structure:\n * - User commands: ~/.claude/commands/\n * - Project commands: {project}/.claude/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 // Support both .claude and .minto directories\n const userClaudeDir = join(homedir(), '.claude', 'commands')\n const projectClaudeDir = join(getCwd(), '.claude', 'commands')\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 all four directories for .md files concurrently\n // This pattern matches the async loading used elsewhere in the project\n const [projectClaudeFiles, userClaudeFiles, projectMintoFiles, userMintoFiles] = await Promise.all([\n existsSync(projectClaudeDir)\n ? scanMarkdownFiles(\n ['--files', '--hidden', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n projectClaudeDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(userClaudeDir)\n ? scanMarkdownFiles(\n ['--files', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n userClaudeDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(projectMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--hidden', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n projectMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(userMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n userMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n ])\n\n // Combine files with priority: project > user, minto > claude\n const projectFiles = [...projectMintoFiles, ...projectClaudeFiles]\n const userFiles = [...userMintoFiles, ...userClaudeFiles]\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\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 // Determine which base directory this file is from\n const baseDir = filePath.includes('.minto/commands') ? projectMintoDir : projectClaudeDir\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n baseDir,\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 // Determine which base directory this file is from\n const baseDir = filePath.includes('.minto/commands') ? userMintoDir : userClaudeDir\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n baseDir,\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\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 userClaudeDir = join(homedir(), '.claude', 'commands')\n const projectClaudeDir = join(cwd, '.claude', 'commands')\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(userClaudeDir)}:${existsSync(projectClaudeDir)}:${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 userClaude: string\n projectClaude: string\n userMinto: string\n projectMinto: string\n} {\n return {\n userClaude: join(homedir(), '.claude', 'commands'),\n projectClaude: join(getCwd(), '.claude', 'commands'),\n userMinto: join(homedir(), '.minto', 'commands'),\n projectMinto: 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 { userClaude, projectClaude, userMinto, projectMinto } = getCustomCommandDirectories()\n return existsSync(userClaude) || existsSync(projectClaude) || existsSync(userMinto) || existsSync(projectMinto)\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 // Process argument substitution following same conventions as custom commands\n\n // Step 1: Handle $ARGUMENTS placeholder\n if (prompt.includes('$ARGUMENTS')) {\n prompt = prompt.replace(/\\$ARGUMENTS/g, args || '')\n }\n\n // Step 2: 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 // Step 3: If args provided but no placeholders, append to prompt\n if (\n args.trim() &&\n !prompt.includes('$ARGUMENTS') &&\n (!pluginCommand.config.argNames ||\n pluginCommand.config.argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Step 4: 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 // Step 5: 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\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;AAG/B,MAAM,gBAAgB,UAAU,QAAQ;AAYxC,eAAsB,oBAAoB,SAAkC;AAE1E,QAAM,mBAAmB;AACzB,QAAM,UAAU,CAAC,GAAG,QAAQ,SAAS,gBAAgB,CAAC;AAEtD,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;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A,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'\n\nconst execFileAsync = promisify(execFile)\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 * @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 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 * Currently it provides logging and validation structure - full enforcement\n * would require deep integration with the tool permission system.\n *\n * Future implementation should connect to src/permissions.ts and the\n * tool execution pipeline to enforce these restrictions.\n *\n * @param allowedTools - Array of tool names from frontmatter\n * @returns boolean - Currently always true, future will return actual validation result\n */\nfunction validateAllowedTools(allowedTools: string[] | undefined): boolean {\n // Log allowed tools for debugging and future integration\n if (allowedTools && allowedTools.length > 0) {\n // TODO: Integrate with src/permissions.ts tool permission system\n // TODO: Connect to Tool.tsx needsPermissions() mechanism\n }\n return true // Allow execution for now - future versions will enforce restrictions\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 // This follows the same pattern as Claude Desktop's command system\n const userClaudeDir = join(homedir(), '.claude', 'commands')\n const userMintoDir = join(homedir(), '.minto', 'commands')\n const scope: 'user' | 'project' =\n baseDir === userClaudeDir || 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 // Process argument substitution following legacy conventions\n // This supports both the official $ARGUMENTS format and legacy {arg} format\n\n // Step 1: Handle $ARGUMENTS placeholder (legacy command format)\n if (prompt.includes('$ARGUMENTS')) {\n prompt = prompt.replace(/\\$ARGUMENTS/g, args || '')\n }\n\n // Step 2: 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 // Step 3: If args are provided but no placeholders used, append to prompt\n if (\n args.trim() &&\n !prompt.includes('$ARGUMENTS') &&\n (!argNames || argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Step 4: 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 .claude/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. It follows the\n * same discovery pattern as Claude Desktop but with additional performance\n * optimizations and error handling.\n *\n * Directory structure:\n * - User commands: ~/.claude/commands/\n * - Project commands: {project}/.claude/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 // Support both .claude and .minto directories\n const userClaudeDir = join(homedir(), '.claude', 'commands')\n const projectClaudeDir = join(getCwd(), '.claude', 'commands')\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 all four directories for .md files concurrently\n // This pattern matches the async loading used elsewhere in the project\n const [\n projectClaudeFiles,\n userClaudeFiles,\n projectMintoFiles,\n userMintoFiles,\n ] = await Promise.all([\n existsSync(projectClaudeDir)\n ? scanMarkdownFiles(\n ['--files', '--hidden', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n projectClaudeDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(userClaudeDir)\n ? scanMarkdownFiles(\n ['--files', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n userClaudeDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(projectMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--hidden', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n projectMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n existsSync(userMintoDir)\n ? scanMarkdownFiles(\n ['--files', '--glob', '*.md'], // Legacy args for ripgrep compatibility\n userMintoDir,\n abortController.signal,\n )\n : Promise.resolve([]),\n ])\n\n // Combine files with priority: project > user, minto > claude\n const projectFiles = [...projectMintoFiles, ...projectClaudeFiles]\n const userFiles = [...userMintoFiles, ...userClaudeFiles]\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 // Determine which base directory this file is from\n const baseDir = filePath.includes('.minto/commands')\n ? projectMintoDir\n : projectClaudeDir\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n baseDir,\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 // Determine which base directory this file is from\n const baseDir = filePath.includes('.minto/commands')\n ? userMintoDir\n : userClaudeDir\n const command = createCustomCommand(\n frontmatter,\n commandContent,\n filePath,\n baseDir,\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 userClaudeDir = join(homedir(), '.claude', 'commands')\n const projectClaudeDir = join(cwd, '.claude', 'commands')\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(userClaudeDir)}:${existsSync(projectClaudeDir)}:${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 userClaude: string\n projectClaude: string\n userMinto: string\n projectMinto: string\n} {\n return {\n userClaude: join(homedir(), '.claude', 'commands'),\n projectClaude: join(getCwd(), '.claude', 'commands'),\n userMinto: join(homedir(), '.minto', 'commands'),\n projectMinto: 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 { userClaude, projectClaude, userMinto, projectMinto } =\n getCustomCommandDirectories()\n return (\n existsSync(userClaude) ||\n existsSync(projectClaude) ||\n existsSync(userMinto) ||\n existsSync(projectMinto)\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 // Process argument substitution following same conventions as custom commands\n\n // Step 1: Handle $ARGUMENTS placeholder\n if (prompt.includes('$ARGUMENTS')) {\n prompt = prompt.replace(/\\$ARGUMENTS/g, args || '')\n }\n\n // Step 2: 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 // Step 3: If args provided but no placeholders, append to prompt\n if (\n args.trim() &&\n !prompt.includes('$ARGUMENTS') &&\n (!pluginCommand.config.argNames ||\n pluginCommand.config.argNames.length === 0)\n ) {\n prompt += `\\n\\nAdditional context: ${args}`\n }\n\n // Step 4: 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 // Step 5: 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;AAG/B,MAAM,gBAAgB,UAAU,QAAQ;AAYxC,eAAsB,oBAAoB,SAAkC;AAE1E,QAAM,mBAAmB;AACzB,QAAM,UAAU,CAAC,GAAG,QAAQ,SAAS,gBAAgB,CAAC;AAEtD,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AAEb,aAAW,SAAS,SAAS;AAC3B,UAAM,YAAY,MAAM,CAAC;AACzB,UAAM,UAAU,MAAM,CAAC,EAAE,KAAK;AAE9B,QAAI;AAGF,YAAM,QAAQ,QAAQ,MAAM,KAAK;AACjC,YAAM,MAAM,MAAM,CAAC;AACnB,YAAM,OAAO,MAAM,MAAM,CAAC;AAG1B,YAAM,EAAE,QAAQ,OAAO,IAAI,MAAM,cAAc,KAAK,MAAM;AAAA,QACxD,SAAS;AAAA,QACT,UAAU;AAAA,QACV,KAAK,OAAO;AAAA;AAAA,MACd,CAAC;AAGD,YAAM,SAAS,OAAO,KAAK,KAAK,OAAO,KAAK,KAAK;AACjD,eAAS,OAAO,QAAQ,WAAW,MAAM;AAAA,IAC3C,SAAS,OAAO;AACd,cAAQ,KA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AGA,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;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/fileFreshness.ts"],
4
- "sourcesContent": ["import { statSync, existsSync, watchFile, unwatchFile } from 'fs'\nimport {\n emitReminderEvent,\n systemReminderService,\n} from '@services/systemReminder'\nimport { getAgentFilePath } from '@utils/agentStorage'\n\ninterface FileTimestamp {\n path: string\n lastRead: number\n lastModified: number\n size: number\n lastAgentEdit?: number // Track when Agent last edited this file\n}\n\ninterface FileFreshnessState {\n readTimestamps: Map<string, FileTimestamp>\n editConflicts: Set<string>\n sessionFiles: Set<string>\n watchedTodoFiles: Map<string, string> // agentId -> filePath\n}\n\nclass FileFreshnessService {\n private state: FileFreshnessState = {\n readTimestamps: new Map(),\n editConflicts: new Set(),\n sessionFiles: new Set(),\n watchedTodoFiles: new Map(),\n }\n\n constructor() {\n this.setupEventListeners()\n }\n\n /**\n * Setup event listeners for session management\n */\n private setupEventListeners(): void {\n // Listen for session startup events through the SystemReminderService\n systemReminderService.addEventListener(\n 'session:startup',\n (context: any) => {\n // Reset session state on startup\n this.resetSession()\n\n \n },\n )\n }\n\n /**\n * Record file read operation with timestamp tracking\n */\n public recordFileRead(filePath: string): void {\n try {\n if (!existsSync(filePath)) {\n return\n }\n\n const stats = statSync(filePath)\n const timestamp: FileTimestamp = {\n path: filePath,\n lastRead: Date.now(),\n lastModified: stats.mtimeMs,\n size: stats.size,\n }\n\n this.state.readTimestamps.set(filePath, timestamp)\n this.state.sessionFiles.add(filePath)\n\n // Emit file read event for system reminders\n emitReminderEvent('file:read', {\n filePath,\n timestamp: timestamp.lastRead,\n size: timestamp.size,\n modified: timestamp.lastModified,\n })\n } catch (error) {\n console.error(`Error recording file read for ${filePath}:`, error)\n }\n }\n\n /**\n * Check if file has been modified since last read\n */\n public checkFileFreshness(filePath: string): {\n isFresh: boolean\n lastRead?: number\n currentModified?: number\n conflict: boolean\n } {\n const recorded = this.state.readTimestamps.get(filePath)\n\n if (!recorded) {\n return { isFresh: true, conflict: false }\n }\n\n try {\n if (!existsSync(filePath)) {\n return { isFresh: false, conflict: true }\n }\n\n const currentStats = statSync(filePath)\n const isFresh = currentStats.mtimeMs <= recorded.lastModified\n const conflict = !isFresh\n\n if (conflict) {\n this.state.editConflicts.add(filePath)\n\n // Emit file conflict event\n emitReminderEvent('file:conflict', {\n filePath,\n lastRead: recorded.lastRead,\n lastModified: recorded.lastModified,\n currentModified: currentStats.mtimeMs,\n sizeDiff: currentStats.size - recorded.size,\n })\n }\n\n return {\n isFresh,\n lastRead: recorded.lastRead,\n currentModified: currentStats.mtimeMs,\n conflict,\n }\n } catch (error) {\n console.error(`Error checking freshness for ${filePath}:`, error)\n return { isFresh: false, conflict: true }\n }\n }\n\n /**\n * Record file edit operation by Agent\n */\n public recordFileEdit(filePath: string, content?: string): void {\n try {\n const now = Date.now()\n\n // Update recorded timestamp after edit\n if (existsSync(filePath)) {\n const stats = statSync(filePath)\n const existing = this.state.readTimestamps.get(filePath)\n\n if (existing) {\n existing.lastModified = stats.mtimeMs\n existing.size = stats.size\n existing.lastAgentEdit = now // Mark this as Agent-initiated edit\n this.state.readTimestamps.set(filePath, existing)\n } else {\n // Create new record for Agent-edited file\n const timestamp: FileTimestamp = {\n path: filePath,\n lastRead: now,\n lastModified: stats.mtimeMs,\n size: stats.size,\n lastAgentEdit: now,\n }\n this.state.readTimestamps.set(filePath, timestamp)\n }\n }\n\n // Remove from conflicts since we just edited it\n this.state.editConflicts.delete(filePath)\n\n // Emit file edit event\n emitReminderEvent('file:edited', {\n filePath,\n timestamp: now,\n contentLength: content?.length || 0,\n source: 'agent',\n })\n } catch (error) {\n console.error(`Error recording file edit for ${filePath}:`, error)\n }\n }\n\n public generateFileModificationReminder(filePath: string): string | null {\n const recorded = this.state.readTimestamps.get(filePath)\n\n if (!recorded) {\n return null\n }\n\n try {\n if (!existsSync(filePath)) {\n return `Note: ${filePath} was deleted since last read.`\n }\n\n const currentStats = statSync(filePath)\n const isModified = currentStats.mtimeMs > recorded.lastModified\n\n if (!isModified) {\n return null\n }\n\n // Check if this was an Agent-initiated change\n // Use small time tolerance to handle filesystem timestamp precision issues\n const TIME_TOLERANCE_MS = 100\n if (\n recorded.lastAgentEdit &&\n recorded.lastAgentEdit >= recorded.lastModified - TIME_TOLERANCE_MS\n ) {\n // Agent modified this file recently, no reminder needed\n // (context already contains before/after content)\n return null\n }\n\n // External modification detected - generate reminder\n return `Note: ${filePath} was modified externally since last read. The file may have changed outside of this session.`\n } catch (error) {\n console.error(`Error checking modification for ${filePath}:`, error)\n return null\n }\n }\n\n public getConflictedFiles(): string[] {\n return Array.from(this.state.editConflicts)\n }\n\n public getSessionFiles(): string[] {\n return Array.from(this.state.sessionFiles)\n }\n\n public resetSession(): void {\n // Clean up existing todo file watchers\n this.state.watchedTodoFiles.forEach(filePath => {\n try {\n unwatchFile(filePath)\n } catch (error) {\n console.error(`Error unwatching file ${filePath}:`, error)\n }\n })\n\n this.state = {\n readTimestamps: new Map(),\n editConflicts: new Set(),\n sessionFiles: new Set(),\n watchedTodoFiles: new Map(),\n }\n }\n\n /**\n * Start watching todo file for an agent\n */\n public startWatchingTodoFile(agentId: string): void {\n try {\n const filePath = getAgentFilePath(agentId)\n\n // Don't watch if already watching\n if (this.state.watchedTodoFiles.has(agentId)) {\n return\n }\n\n this.state.watchedTodoFiles.set(agentId, filePath)\n\n // Record initial state if file exists\n if (existsSync(filePath)) {\n this.recordFileRead(filePath)\n }\n\n // Start watching for changes\n watchFile(filePath, { interval: 1000 }, (curr, prev) => {\n // Check if this was an external modification\n const reminder = this.generateFileModificationReminder(filePath)\n if (reminder) {\n // File was modified externally, emit todo change reminder\n emitReminderEvent('todo:file_changed', {\n agentId,\n filePath,\n reminder,\n timestamp: Date.now(),\n currentStats: { mtime: curr.mtime, size: curr.size },\n previousStats: { mtime: prev.mtime, size: prev.size },\n })\n }\n })\n } catch (error) {\n console.error(\n `Error starting todo file watch for agent ${agentId}:`,\n error,\n )\n }\n }\n\n /**\n * Stop watching todo file for an agent\n */\n public stopWatchingTodoFile(agentId: string): void {\n try {\n const filePath = this.state.watchedTodoFiles.get(agentId)\n if (filePath) {\n unwatchFile(filePath)\n this.state.watchedTodoFiles.delete(agentId)\n }\n } catch (error) {\n console.error(\n `Error stopping todo file watch for agent ${agentId}:`,\n error,\n )\n }\n }\n\n public getFileInfo(filePath: string): FileTimestamp | null {\n return this.state.readTimestamps.get(filePath) || null\n }\n\n public isFileTracked(filePath: string): boolean {\n return this.state.readTimestamps.has(filePath)\n }\n\n /**\n * Retrieves files prioritized for recovery during conversation compression\n *\n * Selects recently accessed files based on:\n * - File access recency (most recent first)\n * - File type relevance (excludes dependencies, build artifacts)\n * - Development workflow importance\n *\n * Used to maintain coding context when conversation history is compressed\n */\n public getImportantFiles(maxFiles: number = 5): Array<{\n path: string\n timestamp: number\n size: number\n }> {\n return Array.from(this.state.readTimestamps.entries())\n .map(([path, info]) => ({\n path,\n timestamp: info.lastRead,\n size: info.size,\n }))\n .filter(file => this.isValidForRecovery(file.path))\n .sort((a, b) => b.timestamp - a.timestamp) // Newest first\n .slice(0, maxFiles)\n }\n\n /**\n * Determines which files are suitable for automatic recovery\n *\n * Excludes files that are typically not relevant for development context:\n * - Build artifacts and generated files\n * - Dependencies and cached files\n * - Temporary files and system directories\n */\n private isValidForRecovery(filePath: string): boolean {\n return (\n !filePath.includes('node_modules') &&\n !filePath.includes('.git') &&\n !filePath.startsWith('/tmp') &&\n !filePath.includes('.cache') &&\n !filePath.includes('dist/') &&\n !filePath.includes('build/')\n )\n }\n}\n\nexport const fileFreshnessService = new FileFreshnessService()\n\nexport const recordFileRead = (filePath: string) =>\n fileFreshnessService.recordFileRead(filePath)\nexport const recordFileEdit = (filePath: string, content?: string) =>\n fileFreshnessService.recordFileEdit(filePath, content)\nexport const checkFileFreshness = (filePath: string) =>\n fileFreshnessService.checkFileFreshness(filePath)\nexport const generateFileModificationReminder = (filePath: string) =>\n fileFreshnessService.generateFileModificationReminder(filePath)\nexport const resetFileFreshnessSession = () =>\n fileFreshnessService.resetSession()\nexport const startWatchingTodoFile = (agentId: string) =>\n fileFreshnessService.startWatchingTodoFile(agentId)\nexport const stopWatchingTodoFile = (agentId: string) =>\n fileFreshnessService.stopWatchingTodoFile(agentId)\n"],
5
- "mappings": "AAAA,SAAS,UAAU,YAAY,WAAW,mBAAmB;AAC7D;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AAiBjC,MAAM,q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,EAYO,kBAAkB,WAAmB,GAIzC;AACD,WAAO,MAAM,KAAK,KAAK,MAAM,eAAe,QAAQ,CAAC,EAClD,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO;AAAA,MACtB;AAAA,MACA,WAAW,KAAK;AAAA,MAChB,MAAM,KAAK;AAAA,IACb,EAAE,EACD,OAAO,UAAQ,KAAK,mBAAmB,KAAK,IAAI,CAAC,EACjD,KAAK,CAAC,GAAG,MAAM,EAAE,YAAY,EAAE,SAAS,EACxC,MAAM,GAAG,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,mBAAmB,UAA2B;AACpD,WACE,CAAC,SAAS,SAAS,cAAc,KACjC,CAAC,SAAS,SAAS,MAAM,KACzB,CAAC,SAAS,WAAW,MAAM,KAC3B,CAAC,SAAS,SAAS,QAAQ,KAC3B,CAAC,SAAS,SAAS,OAAO,KAC1B,CAAC,SAAS,SAAS,QAAQ;AAAA,EAE/B;AACF;AAEO,MAAM,uBAAuB,IAAI,qBAAqB;AAEtD,MAAM,iBAAiB,CAAC,aAC7B,qBAAqB,eAAe,QAAQ;AACvC,MAAM,iBAAiB,CAAC,UAAkB,YAC/C,qBAAqB,eAAe,UAAU,OAAO;AAChD,MAAM,qBAAqB,CAAC,aACjC,qBAAqB,mBAAmB,QAAQ;AAC3C,MAAM,mCAAmC,CAAC,aAC/C,qBAAqB,iCAAiC,QAAQ;AACzD,MAAM,4BAA4B,MACvC,qBAAqB,aAAa;AAC7B,MAAM,wBAAwB,CAAC,YACpC,qBAAqB,sBAAsB,OAAO;AAC7C,MAAM,uBAAuB,CAAC,YACnC,qBAAqB,qBAAqB,OAAO;",
4
+ "sourcesContent": ["import { statSync, existsSync, watchFile, unwatchFile } from 'fs'\nimport {\n emitReminderEvent,\n systemReminderService,\n} from '@services/systemReminder'\nimport { getAgentFilePath } from '@utils/agentStorage'\n\ninterface FileTimestamp {\n path: string\n lastRead: number\n lastModified: number\n size: number\n lastAgentEdit?: number // Track when Agent last edited this file\n}\n\ninterface FileFreshnessState {\n readTimestamps: Map<string, FileTimestamp>\n editConflicts: Set<string>\n sessionFiles: Set<string>\n watchedTodoFiles: Map<string, string> // agentId -> filePath\n}\n\nclass FileFreshnessService {\n private state: FileFreshnessState = {\n readTimestamps: new Map(),\n editConflicts: new Set(),\n sessionFiles: new Set(),\n watchedTodoFiles: new Map(),\n }\n\n constructor() {\n this.setupEventListeners()\n }\n\n /**\n * Setup event listeners for session management\n */\n private setupEventListeners(): void {\n // Listen for session startup events through the SystemReminderService\n systemReminderService.addEventListener(\n 'session:startup',\n (context: any) => {\n // Reset session state on startup\n this.resetSession()\n },\n )\n }\n\n /**\n * Record file read operation with timestamp tracking\n */\n public recordFileRead(filePath: string): void {\n try {\n if (!existsSync(filePath)) {\n return\n }\n\n const stats = statSync(filePath)\n const timestamp: FileTimestamp = {\n path: filePath,\n lastRead: Date.now(),\n lastModified: stats.mtimeMs,\n size: stats.size,\n }\n\n this.state.readTimestamps.set(filePath, timestamp)\n this.state.sessionFiles.add(filePath)\n\n // Emit file read event for system reminders\n emitReminderEvent('file:read', {\n filePath,\n timestamp: timestamp.lastRead,\n size: timestamp.size,\n modified: timestamp.lastModified,\n })\n } catch (error) {\n console.error(`Error recording file read for ${filePath}:`, error)\n }\n }\n\n /**\n * Check if file has been modified since last read\n */\n public checkFileFreshness(filePath: string): {\n isFresh: boolean\n lastRead?: number\n currentModified?: number\n conflict: boolean\n } {\n const recorded = this.state.readTimestamps.get(filePath)\n\n if (!recorded) {\n return { isFresh: true, conflict: false }\n }\n\n try {\n if (!existsSync(filePath)) {\n return { isFresh: false, conflict: true }\n }\n\n const currentStats = statSync(filePath)\n const isFresh = currentStats.mtimeMs <= recorded.lastModified\n const conflict = !isFresh\n\n if (conflict) {\n this.state.editConflicts.add(filePath)\n\n // Emit file conflict event\n emitReminderEvent('file:conflict', {\n filePath,\n lastRead: recorded.lastRead,\n lastModified: recorded.lastModified,\n currentModified: currentStats.mtimeMs,\n sizeDiff: currentStats.size - recorded.size,\n })\n }\n\n return {\n isFresh,\n lastRead: recorded.lastRead,\n currentModified: currentStats.mtimeMs,\n conflict,\n }\n } catch (error) {\n console.error(`Error checking freshness for ${filePath}:`, error)\n return { isFresh: false, conflict: true }\n }\n }\n\n /**\n * Record file edit operation by Agent\n */\n public recordFileEdit(filePath: string, content?: string): void {\n try {\n const now = Date.now()\n\n // Update recorded timestamp after edit\n if (existsSync(filePath)) {\n const stats = statSync(filePath)\n const existing = this.state.readTimestamps.get(filePath)\n\n if (existing) {\n existing.lastModified = stats.mtimeMs\n existing.size = stats.size\n existing.lastAgentEdit = now // Mark this as Agent-initiated edit\n this.state.readTimestamps.set(filePath, existing)\n } else {\n // Create new record for Agent-edited file\n const timestamp: FileTimestamp = {\n path: filePath,\n lastRead: now,\n lastModified: stats.mtimeMs,\n size: stats.size,\n lastAgentEdit: now,\n }\n this.state.readTimestamps.set(filePath, timestamp)\n }\n }\n\n // Remove from conflicts since we just edited it\n this.state.editConflicts.delete(filePath)\n\n // Emit file edit event\n emitReminderEvent('file:edited', {\n filePath,\n timestamp: now,\n contentLength: content?.length || 0,\n source: 'agent',\n })\n } catch (error) {\n console.error(`Error recording file edit for ${filePath}:`, error)\n }\n }\n\n public generateFileModificationReminder(filePath: string): string | null {\n const recorded = this.state.readTimestamps.get(filePath)\n\n if (!recorded) {\n return null\n }\n\n try {\n if (!existsSync(filePath)) {\n return `Note: ${filePath} was deleted since last read.`\n }\n\n const currentStats = statSync(filePath)\n const isModified = currentStats.mtimeMs > recorded.lastModified\n\n if (!isModified) {\n return null\n }\n\n // Check if this was an Agent-initiated change\n // Use small time tolerance to handle filesystem timestamp precision issues\n const TIME_TOLERANCE_MS = 100\n if (\n recorded.lastAgentEdit &&\n recorded.lastAgentEdit >= recorded.lastModified - TIME_TOLERANCE_MS\n ) {\n // Agent modified this file recently, no reminder needed\n // (context already contains before/after content)\n return null\n }\n\n // External modification detected - generate reminder\n return `Note: ${filePath} was modified externally since last read. The file may have changed outside of this session.`\n } catch (error) {\n console.error(`Error checking modification for ${filePath}:`, error)\n return null\n }\n }\n\n public getConflictedFiles(): string[] {\n return Array.from(this.state.editConflicts)\n }\n\n public getSessionFiles(): string[] {\n return Array.from(this.state.sessionFiles)\n }\n\n public resetSession(): void {\n // Clean up existing todo file watchers\n this.state.watchedTodoFiles.forEach(filePath => {\n try {\n unwatchFile(filePath)\n } catch (error) {\n console.error(`Error unwatching file ${filePath}:`, error)\n }\n })\n\n this.state = {\n readTimestamps: new Map(),\n editConflicts: new Set(),\n sessionFiles: new Set(),\n watchedTodoFiles: new Map(),\n }\n }\n\n /**\n * Start watching todo file for an agent\n */\n public startWatchingTodoFile(agentId: string): void {\n try {\n const filePath = getAgentFilePath(agentId)\n\n // Don't watch if already watching\n if (this.state.watchedTodoFiles.has(agentId)) {\n return\n }\n\n this.state.watchedTodoFiles.set(agentId, filePath)\n\n // Record initial state if file exists\n if (existsSync(filePath)) {\n this.recordFileRead(filePath)\n }\n\n // Start watching for changes\n watchFile(filePath, { interval: 1000 }, (curr, prev) => {\n // Check if this was an external modification\n const reminder = this.generateFileModificationReminder(filePath)\n if (reminder) {\n // File was modified externally, emit todo change reminder\n emitReminderEvent('todo:file_changed', {\n agentId,\n filePath,\n reminder,\n timestamp: Date.now(),\n currentStats: { mtime: curr.mtime, size: curr.size },\n previousStats: { mtime: prev.mtime, size: prev.size },\n })\n }\n })\n } catch (error) {\n console.error(\n `Error starting todo file watch for agent ${agentId}:`,\n error,\n )\n }\n }\n\n /**\n * Stop watching todo file for an agent\n */\n public stopWatchingTodoFile(agentId: string): void {\n try {\n const filePath = this.state.watchedTodoFiles.get(agentId)\n if (filePath) {\n unwatchFile(filePath)\n this.state.watchedTodoFiles.delete(agentId)\n }\n } catch (error) {\n console.error(\n `Error stopping todo file watch for agent ${agentId}:`,\n error,\n )\n }\n }\n\n public getFileInfo(filePath: string): FileTimestamp | null {\n return this.state.readTimestamps.get(filePath) || null\n }\n\n public isFileTracked(filePath: string): boolean {\n return this.state.readTimestamps.has(filePath)\n }\n\n /**\n * Retrieves files prioritized for recovery during conversation compression\n *\n * Selects recently accessed files based on:\n * - File access recency (most recent first)\n * - File type relevance (excludes dependencies, build artifacts)\n * - Development workflow importance\n *\n * Used to maintain coding context when conversation history is compressed\n */\n public getImportantFiles(maxFiles: number = 5): Array<{\n path: string\n timestamp: number\n size: number\n }> {\n return Array.from(this.state.readTimestamps.entries())\n .map(([path, info]) => ({\n path,\n timestamp: info.lastRead,\n size: info.size,\n }))\n .filter(file => this.isValidForRecovery(file.path))\n .sort((a, b) => b.timestamp - a.timestamp) // Newest first\n .slice(0, maxFiles)\n }\n\n /**\n * Determines which files are suitable for automatic recovery\n *\n * Excludes files that are typically not relevant for development context:\n * - Build artifacts and generated files\n * - Dependencies and cached files\n * - Temporary files and system directories\n */\n private isValidForRecovery(filePath: string): boolean {\n return (\n !filePath.includes('node_modules') &&\n !filePath.includes('.git') &&\n !filePath.startsWith('/tmp') &&\n !filePath.includes('.cache') &&\n !filePath.includes('dist/') &&\n !filePath.includes('build/')\n )\n }\n}\n\nexport const fileFreshnessService = new FileFreshnessService()\n\nexport const recordFileRead = (filePath: string) =>\n fileFreshnessService.recordFileRead(filePath)\nexport const recordFileEdit = (filePath: string, content?: string) =>\n fileFreshnessService.recordFileEdit(filePath, content)\nexport const checkFileFreshness = (filePath: string) =>\n fileFreshnessService.checkFileFreshness(filePath)\nexport const generateFileModificationReminder = (filePath: string) =>\n fileFreshnessService.generateFileModificationReminder(filePath)\nexport const resetFileFreshnessSession = () =>\n fileFreshnessService.resetSession()\nexport const startWatchingTodoFile = (agentId: string) =>\n fileFreshnessService.startWatchingTodoFile(agentId)\nexport const stopWatchingTodoFile = (agentId: string) =>\n fileFreshnessService.stopWatchingTodoFile(agentId)\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,YAAY,WAAW,mBAAmB;AAC7D;AAAA,EACE;AAAA,EACA;AAAA,OACK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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,kBAAkB,WAAmB,GAIzC;AACD,WAAO,MAAM,KAAK,KAAK,MAAM,eAAe,QAAQ,CAAC,EAClD,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO;AAAA,MACtB;AAAA,MACA,WAAW,KAAK;AAAA,MAChB,MAAM,KAAK;AAAA,IACb,EAAE,EACD,OAAO,UAAQ,KAAK,mBAAmB,KAAK,IAAI,CAAC,EACjD,KAAK,CAAC,GAAG,MAAM,EAAE,YAAY,EAAE,SAAS,EACxC,MAAM,GAAG,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,mBAAmB,UAA2B;AACpD,WACE,CAAC,SAAS,SAAS,cAAc,KACjC,CAAC,SAAS,SAAS,MAAM,KACzB,CAAC,SAAS,WAAW,MAAM,KAC3B,CAAC,SAAS,SAAS,QAAQ,KAC3B,CAAC,SAAS,SAAS,OAAO,KAC1B,CAAC,SAAS,SAAS,QAAQ;AAAA,EAE/B;AACF;AAEO,MAAM,uBAAuB,IAAI,qBAAqB;AAEtD,MAAM,iBAAiB,CAAC,aAC7B,qBAAqB,eAAe,QAAQ;AACvC,MAAM,iBAAiB,CAAC,UAAkB,YAC/C,qBAAqB,eAAe,UAAU,OAAO;AAChD,MAAM,qBAAqB,CAAC,aACjC,qBAAqB,mBAAmB,QAAQ;AAC3C,MAAM,mCAAmC,CAAC,aAC/C,qBAAqB,iCAAiC,QAAQ;AACzD,MAAM,4BAA4B,MACvC,qBAAqB,aAAa;AAC7B,MAAM,wBAAwB,CAAC,YACpC,qBAAqB,sBAAsB,OAAO;AAC7C,MAAM,uBAAuB,CAAC,YACnC,qBAAqB,qBAAqB,OAAO;",
6
6
  "names": []
7
7
  }
@@ -15,7 +15,9 @@ async function testGPT5Connection(config) {
15
15
  console.log(`\u{1F527} Testing GPT-5 connection for model: ${config.model}`);
16
16
  console.log(`\u{1F527} Base URL: ${baseURL}`);
17
17
  console.log(`\u{1F527} Official OpenAI: ${isOfficialOpenAI}`);
18
- console.log(`\u{1F527} Supports Responses API: ${modelFeatures.supportsResponsesAPI}`);
18
+ console.log(
19
+ `\u{1F527} Supports Responses API: ${modelFeatures.supportsResponsesAPI}`
20
+ );
19
21
  if (isGPT5 && modelFeatures.supportsResponsesAPI && isOfficialOpenAI) {
20
22
  console.log(`\u{1F680} Attempting Responses API for ${config.model}`);
21
23
  const responsesResult = await testResponsesAPI(config, baseURL, startTime);
@@ -23,7 +25,9 @@ async function testGPT5Connection(config) {
23
25
  console.log(`\u2705 Responses API test successful for ${config.model}`);
24
26
  return responsesResult;
25
27
  } else {
26
- console.log(`\u26A0\uFE0F Responses API failed, falling back to Chat Completions: ${responsesResult.details}`);
28
+ console.log(
29
+ `\u26A0\uFE0F Responses API failed, falling back to Chat Completions: ${responsesResult.details}`
30
+ );
27
31
  }
28
32
  }
29
33
  console.log(`\u{1F504} Using Chat Completions API for ${config.model}`);
@@ -49,7 +53,7 @@ async function testResponsesAPI(config, baseURL, startTime) {
49
53
  };
50
54
  const headers = {
51
55
  "Content-Type": "application/json",
52
- "Authorization": `Bearer ${config.apiKey}`
56
+ Authorization: `Bearer ${config.apiKey}`
53
57
  };
54
58
  console.log(`\u{1F527} Responses API URL: ${testURL}`);
55
59
  console.log(`\u{1F527} Responses API payload:`, JSON.stringify(testPayload, null, 2));
@@ -69,7 +73,9 @@ async function testResponsesAPI(config, baseURL, startTime) {
69
73
  } else if (data.output && Array.isArray(data.output)) {
70
74
  const messageOutput = data.output.find((item) => item.type === "message");
71
75
  if (messageOutput && messageOutput.content) {
72
- const textContent = messageOutput.content.find((c) => c.type === "output_text");
76
+ const textContent = messageOutput.content.find(
77
+ (c) => c.type === "output_text"
78
+ );
73
79
  responseContent = textContent?.text || "";
74
80
  }
75
81
  }
@@ -136,7 +142,9 @@ async function testChatCompletionsAPI(config, baseURL, startTime) {
136
142
  if (isGPT5) {
137
143
  testPayload.max_completion_tokens = Math.max(config.maxTokens || 8192, 8192);
138
144
  delete testPayload.max_tokens;
139
- console.log(`\u{1F527} GPT-5 mode: Using max_completion_tokens = ${testPayload.max_completion_tokens}`);
145
+ console.log(
146
+ `\u{1F527} GPT-5 mode: Using max_completion_tokens = ${testPayload.max_completion_tokens}`
147
+ );
140
148
  } else {
141
149
  testPayload.max_tokens = Math.max(config.maxTokens || 8192, 8192);
142
150
  }
@@ -149,7 +157,10 @@ async function testChatCompletionsAPI(config, baseURL, startTime) {
149
157
  headers["Authorization"] = `Bearer ${config.apiKey}`;
150
158
  }
151
159
  console.log(`\u{1F527} Chat Completions URL: ${testURL}`);
152
- console.log(`\u{1F527} Chat Completions payload:`, JSON.stringify(testPayload, null, 2));
160
+ console.log(
161
+ `\u{1F527} Chat Completions payload:`,
162
+ JSON.stringify(testPayload, null, 2)
163
+ );
153
164
  try {
154
165
  const response = await fetch(testURL, {
155
166
  method: "POST",
@@ -229,7 +240,9 @@ function validateGPT5Config(config) {
229
240
  }
230
241
  const isGPT5 = config.model?.toLowerCase().includes("gpt-5");
231
242
  if (isGPT5) {
232
- console.log(`\u{1F527} GPT-5 validation: model=${config.model}, maxTokens=${config.maxTokens}`);
243
+ console.log(
244
+ `\u{1F527} GPT-5 validation: model=${config.model}, maxTokens=${config.maxTokens}`
245
+ );
233
246
  if (config.maxTokens && config.maxTokens < 1e3) {
234
247
  errors.push("GPT-5 models typically require at least 1000 max tokens");
235
248
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/gpt5ConnectionTest.ts"],
4
- "sourcesContent": ["/**\n * \uD83D\uDD25 GPT-5 Connection Test Service\n * \n * Specialized connection testing for GPT-5 models that supports both\n * Responses API and Chat Completions API with proper fallback handling.\n */\n\nimport { getModelFeatures } from './openai'\n\nexport interface ConnectionTestResult {\n success: boolean\n message: string\n endpoint?: string\n details?: string\n apiUsed?: 'responses' | 'chat_completions'\n responseTime?: number\n}\n\nexport interface GPT5TestConfig {\n model: string\n apiKey: string\n baseURL?: string\n maxTokens?: number\n provider?: string\n}\n\n/**\n * Test GPT-5 model connection with intelligent API selection\n */\nexport async function testGPT5Connection(config: GPT5TestConfig): Promise<ConnectionTestResult> {\n const startTime = Date.now()\n \n // Validate configuration\n if (!config.model || !config.apiKey) {\n return {\n success: false,\n message: 'Invalid configuration',\n details: 'Model name and API key are required',\n }\n }\n\n const isGPT5 = config.model.toLowerCase().includes('gpt-5')\n const modelFeatures = getModelFeatures(config.model)\n const baseURL = config.baseURL || 'https://api.openai.com/v1'\n const isOfficialOpenAI = !config.baseURL || config.baseURL.includes('api.openai.com')\n\n console.log(`\uD83D\uDD27 Testing GPT-5 connection for model: ${config.model}`)\n console.log(`\uD83D\uDD27 Base URL: ${baseURL}`)\n console.log(`\uD83D\uDD27 Official OpenAI: ${isOfficialOpenAI}`)\n console.log(`\uD83D\uDD27 Supports Responses API: ${modelFeatures.supportsResponsesAPI}`)\n\n // Try Responses API first for official GPT-5 models\n if (isGPT5 && modelFeatures.supportsResponsesAPI && isOfficialOpenAI) {\n console.log(`\uD83D\uDE80 Attempting Responses API for ${config.model}`)\n const responsesResult = await testResponsesAPI(config, baseURL, startTime)\n \n if (responsesResult.success) {\n console.log(`\u2705 Responses API test successful for ${config.model}`)\n return responsesResult\n } else {\n console.log(`\u26A0\uFE0F Responses API failed, falling back to Chat Completions: ${responsesResult.details}`)\n }\n }\n\n // Fallback to Chat Completions API\n console.log(`\uD83D\uDD04 Using Chat Completions API for ${config.model}`)\n return await testChatCompletionsAPI(config, baseURL, startTime)\n}\n\n/**\n * Test using GPT-5 Responses API\n */\nasync function testResponsesAPI(\n config: GPT5TestConfig, \n baseURL: string, \n startTime: number\n): Promise<ConnectionTestResult> {\n const testURL = `${baseURL.replace(/\\/+$/, '')}/responses`\n \n const testPayload = {\n model: config.model,\n input: [\n {\n role: 'user',\n content: 'Please respond with exactly \"YES\" (in capital letters) to confirm this connection is working.',\n },\n ],\n max_completion_tokens: Math.max(config.maxTokens || 8192, 8192),\n temperature: 1, // GPT-5 requirement\n reasoning: {\n effort: 'low', // Fast response for connection test\n },\n }\n\n const headers = {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${config.apiKey}`,\n }\n\n console.log(`\uD83D\uDD27 Responses API URL: ${testURL}`)\n console.log(`\uD83D\uDD27 Responses API payload:`, JSON.stringify(testPayload, null, 2))\n\n try {\n const response = await fetch(testURL, {\n method: 'POST',\n headers,\n body: JSON.stringify(testPayload),\n })\n\n const responseTime = Date.now() - startTime\n\n if (response.ok) {\n const data = await response.json()\n console.log(`\u2705 Responses API successful response:`, data)\n\n // Extract content from Responses API format\n let responseContent = ''\n if (data.output_text) {\n responseContent = data.output_text\n } else if (data.output && Array.isArray(data.output)) {\n // Extract from structured output format\n const messageOutput = data.output.find(item => item.type === 'message')\n if (messageOutput && messageOutput.content) {\n const textContent = messageOutput.content.find(c => c.type === 'output_text')\n responseContent = textContent?.text || ''\n }\n }\n\n const containsYes = responseContent.toLowerCase().includes('yes')\n\n if (containsYes) {\n return {\n success: true,\n message: '\u2705 GPT-5 Responses API connection successful',\n endpoint: '/responses',\n details: `Model responded correctly: \"${responseContent.trim()}\"`,\n apiUsed: 'responses',\n responseTime,\n }\n } else {\n return {\n success: false,\n message: '\u26A0\uFE0F Responses API connected but unexpected response',\n endpoint: '/responses',\n details: `Expected \"YES\" but got: \"${responseContent.trim() || '(empty response)'}\"`,\n apiUsed: 'responses',\n responseTime,\n }\n }\n } else {\n const errorData = await response.json().catch(() => null)\n const errorMessage = errorData?.error?.message || errorData?.message || response.statusText\n\n console.log(`\u274C Responses API error (${response.status}):`, errorData)\n\n return {\n success: false,\n message: `\u274C Responses API failed (${response.status})`,\n endpoint: '/responses',\n details: `Error: ${errorMessage}`,\n apiUsed: 'responses',\n responseTime: Date.now() - startTime,\n }\n }\n } catch (error) {\n console.log(`\u274C Responses API connection error:`, error)\n \n return {\n success: false,\n message: '\u274C Responses API connection failed',\n endpoint: '/responses',\n details: error instanceof Error ? error.message : String(error),\n apiUsed: 'responses',\n responseTime: Date.now() - startTime,\n }\n }\n}\n\n/**\n * Test using Chat Completions API with GPT-5 compatibility\n */\nasync function testChatCompletionsAPI(\n config: GPT5TestConfig, \n baseURL: string, \n startTime: number\n): Promise<ConnectionTestResult> {\n const testURL = `${baseURL.replace(/\\/+$/, '')}/chat/completions`\n \n const isGPT5 = config.model.toLowerCase().includes('gpt-5')\n \n // Create test payload with GPT-5 compatibility\n const testPayload: any = {\n model: config.model,\n messages: [\n {\n role: 'user',\n content: 'Please respond with exactly \"YES\" (in capital letters) to confirm this connection is working.',\n },\n ],\n temperature: isGPT5 ? 1 : 0, // GPT-5 requires temperature=1\n stream: false,\n }\n\n // \uD83D\uDD27 Apply GPT-5 parameter transformations\n if (isGPT5) {\n testPayload.max_completion_tokens = Math.max(config.maxTokens || 8192, 8192)\n delete testPayload.max_tokens // \uD83D\uDD25 CRITICAL: Remove max_tokens for GPT-5\n console.log(`\uD83D\uDD27 GPT-5 mode: Using max_completion_tokens = ${testPayload.max_completion_tokens}`)\n } else {\n testPayload.max_tokens = Math.max(config.maxTokens || 8192, 8192)\n }\n\n const headers = {\n 'Content-Type': 'application/json',\n }\n\n // Add provider-specific headers\n if (config.provider === 'azure') {\n headers['api-key'] = config.apiKey\n } else {\n headers['Authorization'] = `Bearer ${config.apiKey}`\n }\n\n console.log(`\uD83D\uDD27 Chat Completions URL: ${testURL}`)\n console.log(`\uD83D\uDD27 Chat Completions payload:`, JSON.stringify(testPayload, null, 2))\n\n try {\n const response = await fetch(testURL, {\n method: 'POST',\n headers,\n body: JSON.stringify(testPayload),\n })\n\n const responseTime = Date.now() - startTime\n\n if (response.ok) {\n const data = await response.json()\n console.log(`\u2705 Chat Completions successful response:`, data)\n\n const responseContent = data.choices?.[0]?.message?.content || ''\n const containsYes = responseContent.toLowerCase().includes('yes')\n\n if (containsYes) {\n return {\n success: true,\n message: `\u2705 ${isGPT5 ? 'GPT-5' : 'Model'} Chat Completions connection successful`,\n endpoint: '/chat/completions',\n details: `Model responded correctly: \"${responseContent.trim()}\"`,\n apiUsed: 'chat_completions',\n responseTime,\n }\n } else {\n return {\n success: false,\n message: '\u26A0\uFE0F Chat Completions connected but unexpected response',\n endpoint: '/chat/completions',\n details: `Expected \"YES\" but got: \"${responseContent.trim() || '(empty response)'}\"`,\n apiUsed: 'chat_completions',\n responseTime,\n }\n }\n } else {\n const errorData = await response.json().catch(() => null)\n const errorMessage = errorData?.error?.message || errorData?.message || response.statusText\n\n console.log(`\u274C Chat Completions error (${response.status}):`, errorData)\n\n // \uD83D\uDD27 Provide specific guidance for GPT-5 errors\n let details = `Error: ${errorMessage}`\n if (response.status === 400 && errorMessage.includes('max_tokens') && isGPT5) {\n details += '\\n\\n\uD83D\uDD27 GPT-5 Fix Applied: This error suggests a parameter compatibility issue. Please check if the provider supports GPT-5 with max_completion_tokens.'\n }\n\n return {\n success: false,\n message: `\u274C Chat Completions failed (${response.status})`,\n endpoint: '/chat/completions',\n details: details,\n apiUsed: 'chat_completions',\n responseTime: Date.now() - startTime,\n }\n }\n } catch (error) {\n console.log(`\u274C Chat Completions connection error:`, error)\n \n return {\n success: false,\n message: '\u274C Chat Completions connection failed',\n endpoint: '/chat/completions',\n details: error instanceof Error ? error.message : String(error),\n apiUsed: 'chat_completions',\n responseTime: Date.now() - startTime,\n }\n }\n}\n\n/**\n * Quick validation for GPT-5 configuration\n */\nexport function validateGPT5Config(config: GPT5TestConfig): { valid: boolean; errors: string[] } {\n console.log(`\uD83D\uDD27 validateGPT5Config called with:`, {\n model: config.model,\n hasApiKey: !!config.apiKey,\n baseURL: config.baseURL,\n provider: config.provider,\n })\n \n const errors: string[] = []\n\n if (!config.model) {\n errors.push('Model name is required')\n }\n\n if (!config.apiKey) {\n errors.push('API key is required')\n }\n\n if (config.apiKey && config.apiKey.length < 10) {\n errors.push('API key appears to be invalid (too short)')\n }\n\n const isGPT5 = config.model?.toLowerCase().includes('gpt-5')\n if (isGPT5) {\n console.log(`\uD83D\uDD27 GPT-5 validation: model=${config.model}, maxTokens=${config.maxTokens}`)\n \n if (config.maxTokens && config.maxTokens < 1000) {\n errors.push('GPT-5 models typically require at least 1000 max tokens')\n }\n \n // \u5B8C\u5168\u79FB\u9664\u7B2C\u4E09\u65B9provider\u9650\u5236\uFF0C\u5141\u8BB8\u6240\u6709\u4EE3\u7406\u4E2D\u8F6C\u7AD9\u4F7F\u7528GPT-5\n console.log(`\uD83D\uDD27 No third-party restrictions applied for GPT-5`)\n }\n\n console.log(`\uD83D\uDD27 Validation result:`, { valid: errors.length === 0, errors })\n\n return {\n valid: errors.length === 0,\n errors,\n }\n}"],
5
- "mappings": "AAOA,SAAS,wBAAwB;AAsBjC,eAAsB,mBAAmB,QAAuD;AAC9F,QAAM,YAAY,KAAK,IAAI;AAG3B,MAAI,CAAC,OAAO,SAAS,CAAC,OAAO,QAAQ;AACnC,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AAEA,QAAM,SAAS,OAAO,MAAM,YAAY,EAAE,SAAS,OAAO;AAC1D,QAAM,gBAAgB,iBAAiB,OAAO,KAAK;AACnD,QAAM,UAAU,OAAO,WAAW;AAClC,QAAM,mBAAmB,CAAC,OAAO,WAAW,OAAO,QAAQ,SAAS,gBAAgB;AAEpF,UAAQ,IAAI,iDAA0C,OAAO,KAAK,EAAE;AACpE,UAAQ,IAAI,uBAAgB,OAAO,EAAE;AACrC,UAAQ,IAAI,8BAAuB,gBAAgB,EAAE;AACrD,UAAQ,IAAI,qCAA8B,cAAc,oBAAoB,EAAE;AAG9E,MAAI,UAAU,cAAc,wBAAwB,kBAAkB;AACpE,YAAQ,IAAI,0CAAmC,OAAO,KAAK,EAAE;AAC7D,UAAM,kBAAkB,MAAM,iBAAiB,QAAQ,SAAS,SAAS;AAEzE,QAAI,gBAAgB,SAAS;AAC3B,cAAQ,IAAI,4CAAuC,OAAO,KAAK,EAAE;AACjE,a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AAI,CAAC,OAAO,OAAO;AACjB,WAAO,KAAK,wBAAwB;AAAA,EACtC;AAEA,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO,KAAK,qBAAqB;AAAA,EACnC;AAEA,MAAI,OAAO,UAAU,OAAO,OAAO,SAAS,IAAI;AAC9C,WAAO,KAAK,2CAA2C;AAAA,EACzD;AAEA,QAAM,SAAS,OAAO,OAAO,YAAY,EAAE,SAAS,OAAO;AAC3D,MAAI,QAAQ;AACV,YAAQ,IAAI,qCAA8B,OAAO,KAAK,eAAe,OAAO,SAAS,EAAE;AAEvF,QAAI,OAAO,aAAa,OAAO,YAAY,KAAM;AAC/C,aAAO,KAAK,yDAAyD;AAAA,IACvE;AAGA,YAAQ,IAAI,yDAAkD;AAAA,EAChE;AAEA,UAAQ,IAAI,gCAAyB,EAAE,OAAO,OAAO,WAAW,GAAG,OAAO,CAAC;AAE3E,SAAO;AAAA,IACL,OAAO,OAAO,WAAW;AAAA,IACzB;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["/**\n * \uD83D\uDD25 GPT-5 Connection Test Service\n *\n * Specialized connection testing for GPT-5 models that supports both\n * Responses API and Chat Completions API with proper fallback handling.\n */\n\nimport { getModelFeatures } from './openai'\n\nexport interface ConnectionTestResult {\n success: boolean\n message: string\n endpoint?: string\n details?: string\n apiUsed?: 'responses' | 'chat_completions'\n responseTime?: number\n}\n\nexport interface GPT5TestConfig {\n model: string\n apiKey: string\n baseURL?: string\n maxTokens?: number\n provider?: string\n}\n\n/**\n * Test GPT-5 model connection with intelligent API selection\n */\nexport async function testGPT5Connection(\n config: GPT5TestConfig,\n): Promise<ConnectionTestResult> {\n const startTime = Date.now()\n\n // Validate configuration\n if (!config.model || !config.apiKey) {\n return {\n success: false,\n message: 'Invalid configuration',\n details: 'Model name and API key are required',\n }\n }\n\n const isGPT5 = config.model.toLowerCase().includes('gpt-5')\n const modelFeatures = getModelFeatures(config.model)\n const baseURL = config.baseURL || 'https://api.openai.com/v1'\n const isOfficialOpenAI =\n !config.baseURL || config.baseURL.includes('api.openai.com')\n\n console.log(`\uD83D\uDD27 Testing GPT-5 connection for model: ${config.model}`)\n console.log(`\uD83D\uDD27 Base URL: ${baseURL}`)\n console.log(`\uD83D\uDD27 Official OpenAI: ${isOfficialOpenAI}`)\n console.log(\n `\uD83D\uDD27 Supports Responses API: ${modelFeatures.supportsResponsesAPI}`,\n )\n\n // Try Responses API first for official GPT-5 models\n if (isGPT5 && modelFeatures.supportsResponsesAPI && isOfficialOpenAI) {\n console.log(`\uD83D\uDE80 Attempting Responses API for ${config.model}`)\n const responsesResult = await testResponsesAPI(config, baseURL, startTime)\n\n if (responsesResult.success) {\n console.log(`\u2705 Responses API test successful for ${config.model}`)\n return responsesResult\n } else {\n console.log(\n `\u26A0\uFE0F Responses API failed, falling back to Chat Completions: ${responsesResult.details}`,\n )\n }\n }\n\n // Fallback to Chat Completions API\n console.log(`\uD83D\uDD04 Using Chat Completions API for ${config.model}`)\n return await testChatCompletionsAPI(config, baseURL, startTime)\n}\n\n/**\n * Test using GPT-5 Responses API\n */\nasync function testResponsesAPI(\n config: GPT5TestConfig,\n baseURL: string,\n startTime: number,\n): Promise<ConnectionTestResult> {\n const testURL = `${baseURL.replace(/\\/+$/, '')}/responses`\n\n const testPayload = {\n model: config.model,\n input: [\n {\n role: 'user',\n content:\n 'Please respond with exactly \"YES\" (in capital letters) to confirm this connection is working.',\n },\n ],\n max_completion_tokens: Math.max(config.maxTokens || 8192, 8192),\n temperature: 1, // GPT-5 requirement\n reasoning: {\n effort: 'low', // Fast response for connection test\n },\n }\n\n const headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${config.apiKey}`,\n }\n\n console.log(`\uD83D\uDD27 Responses API URL: ${testURL}`)\n console.log(`\uD83D\uDD27 Responses API payload:`, JSON.stringify(testPayload, null, 2))\n\n try {\n const response = await fetch(testURL, {\n method: 'POST',\n headers,\n body: JSON.stringify(testPayload),\n })\n\n const responseTime = Date.now() - startTime\n\n if (response.ok) {\n const data = await response.json()\n console.log(`\u2705 Responses API successful response:`, data)\n\n // Extract content from Responses API format\n let responseContent = ''\n if (data.output_text) {\n responseContent = data.output_text\n } else if (data.output && Array.isArray(data.output)) {\n // Extract from structured output format\n const messageOutput = data.output.find(item => item.type === 'message')\n if (messageOutput && messageOutput.content) {\n const textContent = messageOutput.content.find(\n c => c.type === 'output_text',\n )\n responseContent = textContent?.text || ''\n }\n }\n\n const containsYes = responseContent.toLowerCase().includes('yes')\n\n if (containsYes) {\n return {\n success: true,\n message: '\u2705 GPT-5 Responses API connection successful',\n endpoint: '/responses',\n details: `Model responded correctly: \"${responseContent.trim()}\"`,\n apiUsed: 'responses',\n responseTime,\n }\n } else {\n return {\n success: false,\n message: '\u26A0\uFE0F Responses API connected but unexpected response',\n endpoint: '/responses',\n details: `Expected \"YES\" but got: \"${responseContent.trim() || '(empty response)'}\"`,\n apiUsed: 'responses',\n responseTime,\n }\n }\n } else {\n const errorData = await response.json().catch(() => null)\n const errorMessage =\n errorData?.error?.message || errorData?.message || response.statusText\n\n console.log(`\u274C Responses API error (${response.status}):`, errorData)\n\n return {\n success: false,\n message: `\u274C Responses API failed (${response.status})`,\n endpoint: '/responses',\n details: `Error: ${errorMessage}`,\n apiUsed: 'responses',\n responseTime: Date.now() - startTime,\n }\n }\n } catch (error) {\n console.log(`\u274C Responses API connection error:`, error)\n\n return {\n success: false,\n message: '\u274C Responses API connection failed',\n endpoint: '/responses',\n details: error instanceof Error ? error.message : String(error),\n apiUsed: 'responses',\n responseTime: Date.now() - startTime,\n }\n }\n}\n\n/**\n * Test using Chat Completions API with GPT-5 compatibility\n */\nasync function testChatCompletionsAPI(\n config: GPT5TestConfig,\n baseURL: string,\n startTime: number,\n): Promise<ConnectionTestResult> {\n const testURL = `${baseURL.replace(/\\/+$/, '')}/chat/completions`\n\n const isGPT5 = config.model.toLowerCase().includes('gpt-5')\n\n // Create test payload with GPT-5 compatibility\n const testPayload: any = {\n model: config.model,\n messages: [\n {\n role: 'user',\n content:\n 'Please respond with exactly \"YES\" (in capital letters) to confirm this connection is working.',\n },\n ],\n temperature: isGPT5 ? 1 : 0, // GPT-5 requires temperature=1\n stream: false,\n }\n\n // \uD83D\uDD27 Apply GPT-5 parameter transformations\n if (isGPT5) {\n testPayload.max_completion_tokens = Math.max(config.maxTokens || 8192, 8192)\n delete testPayload.max_tokens // \uD83D\uDD25 CRITICAL: Remove max_tokens for GPT-5\n console.log(\n `\uD83D\uDD27 GPT-5 mode: Using max_completion_tokens = ${testPayload.max_completion_tokens}`,\n )\n } else {\n testPayload.max_tokens = Math.max(config.maxTokens || 8192, 8192)\n }\n\n const headers = {\n 'Content-Type': 'application/json',\n }\n\n // Add provider-specific headers\n if (config.provider === 'azure') {\n headers['api-key'] = config.apiKey\n } else {\n headers['Authorization'] = `Bearer ${config.apiKey}`\n }\n\n console.log(`\uD83D\uDD27 Chat Completions URL: ${testURL}`)\n console.log(\n `\uD83D\uDD27 Chat Completions payload:`,\n JSON.stringify(testPayload, null, 2),\n )\n\n try {\n const response = await fetch(testURL, {\n method: 'POST',\n headers,\n body: JSON.stringify(testPayload),\n })\n\n const responseTime = Date.now() - startTime\n\n if (response.ok) {\n const data = await response.json()\n console.log(`\u2705 Chat Completions successful response:`, data)\n\n const responseContent = data.choices?.[0]?.message?.content || ''\n const containsYes = responseContent.toLowerCase().includes('yes')\n\n if (containsYes) {\n return {\n success: true,\n message: `\u2705 ${isGPT5 ? 'GPT-5' : 'Model'} Chat Completions connection successful`,\n endpoint: '/chat/completions',\n details: `Model responded correctly: \"${responseContent.trim()}\"`,\n apiUsed: 'chat_completions',\n responseTime,\n }\n } else {\n return {\n success: false,\n message: '\u26A0\uFE0F Chat Completions connected but unexpected response',\n endpoint: '/chat/completions',\n details: `Expected \"YES\" but got: \"${responseContent.trim() || '(empty response)'}\"`,\n apiUsed: 'chat_completions',\n responseTime,\n }\n }\n } else {\n const errorData = await response.json().catch(() => null)\n const errorMessage =\n errorData?.error?.message || errorData?.message || response.statusText\n\n console.log(`\u274C Chat Completions error (${response.status}):`, errorData)\n\n // \uD83D\uDD27 Provide specific guidance for GPT-5 errors\n let details = `Error: ${errorMessage}`\n if (\n response.status === 400 &&\n errorMessage.includes('max_tokens') &&\n isGPT5\n ) {\n details +=\n '\\n\\n\uD83D\uDD27 GPT-5 Fix Applied: This error suggests a parameter compatibility issue. Please check if the provider supports GPT-5 with max_completion_tokens.'\n }\n\n return {\n success: false,\n message: `\u274C Chat Completions failed (${response.status})`,\n endpoint: '/chat/completions',\n details: details,\n apiUsed: 'chat_completions',\n responseTime: Date.now() - startTime,\n }\n }\n } catch (error) {\n console.log(`\u274C Chat Completions connection error:`, error)\n\n return {\n success: false,\n message: '\u274C Chat Completions connection failed',\n endpoint: '/chat/completions',\n details: error instanceof Error ? error.message : String(error),\n apiUsed: 'chat_completions',\n responseTime: Date.now() - startTime,\n }\n }\n}\n\n/**\n * Quick validation for GPT-5 configuration\n */\nexport function validateGPT5Config(config: GPT5TestConfig): {\n valid: boolean\n errors: string[]\n} {\n console.log(`\uD83D\uDD27 validateGPT5Config called with:`, {\n model: config.model,\n hasApiKey: !!config.apiKey,\n baseURL: config.baseURL,\n provider: config.provider,\n })\n\n const errors: string[] = []\n\n if (!config.model) {\n errors.push('Model name is required')\n }\n\n if (!config.apiKey) {\n errors.push('API key is required')\n }\n\n if (config.apiKey && config.apiKey.length < 10) {\n errors.push('API key appears to be invalid (too short)')\n }\n\n const isGPT5 = config.model?.toLowerCase().includes('gpt-5')\n if (isGPT5) {\n console.log(\n `\uD83D\uDD27 GPT-5 validation: model=${config.model}, maxTokens=${config.maxTokens}`,\n )\n\n if (config.maxTokens && config.maxTokens < 1000) {\n errors.push('GPT-5 models typically require at least 1000 max tokens')\n }\n\n // \u5B8C\u5168\u79FB\u9664\u7B2C\u4E09\u65B9provider\u9650\u5236\uFF0C\u5141\u8BB8\u6240\u6709\u4EE3\u7406\u4E2D\u8F6C\u7AD9\u4F7F\u7528GPT-5\n console.log(`\uD83D\uDD27 No third-party restrictions applied for GPT-5`)\n }\n\n console.log(`\uD83D\uDD27 Validation result:`, { valid: errors.length === 0, errors })\n\n return {\n valid: errors.length === 0,\n errors,\n }\n}\n"],
5
+ "mappings": "AAOA,SAAS,wBAAwB;AAsBjC,eAAsB,mBACpB,QAC+B;AAC/B,QAAM,YAAY,KAAK,IAAI;AAG3B,MAAI,CAAC,OAAO,SAAS,CAAC,OAAO,QAAQ;AACnC,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AAEA,QAAM,SAAS,OAAO,MAAM,YAAY,EAAE,SAAS,OAAO;AAC1D,QAAM,gBAAgB,iBAAiB,OAAO,KAAK;AACnD,QAAM,UAAU,OAAO,WAAW;AAClC,QAAM,mBACJ,CAAC,OAAO,WAAW,OAAO,QAAQ,SAAS,gBAAgB;AAE7D,UAAQ,IAAI,iDAA0C,OAAO,KAAK,EAAE;AACpE,UAAQ,IAAI,uBAAgB,OAAO,EAAE;AACrC,UAAQ,IAAI,8BAAuB,gBAAgB,EAAE;AACrD,UAAQ;AAAA,IACN,qCAA8B,cAAc,oBAAoB;AAAA,EAClE;AAGA,MAAI,UAAU,cAAc,wBAAwB,kBAAkB;AACpE,YAAQ,IAAI,0CAAmC,OAAO,KAAK,EAAE;AAC7D,UAAM,kBAAkB,MAAM,iBAAiB,QAAQ,SAAS,SAAS;AAEzE,QAAI,gBAAgB,SAAS;AAC3B,cAAQ,IAAI,4CAAuC,OAAO,KAAK,EAAE;AACjE,aAAO;AAAA,IACT,OAAO;AACL,cAAQ;AAAA,QACN,wEAA8D,gBAAgB,OAAO;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AAGA,UAAQ,IAAI,4CAAqC,OAAO,KAAK,EAAE;AAC/D,SAAO,MAAM,uBAAuB,QAAQ,SAAS,SAAS;AAChE;AAKA,eAAe,iBACb,QACA,SACA,WAC+B;AAC/B,QAAM,UAAU,GAAG,QAAQ,QA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O,OAAO,YAAY,EAAE,SAAS,OAAO;AAC3D,MAAI,QAAQ;AACV,YAAQ;AAAA,MACN,qCAA8B,OAAO,KAAK,eAAe,OAAO,SAAS;AAAA,IAC3E;AAEA,QAAI,OAAO,aAAa,OAAO,YAAY,KAAM;AAC/C,aAAO,KAAK,yDAAyD;AAAA,IACvE;AAGA,YAAQ,IAAI,yDAAkD;AAAA,EAChE;AAEA,UAAQ,IAAI,gCAAyB,EAAE,OAAO,OAAO,WAAW,GAAG,OAAO,CAAC;AAE3E,SAAO;AAAA,IACL,OAAO,OAAO,WAAW;AAAA,IACzB;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -21,15 +21,11 @@ async function executeHook(hook, input, options) {
21
21
  try {
22
22
  logDebug(`Executing hook: ${hook.name}`);
23
23
  logDebug(`Command: ${hook.config.command}`);
24
- const result = await executeBashCommand(
25
- hook.config.command,
26
- input,
27
- {
28
- ...options,
29
- timeout,
30
- pluginRoot: options.pluginRoot
31
- }
32
- );
24
+ const result = await executeBashCommand(hook.config.command, input, {
25
+ ...options,
26
+ timeout,
27
+ pluginRoot: options.pluginRoot
28
+ });
33
29
  if (result.timedOut) {
34
30
  logError(`Hook ${hook.name} timed out after ${timeout}ms`);
35
31
  return {
@@ -181,9 +177,7 @@ async function executeHooksForEvent(event, hooks, input, options) {
181
177
  return results;
182
178
  }
183
179
  function processHookDecisions(results) {
184
- const blockedResult = results.find(
185
- (r) => r.success && r.decision === "block"
186
- );
180
+ const blockedResult = results.find((r) => r.success && r.decision === "block");
187
181
  if (blockedResult) {
188
182
  return {
189
183
  shouldContinue: false,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/hookExecutor.ts"],
4
- "sourcesContent": ["/**\n * Hook Execution Engine\n *\n * Executes plugin hooks with bash command execution, JSON I/O,\n * and decision processing (approve/block/ask).\n *\n * Fully compatible with Claude Code CLI hooks specification.\n */\n\nimport { spawn } from 'child_process'\nimport { homedir } from 'os'\nimport { join } from 'path'\nimport {\n HookEvent,\n HookInput,\n HookOutput,\n HookDecision,\n PreToolUseInput,\n PostToolUseInput,\n UserPromptSubmitInput,\n SessionStartInput,\n SessionEndInput,\n} from '../types/hooks'\nimport { LoadedHook } from '../types/plugin'\nimport { getCwd } from '../utils/state'\nimport { logError } from '../utils/log'\n\n// Simple logging helpers\nconst logInfo = (msg: string) => {\n // Only log in debug mode to reduce noise\n if (process.env.DEBUG) console.log(`[INFO] ${msg}`)\n}\nconst logDebug = (msg: string, ...args: any[]) => {\n if (process.env.DEBUG) console.log(`[DEBUG] ${msg}`, ...args)\n}\n\n/**\n * Hook execution result\n */\nexport interface HookExecutionResult {\n success: boolean\n decision?: 'approve' | 'block' | 'ask'\n output?: HookOutput\n error?: string\n timedOut?: boolean\n}\n\n/**\n * Hook execution options\n */\nexport interface HookExecutionOptions {\n timeout?: number\n sessionId: string\n transcriptPath?: string\n pluginRoot: string\n}\n\n/**\n * Execute a hook with bash command\n */\nexport async function executeHook(\n hook: LoadedHook,\n input: HookInput,\n options: HookExecutionOptions,\n): Promise<HookExecutionResult> {\n // Only execute command-type hooks\n if (hook.config.type !== 'command' || !hook.config.command) {\n return {\n success: false,\n error: `Hook type \"${hook.config.type}\" not yet implemented`,\n }\n }\n\n const timeout = hook.config.timeout || options.timeout || 30000 // 30 seconds default\n\n try {\n logDebug(`Executing hook: ${hook.name}`)\n logDebug(`Command: ${hook.config.command}`)\n\n // Execute bash command with JSON input via stdin\n const result = await executeBashCommand(\n hook.config.command,\n input,\n {\n ...options,\n timeout,\n pluginRoot: options.pluginRoot,\n },\n )\n\n if (result.timedOut) {\n logError(`Hook ${hook.name} timed out after ${timeout}ms`)\n return {\n success: false,\n timedOut: true,\n error: `Hook execution timed out after ${timeout}ms`,\n }\n }\n\n if (result.error) {\n logError(`Hook ${hook.name} failed: ${result.error}`)\n return {\n success: false,\n error: result.error,\n }\n }\n\n // Parse JSON output\n const output = parseHookOutput(result.stdout)\n\n if (!output) {\n // No output means hook executed successfully but didn't return decisions\n return {\n success: true,\n }\n }\n\n logDebug(`Hook ${hook.name} output:`, output)\n\n return {\n success: true,\n decision: output.decision,\n output,\n }\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error)\n logError(`Hook ${hook.name} execution error: ${errorMsg}`)\n return {\n success: false,\n error: errorMsg,\n }\n }\n}\n\n/**\n * Execute bash command with JSON stdin/stdout\n */\nasync function executeBashCommand(\n command: string,\n input: HookInput,\n options: {\n timeout: number\n sessionId: string\n transcriptPath?: string\n pluginRoot: string\n },\n): Promise<{\n stdout: string\n stderr: string\n error?: string\n timedOut?: boolean\n}> {\n return new Promise((resolve) => {\n // Prepare environment variables\n const env = {\n ...process.env,\n CLAUDE_PLUGIN_ROOT: options.pluginRoot,\n CLAUDE_SESSION_ID: options.sessionId,\n CLAUDE_CWD: getCwd(),\n CLAUDE_TRANSCRIPT_PATH: options.transcriptPath || '',\n }\n\n // Spawn bash process\n const child = spawn('bash', ['-c', command], {\n env,\n cwd: getCwd(),\n })\n\n let stdout = ''\n let stderr = ''\n let timedOut = false\n\n // Set timeout\n const timer = setTimeout(() => {\n timedOut = true\n child.kill('SIGTERM')\n setTimeout(() => {\n if (!child.killed) {\n child.kill('SIGKILL')\n }\n }, 1000)\n }, options.timeout)\n\n // Collect stdout\n child.stdout?.on('data', (data) => {\n stdout += data.toString()\n })\n\n // Collect stderr\n child.stderr?.on('data', (data) => {\n stderr += data.toString()\n })\n\n // Handle completion\n child.on('close', (code) => {\n clearTimeout(timer)\n\n if (timedOut) {\n resolve({\n stdout: '',\n stderr: '',\n timedOut: true,\n })\n return\n }\n\n if (code !== 0 && code !== null) {\n resolve({\n stdout,\n stderr,\n error: `Command exited with code ${code}: ${stderr}`,\n })\n return\n }\n\n resolve({\n stdout,\n stderr,\n })\n })\n\n // Handle errors\n child.on('error', (error) => {\n clearTimeout(timer)\n resolve({\n stdout: '',\n stderr: '',\n error: `Failed to spawn process: ${error.message}`,\n })\n })\n\n // Send JSON input via stdin\n try {\n if (child.stdin) {\n child.stdin.write(JSON.stringify(input, null, 2))\n child.stdin.end()\n }\n } catch (error) {\n clearTimeout(timer)\n child.kill()\n resolve({\n stdout: '',\n stderr: '',\n error: `Failed to write to stdin: ${error instanceof Error ? error.message : String(error)}`,\n })\n }\n })\n}\n\n/**\n * Parse hook output JSON\n */\nfunction parseHookOutput(stdout: string): HookOutput | null {\n if (!stdout.trim()) {\n return null\n }\n\n try {\n // Try to extract JSON from output (hook might print other things)\n const jsonMatch = stdout.match(/\\{[\\s\\S]*\\}/)\n if (!jsonMatch) {\n logDebug('No JSON found in hook output')\n return null\n }\n\n const output = JSON.parse(jsonMatch[0]) as HookOutput\n\n // Validate decision if present\n if (output.decision) {\n if (!['approve', 'block', 'ask'].includes(output.decision)) {\n logError(`Invalid hook decision: ${output.decision}`)\n return null\n }\n }\n\n return output\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error)\n logError(`Failed to parse hook output JSON: ${errorMsg}`)\n logDebug('Raw output:', stdout)\n return null\n }\n}\n\n/**\n * Execute all matching hooks for an event\n */\nexport async function executeHooksForEvent(\n event: HookEvent,\n hooks: LoadedHook[],\n input: HookInput,\n options: HookExecutionOptions,\n): Promise<HookExecutionResult[]> {\n // Filter hooks for this event\n const matchingHooks = hooks.filter((hook) => hook.event === event)\n\n if (matchingHooks.length === 0) {\n return []\n }\n\n logInfo(`Executing ${matchingHooks.length} hook(s) for event: ${event}`)\n\n // Execute all matching hooks in parallel (Claude Code behavior)\n const results = await Promise.all(\n matchingHooks.map((hook) => executeHook(hook, input, options)),\n )\n\n return results\n}\n\n/**\n * Process hook decisions to determine final action\n */\nexport function processHookDecisions(\n results: HookExecutionResult[],\n): {\n shouldContinue: boolean\n shouldAskUser: boolean\n reason?: string\n} {\n // If any hook says \"block\", we block\n const blockedResult = results.find(\n (r) => r.success && r.decision === 'block',\n )\n if (blockedResult) {\n return {\n shouldContinue: false,\n shouldAskUser: false,\n reason: blockedResult.output?.reason || 'Blocked by hook',\n }\n }\n\n // If any hook says \"ask\", we ask the user\n const askResult = results.find((r) => r.success && r.decision === 'ask')\n if (askResult) {\n return {\n shouldContinue: false,\n shouldAskUser: true,\n reason: askResult.output?.reason || 'Hook requested user approval',\n }\n }\n\n // If any hook failed, we ask the user (fail-safe)\n const failedResult = results.find((r) => !r.success)\n if (failedResult) {\n return {\n shouldContinue: false,\n shouldAskUser: true,\n reason: `Hook execution failed: ${failedResult.error}`,\n }\n }\n\n // All hooks approved or had no decision\n return {\n shouldContinue: true,\n shouldAskUser: false,\n }\n}\n\n/**\n * Create hook input for PreToolUse event\n */\nexport function createPreToolUseInput(\n sessionId: string,\n transcriptPath: string,\n toolName: string,\n toolInput: Record<string, unknown>,\n): PreToolUseInput {\n return {\n hook_event_name: HookEvent.PreToolUse,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n tool_name: toolName,\n tool_input: toolInput,\n }\n}\n\n/**\n * Create hook input for PostToolUse event\n */\nexport function createPostToolUseInput(\n sessionId: string,\n transcriptPath: string,\n toolName: string,\n toolInput: Record<string, unknown>,\n toolOutput: Record<string, unknown>,\n): PostToolUseInput {\n return {\n hook_event_name: HookEvent.PostToolUse,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n tool_name: toolName,\n tool_input: toolInput,\n tool_output: toolOutput,\n }\n}\n\n/**\n * Create hook input for UserPromptSubmit event\n */\nexport function createUserPromptSubmitInput(\n sessionId: string,\n transcriptPath: string,\n userPrompt: string,\n): UserPromptSubmitInput {\n return {\n hook_event_name: HookEvent.UserPromptSubmit,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n user_prompt: userPrompt,\n }\n}\n\n/**\n * Create hook input for SessionStart event\n */\nexport function createSessionStartInput(\n sessionId: string,\n transcriptPath: string,\n): SessionStartInput {\n return {\n hook_event_name: HookEvent.SessionStart,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n source: 'startup' as const,\n permission_mode: 'default',\n }\n}\n\n/**\n * Create hook input for SessionEnd event\n */\nexport function createSessionEndInput(\n sessionId: string,\n transcriptPath: string,\n reason: 'clear' | 'logout' | 'prompt_input_exit' | 'other',\n): SessionEndInput {\n return {\n hook_event_name: HookEvent.SessionEnd,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n reason: reason,\n }\n}\n"],
5
- "mappings": "AASA,SAAS,aAAa;AAGtB;AAAA,EACE;AAAA,OASK;AAEP,SAAS,cAAc;AACvB,SAAS,gBAAgB;AAGzB,MAAM,UAAU,CAAC,QAAgB;AAE/B,MAAI,QAAQ,IAAI,MAAO,SAAQ,IAAI,UAAU,GAAG,EAAE;AACpD;AACA,MAAM,WAAW,CAAC,QAAgB,SAAgB;AAChD,MAAI,QAAQ,IAAI,MAAO,SAAQ,IAAI,WAAW,GAAG,IAAI,GAAG,IAAI;AAC9D;AA0BA,eAAsB,YACpB,MACA,OACA,SAC8B;AAE9B,MAAI,KAAK,OAAO,SAAS,aAAa,CAAC,KAAK,OAAO,SAAS;AAC1D,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO,cAAc,KAAK,OAAO,IAAI;AAAA,IACvC;AAAA,EACF;AAEA,QAAM,UAAU,KAAK,OAAO,WAAW,QAAQ,WAAW;AAE1D,MAAI;AACF,aAAS,mBAAmB,KAAK,IAAI,EAAE;AACvC,aAAS,YAAY,KAAK,OAAO,OAAO,EAAE;AAG1C,UAAM,SAAS,MAAM;AAAA,MACnB,KAAK,OAAO;AAAA,MACZ;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH;AAAA,QACA,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAEA,QAAI,OAAO,UAAU;AACnB,eAAS,QAAQ,KAAK,IAAI,oBAAoB,OAAO,IAAI;AACzD,aAAO;AAAA,QACL,SAAS;AAAA,QACT,UAAU;A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Y;AAAA,IACZ,iBAAiB;AAAA,IACjB,KAAK,OAAO;AAAA,IACZ,iBAAiB;AAAA,IACjB;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["/**\n * Hook Execution Engine\n *\n * Executes plugin hooks with bash command execution, JSON I/O,\n * and decision processing (approve/block/ask).\n *\n * Fully compatible with Claude Code CLI hooks specification.\n */\n\nimport { spawn } from 'child_process'\nimport { homedir } from 'os'\nimport { join } from 'path'\nimport {\n HookEvent,\n HookInput,\n HookOutput,\n HookDecision,\n PreToolUseInput,\n PostToolUseInput,\n UserPromptSubmitInput,\n SessionStartInput,\n SessionEndInput,\n} from '../types/hooks'\nimport { LoadedHook } from '../types/plugin'\nimport { getCwd } from '../utils/state'\nimport { logError } from '../utils/log'\n\n// Simple logging helpers\nconst logInfo = (msg: string) => {\n // Only log in debug mode to reduce noise\n if (process.env.DEBUG) console.log(`[INFO] ${msg}`)\n}\nconst logDebug = (msg: string, ...args: any[]) => {\n if (process.env.DEBUG) console.log(`[DEBUG] ${msg}`, ...args)\n}\n\n/**\n * Hook execution result\n */\nexport interface HookExecutionResult {\n success: boolean\n decision?: 'approve' | 'block' | 'ask'\n output?: HookOutput\n error?: string\n timedOut?: boolean\n}\n\n/**\n * Hook execution options\n */\nexport interface HookExecutionOptions {\n timeout?: number\n sessionId: string\n transcriptPath?: string\n pluginRoot: string\n}\n\n/**\n * Execute a hook with bash command\n */\nexport async function executeHook(\n hook: LoadedHook,\n input: HookInput,\n options: HookExecutionOptions,\n): Promise<HookExecutionResult> {\n // Only execute command-type hooks\n if (hook.config.type !== 'command' || !hook.config.command) {\n return {\n success: false,\n error: `Hook type \"${hook.config.type}\" not yet implemented`,\n }\n }\n\n const timeout = hook.config.timeout || options.timeout || 30000 // 30 seconds default\n\n try {\n logDebug(`Executing hook: ${hook.name}`)\n logDebug(`Command: ${hook.config.command}`)\n\n // Execute bash command with JSON input via stdin\n const result = await executeBashCommand(hook.config.command, input, {\n ...options,\n timeout,\n pluginRoot: options.pluginRoot,\n })\n\n if (result.timedOut) {\n logError(`Hook ${hook.name} timed out after ${timeout}ms`)\n return {\n success: false,\n timedOut: true,\n error: `Hook execution timed out after ${timeout}ms`,\n }\n }\n\n if (result.error) {\n logError(`Hook ${hook.name} failed: ${result.error}`)\n return {\n success: false,\n error: result.error,\n }\n }\n\n // Parse JSON output\n const output = parseHookOutput(result.stdout)\n\n if (!output) {\n // No output means hook executed successfully but didn't return decisions\n return {\n success: true,\n }\n }\n\n logDebug(`Hook ${hook.name} output:`, output)\n\n return {\n success: true,\n decision: output.decision,\n output,\n }\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error)\n logError(`Hook ${hook.name} execution error: ${errorMsg}`)\n return {\n success: false,\n error: errorMsg,\n }\n }\n}\n\n/**\n * Execute bash command with JSON stdin/stdout\n */\nasync function executeBashCommand(\n command: string,\n input: HookInput,\n options: {\n timeout: number\n sessionId: string\n transcriptPath?: string\n pluginRoot: string\n },\n): Promise<{\n stdout: string\n stderr: string\n error?: string\n timedOut?: boolean\n}> {\n return new Promise(resolve => {\n // Prepare environment variables\n const env = {\n ...process.env,\n CLAUDE_PLUGIN_ROOT: options.pluginRoot,\n CLAUDE_SESSION_ID: options.sessionId,\n CLAUDE_CWD: getCwd(),\n CLAUDE_TRANSCRIPT_PATH: options.transcriptPath || '',\n }\n\n // Spawn bash process\n const child = spawn('bash', ['-c', command], {\n env,\n cwd: getCwd(),\n })\n\n let stdout = ''\n let stderr = ''\n let timedOut = false\n\n // Set timeout\n const timer = setTimeout(() => {\n timedOut = true\n child.kill('SIGTERM')\n setTimeout(() => {\n if (!child.killed) {\n child.kill('SIGKILL')\n }\n }, 1000)\n }, options.timeout)\n\n // Collect stdout\n child.stdout?.on('data', data => {\n stdout += data.toString()\n })\n\n // Collect stderr\n child.stderr?.on('data', data => {\n stderr += data.toString()\n })\n\n // Handle completion\n child.on('close', code => {\n clearTimeout(timer)\n\n if (timedOut) {\n resolve({\n stdout: '',\n stderr: '',\n timedOut: true,\n })\n return\n }\n\n if (code !== 0 && code !== null) {\n resolve({\n stdout,\n stderr,\n error: `Command exited with code ${code}: ${stderr}`,\n })\n return\n }\n\n resolve({\n stdout,\n stderr,\n })\n })\n\n // Handle errors\n child.on('error', error => {\n clearTimeout(timer)\n resolve({\n stdout: '',\n stderr: '',\n error: `Failed to spawn process: ${error.message}`,\n })\n })\n\n // Send JSON input via stdin\n try {\n if (child.stdin) {\n child.stdin.write(JSON.stringify(input, null, 2))\n child.stdin.end()\n }\n } catch (error) {\n clearTimeout(timer)\n child.kill()\n resolve({\n stdout: '',\n stderr: '',\n error: `Failed to write to stdin: ${error instanceof Error ? error.message : String(error)}`,\n })\n }\n })\n}\n\n/**\n * Parse hook output JSON\n */\nfunction parseHookOutput(stdout: string): HookOutput | null {\n if (!stdout.trim()) {\n return null\n }\n\n try {\n // Try to extract JSON from output (hook might print other things)\n const jsonMatch = stdout.match(/\\{[\\s\\S]*\\}/)\n if (!jsonMatch) {\n logDebug('No JSON found in hook output')\n return null\n }\n\n const output = JSON.parse(jsonMatch[0]) as HookOutput\n\n // Validate decision if present\n if (output.decision) {\n if (!['approve', 'block', 'ask'].includes(output.decision)) {\n logError(`Invalid hook decision: ${output.decision}`)\n return null\n }\n }\n\n return output\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error)\n logError(`Failed to parse hook output JSON: ${errorMsg}`)\n logDebug('Raw output:', stdout)\n return null\n }\n}\n\n/**\n * Execute all matching hooks for an event\n */\nexport async function executeHooksForEvent(\n event: HookEvent,\n hooks: LoadedHook[],\n input: HookInput,\n options: HookExecutionOptions,\n): Promise<HookExecutionResult[]> {\n // Filter hooks for this event\n const matchingHooks = hooks.filter(hook => hook.event === event)\n\n if (matchingHooks.length === 0) {\n return []\n }\n\n logInfo(`Executing ${matchingHooks.length} hook(s) for event: ${event}`)\n\n // Execute all matching hooks in parallel (Claude Code behavior)\n const results = await Promise.all(\n matchingHooks.map(hook => executeHook(hook, input, options)),\n )\n\n return results\n}\n\n/**\n * Process hook decisions to determine final action\n */\nexport function processHookDecisions(results: HookExecutionResult[]): {\n shouldContinue: boolean\n shouldAskUser: boolean\n reason?: string\n} {\n // If any hook says \"block\", we block\n const blockedResult = results.find(r => r.success && r.decision === 'block')\n if (blockedResult) {\n return {\n shouldContinue: false,\n shouldAskUser: false,\n reason: blockedResult.output?.reason || 'Blocked by hook',\n }\n }\n\n // If any hook says \"ask\", we ask the user\n const askResult = results.find(r => r.success && r.decision === 'ask')\n if (askResult) {\n return {\n shouldContinue: false,\n shouldAskUser: true,\n reason: askResult.output?.reason || 'Hook requested user approval',\n }\n }\n\n // If any hook failed, we ask the user (fail-safe)\n const failedResult = results.find(r => !r.success)\n if (failedResult) {\n return {\n shouldContinue: false,\n shouldAskUser: true,\n reason: `Hook execution failed: ${failedResult.error}`,\n }\n }\n\n // All hooks approved or had no decision\n return {\n shouldContinue: true,\n shouldAskUser: false,\n }\n}\n\n/**\n * Create hook input for PreToolUse event\n */\nexport function createPreToolUseInput(\n sessionId: string,\n transcriptPath: string,\n toolName: string,\n toolInput: Record<string, unknown>,\n): PreToolUseInput {\n return {\n hook_event_name: HookEvent.PreToolUse,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n tool_name: toolName,\n tool_input: toolInput,\n }\n}\n\n/**\n * Create hook input for PostToolUse event\n */\nexport function createPostToolUseInput(\n sessionId: string,\n transcriptPath: string,\n toolName: string,\n toolInput: Record<string, unknown>,\n toolOutput: Record<string, unknown>,\n): PostToolUseInput {\n return {\n hook_event_name: HookEvent.PostToolUse,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n tool_name: toolName,\n tool_input: toolInput,\n tool_output: toolOutput,\n }\n}\n\n/**\n * Create hook input for UserPromptSubmit event\n */\nexport function createUserPromptSubmitInput(\n sessionId: string,\n transcriptPath: string,\n userPrompt: string,\n): UserPromptSubmitInput {\n return {\n hook_event_name: HookEvent.UserPromptSubmit,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n user_prompt: userPrompt,\n }\n}\n\n/**\n * Create hook input for SessionStart event\n */\nexport function createSessionStartInput(\n sessionId: string,\n transcriptPath: string,\n): SessionStartInput {\n return {\n hook_event_name: HookEvent.SessionStart,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n source: 'startup' as const,\n permission_mode: 'default',\n }\n}\n\n/**\n * Create hook input for SessionEnd event\n */\nexport function createSessionEndInput(\n sessionId: string,\n transcriptPath: string,\n reason: 'clear' | 'logout' | 'prompt_input_exit' | 'other',\n): SessionEndInput {\n return {\n hook_event_name: HookEvent.SessionEnd,\n session_id: sessionId,\n transcript_path: transcriptPath,\n cwd: getCwd(),\n permission_mode: 'default',\n reason: reason,\n }\n}\n"],
5
+ "mappings": "AASA,SAAS,aAAa;AAGtB;AAAA,EACE;AAAA,OASK;AAEP,SAAS,cAAc;AACvB,SAAS,gBAAgB;AAGzB,MAAM,UAAU,CAAC,QAAgB;AAE/B,MAAI,QAAQ,IAAI,MAAO,SAAQ,IAAI,UAAU,GAAG,EAAE;AACpD;AACA,MAAM,WAAW,CAAC,QAAgB,SAAgB;AAChD,MAAI,QAAQ,IAAI,MAAO,SAAQ,IAAI,WAAW,GAAG,IAAI,GAAG,IAAI;AAC9D;AA0BA,eAAsB,YACpB,MACA,OACA,SAC8B;AAE9B,MAAI,KAAK,OAAO,SAAS,aAAa,CAAC,KAAK,OAAO,SAAS;AAC1D,WAAO;AAAA,MACL,SAAS;AAAA,MACT,OAAO,cAAc,KAAK,OAAO,IAAI;AAAA,IACvC;AAAA,EACF;AAEA,QAAM,UAAU,KAAK,OAAO,WAAW,QAAQ,WAAW;AAE1D,MAAI;AACF,aAAS,mBAAmB,KAAK,IAAI,EAAE;AACvC,aAAS,YAAY,KAAK,OAAO,OAAO,EAAE;AAG1C,UAAM,SAAS,MAAM,mBAAmB,KAAK,OAAO,SAAS,O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