thaddeus 1.0.18 → 1.0.27

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 (2084) hide show
  1. package/package.json +14 -5
  2. package/src/QueryEngine.js +926 -0
  3. package/src/Task.js +49 -0
  4. package/src/Tool.js +61 -0
  5. package/src/assistant/gate.js +5 -0
  6. package/src/assistant/index.js +106 -0
  7. package/src/assistant/sessionHistory.js +145 -0
  8. package/src/bootstrap/state.js +1163 -0
  9. package/src/bridge/bridgeApi.js +304 -0
  10. package/src/bridge/bridgeConfig.js +39 -0
  11. package/src/bridge/bridgeDebug.js +73 -0
  12. package/src/bridge/bridgeEnabled.js +185 -0
  13. package/src/bridge/bridgeMain.js +2289 -0
  14. package/src/bridge/bridgeMessaging.js +353 -0
  15. package/src/bridge/bridgePermissionCallbacks.js +10 -0
  16. package/src/bridge/bridgePointer.js +175 -0
  17. package/src/bridge/bridgeStatusUtil.js +105 -0
  18. package/src/bridge/bridgeUI.js +411 -0
  19. package/src/bridge/capacityWake.js +35 -0
  20. package/src/bridge/codeSessionApi.js +111 -0
  21. package/src/bridge/createSession.js +273 -0
  22. package/src/bridge/debugUtils.js +115 -0
  23. package/src/bridge/envLessBridgeConfig.js +120 -0
  24. package/src/bridge/flushGate.js +65 -0
  25. package/src/bridge/inboundAttachments.js +152 -0
  26. package/src/bridge/inboundMessages.js +63 -0
  27. package/src/bridge/initReplBridge.js +431 -0
  28. package/src/bridge/jwtUtils.js +185 -0
  29. package/src/bridge/peerSessions.js +5 -0
  30. package/src/bridge/pollConfig.js +85 -0
  31. package/src/bridge/pollConfigDefaults.js +62 -0
  32. package/src/bridge/remoteBridgeCore.js +712 -0
  33. package/src/bridge/replBridge.js +1719 -0
  34. package/src/bridge/replBridgeHandle.js +30 -0
  35. package/src/bridge/replBridgeTransport.js +236 -0
  36. package/src/bridge/sessionIdCompat.js +56 -0
  37. package/src/bridge/sessionRunner.js +421 -0
  38. package/src/bridge/trustedDevice.js +170 -0
  39. package/src/bridge/types.js +9 -0
  40. package/src/bridge/webhookSanitizer.js +6 -0
  41. package/src/bridge/workSecret.js +99 -0
  42. package/src/buddy/CompanionSprite.js +348 -0
  43. package/src/buddy/companion.js +107 -0
  44. package/src/buddy/prompt.js +33 -0
  45. package/src/buddy/sprites.js +488 -0
  46. package/src/buddy/types.js +90 -0
  47. package/src/buddy/useBuddyNotification.js +85 -0
  48. package/src/cli/bg.js +17 -0
  49. package/src/cli/exit.js +30 -0
  50. package/src/cli/handlers/agents.js +55 -0
  51. package/src/cli/handlers/auth.js +249 -0
  52. package/src/cli/handlers/autoMode.js +128 -0
  53. package/src/cli/handlers/mcp.js +335 -0
  54. package/src/cli/handlers/plugins.js +634 -0
  55. package/src/cli/handlers/templateJobs.js +19 -0
  56. package/src/cli/handlers/util.js +76 -0
  57. package/src/cli/ndjsonSafeStringify.js +27 -0
  58. package/src/cli/print.js +4294 -0
  59. package/src/cli/remoteIO.js +208 -0
  60. package/src/cli/structuredIO.js +644 -0
  61. package/src/cli/transports/HybridTransport.js +233 -0
  62. package/src/cli/transports/SSETransport.js +538 -0
  63. package/src/cli/transports/SerialBatchEventUploader.js +224 -0
  64. package/src/cli/transports/WebSocketTransport.js +613 -0
  65. package/src/cli/transports/WorkerStateUploader.js +88 -0
  66. package/src/cli/transports/ccrClient.js +711 -0
  67. package/src/cli/transports/transportUtils.js +39 -0
  68. package/src/cli/update.js +314 -0
  69. package/src/commandCenter/launch.js +39 -0
  70. package/src/commandCenter/phoneApi.js +168 -0
  71. package/src/commandCenter/phoneStore.js +159 -0
  72. package/src/commandCenter/reactorBus.js +130 -0
  73. package/src/commandCenter/server.js +288 -0
  74. package/src/commandCenter/server.ts +42 -7
  75. package/src/commandCenter/tunnel.js +199 -0
  76. package/src/commands/add-dir/add-dir.js +121 -0
  77. package/src/commands/add-dir/index.js +8 -0
  78. package/src/commands/add-dir/validation.js +76 -0
  79. package/src/commands/advisor.js +88 -0
  80. package/src/commands/agents/agents.js +10 -0
  81. package/src/commands/agents/index.js +7 -0
  82. package/src/commands/agents-platform/index.js +2 -0
  83. package/src/commands/assistant/index.js +86 -0
  84. package/src/commands/backup/index.js +31 -0
  85. package/src/commands/branch/branch.js +205 -0
  86. package/src/commands/branch/index.js +11 -0
  87. package/src/commands/bridge/bridge.js +513 -0
  88. package/src/commands/bridge/index.js +22 -0
  89. package/src/commands/bridge-kick.js +179 -0
  90. package/src/commands/brief.js +89 -0
  91. package/src/commands/btw/btw.js +235 -0
  92. package/src/commands/btw/index.js +9 -0
  93. package/src/commands/buddy/buddy.js +100 -0
  94. package/src/commands/buddy/index.js +11 -0
  95. package/src/commands/chrome/chrome.js +291 -0
  96. package/src/commands/chrome/index.js +10 -0
  97. package/src/commands/clear/caches.js +116 -0
  98. package/src/commands/clear/clear.js +5 -0
  99. package/src/commands/clear/conversation.js +189 -0
  100. package/src/commands/clear/index.js +9 -0
  101. package/src/commands/color/color.js +58 -0
  102. package/src/commands/color/index.js +9 -0
  103. package/src/commands/commit-push-pr.js +137 -0
  104. package/src/commands/commit.js +80 -0
  105. package/src/commands/compact/compact.js +194 -0
  106. package/src/commands/compact/index.js +11 -0
  107. package/src/commands/config/config.js +6 -0
  108. package/src/commands/config/index.js +8 -0
  109. package/src/commands/context/context-noninteractive.js +219 -0
  110. package/src/commands/context/context.js +45 -0
  111. package/src/commands/context/index.js +21 -0
  112. package/src/commands/coordinator.js +34 -0
  113. package/src/commands/copy/copy.js +366 -0
  114. package/src/commands/copy/index.js +7 -0
  115. package/src/commands/cost/cost.js +21 -0
  116. package/src/commands/cost/index.js +16 -0
  117. package/src/commands/createMovedToPluginCommand.js +33 -0
  118. package/src/commands/desktop/desktop.js +6 -0
  119. package/src/commands/desktop/index.js +22 -0
  120. package/src/commands/diff/diff.js +6 -0
  121. package/src/commands/diff/index.js +6 -0
  122. package/src/commands/doctor/doctor.js +6 -0
  123. package/src/commands/doctor/index.js +9 -0
  124. package/src/commands/effort/effort.js +166 -0
  125. package/src/commands/effort/index.js +11 -0
  126. package/src/commands/exit/exit.js +32 -0
  127. package/src/commands/exit/index.js +9 -0
  128. package/src/commands/export/export.js +87 -0
  129. package/src/commands/export/index.js +8 -0
  130. package/src/commands/extra-usage/extra-usage-core.js +99 -0
  131. package/src/commands/extra-usage/extra-usage-noninteractive.js +13 -0
  132. package/src/commands/extra-usage/extra-usage.js +15 -0
  133. package/src/commands/extra-usage/index.js +29 -0
  134. package/src/commands/fast/fast.js +276 -0
  135. package/src/commands/fast/index.js +19 -0
  136. package/src/commands/feedback/feedback.js +11 -0
  137. package/src/commands/feedback/index.js +20 -0
  138. package/src/commands/files/files.js +11 -0
  139. package/src/commands/files/index.js +9 -0
  140. package/src/commands/force-snip.js +19 -0
  141. package/src/commands/fork/index.js +67 -0
  142. package/src/commands/heapdump/heapdump.js +14 -0
  143. package/src/commands/heapdump/index.js +9 -0
  144. package/src/commands/help/help.js +6 -0
  145. package/src/commands/help/index.js +7 -0
  146. package/src/commands/hooks/hooks.js +12 -0
  147. package/src/commands/hooks/index.js +8 -0
  148. package/src/commands/ide/ide.js +615 -0
  149. package/src/commands/ide/index.js +8 -0
  150. package/src/commands/init-verifiers.js +258 -0
  151. package/src/commands/init.js +248 -0
  152. package/src/commands/insights.js +2554 -0
  153. package/src/commands/install-github-app/ApiKeyStep.js +230 -0
  154. package/src/commands/install-github-app/CheckExistingSecretStep.js +194 -0
  155. package/src/commands/install-github-app/CheckGitHubStep.js +16 -0
  156. package/src/commands/install-github-app/ChooseRepoStep.js +211 -0
  157. package/src/commands/install-github-app/CreatingStep.js +53 -0
  158. package/src/commands/install-github-app/ErrorStep.js +84 -0
  159. package/src/commands/install-github-app/ExistingWorkflowStep.js +105 -0
  160. package/src/commands/install-github-app/InstallAppStep.js +97 -0
  161. package/src/commands/install-github-app/OAuthFlowStep.js +190 -0
  162. package/src/commands/install-github-app/SuccessStep.js +94 -0
  163. package/src/commands/install-github-app/WarningsStep.js +71 -0
  164. package/src/commands/install-github-app/index.js +10 -0
  165. package/src/commands/install-github-app/install-github-app.js +593 -0
  166. package/src/commands/install-github-app/setupGitHubActions.js +227 -0
  167. package/src/commands/install-slack-app/index.js +9 -0
  168. package/src/commands/install-slack-app/install-slack-app.js +25 -0
  169. package/src/commands/install.js +198 -0
  170. package/src/commands/keybindings/index.js +10 -0
  171. package/src/commands/keybindings/keybindings.js +47 -0
  172. package/src/commands/login/index.js +21 -0
  173. package/src/commands/login/login.js +135 -0
  174. package/src/commands/logout/index.js +11 -0
  175. package/src/commands/logout/logout.js +75 -0
  176. package/src/commands/mcp/addCommand.js +183 -0
  177. package/src/commands/mcp/index.js +9 -0
  178. package/src/commands/mcp/mcp.js +78 -0
  179. package/src/commands/mcp/xaaIdpCommand.js +193 -0
  180. package/src/commands/memories/index.js +9 -0
  181. package/src/commands/memories/index.ts +12 -0
  182. package/src/commands/memories/memories.tsx +950 -0
  183. package/src/commands/memory/index.js +7 -0
  184. package/src/commands/memory/memory.js +71 -0
  185. package/src/commands/mobile/index.js +9 -0
  186. package/src/commands/mobile/mobile.js +279 -0
  187. package/src/commands/model/index.js +14 -0
  188. package/src/commands/model/model.js +284 -0
  189. package/src/commands/output-style/index.js +8 -0
  190. package/src/commands/output-style/output-style.js +6 -0
  191. package/src/commands/passes/index.js +17 -0
  192. package/src/commands/passes/passes.js +23 -0
  193. package/src/commands/peers/index.js +68 -0
  194. package/src/commands/permissions/index.js +8 -0
  195. package/src/commands/permissions/permissions.js +9 -0
  196. package/src/commands/plan/index.js +8 -0
  197. package/src/commands/plan/plan.js +116 -0
  198. package/src/commands/plugin/AddMarketplace.js +96 -0
  199. package/src/commands/plugin/BrowseMarketplace.js +582 -0
  200. package/src/commands/plugin/DiscoverPlugins.js +613 -0
  201. package/src/commands/plugin/ManageMarketplaces.js +583 -0
  202. package/src/commands/plugin/ManagePlugins.js +1783 -0
  203. package/src/commands/plugin/PluginErrors.js +124 -0
  204. package/src/commands/plugin/PluginOptionsDialog.js +367 -0
  205. package/src/commands/plugin/PluginOptionsFlow.js +97 -0
  206. package/src/commands/plugin/PluginSettings.js +1041 -0
  207. package/src/commands/plugin/PluginTrustWarning.js +35 -0
  208. package/src/commands/plugin/UnifiedInstalledCell.js +616 -0
  209. package/src/commands/plugin/ValidatePlugin.js +96 -0
  210. package/src/commands/plugin/index.js +10 -0
  211. package/src/commands/plugin/parseArgs.js +71 -0
  212. package/src/commands/plugin/plugin.js +6 -0
  213. package/src/commands/plugin/pluginDetailsHelpers.js +95 -0
  214. package/src/commands/plugin/usePagination.js +89 -0
  215. package/src/commands/pr_comments/index.js +49 -0
  216. package/src/commands/privacy-settings/index.js +11 -0
  217. package/src/commands/privacy-settings/privacy-settings.js +55 -0
  218. package/src/commands/proactive.js +29 -0
  219. package/src/commands/rate-limit-options/index.js +15 -0
  220. package/src/commands/rate-limit-options/rate-limit-options.js +213 -0
  221. package/src/commands/release-notes/index.js +8 -0
  222. package/src/commands/release-notes/release-notes.js +38 -0
  223. package/src/commands/reload-plugins/index.js +11 -0
  224. package/src/commands/reload-plugins/reload-plugins.js +52 -0
  225. package/src/commands/remote-env/index.js +12 -0
  226. package/src/commands/remote-env/remote-env.js +6 -0
  227. package/src/commands/remote-setup/api.js +155 -0
  228. package/src/commands/remote-setup/index.js +15 -0
  229. package/src/commands/remote-setup/remote-setup.js +150 -0
  230. package/src/commands/remoteControlServer/index.js +58 -0
  231. package/src/commands/rename/generateSessionName.js +58 -0
  232. package/src/commands/rename/index.js +9 -0
  233. package/src/commands/rename/rename.js +52 -0
  234. package/src/commands/resume/index.js +9 -0
  235. package/src/commands/resume/resume.js +239 -0
  236. package/src/commands/review/UltrareviewOverageDialog.js +97 -0
  237. package/src/commands/review/reviewRemote.js +259 -0
  238. package/src/commands/review/ultrareviewCommand.js +58 -0
  239. package/src/commands/review/ultrareviewEnabled.js +10 -0
  240. package/src/commands/review.js +53 -0
  241. package/src/commands/rewind/index.js +10 -0
  242. package/src/commands/rewind/rewind.js +7 -0
  243. package/src/commands/sandbox-toggle/index.js +41 -0
  244. package/src/commands/sandbox-toggle/sandbox-toggle.js +73 -0
  245. package/src/commands/security-review.js +231 -0
  246. package/src/commands/session/index.js +13 -0
  247. package/src/commands/session/session.js +143 -0
  248. package/src/commands/skills/index.js +7 -0
  249. package/src/commands/skills/skills.js +6 -0
  250. package/src/commands/speak.js +21 -0
  251. package/src/commands/start-business.js +1575 -0
  252. package/src/commands/start-business.ts +1581 -0
  253. package/src/commands/stats/index.js +7 -0
  254. package/src/commands/stats/stats.js +6 -0
  255. package/src/commands/status/index.js +8 -0
  256. package/src/commands/status/status.js +6 -0
  257. package/src/commands/statusline.js +22 -0
  258. package/src/commands/stickers/index.js +8 -0
  259. package/src/commands/stickers/stickers.js +14 -0
  260. package/src/commands/subscribe-pr.js +131 -0
  261. package/src/commands/tag/index.js +9 -0
  262. package/src/commands/tag/tag.js +215 -0
  263. package/src/commands/tasks/index.js +8 -0
  264. package/src/commands/tasks/tasks.js +6 -0
  265. package/src/commands/terminalSetup/index.js +18 -0
  266. package/src/commands/terminalSetup/terminalSetup.js +491 -0
  267. package/src/commands/thaddeus-usage/index.js +17 -0
  268. package/src/commands/theme/index.js +7 -0
  269. package/src/commands/theme/theme.js +51 -0
  270. package/src/commands/thinkback/index.js +9 -0
  271. package/src/commands/thinkback/thinkback.js +528 -0
  272. package/src/commands/thinkback-play/index.js +13 -0
  273. package/src/commands/thinkback-play/thinkback-play.js +34 -0
  274. package/src/commands/torch.js +122 -0
  275. package/src/commands/ultraplan.js +416 -0
  276. package/src/commands/upgrade/index.js +12 -0
  277. package/src/commands/upgrade/upgrade.js +38 -0
  278. package/src/commands/usage/index.js +7 -0
  279. package/src/commands/usage/usage.js +6 -0
  280. package/src/commands/version.js +17 -0
  281. package/src/commands/vim/index.js +8 -0
  282. package/src/commands/vim/vim.js +25 -0
  283. package/src/commands/voice/index.js +13 -0
  284. package/src/commands/voice/voice.js +44 -0
  285. package/src/commands/workflows/index.js +123 -0
  286. package/src/commands.js +614 -0
  287. package/src/commands.ts +4 -0
  288. package/src/components/AgentProgressLine.js +112 -0
  289. package/src/components/AntModelSwitchCallout.js +8 -0
  290. package/src/components/App.js +46 -0
  291. package/src/components/ApproveApiKey.js +125 -0
  292. package/src/components/AutoModeOptInDialog.js +140 -0
  293. package/src/components/AutoUpdater.js +156 -0
  294. package/src/components/AutoUpdaterWrapper.js +78 -0
  295. package/src/components/AwsAuthStatusBox.js +88 -0
  296. package/src/components/BaseTextInput.js +105 -0
  297. package/src/components/BashModeProgress.js +49 -0
  298. package/src/components/BridgeDialog.js +415 -0
  299. package/src/components/BypassPermissionsModeDialog.js +87 -0
  300. package/src/components/ChannelDowngradeDialog.js +101 -0
  301. package/src/components/ClaudeInChromeOnboarding.js +126 -0
  302. package/src/components/ClaudeMdExternalIncludesDialog.js +137 -0
  303. package/src/components/ClickableImageRef.js +65 -0
  304. package/src/components/CompactSummary.js +120 -0
  305. package/src/components/ConfigurableShortcutHint.js +35 -0
  306. package/src/components/ConsoleOAuthFlow.js +554 -0
  307. package/src/components/ContextSuggestions.js +44 -0
  308. package/src/components/ContextVisualization.js +482 -0
  309. package/src/components/CoordinatorAgentStatus.js +261 -0
  310. package/src/components/CostThresholdDialog.js +49 -0
  311. package/src/components/CtrlOToExpand.js +50 -0
  312. package/src/components/CustomSelect/SelectMulti.js +150 -0
  313. package/src/components/CustomSelect/index.js +2 -0
  314. package/src/components/CustomSelect/option-map.js +32 -0
  315. package/src/components/CustomSelect/select-input-option.js +426 -0
  316. package/src/components/CustomSelect/select-option.js +24 -0
  317. package/src/components/CustomSelect/select.js +518 -0
  318. package/src/components/CustomSelect/use-multi-select-state.js +214 -0
  319. package/src/components/CustomSelect/use-select-input.js +170 -0
  320. package/src/components/CustomSelect/use-select-navigation.js +366 -0
  321. package/src/components/CustomSelect/use-select-state.js +22 -0
  322. package/src/components/DesktopHandoff.js +195 -0
  323. package/src/components/DesktopUpsell/DesktopUpsellStartup.js +174 -0
  324. package/src/components/DevBar.js +51 -0
  325. package/src/components/DevChannelsDialog.js +104 -0
  326. package/src/components/DiagnosticsDisplay.js +91 -0
  327. package/src/components/EffortCallout.js +264 -0
  328. package/src/components/EffortIndicator.js +28 -0
  329. package/src/components/ExitFlow.js +41 -0
  330. package/src/components/ExportDialog.js +101 -0
  331. package/src/components/FallbackToolUseErrorMessage.js +116 -0
  332. package/src/components/FallbackToolUseRejectedMessage.js +17 -0
  333. package/src/components/FastIcon.js +43 -0
  334. package/src/components/Feedback.js +369 -0
  335. package/src/components/FeedbackSurvey/FeedbackSurvey.js +151 -0
  336. package/src/components/FeedbackSurvey/FeedbackSurveyView.js +104 -0
  337. package/src/components/FeedbackSurvey/TranscriptSharePrompt.js +84 -0
  338. package/src/components/FeedbackSurvey/submitTranscriptShare.js +10 -0
  339. package/src/components/FeedbackSurvey/useDebouncedDigitInput.js +51 -0
  340. package/src/components/FeedbackSurvey/useFeedbackSurvey.js +258 -0
  341. package/src/components/FeedbackSurvey/useFrustrationDetection.js +8 -0
  342. package/src/components/FeedbackSurvey/useMemorySurvey.js +191 -0
  343. package/src/components/FeedbackSurvey/usePostCompactSurvey.js +202 -0
  344. package/src/components/FeedbackSurvey/useSurveyState.js +80 -0
  345. package/src/components/FileEditToolDiff.js +167 -0
  346. package/src/components/FileEditToolUpdatedMessage.js +112 -0
  347. package/src/components/FileEditToolUseRejectedMessage.js +158 -0
  348. package/src/components/FilePathLink.js +35 -0
  349. package/src/components/FullscreenLayout.js +578 -0
  350. package/src/components/GlobalSearchDialog.js +340 -0
  351. package/src/components/HelpV2/Commands.js +66 -0
  352. package/src/components/HelpV2/General.js +25 -0
  353. package/src/components/HelpV2/HelpV2.js +186 -0
  354. package/src/components/HighlightedCode/Fallback.js +193 -0
  355. package/src/components/HighlightedCode.js +185 -0
  356. package/src/components/HistorySearchDialog.js +93 -0
  357. package/src/components/IdeAutoConnectDialog.js +154 -0
  358. package/src/components/IdeOnboardingDialog.js +175 -0
  359. package/src/components/IdeStatusIndicator.js +50 -0
  360. package/src/components/IdleReturnDialog.js +117 -0
  361. package/src/components/InterruptedByUser.js +16 -0
  362. package/src/components/InvalidConfigDialog.js +135 -0
  363. package/src/components/InvalidSettingsDialog.js +85 -0
  364. package/src/components/KeybindingWarnings.js +55 -0
  365. package/src/components/LanguagePicker.js +84 -0
  366. package/src/components/LogSelector.js +1579 -0
  367. package/src/components/LogoV2/AnimatedAsterisk.js +43 -0
  368. package/src/components/LogoV2/AnimatedClawd.js +64 -0
  369. package/src/components/LogoV2/ChannelsNotice.js +262 -0
  370. package/src/components/LogoV2/Clawd.js +33 -0
  371. package/src/components/LogoV2/CondensedLogo.js +160 -0
  372. package/src/components/LogoV2/EmergencyTip.js +48 -0
  373. package/src/components/LogoV2/Feed.js +85 -0
  374. package/src/components/LogoV2/FeedColumn.js +55 -0
  375. package/src/components/LogoV2/GuestPassesUpsell.js +71 -0
  376. package/src/components/LogoV2/LogoV2.js +565 -0
  377. package/src/components/LogoV2/Opus1mMergeNotice.js +57 -0
  378. package/src/components/LogoV2/OverageCreditUpsell.js +161 -0
  379. package/src/components/LogoV2/VoiceModeNotice.js +71 -0
  380. package/src/components/LogoV2/WelcomeV2.js +14 -0
  381. package/src/components/LogoV2/feedConfigs.js +79 -0
  382. package/src/components/LspRecommendation/LspRecommendationMenu.js +46 -0
  383. package/src/components/MCPServerApprovalDialog.js +114 -0
  384. package/src/components/MCPServerDesktopImportDialog.js +206 -0
  385. package/src/components/MCPServerDialogCopy.js +16 -0
  386. package/src/components/MCPServerMultiselectDialog.js +134 -0
  387. package/src/components/ManagedSettingsSecurityDialog/ManagedSettingsSecurityDialog.js +150 -0
  388. package/src/components/ManagedSettingsSecurityDialog/utils.js +105 -0
  389. package/src/components/Markdown.js +233 -0
  390. package/src/components/MarkdownTable.js +280 -0
  391. package/src/components/MemoryUsageIndicator.js +28 -0
  392. package/src/components/Message.js +564 -0
  393. package/src/components/MessageModel.js +37 -0
  394. package/src/components/MessageResponse.js +73 -0
  395. package/src/components/MessageRow.js +346 -0
  396. package/src/components/MessageSelector.js +744 -0
  397. package/src/components/MessageTimestamp.js +58 -0
  398. package/src/components/Messages.js +645 -0
  399. package/src/components/ModelPicker.js +452 -0
  400. package/src/components/NativeAutoUpdater.js +152 -0
  401. package/src/components/NotebookEditToolUseRejectedMessage.js +84 -0
  402. package/src/components/OffscreenFreeze.js +35 -0
  403. package/src/components/Onboarding.js +174 -0
  404. package/src/components/OutputStylePicker.js +103 -0
  405. package/src/components/PackageManagerAutoUpdater.js +99 -0
  406. package/src/components/Passes/Passes.js +114 -0
  407. package/src/components/PrBadge.js +91 -0
  408. package/src/components/PressEnterToContinue.js +16 -0
  409. package/src/components/PromptInput/HistorySearchInput.js +45 -0
  410. package/src/components/PromptInput/IssueFlagBanner.js +8 -0
  411. package/src/components/PromptInput/Notifications.js +220 -0
  412. package/src/components/PromptInput/PromptInput.js +2014 -0
  413. package/src/components/PromptInput/PromptInputFooter.js +85 -0
  414. package/src/components/PromptInput/PromptInputFooterLeftSide.js +408 -0
  415. package/src/components/PromptInput/PromptInputFooterSuggestions.js +281 -0
  416. package/src/components/PromptInput/PromptInputHelpMenu.js +380 -0
  417. package/src/components/PromptInput/PromptInputModeIndicator.js +73 -0
  418. package/src/components/PromptInput/PromptInputQueuedCommands.js +105 -0
  419. package/src/components/PromptInput/PromptInputStashNotice.js +21 -0
  420. package/src/components/PromptInput/SandboxPromptFooterHint.js +66 -0
  421. package/src/components/PromptInput/ShimmeredInput.js +133 -0
  422. package/src/components/PromptInput/VoiceIndicator.js +137 -0
  423. package/src/components/PromptInput/inputModes.js +24 -0
  424. package/src/components/PromptInput/inputPaste.js +62 -0
  425. package/src/components/PromptInput/useMaybeTruncateInput.js +33 -0
  426. package/src/components/PromptInput/usePromptInputPlaceholder.js +53 -0
  427. package/src/components/PromptInput/useShowFastIconHint.js +23 -0
  428. package/src/components/PromptInput/useSwarmBanner.js +112 -0
  429. package/src/components/PromptInput/utils.js +50 -0
  430. package/src/components/QuickOpenDialog.js +244 -0
  431. package/src/components/RemoteCallout.js +53 -0
  432. package/src/components/RemoteEnvironmentDialog.js +346 -0
  433. package/src/components/ResumeTask.js +173 -0
  434. package/src/components/SandboxViolationExpandedView.js +106 -0
  435. package/src/components/SandboxViolationExpandedView.tsx +3 -0
  436. package/src/components/ScrollKeybindingHandler.js +982 -0
  437. package/src/components/SearchBox.js +56 -0
  438. package/src/components/SentryErrorBoundary.js +16 -0
  439. package/src/components/SessionBackgroundHint.js +105 -0
  440. package/src/components/SessionPreview.js +200 -0
  441. package/src/components/Settings/Config.js +1626 -0
  442. package/src/components/Settings/Settings.js +131 -0
  443. package/src/components/Settings/Status.js +230 -0
  444. package/src/components/Settings/Usage.js +341 -0
  445. package/src/components/ShowInIDEPrompt.js +152 -0
  446. package/src/components/SkillImprovementSurvey.js +130 -0
  447. package/src/components/Spinner/FlashingChar.js +52 -0
  448. package/src/components/Spinner/GlimmerMessage.js +329 -0
  449. package/src/components/Spinner/ShimmerChar.js +23 -0
  450. package/src/components/Spinner/SpinnerAnimationRow.js +170 -0
  451. package/src/components/Spinner/SpinnerGlyph.js +70 -0
  452. package/src/components/Spinner/TeammateSpinnerLine.js +171 -0
  453. package/src/components/Spinner/TeammateSpinnerTree.js +269 -0
  454. package/src/components/Spinner/index.js +9 -0
  455. package/src/components/Spinner/teammateSelectHint.js +1 -0
  456. package/src/components/Spinner/useShimmerAnimation.js +22 -0
  457. package/src/components/Spinner/useStalledAnimation.js +63 -0
  458. package/src/components/Spinner/utils.js +78 -0
  459. package/src/components/Spinner.js +474 -0
  460. package/src/components/Stats.js +1000 -0
  461. package/src/components/StatusLine.js +286 -0
  462. package/src/components/StatusNotices.js +50 -0
  463. package/src/components/StructuredDiff/Fallback.js +336 -0
  464. package/src/components/StructuredDiff/colorDiff.js +37 -0
  465. package/src/components/StructuredDiff.js +153 -0
  466. package/src/components/StructuredDiffList.js +9 -0
  467. package/src/components/TagTabs.js +101 -0
  468. package/src/components/TaskListV2.js +333 -0
  469. package/src/components/TeammateViewHeader.js +88 -0
  470. package/src/components/TeleportError.js +191 -0
  471. package/src/components/TeleportProgress.js +131 -0
  472. package/src/components/TeleportRepoMismatchDialog.js +98 -0
  473. package/src/components/TeleportResumeWrapper.js +158 -0
  474. package/src/components/TeleportStash.js +82 -0
  475. package/src/components/TextInput.js +108 -0
  476. package/src/components/ThaddeusHint/PluginHintMenu.js +37 -0
  477. package/src/components/ThemePicker.js +331 -0
  478. package/src/components/ThinkingToggle.js +154 -0
  479. package/src/components/TokenWarning.js +171 -0
  480. package/src/components/ToolUseLoader.js +35 -0
  481. package/src/components/TrustDialog/TrustDialog.js +301 -0
  482. package/src/components/TrustDialog/utils.js +199 -0
  483. package/src/components/UndercoverAutoCallout.js +5 -0
  484. package/src/components/ValidationErrorsList.js +147 -0
  485. package/src/components/VimTextInput.js +136 -0
  486. package/src/components/VirtualMessageList.js +893 -0
  487. package/src/components/WorkflowMultiselectDialog.js +118 -0
  488. package/src/components/WorktreeExitDialog.js +220 -0
  489. package/src/components/agents/AgentDetail.js +227 -0
  490. package/src/components/agents/AgentEditor.js +147 -0
  491. package/src/components/agents/AgentNavigationFooter.js +22 -0
  492. package/src/components/agents/AgentsList.js +436 -0
  493. package/src/components/agents/AgentsMenu.js +849 -0
  494. package/src/components/agents/ColorPicker.js +110 -0
  495. package/src/components/agents/ModelSelector.js +63 -0
  496. package/src/components/agents/SnapshotUpdateDialog.js +14 -0
  497. package/src/components/agents/ToolSelector.js +557 -0
  498. package/src/components/agents/agentFileUtils.js +179 -0
  499. package/src/components/agents/generateAgent.js +161 -0
  500. package/src/components/agents/new-agent-creation/CreateAgentWizard.js +89 -0
  501. package/src/components/agents/new-agent-creation/wizard-steps/ColorStep.js +81 -0
  502. package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStep.js +387 -0
  503. package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.js +63 -0
  504. package/src/components/agents/new-agent-creation/wizard-steps/DescriptionStep.js +126 -0
  505. package/src/components/agents/new-agent-creation/wizard-steps/GenerateStep.js +118 -0
  506. package/src/components/agents/new-agent-creation/wizard-steps/LocationStep.js +80 -0
  507. package/src/components/agents/new-agent-creation/wizard-steps/MemoryStep.js +108 -0
  508. package/src/components/agents/new-agent-creation/wizard-steps/MethodStep.js +80 -0
  509. package/src/components/agents/new-agent-creation/wizard-steps/ModelStep.js +49 -0
  510. package/src/components/agents/new-agent-creation/wizard-steps/PromptStep.js +131 -0
  511. package/src/components/agents/new-agent-creation/wizard-steps/ToolsStep.js +52 -0
  512. package/src/components/agents/new-agent-creation/wizard-steps/TypeStep.js +100 -0
  513. package/src/components/agents/types.js +4 -0
  514. package/src/components/agents/utils.js +14 -0
  515. package/src/components/agents/validateAgent.js +79 -0
  516. package/src/components/design-system/Byline.js +72 -0
  517. package/src/components/design-system/Dialog.js +117 -0
  518. package/src/components/design-system/Divider.js +110 -0
  519. package/src/components/design-system/FuzzyPicker.js +191 -0
  520. package/src/components/design-system/KeyboardShortcutHint.js +68 -0
  521. package/src/components/design-system/ListItem.js +184 -0
  522. package/src/components/design-system/LoadingState.js +69 -0
  523. package/src/components/design-system/Pane.js +69 -0
  524. package/src/components/design-system/ProgressBar.js +63 -0
  525. package/src/components/design-system/Ratchet.js +71 -0
  526. package/src/components/design-system/StatusIcon.js +70 -0
  527. package/src/components/design-system/Tabs.js +269 -0
  528. package/src/components/design-system/ThemeProvider.js +137 -0
  529. package/src/components/design-system/ThemedBox.js +126 -0
  530. package/src/components/design-system/ThemedText.js +60 -0
  531. package/src/components/design-system/color.js +22 -0
  532. package/src/components/diff/DiffDetailView.js +285 -0
  533. package/src/components/diff/DiffDialog.js +387 -0
  534. package/src/components/diff/DiffFileList.js +292 -0
  535. package/src/components/grove/Grove.js +483 -0
  536. package/src/components/hooks/HooksConfigMenu.js +583 -0
  537. package/src/components/hooks/PromptDialog.js +82 -0
  538. package/src/components/hooks/SelectEventMode.js +118 -0
  539. package/src/components/hooks/SelectHookMode.js +101 -0
  540. package/src/components/hooks/SelectMatcherMode.js +131 -0
  541. package/src/components/hooks/ViewHookMode.js +204 -0
  542. package/src/components/mcp/CapabilitiesSection.js +56 -0
  543. package/src/components/mcp/ElicitationDialog.js +945 -0
  544. package/src/components/mcp/MCPAgentServerMenu.js +95 -0
  545. package/src/components/mcp/MCPListPanel.js +505 -0
  546. package/src/components/mcp/MCPReconnect.js +168 -0
  547. package/src/components/mcp/MCPRemoteServerMenu.js +460 -0
  548. package/src/components/mcp/MCPSettings.js +414 -0
  549. package/src/components/mcp/MCPStdioServerMenu.js +95 -0
  550. package/src/components/mcp/MCPToolDetailView.js +219 -0
  551. package/src/components/mcp/MCPToolListView.js +137 -0
  552. package/src/components/mcp/McpParsingWarnings.js +212 -0
  553. package/src/components/mcp/index.js +8 -0
  554. package/src/components/mcp/utils/reconnectHelpers.js +35 -0
  555. package/src/components/memory/MemoryFileSelector.js +454 -0
  556. package/src/components/memory/MemoryUpdateNotification.js +43 -0
  557. package/src/components/messageActions.js +418 -0
  558. package/src/components/messages/AdvisorMessage.js +152 -0
  559. package/src/components/messages/AssistantRedactedThinkingMessage.js +28 -0
  560. package/src/components/messages/AssistantTextMessage.js +287 -0
  561. package/src/components/messages/AssistantThinkingMessage.js +70 -0
  562. package/src/components/messages/AssistantToolUseMessage.js +324 -0
  563. package/src/components/messages/AttachmentMessage.js +418 -0
  564. package/src/components/messages/CollapsedReadSearchContent.js +363 -0
  565. package/src/components/messages/CompactBoundaryMessage.js +19 -0
  566. package/src/components/messages/GroupedToolUseContent.js +37 -0
  567. package/src/components/messages/HighlightedThinkingText.js +165 -0
  568. package/src/components/messages/HookProgressMessage.js +111 -0
  569. package/src/components/messages/PlanApprovalMessage.js +213 -0
  570. package/src/components/messages/RateLimitMessage.js +149 -0
  571. package/src/components/messages/ShutdownMessage.js +124 -0
  572. package/src/components/messages/SnipBoundaryMessage.js +7 -0
  573. package/src/components/messages/SystemAPIErrorMessage.js +136 -0
  574. package/src/components/messages/SystemTextMessage.js +842 -0
  575. package/src/components/messages/TaskAssignmentMessage.js +72 -0
  576. package/src/components/messages/UserAgentNotificationMessage.js +78 -0
  577. package/src/components/messages/UserBashInputMessage.js +52 -0
  578. package/src/components/messages/UserBashOutputMessage.js +55 -0
  579. package/src/components/messages/UserChannelMessage.js +130 -0
  580. package/src/components/messages/UserCommandMessage.js +107 -0
  581. package/src/components/messages/UserCrossSessionMessage.js +11 -0
  582. package/src/components/messages/UserForkBoilerplateMessage.js +11 -0
  583. package/src/components/messages/UserGitHubWebhookMessage.js +12 -0
  584. package/src/components/messages/UserImageMessage.js +54 -0
  585. package/src/components/messages/UserLocalCommandOutputMessage.js +170 -0
  586. package/src/components/messages/UserMemoryInputMessage.js +73 -0
  587. package/src/components/messages/UserPlanMessage.js +38 -0
  588. package/src/components/messages/UserPromptMessage.js +63 -0
  589. package/src/components/messages/UserResourceUpdateMessage.js +102 -0
  590. package/src/components/messages/UserTeammateMessage.js +156 -0
  591. package/src/components/messages/UserTextMessage.js +270 -0
  592. package/src/components/messages/UserToolResultMessage/RejectedPlanMessage.js +28 -0
  593. package/src/components/messages/UserToolResultMessage/RejectedToolUseMessage.js +17 -0
  594. package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.js +17 -0
  595. package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.js +92 -0
  596. package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.js +74 -0
  597. package/src/components/messages/UserToolResultMessage/UserToolResultMessage.js +84 -0
  598. package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +58 -0
  599. package/src/components/messages/UserToolResultMessage/utils.js +43 -0
  600. package/src/components/messages/nullRenderingAttachments.js +58 -0
  601. package/src/components/messages/teamMemCollapsed.js +142 -0
  602. package/src/components/messages/teamMemSaved.js +16 -0
  603. package/src/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.js +659 -0
  604. package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.js +219 -0
  605. package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.js +227 -0
  606. package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.js +175 -0
  607. package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionView.js +444 -0
  608. package/src/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.js +137 -0
  609. package/src/components/permissions/AskUserQuestionPermissionRequest/use-multiple-choice-state.js +100 -0
  610. package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.js +404 -0
  611. package/src/components/permissions/BashPermissionRequest/bashToolUseOptions.js +110 -0
  612. package/src/components/permissions/ComputerUseApproval/ComputerUseApproval.js +449 -0
  613. package/src/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.js +126 -0
  614. package/src/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.js +653 -0
  615. package/src/components/permissions/FallbackPermissionRequest.js +349 -0
  616. package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +185 -0
  617. package/src/components/permissions/FilePermissionDialog/FilePermissionDialog.js +108 -0
  618. package/src/components/permissions/FilePermissionDialog/ideDiffConfig.js +13 -0
  619. package/src/components/permissions/FilePermissionDialog/permissionOptions.js +137 -0
  620. package/src/components/permissions/FilePermissionDialog/useFilePermissionDialog.js +131 -0
  621. package/src/components/permissions/FilePermissionDialog/usePermissionHandler.js +86 -0
  622. package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +164 -0
  623. package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +79 -0
  624. package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +113 -0
  625. package/src/components/permissions/MonitorPermissionRequest/MonitorPermissionRequest.js +7 -0
  626. package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.js +164 -0
  627. package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.js +218 -0
  628. package/src/components/permissions/PermissionDecisionDebugInfo.js +467 -0
  629. package/src/components/permissions/PermissionDialog.js +55 -0
  630. package/src/components/permissions/PermissionExplanation.js +269 -0
  631. package/src/components/permissions/PermissionPrompt.js +316 -0
  632. package/src/components/permissions/PermissionRequest.js +159 -0
  633. package/src/components/permissions/PermissionRequestTitle.js +58 -0
  634. package/src/components/permissions/PermissionRuleExplanation.js +110 -0
  635. package/src/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.js +178 -0
  636. package/src/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.js +73 -0
  637. package/src/components/permissions/ReviewArtifactPermissionRequest/ReviewArtifactPermissionRequest.js +7 -0
  638. package/src/components/permissions/SandboxPermissionRequest.js +162 -0
  639. package/src/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.js +228 -0
  640. package/src/components/permissions/SkillPermissionRequest/SkillPermissionRequest.js +385 -0
  641. package/src/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.js +259 -0
  642. package/src/components/permissions/WorkerBadge.js +44 -0
  643. package/src/components/permissions/WorkerPendingPermission.js +107 -0
  644. package/src/components/permissions/hooks.js +163 -0
  645. package/src/components/permissions/rules/AddPermissionRules.js +171 -0
  646. package/src/components/permissions/rules/AddWorkspaceDirectory.js +335 -0
  647. package/src/components/permissions/rules/PermissionRuleDescription.js +78 -0
  648. package/src/components/permissions/rules/PermissionRuleInput.js +136 -0
  649. package/src/components/permissions/rules/PermissionRuleList.js +1190 -0
  650. package/src/components/permissions/rules/RecentDenialsTab.js +205 -0
  651. package/src/components/permissions/rules/RemoveWorkspaceDirectory.js +103 -0
  652. package/src/components/permissions/rules/WorkspaceTab.js +133 -0
  653. package/src/components/permissions/shellPermissionHelpers.js +112 -0
  654. package/src/components/permissions/useShellPermissionFeedback.js +108 -0
  655. package/src/components/permissions/utils.js +14 -0
  656. package/src/components/sandbox/SandboxConfigTab.js +48 -0
  657. package/src/components/sandbox/SandboxDependenciesTab.js +123 -0
  658. package/src/components/sandbox/SandboxDoctorSection.js +47 -0
  659. package/src/components/sandbox/SandboxOverridesTab.js +193 -0
  660. package/src/components/sandbox/SandboxSettings.js +297 -0
  661. package/src/components/shell/ExpandShellOutputContext.js +33 -0
  662. package/src/components/shell/OutputLine.js +110 -0
  663. package/src/components/shell/ShellProgressMessage.js +144 -0
  664. package/src/components/shell/ShellTimeDisplay.js +72 -0
  665. package/src/components/skills/SkillsMenu.js +239 -0
  666. package/src/components/tasks/AsyncAgentDetailDialog.js +235 -0
  667. package/src/components/tasks/BackgroundTask.js +364 -0
  668. package/src/components/tasks/BackgroundTaskStatus.js +419 -0
  669. package/src/components/tasks/BackgroundTasksDialog.js +494 -0
  670. package/src/components/tasks/DreamDetailDialog.js +251 -0
  671. package/src/components/tasks/InProcessTeammateDetailDialog.js +275 -0
  672. package/src/components/tasks/MonitorMcpDetailDialog.js +7 -0
  673. package/src/components/tasks/RemoteSessionDetailDialog.js +868 -0
  674. package/src/components/tasks/RemoteSessionProgress.js +249 -0
  675. package/src/components/tasks/ShellDetailDialog.js +403 -0
  676. package/src/components/tasks/ShellProgress.js +77 -0
  677. package/src/components/tasks/WorkflowDetailDialog.js +7 -0
  678. package/src/components/tasks/renderToolActivity.js +29 -0
  679. package/src/components/tasks/taskStatusUtils.js +94 -0
  680. package/src/components/teams/TeamStatus.js +77 -0
  681. package/src/components/teams/TeamsDialog.js +673 -0
  682. package/src/components/ui/OrderedList.js +66 -0
  683. package/src/components/ui/OrderedListItem.js +41 -0
  684. package/src/components/ui/TreeSelect.js +300 -0
  685. package/src/components/wizard/WizardDialogLayout.js +48 -0
  686. package/src/components/wizard/WizardNavigationFooter.js +11 -0
  687. package/src/components/wizard/WizardProvider.js +217 -0
  688. package/src/components/wizard/index.js +4 -0
  689. package/src/components/wizard/useWizard.js +9 -0
  690. package/src/constants/apiLimits.js +81 -0
  691. package/src/constants/betas.js +45 -0
  692. package/src/constants/common.js +29 -0
  693. package/src/constants/cyberRiskInstruction.js +23 -0
  694. package/src/constants/errorIds.js +14 -0
  695. package/src/constants/figures.js +38 -0
  696. package/src/constants/files.js +150 -0
  697. package/src/constants/github-app.js +139 -0
  698. package/src/constants/identity.js +112 -0
  699. package/src/constants/keys.js +10 -0
  700. package/src/constants/messages.js +1 -0
  701. package/src/constants/oauth.js +175 -0
  702. package/src/constants/outputStyles.js +162 -0
  703. package/src/constants/product.js +54 -0
  704. package/src/constants/prompts.js +994 -0
  705. package/src/constants/spinnerVerbs.js +98 -0
  706. package/src/constants/system.js +77 -0
  707. package/src/constants/systemPromptSections.js +39 -0
  708. package/src/constants/toolLimits.js +50 -0
  709. package/src/constants/tools.js +103 -0
  710. package/src/constants/turnCompletionVerbs.js +12 -0
  711. package/src/constants/xml.js +73 -0
  712. package/src/context/QueuedMessageContext.js +51 -0
  713. package/src/context/fpsMetrics.js +22 -0
  714. package/src/context/mailbox.js +35 -0
  715. package/src/context/modalContext.js +34 -0
  716. package/src/context/notifications.js +199 -0
  717. package/src/context/overlayContext.js +149 -0
  718. package/src/context/promptOverlayContext.js +118 -0
  719. package/src/context/stats.js +207 -0
  720. package/src/context/voice.js +74 -0
  721. package/src/context.js +146 -0
  722. package/src/coordinator/coordinatorMode.js +345 -0
  723. package/src/coordinator/workerAgent.js +24 -0
  724. package/src/cost-tracker.js +208 -0
  725. package/src/costHook.js +17 -0
  726. package/src/daemon/main.js +19 -0
  727. package/src/dialogLaunchers.js +77 -0
  728. package/src/entrypoints/agentSdkTypes.js +202 -0
  729. package/src/entrypoints/cli.js +226 -0
  730. package/src/entrypoints/init.js +265 -0
  731. package/src/entrypoints/mcp.js +141 -0
  732. package/src/entrypoints/sandboxTypes.js +112 -0
  733. package/src/entrypoints/sdk/controlSchemas.js +452 -0
  734. package/src/entrypoints/sdk/controlTypes.js +1 -0
  735. package/src/entrypoints/sdk/coreSchemas.js +1331 -0
  736. package/src/entrypoints/sdk/coreTypes.generated.js +3 -0
  737. package/src/entrypoints/sdk/coreTypes.js +49 -0
  738. package/src/entrypoints/sdk/runtimeTypes.js +1 -0
  739. package/src/entrypoints/sdk/sdkUtilityTypes.js +1 -0
  740. package/src/entrypoints/sdk/settingsTypes.generated.js +1 -0
  741. package/src/entrypoints/sdk/toolTypes.js +1 -0
  742. package/src/environment-runner/main.js +8 -0
  743. package/src/history.js +386 -0
  744. package/src/hooks/fileSuggestions.js +635 -0
  745. package/src/hooks/notifs/useAntOrgWarningNotification.js +5 -0
  746. package/src/hooks/notifs/useAutoModeUnavailableNotification.js +47 -0
  747. package/src/hooks/notifs/useCanSwitchToExistingSubscription.js +58 -0
  748. package/src/hooks/notifs/useDeprecationWarningNotification.js +43 -0
  749. package/src/hooks/notifs/useFastModeNotification.js +164 -0
  750. package/src/hooks/notifs/useIDEStatusIndicator.js +174 -0
  751. package/src/hooks/notifs/useInstallMessages.js +27 -0
  752. package/src/hooks/notifs/useLspInitializationNotification.js +144 -0
  753. package/src/hooks/notifs/useMcpConnectivityStatus.js +81 -0
  754. package/src/hooks/notifs/useModelMigrationNotifications.js +53 -0
  755. package/src/hooks/notifs/useNpmDeprecationNotification.js +25 -0
  756. package/src/hooks/notifs/usePluginAutoupdateNotification.js +83 -0
  757. package/src/hooks/notifs/usePluginInstallationStatus.js +128 -0
  758. package/src/hooks/notifs/useRateLimitWarningNotification.js +119 -0
  759. package/src/hooks/notifs/useSettingsErrors.js +64 -0
  760. package/src/hooks/notifs/useStartupNotification.js +33 -0
  761. package/src/hooks/notifs/useTeammateShutdownNotification.js +64 -0
  762. package/src/hooks/renderPlaceholder.js +26 -0
  763. package/src/hooks/toolPermission/PermissionContext.js +211 -0
  764. package/src/hooks/toolPermission/handlers/coordinatorHandler.js +44 -0
  765. package/src/hooks/toolPermission/handlers/interactiveHandler.js +397 -0
  766. package/src/hooks/toolPermission/handlers/swarmWorkerHandler.js +108 -0
  767. package/src/hooks/toolPermission/permissionLogging.js +145 -0
  768. package/src/hooks/unifiedSuggestions.js +130 -0
  769. package/src/hooks/useAfterFirstRender.js +12 -0
  770. package/src/hooks/useApiKeyVerification.js +63 -0
  771. package/src/hooks/useArrowKeyHistory.js +203 -0
  772. package/src/hooks/useAssistantHistory.js +193 -0
  773. package/src/hooks/useAwaySummary.js +105 -0
  774. package/src/hooks/useBackgroundTaskNavigation.js +204 -0
  775. package/src/hooks/useBlink.js +28 -0
  776. package/src/hooks/useCanUseTool.js +193 -0
  777. package/src/hooks/useCancelRequest.js +195 -0
  778. package/src/hooks/useChromeExtensionNotification.js +50 -0
  779. package/src/hooks/useClipboardImageHint.js +59 -0
  780. package/src/hooks/useCommandKeybindings.js +87 -0
  781. package/src/hooks/useCommandQueue.js +10 -0
  782. package/src/hooks/useCopyOnSelect.js +88 -0
  783. package/src/hooks/useDeferredHookMessages.js +43 -0
  784. package/src/hooks/useDiffData.js +69 -0
  785. package/src/hooks/useDiffInIDE.js +252 -0
  786. package/src/hooks/useDirectConnect.js +150 -0
  787. package/src/hooks/useDoublePress.js +44 -0
  788. package/src/hooks/useDynamicConfig.js +17 -0
  789. package/src/hooks/useElapsedTime.js +25 -0
  790. package/src/hooks/useExitOnCtrlCD.js +57 -0
  791. package/src/hooks/useExitOnCtrlCDWithKeybindings.js +17 -0
  792. package/src/hooks/useFileHistorySnapshotInit.js +14 -0
  793. package/src/hooks/useGlobalKeybindings.js +213 -0
  794. package/src/hooks/useHistorySearch.js +241 -0
  795. package/src/hooks/useIDEIntegration.js +56 -0
  796. package/src/hooks/useIdeAtMentioned.js +51 -0
  797. package/src/hooks/useIdeConnectionStatus.js +21 -0
  798. package/src/hooks/useIdeLogging.js +29 -0
  799. package/src/hooks/useIdeSelection.js +106 -0
  800. package/src/hooks/useInboxPoller.js +709 -0
  801. package/src/hooks/useInputBuffer.js +73 -0
  802. package/src/hooks/useIssueFlagBanner.js +115 -0
  803. package/src/hooks/useLogMessages.js +98 -0
  804. package/src/hooks/useLspPluginRecommendation.js +176 -0
  805. package/src/hooks/useMailboxBridge.js +15 -0
  806. package/src/hooks/useMainLoopModel.js +25 -0
  807. package/src/hooks/useManagePlugins.js +261 -0
  808. package/src/hooks/useMemoryUsage.js +28 -0
  809. package/src/hooks/useMergedClients.js +11 -0
  810. package/src/hooks/useMergedCommands.js +10 -0
  811. package/src/hooks/useMergedTools.js +32 -0
  812. package/src/hooks/useMinDisplayTime.js +26 -0
  813. package/src/hooks/useNotifyAfterTimeout.js +51 -0
  814. package/src/hooks/useOfficialMarketplaceNotification.js +47 -0
  815. package/src/hooks/usePasteHandler.js +195 -0
  816. package/src/hooks/usePluginRecommendationBase.js +101 -0
  817. package/src/hooks/usePrStatus.js +91 -0
  818. package/src/hooks/usePromptSuggestion.js +128 -0
  819. package/src/hooks/usePromptsFromClaudeInChrome.js +66 -0
  820. package/src/hooks/useQueueProcessor.js +46 -0
  821. package/src/hooks/useRemoteSession.js +431 -0
  822. package/src/hooks/useReplBridge.js +715 -0
  823. package/src/hooks/useSSHSession.js +167 -0
  824. package/src/hooks/useScheduledTasks.js +104 -0
  825. package/src/hooks/useSearchInput.js +302 -0
  826. package/src/hooks/useSessionBackgrounding.js +132 -0
  827. package/src/hooks/useSettings.js +10 -0
  828. package/src/hooks/useSettingsChange.js +13 -0
  829. package/src/hooks/useSkillImprovementSurvey.js +69 -0
  830. package/src/hooks/useSkillsChange.js +51 -0
  831. package/src/hooks/useSwarmInitialization.js +67 -0
  832. package/src/hooks/useSwarmPermissionPoller.js +215 -0
  833. package/src/hooks/useTaskListWatcher.js +157 -0
  834. package/src/hooks/useTasksV2.js +220 -0
  835. package/src/hooks/useTeammateViewAutoExit.js +55 -0
  836. package/src/hooks/useTeleportResume.js +81 -0
  837. package/src/hooks/useTerminalSize.js +9 -0
  838. package/src/hooks/useTextInput.js +397 -0
  839. package/src/hooks/useThaddeusHintRecommendation.js +117 -0
  840. package/src/hooks/useTimeout.js +10 -0
  841. package/src/hooks/useTurnDiffs.js +160 -0
  842. package/src/hooks/useTypeahead.js +1250 -0
  843. package/src/hooks/useUpdateNotification.js +21 -0
  844. package/src/hooks/useVimInput.js +232 -0
  845. package/src/hooks/useVirtualScroll.js +627 -0
  846. package/src/hooks/useVoice.js +952 -0
  847. package/src/hooks/useVoiceEnabled.js +21 -0
  848. package/src/hooks/useVoiceIntegration.js +629 -0
  849. package/src/infrastructure/audit.js +210 -0
  850. package/src/infrastructure/guardrails.js +513 -0
  851. package/src/infrastructure/index.js +11 -0
  852. package/src/ink/Ansi.js +269 -0
  853. package/src/ink/bidi.js +117 -0
  854. package/src/ink/clearTerminal.js +58 -0
  855. package/src/ink/colorize.js +198 -0
  856. package/src/ink/components/AlternateScreen.js +74 -0
  857. package/src/ink/components/App.js +562 -0
  858. package/src/ink/components/AppContext.js +11 -0
  859. package/src/ink/components/Box.js +155 -0
  860. package/src/ink/components/Button.js +166 -0
  861. package/src/ink/components/ClockContext.js +108 -0
  862. package/src/ink/components/CursorDeclarationContext.js +3 -0
  863. package/src/ink/components/ErrorOverview.js +50 -0
  864. package/src/ink/components/Link.js +34 -0
  865. package/src/ink/components/Newline.js +30 -0
  866. package/src/ink/components/NoSelect.js +57 -0
  867. package/src/ink/components/RawAnsi.js +46 -0
  868. package/src/ink/components/ScrollBox.js +171 -0
  869. package/src/ink/components/Spacer.js +20 -0
  870. package/src/ink/components/StdinContext.js +16 -0
  871. package/src/ink/components/TerminalFocusContext.js +45 -0
  872. package/src/ink/components/TerminalSizeContext.js +3 -0
  873. package/src/ink/components/Text.js +195 -0
  874. package/src/ink/constants.js +2 -0
  875. package/src/ink/dom.js +298 -0
  876. package/src/ink/events/click-event.js +36 -0
  877. package/src/ink/events/dispatcher.js +172 -0
  878. package/src/ink/events/emitter.js +31 -0
  879. package/src/ink/events/event-handlers.js +30 -0
  880. package/src/ink/events/event.js +9 -0
  881. package/src/ink/events/focus-event.js +16 -0
  882. package/src/ink/events/input-event.js +161 -0
  883. package/src/ink/events/keyboard-event.js +46 -0
  884. package/src/ink/events/terminal-event.js +78 -0
  885. package/src/ink/events/terminal-focus-event.js +15 -0
  886. package/src/ink/focus.js +158 -0
  887. package/src/ink/frame.js +30 -0
  888. package/src/ink/get-max-width.js +23 -0
  889. package/src/ink/hit-test.js +113 -0
  890. package/src/ink/hooks/use-animation-frame.js +48 -0
  891. package/src/ink/hooks/use-app.js +7 -0
  892. package/src/ink/hooks/use-declared-cursor.js +60 -0
  893. package/src/ink/hooks/use-input.js +70 -0
  894. package/src/ink/hooks/use-interval.js +54 -0
  895. package/src/ink/hooks/use-search-highlight.js +32 -0
  896. package/src/ink/hooks/use-selection.js +60 -0
  897. package/src/ink/hooks/use-stdin.js +7 -0
  898. package/src/ink/hooks/use-tab-status.js +57 -0
  899. package/src/ink/hooks/use-terminal-focus.js +15 -0
  900. package/src/ink/hooks/use-terminal-title.js +29 -0
  901. package/src/ink/hooks/use-terminal-viewport.js +77 -0
  902. package/src/ink/ink.js +1645 -0
  903. package/src/ink/instances.js +7 -0
  904. package/src/ink/layout/engine.js +4 -0
  905. package/src/ink/layout/geometry.js +61 -0
  906. package/src/ink/layout/node.js +62 -0
  907. package/src/ink/layout/yoga.js +237 -0
  908. package/src/ink/line-width-cache.js +19 -0
  909. package/src/ink/log-update.js +583 -0
  910. package/src/ink/measure-element.js +8 -0
  911. package/src/ink/measure-text.js +35 -0
  912. package/src/ink/node-cache.js +30 -0
  913. package/src/ink/optimizer.js +81 -0
  914. package/src/ink/output.js +556 -0
  915. package/src/ink/parse-keypress.js +695 -0
  916. package/src/ink/reconciler.js +384 -0
  917. package/src/ink/render-border.js +134 -0
  918. package/src/ink/render-node-to-output.js +1216 -0
  919. package/src/ink/render-to-screen.js +171 -0
  920. package/src/ink/renderer.js +129 -0
  921. package/src/ink/root.js +80 -0
  922. package/src/ink/screen.js +1132 -0
  923. package/src/ink/searchHighlight.js +78 -0
  924. package/src/ink/selection.js +792 -0
  925. package/src/ink/squash-text-nodes.js +56 -0
  926. package/src/ink/stringWidth.js +200 -0
  927. package/src/ink/styles.js +299 -0
  928. package/src/ink/supports-hyperlinks.js +40 -0
  929. package/src/ink/tabstops.js +39 -0
  930. package/src/ink/terminal-focus-state.js +35 -0
  931. package/src/ink/terminal-querier.js +173 -0
  932. package/src/ink/terminal.js +208 -0
  933. package/src/ink/termio/ansi.js +70 -0
  934. package/src/ink/termio/csi.js +260 -0
  935. package/src/ink/termio/dec.js +53 -0
  936. package/src/ink/termio/esc.js +55 -0
  937. package/src/ink/termio/osc.js +432 -0
  938. package/src/ink/termio/parser.js +356 -0
  939. package/src/ink/termio/sgr.js +292 -0
  940. package/src/ink/termio/tokenize.js +264 -0
  941. package/src/ink/termio/types.js +55 -0
  942. package/src/ink/termio.js +24 -0
  943. package/src/ink/useTerminalNotification.js +57 -0
  944. package/src/ink/warn.js +10 -0
  945. package/src/ink/widest-line.js +14 -0
  946. package/src/ink/wrap-text.js +54 -0
  947. package/src/ink/wrapAnsi.js +6 -0
  948. package/src/ink.js +50 -0
  949. package/src/integrations/credentialStore.js +176 -0
  950. package/src/integrations/index.js +5 -0
  951. package/src/integrations/integrationManager.js +180 -0
  952. package/src/integrations/providers/BaseProvider.js +180 -0
  953. package/src/integrations/providers/GitHubProvider.js +217 -0
  954. package/src/integrations/providers/GmailProvider.js +204 -0
  955. package/src/integrations/providers/GoogleCalendarProvider.js +113 -0
  956. package/src/integrations/providers/HubSpotProvider.js +159 -0
  957. package/src/integrations/providers/JiraProvider.js +216 -0
  958. package/src/integrations/providers/NotionProvider.js +221 -0
  959. package/src/integrations/providers/QuickBooksProvider.js +176 -0
  960. package/src/integrations/providers/SlackProvider.js +174 -0
  961. package/src/integrations/providers/StripeProvider.js +206 -0
  962. package/src/integrations/providers/TwilioProvider.js +239 -0
  963. package/src/integrations/providers/_template.js +112 -0
  964. package/src/integrations/types.js +7 -0
  965. package/src/interactiveHelpers.js +308 -0
  966. package/src/jobs/classifier.js +6 -0
  967. package/src/keybindings/KeybindingContext.js +184 -0
  968. package/src/keybindings/KeybindingProviderSetup.js +259 -0
  969. package/src/keybindings/defaultBindings.js +333 -0
  970. package/src/keybindings/loadUserBindings.js +393 -0
  971. package/src/keybindings/match.js +111 -0
  972. package/src/keybindings/parser.js +184 -0
  973. package/src/keybindings/reservedShortcuts.js +109 -0
  974. package/src/keybindings/resolver.js +182 -0
  975. package/src/keybindings/schema.js +205 -0
  976. package/src/keybindings/shortcutFormat.js +48 -0
  977. package/src/keybindings/template.js +40 -0
  978. package/src/keybindings/useKeybinding.js +161 -0
  979. package/src/keybindings/useShortcutDisplay.js +43 -0
  980. package/src/keybindings/validate.js +395 -0
  981. package/src/main.js +4128 -0
  982. package/src/memdir/findRelevantMemories.js +99 -0
  983. package/src/memdir/memdir.js +406 -0
  984. package/src/memdir/memoryAge.js +52 -0
  985. package/src/memdir/memoryScan.js +65 -0
  986. package/src/memdir/memoryShapeTelemetry.js +8 -0
  987. package/src/memdir/memoryTypes.js +260 -0
  988. package/src/memdir/paths.js +235 -0
  989. package/src/memdir/teamMemPaths.js +261 -0
  990. package/src/memdir/teamMemPrompts.js +82 -0
  991. package/src/migrations/migrateAutoUpdatesToSettings.js +47 -0
  992. package/src/migrations/migrateBypassPermissionsAcceptedToSettings.js +32 -0
  993. package/src/migrations/migrateEnableAllProjectMcpServersToSettings.js +83 -0
  994. package/src/migrations/migrateFennecToOpus.js +39 -0
  995. package/src/migrations/migrateLegacyOpusToCurrent.js +44 -0
  996. package/src/migrations/migrateOpusToOpus1m.js +31 -0
  997. package/src/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.js +23 -0
  998. package/src/migrations/migrateSonnet1mToSonnet45.js +38 -0
  999. package/src/migrations/migrateSonnet45ToSonnet46.js +48 -0
  1000. package/src/migrations/resetAutoModeOptInForDefaultOffer.js +47 -0
  1001. package/src/migrations/resetProToOpusDefault.js +46 -0
  1002. package/src/moreright/useMoreRight.js +13 -0
  1003. package/src/native-ts/color-diff/index.js +819 -0
  1004. package/src/native-ts/file-index/index.js +328 -0
  1005. package/src/native-ts/yoga-layout/enums.js +101 -0
  1006. package/src/native-ts/yoga-layout/index.js +2113 -0
  1007. package/src/outputStyles/loadOutputStylesDir.js +71 -0
  1008. package/src/plugins/builtinPlugins.js +132 -0
  1009. package/src/plugins/bundled/index.js +22 -0
  1010. package/src/proactive/index.js +138 -0
  1011. package/src/proactive/useProactive.js +82 -0
  1012. package/src/projectOnboardingState.js +61 -0
  1013. package/src/query/config.js +17 -0
  1014. package/src/query/deps.js +12 -0
  1015. package/src/query/stopHooks.js +332 -0
  1016. package/src/query/tokenBudget.js +49 -0
  1017. package/src/query.js +1264 -0
  1018. package/src/remote/RemoteSessionManager.js +172 -0
  1019. package/src/remote/SessionsWebSocket.js +308 -0
  1020. package/src/remote/remotePermissionBridge.js +70 -0
  1021. package/src/remote/sdkMessageAdapter.js +227 -0
  1022. package/src/replLauncher.js +7 -0
  1023. package/src/schemas/hooks.js +174 -0
  1024. package/src/screens/Doctor.js +580 -0
  1025. package/src/screens/REPL.js +4500 -0
  1026. package/src/screens/ResumeConversation.js +339 -0
  1027. package/src/self-hosted-runner/main.js +8 -0
  1028. package/src/server/backends/dangerousBackend.js +8 -0
  1029. package/src/server/connectHeadless.js +6 -0
  1030. package/src/server/createDirectConnectSession.js +62 -0
  1031. package/src/server/directConnectManager.js +153 -0
  1032. package/src/server/lockfile.js +11 -0
  1033. package/src/server/parseConnectUrl.js +20 -0
  1034. package/src/server/server.js +12 -0
  1035. package/src/server/serverBanner.js +9 -0
  1036. package/src/server/serverLog.js +11 -0
  1037. package/src/server/sessionManager.js +19 -0
  1038. package/src/server/types.js +7 -0
  1039. package/src/services/AgentSummary/agentSummary.js +147 -0
  1040. package/src/services/MagicDocs/magicDocs.js +193 -0
  1041. package/src/services/MagicDocs/prompts.js +110 -0
  1042. package/src/services/PromptSuggestion/promptSuggestion.js +402 -0
  1043. package/src/services/PromptSuggestion/speculation.js +643 -0
  1044. package/src/services/SessionMemory/prompts.js +254 -0
  1045. package/src/services/SessionMemory/sessionMemory.js +358 -0
  1046. package/src/services/SessionMemory/sessionMemoryUtils.js +157 -0
  1047. package/src/services/analytics/config.js +27 -0
  1048. package/src/services/analytics/datadog.js +26 -0
  1049. package/src/services/analytics/firstPartyEventLogger.js +65 -0
  1050. package/src/services/analytics/firstPartyEventLoggingExporter.js +595 -0
  1051. package/src/services/analytics/growthbook.js +103 -0
  1052. package/src/services/analytics/index.js +91 -0
  1053. package/src/services/analytics/metadata.js +696 -0
  1054. package/src/services/analytics/sink.js +19 -0
  1055. package/src/services/analytics/sinkKillswitch.js +19 -0
  1056. package/src/services/api/adminRequests.js +57 -0
  1057. package/src/services/api/bootstrap.js +118 -0
  1058. package/src/services/api/claude.js +2466 -0
  1059. package/src/services/api/client.js +335 -0
  1060. package/src/services/api/dumpPrompts.js +174 -0
  1061. package/src/services/api/emptyUsage.js +20 -0
  1062. package/src/services/api/errorUtils.js +203 -0
  1063. package/src/services/api/errors.js +926 -0
  1064. package/src/services/api/filesApi.js +523 -0
  1065. package/src/services/api/firstTokenDate.js +49 -0
  1066. package/src/services/api/grove.js +44 -0
  1067. package/src/services/api/logging.js +484 -0
  1068. package/src/services/api/metricsOptOut.js +15 -0
  1069. package/src/services/api/overageCreditGrant.js +123 -0
  1070. package/src/services/api/promptCacheBreakDetection.js +510 -0
  1071. package/src/services/api/referral.js +219 -0
  1072. package/src/services/api/sessionIngress.js +358 -0
  1073. package/src/services/api/ultrareviewQuota.js +29 -0
  1074. package/src/services/api/usage.js +31 -0
  1075. package/src/services/api/withRetry.js +587 -0
  1076. package/src/services/api/xai/anthropic-shim.js +885 -0
  1077. package/src/services/api/xai/brightDataSearch.js +161 -0
  1078. package/src/services/api/xai/thaddeus-engine.js +605 -0
  1079. package/src/services/api/xai/xai-client.js +276 -0
  1080. package/src/services/autoDream/autoDream.js +244 -0
  1081. package/src/services/autoDream/config.js +17 -0
  1082. package/src/services/autoDream/consolidationLock.js +122 -0
  1083. package/src/services/autoDream/consolidationPrompt.js +55 -0
  1084. package/src/services/awaySummary.js +61 -0
  1085. package/src/services/claudeAiLimits.js +331 -0
  1086. package/src/services/claudeAiLimitsHook.js +15 -0
  1087. package/src/services/compact/apiMicrocompact.js +97 -0
  1088. package/src/services/compact/autoCompact.js +234 -0
  1089. package/src/services/compact/cachedMCConfig.js +5 -0
  1090. package/src/services/compact/compact.js +1256 -0
  1091. package/src/services/compact/compactWarningHook.js +12 -0
  1092. package/src/services/compact/compactWarningState.js +15 -0
  1093. package/src/services/compact/grouping.js +58 -0
  1094. package/src/services/compact/microCompact.js +414 -0
  1095. package/src/services/compact/postCompactCleanup.js +70 -0
  1096. package/src/services/compact/prompt.js +325 -0
  1097. package/src/services/compact/reactiveCompact.js +20 -0
  1098. package/src/services/compact/sessionMemoryCompact.js +467 -0
  1099. package/src/services/compact/snipCompact.js +23 -0
  1100. package/src/services/compact/snipProjection.js +11 -0
  1101. package/src/services/compact/timeBasedMCConfig.js +11 -0
  1102. package/src/services/contextCollapse/index.js +33 -0
  1103. package/src/services/contextCollapse/operations.js +5 -0
  1104. package/src/services/contextCollapse/persist.js +5 -0
  1105. package/src/services/diagnosticTracking.js +282 -0
  1106. package/src/services/elevenlabsTTS.js +245 -0
  1107. package/src/services/extractMemories/extractMemories.js +442 -0
  1108. package/src/services/extractMemories/prompts.js +129 -0
  1109. package/src/services/internalLogging.js +68 -0
  1110. package/src/services/lsp/LSPClient.js +306 -0
  1111. package/src/services/lsp/LSPDiagnosticRegistry.js +277 -0
  1112. package/src/services/lsp/LSPServerInstance.js +388 -0
  1113. package/src/services/lsp/LSPServerManager.js +305 -0
  1114. package/src/services/lsp/config.js +57 -0
  1115. package/src/services/lsp/manager.js +246 -0
  1116. package/src/services/lsp/passiveFeedback.js +226 -0
  1117. package/src/services/mcp/InProcessTransport.js +54 -0
  1118. package/src/services/mcp/MCPConnectionManager.js +50 -0
  1119. package/src/services/mcp/SdkControlTransport.js +115 -0
  1120. package/src/services/mcp/auth.js +1882 -0
  1121. package/src/services/mcp/channelAllowlist.js +57 -0
  1122. package/src/services/mcp/channelNotification.js +235 -0
  1123. package/src/services/mcp/channelPermissions.js +192 -0
  1124. package/src/services/mcp/claudeai.js +123 -0
  1125. package/src/services/mcp/client.js +2478 -0
  1126. package/src/services/mcp/config.js +1271 -0
  1127. package/src/services/mcp/elicitationHandler.js +192 -0
  1128. package/src/services/mcp/envExpansion.js +30 -0
  1129. package/src/services/mcp/headersHelper.js +93 -0
  1130. package/src/services/mcp/mcpStringUtils.js +85 -0
  1131. package/src/services/mcp/normalization.js +21 -0
  1132. package/src/services/mcp/oauthPort.js +69 -0
  1133. package/src/services/mcp/officialRegistry.js +20 -0
  1134. package/src/services/mcp/types.js +94 -0
  1135. package/src/services/mcp/useManageMCPConnections.js +818 -0
  1136. package/src/services/mcp/utils.js +433 -0
  1137. package/src/services/mcp/vscodeSdkMcp.js +69 -0
  1138. package/src/services/mcp/xaa.js +342 -0
  1139. package/src/services/mcp/xaaIdpLogin.js +377 -0
  1140. package/src/services/mcpServerApproval.js +30 -0
  1141. package/src/services/mockRateLimits.js +666 -0
  1142. package/src/services/notifier.js +114 -0
  1143. package/src/services/oauth/auth-code-listener.js +165 -0
  1144. package/src/services/oauth/client.js +397 -0
  1145. package/src/services/oauth/crypto.js +19 -0
  1146. package/src/services/oauth/getOauthProfile.js +48 -0
  1147. package/src/services/oauth/index.js +133 -0
  1148. package/src/services/plugins/PluginInstallationManager.js +139 -0
  1149. package/src/services/plugins/pluginCliCommands.js +230 -0
  1150. package/src/services/plugins/pluginOperations.js +826 -0
  1151. package/src/services/policyLimits/index.js +547 -0
  1152. package/src/services/policyLimits/types.js +9 -0
  1153. package/src/services/preventSleep.js +143 -0
  1154. package/src/services/rateLimitMessages.js +271 -0
  1155. package/src/services/rateLimitMocking.js +91 -0
  1156. package/src/services/remoteManagedSettings/index.js +534 -0
  1157. package/src/services/remoteManagedSettings/securityCheck.js +60 -0
  1158. package/src/services/remoteManagedSettings/syncCache.js +90 -0
  1159. package/src/services/remoteManagedSettings/syncCacheState.js +89 -0
  1160. package/src/services/remoteManagedSettings/types.js +12 -0
  1161. package/src/services/sessionTranscript/sessionTranscript.js +5 -0
  1162. package/src/services/settingsSync/index.js +478 -0
  1163. package/src/services/settingsSync/types.js +35 -0
  1164. package/src/services/skillSearch/featureCheck.js +8 -0
  1165. package/src/services/skillSearch/localSearch.js +5 -0
  1166. package/src/services/skillSearch/prefetch.js +8 -0
  1167. package/src/services/skillSearch/remoteSkillLoader.js +8 -0
  1168. package/src/services/skillSearch/remoteSkillState.js +11 -0
  1169. package/src/services/skillSearch/signals.js +3 -0
  1170. package/src/services/skillSearch/telemetry.js +8 -0
  1171. package/src/services/teamMemorySync/index.js +976 -0
  1172. package/src/services/teamMemorySync/secretScanner.js +275 -0
  1173. package/src/services/teamMemorySync/teamMemSecretGuard.js +33 -0
  1174. package/src/services/teamMemorySync/types.js +47 -0
  1175. package/src/services/teamMemorySync/watcher.js +326 -0
  1176. package/src/services/thaddeusAuth.js +485 -0
  1177. package/src/services/thaddeusAuthTypes.js +9 -0
  1178. package/src/services/thaddeusLoginFlow.js +236 -0
  1179. package/src/services/tips/tipHistory.js +17 -0
  1180. package/src/services/tips/tipRegistry.js +593 -0
  1181. package/src/services/tips/tipScheduler.js +40 -0
  1182. package/src/services/tokenEstimation.js +365 -0
  1183. package/src/services/toolUseSummary/toolUseSummaryGenerator.js +87 -0
  1184. package/src/services/tools/StreamingToolExecutor.js +413 -0
  1185. package/src/services/tools/toolExecution.js +1309 -0
  1186. package/src/services/tools/toolHooks.js +454 -0
  1187. package/src/services/tools/toolOrchestration.js +110 -0
  1188. package/src/services/vcr.js +291 -0
  1189. package/src/services/voice.js +392 -0
  1190. package/src/services/voiceKeyterms.js +94 -0
  1191. package/src/services/voiceStreamSTT.js +405 -0
  1192. package/src/setup.js +310 -0
  1193. package/src/skills/bundled/batch.js +114 -0
  1194. package/src/skills/bundled/claudeApi.js +145 -0
  1195. package/src/skills/bundled/claudeApiContent.js +71 -0
  1196. package/src/skills/bundled/claudeInChrome.js +27 -0
  1197. package/src/skills/bundled/debug.js +99 -0
  1198. package/src/skills/bundled/dream.js +49 -0
  1199. package/src/skills/bundled/emailSetup.js +196 -0
  1200. package/src/skills/bundled/hunter.js +28 -0
  1201. package/src/skills/bundled/index.js +80 -0
  1202. package/src/skills/bundled/keybindings.js +292 -0
  1203. package/src/skills/bundled/loop.js +81 -0
  1204. package/src/skills/bundled/loremIpsum.js +264 -0
  1205. package/src/skills/bundled/reactor.js +31 -0
  1206. package/src/skills/bundled/remember.js +73 -0
  1207. package/src/skills/bundled/runSkillGenerator.js +12 -0
  1208. package/src/skills/bundled/scheduleRemoteAgents.js +373 -0
  1209. package/src/skills/bundled/simplify.js +66 -0
  1210. package/src/skills/bundled/skillify.js +182 -0
  1211. package/src/skills/bundled/stuck.js +69 -0
  1212. package/src/skills/bundled/updateConfig.js +463 -0
  1213. package/src/skills/bundled/verify.js +23 -0
  1214. package/src/skills/bundled/verifyContent.js +10 -0
  1215. package/src/skills/bundledSkills.js +159 -0
  1216. package/src/skills/loadSkillsDir.js +736 -0
  1217. package/src/skills/mcpSkillBuilders.js +10 -0
  1218. package/src/skills/mcpSkills.js +5 -0
  1219. package/src/state/AppState.js +182 -0
  1220. package/src/state/AppStateStore.js +117 -0
  1221. package/src/state/onChangeAppState.js +132 -0
  1222. package/src/state/selectors.js +51 -0
  1223. package/src/state/store.js +21 -0
  1224. package/src/state/teammateViewHelpers.js +124 -0
  1225. package/src/stubs/ant-chrome-mcp/index.js +4 -0
  1226. package/src/stubs/ant-computer-use-input/index.js +2 -0
  1227. package/src/stubs/ant-computer-use-mcp/index.js +7 -0
  1228. package/src/stubs/ant-computer-use-mcp/sentinelApps.js +2 -0
  1229. package/src/stubs/ant-computer-use-mcp/types.js +3 -0
  1230. package/src/stubs/ant-computer-use-swift/index.js +1 -0
  1231. package/src/stubs/anthropic-sandbox/index.js +34 -0
  1232. package/src/tasks/DreamTask/DreamTask.js +99 -0
  1233. package/src/tasks/InProcessTeammateTask/InProcessTeammateTask.js +116 -0
  1234. package/src/tasks/InProcessTeammateTask/types.js +35 -0
  1235. package/src/tasks/LocalAgentTask/LocalAgentTask.js +507 -0
  1236. package/src/tasks/LocalMainSessionTask.js +338 -0
  1237. package/src/tasks/LocalShellTask/LocalShellTask.js +475 -0
  1238. package/src/tasks/LocalShellTask/guards.js +9 -0
  1239. package/src/tasks/LocalShellTask/killShellTasks.js +59 -0
  1240. package/src/tasks/LocalWorkflowTask/LocalWorkflowTask.js +7 -0
  1241. package/src/tasks/MonitorMcpTask/MonitorMcpTask.js +20 -0
  1242. package/src/tasks/RemoteAgentTask/RemoteAgentTask.js +742 -0
  1243. package/src/tasks/pillLabel.js +69 -0
  1244. package/src/tasks/stopTask.js +67 -0
  1245. package/src/tasks/types.js +18 -0
  1246. package/src/tasks.js +37 -0
  1247. package/src/tools/AIEmployeesTool/AIEmployeesTool.js +674 -0
  1248. package/src/tools/AIEmployeesTool/constants.js +1 -0
  1249. package/src/tools/AIEmployeesTool/prompt.js +56 -0
  1250. package/src/tools/AgentTool/AgentTool.js +1221 -0
  1251. package/src/tools/AgentTool/UI.js +593 -0
  1252. package/src/tools/AgentTool/agentColorManager.js +43 -0
  1253. package/src/tools/AgentTool/agentDisplay.js +72 -0
  1254. package/src/tools/AgentTool/agentMemory.js +125 -0
  1255. package/src/tools/AgentTool/agentMemorySnapshot.js +136 -0
  1256. package/src/tools/AgentTool/agentToolUtils.js +456 -0
  1257. package/src/tools/AgentTool/built-in/exploreAgent.js +76 -0
  1258. package/src/tools/AgentTool/built-in/generalPurposeAgent.js +28 -0
  1259. package/src/tools/AgentTool/built-in/planAgent.js +87 -0
  1260. package/src/tools/AgentTool/built-in/statuslineSetup.js +140 -0
  1261. package/src/tools/AgentTool/built-in/thaddeusGuideAgent.js +174 -0
  1262. package/src/tools/AgentTool/built-in/verificationAgent.js +146 -0
  1263. package/src/tools/AgentTool/builtInAgents.js +56 -0
  1264. package/src/tools/AgentTool/constants.js +11 -0
  1265. package/src/tools/AgentTool/forkSubagent.js +177 -0
  1266. package/src/tools/AgentTool/loadAgentsDir.js +497 -0
  1267. package/src/tools/AgentTool/prompt.js +260 -0
  1268. package/src/tools/AgentTool/resumeAgent.js +182 -0
  1269. package/src/tools/AgentTool/runAgent.js +627 -0
  1270. package/src/tools/AppointmentsTool/AppointmentsTool.js +628 -0
  1271. package/src/tools/AppointmentsTool/constants.js +1 -0
  1272. package/src/tools/AppointmentsTool/prompt.js +15 -0
  1273. package/src/tools/AskUserQuestionTool/AskUserQuestionTool.js +238 -0
  1274. package/src/tools/AskUserQuestionTool/prompt.js +38 -0
  1275. package/src/tools/BashTool/BashTool.js +1009 -0
  1276. package/src/tools/BashTool/BashToolResultMessage.js +169 -0
  1277. package/src/tools/BashTool/UI.js +134 -0
  1278. package/src/tools/BashTool/bashCommandHelpers.js +184 -0
  1279. package/src/tools/BashTool/bashPermissions.js +2023 -0
  1280. package/src/tools/BashTool/bashSecurity.js +2267 -0
  1281. package/src/tools/BashTool/commandSemantics.js +105 -0
  1282. package/src/tools/BashTool/commentLabel.js +14 -0
  1283. package/src/tools/BashTool/destructiveCommandWarning.js +88 -0
  1284. package/src/tools/BashTool/modeValidation.js +86 -0
  1285. package/src/tools/BashTool/pathValidation.js +1079 -0
  1286. package/src/tools/BashTool/prompt.js +333 -0
  1287. package/src/tools/BashTool/readOnlyValidation.js +1794 -0
  1288. package/src/tools/BashTool/sedEditParser.js +282 -0
  1289. package/src/tools/BashTool/sedValidation.js +580 -0
  1290. package/src/tools/BashTool/shouldUseSandbox.js +125 -0
  1291. package/src/tools/BashTool/toolName.js +2 -0
  1292. package/src/tools/BashTool/utils.js +180 -0
  1293. package/src/tools/BriefTool/BriefTool.js +173 -0
  1294. package/src/tools/BriefTool/UI.js +67 -0
  1295. package/src/tools/BriefTool/attachments.js +86 -0
  1296. package/src/tools/BriefTool/prompt.js +19 -0
  1297. package/src/tools/BriefTool/upload.js +136 -0
  1298. package/src/tools/CalendarTool/CalendarTool.js +498 -0
  1299. package/src/tools/CalendarTool/constants.js +1 -0
  1300. package/src/tools/CalendarTool/prompt.js +11 -0
  1301. package/src/tools/ConfigTool/ConfigTool.js +398 -0
  1302. package/src/tools/ConfigTool/UI.js +25 -0
  1303. package/src/tools/ConfigTool/constants.js +1 -0
  1304. package/src/tools/ConfigTool/prompt.js +82 -0
  1305. package/src/tools/ConfigTool/supportedSettings.js +180 -0
  1306. package/src/tools/ContactsTool/ContactsTool.js +648 -0
  1307. package/src/tools/ContactsTool/constants.js +1 -0
  1308. package/src/tools/ContactsTool/prompt.js +15 -0
  1309. package/src/tools/CtxInspectTool/CtxInspectTool.js +44 -0
  1310. package/src/tools/DiscoverSkillsTool/prompt.js +4 -0
  1311. package/src/tools/EmailReadTool/index.js +410 -0
  1312. package/src/tools/EmailSendTool/index.js +178 -0
  1313. package/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +98 -0
  1314. package/src/tools/EnterPlanModeTool/UI.js +14 -0
  1315. package/src/tools/EnterPlanModeTool/constants.js +1 -0
  1316. package/src/tools/EnterPlanModeTool/prompt.js +164 -0
  1317. package/src/tools/EnterWorktreeTool/EnterWorktreeTool.js +104 -0
  1318. package/src/tools/EnterWorktreeTool/UI.js +9 -0
  1319. package/src/tools/EnterWorktreeTool/constants.js +1 -0
  1320. package/src/tools/EnterWorktreeTool/prompt.js +30 -0
  1321. package/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +383 -0
  1322. package/src/tools/ExitPlanModeTool/UI.js +32 -0
  1323. package/src/tools/ExitPlanModeTool/constants.js +2 -0
  1324. package/src/tools/ExitPlanModeTool/prompt.js +27 -0
  1325. package/src/tools/ExitWorktreeTool/ExitWorktreeTool.js +257 -0
  1326. package/src/tools/ExitWorktreeTool/UI.js +10 -0
  1327. package/src/tools/ExitWorktreeTool/constants.js +1 -0
  1328. package/src/tools/ExitWorktreeTool/prompt.js +32 -0
  1329. package/src/tools/FileEditTool/FileEditTool.js +480 -0
  1330. package/src/tools/FileEditTool/UI.js +202 -0
  1331. package/src/tools/FileEditTool/constants.js +7 -0
  1332. package/src/tools/FileEditTool/prompt.js +24 -0
  1333. package/src/tools/FileEditTool/types.js +50 -0
  1334. package/src/tools/FileEditTool/utils.js +579 -0
  1335. package/src/tools/FileReadTool/FileReadTool.js +889 -0
  1336. package/src/tools/FileReadTool/UI.js +126 -0
  1337. package/src/tools/FileReadTool/imageProcessor.js +46 -0
  1338. package/src/tools/FileReadTool/limits.js +70 -0
  1339. package/src/tools/FileReadTool/prompt.js +31 -0
  1340. package/src/tools/FileWriteTool/FileWriteTool.js +341 -0
  1341. package/src/tools/FileWriteTool/UI.js +339 -0
  1342. package/src/tools/FileWriteTool/prompt.js +15 -0
  1343. package/src/tools/GlobTool/GlobTool.js +161 -0
  1344. package/src/tools/GlobTool/UI.js +40 -0
  1345. package/src/tools/GlobTool/prompt.js +6 -0
  1346. package/src/tools/GrepTool/GrepTool.js +439 -0
  1347. package/src/tools/GrepTool/UI.js +155 -0
  1348. package/src/tools/GrepTool/prompt.js +16 -0
  1349. package/src/tools/IntegrationsTool/IntegrationsTool.js +217 -0
  1350. package/src/tools/IntegrationsTool/constants.js +1 -0
  1351. package/src/tools/IntegrationsTool/prompt.js +41 -0
  1352. package/src/tools/InteractionsTool/InteractionsTool.js +525 -0
  1353. package/src/tools/InteractionsTool/constants.js +1 -0
  1354. package/src/tools/InteractionsTool/prompt.js +14 -0
  1355. package/src/tools/InvoicesTool/InvoicesTool.js +581 -0
  1356. package/src/tools/InvoicesTool/constants.js +1 -0
  1357. package/src/tools/InvoicesTool/prompt.js +15 -0
  1358. package/src/tools/LSPTool/LSPTool.js +660 -0
  1359. package/src/tools/LSPTool/UI.js +205 -0
  1360. package/src/tools/LSPTool/formatters.js +445 -0
  1361. package/src/tools/LSPTool/prompt.js +20 -0
  1362. package/src/tools/LSPTool/schemas.js +197 -0
  1363. package/src/tools/LSPTool/symbolContext.js +75 -0
  1364. package/src/tools/LeadScorerTool/LeadScorerTool.js +509 -0
  1365. package/src/tools/LeadScorerTool/constants.js +1 -0
  1366. package/src/tools/LeadScorerTool/prompt.js +11 -0
  1367. package/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +100 -0
  1368. package/src/tools/ListMcpResourcesTool/UI.js +17 -0
  1369. package/src/tools/ListMcpResourcesTool/prompt.js +18 -0
  1370. package/src/tools/ListPeersTool/ListPeersTool.js +45 -0
  1371. package/src/tools/MCPTool/MCPTool.js +60 -0
  1372. package/src/tools/MCPTool/UI.js +343 -0
  1373. package/src/tools/MCPTool/classifyForCollapse.js +597 -0
  1374. package/src/tools/MCPTool/prompt.js +3 -0
  1375. package/src/tools/McpAuthTool/McpAuthTool.js +162 -0
  1376. package/src/tools/MonitorTool/MonitorTool.js +55 -0
  1377. package/src/tools/NotebookEditTool/NotebookEditTool.js +421 -0
  1378. package/src/tools/NotebookEditTool/UI.js +41 -0
  1379. package/src/tools/NotebookEditTool/constants.js +2 -0
  1380. package/src/tools/NotebookEditTool/prompt.js +2 -0
  1381. package/src/tools/OverflowTestTool/OverflowTestTool.js +51 -0
  1382. package/src/tools/PhoneBridgeTool/PhoneBridgeTool.js +301 -0
  1383. package/src/tools/PhoneBridgeTool/constants.js +1 -0
  1384. package/src/tools/PhoneBridgeTool/prompt.js +26 -0
  1385. package/src/tools/PowerShellTool/PowerShellTool.js +900 -0
  1386. package/src/tools/PowerShellTool/UI.js +58 -0
  1387. package/src/tools/PowerShellTool/clmTypes.js +207 -0
  1388. package/src/tools/PowerShellTool/commandSemantics.js +115 -0
  1389. package/src/tools/PowerShellTool/commonParameters.js +27 -0
  1390. package/src/tools/PowerShellTool/destructiveCommandWarning.js +92 -0
  1391. package/src/tools/PowerShellTool/gitSafety.js +185 -0
  1392. package/src/tools/PowerShellTool/modeValidation.js +357 -0
  1393. package/src/tools/PowerShellTool/pathValidation.js +1712 -0
  1394. package/src/tools/PowerShellTool/powershellPermissions.js +1351 -0
  1395. package/src/tools/PowerShellTool/powershellSecurity.js +942 -0
  1396. package/src/tools/PowerShellTool/prompt.js +132 -0
  1397. package/src/tools/PowerShellTool/readOnlyValidation.js +1633 -0
  1398. package/src/tools/PowerShellTool/toolName.js +2 -0
  1399. package/src/tools/PushNotificationTool/PushNotificationTool.js +35 -0
  1400. package/src/tools/REPLTool/REPLTool.js +44 -0
  1401. package/src/tools/REPLTool/constants.js +43 -0
  1402. package/src/tools/REPLTool/primitiveTools.js +36 -0
  1403. package/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +112 -0
  1404. package/src/tools/ReadMcpResourceTool/UI.js +24 -0
  1405. package/src/tools/ReadMcpResourceTool/prompt.js +15 -0
  1406. package/src/tools/RemoteTriggerTool/RemoteTriggerTool.js +142 -0
  1407. package/src/tools/RemoteTriggerTool/UI.js +12 -0
  1408. package/src/tools/RemoteTriggerTool/prompt.js +12 -0
  1409. package/src/tools/ReviewArtifactTool/ReviewArtifactTool.js +51 -0
  1410. package/src/tools/ScheduleCronTool/CronCreateTool.js +120 -0
  1411. package/src/tools/ScheduleCronTool/CronDeleteTool.js +74 -0
  1412. package/src/tools/ScheduleCronTool/CronListTool.js +77 -0
  1413. package/src/tools/ScheduleCronTool/UI.js +29 -0
  1414. package/src/tools/ScheduleCronTool/prompt.js +115 -0
  1415. package/src/tools/SendMessageTool/SendMessageTool.js +673 -0
  1416. package/src/tools/SendMessageTool/UI.js +24 -0
  1417. package/src/tools/SendMessageTool/constants.js +1 -0
  1418. package/src/tools/SendMessageTool/prompt.js +47 -0
  1419. package/src/tools/SendUserFileTool/SendUserFileTool.js +35 -0
  1420. package/src/tools/SendUserFileTool/prompt.js +5 -0
  1421. package/src/tools/SkillTool/SkillTool.js +825 -0
  1422. package/src/tools/SkillTool/UI.js +61 -0
  1423. package/src/tools/SkillTool/constants.js +1 -0
  1424. package/src/tools/SkillTool/prompt.js +184 -0
  1425. package/src/tools/SleepTool/SleepTool.js +42 -0
  1426. package/src/tools/SleepTool/prompt.js +14 -0
  1427. package/src/tools/SnipTool/SnipTool.js +47 -0
  1428. package/src/tools/SnipTool/prompt.js +5 -0
  1429. package/src/tools/SubscribePRTool/SubscribePRTool.js +49 -0
  1430. package/src/tools/SuggestBackgroundPRTool/SuggestBackgroundPRTool.js +44 -0
  1431. package/src/tools/SyntheticOutputTool/SyntheticOutputTool.js +138 -0
  1432. package/src/tools/SyntheticOutputTool/SyntheticOutputTool.ts +1 -1
  1433. package/src/tools/TaskCreateTool/TaskCreateTool.js +104 -0
  1434. package/src/tools/TaskCreateTool/constants.js +1 -0
  1435. package/src/tools/TaskCreateTool/prompt.js +52 -0
  1436. package/src/tools/TaskGetTool/TaskGetTool.js +106 -0
  1437. package/src/tools/TaskGetTool/constants.js +1 -0
  1438. package/src/tools/TaskGetTool/prompt.js +23 -0
  1439. package/src/tools/TaskListTool/TaskListTool.js +89 -0
  1440. package/src/tools/TaskListTool/constants.js +1 -0
  1441. package/src/tools/TaskListTool/prompt.js +44 -0
  1442. package/src/tools/TaskOutputTool/TaskOutputTool.js +536 -0
  1443. package/src/tools/TaskOutputTool/constants.js +1 -0
  1444. package/src/tools/TaskStopTool/TaskStopTool.js +110 -0
  1445. package/src/tools/TaskStopTool/UI.js +31 -0
  1446. package/src/tools/TaskStopTool/prompt.js +7 -0
  1447. package/src/tools/TaskUpdateTool/TaskUpdateTool.js +301 -0
  1448. package/src/tools/TaskUpdateTool/constants.js +1 -0
  1449. package/src/tools/TaskUpdateTool/prompt.js +76 -0
  1450. package/src/tools/TeamCreateTool/TeamCreateTool.js +177 -0
  1451. package/src/tools/TeamCreateTool/UI.js +4 -0
  1452. package/src/tools/TeamCreateTool/constants.js +1 -0
  1453. package/src/tools/TeamCreateTool/prompt.js +113 -0
  1454. package/src/tools/TeamDeleteTool/TeamDeleteTool.js +102 -0
  1455. package/src/tools/TeamDeleteTool/UI.js +13 -0
  1456. package/src/tools/TeamDeleteTool/constants.js +1 -0
  1457. package/src/tools/TeamDeleteTool/prompt.js +16 -0
  1458. package/src/tools/TerminalCaptureTool/TerminalCaptureTool.js +47 -0
  1459. package/src/tools/TerminalCaptureTool/prompt.js +11 -0
  1460. package/src/tools/TodoWriteTool/TodoWriteTool.js +99 -0
  1461. package/src/tools/TodoWriteTool/constants.js +1 -0
  1462. package/src/tools/TodoWriteTool/prompt.js +181 -0
  1463. package/src/tools/ToolSearchTool/ToolSearchTool.js +357 -0
  1464. package/src/tools/ToolSearchTool/constants.js +1 -0
  1465. package/src/tools/ToolSearchTool/prompt.js +97 -0
  1466. package/src/tools/TungstenTool/TungstenLiveMonitor.js +7 -0
  1467. package/src/tools/TungstenTool/TungstenTool.js +3 -0
  1468. package/src/tools/VerifyPlanExecutionTool/VerifyPlanExecutionTool.js +45 -0
  1469. package/src/tools/VerifyPlanExecutionTool/constants.js +2 -0
  1470. package/src/tools/WebBrowserTool/WebBrowserPanel.js +5 -0
  1471. package/src/tools/WebBrowserTool/WebBrowserTool.js +58 -0
  1472. package/src/tools/WebFetchTool/UI.js +31 -0
  1473. package/src/tools/WebFetchTool/WebFetchTool.js +246 -0
  1474. package/src/tools/WebFetchTool/preapproved.js +154 -0
  1475. package/src/tools/WebFetchTool/prompt.js +39 -0
  1476. package/src/tools/WebFetchTool/utils.js +368 -0
  1477. package/src/tools/WebSearchTool/UI.js +67 -0
  1478. package/src/tools/WebSearchTool/WebSearchTool.js +396 -0
  1479. package/src/tools/WebSearchTool/prompt.js +32 -0
  1480. package/src/tools/WorkflowTool/WorkflowPermissionRequest.js +7 -0
  1481. package/src/tools/WorkflowTool/WorkflowTool.js +51 -0
  1482. package/src/tools/WorkflowTool/bundled/index.js +5 -0
  1483. package/src/tools/WorkflowTool/constants.js +1 -0
  1484. package/src/tools/WorkflowTool/createWorkflowCommand.js +5 -0
  1485. package/src/tools/shared/gitOperationTracking.js +220 -0
  1486. package/src/tools/shared/spawnMultiAgent.js +805 -0
  1487. package/src/tools/testing/TestingPermissionTool.js +72 -0
  1488. package/src/tools/utils.js +24 -0
  1489. package/src/tools.js +365 -0
  1490. package/src/types/command.js +8 -0
  1491. package/src/types/connectorText.js +3 -0
  1492. package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.js +673 -0
  1493. package/src/types/generated/events_mono/common/v1/auth.js +49 -0
  1494. package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.js +147 -0
  1495. package/src/types/generated/google/protobuf/timestamp.js +38 -0
  1496. package/src/types/hooks.js +153 -0
  1497. package/src/types/ids.js +27 -0
  1498. package/src/types/logs.js +11 -0
  1499. package/src/types/permissions.js +25 -0
  1500. package/src/types/plugin.js +72 -0
  1501. package/src/types/textInputTypes.js +20 -0
  1502. package/src/upstreamproxy/relay.js +346 -0
  1503. package/src/upstreamproxy/upstreamproxy.js +234 -0
  1504. package/src/utils/CircularBuffer.js +75 -0
  1505. package/src/utils/Cursor.js +1229 -0
  1506. package/src/utils/QueryGuard.js +115 -0
  1507. package/src/utils/Shell.js +374 -0
  1508. package/src/utils/ShellCommand.js +336 -0
  1509. package/src/utils/abortController.js +74 -0
  1510. package/src/utils/activityManager.js +127 -0
  1511. package/src/utils/advisor.js +77 -0
  1512. package/src/utils/agentContext.js +91 -0
  1513. package/src/utils/agentId.js +83 -0
  1514. package/src/utils/agentSwarmsEnabled.js +37 -0
  1515. package/src/utils/agenticSessionSearch.js +255 -0
  1516. package/src/utils/analyzeContext.js +846 -0
  1517. package/src/utils/ansiToPng.js +259 -0
  1518. package/src/utils/ansiToSvg.js +207 -0
  1519. package/src/utils/api.js +555 -0
  1520. package/src/utils/apiPreconnect.js +62 -0
  1521. package/src/utils/appleTerminalBackup.js +95 -0
  1522. package/src/utils/argumentSubstitution.js +114 -0
  1523. package/src/utils/array.js +12 -0
  1524. package/src/utils/asciicast.js +200 -0
  1525. package/src/utils/attachments.js +2518 -0
  1526. package/src/utils/attribution.js +308 -0
  1527. package/src/utils/auth.js +1598 -0
  1528. package/src/utils/authFileDescriptor.js +152 -0
  1529. package/src/utils/authPortable.js +14 -0
  1530. package/src/utils/autoModeDenials.js +15 -0
  1531. package/src/utils/autoRunIssue.js +113 -0
  1532. package/src/utils/autoUpdater.js +457 -0
  1533. package/src/utils/aws.js +44 -0
  1534. package/src/utils/awsAuthStatusManager.js +66 -0
  1535. package/src/utils/background/remote/preconditions.js +175 -0
  1536. package/src/utils/background/remote/remoteSession.js +53 -0
  1537. package/src/utils/backgroundHousekeeping.js +64 -0
  1538. package/src/utils/bash/ParsedCommand.js +241 -0
  1539. package/src/utils/bash/ShellSnapshot.js +489 -0
  1540. package/src/utils/bash/ast.js +2590 -0
  1541. package/src/utils/bash/bashParser.js +4355 -0
  1542. package/src/utils/bash/bashPipeCommand.js +249 -0
  1543. package/src/utils/bash/commands.js +1131 -0
  1544. package/src/utils/bash/heredoc.js +647 -0
  1545. package/src/utils/bash/parser.js +195 -0
  1546. package/src/utils/bash/prefix.js +154 -0
  1547. package/src/utils/bash/registry.js +23 -0
  1548. package/src/utils/bash/shellCompletion.js +196 -0
  1549. package/src/utils/bash/shellPrefix.js +25 -0
  1550. package/src/utils/bash/shellQuote.js +253 -0
  1551. package/src/utils/bash/shellQuoting.js +106 -0
  1552. package/src/utils/bash/specs/alias.js +11 -0
  1553. package/src/utils/bash/specs/index.js +16 -0
  1554. package/src/utils/bash/specs/nohup.js +10 -0
  1555. package/src/utils/bash/specs/pyright.js +88 -0
  1556. package/src/utils/bash/specs/sleep.js +10 -0
  1557. package/src/utils/bash/specs/srun.js +28 -0
  1558. package/src/utils/bash/specs/time.js +10 -0
  1559. package/src/utils/bash/specs/timeout.js +17 -0
  1560. package/src/utils/bash/treeSitterAnalysis.js +407 -0
  1561. package/src/utils/betas.js +331 -0
  1562. package/src/utils/billing.js +54 -0
  1563. package/src/utils/binaryCheck.js +40 -0
  1564. package/src/utils/browser.js +58 -0
  1565. package/src/utils/bufferedWriter.js +77 -0
  1566. package/src/utils/bundledMode.js +19 -0
  1567. package/src/utils/businessDb.js +390 -0
  1568. package/src/utils/caCerts.js +91 -0
  1569. package/src/utils/caCertsConfig.js +77 -0
  1570. package/src/utils/cachePaths.js +28 -0
  1571. package/src/utils/classifierApprovals.js +66 -0
  1572. package/src/utils/classifierApprovalsHook.js +10 -0
  1573. package/src/utils/claudeDesktop.js +108 -0
  1574. package/src/utils/claudeInChrome/chromeNativeHost.js +416 -0
  1575. package/src/utils/claudeInChrome/common.js +466 -0
  1576. package/src/utils/claudeInChrome/mcpServer.js +237 -0
  1577. package/src/utils/claudeInChrome/prompt.js +79 -0
  1578. package/src/utils/claudeInChrome/setup.js +304 -0
  1579. package/src/utils/claudeInChrome/setupPortable.js +172 -0
  1580. package/src/utils/claudeInChrome/toolRendering.js +235 -0
  1581. package/src/utils/claudemd.js +1052 -0
  1582. package/src/utils/cleanup.js +514 -0
  1583. package/src/utils/cleanupRegistry.js +22 -0
  1584. package/src/utils/cliArgs.js +53 -0
  1585. package/src/utils/cliHighlight.js +45 -0
  1586. package/src/utils/codeIndexing.js +149 -0
  1587. package/src/utils/collapseBackgroundBashNotifications.js +70 -0
  1588. package/src/utils/collapseHookSummaries.js +48 -0
  1589. package/src/utils/collapseReadSearch.js +869 -0
  1590. package/src/utils/collapseTeammateShutdowns.js +44 -0
  1591. package/src/utils/combinedAbortSignal.js +40 -0
  1592. package/src/utils/commandLifecycle.js +7 -0
  1593. package/src/utils/commitAttribution.js +718 -0
  1594. package/src/utils/completionCache.js +138 -0
  1595. package/src/utils/computerUse/appNames.js +170 -0
  1596. package/src/utils/computerUse/cleanup.js +65 -0
  1597. package/src/utils/computerUse/common.js +56 -0
  1598. package/src/utils/computerUse/computerUseLock.js +183 -0
  1599. package/src/utils/computerUse/drainRunLoop.js +71 -0
  1600. package/src/utils/computerUse/escHotkey.js +53 -0
  1601. package/src/utils/computerUse/executor.js +480 -0
  1602. package/src/utils/computerUse/gates.js +55 -0
  1603. package/src/utils/computerUse/hostAdapter.js +62 -0
  1604. package/src/utils/computerUse/inputLoader.js +25 -0
  1605. package/src/utils/computerUse/mcpServer.js +84 -0
  1606. package/src/utils/computerUse/setup.js +42 -0
  1607. package/src/utils/computerUse/swiftLoader.js +18 -0
  1608. package/src/utils/computerUse/toolRendering.js +101 -0
  1609. package/src/utils/computerUse/wrapper.js +317 -0
  1610. package/src/utils/concurrentSessions.js +179 -0
  1611. package/src/utils/config.js +1078 -0
  1612. package/src/utils/configConstants.js +18 -0
  1613. package/src/utils/contentArray.js +45 -0
  1614. package/src/utils/context.js +185 -0
  1615. package/src/utils/contextAnalysis.js +171 -0
  1616. package/src/utils/contextSuggestions.js +158 -0
  1617. package/src/utils/controlMessageCompat.js +31 -0
  1618. package/src/utils/conversationRecovery.js +434 -0
  1619. package/src/utils/cron.js +260 -0
  1620. package/src/utils/cronJitterConfig.js +62 -0
  1621. package/src/utils/cronScheduler.js +388 -0
  1622. package/src/utils/cronTasks.js +328 -0
  1623. package/src/utils/cronTasksLock.js +159 -0
  1624. package/src/utils/crossProjectResume.js +46 -0
  1625. package/src/utils/crypto.js +13 -0
  1626. package/src/utils/cwd.js +29 -0
  1627. package/src/utils/debug.js +220 -0
  1628. package/src/utils/debugFilter.js +125 -0
  1629. package/src/utils/deepLink/banner.js +103 -0
  1630. package/src/utils/deepLink/parseDeepLink.js +138 -0
  1631. package/src/utils/deepLink/protocolHandler.js +119 -0
  1632. package/src/utils/deepLink/registerProtocol.js +291 -0
  1633. package/src/utils/deepLink/terminalLauncher.js +455 -0
  1634. package/src/utils/deepLink/terminalPreference.js +51 -0
  1635. package/src/utils/desktopDeepLink.js +208 -0
  1636. package/src/utils/detectRepository.js +157 -0
  1637. package/src/utils/diagLogs.js +74 -0
  1638. package/src/utils/diff.js +108 -0
  1639. package/src/utils/directMemberMessage.js +34 -0
  1640. package/src/utils/displayTags.js +46 -0
  1641. package/src/utils/doctorContextWarnings.js +179 -0
  1642. package/src/utils/doctorDiagnostic.js +494 -0
  1643. package/src/utils/dxt/helpers.js +64 -0
  1644. package/src/utils/dxt/zip.js +167 -0
  1645. package/src/utils/earlyInput.js +166 -0
  1646. package/src/utils/editor.js +163 -0
  1647. package/src/utils/effort.js +271 -0
  1648. package/src/utils/embeddedTools.js +26 -0
  1649. package/src/utils/employeeChat.js +271 -0
  1650. package/src/utils/employeeDb.js +326 -0
  1651. package/src/utils/env.js +358 -0
  1652. package/src/utils/envDynamic.js +130 -0
  1653. package/src/utils/envUtils.js +161 -0
  1654. package/src/utils/envValidation.js +26 -0
  1655. package/src/utils/errorLogSink.js +196 -0
  1656. package/src/utils/errors.js +207 -0
  1657. package/src/utils/exampleCommands.js +165 -0
  1658. package/src/utils/execFileNoThrow.js +93 -0
  1659. package/src/utils/execFileNoThrowPortable.js +49 -0
  1660. package/src/utils/execSyncWrapper.js +6 -0
  1661. package/src/utils/exportRenderer.js +71 -0
  1662. package/src/utils/extraUsage.js +19 -0
  1663. package/src/utils/fastMode.js +393 -0
  1664. package/src/utils/file.js +467 -0
  1665. package/src/utils/fileHistory.js +851 -0
  1666. package/src/utils/fileOperationAnalytics.js +45 -0
  1667. package/src/utils/filePersistence/filePersistence.js +212 -0
  1668. package/src/utils/filePersistence/outputsScanner.js +104 -0
  1669. package/src/utils/filePersistence/types.js +4 -0
  1670. package/src/utils/fileRead.js +81 -0
  1671. package/src/utils/fileReadCache.js +78 -0
  1672. package/src/utils/fileStateCache.js +99 -0
  1673. package/src/utils/findExecutable.js +13 -0
  1674. package/src/utils/fingerprint.js +58 -0
  1675. package/src/utils/forkedAgent.js +410 -0
  1676. package/src/utils/format.js +238 -0
  1677. package/src/utils/formatBriefTimestamp.js +72 -0
  1678. package/src/utils/fpsTracker.js +34 -0
  1679. package/src/utils/frontmatterParser.js +260 -0
  1680. package/src/utils/fsOperations.js +555 -0
  1681. package/src/utils/fullscreen.js +194 -0
  1682. package/src/utils/generatedFiles.js +122 -0
  1683. package/src/utils/generators.js +67 -0
  1684. package/src/utils/genericProcessUtils.js +155 -0
  1685. package/src/utils/getWorktreePaths.js +56 -0
  1686. package/src/utils/getWorktreePathsPortable.js +23 -0
  1687. package/src/utils/ghPrStatus.js +71 -0
  1688. package/src/utils/git/gitConfigParser.js +226 -0
  1689. package/src/utils/git/gitFilesystem.js +606 -0
  1690. package/src/utils/git/gitignore.js +84 -0
  1691. package/src/utils/git.js +725 -0
  1692. package/src/utils/gitDiff.js +395 -0
  1693. package/src/utils/gitSettings.js +18 -0
  1694. package/src/utils/github/ghAuthStatus.js +23 -0
  1695. package/src/utils/githubRepoPathMapping.js +135 -0
  1696. package/src/utils/glob.js +90 -0
  1697. package/src/utils/gracefulShutdown.js +447 -0
  1698. package/src/utils/groupToolUses.js +126 -0
  1699. package/src/utils/handlePromptSubmit.js +398 -0
  1700. package/src/utils/hash.js +44 -0
  1701. package/src/utils/headlessProfiler.js +147 -0
  1702. package/src/utils/heapDumpService.js +201 -0
  1703. package/src/utils/heatmap.js +151 -0
  1704. package/src/utils/highlightMatch.js +29 -0
  1705. package/src/utils/hooks/AsyncHookRegistry.js +187 -0
  1706. package/src/utils/hooks/apiQueryHookHelper.js +77 -0
  1707. package/src/utils/hooks/execAgentHook.js +257 -0
  1708. package/src/utils/hooks/execHttpHook.js +184 -0
  1709. package/src/utils/hooks/execPromptHook.js +171 -0
  1710. package/src/utils/hooks/fileChangedWatcher.js +161 -0
  1711. package/src/utils/hooks/hookEvents.js +111 -0
  1712. package/src/utils/hooks/hookHelpers.js +60 -0
  1713. package/src/utils/hooks/hooksConfigManager.js +323 -0
  1714. package/src/utils/hooks/hooksConfigSnapshot.js +114 -0
  1715. package/src/utils/hooks/hooksSettings.js +204 -0
  1716. package/src/utils/hooks/postSamplingHooks.js +39 -0
  1717. package/src/utils/hooks/registerFrontmatterHooks.js +47 -0
  1718. package/src/utils/hooks/registerSkillHooks.js +40 -0
  1719. package/src/utils/hooks/sessionHooks.js +252 -0
  1720. package/src/utils/hooks/skillImprovement.js +211 -0
  1721. package/src/utils/hooks/ssrfGuard.js +258 -0
  1722. package/src/utils/hooks.js +3668 -0
  1723. package/src/utils/horizontalScroll.js +108 -0
  1724. package/src/utils/http.js +120 -0
  1725. package/src/utils/hyperlink.js +28 -0
  1726. package/src/utils/iTermBackup.js +48 -0
  1727. package/src/utils/ide.js +1195 -0
  1728. package/src/utils/idePathConversion.js +66 -0
  1729. package/src/utils/idleTimeout.js +44 -0
  1730. package/src/utils/imagePaste.js +343 -0
  1731. package/src/utils/imageResizer.js +664 -0
  1732. package/src/utils/imageStore.js +150 -0
  1733. package/src/utils/imageValidation.js +92 -0
  1734. package/src/utils/immediateCommand.js +12 -0
  1735. package/src/utils/inProcessTeammateHelpers.js +71 -0
  1736. package/src/utils/ink.js +20 -0
  1737. package/src/utils/intl.js +83 -0
  1738. package/src/utils/jetbrains.js +152 -0
  1739. package/src/utils/json.js +231 -0
  1740. package/src/utils/jsonRead.js +14 -0
  1741. package/src/utils/keyboardShortcuts.js +11 -0
  1742. package/src/utils/lazySchema.js +8 -0
  1743. package/src/utils/listSessionsImpl.js +332 -0
  1744. package/src/utils/localInstaller.js +130 -0
  1745. package/src/utils/lockfile.js +30 -0
  1746. package/src/utils/log.js +280 -0
  1747. package/src/utils/logoV2Utils.js +256 -0
  1748. package/src/utils/mailbox.js +50 -0
  1749. package/src/utils/managedEnv.js +160 -0
  1750. package/src/utils/managedEnvConstants.js +185 -0
  1751. package/src/utils/markdown.js +315 -0
  1752. package/src/utils/markdownConfigLoader.js +480 -0
  1753. package/src/utils/mcp/dateTimeParser.js +102 -0
  1754. package/src/utils/mcp/elicitationValidation.js +259 -0
  1755. package/src/utils/mcpInstructionsDelta.js +97 -0
  1756. package/src/utils/mcpOutputStorage.js +159 -0
  1757. package/src/utils/mcpValidation.js +165 -0
  1758. package/src/utils/mcpWebSocketTransport.js +180 -0
  1759. package/src/utils/memoize.js +205 -0
  1760. package/src/utils/memory/types.js +9 -0
  1761. package/src/utils/memory/versions.js +7 -0
  1762. package/src/utils/memoryFileDetection.js +245 -0
  1763. package/src/utils/messagePredicates.js +6 -0
  1764. package/src/utils/messageQueueManager.js +430 -0
  1765. package/src/utils/messages/mappers.js +240 -0
  1766. package/src/utils/messages/systemInit.js +72 -0
  1767. package/src/utils/messages.js +4286 -0
  1768. package/src/utils/model/agent.js +128 -0
  1769. package/src/utils/model/aliases.js +21 -0
  1770. package/src/utils/model/antModels.js +25 -0
  1771. package/src/utils/model/bedrock.js +220 -0
  1772. package/src/utils/model/check1mAccess.js +64 -0
  1773. package/src/utils/model/configs.js +86 -0
  1774. package/src/utils/model/contextWindowUpgradeCheck.js +41 -0
  1775. package/src/utils/model/deprecation.js +72 -0
  1776. package/src/utils/model/model.js +533 -0
  1777. package/src/utils/model/modelAllowlist.js +148 -0
  1778. package/src/utils/model/modelCapabilities.js +105 -0
  1779. package/src/utils/model/modelOptions.js +450 -0
  1780. package/src/utils/model/modelStrings.js +144 -0
  1781. package/src/utils/model/modelSupportOverrides.js +40 -0
  1782. package/src/utils/model/providers.js +35 -0
  1783. package/src/utils/model/validateModel.js +131 -0
  1784. package/src/utils/modelCost.js +160 -0
  1785. package/src/utils/modifiers.js +39 -0
  1786. package/src/utils/mtls.js +132 -0
  1787. package/src/utils/nativeInstaller/download.js +370 -0
  1788. package/src/utils/nativeInstaller/index.js +8 -0
  1789. package/src/utils/nativeInstaller/installer.js +1395 -0
  1790. package/src/utils/nativeInstaller/packageManagers.js +258 -0
  1791. package/src/utils/nativeInstaller/pidLock.js +347 -0
  1792. package/src/utils/notebook.js +176 -0
  1793. package/src/utils/objectGroupBy.js +15 -0
  1794. package/src/utils/pasteStore.js +93 -0
  1795. package/src/utils/path.js +140 -0
  1796. package/src/utils/pdf.js +236 -0
  1797. package/src/utils/pdfUtils.js +61 -0
  1798. package/src/utils/peerAddress.js +20 -0
  1799. package/src/utils/permissions/PermissionMode.js +95 -0
  1800. package/src/utils/permissions/PermissionPromptToolResultSchema.js +85 -0
  1801. package/src/utils/permissions/PermissionResult.js +11 -0
  1802. package/src/utils/permissions/PermissionRule.js +19 -0
  1803. package/src/utils/permissions/PermissionUpdate.js +268 -0
  1804. package/src/utils/permissions/PermissionUpdateSchema.js +61 -0
  1805. package/src/utils/permissions/autoModeState.js +31 -0
  1806. package/src/utils/permissions/bashClassifier.js +30 -0
  1807. package/src/utils/permissions/bypassPermissionsKillswitch.js +115 -0
  1808. package/src/utils/permissions/classifierDecision.js +86 -0
  1809. package/src/utils/permissions/classifierShared.js +28 -0
  1810. package/src/utils/permissions/dangerousPatterns.js +78 -0
  1811. package/src/utils/permissions/denialTracking.js +34 -0
  1812. package/src/utils/permissions/filesystem.js +1411 -0
  1813. package/src/utils/permissions/getNextPermissionMode.js +74 -0
  1814. package/src/utils/permissions/pathValidation.js +351 -0
  1815. package/src/utils/permissions/permissionExplainer.js +188 -0
  1816. package/src/utils/permissions/permissionRuleParser.js +175 -0
  1817. package/src/utils/permissions/permissionSetup.js +1162 -0
  1818. package/src/utils/permissions/permissions.js +1063 -0
  1819. package/src/utils/permissions/permissionsLoader.js +217 -0
  1820. package/src/utils/permissions/shadowedRuleDetection.js +149 -0
  1821. package/src/utils/permissions/shellRuleMatching.js +174 -0
  1822. package/src/utils/permissions/yoloClassifier.js +1193 -0
  1823. package/src/utils/planModeV2.js +75 -0
  1824. package/src/utils/plans.js +334 -0
  1825. package/src/utils/platform.js +122 -0
  1826. package/src/utils/plugins/addDirPluginSettings.js +53 -0
  1827. package/src/utils/plugins/cacheUtils.js +174 -0
  1828. package/src/utils/plugins/dependencyResolver.js +244 -0
  1829. package/src/utils/plugins/fetchTelemetry.js +108 -0
  1830. package/src/utils/plugins/gitAvailability.js +65 -0
  1831. package/src/utils/plugins/headlessPluginInstall.js +136 -0
  1832. package/src/utils/plugins/hintRecommendation.js +136 -0
  1833. package/src/utils/plugins/installCounts.js +221 -0
  1834. package/src/utils/plugins/installedPluginsManager.js +1003 -0
  1835. package/src/utils/plugins/loadPluginAgents.js +219 -0
  1836. package/src/utils/plugins/loadPluginCommands.js +595 -0
  1837. package/src/utils/plugins/loadPluginHooks.js +239 -0
  1838. package/src/utils/plugins/loadPluginOutputStyles.js +112 -0
  1839. package/src/utils/plugins/lspPluginIntegration.js +293 -0
  1840. package/src/utils/plugins/lspRecommendation.js +278 -0
  1841. package/src/utils/plugins/managedPlugins.js +26 -0
  1842. package/src/utils/plugins/marketplaceHelpers.js +470 -0
  1843. package/src/utils/plugins/marketplaceManager.js +1939 -0
  1844. package/src/utils/plugins/mcpPluginIntegration.js +465 -0
  1845. package/src/utils/plugins/mcpbHandler.js +708 -0
  1846. package/src/utils/plugins/officialMarketplace.js +19 -0
  1847. package/src/utils/plugins/officialMarketplaceGcs.js +202 -0
  1848. package/src/utils/plugins/officialMarketplaceStartupCheck.js +344 -0
  1849. package/src/utils/plugins/orphanedPluginFilter.js +96 -0
  1850. package/src/utils/plugins/parseMarketplaceInput.js +143 -0
  1851. package/src/utils/plugins/performStartupChecks.js +66 -0
  1852. package/src/utils/plugins/pluginAutoupdate.js +210 -0
  1853. package/src/utils/plugins/pluginBlocklist.js +93 -0
  1854. package/src/utils/plugins/pluginDirectories.js +170 -0
  1855. package/src/utils/plugins/pluginFlagging.js +173 -0
  1856. package/src/utils/plugins/pluginIdentifier.js +78 -0
  1857. package/src/utils/plugins/pluginInstallationHelpers.js +400 -0
  1858. package/src/utils/plugins/pluginLoader.js +2426 -0
  1859. package/src/utils/plugins/pluginOptionsStorage.js +311 -0
  1860. package/src/utils/plugins/pluginPolicy.js +18 -0
  1861. package/src/utils/plugins/pluginStartupCheck.js +261 -0
  1862. package/src/utils/plugins/pluginVersioning.js +128 -0
  1863. package/src/utils/plugins/reconciler.js +181 -0
  1864. package/src/utils/plugins/refresh.js +162 -0
  1865. package/src/utils/plugins/schemas.js +1283 -0
  1866. package/src/utils/plugins/validatePlugin.js +765 -0
  1867. package/src/utils/plugins/walkPluginMarkdown.js +49 -0
  1868. package/src/utils/plugins/zipCache.js +346 -0
  1869. package/src/utils/plugins/zipCacheAdapters.js +133 -0
  1870. package/src/utils/powershell/dangerousCmdlets.js +174 -0
  1871. package/src/utils/powershell/parser.js +1357 -0
  1872. package/src/utils/powershell/staticPrefix.js +277 -0
  1873. package/src/utils/preflightChecks.js +147 -0
  1874. package/src/utils/privacyLevel.js +49 -0
  1875. package/src/utils/process.js +56 -0
  1876. package/src/utils/processUserInput/processBashCommand.js +118 -0
  1877. package/src/utils/processUserInput/processSlashCommand.js +845 -0
  1878. package/src/utils/processUserInput/processTextPrompt.js +68 -0
  1879. package/src/utils/processUserInput/processUserInput.js +344 -0
  1880. package/src/utils/profilerBase.js +32 -0
  1881. package/src/utils/promptCategory.js +39 -0
  1882. package/src/utils/promptEditor.js +151 -0
  1883. package/src/utils/promptShellExecution.js +117 -0
  1884. package/src/utils/protectedNamespace.js +4 -0
  1885. package/src/utils/proxy.js +345 -0
  1886. package/src/utils/queryContext.js +110 -0
  1887. package/src/utils/queryHelpers.js +436 -0
  1888. package/src/utils/queryProfiler.js +242 -0
  1889. package/src/utils/queueProcessor.js +70 -0
  1890. package/src/utils/readEditContext.js +176 -0
  1891. package/src/utils/readFileInRange.js +278 -0
  1892. package/src/utils/releaseNotes.js +307 -0
  1893. package/src/utils/renderOptions.js +67 -0
  1894. package/src/utils/ripgrep.js +521 -0
  1895. package/src/utils/sandbox/sandbox-adapter.js +750 -0
  1896. package/src/utils/sandbox/sandbox-ui-utils.js +11 -0
  1897. package/src/utils/sanitization.js +72 -0
  1898. package/src/utils/screenshotClipboard.js +89 -0
  1899. package/src/utils/sdkEventQueue.js +49 -0
  1900. package/src/utils/secureStorage/fallbackStorage.js +59 -0
  1901. package/src/utils/secureStorage/index.js +13 -0
  1902. package/src/utils/secureStorage/keychainPrefetch.js +91 -0
  1903. package/src/utils/secureStorage/macOsKeychainHelpers.js +91 -0
  1904. package/src/utils/secureStorage/macOsKeychainStorage.js +192 -0
  1905. package/src/utils/secureStorage/plainTextStorage.js +81 -0
  1906. package/src/utils/semanticBoolean.js +23 -0
  1907. package/src/utils/semanticNumber.js +34 -0
  1908. package/src/utils/semver.js +51 -0
  1909. package/src/utils/sequential.js +43 -0
  1910. package/src/utils/sessionActivity.js +120 -0
  1911. package/src/utils/sessionEnvVars.js +18 -0
  1912. package/src/utils/sessionEnvironment.js +131 -0
  1913. package/src/utils/sessionFileAccessHooks.js +205 -0
  1914. package/src/utils/sessionIngressAuth.js +113 -0
  1915. package/src/utils/sessionRestore.js +357 -0
  1916. package/src/utils/sessionStart.js +165 -0
  1917. package/src/utils/sessionState.js +76 -0
  1918. package/src/utils/sessionStorage.js +4162 -0
  1919. package/src/utils/sessionStoragePortable.js +665 -0
  1920. package/src/utils/sessionTitle.js +120 -0
  1921. package/src/utils/sessionUrl.js +50 -0
  1922. package/src/utils/set.js +50 -0
  1923. package/src/utils/settings/allErrors.js +29 -0
  1924. package/src/utils/settings/applySettingsChange.js +65 -0
  1925. package/src/utils/settings/changeDetector.js +409 -0
  1926. package/src/utils/settings/constants.js +166 -0
  1927. package/src/utils/settings/internalWrites.js +33 -0
  1928. package/src/utils/settings/managedPath.js +29 -0
  1929. package/src/utils/settings/mdm/constants.js +62 -0
  1930. package/src/utils/settings/mdm/rawRead.js +97 -0
  1931. package/src/utils/settings/mdm/settings.js +254 -0
  1932. package/src/utils/settings/permissionValidation.js +224 -0
  1933. package/src/utils/settings/pluginOnlyPolicy.js +53 -0
  1934. package/src/utils/settings/schemaOutput.js +7 -0
  1935. package/src/utils/settings/settings.js +791 -0
  1936. package/src/utils/settings/settingsCache.js +47 -0
  1937. package/src/utils/settings/toolValidationConfig.js +76 -0
  1938. package/src/utils/settings/types.js +846 -0
  1939. package/src/utils/settings/validateEditTool.js +34 -0
  1940. package/src/utils/settings/validation.js +192 -0
  1941. package/src/utils/settings/validationTips.js +111 -0
  1942. package/src/utils/shell/bashProvider.js +202 -0
  1943. package/src/utils/shell/outputLimits.js +7 -0
  1944. package/src/utils/shell/powershellDetection.js +96 -0
  1945. package/src/utils/shell/powershellProvider.js +104 -0
  1946. package/src/utils/shell/prefix.js +246 -0
  1947. package/src/utils/shell/readOnlyCommandValidation.js +1776 -0
  1948. package/src/utils/shell/resolveDefaultShell.js +13 -0
  1949. package/src/utils/shell/shellProvider.js +2 -0
  1950. package/src/utils/shell/shellToolUtils.js +21 -0
  1951. package/src/utils/shell/specPrefix.js +198 -0
  1952. package/src/utils/shellConfig.js +136 -0
  1953. package/src/utils/sideQuery.js +134 -0
  1954. package/src/utils/sideQuestion.js +121 -0
  1955. package/src/utils/signal.js +34 -0
  1956. package/src/utils/sinks.js +15 -0
  1957. package/src/utils/skills/skillChangeDetector.js +264 -0
  1958. package/src/utils/slashCommandParsing.js +46 -0
  1959. package/src/utils/sleep.js +72 -0
  1960. package/src/utils/sliceAnsi.js +74 -0
  1961. package/src/utils/slowOperations.js +216 -0
  1962. package/src/utils/standaloneAgent.js +20 -0
  1963. package/src/utils/startupProfiler.js +149 -0
  1964. package/src/utils/staticRender.js +104 -0
  1965. package/src/utils/stats.js +802 -0
  1966. package/src/utils/statsCache.js +330 -0
  1967. package/src/utils/status.js +359 -0
  1968. package/src/utils/statusNoticeDefinitions.js +123 -0
  1969. package/src/utils/statusNoticeHelpers.js +15 -0
  1970. package/src/utils/stream.js +73 -0
  1971. package/src/utils/streamJsonStdoutGuard.js +107 -0
  1972. package/src/utils/streamlinedTransform.js +162 -0
  1973. package/src/utils/stringUtils.js +202 -0
  1974. package/src/utils/subprocessEnv.js +87 -0
  1975. package/src/utils/suggestions/commandSuggestions.js +458 -0
  1976. package/src/utils/suggestions/directoryCompletion.js +191 -0
  1977. package/src/utils/suggestions/shellHistoryCompletion.js +95 -0
  1978. package/src/utils/suggestions/skillUsageTracking.js +50 -0
  1979. package/src/utils/suggestions/slackChannelSuggestions.js +169 -0
  1980. package/src/utils/swarm/It2SetupPrompt.js +386 -0
  1981. package/src/utils/swarm/backends/ITermBackend.js +276 -0
  1982. package/src/utils/swarm/backends/InProcessBackend.js +237 -0
  1983. package/src/utils/swarm/backends/PaneBackendExecutor.js +250 -0
  1984. package/src/utils/swarm/backends/TmuxBackend.js +574 -0
  1985. package/src/utils/swarm/backends/detection.js +112 -0
  1986. package/src/utils/swarm/backends/it2Setup.js +185 -0
  1987. package/src/utils/swarm/backends/registry.js +369 -0
  1988. package/src/utils/swarm/backends/teammateModeSnapshot.js +68 -0
  1989. package/src/utils/swarm/backends/types.js +9 -0
  1990. package/src/utils/swarm/constants.js +29 -0
  1991. package/src/utils/swarm/inProcessRunner.js +1021 -0
  1992. package/src/utils/swarm/leaderPermissionBridge.js +31 -0
  1993. package/src/utils/swarm/permissionSync.js +667 -0
  1994. package/src/utils/swarm/reconnection.js +82 -0
  1995. package/src/utils/swarm/spawnInProcess.js +218 -0
  1996. package/src/utils/swarm/spawnUtils.js +123 -0
  1997. package/src/utils/swarm/teamHelpers.js +484 -0
  1998. package/src/utils/swarm/teammateInit.js +87 -0
  1999. package/src/utils/swarm/teammateLayoutManager.js +82 -0
  2000. package/src/utils/swarm/teammateModel.js +9 -0
  2001. package/src/utils/swarm/teammatePromptAddendum.js +17 -0
  2002. package/src/utils/systemDirectories.js +51 -0
  2003. package/src/utils/systemPrompt.js +88 -0
  2004. package/src/utils/systemPromptType.js +9 -0
  2005. package/src/utils/systemTheme.js +108 -0
  2006. package/src/utils/taggedId.js +49 -0
  2007. package/src/utils/task/TaskOutput.js +320 -0
  2008. package/src/utils/task/diskOutput.js +387 -0
  2009. package/src/utils/task/framework.js +236 -0
  2010. package/src/utils/task/outputFormatting.js +24 -0
  2011. package/src/utils/task/sdkProgress.js +24 -0
  2012. package/src/utils/taskSummary.js +3 -0
  2013. package/src/utils/tasks.js +672 -0
  2014. package/src/utils/teamDiscovery.js +48 -0
  2015. package/src/utils/teamMemoryOps.js +67 -0
  2016. package/src/utils/teammate.js +237 -0
  2017. package/src/utils/teammateContext.js +56 -0
  2018. package/src/utils/teammateMailbox.js +793 -0
  2019. package/src/utils/telemetry/betaSessionTracing.js +25 -0
  2020. package/src/utils/telemetry/bigqueryExporter.js +17 -0
  2021. package/src/utils/telemetry/events.js +7 -0
  2022. package/src/utils/telemetry/instrumentation.js +16 -0
  2023. package/src/utils/telemetry/logger.js +25 -0
  2024. package/src/utils/telemetry/perfettoTracing.js +882 -0
  2025. package/src/utils/telemetry/pluginTelemetry.js +76 -0
  2026. package/src/utils/telemetry/sessionTracing.js +62 -0
  2027. package/src/utils/telemetry/skillLoadedEvent.js +4 -0
  2028. package/src/utils/telemetryAttributes.js +56 -0
  2029. package/src/utils/teleport/api.js +299 -0
  2030. package/src/utils/teleport/environmentSelection.js +55 -0
  2031. package/src/utils/teleport/environments.js +84 -0
  2032. package/src/utils/teleport/gitBundle.js +192 -0
  2033. package/src/utils/teleport.js +1047 -0
  2034. package/src/utils/tempfile.js +26 -0
  2035. package/src/utils/terminal.js +105 -0
  2036. package/src/utils/terminalPanel.js +155 -0
  2037. package/src/utils/textHighlighting.js +113 -0
  2038. package/src/utils/thaddeusHints.js +142 -0
  2039. package/src/utils/theme.js +525 -0
  2040. package/src/utils/thinking.js +130 -0
  2041. package/src/utils/timeouts.js +35 -0
  2042. package/src/utils/tmuxSocket.js +373 -0
  2043. package/src/utils/todo/types.js +9 -0
  2044. package/src/utils/tokenBudget.js +62 -0
  2045. package/src/utils/tokens.js +223 -0
  2046. package/src/utils/toolErrors.js +101 -0
  2047. package/src/utils/toolPool.js +61 -0
  2048. package/src/utils/toolResultStorage.js +768 -0
  2049. package/src/utils/toolSchemaCache.js +7 -0
  2050. package/src/utils/toolSearch.js +551 -0
  2051. package/src/utils/transcriptSearch.js +200 -0
  2052. package/src/utils/treeify.js +111 -0
  2053. package/src/utils/truncate.js +164 -0
  2054. package/src/utils/udsClient.js +5 -0
  2055. package/src/utils/udsMessaging.js +23 -0
  2056. package/src/utils/ultraplan/ccrSession.js +264 -0
  2057. package/src/utils/ultraplan/keyword.js +122 -0
  2058. package/src/utils/unaryLogging.js +16 -0
  2059. package/src/utils/undercover.js +89 -0
  2060. package/src/utils/user.js +137 -0
  2061. package/src/utils/userAgent.js +9 -0
  2062. package/src/utils/userPromptKeywords.js +21 -0
  2063. package/src/utils/uuid.js +22 -0
  2064. package/src/utils/warningHandler.js +97 -0
  2065. package/src/utils/which.js +75 -0
  2066. package/src/utils/windowsPaths.js +146 -0
  2067. package/src/utils/withResolvers.js +13 -0
  2068. package/src/utils/words.js +793 -0
  2069. package/src/utils/workforceIntent.js +192 -0
  2070. package/src/utils/workloadContext.js +42 -0
  2071. package/src/utils/worktree.js +1142 -0
  2072. package/src/utils/worktreeModeEnabled.js +11 -0
  2073. package/src/utils/xdg.js +52 -0
  2074. package/src/utils/xml.js +15 -0
  2075. package/src/utils/yaml.js +14 -0
  2076. package/src/utils/zodToJsonSchema.js +19 -0
  2077. package/src/vim/motions.js +73 -0
  2078. package/src/vim/operators.js +401 -0
  2079. package/src/vim/textObjects.js +153 -0
  2080. package/src/vim/transitions.js +340 -0
  2081. package/src/vim/types.js +93 -0
  2082. package/src/voice/voiceModeEnabled.js +20 -0
  2083. package/thaddeus-terminal.ts +401 -3
  2084. package/thaddeus.command +1 -1
@@ -0,0 +1,3668 @@
1
+ // biome-ignore-all assist/source/organizeImports: ANT-ONLY import markers must not be reordered
2
+ /**
3
+ * Hooks are user-defined shell commands that can be executed at various points
4
+ * in Thaddeus's lifecycle.
5
+ */
6
+ import { basename } from 'path';
7
+ import { spawn } from 'child_process';
8
+ import { pathExists } from './file.js';
9
+ import { wrapSpawn } from './ShellCommand.js';
10
+ import { TaskOutput } from './task/TaskOutput.js';
11
+ import { getCwd } from './cwd.js';
12
+ import { randomUUID } from 'crypto';
13
+ import { formatShellPrefixCommand } from './bash/shellPrefix.js';
14
+ import { getHookEnvFilePath, invalidateSessionEnvCache, } from './sessionEnvironment.js';
15
+ import { subprocessEnv } from './subprocessEnv.js';
16
+ import { getPlatform } from './platform.js';
17
+ import { findGitBashPath, windowsPathToPosixPath } from './windowsPaths.js';
18
+ import { getCachedPowerShellPath } from './shell/powershellDetection.js';
19
+ import { DEFAULT_HOOK_SHELL } from './shell/shellProvider.js';
20
+ import { buildPowerShellArgs } from './shell/powershellProvider.js';
21
+ import { loadPluginOptions, substituteUserConfigVariables, } from './plugins/pluginOptionsStorage.js';
22
+ import { getPluginDataDir } from './plugins/pluginDirectories.js';
23
+ import { getSessionId, getProjectRoot, getIsNonInteractiveSession, getRegisteredHooks, getStatsStore, addToTurnHookDuration, getOriginalCwd, getMainThreadAgentType, } from '../bootstrap/state.js';
24
+ import { checkHasTrustDialogAccepted } from './config.js';
25
+ import { getHooksConfigFromSnapshot, shouldAllowManagedHooksOnly, shouldDisableAllHooksIncludingManaged, } from './hooks/hooksConfigSnapshot.js';
26
+ import { getTranscriptPathForSession, getAgentTranscriptPath, } from './sessionStorage.js';
27
+ import { getSettings_DEPRECATED, getSettingsForSource, } from './settings/settings.js';
28
+ import { logEvent, } from 'src/services/analytics/index.js';
29
+ import { logOTelEvent } from './telemetry/events.js';
30
+ import { ALLOWED_OFFICIAL_MARKETPLACE_NAMES } from './plugins/schemas.js';
31
+ import { startHookSpan, endHookSpan, isBetaTracingEnabled, } from './telemetry/sessionTracing.js';
32
+ import { hookJSONOutputSchema, promptRequestSchema, isAsyncHookJSONOutput, isSyncHookJSONOutput, } from '../types/hooks.js';
33
+ import chalk from 'chalk';
34
+ import { getHookDisplayText } from './hooks/hooksSettings.js';
35
+ import { logForDebugging } from './debug.js';
36
+ import { logForDiagnosticsNoPII } from './diagLogs.js';
37
+ import { firstLineOf } from './stringUtils.js';
38
+ import { normalizeLegacyToolName, getLegacyToolNames, permissionRuleValueFromString, } from './permissions/permissionRuleParser.js';
39
+ import { logError } from './log.js';
40
+ import { createCombinedAbortSignal } from './combinedAbortSignal.js';
41
+ import { registerPendingAsyncHook } from './hooks/AsyncHookRegistry.js';
42
+ import { enqueuePendingNotification } from './messageQueueManager.js';
43
+ import { extractTextContent, getLastAssistantMessage, wrapInSystemReminder, } from './messages.js';
44
+ import { emitHookStarted, emitHookResponse, startHookProgressInterval, } from './hooks/hookEvents.js';
45
+ import { createAttachmentMessage } from './attachments.js';
46
+ import { all } from './generators.js';
47
+ import { findToolByName } from '../Tool.js';
48
+ import { execPromptHook } from './hooks/execPromptHook.js';
49
+ import { execAgentHook } from './hooks/execAgentHook.js';
50
+ import { execHttpHook } from './hooks/execHttpHook.js';
51
+ import { getSessionHooks, getSessionFunctionHooks, getSessionHookCallback, clearSessionHooks, } from './hooks/sessionHooks.js';
52
+ import { jsonStringify, jsonParse } from './slowOperations.js';
53
+ import { isEnvTruthy } from './envUtils.js';
54
+ import { errorMessage, getErrnoCode } from './errors.js';
55
+ const TOOL_HOOK_EXECUTION_TIMEOUT_MS = 10 * 60 * 1000;
56
+ /**
57
+ * SessionEnd hooks run during shutdown/clear and need a much tighter bound
58
+ * than TOOL_HOOK_EXECUTION_TIMEOUT_MS. This value is used by callers as both
59
+ * the per-hook default timeout AND the overall AbortSignal cap (hooks run in
60
+ * parallel, so one value suffices). Overridable via env var for users whose
61
+ * teardown scripts need more time.
62
+ */
63
+ const SESSION_END_HOOK_TIMEOUT_MS_DEFAULT = 1500;
64
+ export function getSessionEndHookTimeoutMs() {
65
+ const raw = process.env.THADDEUS_SESSIONEND_HOOKS_TIMEOUT_MS;
66
+ const parsed = raw ? parseInt(raw, 10) : NaN;
67
+ return Number.isFinite(parsed) && parsed > 0
68
+ ? parsed
69
+ : SESSION_END_HOOK_TIMEOUT_MS_DEFAULT;
70
+ }
71
+ function executeInBackground({ processId, hookId, shellCommand, asyncResponse, hookEvent, hookName, command, asyncRewake, pluginId, }) {
72
+ if (asyncRewake) {
73
+ // asyncRewake hooks bypass the registry entirely. On completion, if exit
74
+ // code 2 (blocking error), enqueue as a task-notification so it wakes the
75
+ // model via useQueueProcessor (idle) or gets injected mid-query via
76
+ // queued_command attachments (busy).
77
+ //
78
+ // NOTE: We deliberately do NOT call shellCommand.background() here, because
79
+ // it calls taskOutput.spillToDisk() which breaks in-memory stdout/stderr
80
+ // capture (getStderr() returns '' in disk mode). The StreamWrappers stay
81
+ // attached and pipe data into the in-memory TaskOutput buffers. The abort
82
+ // handler already no-ops on 'interrupt' reason (user submitted a new
83
+ // message), so the hook survives new prompts. A hard cancel (Escape) WILL
84
+ // kill the hook via the abort handler, which is the desired behavior.
85
+ void shellCommand.result.then(async (result) => {
86
+ // result resolves on 'exit', but stdio 'data' events may still be
87
+ // pending. Yield to I/O so the StreamWrapper data handlers drain into
88
+ // TaskOutput before we read it.
89
+ await new Promise(resolve => setImmediate(resolve));
90
+ const stdout = await shellCommand.taskOutput.getStdout();
91
+ const stderr = shellCommand.taskOutput.getStderr();
92
+ shellCommand.cleanup();
93
+ emitHookResponse({
94
+ hookId,
95
+ hookName,
96
+ hookEvent,
97
+ output: stdout + stderr,
98
+ stdout,
99
+ stderr,
100
+ exitCode: result.code,
101
+ outcome: result.code === 0 ? 'success' : 'error',
102
+ });
103
+ if (result.code === 2) {
104
+ enqueuePendingNotification({
105
+ value: wrapInSystemReminder(`Stop hook blocking error from command "${hookName}": ${stderr || stdout}`),
106
+ mode: 'task-notification',
107
+ });
108
+ }
109
+ });
110
+ return true;
111
+ }
112
+ // TaskOutput on the ShellCommand accumulates data — no stream listeners needed
113
+ if (!shellCommand.background(processId)) {
114
+ return false;
115
+ }
116
+ registerPendingAsyncHook({
117
+ processId,
118
+ hookId,
119
+ asyncResponse,
120
+ hookEvent,
121
+ hookName,
122
+ command,
123
+ shellCommand,
124
+ pluginId,
125
+ });
126
+ return true;
127
+ }
128
+ /**
129
+ * Checks if a hook should be skipped due to lack of workspace trust.
130
+ *
131
+ * ALL hooks require workspace trust because they execute arbitrary commands from
132
+ * .claude/settings.json. This is a defense-in-depth security measure.
133
+ *
134
+ * Context: Hooks are captured via captureHooksConfigSnapshot() before the trust
135
+ * dialog is shown. While most hooks won't execute until after trust is established
136
+ * through normal program flow, enforcing trust for ALL hooks prevents:
137
+ * - Future bugs where a hook might accidentally execute before trust
138
+ * - Any codepath that might trigger hooks before trust dialog
139
+ * - Security issues from hook execution in untrusted workspaces
140
+ *
141
+ * Historical vulnerabilities that prompted this check:
142
+ * - SessionEnd hooks executing when user declines trust dialog
143
+ * - SubagentStop hooks executing when subagent completes before trust
144
+ *
145
+ * @returns true if hook should be skipped, false if it should execute
146
+ */
147
+ export function shouldSkipHookDueToTrust() {
148
+ // In non-interactive mode (SDK), trust is implicit - always execute
149
+ const isInteractive = !getIsNonInteractiveSession();
150
+ if (!isInteractive) {
151
+ return false;
152
+ }
153
+ // In interactive mode, ALL hooks require trust
154
+ const hasTrust = checkHasTrustDialogAccepted();
155
+ return !hasTrust;
156
+ }
157
+ /**
158
+ * Creates the base hook input that's common to all hook types
159
+ */
160
+ export function createBaseHookInput(permissionMode, sessionId,
161
+ // Typed narrowly (not ToolUseContext) so callers can pass toolUseContext
162
+ // directly via structural typing without this function depending on Tool.ts.
163
+ agentInfo) {
164
+ const resolvedSessionId = sessionId ?? getSessionId();
165
+ // agent_type: subagent's type (from toolUseContext) takes precedence over
166
+ // the session's --agent flag. Hooks use agent_id presence to distinguish
167
+ // subagent calls from main-thread calls in a --agent session.
168
+ const resolvedAgentType = agentInfo?.agentType ?? getMainThreadAgentType();
169
+ return {
170
+ session_id: resolvedSessionId,
171
+ transcript_path: getTranscriptPathForSession(resolvedSessionId),
172
+ cwd: getCwd(),
173
+ permission_mode: permissionMode,
174
+ agent_id: agentInfo?.agentId,
175
+ agent_type: resolvedAgentType,
176
+ };
177
+ }
178
+ /**
179
+ * Parse and validate a JSON string against the hook output Zod schema.
180
+ * Returns the validated output or formatted validation errors.
181
+ */
182
+ function validateHookJson(jsonString) {
183
+ const parsed = jsonParse(jsonString);
184
+ const validation = hookJSONOutputSchema().safeParse(parsed);
185
+ if (validation.success) {
186
+ logForDebugging('Successfully parsed and validated hook JSON output');
187
+ return { json: validation.data };
188
+ }
189
+ const errors = validation.error.issues
190
+ .map(err => ` - ${err.path.join('.')}: ${err.message}`)
191
+ .join('\n');
192
+ return {
193
+ validationError: `Hook JSON output validation failed:\n${errors}\n\nThe hook's output was: ${jsonStringify(parsed, null, 2)}`,
194
+ };
195
+ }
196
+ function parseHookOutput(stdout) {
197
+ const trimmed = stdout.trim();
198
+ if (!trimmed.startsWith('{')) {
199
+ logForDebugging('Hook output does not start with {, treating as plain text');
200
+ return { plainText: stdout };
201
+ }
202
+ try {
203
+ const result = validateHookJson(trimmed);
204
+ if ('json' in result) {
205
+ return result;
206
+ }
207
+ // For command hooks, include the schema hint in the error message
208
+ const errorMessage = `${result.validationError}\n\nExpected schema:\n${jsonStringify({
209
+ continue: 'boolean (optional)',
210
+ suppressOutput: 'boolean (optional)',
211
+ stopReason: 'string (optional)',
212
+ decision: '"approve" | "block" (optional)',
213
+ reason: 'string (optional)',
214
+ systemMessage: 'string (optional)',
215
+ permissionDecision: '"allow" | "deny" | "ask" (optional)',
216
+ hookSpecificOutput: {
217
+ 'for PreToolUse': {
218
+ hookEventName: '"PreToolUse"',
219
+ permissionDecision: '"allow" | "deny" | "ask" (optional)',
220
+ permissionDecisionReason: 'string (optional)',
221
+ updatedInput: 'object (optional) - Modified tool input to use',
222
+ },
223
+ 'for UserPromptSubmit': {
224
+ hookEventName: '"UserPromptSubmit"',
225
+ additionalContext: 'string (required)',
226
+ },
227
+ 'for PostToolUse': {
228
+ hookEventName: '"PostToolUse"',
229
+ additionalContext: 'string (optional)',
230
+ },
231
+ },
232
+ }, null, 2)}`;
233
+ logForDebugging(errorMessage);
234
+ return { plainText: stdout, validationError: errorMessage };
235
+ }
236
+ catch (e) {
237
+ logForDebugging(`Failed to parse hook output as JSON: ${e}`);
238
+ return { plainText: stdout };
239
+ }
240
+ }
241
+ function parseHttpHookOutput(body) {
242
+ const trimmed = body.trim();
243
+ if (trimmed === '') {
244
+ const validation = hookJSONOutputSchema().safeParse({});
245
+ if (validation.success) {
246
+ logForDebugging('HTTP hook returned empty body, treating as empty JSON object');
247
+ return { json: validation.data };
248
+ }
249
+ }
250
+ if (!trimmed.startsWith('{')) {
251
+ const validationError = `HTTP hook must return JSON, but got non-JSON response body: ${trimmed.length > 200 ? trimmed.slice(0, 200) + '\u2026' : trimmed}`;
252
+ logForDebugging(validationError);
253
+ return { validationError };
254
+ }
255
+ try {
256
+ const result = validateHookJson(trimmed);
257
+ if ('json' in result) {
258
+ return result;
259
+ }
260
+ logForDebugging(result.validationError);
261
+ return result;
262
+ }
263
+ catch (e) {
264
+ const validationError = `HTTP hook must return valid JSON, but parsing failed: ${e}`;
265
+ logForDebugging(validationError);
266
+ return { validationError };
267
+ }
268
+ }
269
+ function processHookJSONOutput({ json, command, hookName, toolUseID, hookEvent, expectedHookEvent, stdout, stderr, exitCode, durationMs, }) {
270
+ const result = {};
271
+ // At this point we know it's a sync response
272
+ const syncJson = json;
273
+ // Handle common elements
274
+ if (syncJson.continue === false) {
275
+ result.preventContinuation = true;
276
+ if (syncJson.stopReason) {
277
+ result.stopReason = syncJson.stopReason;
278
+ }
279
+ }
280
+ if (json.decision) {
281
+ switch (json.decision) {
282
+ case 'approve':
283
+ result.permissionBehavior = 'allow';
284
+ break;
285
+ case 'block':
286
+ result.permissionBehavior = 'deny';
287
+ result.blockingError = {
288
+ blockingError: json.reason || 'Blocked by hook',
289
+ command,
290
+ };
291
+ break;
292
+ default:
293
+ // Handle unknown decision types as errors
294
+ throw new Error(`Unknown hook decision type: ${json.decision}. Valid types are: approve, block`);
295
+ }
296
+ }
297
+ // Handle systemMessage field
298
+ if (json.systemMessage) {
299
+ result.systemMessage = json.systemMessage;
300
+ }
301
+ // Handle PreToolUse specific
302
+ if (json.hookSpecificOutput?.hookEventName === 'PreToolUse' &&
303
+ json.hookSpecificOutput.permissionDecision) {
304
+ switch (json.hookSpecificOutput.permissionDecision) {
305
+ case 'allow':
306
+ result.permissionBehavior = 'allow';
307
+ break;
308
+ case 'deny':
309
+ result.permissionBehavior = 'deny';
310
+ result.blockingError = {
311
+ blockingError: json.reason || 'Blocked by hook',
312
+ command,
313
+ };
314
+ break;
315
+ case 'ask':
316
+ result.permissionBehavior = 'ask';
317
+ break;
318
+ default:
319
+ // Handle unknown decision types as errors
320
+ throw new Error(`Unknown hook permissionDecision type: ${json.hookSpecificOutput.permissionDecision}. Valid types are: allow, deny, ask`);
321
+ }
322
+ }
323
+ if (result.permissionBehavior !== undefined && json.reason !== undefined) {
324
+ result.hookPermissionDecisionReason = json.reason;
325
+ }
326
+ // Handle hookSpecificOutput
327
+ if (json.hookSpecificOutput) {
328
+ // Validate hook event name matches expected if provided
329
+ if (expectedHookEvent &&
330
+ json.hookSpecificOutput.hookEventName !== expectedHookEvent) {
331
+ throw new Error(`Hook returned incorrect event name: expected '${expectedHookEvent}' but got '${json.hookSpecificOutput.hookEventName}'. Full stdout: ${jsonStringify(json, null, 2)}`);
332
+ }
333
+ switch (json.hookSpecificOutput.hookEventName) {
334
+ case 'PreToolUse':
335
+ // Override with more specific permission decision if provided
336
+ if (json.hookSpecificOutput.permissionDecision) {
337
+ switch (json.hookSpecificOutput.permissionDecision) {
338
+ case 'allow':
339
+ result.permissionBehavior = 'allow';
340
+ break;
341
+ case 'deny':
342
+ result.permissionBehavior = 'deny';
343
+ result.blockingError = {
344
+ blockingError: json.hookSpecificOutput.permissionDecisionReason ||
345
+ json.reason ||
346
+ 'Blocked by hook',
347
+ command,
348
+ };
349
+ break;
350
+ case 'ask':
351
+ result.permissionBehavior = 'ask';
352
+ break;
353
+ }
354
+ }
355
+ result.hookPermissionDecisionReason =
356
+ json.hookSpecificOutput.permissionDecisionReason;
357
+ // Extract updatedInput if provided
358
+ if (json.hookSpecificOutput.updatedInput) {
359
+ result.updatedInput = json.hookSpecificOutput.updatedInput;
360
+ }
361
+ // Extract additionalContext if provided
362
+ result.additionalContext = json.hookSpecificOutput.additionalContext;
363
+ break;
364
+ case 'UserPromptSubmit':
365
+ result.additionalContext = json.hookSpecificOutput.additionalContext;
366
+ break;
367
+ case 'SessionStart':
368
+ result.additionalContext = json.hookSpecificOutput.additionalContext;
369
+ result.initialUserMessage = json.hookSpecificOutput.initialUserMessage;
370
+ if ('watchPaths' in json.hookSpecificOutput &&
371
+ json.hookSpecificOutput.watchPaths) {
372
+ result.watchPaths = json.hookSpecificOutput.watchPaths;
373
+ }
374
+ break;
375
+ case 'Setup':
376
+ result.additionalContext = json.hookSpecificOutput.additionalContext;
377
+ break;
378
+ case 'SubagentStart':
379
+ result.additionalContext = json.hookSpecificOutput.additionalContext;
380
+ break;
381
+ case 'PostToolUse':
382
+ result.additionalContext = json.hookSpecificOutput.additionalContext;
383
+ // Extract updatedMCPToolOutput if provided
384
+ if (json.hookSpecificOutput.updatedMCPToolOutput) {
385
+ result.updatedMCPToolOutput =
386
+ json.hookSpecificOutput.updatedMCPToolOutput;
387
+ }
388
+ break;
389
+ case 'PostToolUseFailure':
390
+ result.additionalContext = json.hookSpecificOutput.additionalContext;
391
+ break;
392
+ case 'PermissionDenied':
393
+ result.retry = json.hookSpecificOutput.retry;
394
+ break;
395
+ case 'PermissionRequest':
396
+ // Extract the permission request decision
397
+ if (json.hookSpecificOutput.decision) {
398
+ result.permissionRequestResult = json.hookSpecificOutput.decision;
399
+ // Also update permissionBehavior for consistency
400
+ result.permissionBehavior =
401
+ json.hookSpecificOutput.decision.behavior === 'allow'
402
+ ? 'allow'
403
+ : 'deny';
404
+ if (json.hookSpecificOutput.decision.behavior === 'allow' &&
405
+ json.hookSpecificOutput.decision.updatedInput) {
406
+ result.updatedInput = json.hookSpecificOutput.decision.updatedInput;
407
+ }
408
+ }
409
+ break;
410
+ case 'Elicitation':
411
+ if (json.hookSpecificOutput.action) {
412
+ result.elicitationResponse = {
413
+ action: json.hookSpecificOutput.action,
414
+ content: json.hookSpecificOutput.content,
415
+ };
416
+ if (json.hookSpecificOutput.action === 'decline') {
417
+ result.blockingError = {
418
+ blockingError: json.reason || 'Elicitation denied by hook',
419
+ command,
420
+ };
421
+ }
422
+ }
423
+ break;
424
+ case 'ElicitationResult':
425
+ if (json.hookSpecificOutput.action) {
426
+ result.elicitationResultResponse = {
427
+ action: json.hookSpecificOutput.action,
428
+ content: json.hookSpecificOutput.content,
429
+ };
430
+ if (json.hookSpecificOutput.action === 'decline') {
431
+ result.blockingError = {
432
+ blockingError: json.reason || 'Elicitation result blocked by hook',
433
+ command,
434
+ };
435
+ }
436
+ }
437
+ break;
438
+ }
439
+ }
440
+ return {
441
+ ...result,
442
+ message: result.blockingError
443
+ ? createAttachmentMessage({
444
+ type: 'hook_blocking_error',
445
+ hookName,
446
+ toolUseID,
447
+ hookEvent,
448
+ blockingError: result.blockingError,
449
+ })
450
+ : createAttachmentMessage({
451
+ type: 'hook_success',
452
+ hookName,
453
+ toolUseID,
454
+ hookEvent,
455
+ // JSON-output hooks inject context via additionalContext →
456
+ // hook_additional_context, not this field. Empty content suppresses
457
+ // the trivial "X hook success: Success" system-reminder that
458
+ // otherwise pollutes every turn (messages.ts:3577 skips on '').
459
+ content: '',
460
+ stdout,
461
+ stderr,
462
+ exitCode,
463
+ command,
464
+ durationMs,
465
+ }),
466
+ };
467
+ }
468
+ /**
469
+ * Execute a command-based hook using bash or PowerShell.
470
+ *
471
+ * Shell resolution: hook.shell → 'bash'. PowerShell hooks spawn pwsh
472
+ * with -NoProfile -NonInteractive -Command and skip bash-specific prep
473
+ * (POSIX path conversion, .sh auto-prepend, THADDEUS_SHELL_PREFIX).
474
+ * See docs/design/ps-shell-selection.md §5.1.
475
+ */
476
+ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hookId, hookIndex, pluginRoot, pluginId, skillRoot, forceSyncExecution, requestPrompt) {
477
+ // Gated to once-per-session events to keep diag_log volume bounded.
478
+ // started/completed live inside the try/finally so setup-path throws
479
+ // don't orphan a started marker — that'd be indistinguishable from a hang.
480
+ const shouldEmitDiag = hookEvent === 'SessionStart' ||
481
+ hookEvent === 'Setup' ||
482
+ hookEvent === 'SessionEnd';
483
+ const diagStartMs = Date.now();
484
+ let diagExitCode;
485
+ let diagAborted = false;
486
+ const isWindows = getPlatform() === 'windows';
487
+ // --
488
+ // Per-hook shell selection (phase 1 of docs/design/ps-shell-selection.md).
489
+ // Resolution order: hook.shell → DEFAULT_HOOK_SHELL. The defaultShell
490
+ // fallback (settings.defaultShell) is phase 2 — not wired yet.
491
+ //
492
+ // The bash path is the historical default and stays unchanged. The
493
+ // PowerShell path deliberately skips the Windows-specific bash
494
+ // accommodations (cygpath conversion, .sh auto-prepend, POSIX-quoted
495
+ // SHELL_PREFIX).
496
+ const shellType = hook.shell ?? DEFAULT_HOOK_SHELL;
497
+ const isPowerShell = shellType === 'powershell';
498
+ // --
499
+ // Windows bash path: hooks run via Git Bash (Cygwin), NOT cmd.exe.
500
+ //
501
+ // This means every path we put into env vars or substitute into the command
502
+ // string MUST be a POSIX path (/c/Users/foo), not a Windows path
503
+ // (C:\Users\foo or C:/Users/foo). Git Bash cannot resolve Windows paths.
504
+ //
505
+ // windowsPathToPosixPath() is pure-JS regex conversion (no cygpath shell-out):
506
+ // C:\Users\foo -> /c/Users/foo, UNC preserved, slashes flipped. Memoized
507
+ // (LRU-500) so repeated calls are cheap.
508
+ //
509
+ // PowerShell path: use native paths — skip the conversion entirely.
510
+ // PowerShell expects Windows paths on Windows (and native paths on
511
+ // Unix where pwsh is also available).
512
+ const toHookPath = isWindows && !isPowerShell
513
+ ? (p) => windowsPathToPosixPath(p)
514
+ : (p) => p;
515
+ // Set CLAUDE_PROJECT_DIR to the stable project root (not the worktree path).
516
+ // getProjectRoot() is never updated when entering a worktree, so hooks that
517
+ // reference $CLAUDE_PROJECT_DIR always resolve relative to the real repo root.
518
+ const projectDir = getProjectRoot();
519
+ // Substitute ${CLAUDE_PLUGIN_ROOT} and ${user_config.X} in the command string.
520
+ // Order matches MCP/LSP (plugin vars FIRST, then user config) so a user-
521
+ // entered value containing the literal text ${CLAUDE_PLUGIN_ROOT} is treated
522
+ // as opaque — not re-interpreted as a template.
523
+ let command = hook.command;
524
+ let pluginOpts;
525
+ if (pluginRoot) {
526
+ // Plugin directory gone (orphan GC race, concurrent session deleted it):
527
+ // throw so callers yield a non-blocking error. Running would fail — and
528
+ // `python3 <missing>.py` exits 2, the hook protocol's "block" code, which
529
+ // bricks UserPromptSubmit/Stop until restart. The pre-check is necessary
530
+ // because exit-2-from-missing-script is indistinguishable from an
531
+ // intentional block after spawn.
532
+ if (!(await pathExists(pluginRoot))) {
533
+ throw new Error(`Plugin directory does not exist: ${pluginRoot}` +
534
+ (pluginId ? ` (${pluginId} — run /plugin to reinstall)` : ''));
535
+ }
536
+ // Inline both ROOT and DATA substitution instead of calling
537
+ // substitutePluginVariables(). That helper normalizes \ → / on Windows
538
+ // unconditionally — correct for bash (toHookPath already produced /c/...
539
+ // so it's a no-op) but wrong for PS where toHookPath is identity and we
540
+ // want native C:\... backslashes. Inlining also lets us use the function-
541
+ // form .replace() so paths containing $ aren't mangled by $-pattern
542
+ // interpretation (rare but possible: \\server\c$\plugin).
543
+ const rootPath = toHookPath(pluginRoot);
544
+ command = command.replace(/\$\{CLAUDE_PLUGIN_ROOT\}/g, () => rootPath);
545
+ if (pluginId) {
546
+ const dataPath = toHookPath(getPluginDataDir(pluginId));
547
+ command = command.replace(/\$\{CLAUDE_PLUGIN_DATA\}/g, () => dataPath);
548
+ }
549
+ if (pluginId) {
550
+ pluginOpts = loadPluginOptions(pluginId);
551
+ // Throws if a referenced key is missing — that means the hook uses a key
552
+ // that's either not declared in manifest.userConfig or not yet configured.
553
+ // Caught upstream like any other hook exec failure.
554
+ command = substituteUserConfigVariables(command, pluginOpts);
555
+ }
556
+ }
557
+ // On Windows (bash only), auto-prepend `bash` for .sh scripts so they
558
+ // execute instead of opening in the default file handler. PowerShell
559
+ // runs .ps1 files natively — no prepend needed.
560
+ if (isWindows && !isPowerShell && command.trim().match(/\.sh(\s|$|")/)) {
561
+ if (!command.trim().startsWith('bash ')) {
562
+ command = `bash ${command}`;
563
+ }
564
+ }
565
+ // THADDEUS_SHELL_PREFIX wraps the command via POSIX quoting
566
+ // (formatShellPrefixCommand uses shell-quote). This makes no sense for
567
+ // PowerShell — see design §8.1. For now PS hooks ignore the prefix;
568
+ // a THADDEUS_PS_SHELL_PREFIX (or shell-aware prefix) is a follow-up.
569
+ const finalCommand = !isPowerShell && process.env.THADDEUS_SHELL_PREFIX
570
+ ? formatShellPrefixCommand(process.env.THADDEUS_SHELL_PREFIX, command)
571
+ : command;
572
+ const hookTimeoutMs = hook.timeout
573
+ ? hook.timeout * 1000
574
+ : TOOL_HOOK_EXECUTION_TIMEOUT_MS;
575
+ // Build env vars — all paths go through toHookPath for Windows POSIX conversion
576
+ const envVars = {
577
+ ...subprocessEnv(),
578
+ CLAUDE_PROJECT_DIR: toHookPath(projectDir),
579
+ };
580
+ // Plugin and skill hooks both set CLAUDE_PLUGIN_ROOT (skills use the same
581
+ // name for consistency — skills can migrate to plugins without code changes)
582
+ if (pluginRoot) {
583
+ envVars.CLAUDE_PLUGIN_ROOT = toHookPath(pluginRoot);
584
+ if (pluginId) {
585
+ envVars.CLAUDE_PLUGIN_DATA = toHookPath(getPluginDataDir(pluginId));
586
+ }
587
+ }
588
+ // Expose plugin options as env vars too, so hooks can read them without
589
+ // ${user_config.X} in the command string. Sensitive values included — hooks
590
+ // run the user's own code, same trust boundary as reading keychain directly.
591
+ if (pluginOpts) {
592
+ for (const [key, value] of Object.entries(pluginOpts)) {
593
+ // Sanitize non-identifier chars (bash can't ref $FOO-BAR). The schema
594
+ // at schemas.ts:611 now constrains keys to /^[A-Za-z_]\w*$/ so this is
595
+ // belt-and-suspenders, but cheap insurance if someone bypasses the schema.
596
+ const envKey = key.replace(/[^A-Za-z0-9_]/g, '_').toUpperCase();
597
+ envVars[`CLAUDE_PLUGIN_OPTION_${envKey}`] = String(value);
598
+ }
599
+ }
600
+ if (skillRoot) {
601
+ envVars.CLAUDE_PLUGIN_ROOT = toHookPath(skillRoot);
602
+ }
603
+ // CLAUDE_ENV_FILE points to a .sh file that the hook writes env var
604
+ // definitions into; getSessionEnvironmentScript() concatenates them and
605
+ // bashProvider injects the content into bash commands. A PS hook would
606
+ // naturally write PS syntax ($env:FOO = 'bar'), which bash can't parse.
607
+ // Skip for PS — consistent with how .sh prepend and SHELL_PREFIX are
608
+ // already bash-only above.
609
+ if (!isPowerShell &&
610
+ (hookEvent === 'SessionStart' ||
611
+ hookEvent === 'Setup' ||
612
+ hookEvent === 'CwdChanged' ||
613
+ hookEvent === 'FileChanged') &&
614
+ hookIndex !== undefined) {
615
+ envVars.CLAUDE_ENV_FILE = await getHookEnvFilePath(hookEvent, hookIndex);
616
+ }
617
+ // When agent worktrees are removed, getCwd() may return a deleted path via
618
+ // AsyncLocalStorage. Validate before spawning since spawn() emits async
619
+ // 'error' events for missing cwd rather than throwing synchronously.
620
+ const hookCwd = getCwd();
621
+ const safeCwd = (await pathExists(hookCwd)) ? hookCwd : getOriginalCwd();
622
+ if (safeCwd !== hookCwd) {
623
+ logForDebugging(`Hooks: cwd ${hookCwd} not found, falling back to original cwd`, { level: 'warn' });
624
+ }
625
+ // --
626
+ // Spawn. Two completely separate paths:
627
+ //
628
+ // Bash: spawn(cmd, [], { shell: <gitBashPath | true> }) — the shell
629
+ // option makes Node pass the whole string to the shell for parsing.
630
+ //
631
+ // PowerShell: spawn(pwshPath, ['-NoProfile', '-NonInteractive',
632
+ // '-Command', cmd]) — explicit argv, no shell option. -NoProfile
633
+ // skips user profile scripts (faster, deterministic).
634
+ // -NonInteractive fails fast instead of prompting.
635
+ //
636
+ // The Git Bash hard-exit in findGitBashPath() is still in place for
637
+ // bash hooks. PowerShell hooks never call it, so a Windows user with
638
+ // only pwsh and shell: 'powershell' on every hook could in theory run
639
+ // without Git Bash — but init.ts still calls setShellIfWindows() on
640
+ // startup, which will exit first. Relaxing that is phase 1 of the
641
+ // design's implementation order (separate PR).
642
+ let child;
643
+ if (shellType === 'powershell') {
644
+ const pwshPath = await getCachedPowerShellPath();
645
+ if (!pwshPath) {
646
+ throw new Error(`Hook "${hook.command}" has shell: 'powershell' but no PowerShell ` +
647
+ `executable (pwsh or powershell) was found on PATH. Install ` +
648
+ `PowerShell, or remove "shell": "powershell" to use bash.`);
649
+ }
650
+ child = spawn(pwshPath, buildPowerShellArgs(finalCommand), {
651
+ env: envVars,
652
+ cwd: safeCwd,
653
+ // Prevent visible console window on Windows (no-op on other platforms)
654
+ windowsHide: true,
655
+ });
656
+ }
657
+ else {
658
+ // On Windows, use Git Bash explicitly (cmd.exe can't run bash syntax).
659
+ // On other platforms, shell: true uses /bin/sh.
660
+ const shell = isWindows ? findGitBashPath() : true;
661
+ child = spawn(finalCommand, [], {
662
+ env: envVars,
663
+ cwd: safeCwd,
664
+ shell,
665
+ // Prevent visible console window on Windows (no-op on other platforms)
666
+ windowsHide: true,
667
+ });
668
+ }
669
+ // Hooks use pipe mode — stdout must be streamed into JS so we can parse
670
+ // the first response line to detect async hooks ({"async": true}).
671
+ const hookTaskOutput = new TaskOutput(`hook_${child.pid}`, null);
672
+ const shellCommand = wrapSpawn(child, signal, hookTimeoutMs, hookTaskOutput);
673
+ // Track whether shellCommand ownership was transferred (e.g., to async hook registry)
674
+ let shellCommandTransferred = false;
675
+ // Track whether stdin has already been written (to avoid "write after end" errors)
676
+ let stdinWritten = false;
677
+ if ((hook.async || hook.asyncRewake) && !forceSyncExecution) {
678
+ const processId = `async_hook_${child.pid}`;
679
+ logForDebugging(`Hooks: Config-based async hook, backgrounding process ${processId}`);
680
+ // Write stdin before backgrounding so the hook receives its input.
681
+ // The trailing newline matches the sync path (L1000). Without it,
682
+ // bash `read -r line` returns exit 1 (EOF before delimiter) — the
683
+ // variable IS populated but `if read -r line; then ...` skips the
684
+ // branch. See gh-30509 / CC-161.
685
+ child.stdin.write(jsonInput + '\n', 'utf8');
686
+ child.stdin.end();
687
+ stdinWritten = true;
688
+ const backgrounded = executeInBackground({
689
+ processId,
690
+ hookId,
691
+ shellCommand,
692
+ asyncResponse: { async: true, asyncTimeout: hookTimeoutMs },
693
+ hookEvent,
694
+ hookName,
695
+ command: hook.command,
696
+ asyncRewake: hook.asyncRewake,
697
+ pluginId,
698
+ });
699
+ if (backgrounded) {
700
+ return {
701
+ stdout: '',
702
+ stderr: '',
703
+ output: '',
704
+ status: 0,
705
+ backgrounded: true,
706
+ };
707
+ }
708
+ }
709
+ let stdout = '';
710
+ let stderr = '';
711
+ let output = '';
712
+ // Set up output data collection with explicit UTF-8 encoding
713
+ child.stdout.setEncoding('utf8');
714
+ child.stderr.setEncoding('utf8');
715
+ let initialResponseChecked = false;
716
+ let asyncResolve = null;
717
+ const childIsAsyncPromise = new Promise(resolve => {
718
+ asyncResolve = resolve;
719
+ });
720
+ // Track trimmed prompt-request lines we processed so we can strip them
721
+ // from final stdout by content match (no index tracking → no index drift)
722
+ const processedPromptLines = new Set();
723
+ // Serialize async prompt handling so responses are sent in order
724
+ let promptChain = Promise.resolve();
725
+ // Line buffer for detecting prompt requests in streaming output
726
+ let lineBuffer = '';
727
+ child.stdout.on('data', data => {
728
+ stdout += data;
729
+ output += data;
730
+ // When requestPrompt is provided, parse stdout line-by-line for prompt requests
731
+ if (requestPrompt) {
732
+ lineBuffer += data;
733
+ const lines = lineBuffer.split('\n');
734
+ lineBuffer = lines.pop() ?? ''; // last element is an incomplete line
735
+ for (const line of lines) {
736
+ const trimmed = line.trim();
737
+ if (!trimmed)
738
+ continue;
739
+ try {
740
+ const parsed = jsonParse(trimmed);
741
+ const validation = promptRequestSchema().safeParse(parsed);
742
+ if (validation.success) {
743
+ processedPromptLines.add(trimmed);
744
+ logForDebugging(`Hooks: Detected prompt request from hook: ${trimmed}`);
745
+ // Chain the async handling to serialize prompt responses
746
+ const promptReq = validation.data;
747
+ const reqPrompt = requestPrompt;
748
+ promptChain = promptChain.then(async () => {
749
+ try {
750
+ const response = await reqPrompt(promptReq);
751
+ child.stdin.write(jsonStringify(response) + '\n', 'utf8');
752
+ }
753
+ catch (err) {
754
+ logForDebugging(`Hooks: Prompt request handling failed: ${err}`);
755
+ // User cancelled or prompt failed — close stdin so the hook
756
+ // process doesn't hang waiting for input
757
+ child.stdin.destroy();
758
+ }
759
+ });
760
+ continue;
761
+ }
762
+ }
763
+ catch {
764
+ // Not JSON, just a normal line
765
+ }
766
+ }
767
+ }
768
+ // Check for async response on first line of output. The async protocol is:
769
+ // hook emits {"async":true,...} as its FIRST line, then its normal output.
770
+ // We must parse ONLY the first line — if the process is fast and writes more
771
+ // before this 'data' event fires, parsing the full accumulated stdout fails
772
+ // and an async hook blocks for its full duration instead of backgrounding.
773
+ if (!initialResponseChecked) {
774
+ const firstLine = firstLineOf(stdout).trim();
775
+ if (!firstLine.includes('}'))
776
+ return;
777
+ initialResponseChecked = true;
778
+ logForDebugging(`Hooks: Checking first line for async: ${firstLine}`);
779
+ try {
780
+ const parsed = jsonParse(firstLine);
781
+ logForDebugging(`Hooks: Parsed initial response: ${jsonStringify(parsed)}`);
782
+ if (isAsyncHookJSONOutput(parsed) && !forceSyncExecution) {
783
+ const processId = `async_hook_${child.pid}`;
784
+ logForDebugging(`Hooks: Detected async hook, backgrounding process ${processId}`);
785
+ const backgrounded = executeInBackground({
786
+ processId,
787
+ hookId,
788
+ shellCommand,
789
+ asyncResponse: parsed,
790
+ hookEvent,
791
+ hookName,
792
+ command: hook.command,
793
+ pluginId,
794
+ });
795
+ if (backgrounded) {
796
+ shellCommandTransferred = true;
797
+ asyncResolve?.({
798
+ stdout,
799
+ stderr,
800
+ output,
801
+ status: 0,
802
+ });
803
+ }
804
+ }
805
+ else if (isAsyncHookJSONOutput(parsed) && forceSyncExecution) {
806
+ logForDebugging(`Hooks: Detected async hook but forceSyncExecution is true, waiting for completion`);
807
+ }
808
+ else {
809
+ logForDebugging(`Hooks: Initial response is not async, continuing normal processing`);
810
+ }
811
+ }
812
+ catch (e) {
813
+ logForDebugging(`Hooks: Failed to parse initial response as JSON: ${e}`);
814
+ }
815
+ }
816
+ });
817
+ child.stderr.on('data', data => {
818
+ stderr += data;
819
+ output += data;
820
+ });
821
+ const stopProgressInterval = startHookProgressInterval({
822
+ hookId,
823
+ hookName,
824
+ hookEvent,
825
+ getOutput: async () => ({ stdout, stderr, output }),
826
+ });
827
+ // Wait for stdout and stderr streams to finish before considering output complete
828
+ // This prevents a race condition where 'close' fires before all 'data' events are processed
829
+ const stdoutEndPromise = new Promise(resolve => {
830
+ child.stdout.on('end', () => resolve());
831
+ });
832
+ const stderrEndPromise = new Promise(resolve => {
833
+ child.stderr.on('end', () => resolve());
834
+ });
835
+ // Write to stdin, making sure to handle EPIPE errors that can happen when
836
+ // the hook command exits before reading all input.
837
+ // Note: EPIPE handling is difficult to set up in testing since Bun and Node
838
+ // have different behaviors.
839
+ // TODO: Add tests for EPIPE handling.
840
+ // Skip if stdin was already written (e.g., by config-based async hook path)
841
+ const stdinWritePromise = stdinWritten
842
+ ? Promise.resolve()
843
+ : new Promise((resolve, reject) => {
844
+ child.stdin.on('error', err => {
845
+ // When requestPrompt is provided, stdin stays open for prompt responses.
846
+ // EPIPE errors from later writes (after process exits) are expected -- suppress them.
847
+ if (!requestPrompt) {
848
+ reject(err);
849
+ }
850
+ else {
851
+ logForDebugging(`Hooks: stdin error during prompt flow (likely process exited): ${err}`);
852
+ }
853
+ });
854
+ // Explicitly specify UTF-8 encoding to ensure proper handling of Unicode characters
855
+ child.stdin.write(jsonInput + '\n', 'utf8');
856
+ // When requestPrompt is provided, keep stdin open for prompt responses
857
+ if (!requestPrompt) {
858
+ child.stdin.end();
859
+ }
860
+ resolve();
861
+ });
862
+ // Create promise for child process error
863
+ const childErrorPromise = new Promise((_, reject) => {
864
+ child.on('error', reject);
865
+ });
866
+ // Create promise for child process close - but only resolve after streams end
867
+ // to ensure all output has been collected
868
+ const childClosePromise = new Promise(resolve => {
869
+ let exitCode = null;
870
+ child.on('close', code => {
871
+ exitCode = code ?? 1;
872
+ // Wait for both streams to end before resolving with the final output
873
+ void Promise.all([stdoutEndPromise, stderrEndPromise]).then(() => {
874
+ // Strip lines we processed as prompt requests so parseHookOutput
875
+ // only sees the final hook result. Content-matching against the set
876
+ // of actually-processed lines means prompt JSON can never leak
877
+ // through (fail-closed), regardless of line positioning.
878
+ const finalStdout = processedPromptLines.size === 0
879
+ ? stdout
880
+ : stdout
881
+ .split('\n')
882
+ .filter(line => !processedPromptLines.has(line.trim()))
883
+ .join('\n');
884
+ resolve({
885
+ stdout: finalStdout,
886
+ stderr,
887
+ output,
888
+ status: exitCode,
889
+ aborted: signal.aborted,
890
+ });
891
+ });
892
+ });
893
+ });
894
+ // Race between stdin write, async detection, and process completion
895
+ try {
896
+ if (shouldEmitDiag) {
897
+ logForDiagnosticsNoPII('info', 'hook_spawn_started', {
898
+ hook_event_name: hookEvent,
899
+ index: hookIndex,
900
+ });
901
+ }
902
+ await Promise.race([stdinWritePromise, childErrorPromise]);
903
+ // Wait for any pending prompt responses before resolving
904
+ const result = await Promise.race([
905
+ childIsAsyncPromise,
906
+ childClosePromise,
907
+ childErrorPromise,
908
+ ]);
909
+ // Ensure all queued prompt responses have been sent
910
+ await promptChain;
911
+ diagExitCode = result.status;
912
+ diagAborted = result.aborted ?? false;
913
+ return result;
914
+ }
915
+ catch (error) {
916
+ // Handle errors from stdin write or child process
917
+ const code = getErrnoCode(error);
918
+ diagExitCode = 1;
919
+ if (code === 'EPIPE') {
920
+ logForDebugging('EPIPE error while writing to hook stdin (hook command likely closed early)');
921
+ const errMsg = 'Hook command closed stdin before hook input was fully written (EPIPE)';
922
+ return {
923
+ stdout: '',
924
+ stderr: errMsg,
925
+ output: errMsg,
926
+ status: 1,
927
+ };
928
+ }
929
+ else if (code === 'ABORT_ERR') {
930
+ diagAborted = true;
931
+ return {
932
+ stdout: '',
933
+ stderr: 'Hook cancelled',
934
+ output: 'Hook cancelled',
935
+ status: 1,
936
+ aborted: true,
937
+ };
938
+ }
939
+ else {
940
+ const errorMsg = errorMessage(error);
941
+ const errOutput = `Error occurred while executing hook command: ${errorMsg}`;
942
+ return {
943
+ stdout: '',
944
+ stderr: errOutput,
945
+ output: errOutput,
946
+ status: 1,
947
+ };
948
+ }
949
+ }
950
+ finally {
951
+ if (shouldEmitDiag) {
952
+ logForDiagnosticsNoPII('info', 'hook_spawn_completed', {
953
+ hook_event_name: hookEvent,
954
+ index: hookIndex,
955
+ duration_ms: Date.now() - diagStartMs,
956
+ exit_code: diagExitCode,
957
+ aborted: diagAborted,
958
+ });
959
+ }
960
+ stopProgressInterval();
961
+ // Clean up stream resources unless ownership was transferred (e.g., to async hook registry)
962
+ if (!shellCommandTransferred) {
963
+ shellCommand.cleanup();
964
+ }
965
+ }
966
+ }
967
+ /**
968
+ * Check if a match query matches a hook matcher pattern
969
+ * @param matchQuery The query to match (e.g., 'Write', 'Edit', 'Bash')
970
+ * @param matcher The matcher pattern - can be:
971
+ * - Simple string for exact match (e.g., 'Write')
972
+ * - Pipe-separated list for multiple exact matches (e.g., 'Write|Edit')
973
+ * - Regex pattern (e.g., '^Write.*', '.*', '^(Write|Edit)$')
974
+ * @returns true if the query matches the pattern
975
+ */
976
+ function matchesPattern(matchQuery, matcher) {
977
+ if (!matcher || matcher === '*') {
978
+ return true;
979
+ }
980
+ // Check if it's a simple string or pipe-separated list (no regex special chars except |)
981
+ if (/^[a-zA-Z0-9_|]+$/.test(matcher)) {
982
+ // Handle pipe-separated exact matches
983
+ if (matcher.includes('|')) {
984
+ const patterns = matcher
985
+ .split('|')
986
+ .map(p => normalizeLegacyToolName(p.trim()));
987
+ return patterns.includes(matchQuery);
988
+ }
989
+ // Simple exact match
990
+ return matchQuery === normalizeLegacyToolName(matcher);
991
+ }
992
+ // Otherwise treat as regex
993
+ try {
994
+ const regex = new RegExp(matcher);
995
+ if (regex.test(matchQuery)) {
996
+ return true;
997
+ }
998
+ // Also test against legacy names so patterns like "^Task$" still match
999
+ for (const legacyName of getLegacyToolNames(matchQuery)) {
1000
+ if (regex.test(legacyName)) {
1001
+ return true;
1002
+ }
1003
+ }
1004
+ return false;
1005
+ }
1006
+ catch {
1007
+ // If the regex is invalid, log error and return false
1008
+ logForDebugging(`Invalid regex pattern in hook matcher: ${matcher}`);
1009
+ return false;
1010
+ }
1011
+ }
1012
+ /**
1013
+ * Prepare a matcher for hook `if` conditions. Expensive work (tool lookup,
1014
+ * Zod validation, tree-sitter parsing for Bash) happens once here; the
1015
+ * returned closure is called per hook. Returns undefined for non-tool events.
1016
+ */
1017
+ async function prepareIfConditionMatcher(hookInput, tools) {
1018
+ if (hookInput.hook_event_name !== 'PreToolUse' &&
1019
+ hookInput.hook_event_name !== 'PostToolUse' &&
1020
+ hookInput.hook_event_name !== 'PostToolUseFailure' &&
1021
+ hookInput.hook_event_name !== 'PermissionRequest') {
1022
+ return undefined;
1023
+ }
1024
+ const toolName = normalizeLegacyToolName(hookInput.tool_name);
1025
+ const tool = tools && findToolByName(tools, hookInput.tool_name);
1026
+ const input = tool?.inputSchema.safeParse(hookInput.tool_input);
1027
+ const patternMatcher = input?.success && tool?.preparePermissionMatcher
1028
+ ? await tool.preparePermissionMatcher(input.data)
1029
+ : undefined;
1030
+ return ifCondition => {
1031
+ const parsed = permissionRuleValueFromString(ifCondition);
1032
+ if (normalizeLegacyToolName(parsed.toolName) !== toolName) {
1033
+ return false;
1034
+ }
1035
+ if (!parsed.ruleContent) {
1036
+ return true;
1037
+ }
1038
+ return patternMatcher ? patternMatcher(parsed.ruleContent) : false;
1039
+ };
1040
+ }
1041
+ function isInternalHook(matched) {
1042
+ return matched.hook.type === 'callback' && matched.hook.internal === true;
1043
+ }
1044
+ /**
1045
+ * Build a dedup key for a matched hook, namespaced by source context.
1046
+ *
1047
+ * Settings-file hooks (no pluginRoot/skillRoot) share the '' prefix so the
1048
+ * same command defined in user/project/local still collapses to one — the
1049
+ * original intent of the dedup. Plugin/skill hooks get their root as the
1050
+ * prefix, so two plugins sharing an unexpanded `${CLAUDE_PLUGIN_ROOT}/hook.sh`
1051
+ * template don't collapse: after expansion they point to different files.
1052
+ */
1053
+ function hookDedupKey(m, payload) {
1054
+ return `${m.pluginRoot ?? m.skillRoot ?? ''}\0${payload}`;
1055
+ }
1056
+ /**
1057
+ * Build a map of {sanitizedPluginName: hookCount} from matched hooks.
1058
+ * Only logs actual names for official marketplace plugins; others become 'third-party'.
1059
+ */
1060
+ function getPluginHookCounts(hooks) {
1061
+ const pluginHooks = hooks.filter(h => h.pluginId);
1062
+ if (pluginHooks.length === 0) {
1063
+ return undefined;
1064
+ }
1065
+ const counts = {};
1066
+ for (const h of pluginHooks) {
1067
+ const atIndex = h.pluginId.lastIndexOf('@');
1068
+ const isOfficial = atIndex > 0 &&
1069
+ ALLOWED_OFFICIAL_MARKETPLACE_NAMES.has(h.pluginId.slice(atIndex + 1));
1070
+ const key = isOfficial ? h.pluginId : 'third-party';
1071
+ counts[key] = (counts[key] || 0) + 1;
1072
+ }
1073
+ return counts;
1074
+ }
1075
+ /**
1076
+ * Build a map of {hookType: count} from matched hooks.
1077
+ */
1078
+ function getHookTypeCounts(hooks) {
1079
+ const counts = {};
1080
+ for (const h of hooks) {
1081
+ counts[h.hook.type] = (counts[h.hook.type] || 0) + 1;
1082
+ }
1083
+ return counts;
1084
+ }
1085
+ function getHooksConfig(appState, sessionId, hookEvent) {
1086
+ // HookMatcher is a zod-stripped {matcher, hooks} so snapshot matchers can be
1087
+ // pushed directly without re-wrapping.
1088
+ const hooks = [...(getHooksConfigFromSnapshot()?.[hookEvent] ?? [])];
1089
+ // Check if only managed hooks should run (used for both registered and session hooks)
1090
+ const managedOnly = shouldAllowManagedHooksOnly();
1091
+ // Process registered hooks (SDK callbacks and plugin native hooks)
1092
+ const registeredHooks = getRegisteredHooks()?.[hookEvent];
1093
+ if (registeredHooks) {
1094
+ for (const matcher of registeredHooks) {
1095
+ // Skip plugin hooks when restricted to managed hooks only
1096
+ // Plugin hooks have pluginRoot set, SDK callbacks do not
1097
+ if (managedOnly && 'pluginRoot' in matcher) {
1098
+ continue;
1099
+ }
1100
+ hooks.push(matcher);
1101
+ }
1102
+ }
1103
+ // Merge session hooks for the current session only
1104
+ // Function hooks (like structured output enforcement) must be scoped to their session
1105
+ // to prevent hooks from one agent leaking to another (e.g., verification agent to main agent)
1106
+ // Skip session hooks entirely when allowManagedHooksOnly is set —
1107
+ // this prevents frontmatter hooks from agents/skills from bypassing the policy.
1108
+ // strictPluginOnlyCustomization does NOT block here — it gates at the
1109
+ // REGISTRATION sites (runAgent.ts:526 for agent frontmatter hooks) where
1110
+ // agentDefinition.source is known. A blanket block here would also kill
1111
+ // plugin-provided agents' frontmatter hooks, which is too broad.
1112
+ // Also skip if appState not provided (for backwards compatibility)
1113
+ if (!managedOnly && appState !== undefined) {
1114
+ const sessionHooks = getSessionHooks(appState, sessionId, hookEvent).get(hookEvent);
1115
+ if (sessionHooks) {
1116
+ // SessionDerivedHookMatcher already includes optional skillRoot
1117
+ for (const matcher of sessionHooks) {
1118
+ hooks.push(matcher);
1119
+ }
1120
+ }
1121
+ // Merge session function hooks separately (can't be persisted to HookMatcher format)
1122
+ const sessionFunctionHooks = getSessionFunctionHooks(appState, sessionId, hookEvent).get(hookEvent);
1123
+ if (sessionFunctionHooks) {
1124
+ for (const matcher of sessionFunctionHooks) {
1125
+ hooks.push(matcher);
1126
+ }
1127
+ }
1128
+ }
1129
+ return hooks;
1130
+ }
1131
+ /**
1132
+ * Lightweight existence check for hooks on a given event. Mirrors the sources
1133
+ * assembled by getHooksConfig() but stops at the first hit without building
1134
+ * the full merged config.
1135
+ *
1136
+ * Intentionally over-approximates: returns true if any matcher exists for the
1137
+ * event, even if managed-only filtering or pattern matching would later
1138
+ * discard it. A false positive just means we proceed to the full matching
1139
+ * path; a false negative would skip a hook, so we err on the side of true.
1140
+ *
1141
+ * Used to skip createBaseHookInput (getTranscriptPathForSession path joins)
1142
+ * and getMatchingHooks on hot paths where hooks are typically unconfigured.
1143
+ * See hasInstructionsLoadedHook / hasWorktreeCreateHook for the same pattern.
1144
+ */
1145
+ function hasHookForEvent(hookEvent, appState, sessionId) {
1146
+ const snap = getHooksConfigFromSnapshot()?.[hookEvent];
1147
+ if (snap && snap.length > 0)
1148
+ return true;
1149
+ const reg = getRegisteredHooks()?.[hookEvent];
1150
+ if (reg && reg.length > 0)
1151
+ return true;
1152
+ if (appState?.sessionHooks.get(sessionId)?.hooks[hookEvent])
1153
+ return true;
1154
+ return false;
1155
+ }
1156
+ /**
1157
+ * Get hook commands that match the given query
1158
+ * @param appState The current app state (optional for backwards compatibility)
1159
+ * @param sessionId The current session ID (main session or agent ID)
1160
+ * @param hookEvent The hook event
1161
+ * @param hookInput The hook input for matching
1162
+ * @returns Array of matched hooks with optional plugin context
1163
+ */
1164
+ export async function getMatchingHooks(appState, sessionId, hookEvent, hookInput, tools) {
1165
+ try {
1166
+ const hookMatchers = getHooksConfig(appState, sessionId, hookEvent);
1167
+ // If you change the criteria below, then you must change
1168
+ // src/utils/hooks/hooksConfigManager.ts as well.
1169
+ let matchQuery = undefined;
1170
+ switch (hookInput.hook_event_name) {
1171
+ case 'PreToolUse':
1172
+ case 'PostToolUse':
1173
+ case 'PostToolUseFailure':
1174
+ case 'PermissionRequest':
1175
+ case 'PermissionDenied':
1176
+ matchQuery = hookInput.tool_name;
1177
+ break;
1178
+ case 'SessionStart':
1179
+ matchQuery = hookInput.source;
1180
+ break;
1181
+ case 'Setup':
1182
+ matchQuery = hookInput.trigger;
1183
+ break;
1184
+ case 'PreCompact':
1185
+ case 'PostCompact':
1186
+ matchQuery = hookInput.trigger;
1187
+ break;
1188
+ case 'Notification':
1189
+ matchQuery = hookInput.notification_type;
1190
+ break;
1191
+ case 'SessionEnd':
1192
+ matchQuery = hookInput.reason;
1193
+ break;
1194
+ case 'StopFailure':
1195
+ matchQuery = hookInput.error;
1196
+ break;
1197
+ case 'SubagentStart':
1198
+ matchQuery = hookInput.agent_type;
1199
+ break;
1200
+ case 'SubagentStop':
1201
+ matchQuery = hookInput.agent_type;
1202
+ break;
1203
+ case 'TeammateIdle':
1204
+ case 'TaskCreated':
1205
+ case 'TaskCompleted':
1206
+ break;
1207
+ case 'Elicitation':
1208
+ matchQuery = hookInput.mcp_server_name;
1209
+ break;
1210
+ case 'ElicitationResult':
1211
+ matchQuery = hookInput.mcp_server_name;
1212
+ break;
1213
+ case 'ConfigChange':
1214
+ matchQuery = hookInput.source;
1215
+ break;
1216
+ case 'InstructionsLoaded':
1217
+ matchQuery = hookInput.load_reason;
1218
+ break;
1219
+ case 'FileChanged':
1220
+ matchQuery = basename(hookInput.file_path);
1221
+ break;
1222
+ default:
1223
+ break;
1224
+ }
1225
+ logForDebugging(`Getting matching hook commands for ${hookEvent} with query: ${matchQuery}`, { level: 'verbose' });
1226
+ logForDebugging(`Found ${hookMatchers.length} hook matchers in settings`, {
1227
+ level: 'verbose',
1228
+ });
1229
+ // Extract hooks with their plugin context (if any)
1230
+ const filteredMatchers = matchQuery
1231
+ ? hookMatchers.filter(matcher => !matcher.matcher || matchesPattern(matchQuery, matcher.matcher))
1232
+ : hookMatchers;
1233
+ const matchedHooks = filteredMatchers.flatMap(matcher => {
1234
+ // Check if this is a PluginHookMatcher (has pluginRoot) or SkillHookMatcher (has skillRoot)
1235
+ const pluginRoot = 'pluginRoot' in matcher ? matcher.pluginRoot : undefined;
1236
+ const pluginId = 'pluginId' in matcher ? matcher.pluginId : undefined;
1237
+ const skillRoot = 'skillRoot' in matcher ? matcher.skillRoot : undefined;
1238
+ const hookSource = pluginRoot
1239
+ ? 'pluginName' in matcher
1240
+ ? `plugin:${matcher.pluginName}`
1241
+ : 'plugin'
1242
+ : skillRoot
1243
+ ? 'skillName' in matcher
1244
+ ? `skill:${matcher.skillName}`
1245
+ : 'skill'
1246
+ : 'settings';
1247
+ return matcher.hooks.map(hook => ({
1248
+ hook,
1249
+ pluginRoot,
1250
+ pluginId,
1251
+ skillRoot,
1252
+ hookSource,
1253
+ }));
1254
+ });
1255
+ // Deduplicate hooks by command/prompt/url within the same source context.
1256
+ // Key is namespaced by pluginRoot/skillRoot (see hookDedupKey above) so
1257
+ // cross-plugin template collisions don't drop hooks (gh-29724).
1258
+ //
1259
+ // Note: new Map(entries) keeps the LAST entry on key collision, not first.
1260
+ // For settings hooks this means the last-merged scope wins; for
1261
+ // same-plugin duplicates the pluginRoot is identical so it doesn't matter.
1262
+ // Fast-path: callback/function hooks don't need dedup (each is unique).
1263
+ // Skip the 6-pass filter + 4×Map + 4×Array.from below when all hooks are
1264
+ // callback/function — the common case for internal hooks like
1265
+ // sessionFileAccessHooks/attributionHooks (44x faster in microbench).
1266
+ if (matchedHooks.every(m => m.hook.type === 'callback' || m.hook.type === 'function')) {
1267
+ return matchedHooks;
1268
+ }
1269
+ // Helper to extract the `if` condition from a hook for dedup keys.
1270
+ // Hooks with different `if` conditions are distinct even if otherwise identical.
1271
+ const getIfCondition = (hook) => hook.if ?? '';
1272
+ const uniqueCommandHooks = Array.from(new Map(matchedHooks
1273
+ .filter((m) => m.hook.type === 'command')
1274
+ // shell is part of identity: {command:'echo x', shell:'bash'}
1275
+ // and {command:'echo x', shell:'powershell'} are distinct hooks,
1276
+ // not duplicates. Default to 'bash' so legacy configs (no shell
1277
+ // field) still dedup against explicit shell:'bash'.
1278
+ .map(m => [
1279
+ hookDedupKey(m, `${m.hook.shell ?? DEFAULT_HOOK_SHELL}\0${m.hook.command}\0${getIfCondition(m.hook)}`),
1280
+ m,
1281
+ ])).values());
1282
+ const uniquePromptHooks = Array.from(new Map(matchedHooks
1283
+ .filter(m => m.hook.type === 'prompt')
1284
+ .map(m => [
1285
+ hookDedupKey(m, `${m.hook.prompt}\0${getIfCondition(m.hook)}`),
1286
+ m,
1287
+ ])).values());
1288
+ const uniqueAgentHooks = Array.from(new Map(matchedHooks
1289
+ .filter(m => m.hook.type === 'agent')
1290
+ .map(m => [
1291
+ hookDedupKey(m, `${m.hook.prompt}\0${getIfCondition(m.hook)}`),
1292
+ m,
1293
+ ])).values());
1294
+ const uniqueHttpHooks = Array.from(new Map(matchedHooks
1295
+ .filter(m => m.hook.type === 'http')
1296
+ .map(m => [
1297
+ hookDedupKey(m, `${m.hook.url}\0${getIfCondition(m.hook)}`),
1298
+ m,
1299
+ ])).values());
1300
+ const callbackHooks = matchedHooks.filter(m => m.hook.type === 'callback');
1301
+ // Function hooks don't need deduplication - each callback is unique
1302
+ const functionHooks = matchedHooks.filter(m => m.hook.type === 'function');
1303
+ const uniqueHooks = [
1304
+ ...uniqueCommandHooks,
1305
+ ...uniquePromptHooks,
1306
+ ...uniqueAgentHooks,
1307
+ ...uniqueHttpHooks,
1308
+ ...callbackHooks,
1309
+ ...functionHooks,
1310
+ ];
1311
+ // Filter hooks based on their `if` condition. This allows hooks to specify
1312
+ // conditions like "Bash(git *)" to only run for git commands, avoiding
1313
+ // process spawning overhead for non-matching commands.
1314
+ const hasIfCondition = uniqueHooks.some(h => (h.hook.type === 'command' ||
1315
+ h.hook.type === 'prompt' ||
1316
+ h.hook.type === 'agent' ||
1317
+ h.hook.type === 'http') &&
1318
+ h.hook.if);
1319
+ const ifMatcher = hasIfCondition
1320
+ ? await prepareIfConditionMatcher(hookInput, tools)
1321
+ : undefined;
1322
+ const ifFilteredHooks = uniqueHooks.filter(h => {
1323
+ if (h.hook.type !== 'command' &&
1324
+ h.hook.type !== 'prompt' &&
1325
+ h.hook.type !== 'agent' &&
1326
+ h.hook.type !== 'http') {
1327
+ return true;
1328
+ }
1329
+ const ifCondition = h.hook.if;
1330
+ if (!ifCondition) {
1331
+ return true;
1332
+ }
1333
+ if (!ifMatcher) {
1334
+ logForDebugging(`Hook if condition "${ifCondition}" cannot be evaluated for non-tool event ${hookInput.hook_event_name}`);
1335
+ return false;
1336
+ }
1337
+ if (ifMatcher(ifCondition)) {
1338
+ return true;
1339
+ }
1340
+ logForDebugging(`Skipping hook due to if condition "${ifCondition}" not matching`);
1341
+ return false;
1342
+ });
1343
+ // HTTP hooks are not supported for SessionStart/Setup events. In headless
1344
+ // mode the sandbox ask callback deadlocks because the structuredInput
1345
+ // consumer hasn't started yet when these hooks fire.
1346
+ const filteredHooks = hookEvent === 'SessionStart' || hookEvent === 'Setup'
1347
+ ? ifFilteredHooks.filter(h => {
1348
+ if (h.hook.type === 'http') {
1349
+ logForDebugging(`Skipping HTTP hook ${h.hook.url} — HTTP hooks are not supported for ${hookEvent}`);
1350
+ return false;
1351
+ }
1352
+ return true;
1353
+ })
1354
+ : ifFilteredHooks;
1355
+ logForDebugging(`Matched ${filteredHooks.length} unique hooks for query "${matchQuery || 'no match query'}" (${matchedHooks.length} before deduplication)`, { level: 'verbose' });
1356
+ return filteredHooks;
1357
+ }
1358
+ catch {
1359
+ return [];
1360
+ }
1361
+ }
1362
+ /**
1363
+ * Format a list of blocking errors from a PreTool hook's configured commands.
1364
+ * @param hookName The name of the hook (e.g., 'PreToolUse:Write', 'PreToolUse:Edit', 'PreToolUse:Bash')
1365
+ * @param blockingErrors Array of blocking errors from hooks
1366
+ * @returns Formatted blocking message
1367
+ */
1368
+ export function getPreToolHookBlockingMessage(hookName, blockingError) {
1369
+ return `${hookName} hook error: ${blockingError.blockingError}`;
1370
+ }
1371
+ /**
1372
+ * Format a list of blocking errors from a Stop hook's configured commands.
1373
+ * @param blockingErrors Array of blocking errors from hooks
1374
+ * @returns Formatted message to give feedback to the model
1375
+ */
1376
+ export function getStopHookMessage(blockingError) {
1377
+ return `Stop hook feedback:\n${blockingError.blockingError}`;
1378
+ }
1379
+ /**
1380
+ * Format a blocking error from a TeammateIdle hook.
1381
+ * @param blockingError The blocking error from the hook
1382
+ * @returns Formatted message to give feedback to the model
1383
+ */
1384
+ export function getTeammateIdleHookMessage(blockingError) {
1385
+ return `TeammateIdle hook feedback:\n${blockingError.blockingError}`;
1386
+ }
1387
+ /**
1388
+ * Format a blocking error from a TaskCreated hook.
1389
+ * @param blockingError The blocking error from the hook
1390
+ * @returns Formatted message to give feedback to the model
1391
+ */
1392
+ export function getTaskCreatedHookMessage(blockingError) {
1393
+ return `TaskCreated hook feedback:\n${blockingError.blockingError}`;
1394
+ }
1395
+ /**
1396
+ * Format a blocking error from a TaskCompleted hook.
1397
+ * @param blockingError The blocking error from the hook
1398
+ * @returns Formatted message to give feedback to the model
1399
+ */
1400
+ export function getTaskCompletedHookMessage(blockingError) {
1401
+ return `TaskCompleted hook feedback:\n${blockingError.blockingError}`;
1402
+ }
1403
+ /**
1404
+ * Format a list of blocking errors from a UserPromptSubmit hook's configured commands.
1405
+ * @param blockingErrors Array of blocking errors from hooks
1406
+ * @returns Formatted blocking message
1407
+ */
1408
+ export function getUserPromptSubmitHookBlockingMessage(blockingError) {
1409
+ return `UserPromptSubmit operation blocked by hook:\n${blockingError.blockingError}`;
1410
+ }
1411
+ /**
1412
+ * Common logic for executing hooks
1413
+ * @param hookInput The structured hook input that will be validated and converted to JSON
1414
+ * @param toolUseID The ID for tracking this hook execution
1415
+ * @param matchQuery The query to match against hook matchers
1416
+ * @param signal Optional AbortSignal to cancel hook execution
1417
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
1418
+ * @param toolUseContext Optional ToolUseContext for prompt-based hooks (required if using prompt hooks)
1419
+ * @param messages Optional conversation history for prompt/function hooks
1420
+ * @returns Async generator that yields progress messages and hook results
1421
+ */
1422
+ async function* executeHooks({ hookInput, toolUseID, matchQuery, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, toolUseContext, messages, forceSyncExecution, requestPrompt, toolInputSummary, }) {
1423
+ if (shouldDisableAllHooksIncludingManaged()) {
1424
+ return;
1425
+ }
1426
+ if (isEnvTruthy(process.env.THADDEUS_SIMPLE)) {
1427
+ return;
1428
+ }
1429
+ const hookEvent = hookInput.hook_event_name;
1430
+ const hookName = matchQuery ? `${hookEvent}:${matchQuery}` : hookEvent;
1431
+ // Bind the prompt callback to this hook's name and tool input summary so the UI can display context
1432
+ const boundRequestPrompt = requestPrompt?.(hookName, toolInputSummary);
1433
+ // SECURITY: ALL hooks require workspace trust in interactive mode
1434
+ // This centralized check prevents RCE vulnerabilities for all current and future hooks
1435
+ if (shouldSkipHookDueToTrust()) {
1436
+ logForDebugging(`Skipping ${hookName} hook execution - workspace trust not accepted`);
1437
+ return;
1438
+ }
1439
+ const appState = toolUseContext ? toolUseContext.getAppState() : undefined;
1440
+ // Use the agent's session ID if available, otherwise fall back to main session
1441
+ const sessionId = toolUseContext?.agentId ?? getSessionId();
1442
+ const matchingHooks = await getMatchingHooks(appState, sessionId, hookEvent, hookInput, toolUseContext?.options?.tools);
1443
+ if (matchingHooks.length === 0) {
1444
+ return;
1445
+ }
1446
+ if (signal?.aborted) {
1447
+ return;
1448
+ }
1449
+ const userHooks = matchingHooks.filter(h => !isInternalHook(h));
1450
+ if (userHooks.length > 0) {
1451
+ const pluginHookCounts = getPluginHookCounts(userHooks);
1452
+ const hookTypeCounts = getHookTypeCounts(userHooks);
1453
+ logEvent(`thaddeus_run_hook`, {
1454
+ hookName: hookName,
1455
+ numCommands: userHooks.length,
1456
+ hookTypeCounts: jsonStringify(hookTypeCounts),
1457
+ ...(pluginHookCounts && {
1458
+ pluginHookCounts: jsonStringify(pluginHookCounts),
1459
+ }),
1460
+ });
1461
+ }
1462
+ else {
1463
+ // Fast-path: all hooks are internal callbacks (sessionFileAccessHooks,
1464
+ // attributionHooks). These return {} and don't use the abort signal, so we
1465
+ // can skip span/progress/abortSignal/processHookJSONOutput/resultLoop.
1466
+ // Measured: 6.01µs → ~1.8µs per PostToolUse hit (-70%).
1467
+ const batchStartTime = Date.now();
1468
+ const context = toolUseContext
1469
+ ? {
1470
+ getAppState: toolUseContext.getAppState,
1471
+ updateAttributionState: toolUseContext.updateAttributionState,
1472
+ }
1473
+ : undefined;
1474
+ for (const [i, { hook }] of matchingHooks.entries()) {
1475
+ if (hook.type === 'callback') {
1476
+ await hook.callback(hookInput, toolUseID, signal, i, context);
1477
+ }
1478
+ }
1479
+ const totalDurationMs = Date.now() - batchStartTime;
1480
+ getStatsStore()?.observe('hook_duration_ms', totalDurationMs);
1481
+ addToTurnHookDuration(totalDurationMs);
1482
+ logEvent(`thaddeus_repl_hook_finished`, {
1483
+ hookName: hookName,
1484
+ numCommands: matchingHooks.length,
1485
+ numSuccess: matchingHooks.length,
1486
+ numBlocking: 0,
1487
+ numNonBlockingError: 0,
1488
+ numCancelled: 0,
1489
+ totalDurationMs,
1490
+ });
1491
+ return;
1492
+ }
1493
+ // Collect hook definitions for beta tracing telemetry
1494
+ const hookDefinitionsJson = isBetaTracingEnabled()
1495
+ ? jsonStringify(getHookDefinitionsForTelemetry(matchingHooks))
1496
+ : '[]';
1497
+ // Log hook execution start to OTEL (only for beta tracing)
1498
+ if (isBetaTracingEnabled()) {
1499
+ void logOTelEvent('hook_execution_start', {
1500
+ hook_event: hookEvent,
1501
+ hook_name: hookName,
1502
+ num_hooks: String(matchingHooks.length),
1503
+ managed_only: String(shouldAllowManagedHooksOnly()),
1504
+ hook_definitions: hookDefinitionsJson,
1505
+ hook_source: shouldAllowManagedHooksOnly() ? 'policySettings' : 'merged',
1506
+ });
1507
+ }
1508
+ // Start hook span for beta tracing
1509
+ const hookSpan = startHookSpan(hookEvent, hookName, matchingHooks.length, hookDefinitionsJson);
1510
+ // Yield progress messages for each hook before execution
1511
+ for (const { hook } of matchingHooks) {
1512
+ yield {
1513
+ message: {
1514
+ type: 'progress',
1515
+ data: {
1516
+ type: 'hook_progress',
1517
+ hookEvent,
1518
+ hookName,
1519
+ command: getHookDisplayText(hook),
1520
+ ...(hook.type === 'prompt' && { promptText: hook.prompt }),
1521
+ ...('statusMessage' in hook &&
1522
+ hook.statusMessage != null && {
1523
+ statusMessage: hook.statusMessage,
1524
+ }),
1525
+ },
1526
+ parentToolUseID: toolUseID,
1527
+ toolUseID,
1528
+ timestamp: new Date().toISOString(),
1529
+ uuid: randomUUID(),
1530
+ },
1531
+ };
1532
+ }
1533
+ // Track wall-clock time for the entire hook batch
1534
+ const batchStartTime = Date.now();
1535
+ // Lazy-once stringify of hookInput. Shared across all command/prompt/agent/http
1536
+ // hooks in this batch (hookInput is never mutated). Callback/function hooks
1537
+ // return before reaching this, so batches with only those pay no stringify cost.
1538
+ let jsonInputResult;
1539
+ function getJsonInput() {
1540
+ if (jsonInputResult !== undefined) {
1541
+ return jsonInputResult;
1542
+ }
1543
+ try {
1544
+ return (jsonInputResult = { ok: true, value: jsonStringify(hookInput) });
1545
+ }
1546
+ catch (error) {
1547
+ logError(Error(`Failed to stringify hook ${hookName} input`, { cause: error }));
1548
+ return (jsonInputResult = { ok: false, error });
1549
+ }
1550
+ }
1551
+ // Run all hooks in parallel with individual timeouts
1552
+ const hookPromises = matchingHooks.map(async function* ({ hook, pluginRoot, pluginId, skillRoot }, hookIndex) {
1553
+ if (hook.type === 'callback') {
1554
+ const callbackTimeoutMs = hook.timeout ? hook.timeout * 1000 : timeoutMs;
1555
+ const { signal: abortSignal, cleanup } = createCombinedAbortSignal(signal, { timeoutMs: callbackTimeoutMs });
1556
+ yield executeHookCallback({
1557
+ toolUseID,
1558
+ hook,
1559
+ hookEvent,
1560
+ hookInput,
1561
+ signal: abortSignal,
1562
+ hookIndex,
1563
+ toolUseContext,
1564
+ }).finally(cleanup);
1565
+ return;
1566
+ }
1567
+ if (hook.type === 'function') {
1568
+ if (!messages) {
1569
+ yield {
1570
+ message: createAttachmentMessage({
1571
+ type: 'hook_error_during_execution',
1572
+ hookName,
1573
+ toolUseID,
1574
+ hookEvent,
1575
+ content: 'Messages not provided for function hook',
1576
+ }),
1577
+ outcome: 'non_blocking_error',
1578
+ hook,
1579
+ };
1580
+ return;
1581
+ }
1582
+ // Function hooks only come from session storage with callback embedded
1583
+ yield executeFunctionHook({
1584
+ hook,
1585
+ messages,
1586
+ hookName,
1587
+ toolUseID,
1588
+ hookEvent,
1589
+ timeoutMs,
1590
+ signal,
1591
+ });
1592
+ return;
1593
+ }
1594
+ // Command and prompt hooks need jsonInput
1595
+ const commandTimeoutMs = hook.timeout ? hook.timeout * 1000 : timeoutMs;
1596
+ const { signal: abortSignal, cleanup } = createCombinedAbortSignal(signal, {
1597
+ timeoutMs: commandTimeoutMs,
1598
+ });
1599
+ const hookId = randomUUID();
1600
+ const hookStartMs = Date.now();
1601
+ const hookCommand = getHookDisplayText(hook);
1602
+ try {
1603
+ const jsonInputRes = getJsonInput();
1604
+ if (!jsonInputRes.ok) {
1605
+ yield {
1606
+ message: createAttachmentMessage({
1607
+ type: 'hook_error_during_execution',
1608
+ hookName,
1609
+ toolUseID,
1610
+ hookEvent,
1611
+ content: `Failed to prepare hook input: ${errorMessage(jsonInputRes.error)}`,
1612
+ command: hookCommand,
1613
+ durationMs: Date.now() - hookStartMs,
1614
+ }),
1615
+ outcome: 'non_blocking_error',
1616
+ hook,
1617
+ };
1618
+ cleanup();
1619
+ return;
1620
+ }
1621
+ const jsonInput = jsonInputRes.value;
1622
+ if (hook.type === 'prompt') {
1623
+ if (!toolUseContext) {
1624
+ throw new Error('ToolUseContext is required for prompt hooks. This is a bug.');
1625
+ }
1626
+ const promptResult = await execPromptHook(hook, hookName, hookEvent, jsonInput, abortSignal, toolUseContext, messages, toolUseID);
1627
+ // Inject timing fields for hook visibility
1628
+ if (promptResult.message?.type === 'attachment') {
1629
+ const att = promptResult.message.attachment;
1630
+ if (att.type === 'hook_success' ||
1631
+ att.type === 'hook_non_blocking_error') {
1632
+ att.command = hookCommand;
1633
+ att.durationMs = Date.now() - hookStartMs;
1634
+ }
1635
+ }
1636
+ yield promptResult;
1637
+ cleanup?.();
1638
+ return;
1639
+ }
1640
+ if (hook.type === 'agent') {
1641
+ if (!toolUseContext) {
1642
+ throw new Error('ToolUseContext is required for agent hooks. This is a bug.');
1643
+ }
1644
+ if (!messages) {
1645
+ throw new Error('Messages are required for agent hooks. This is a bug.');
1646
+ }
1647
+ const agentResult = await execAgentHook(hook, hookName, hookEvent, jsonInput, abortSignal, toolUseContext, toolUseID, messages, 'agent_type' in hookInput
1648
+ ? hookInput.agent_type
1649
+ : undefined);
1650
+ // Inject timing fields for hook visibility
1651
+ if (agentResult.message?.type === 'attachment') {
1652
+ const att = agentResult.message.attachment;
1653
+ if (att.type === 'hook_success' ||
1654
+ att.type === 'hook_non_blocking_error') {
1655
+ att.command = hookCommand;
1656
+ att.durationMs = Date.now() - hookStartMs;
1657
+ }
1658
+ }
1659
+ yield agentResult;
1660
+ cleanup?.();
1661
+ return;
1662
+ }
1663
+ if (hook.type === 'http') {
1664
+ emitHookStarted(hookId, hookName, hookEvent);
1665
+ // execHttpHook manages its own timeout internally via hook.timeout or
1666
+ // DEFAULT_HTTP_HOOK_TIMEOUT_MS, so pass the parent signal directly
1667
+ // to avoid double-stacking timeouts with abortSignal.
1668
+ const httpResult = await execHttpHook(hook, hookEvent, jsonInput, signal);
1669
+ cleanup?.();
1670
+ if (httpResult.aborted) {
1671
+ emitHookResponse({
1672
+ hookId,
1673
+ hookName,
1674
+ hookEvent,
1675
+ output: 'Hook cancelled',
1676
+ stdout: '',
1677
+ stderr: '',
1678
+ exitCode: undefined,
1679
+ outcome: 'cancelled',
1680
+ });
1681
+ yield {
1682
+ message: createAttachmentMessage({
1683
+ type: 'hook_cancelled',
1684
+ hookName,
1685
+ toolUseID,
1686
+ hookEvent,
1687
+ }),
1688
+ outcome: 'cancelled',
1689
+ hook,
1690
+ };
1691
+ return;
1692
+ }
1693
+ if (httpResult.error || !httpResult.ok) {
1694
+ const stderr = httpResult.error || `HTTP ${httpResult.statusCode} from ${hook.url}`;
1695
+ emitHookResponse({
1696
+ hookId,
1697
+ hookName,
1698
+ hookEvent,
1699
+ output: stderr,
1700
+ stdout: '',
1701
+ stderr,
1702
+ exitCode: httpResult.statusCode,
1703
+ outcome: 'error',
1704
+ });
1705
+ yield {
1706
+ message: createAttachmentMessage({
1707
+ type: 'hook_non_blocking_error',
1708
+ hookName,
1709
+ toolUseID,
1710
+ hookEvent,
1711
+ stderr,
1712
+ stdout: '',
1713
+ exitCode: httpResult.statusCode ?? 0,
1714
+ }),
1715
+ outcome: 'non_blocking_error',
1716
+ hook,
1717
+ };
1718
+ return;
1719
+ }
1720
+ // HTTP hooks must return JSON — parse and validate through Zod
1721
+ const { json: httpJson, validationError: httpValidationError } = parseHttpHookOutput(httpResult.body);
1722
+ if (httpValidationError) {
1723
+ emitHookResponse({
1724
+ hookId,
1725
+ hookName,
1726
+ hookEvent,
1727
+ output: httpResult.body,
1728
+ stdout: httpResult.body,
1729
+ stderr: `JSON validation failed: ${httpValidationError}`,
1730
+ exitCode: httpResult.statusCode,
1731
+ outcome: 'error',
1732
+ });
1733
+ yield {
1734
+ message: createAttachmentMessage({
1735
+ type: 'hook_non_blocking_error',
1736
+ hookName,
1737
+ toolUseID,
1738
+ hookEvent,
1739
+ stderr: `JSON validation failed: ${httpValidationError}`,
1740
+ stdout: httpResult.body,
1741
+ exitCode: httpResult.statusCode ?? 0,
1742
+ }),
1743
+ outcome: 'non_blocking_error',
1744
+ hook,
1745
+ };
1746
+ return;
1747
+ }
1748
+ if (httpJson && isAsyncHookJSONOutput(httpJson)) {
1749
+ // Async response: treat as success (no further processing)
1750
+ emitHookResponse({
1751
+ hookId,
1752
+ hookName,
1753
+ hookEvent,
1754
+ output: httpResult.body,
1755
+ stdout: httpResult.body,
1756
+ stderr: '',
1757
+ exitCode: httpResult.statusCode,
1758
+ outcome: 'success',
1759
+ });
1760
+ yield {
1761
+ outcome: 'success',
1762
+ hook,
1763
+ };
1764
+ return;
1765
+ }
1766
+ if (httpJson) {
1767
+ const processed = processHookJSONOutput({
1768
+ json: httpJson,
1769
+ command: hook.url,
1770
+ hookName,
1771
+ toolUseID,
1772
+ hookEvent,
1773
+ expectedHookEvent: hookEvent,
1774
+ stdout: httpResult.body,
1775
+ stderr: '',
1776
+ exitCode: httpResult.statusCode,
1777
+ });
1778
+ emitHookResponse({
1779
+ hookId,
1780
+ hookName,
1781
+ hookEvent,
1782
+ output: httpResult.body,
1783
+ stdout: httpResult.body,
1784
+ stderr: '',
1785
+ exitCode: httpResult.statusCode,
1786
+ outcome: 'success',
1787
+ });
1788
+ yield {
1789
+ ...processed,
1790
+ outcome: 'success',
1791
+ hook,
1792
+ };
1793
+ return;
1794
+ }
1795
+ return;
1796
+ }
1797
+ emitHookStarted(hookId, hookName, hookEvent);
1798
+ const result = await execCommandHook(hook, hookEvent, hookName, jsonInput, abortSignal, hookId, hookIndex, pluginRoot, pluginId, skillRoot, forceSyncExecution, boundRequestPrompt);
1799
+ cleanup?.();
1800
+ const durationMs = Date.now() - hookStartMs;
1801
+ if (result.backgrounded) {
1802
+ yield {
1803
+ outcome: 'success',
1804
+ hook,
1805
+ };
1806
+ return;
1807
+ }
1808
+ if (result.aborted) {
1809
+ emitHookResponse({
1810
+ hookId,
1811
+ hookName,
1812
+ hookEvent,
1813
+ output: result.output,
1814
+ stdout: result.stdout,
1815
+ stderr: result.stderr,
1816
+ exitCode: result.status,
1817
+ outcome: 'cancelled',
1818
+ });
1819
+ yield {
1820
+ message: createAttachmentMessage({
1821
+ type: 'hook_cancelled',
1822
+ hookName,
1823
+ toolUseID,
1824
+ hookEvent,
1825
+ command: hookCommand,
1826
+ durationMs,
1827
+ }),
1828
+ outcome: 'cancelled',
1829
+ hook,
1830
+ };
1831
+ return;
1832
+ }
1833
+ // Try JSON parsing first
1834
+ const { json, plainText, validationError } = parseHookOutput(result.stdout);
1835
+ if (validationError) {
1836
+ emitHookResponse({
1837
+ hookId,
1838
+ hookName,
1839
+ hookEvent,
1840
+ output: result.output,
1841
+ stdout: result.stdout,
1842
+ stderr: `JSON validation failed: ${validationError}`,
1843
+ exitCode: 1,
1844
+ outcome: 'error',
1845
+ });
1846
+ yield {
1847
+ message: createAttachmentMessage({
1848
+ type: 'hook_non_blocking_error',
1849
+ hookName,
1850
+ toolUseID,
1851
+ hookEvent,
1852
+ stderr: `JSON validation failed: ${validationError}`,
1853
+ stdout: result.stdout,
1854
+ exitCode: 1,
1855
+ command: hookCommand,
1856
+ durationMs,
1857
+ }),
1858
+ outcome: 'non_blocking_error',
1859
+ hook,
1860
+ };
1861
+ return;
1862
+ }
1863
+ if (json) {
1864
+ // Async responses were already backgrounded during execution
1865
+ if (isAsyncHookJSONOutput(json)) {
1866
+ yield {
1867
+ outcome: 'success',
1868
+ hook,
1869
+ };
1870
+ return;
1871
+ }
1872
+ // Process JSON output
1873
+ const processed = processHookJSONOutput({
1874
+ json,
1875
+ command: hookCommand,
1876
+ hookName,
1877
+ toolUseID,
1878
+ hookEvent,
1879
+ expectedHookEvent: hookEvent,
1880
+ stdout: result.stdout,
1881
+ stderr: result.stderr,
1882
+ exitCode: result.status,
1883
+ durationMs,
1884
+ });
1885
+ // Handle suppressOutput (skip for async responses)
1886
+ if (isSyncHookJSONOutput(json) &&
1887
+ !json.suppressOutput &&
1888
+ plainText &&
1889
+ result.status === 0) {
1890
+ // Still show non-JSON output if not suppressed
1891
+ const content = `${chalk.bold(hookName)} completed`;
1892
+ emitHookResponse({
1893
+ hookId,
1894
+ hookName,
1895
+ hookEvent,
1896
+ output: result.output,
1897
+ stdout: result.stdout,
1898
+ stderr: result.stderr,
1899
+ exitCode: result.status,
1900
+ outcome: 'success',
1901
+ });
1902
+ yield {
1903
+ ...processed,
1904
+ message: processed.message ||
1905
+ createAttachmentMessage({
1906
+ type: 'hook_success',
1907
+ hookName,
1908
+ toolUseID,
1909
+ hookEvent,
1910
+ content,
1911
+ stdout: result.stdout,
1912
+ stderr: result.stderr,
1913
+ exitCode: result.status,
1914
+ command: hookCommand,
1915
+ durationMs,
1916
+ }),
1917
+ outcome: 'success',
1918
+ hook,
1919
+ };
1920
+ return;
1921
+ }
1922
+ emitHookResponse({
1923
+ hookId,
1924
+ hookName,
1925
+ hookEvent,
1926
+ output: result.output,
1927
+ stdout: result.stdout,
1928
+ stderr: result.stderr,
1929
+ exitCode: result.status,
1930
+ outcome: result.status === 0 ? 'success' : 'error',
1931
+ });
1932
+ yield {
1933
+ ...processed,
1934
+ outcome: 'success',
1935
+ hook,
1936
+ };
1937
+ return;
1938
+ }
1939
+ // Fall back to existing logic for non-JSON output
1940
+ if (result.status === 0) {
1941
+ emitHookResponse({
1942
+ hookId,
1943
+ hookName,
1944
+ hookEvent,
1945
+ output: result.output,
1946
+ stdout: result.stdout,
1947
+ stderr: result.stderr,
1948
+ exitCode: result.status,
1949
+ outcome: 'success',
1950
+ });
1951
+ yield {
1952
+ message: createAttachmentMessage({
1953
+ type: 'hook_success',
1954
+ hookName,
1955
+ toolUseID,
1956
+ hookEvent,
1957
+ content: result.stdout.trim(),
1958
+ stdout: result.stdout,
1959
+ stderr: result.stderr,
1960
+ exitCode: result.status,
1961
+ command: hookCommand,
1962
+ durationMs,
1963
+ }),
1964
+ outcome: 'success',
1965
+ hook,
1966
+ };
1967
+ return;
1968
+ }
1969
+ // Hooks with exit code 2 provide blocking feedback
1970
+ if (result.status === 2) {
1971
+ emitHookResponse({
1972
+ hookId,
1973
+ hookName,
1974
+ hookEvent,
1975
+ output: result.output,
1976
+ stdout: result.stdout,
1977
+ stderr: result.stderr,
1978
+ exitCode: result.status,
1979
+ outcome: 'error',
1980
+ });
1981
+ yield {
1982
+ blockingError: {
1983
+ blockingError: `[${hook.command}]: ${result.stderr || 'No stderr output'}`,
1984
+ command: hook.command,
1985
+ },
1986
+ outcome: 'blocking',
1987
+ hook,
1988
+ };
1989
+ return;
1990
+ }
1991
+ // Any other non-zero exit code is a non-critical error that should just
1992
+ // be shown to the user.
1993
+ emitHookResponse({
1994
+ hookId,
1995
+ hookName,
1996
+ hookEvent,
1997
+ output: result.output,
1998
+ stdout: result.stdout,
1999
+ stderr: result.stderr,
2000
+ exitCode: result.status,
2001
+ outcome: 'error',
2002
+ });
2003
+ yield {
2004
+ message: createAttachmentMessage({
2005
+ type: 'hook_non_blocking_error',
2006
+ hookName,
2007
+ toolUseID,
2008
+ hookEvent,
2009
+ stderr: `Failed with non-blocking status code: ${result.stderr.trim() || 'No stderr output'}`,
2010
+ stdout: result.stdout,
2011
+ exitCode: result.status,
2012
+ command: hookCommand,
2013
+ durationMs,
2014
+ }),
2015
+ outcome: 'non_blocking_error',
2016
+ hook,
2017
+ };
2018
+ return;
2019
+ }
2020
+ catch (error) {
2021
+ // Clean up on error
2022
+ cleanup?.();
2023
+ const errorMessage = error instanceof Error ? error.message : String(error);
2024
+ emitHookResponse({
2025
+ hookId,
2026
+ hookName,
2027
+ hookEvent,
2028
+ output: `Failed to run: ${errorMessage}`,
2029
+ stdout: '',
2030
+ stderr: `Failed to run: ${errorMessage}`,
2031
+ exitCode: 1,
2032
+ outcome: 'error',
2033
+ });
2034
+ yield {
2035
+ message: createAttachmentMessage({
2036
+ type: 'hook_non_blocking_error',
2037
+ hookName,
2038
+ toolUseID,
2039
+ hookEvent,
2040
+ stderr: `Failed to run: ${errorMessage}`,
2041
+ stdout: '',
2042
+ exitCode: 1,
2043
+ command: hookCommand,
2044
+ durationMs: Date.now() - hookStartMs,
2045
+ }),
2046
+ outcome: 'non_blocking_error',
2047
+ hook,
2048
+ };
2049
+ return;
2050
+ }
2051
+ });
2052
+ // Track outcomes for logging
2053
+ const outcomes = {
2054
+ success: 0,
2055
+ blocking: 0,
2056
+ non_blocking_error: 0,
2057
+ cancelled: 0,
2058
+ };
2059
+ let permissionBehavior;
2060
+ // Run all hooks in parallel and wait for all to complete
2061
+ for await (const result of all(hookPromises)) {
2062
+ outcomes[result.outcome]++;
2063
+ // Check for preventContinuation early
2064
+ if (result.preventContinuation) {
2065
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) requested preventContinuation`);
2066
+ yield {
2067
+ preventContinuation: true,
2068
+ stopReason: result.stopReason,
2069
+ };
2070
+ }
2071
+ // Handle different result types
2072
+ if (result.blockingError) {
2073
+ yield {
2074
+ blockingError: result.blockingError,
2075
+ };
2076
+ }
2077
+ if (result.message) {
2078
+ yield { message: result.message };
2079
+ }
2080
+ // Yield system message separately if present
2081
+ if (result.systemMessage) {
2082
+ yield {
2083
+ message: createAttachmentMessage({
2084
+ type: 'hook_system_message',
2085
+ content: result.systemMessage,
2086
+ hookName,
2087
+ toolUseID,
2088
+ hookEvent,
2089
+ }),
2090
+ };
2091
+ }
2092
+ // Collect additional context from hooks
2093
+ if (result.additionalContext) {
2094
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) provided additionalContext (${result.additionalContext.length} chars)`);
2095
+ yield {
2096
+ additionalContexts: [result.additionalContext],
2097
+ };
2098
+ }
2099
+ if (result.initialUserMessage) {
2100
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) provided initialUserMessage (${result.initialUserMessage.length} chars)`);
2101
+ yield {
2102
+ initialUserMessage: result.initialUserMessage,
2103
+ };
2104
+ }
2105
+ if (result.watchPaths && result.watchPaths.length > 0) {
2106
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) provided ${result.watchPaths.length} watchPaths`);
2107
+ yield {
2108
+ watchPaths: result.watchPaths,
2109
+ };
2110
+ }
2111
+ // Yield updatedMCPToolOutput if provided (from PostToolUse hooks)
2112
+ if (result.updatedMCPToolOutput) {
2113
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) replaced MCP tool output`);
2114
+ yield {
2115
+ updatedMCPToolOutput: result.updatedMCPToolOutput,
2116
+ };
2117
+ }
2118
+ // Check for permission behavior with precedence: deny > ask > allow
2119
+ if (result.permissionBehavior) {
2120
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) returned permissionDecision: ${result.permissionBehavior}${result.hookPermissionDecisionReason ? ` (reason: ${result.hookPermissionDecisionReason})` : ''}`);
2121
+ // Apply precedence rules
2122
+ switch (result.permissionBehavior) {
2123
+ case 'deny':
2124
+ // deny always takes precedence
2125
+ permissionBehavior = 'deny';
2126
+ break;
2127
+ case 'ask':
2128
+ // ask takes precedence over allow but not deny
2129
+ if (permissionBehavior !== 'deny') {
2130
+ permissionBehavior = 'ask';
2131
+ }
2132
+ break;
2133
+ case 'allow':
2134
+ // allow only if no other behavior set
2135
+ if (!permissionBehavior) {
2136
+ permissionBehavior = 'allow';
2137
+ }
2138
+ break;
2139
+ case 'passthrough':
2140
+ // passthrough doesn't set permission behavior
2141
+ break;
2142
+ }
2143
+ }
2144
+ // Yield permission behavior and updatedInput if provided (from allow or ask behavior)
2145
+ if (permissionBehavior !== undefined) {
2146
+ const updatedInput = result.updatedInput &&
2147
+ (result.permissionBehavior === 'allow' ||
2148
+ result.permissionBehavior === 'ask')
2149
+ ? result.updatedInput
2150
+ : undefined;
2151
+ if (updatedInput) {
2152
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) modified tool input keys: [${Object.keys(updatedInput).join(', ')}]`);
2153
+ }
2154
+ yield {
2155
+ permissionBehavior,
2156
+ hookPermissionDecisionReason: result.hookPermissionDecisionReason,
2157
+ hookSource: matchingHooks.find(m => m.hook === result.hook)?.hookSource,
2158
+ updatedInput,
2159
+ };
2160
+ }
2161
+ // Yield updatedInput separately for passthrough case (no permission decision)
2162
+ // This allows hooks to modify input without making a permission decision
2163
+ // Note: Check result.permissionBehavior (this hook's behavior), not the aggregated permissionBehavior
2164
+ if (result.updatedInput && result.permissionBehavior === undefined) {
2165
+ logForDebugging(`Hook ${hookEvent} (${getHookDisplayText(result.hook)}) modified tool input keys: [${Object.keys(result.updatedInput).join(', ')}]`);
2166
+ yield {
2167
+ updatedInput: result.updatedInput,
2168
+ };
2169
+ }
2170
+ // Yield permission request result if provided (from PermissionRequest hooks)
2171
+ if (result.permissionRequestResult) {
2172
+ yield {
2173
+ permissionRequestResult: result.permissionRequestResult,
2174
+ };
2175
+ }
2176
+ // Yield retry flag if provided (from PermissionDenied hooks)
2177
+ if (result.retry) {
2178
+ yield {
2179
+ retry: result.retry,
2180
+ };
2181
+ }
2182
+ // Yield elicitation response if provided (from Elicitation hooks)
2183
+ if (result.elicitationResponse) {
2184
+ yield {
2185
+ elicitationResponse: result.elicitationResponse,
2186
+ };
2187
+ }
2188
+ // Yield elicitation result response if provided (from ElicitationResult hooks)
2189
+ if (result.elicitationResultResponse) {
2190
+ yield {
2191
+ elicitationResultResponse: result.elicitationResultResponse,
2192
+ };
2193
+ }
2194
+ // Invoke session hook callback if this is a command/prompt/function hook (not a callback hook)
2195
+ if (appState && result.hook.type !== 'callback') {
2196
+ const sessionId = getSessionId();
2197
+ // Use empty string as matcher when matchQuery is undefined (e.g., for Stop hooks)
2198
+ const matcher = matchQuery ?? '';
2199
+ const hookEntry = getSessionHookCallback(appState, sessionId, hookEvent, matcher, result.hook);
2200
+ // Invoke onHookSuccess only on success outcome
2201
+ if (hookEntry?.onHookSuccess && result.outcome === 'success') {
2202
+ try {
2203
+ hookEntry.onHookSuccess(result.hook, result);
2204
+ }
2205
+ catch (error) {
2206
+ logError(Error('Session hook success callback failed', { cause: error }));
2207
+ }
2208
+ }
2209
+ }
2210
+ }
2211
+ const totalDurationMs = Date.now() - batchStartTime;
2212
+ getStatsStore()?.observe('hook_duration_ms', totalDurationMs);
2213
+ addToTurnHookDuration(totalDurationMs);
2214
+ logEvent(`thaddeus_repl_hook_finished`, {
2215
+ hookName: hookName,
2216
+ numCommands: matchingHooks.length,
2217
+ numSuccess: outcomes.success,
2218
+ numBlocking: outcomes.blocking,
2219
+ numNonBlockingError: outcomes.non_blocking_error,
2220
+ numCancelled: outcomes.cancelled,
2221
+ totalDurationMs,
2222
+ });
2223
+ // Log hook execution completion to OTEL (only for beta tracing)
2224
+ if (isBetaTracingEnabled()) {
2225
+ const hookDefinitionsComplete = getHookDefinitionsForTelemetry(matchingHooks);
2226
+ void logOTelEvent('hook_execution_complete', {
2227
+ hook_event: hookEvent,
2228
+ hook_name: hookName,
2229
+ num_hooks: String(matchingHooks.length),
2230
+ num_success: String(outcomes.success),
2231
+ num_blocking: String(outcomes.blocking),
2232
+ num_non_blocking_error: String(outcomes.non_blocking_error),
2233
+ num_cancelled: String(outcomes.cancelled),
2234
+ managed_only: String(shouldAllowManagedHooksOnly()),
2235
+ hook_definitions: jsonStringify(hookDefinitionsComplete),
2236
+ hook_source: shouldAllowManagedHooksOnly() ? 'policySettings' : 'merged',
2237
+ });
2238
+ }
2239
+ // End hook span for beta tracing
2240
+ endHookSpan(hookSpan, {
2241
+ numSuccess: outcomes.success,
2242
+ numBlocking: outcomes.blocking,
2243
+ numNonBlockingError: outcomes.non_blocking_error,
2244
+ numCancelled: outcomes.cancelled,
2245
+ });
2246
+ }
2247
+ export function hasBlockingResult(results) {
2248
+ return results.some(r => r.blocked);
2249
+ }
2250
+ /**
2251
+ * Execute hooks outside of the REPL (e.g. notifications, session end)
2252
+ *
2253
+ * Unlike executeHooks() which yields messages that are exposed to the model as
2254
+ * system messages, this function only logs errors via logForDebugging (visible
2255
+ * with --debug). Callers that need to surface errors to users should handle
2256
+ * the returned results appropriately (e.g. executeSessionEndHooks writes to
2257
+ * stderr during shutdown).
2258
+ *
2259
+ * @param getAppState Optional function to get the current app state (for session hooks)
2260
+ * @param hookInput The structured hook input that will be validated and converted to JSON
2261
+ * @param matchQuery The query to match against hook matchers
2262
+ * @param signal Optional AbortSignal to cancel hook execution
2263
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2264
+ * @returns Array of HookOutsideReplResult objects containing command, succeeded, and output
2265
+ */
2266
+ async function executeHooksOutsideREPL({ getAppState, hookInput, matchQuery, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, }) {
2267
+ if (isEnvTruthy(process.env.THADDEUS_SIMPLE)) {
2268
+ return [];
2269
+ }
2270
+ const hookEvent = hookInput.hook_event_name;
2271
+ const hookName = matchQuery ? `${hookEvent}:${matchQuery}` : hookEvent;
2272
+ if (shouldDisableAllHooksIncludingManaged()) {
2273
+ logForDebugging(`Skipping hooks for ${hookName} due to 'disableAllHooks' managed setting`);
2274
+ return [];
2275
+ }
2276
+ // SECURITY: ALL hooks require workspace trust in interactive mode
2277
+ // This centralized check prevents RCE vulnerabilities for all current and future hooks
2278
+ if (shouldSkipHookDueToTrust()) {
2279
+ logForDebugging(`Skipping ${hookName} hook execution - workspace trust not accepted`);
2280
+ return [];
2281
+ }
2282
+ const appState = getAppState ? getAppState() : undefined;
2283
+ // Use main session ID for outside-REPL hooks
2284
+ const sessionId = getSessionId();
2285
+ const matchingHooks = await getMatchingHooks(appState, sessionId, hookEvent, hookInput);
2286
+ if (matchingHooks.length === 0) {
2287
+ return [];
2288
+ }
2289
+ if (signal?.aborted) {
2290
+ return [];
2291
+ }
2292
+ const userHooks = matchingHooks.filter(h => !isInternalHook(h));
2293
+ if (userHooks.length > 0) {
2294
+ const pluginHookCounts = getPluginHookCounts(userHooks);
2295
+ const hookTypeCounts = getHookTypeCounts(userHooks);
2296
+ logEvent(`thaddeus_run_hook`, {
2297
+ hookName: hookName,
2298
+ numCommands: userHooks.length,
2299
+ hookTypeCounts: jsonStringify(hookTypeCounts),
2300
+ ...(pluginHookCounts && {
2301
+ pluginHookCounts: jsonStringify(pluginHookCounts),
2302
+ }),
2303
+ });
2304
+ }
2305
+ // Validate and stringify the hook input
2306
+ let jsonInput;
2307
+ try {
2308
+ jsonInput = jsonStringify(hookInput);
2309
+ }
2310
+ catch (error) {
2311
+ logError(error);
2312
+ return [];
2313
+ }
2314
+ // Run all hooks in parallel with individual timeouts
2315
+ const hookPromises = matchingHooks.map(async ({ hook, pluginRoot, pluginId }, hookIndex) => {
2316
+ // Handle callback hooks
2317
+ if (hook.type === 'callback') {
2318
+ const callbackTimeoutMs = hook.timeout ? hook.timeout * 1000 : timeoutMs;
2319
+ const { signal: abortSignal, cleanup } = createCombinedAbortSignal(signal, { timeoutMs: callbackTimeoutMs });
2320
+ try {
2321
+ const toolUseID = randomUUID();
2322
+ const json = await hook.callback(hookInput, toolUseID, abortSignal, hookIndex);
2323
+ cleanup?.();
2324
+ if (isAsyncHookJSONOutput(json)) {
2325
+ logForDebugging(`${hookName} [callback] returned async response, returning empty output`);
2326
+ return {
2327
+ command: 'callback',
2328
+ succeeded: true,
2329
+ output: '',
2330
+ blocked: false,
2331
+ };
2332
+ }
2333
+ const output = hookEvent === 'WorktreeCreate' &&
2334
+ isSyncHookJSONOutput(json) &&
2335
+ json.hookSpecificOutput?.hookEventName === 'WorktreeCreate'
2336
+ ? json.hookSpecificOutput.worktreePath
2337
+ : json.systemMessage || '';
2338
+ const blocked = isSyncHookJSONOutput(json) && json.decision === 'block';
2339
+ logForDebugging(`${hookName} [callback] completed successfully`);
2340
+ return {
2341
+ command: 'callback',
2342
+ succeeded: true,
2343
+ output,
2344
+ blocked,
2345
+ };
2346
+ }
2347
+ catch (error) {
2348
+ cleanup?.();
2349
+ const errorMessage = error instanceof Error ? error.message : String(error);
2350
+ logForDebugging(`${hookName} [callback] failed to run: ${errorMessage}`, { level: 'error' });
2351
+ return {
2352
+ command: 'callback',
2353
+ succeeded: false,
2354
+ output: errorMessage,
2355
+ blocked: false,
2356
+ };
2357
+ }
2358
+ }
2359
+ // TODO: Implement prompt stop hooks outside REPL
2360
+ if (hook.type === 'prompt') {
2361
+ return {
2362
+ command: hook.prompt,
2363
+ succeeded: false,
2364
+ output: 'Prompt stop hooks are not yet supported outside REPL',
2365
+ blocked: false,
2366
+ };
2367
+ }
2368
+ // TODO: Implement agent stop hooks outside REPL
2369
+ if (hook.type === 'agent') {
2370
+ return {
2371
+ command: hook.prompt,
2372
+ succeeded: false,
2373
+ output: 'Agent stop hooks are not yet supported outside REPL',
2374
+ blocked: false,
2375
+ };
2376
+ }
2377
+ // Function hooks require messages array (only available in REPL context)
2378
+ // For -p mode Stop hooks, use executeStopHooks which supports function hooks
2379
+ if (hook.type === 'function') {
2380
+ logError(new Error(`Function hook reached executeHooksOutsideREPL for ${hookEvent}. Function hooks should only be used in REPL context (Stop hooks).`));
2381
+ return {
2382
+ command: 'function',
2383
+ succeeded: false,
2384
+ output: 'Internal error: function hook executed outside REPL context',
2385
+ blocked: false,
2386
+ };
2387
+ }
2388
+ // Handle HTTP hooks (no toolUseContext needed - just HTTP POST).
2389
+ // execHttpHook handles its own timeout internally via hook.timeout or
2390
+ // DEFAULT_HTTP_HOOK_TIMEOUT_MS, so we pass signal directly.
2391
+ if (hook.type === 'http') {
2392
+ try {
2393
+ const httpResult = await execHttpHook(hook, hookEvent, jsonInput, signal);
2394
+ if (httpResult.aborted) {
2395
+ logForDebugging(`${hookName} [${hook.url}] cancelled`);
2396
+ return {
2397
+ command: hook.url,
2398
+ succeeded: false,
2399
+ output: 'Hook cancelled',
2400
+ blocked: false,
2401
+ };
2402
+ }
2403
+ if (httpResult.error || !httpResult.ok) {
2404
+ const errMsg = httpResult.error ||
2405
+ `HTTP ${httpResult.statusCode} from ${hook.url}`;
2406
+ logForDebugging(`${hookName} [${hook.url}] failed: ${errMsg}`, {
2407
+ level: 'error',
2408
+ });
2409
+ return {
2410
+ command: hook.url,
2411
+ succeeded: false,
2412
+ output: errMsg,
2413
+ blocked: false,
2414
+ };
2415
+ }
2416
+ // HTTP hooks must return JSON — parse and validate through Zod
2417
+ const { json: httpJson, validationError: httpValidationError } = parseHttpHookOutput(httpResult.body);
2418
+ if (httpValidationError) {
2419
+ throw new Error(httpValidationError);
2420
+ }
2421
+ if (httpJson && !isAsyncHookJSONOutput(httpJson)) {
2422
+ logForDebugging(`Parsed JSON output from HTTP hook: ${jsonStringify(httpJson)}`, { level: 'verbose' });
2423
+ }
2424
+ const jsonBlocked = httpJson &&
2425
+ !isAsyncHookJSONOutput(httpJson) &&
2426
+ isSyncHookJSONOutput(httpJson) &&
2427
+ httpJson.decision === 'block';
2428
+ // WorktreeCreate's consumer reads `output` as the bare filesystem
2429
+ // path. Command hooks provide it via stdout; http hooks provide it
2430
+ // via hookSpecificOutput.worktreePath. Without worktreePath, emit ''
2431
+ // so the consumer's length filter skips it instead of treating the
2432
+ // raw '{}' body as a path.
2433
+ const output = hookEvent === 'WorktreeCreate'
2434
+ ? httpJson &&
2435
+ isSyncHookJSONOutput(httpJson) &&
2436
+ httpJson.hookSpecificOutput?.hookEventName === 'WorktreeCreate'
2437
+ ? httpJson.hookSpecificOutput.worktreePath
2438
+ : ''
2439
+ : httpResult.body;
2440
+ return {
2441
+ command: hook.url,
2442
+ succeeded: true,
2443
+ output,
2444
+ blocked: !!jsonBlocked,
2445
+ };
2446
+ }
2447
+ catch (error) {
2448
+ const errorMessage = error instanceof Error ? error.message : String(error);
2449
+ logForDebugging(`${hookName} [${hook.url}] failed to run: ${errorMessage}`, { level: 'error' });
2450
+ return {
2451
+ command: hook.url,
2452
+ succeeded: false,
2453
+ output: errorMessage,
2454
+ blocked: false,
2455
+ };
2456
+ }
2457
+ }
2458
+ // Handle command hooks
2459
+ const commandTimeoutMs = hook.timeout ? hook.timeout * 1000 : timeoutMs;
2460
+ const { signal: abortSignal, cleanup } = createCombinedAbortSignal(signal, { timeoutMs: commandTimeoutMs });
2461
+ try {
2462
+ const result = await execCommandHook(hook, hookEvent, hookName, jsonInput, abortSignal, randomUUID(), hookIndex, pluginRoot, pluginId);
2463
+ // Clear timeout if hook completes
2464
+ cleanup?.();
2465
+ if (result.aborted) {
2466
+ logForDebugging(`${hookName} [${hook.command}] cancelled`);
2467
+ return {
2468
+ command: hook.command,
2469
+ succeeded: false,
2470
+ output: 'Hook cancelled',
2471
+ blocked: false,
2472
+ };
2473
+ }
2474
+ logForDebugging(`${hookName} [${hook.command}] completed with status ${result.status}`);
2475
+ // Parse JSON for any messages to print out.
2476
+ const { json, validationError } = parseHookOutput(result.stdout);
2477
+ if (validationError) {
2478
+ // Validation error is logged via logForDebugging and returned in output
2479
+ throw new Error(validationError);
2480
+ }
2481
+ if (json && !isAsyncHookJSONOutput(json)) {
2482
+ logForDebugging(`Parsed JSON output from hook: ${jsonStringify(json)}`, { level: 'verbose' });
2483
+ }
2484
+ // Blocked if exit code 2 or JSON decision: 'block'
2485
+ const jsonBlocked = json &&
2486
+ !isAsyncHookJSONOutput(json) &&
2487
+ isSyncHookJSONOutput(json) &&
2488
+ json.decision === 'block';
2489
+ const blocked = result.status === 2 || !!jsonBlocked;
2490
+ // For successful hooks (exit code 0), use stdout; for failed hooks, use stderr
2491
+ const output = result.status === 0 ? result.stdout || '' : result.stderr || '';
2492
+ const watchPaths = json &&
2493
+ isSyncHookJSONOutput(json) &&
2494
+ json.hookSpecificOutput &&
2495
+ 'watchPaths' in json.hookSpecificOutput
2496
+ ? json.hookSpecificOutput.watchPaths
2497
+ : undefined;
2498
+ const systemMessage = json && isSyncHookJSONOutput(json) ? json.systemMessage : undefined;
2499
+ return {
2500
+ command: hook.command,
2501
+ succeeded: result.status === 0,
2502
+ output,
2503
+ blocked,
2504
+ watchPaths,
2505
+ systemMessage,
2506
+ };
2507
+ }
2508
+ catch (error) {
2509
+ // Clean up on error
2510
+ cleanup?.();
2511
+ const errorMessage = error instanceof Error ? error.message : String(error);
2512
+ logForDebugging(`${hookName} [${hook.command}] failed to run: ${errorMessage}`, { level: 'error' });
2513
+ return {
2514
+ command: hook.command,
2515
+ succeeded: false,
2516
+ output: errorMessage,
2517
+ blocked: false,
2518
+ };
2519
+ }
2520
+ });
2521
+ // Wait for all hooks to complete and collect results
2522
+ return await Promise.all(hookPromises);
2523
+ }
2524
+ /**
2525
+ * Execute pre-tool hooks if configured
2526
+ * @param toolName The name of the tool (e.g., 'Write', 'Edit', 'Bash')
2527
+ * @param toolUseID The ID of the tool use
2528
+ * @param toolInput The input that will be passed to the tool
2529
+ * @param permissionMode Optional permission mode from toolPermissionContext
2530
+ * @param signal Optional AbortSignal to cancel hook execution
2531
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2532
+ * @param toolUseContext Optional ToolUseContext for prompt-based hooks
2533
+ * @returns Async generator that yields progress messages and returns blocking errors
2534
+ */
2535
+ export async function* executePreToolHooks(toolName, toolUseID, toolInput, toolUseContext, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, requestPrompt, toolInputSummary) {
2536
+ const appState = toolUseContext.getAppState();
2537
+ const sessionId = toolUseContext.agentId ?? getSessionId();
2538
+ if (!hasHookForEvent('PreToolUse', appState, sessionId)) {
2539
+ return;
2540
+ }
2541
+ logForDebugging(`executePreToolHooks called for tool: ${toolName}`, {
2542
+ level: 'verbose',
2543
+ });
2544
+ const hookInput = {
2545
+ ...createBaseHookInput(permissionMode, undefined, toolUseContext),
2546
+ hook_event_name: 'PreToolUse',
2547
+ tool_name: toolName,
2548
+ tool_input: toolInput,
2549
+ tool_use_id: toolUseID,
2550
+ };
2551
+ yield* executeHooks({
2552
+ hookInput,
2553
+ toolUseID,
2554
+ matchQuery: toolName,
2555
+ signal,
2556
+ timeoutMs,
2557
+ toolUseContext,
2558
+ requestPrompt,
2559
+ toolInputSummary,
2560
+ });
2561
+ }
2562
+ /**
2563
+ * Execute post-tool hooks if configured
2564
+ * @param toolName The name of the tool (e.g., 'Write', 'Edit', 'Bash')
2565
+ * @param toolUseID The ID of the tool use
2566
+ * @param toolInput The input that was passed to the tool
2567
+ * @param toolResponse The response from the tool
2568
+ * @param toolUseContext ToolUseContext for prompt-based hooks
2569
+ * @param permissionMode Optional permission mode from toolPermissionContext
2570
+ * @param signal Optional AbortSignal to cancel hook execution
2571
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2572
+ * @returns Async generator that yields progress messages and blocking errors for automated feedback
2573
+ */
2574
+ export async function* executePostToolHooks(toolName, toolUseID, toolInput, toolResponse, toolUseContext, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2575
+ const hookInput = {
2576
+ ...createBaseHookInput(permissionMode, undefined, toolUseContext),
2577
+ hook_event_name: 'PostToolUse',
2578
+ tool_name: toolName,
2579
+ tool_input: toolInput,
2580
+ tool_response: toolResponse,
2581
+ tool_use_id: toolUseID,
2582
+ };
2583
+ yield* executeHooks({
2584
+ hookInput,
2585
+ toolUseID,
2586
+ matchQuery: toolName,
2587
+ signal,
2588
+ timeoutMs,
2589
+ toolUseContext,
2590
+ });
2591
+ }
2592
+ /**
2593
+ * Execute post-tool-use-failure hooks if configured
2594
+ * @param toolName The name of the tool (e.g., 'Write', 'Edit', 'Bash')
2595
+ * @param toolUseID The ID of the tool use
2596
+ * @param toolInput The input that was passed to the tool
2597
+ * @param error The error message from the failed tool call
2598
+ * @param toolUseContext ToolUseContext for prompt-based hooks
2599
+ * @param isInterrupt Whether the tool was interrupted by user
2600
+ * @param permissionMode Optional permission mode from toolPermissionContext
2601
+ * @param signal Optional AbortSignal to cancel hook execution
2602
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2603
+ * @returns Async generator that yields progress messages and blocking errors
2604
+ */
2605
+ export async function* executePostToolUseFailureHooks(toolName, toolUseID, toolInput, error, toolUseContext, isInterrupt, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2606
+ const appState = toolUseContext.getAppState();
2607
+ const sessionId = toolUseContext.agentId ?? getSessionId();
2608
+ if (!hasHookForEvent('PostToolUseFailure', appState, sessionId)) {
2609
+ return;
2610
+ }
2611
+ const hookInput = {
2612
+ ...createBaseHookInput(permissionMode, undefined, toolUseContext),
2613
+ hook_event_name: 'PostToolUseFailure',
2614
+ tool_name: toolName,
2615
+ tool_input: toolInput,
2616
+ tool_use_id: toolUseID,
2617
+ error,
2618
+ is_interrupt: isInterrupt,
2619
+ };
2620
+ yield* executeHooks({
2621
+ hookInput,
2622
+ toolUseID,
2623
+ matchQuery: toolName,
2624
+ signal,
2625
+ timeoutMs,
2626
+ toolUseContext,
2627
+ });
2628
+ }
2629
+ export async function* executePermissionDeniedHooks(toolName, toolUseID, toolInput, reason, toolUseContext, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2630
+ const appState = toolUseContext.getAppState();
2631
+ const sessionId = toolUseContext.agentId ?? getSessionId();
2632
+ if (!hasHookForEvent('PermissionDenied', appState, sessionId)) {
2633
+ return;
2634
+ }
2635
+ const hookInput = {
2636
+ ...createBaseHookInput(permissionMode, undefined, toolUseContext),
2637
+ hook_event_name: 'PermissionDenied',
2638
+ tool_name: toolName,
2639
+ tool_input: toolInput,
2640
+ tool_use_id: toolUseID,
2641
+ reason,
2642
+ };
2643
+ yield* executeHooks({
2644
+ hookInput,
2645
+ toolUseID,
2646
+ matchQuery: toolName,
2647
+ signal,
2648
+ timeoutMs,
2649
+ toolUseContext,
2650
+ });
2651
+ }
2652
+ /**
2653
+ * Execute notification hooks if configured
2654
+ * @param notificationData The notification data to pass to hooks
2655
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2656
+ * @returns Promise that resolves when all hooks complete
2657
+ */
2658
+ export async function executeNotificationHooks(notificationData, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2659
+ const { message, title, notificationType } = notificationData;
2660
+ const hookInput = {
2661
+ ...createBaseHookInput(undefined),
2662
+ hook_event_name: 'Notification',
2663
+ message,
2664
+ title,
2665
+ notification_type: notificationType,
2666
+ };
2667
+ await executeHooksOutsideREPL({
2668
+ hookInput,
2669
+ timeoutMs,
2670
+ matchQuery: notificationType,
2671
+ });
2672
+ }
2673
+ export async function executeStopFailureHooks(lastMessage, toolUseContext, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2674
+ const appState = toolUseContext?.getAppState();
2675
+ // executeHooksOutsideREPL hardcodes main sessionId (:2738). Agent frontmatter
2676
+ // hooks (registerFrontmatterHooks) key by agentId; gating with agentId here
2677
+ // would pass the gate but fail execution. Align gate with execution.
2678
+ const sessionId = getSessionId();
2679
+ if (!hasHookForEvent('StopFailure', appState, sessionId))
2680
+ return;
2681
+ const lastAssistantText = extractTextContent(lastMessage.message.content, '\n').trim() || undefined;
2682
+ // Some createAssistantAPIErrorMessage call sites omit `error` (e.g.
2683
+ // image-size at errors.ts:431). Default to 'unknown' so matcher filtering
2684
+ // at getMatchingHooks:1525 always applies.
2685
+ const error = lastMessage.error ?? 'unknown';
2686
+ const hookInput = {
2687
+ ...createBaseHookInput(undefined, undefined, toolUseContext),
2688
+ hook_event_name: 'StopFailure',
2689
+ error,
2690
+ error_details: lastMessage.errorDetails,
2691
+ last_assistant_message: lastAssistantText,
2692
+ };
2693
+ await executeHooksOutsideREPL({
2694
+ getAppState: toolUseContext?.getAppState,
2695
+ hookInput,
2696
+ timeoutMs,
2697
+ matchQuery: error,
2698
+ });
2699
+ }
2700
+ /**
2701
+ * Execute stop hooks if configured
2702
+ * @param toolUseContext ToolUseContext for prompt-based hooks
2703
+ * @param permissionMode permission mode from toolPermissionContext
2704
+ * @param signal AbortSignal to cancel hook execution
2705
+ * @param stopHookActive Whether this call is happening within another stop hook
2706
+ * @param isSubagent Whether the current execution context is a subagent
2707
+ * @param messages Optional conversation history for prompt/function hooks
2708
+ * @returns Async generator that yields progress messages and blocking errors
2709
+ */
2710
+ export async function* executeStopHooks(permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, stopHookActive = false, subagentId, toolUseContext, messages, agentType, requestPrompt) {
2711
+ const hookEvent = subagentId ? 'SubagentStop' : 'Stop';
2712
+ const appState = toolUseContext?.getAppState();
2713
+ const sessionId = toolUseContext?.agentId ?? getSessionId();
2714
+ if (!hasHookForEvent(hookEvent, appState, sessionId)) {
2715
+ return;
2716
+ }
2717
+ // Extract text content from the last assistant message so hooks can
2718
+ // inspect the final response without reading the transcript file.
2719
+ const lastAssistantMessage = messages
2720
+ ? getLastAssistantMessage(messages)
2721
+ : undefined;
2722
+ const lastAssistantText = lastAssistantMessage
2723
+ ? extractTextContent(lastAssistantMessage.message.content, '\n').trim() ||
2724
+ undefined
2725
+ : undefined;
2726
+ const hookInput = subagentId
2727
+ ? {
2728
+ ...createBaseHookInput(permissionMode),
2729
+ hook_event_name: 'SubagentStop',
2730
+ stop_hook_active: stopHookActive,
2731
+ agent_id: subagentId,
2732
+ agent_transcript_path: getAgentTranscriptPath(subagentId),
2733
+ agent_type: agentType ?? '',
2734
+ last_assistant_message: lastAssistantText,
2735
+ }
2736
+ : {
2737
+ ...createBaseHookInput(permissionMode),
2738
+ hook_event_name: 'Stop',
2739
+ stop_hook_active: stopHookActive,
2740
+ last_assistant_message: lastAssistantText,
2741
+ };
2742
+ // Trust check is now centralized in executeHooks()
2743
+ yield* executeHooks({
2744
+ hookInput,
2745
+ toolUseID: randomUUID(),
2746
+ signal,
2747
+ timeoutMs,
2748
+ toolUseContext,
2749
+ messages,
2750
+ requestPrompt,
2751
+ });
2752
+ }
2753
+ /**
2754
+ * Execute TeammateIdle hooks when a teammate is about to go idle.
2755
+ * If a hook blocks (exit code 2), the teammate should continue working instead of going idle.
2756
+ * @param teammateName The name of the teammate going idle
2757
+ * @param teamName The team this teammate belongs to
2758
+ * @param permissionMode Optional permission mode
2759
+ * @param signal Optional AbortSignal to cancel hook execution
2760
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2761
+ * @returns Async generator that yields progress messages and blocking errors
2762
+ */
2763
+ export async function* executeTeammateIdleHooks(teammateName, teamName, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2764
+ const hookInput = {
2765
+ ...createBaseHookInput(permissionMode),
2766
+ hook_event_name: 'TeammateIdle',
2767
+ teammate_name: teammateName,
2768
+ team_name: teamName,
2769
+ };
2770
+ yield* executeHooks({
2771
+ hookInput,
2772
+ toolUseID: randomUUID(),
2773
+ signal,
2774
+ timeoutMs,
2775
+ });
2776
+ }
2777
+ /**
2778
+ * Execute TaskCreated hooks when a task is being created.
2779
+ * If a hook blocks (exit code 2), the task creation should be prevented and feedback returned.
2780
+ * @param taskId The ID of the task being created
2781
+ * @param taskSubject The subject/title of the task
2782
+ * @param taskDescription Optional description of the task
2783
+ * @param teammateName Optional name of the teammate creating the task
2784
+ * @param teamName Optional team name
2785
+ * @param permissionMode Optional permission mode
2786
+ * @param signal Optional AbortSignal to cancel hook execution
2787
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2788
+ * @param toolUseContext Optional ToolUseContext for resolving appState and sessionId
2789
+ * @returns Async generator that yields progress messages and blocking errors
2790
+ */
2791
+ export async function* executeTaskCreatedHooks(taskId, taskSubject, taskDescription, teammateName, teamName, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, toolUseContext) {
2792
+ const hookInput = {
2793
+ ...createBaseHookInput(permissionMode),
2794
+ hook_event_name: 'TaskCreated',
2795
+ task_id: taskId,
2796
+ task_subject: taskSubject,
2797
+ task_description: taskDescription,
2798
+ teammate_name: teammateName,
2799
+ team_name: teamName,
2800
+ };
2801
+ yield* executeHooks({
2802
+ hookInput,
2803
+ toolUseID: randomUUID(),
2804
+ signal,
2805
+ timeoutMs,
2806
+ toolUseContext,
2807
+ });
2808
+ }
2809
+ /**
2810
+ * Execute TaskCompleted hooks when a task is being marked as completed.
2811
+ * If a hook blocks (exit code 2), the task completion should be prevented and feedback returned.
2812
+ * @param taskId The ID of the task being completed
2813
+ * @param taskSubject The subject/title of the task
2814
+ * @param taskDescription Optional description of the task
2815
+ * @param teammateName Optional name of the teammate completing the task
2816
+ * @param teamName Optional team name
2817
+ * @param permissionMode Optional permission mode
2818
+ * @param signal Optional AbortSignal to cancel hook execution
2819
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2820
+ * @param toolUseContext Optional ToolUseContext for resolving appState and sessionId
2821
+ * @returns Async generator that yields progress messages and blocking errors
2822
+ */
2823
+ export async function* executeTaskCompletedHooks(taskId, taskSubject, taskDescription, teammateName, teamName, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, toolUseContext) {
2824
+ const hookInput = {
2825
+ ...createBaseHookInput(permissionMode),
2826
+ hook_event_name: 'TaskCompleted',
2827
+ task_id: taskId,
2828
+ task_subject: taskSubject,
2829
+ task_description: taskDescription,
2830
+ teammate_name: teammateName,
2831
+ team_name: teamName,
2832
+ };
2833
+ yield* executeHooks({
2834
+ hookInput,
2835
+ toolUseID: randomUUID(),
2836
+ signal,
2837
+ timeoutMs,
2838
+ toolUseContext,
2839
+ });
2840
+ }
2841
+ /**
2842
+ * Execute start hooks if configured
2843
+ * @param prompt The user prompt that will be passed to the tool
2844
+ * @param permissionMode Permission mode from toolPermissionContext
2845
+ * @param toolUseContext ToolUseContext for prompt-based hooks
2846
+ * @returns Async generator that yields progress messages and hook results
2847
+ */
2848
+ export async function* executeUserPromptSubmitHooks(prompt, permissionMode, toolUseContext, requestPrompt) {
2849
+ const appState = toolUseContext.getAppState();
2850
+ const sessionId = toolUseContext.agentId ?? getSessionId();
2851
+ if (!hasHookForEvent('UserPromptSubmit', appState, sessionId)) {
2852
+ return;
2853
+ }
2854
+ const hookInput = {
2855
+ ...createBaseHookInput(permissionMode),
2856
+ hook_event_name: 'UserPromptSubmit',
2857
+ prompt,
2858
+ };
2859
+ yield* executeHooks({
2860
+ hookInput,
2861
+ toolUseID: randomUUID(),
2862
+ signal: toolUseContext.abortController.signal,
2863
+ timeoutMs: TOOL_HOOK_EXECUTION_TIMEOUT_MS,
2864
+ toolUseContext,
2865
+ requestPrompt,
2866
+ });
2867
+ }
2868
+ /**
2869
+ * Execute session start hooks if configured
2870
+ * @param source The source of the session start (startup, resume, clear)
2871
+ * @param sessionId Optional The session id to use as hook input
2872
+ * @param agentType Optional The agent type (from --agent flag) running this session
2873
+ * @param model Optional The model being used for this session
2874
+ * @param signal Optional AbortSignal to cancel hook execution
2875
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2876
+ * @returns Async generator that yields progress messages and hook results
2877
+ */
2878
+ export async function* executeSessionStartHooks(source, sessionId, agentType, model, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, forceSyncExecution) {
2879
+ const hookInput = {
2880
+ ...createBaseHookInput(undefined, sessionId),
2881
+ hook_event_name: 'SessionStart',
2882
+ source,
2883
+ agent_type: agentType,
2884
+ model,
2885
+ };
2886
+ yield* executeHooks({
2887
+ hookInput,
2888
+ toolUseID: randomUUID(),
2889
+ matchQuery: source,
2890
+ signal,
2891
+ timeoutMs,
2892
+ forceSyncExecution,
2893
+ });
2894
+ }
2895
+ /**
2896
+ * Execute setup hooks if configured
2897
+ * @param trigger The trigger type ('init' or 'maintenance')
2898
+ * @param signal Optional AbortSignal to cancel hook execution
2899
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2900
+ * @param forceSyncExecution If true, async hooks will not be backgrounded
2901
+ * @returns Async generator that yields progress messages and hook results
2902
+ */
2903
+ export async function* executeSetupHooks(trigger, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, forceSyncExecution) {
2904
+ const hookInput = {
2905
+ ...createBaseHookInput(undefined),
2906
+ hook_event_name: 'Setup',
2907
+ trigger,
2908
+ };
2909
+ yield* executeHooks({
2910
+ hookInput,
2911
+ toolUseID: randomUUID(),
2912
+ matchQuery: trigger,
2913
+ signal,
2914
+ timeoutMs,
2915
+ forceSyncExecution,
2916
+ });
2917
+ }
2918
+ /**
2919
+ * Execute subagent start hooks if configured
2920
+ * @param agentId The unique identifier for the subagent
2921
+ * @param agentType The type/name of the subagent being started
2922
+ * @param signal Optional AbortSignal to cancel hook execution
2923
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2924
+ * @returns Async generator that yields progress messages and hook results
2925
+ */
2926
+ export async function* executeSubagentStartHooks(agentId, agentType, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2927
+ const hookInput = {
2928
+ ...createBaseHookInput(undefined),
2929
+ hook_event_name: 'SubagentStart',
2930
+ agent_id: agentId,
2931
+ agent_type: agentType,
2932
+ };
2933
+ yield* executeHooks({
2934
+ hookInput,
2935
+ toolUseID: randomUUID(),
2936
+ matchQuery: agentType,
2937
+ signal,
2938
+ timeoutMs,
2939
+ });
2940
+ }
2941
+ /**
2942
+ * Execute pre-compact hooks if configured
2943
+ * @param compactData The compact data to pass to hooks
2944
+ * @param signal Optional AbortSignal to cancel hook execution
2945
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2946
+ * @returns Object with optional newCustomInstructions and userDisplayMessage
2947
+ */
2948
+ export async function executePreCompactHooks(compactData, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
2949
+ const hookInput = {
2950
+ ...createBaseHookInput(undefined),
2951
+ hook_event_name: 'PreCompact',
2952
+ trigger: compactData.trigger,
2953
+ custom_instructions: compactData.customInstructions,
2954
+ };
2955
+ const results = await executeHooksOutsideREPL({
2956
+ hookInput,
2957
+ matchQuery: compactData.trigger,
2958
+ signal,
2959
+ timeoutMs,
2960
+ });
2961
+ if (results.length === 0) {
2962
+ return {};
2963
+ }
2964
+ // Extract custom instructions from successful hooks with non-empty output
2965
+ const successfulOutputs = results
2966
+ .filter(result => result.succeeded && result.output.trim().length > 0)
2967
+ .map(result => result.output.trim());
2968
+ // Build user display messages with command info
2969
+ const displayMessages = [];
2970
+ for (const result of results) {
2971
+ if (result.succeeded) {
2972
+ if (result.output.trim()) {
2973
+ displayMessages.push(`PreCompact [${result.command}] completed successfully: ${result.output.trim()}`);
2974
+ }
2975
+ else {
2976
+ displayMessages.push(`PreCompact [${result.command}] completed successfully`);
2977
+ }
2978
+ }
2979
+ else {
2980
+ if (result.output.trim()) {
2981
+ displayMessages.push(`PreCompact [${result.command}] failed: ${result.output.trim()}`);
2982
+ }
2983
+ else {
2984
+ displayMessages.push(`PreCompact [${result.command}] failed`);
2985
+ }
2986
+ }
2987
+ }
2988
+ return {
2989
+ newCustomInstructions: successfulOutputs.length > 0 ? successfulOutputs.join('\n\n') : undefined,
2990
+ userDisplayMessage: displayMessages.length > 0 ? displayMessages.join('\n') : undefined,
2991
+ };
2992
+ }
2993
+ /**
2994
+ * Execute post-compact hooks if configured
2995
+ * @param compactData The compact data to pass to hooks, including the summary
2996
+ * @param signal Optional AbortSignal to cancel hook execution
2997
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
2998
+ * @returns Object with optional userDisplayMessage
2999
+ */
3000
+ export async function executePostCompactHooks(compactData, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
3001
+ const hookInput = {
3002
+ ...createBaseHookInput(undefined),
3003
+ hook_event_name: 'PostCompact',
3004
+ trigger: compactData.trigger,
3005
+ compact_summary: compactData.compactSummary,
3006
+ };
3007
+ const results = await executeHooksOutsideREPL({
3008
+ hookInput,
3009
+ matchQuery: compactData.trigger,
3010
+ signal,
3011
+ timeoutMs,
3012
+ });
3013
+ if (results.length === 0) {
3014
+ return {};
3015
+ }
3016
+ const displayMessages = [];
3017
+ for (const result of results) {
3018
+ if (result.succeeded) {
3019
+ if (result.output.trim()) {
3020
+ displayMessages.push(`PostCompact [${result.command}] completed successfully: ${result.output.trim()}`);
3021
+ }
3022
+ else {
3023
+ displayMessages.push(`PostCompact [${result.command}] completed successfully`);
3024
+ }
3025
+ }
3026
+ else {
3027
+ if (result.output.trim()) {
3028
+ displayMessages.push(`PostCompact [${result.command}] failed: ${result.output.trim()}`);
3029
+ }
3030
+ else {
3031
+ displayMessages.push(`PostCompact [${result.command}] failed`);
3032
+ }
3033
+ }
3034
+ }
3035
+ return {
3036
+ userDisplayMessage: displayMessages.length > 0 ? displayMessages.join('\n') : undefined,
3037
+ };
3038
+ }
3039
+ /**
3040
+ * Execute session end hooks if configured
3041
+ * @param reason The reason for ending the session
3042
+ * @param options Optional parameters including app state functions and signal
3043
+ * @returns Promise that resolves when all hooks complete
3044
+ */
3045
+ export async function executeSessionEndHooks(reason, options) {
3046
+ const { getAppState, setAppState, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, } = options || {};
3047
+ const hookInput = {
3048
+ ...createBaseHookInput(undefined),
3049
+ hook_event_name: 'SessionEnd',
3050
+ reason,
3051
+ };
3052
+ const results = await executeHooksOutsideREPL({
3053
+ getAppState,
3054
+ hookInput,
3055
+ matchQuery: reason,
3056
+ signal,
3057
+ timeoutMs,
3058
+ });
3059
+ // During shutdown, Ink is unmounted so we can write directly to stderr
3060
+ for (const result of results) {
3061
+ if (!result.succeeded && result.output) {
3062
+ process.stderr.write(`SessionEnd hook [${result.command}] failed: ${result.output}\n`);
3063
+ }
3064
+ }
3065
+ // Clear session hooks after execution
3066
+ if (setAppState) {
3067
+ const sessionId = getSessionId();
3068
+ clearSessionHooks(setAppState, sessionId);
3069
+ }
3070
+ }
3071
+ /**
3072
+ * Execute permission request hooks if configured
3073
+ * These hooks are called when a permission dialog would be displayed to the user.
3074
+ * Hooks can approve or deny the permission request programmatically.
3075
+ * @param toolName The name of the tool requesting permission
3076
+ * @param toolUseID The ID of the tool use
3077
+ * @param toolInput The input that would be passed to the tool
3078
+ * @param toolUseContext ToolUseContext for the request
3079
+ * @param permissionMode Optional permission mode from toolPermissionContext
3080
+ * @param permissionSuggestions Optional permission suggestions (the "always allow" options)
3081
+ * @param signal Optional AbortSignal to cancel hook execution
3082
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
3083
+ * @returns Async generator that yields progress messages and returns aggregated result
3084
+ */
3085
+ export async function* executePermissionRequestHooks(toolName, toolUseID, toolInput, toolUseContext, permissionMode, permissionSuggestions, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, requestPrompt, toolInputSummary) {
3086
+ logForDebugging(`executePermissionRequestHooks called for tool: ${toolName}`);
3087
+ const hookInput = {
3088
+ ...createBaseHookInput(permissionMode, undefined, toolUseContext),
3089
+ hook_event_name: 'PermissionRequest',
3090
+ tool_name: toolName,
3091
+ tool_input: toolInput,
3092
+ permission_suggestions: permissionSuggestions,
3093
+ };
3094
+ yield* executeHooks({
3095
+ hookInput,
3096
+ toolUseID,
3097
+ matchQuery: toolName,
3098
+ signal,
3099
+ timeoutMs,
3100
+ toolUseContext,
3101
+ requestPrompt,
3102
+ toolInputSummary,
3103
+ });
3104
+ }
3105
+ /**
3106
+ * Execute config change hooks when configuration files change during a session.
3107
+ * Fired by file watchers when settings, skills, or commands change on disk.
3108
+ * Enables enterprise admins to audit/log configuration changes for security.
3109
+ *
3110
+ * Policy settings are enterprise-managed and must never be blockable by hooks.
3111
+ * Hooks still fire (for audit logging) but blocking results are ignored — callers
3112
+ * will always see an empty result for policy sources.
3113
+ *
3114
+ * @param source The type of config that changed
3115
+ * @param filePath Optional path to the changed file
3116
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
3117
+ */
3118
+ export async function executeConfigChangeHooks(source, filePath, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
3119
+ const hookInput = {
3120
+ ...createBaseHookInput(undefined),
3121
+ hook_event_name: 'ConfigChange',
3122
+ source,
3123
+ file_path: filePath,
3124
+ };
3125
+ const results = await executeHooksOutsideREPL({
3126
+ hookInput,
3127
+ timeoutMs,
3128
+ matchQuery: source,
3129
+ });
3130
+ // Policy settings are enterprise-managed — hooks fire for audit logging
3131
+ // but must never block policy changes from being applied
3132
+ if (source === 'policy_settings') {
3133
+ return results.map(r => ({ ...r, blocked: false }));
3134
+ }
3135
+ return results;
3136
+ }
3137
+ async function executeEnvHooks(hookInput, timeoutMs) {
3138
+ const results = await executeHooksOutsideREPL({ hookInput, timeoutMs });
3139
+ if (results.length > 0) {
3140
+ invalidateSessionEnvCache();
3141
+ }
3142
+ const watchPaths = results.flatMap(r => r.watchPaths ?? []);
3143
+ const systemMessages = results
3144
+ .map(r => r.systemMessage)
3145
+ .filter((m) => !!m);
3146
+ return { results, watchPaths, systemMessages };
3147
+ }
3148
+ export function executeCwdChangedHooks(oldCwd, newCwd, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
3149
+ const hookInput = {
3150
+ ...createBaseHookInput(undefined),
3151
+ hook_event_name: 'CwdChanged',
3152
+ old_cwd: oldCwd,
3153
+ new_cwd: newCwd,
3154
+ };
3155
+ return executeEnvHooks(hookInput, timeoutMs);
3156
+ }
3157
+ export function executeFileChangedHooks(filePath, event, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS) {
3158
+ const hookInput = {
3159
+ ...createBaseHookInput(undefined),
3160
+ hook_event_name: 'FileChanged',
3161
+ file_path: filePath,
3162
+ event,
3163
+ };
3164
+ return executeEnvHooks(hookInput, timeoutMs);
3165
+ }
3166
+ /**
3167
+ * Check if InstructionsLoaded hooks are configured (without executing them).
3168
+ * Callers should check this before invoking executeInstructionsLoadedHooks to avoid
3169
+ * building hook inputs for every instruction file when no hook is configured.
3170
+ *
3171
+ * Checks both settings-file hooks (getHooksConfigFromSnapshot) and registered
3172
+ * hooks (plugin hooks + SDK callback hooks via registerHookCallbacks). Session-
3173
+ * derived hooks (structured output enforcement etc.) are internal and not checked.
3174
+ */
3175
+ export function hasInstructionsLoadedHook() {
3176
+ const snapshotHooks = getHooksConfigFromSnapshot()?.['InstructionsLoaded'];
3177
+ if (snapshotHooks && snapshotHooks.length > 0)
3178
+ return true;
3179
+ const registeredHooks = getRegisteredHooks()?.['InstructionsLoaded'];
3180
+ if (registeredHooks && registeredHooks.length > 0)
3181
+ return true;
3182
+ return false;
3183
+ }
3184
+ /**
3185
+ * Execute InstructionsLoaded hooks when an instruction file (THADDEUS.md or
3186
+ * .claude/rules/*.md) is loaded into context. Fire-and-forget — this hook is
3187
+ * for observability/audit only and does not support blocking.
3188
+ *
3189
+ * Dispatch sites:
3190
+ * - Eager load at session start (getMemoryFiles in claudemd.ts)
3191
+ * - Eager reload after compaction (getMemoryFiles cache cleared by
3192
+ * runPostCompactCleanup; next call reports load_reason: 'compact')
3193
+ * - Lazy load when Thaddeus touches a file that triggers nested THADDEUS.md or
3194
+ * conditional rules with paths: frontmatter (memoryFilesToAttachments in
3195
+ * attachments.ts)
3196
+ */
3197
+ export async function executeInstructionsLoadedHooks(filePath, memoryType, loadReason, options) {
3198
+ const { globs, triggerFilePath, parentFilePath, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, } = options ?? {};
3199
+ const hookInput = {
3200
+ ...createBaseHookInput(undefined),
3201
+ hook_event_name: 'InstructionsLoaded',
3202
+ file_path: filePath,
3203
+ memory_type: memoryType,
3204
+ load_reason: loadReason,
3205
+ globs,
3206
+ trigger_file_path: triggerFilePath,
3207
+ parent_file_path: parentFilePath,
3208
+ };
3209
+ await executeHooksOutsideREPL({
3210
+ hookInput,
3211
+ timeoutMs,
3212
+ matchQuery: loadReason,
3213
+ });
3214
+ }
3215
+ /**
3216
+ * Parse elicitation-specific fields from a HookOutsideReplResult.
3217
+ * Mirrors the relevant branches of processHookJSONOutput for Elicitation
3218
+ * and ElicitationResult hook events.
3219
+ */
3220
+ function parseElicitationHookOutput(result, expectedEventName) {
3221
+ // Exit code 2 = blocking (same as executeHooks path)
3222
+ if (result.blocked && !result.succeeded) {
3223
+ return {
3224
+ blockingError: {
3225
+ blockingError: result.output || `Elicitation blocked by hook`,
3226
+ command: result.command,
3227
+ },
3228
+ };
3229
+ }
3230
+ if (!result.output.trim()) {
3231
+ return {};
3232
+ }
3233
+ // Try to parse JSON output for structured elicitation response
3234
+ const trimmed = result.output.trim();
3235
+ if (!trimmed.startsWith('{')) {
3236
+ return {};
3237
+ }
3238
+ try {
3239
+ const parsed = hookJSONOutputSchema().parse(JSON.parse(trimmed));
3240
+ if (isAsyncHookJSONOutput(parsed)) {
3241
+ return {};
3242
+ }
3243
+ if (!isSyncHookJSONOutput(parsed)) {
3244
+ return {};
3245
+ }
3246
+ // Check for top-level decision: 'block' (exit code 0 + JSON block)
3247
+ if (parsed.decision === 'block' || result.blocked) {
3248
+ return {
3249
+ blockingError: {
3250
+ blockingError: parsed.reason || 'Elicitation blocked by hook',
3251
+ command: result.command,
3252
+ },
3253
+ };
3254
+ }
3255
+ const specific = parsed.hookSpecificOutput;
3256
+ if (!specific || specific.hookEventName !== expectedEventName) {
3257
+ return {};
3258
+ }
3259
+ if (!specific.action) {
3260
+ return {};
3261
+ }
3262
+ const response = {
3263
+ action: specific.action,
3264
+ content: specific.content,
3265
+ };
3266
+ const out = { response };
3267
+ if (specific.action === 'decline') {
3268
+ out.blockingError = {
3269
+ blockingError: parsed.reason ||
3270
+ (expectedEventName === 'Elicitation'
3271
+ ? 'Elicitation denied by hook'
3272
+ : 'Elicitation result blocked by hook'),
3273
+ command: result.command,
3274
+ };
3275
+ }
3276
+ return out;
3277
+ }
3278
+ catch {
3279
+ return {};
3280
+ }
3281
+ }
3282
+ export async function executeElicitationHooks({ serverName, message, requestedSchema, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, mode, url, elicitationId, }) {
3283
+ const hookInput = {
3284
+ ...createBaseHookInput(permissionMode),
3285
+ hook_event_name: 'Elicitation',
3286
+ mcp_server_name: serverName,
3287
+ message,
3288
+ mode,
3289
+ url,
3290
+ elicitation_id: elicitationId,
3291
+ requested_schema: requestedSchema,
3292
+ };
3293
+ const results = await executeHooksOutsideREPL({
3294
+ hookInput,
3295
+ matchQuery: serverName,
3296
+ signal,
3297
+ timeoutMs,
3298
+ });
3299
+ let elicitationResponse;
3300
+ let blockingError;
3301
+ for (const result of results) {
3302
+ const parsed = parseElicitationHookOutput(result, 'Elicitation');
3303
+ if (parsed.blockingError) {
3304
+ blockingError = parsed.blockingError;
3305
+ }
3306
+ if (parsed.response) {
3307
+ elicitationResponse = parsed.response;
3308
+ }
3309
+ }
3310
+ return { elicitationResponse, blockingError };
3311
+ }
3312
+ export async function executeElicitationResultHooks({ serverName, action, content, permissionMode, signal, timeoutMs = TOOL_HOOK_EXECUTION_TIMEOUT_MS, mode, elicitationId, }) {
3313
+ const hookInput = {
3314
+ ...createBaseHookInput(permissionMode),
3315
+ hook_event_name: 'ElicitationResult',
3316
+ mcp_server_name: serverName,
3317
+ elicitation_id: elicitationId,
3318
+ mode,
3319
+ action,
3320
+ content,
3321
+ };
3322
+ const results = await executeHooksOutsideREPL({
3323
+ hookInput,
3324
+ matchQuery: serverName,
3325
+ signal,
3326
+ timeoutMs,
3327
+ });
3328
+ let elicitationResultResponse;
3329
+ let blockingError;
3330
+ for (const result of results) {
3331
+ const parsed = parseElicitationHookOutput(result, 'ElicitationResult');
3332
+ if (parsed.blockingError) {
3333
+ blockingError = parsed.blockingError;
3334
+ }
3335
+ if (parsed.response) {
3336
+ elicitationResultResponse = parsed.response;
3337
+ }
3338
+ }
3339
+ return { elicitationResultResponse, blockingError };
3340
+ }
3341
+ /**
3342
+ * Execute status line command if configured
3343
+ * @param statusLineInput The structured status input that will be converted to JSON
3344
+ * @param signal Optional AbortSignal to cancel hook execution
3345
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
3346
+ * @returns The status line text to display, or undefined if no command configured
3347
+ */
3348
+ export async function executeStatusLineCommand(statusLineInput, signal, timeoutMs = 5000, // Short timeout for status line
3349
+ logResult = false) {
3350
+ // Check if all hooks (including statusLine) are disabled by managed settings
3351
+ if (shouldDisableAllHooksIncludingManaged()) {
3352
+ return undefined;
3353
+ }
3354
+ // SECURITY: ALL hooks require workspace trust in interactive mode
3355
+ // This centralized check prevents RCE vulnerabilities for all current and future hooks
3356
+ if (shouldSkipHookDueToTrust()) {
3357
+ logForDebugging(`Skipping StatusLine command execution - workspace trust not accepted`);
3358
+ return undefined;
3359
+ }
3360
+ // When disableAllHooks is set in non-managed settings, only managed statusLine runs
3361
+ // (non-managed settings cannot disable managed commands, but non-managed commands are disabled)
3362
+ let statusLine;
3363
+ if (shouldAllowManagedHooksOnly()) {
3364
+ statusLine = getSettingsForSource('policySettings')?.statusLine;
3365
+ }
3366
+ else {
3367
+ statusLine = getSettings_DEPRECATED()?.statusLine;
3368
+ }
3369
+ if (!statusLine || statusLine.type !== 'command') {
3370
+ return undefined;
3371
+ }
3372
+ // Use provided signal or create a default one
3373
+ const abortSignal = signal || AbortSignal.timeout(timeoutMs);
3374
+ try {
3375
+ // Convert status input to JSON
3376
+ const jsonInput = jsonStringify(statusLineInput);
3377
+ const result = await execCommandHook(statusLine, 'StatusLine', 'statusLine', jsonInput, abortSignal, randomUUID());
3378
+ if (result.aborted) {
3379
+ return undefined;
3380
+ }
3381
+ // For successful hooks (exit code 0), use stdout
3382
+ if (result.status === 0) {
3383
+ // Trim and split output into lines, then join with newlines
3384
+ const output = result.stdout
3385
+ .trim()
3386
+ .split('\n')
3387
+ .flatMap(line => line.trim() || [])
3388
+ .join('\n');
3389
+ if (output) {
3390
+ if (logResult) {
3391
+ logForDebugging(`StatusLine [${statusLine.command}] completed with status ${result.status}`);
3392
+ }
3393
+ return output;
3394
+ }
3395
+ }
3396
+ else if (logResult) {
3397
+ logForDebugging(`StatusLine [${statusLine.command}] completed with status ${result.status}`, { level: 'warn' });
3398
+ }
3399
+ return undefined;
3400
+ }
3401
+ catch (error) {
3402
+ logForDebugging(`Status hook failed: ${error}`, { level: 'error' });
3403
+ return undefined;
3404
+ }
3405
+ }
3406
+ /**
3407
+ * Execute file suggestion command if configured
3408
+ * @param fileSuggestionInput The structured input that will be converted to JSON
3409
+ * @param signal Optional AbortSignal to cancel hook execution
3410
+ * @param timeoutMs Optional timeout in milliseconds for hook execution
3411
+ * @returns Array of file paths, or empty array if no command configured
3412
+ */
3413
+ export async function executeFileSuggestionCommand(fileSuggestionInput, signal, timeoutMs = 5000) {
3414
+ // Check if all hooks are disabled by managed settings
3415
+ if (shouldDisableAllHooksIncludingManaged()) {
3416
+ return [];
3417
+ }
3418
+ // SECURITY: ALL hooks require workspace trust in interactive mode
3419
+ // This centralized check prevents RCE vulnerabilities for all current and future hooks
3420
+ if (shouldSkipHookDueToTrust()) {
3421
+ logForDebugging(`Skipping FileSuggestion command execution - workspace trust not accepted`);
3422
+ return [];
3423
+ }
3424
+ // When disableAllHooks is set in non-managed settings, only managed fileSuggestion runs
3425
+ // (non-managed settings cannot disable managed commands, but non-managed commands are disabled)
3426
+ let fileSuggestion;
3427
+ if (shouldAllowManagedHooksOnly()) {
3428
+ fileSuggestion = getSettingsForSource('policySettings')?.fileSuggestion;
3429
+ }
3430
+ else {
3431
+ fileSuggestion = getSettings_DEPRECATED()?.fileSuggestion;
3432
+ }
3433
+ if (!fileSuggestion || fileSuggestion.type !== 'command') {
3434
+ return [];
3435
+ }
3436
+ // Use provided signal or create a default one
3437
+ const abortSignal = signal || AbortSignal.timeout(timeoutMs);
3438
+ try {
3439
+ const jsonInput = jsonStringify(fileSuggestionInput);
3440
+ const hook = { type: 'command', command: fileSuggestion.command };
3441
+ const result = await execCommandHook(hook, 'FileSuggestion', 'FileSuggestion', jsonInput, abortSignal, randomUUID());
3442
+ if (result.aborted || result.status !== 0) {
3443
+ return [];
3444
+ }
3445
+ return result.stdout
3446
+ .split('\n')
3447
+ .map(line => line.trim())
3448
+ .filter(Boolean);
3449
+ }
3450
+ catch (error) {
3451
+ logForDebugging(`File suggestion helper failed: ${error}`, {
3452
+ level: 'error',
3453
+ });
3454
+ return [];
3455
+ }
3456
+ }
3457
+ async function executeFunctionHook({ hook, messages, hookName, toolUseID, hookEvent, timeoutMs, signal, }) {
3458
+ const callbackTimeoutMs = hook.timeout ?? timeoutMs;
3459
+ const { signal: abortSignal, cleanup } = createCombinedAbortSignal(signal, {
3460
+ timeoutMs: callbackTimeoutMs,
3461
+ });
3462
+ try {
3463
+ // Check if already aborted
3464
+ if (abortSignal.aborted) {
3465
+ cleanup();
3466
+ return {
3467
+ outcome: 'cancelled',
3468
+ hook,
3469
+ };
3470
+ }
3471
+ // Execute callback with abort signal
3472
+ const passed = await new Promise((resolve, reject) => {
3473
+ // Handle abort signal
3474
+ const onAbort = () => reject(new Error('Function hook cancelled'));
3475
+ abortSignal.addEventListener('abort', onAbort);
3476
+ // Execute callback
3477
+ Promise.resolve(hook.callback(messages, abortSignal))
3478
+ .then(result => {
3479
+ abortSignal.removeEventListener('abort', onAbort);
3480
+ resolve(result);
3481
+ })
3482
+ .catch(error => {
3483
+ abortSignal.removeEventListener('abort', onAbort);
3484
+ reject(error);
3485
+ });
3486
+ });
3487
+ cleanup();
3488
+ if (passed) {
3489
+ return {
3490
+ outcome: 'success',
3491
+ hook,
3492
+ };
3493
+ }
3494
+ return {
3495
+ blockingError: {
3496
+ blockingError: hook.errorMessage,
3497
+ command: 'function',
3498
+ },
3499
+ outcome: 'blocking',
3500
+ hook,
3501
+ };
3502
+ }
3503
+ catch (error) {
3504
+ cleanup();
3505
+ // Handle cancellation
3506
+ if (error instanceof Error &&
3507
+ (error.message === 'Function hook cancelled' ||
3508
+ error.name === 'AbortError')) {
3509
+ return {
3510
+ outcome: 'cancelled',
3511
+ hook,
3512
+ };
3513
+ }
3514
+ // Log for monitoring
3515
+ logError(error);
3516
+ return {
3517
+ message: createAttachmentMessage({
3518
+ type: 'hook_error_during_execution',
3519
+ hookName,
3520
+ toolUseID,
3521
+ hookEvent,
3522
+ content: error instanceof Error
3523
+ ? error.message
3524
+ : 'Function hook execution error',
3525
+ }),
3526
+ outcome: 'non_blocking_error',
3527
+ hook,
3528
+ };
3529
+ }
3530
+ }
3531
+ async function executeHookCallback({ toolUseID, hook, hookEvent, hookInput, signal, hookIndex, toolUseContext, }) {
3532
+ // Create context for callbacks that need state access
3533
+ const context = toolUseContext
3534
+ ? {
3535
+ getAppState: toolUseContext.getAppState,
3536
+ updateAttributionState: toolUseContext.updateAttributionState,
3537
+ }
3538
+ : undefined;
3539
+ const json = await hook.callback(hookInput, toolUseID, signal, hookIndex, context);
3540
+ if (isAsyncHookJSONOutput(json)) {
3541
+ return {
3542
+ outcome: 'success',
3543
+ hook,
3544
+ };
3545
+ }
3546
+ const processed = processHookJSONOutput({
3547
+ json,
3548
+ command: 'callback',
3549
+ // TODO: If the hook came from a plugin, use the full path to the plugin for easier debugging
3550
+ hookName: `${hookEvent}:Callback`,
3551
+ toolUseID,
3552
+ hookEvent,
3553
+ expectedHookEvent: hookEvent,
3554
+ // Callbacks don't have stdout/stderr/exitCode
3555
+ stdout: undefined,
3556
+ stderr: undefined,
3557
+ exitCode: undefined,
3558
+ });
3559
+ return {
3560
+ ...processed,
3561
+ outcome: 'success',
3562
+ hook,
3563
+ };
3564
+ }
3565
+ /**
3566
+ * Check if WorktreeCreate hooks are configured (without executing them).
3567
+ *
3568
+ * Checks both settings-file hooks (getHooksConfigFromSnapshot) and registered
3569
+ * hooks (plugin hooks + SDK callback hooks via registerHookCallbacks).
3570
+ *
3571
+ * Must mirror the managedOnly filtering in getHooksConfig() — when
3572
+ * shouldAllowManagedHooksOnly() is true, plugin hooks (pluginRoot set) are
3573
+ * skipped at execution, so we must also skip them here. Otherwise this returns
3574
+ * true but executeWorktreeCreateHook() finds no matching hooks and throws,
3575
+ * blocking the git-worktree fallback.
3576
+ */
3577
+ export function hasWorktreeCreateHook() {
3578
+ const snapshotHooks = getHooksConfigFromSnapshot()?.['WorktreeCreate'];
3579
+ if (snapshotHooks && snapshotHooks.length > 0)
3580
+ return true;
3581
+ const registeredHooks = getRegisteredHooks()?.['WorktreeCreate'];
3582
+ if (!registeredHooks || registeredHooks.length === 0)
3583
+ return false;
3584
+ // Mirror getHooksConfig(): skip plugin hooks in managed-only mode
3585
+ const managedOnly = shouldAllowManagedHooksOnly();
3586
+ return registeredHooks.some(matcher => !(managedOnly && 'pluginRoot' in matcher));
3587
+ }
3588
+ /**
3589
+ * Execute WorktreeCreate hooks.
3590
+ * Returns the worktree path from hook stdout.
3591
+ * Throws if hooks fail or produce no output.
3592
+ * Callers should check hasWorktreeCreateHook() before calling this.
3593
+ */
3594
+ export async function executeWorktreeCreateHook(name) {
3595
+ const hookInput = {
3596
+ ...createBaseHookInput(undefined),
3597
+ hook_event_name: 'WorktreeCreate',
3598
+ name,
3599
+ };
3600
+ const results = await executeHooksOutsideREPL({
3601
+ hookInput,
3602
+ timeoutMs: TOOL_HOOK_EXECUTION_TIMEOUT_MS,
3603
+ });
3604
+ // Find the first successful result with non-empty output
3605
+ const successfulResult = results.find(r => r.succeeded && r.output.trim().length > 0);
3606
+ if (!successfulResult) {
3607
+ const failedOutputs = results
3608
+ .filter(r => !r.succeeded)
3609
+ .map(r => `${r.command}: ${r.output.trim() || 'no output'}`);
3610
+ throw new Error(`WorktreeCreate hook failed: ${failedOutputs.join('; ') || 'no successful output'}`);
3611
+ }
3612
+ const worktreePath = successfulResult.output.trim();
3613
+ return { worktreePath };
3614
+ }
3615
+ /**
3616
+ * Execute WorktreeRemove hooks if configured.
3617
+ * Returns true if hooks were configured and ran, false if no hooks are configured.
3618
+ *
3619
+ * Checks both settings-file hooks (getHooksConfigFromSnapshot) and registered
3620
+ * hooks (plugin hooks + SDK callback hooks via registerHookCallbacks).
3621
+ */
3622
+ export async function executeWorktreeRemoveHook(worktreePath) {
3623
+ const snapshotHooks = getHooksConfigFromSnapshot()?.['WorktreeRemove'];
3624
+ const registeredHooks = getRegisteredHooks()?.['WorktreeRemove'];
3625
+ const hasSnapshotHooks = snapshotHooks && snapshotHooks.length > 0;
3626
+ const hasRegisteredHooks = registeredHooks && registeredHooks.length > 0;
3627
+ if (!hasSnapshotHooks && !hasRegisteredHooks) {
3628
+ return false;
3629
+ }
3630
+ const hookInput = {
3631
+ ...createBaseHookInput(undefined),
3632
+ hook_event_name: 'WorktreeRemove',
3633
+ worktree_path: worktreePath,
3634
+ };
3635
+ const results = await executeHooksOutsideREPL({
3636
+ hookInput,
3637
+ timeoutMs: TOOL_HOOK_EXECUTION_TIMEOUT_MS,
3638
+ });
3639
+ if (results.length === 0) {
3640
+ return false;
3641
+ }
3642
+ for (const result of results) {
3643
+ if (!result.succeeded) {
3644
+ logForDebugging(`WorktreeRemove hook failed [${result.command}]: ${result.output.trim()}`, { level: 'error' });
3645
+ }
3646
+ }
3647
+ return true;
3648
+ }
3649
+ function getHookDefinitionsForTelemetry(matchedHooks) {
3650
+ return matchedHooks.map(({ hook }) => {
3651
+ if (hook.type === 'command') {
3652
+ return { type: 'command', command: hook.command };
3653
+ }
3654
+ else if (hook.type === 'prompt') {
3655
+ return { type: 'prompt', prompt: hook.prompt };
3656
+ }
3657
+ else if (hook.type === 'http') {
3658
+ return { type: 'http', command: hook.url };
3659
+ }
3660
+ else if (hook.type === 'function') {
3661
+ return { type: 'function', name: 'function' };
3662
+ }
3663
+ else if (hook.type === 'callback') {
3664
+ return { type: 'callback', name: 'callback' };
3665
+ }
3666
+ return { type: 'unknown' };
3667
+ });
3668
+ }