thaddeus 1.0.26 → 1.0.28

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 (2082) 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 +949 -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/ScrollKeybindingHandler.js +982 -0
  436. package/src/components/SearchBox.js +56 -0
  437. package/src/components/SentryErrorBoundary.js +16 -0
  438. package/src/components/SessionBackgroundHint.js +105 -0
  439. package/src/components/SessionPreview.js +200 -0
  440. package/src/components/Settings/Config.js +1626 -0
  441. package/src/components/Settings/Settings.js +131 -0
  442. package/src/components/Settings/Status.js +230 -0
  443. package/src/components/Settings/Usage.js +341 -0
  444. package/src/components/ShowInIDEPrompt.js +152 -0
  445. package/src/components/SkillImprovementSurvey.js +130 -0
  446. package/src/components/Spinner/FlashingChar.js +52 -0
  447. package/src/components/Spinner/GlimmerMessage.js +329 -0
  448. package/src/components/Spinner/ShimmerChar.js +23 -0
  449. package/src/components/Spinner/SpinnerAnimationRow.js +170 -0
  450. package/src/components/Spinner/SpinnerGlyph.js +70 -0
  451. package/src/components/Spinner/TeammateSpinnerLine.js +171 -0
  452. package/src/components/Spinner/TeammateSpinnerTree.js +269 -0
  453. package/src/components/Spinner/index.js +9 -0
  454. package/src/components/Spinner/teammateSelectHint.js +1 -0
  455. package/src/components/Spinner/useShimmerAnimation.js +22 -0
  456. package/src/components/Spinner/useStalledAnimation.js +63 -0
  457. package/src/components/Spinner/utils.js +78 -0
  458. package/src/components/Spinner.js +474 -0
  459. package/src/components/Stats.js +1000 -0
  460. package/src/components/StatusLine.js +286 -0
  461. package/src/components/StatusNotices.js +50 -0
  462. package/src/components/StructuredDiff/Fallback.js +336 -0
  463. package/src/components/StructuredDiff/colorDiff.js +37 -0
  464. package/src/components/StructuredDiff.js +153 -0
  465. package/src/components/StructuredDiffList.js +9 -0
  466. package/src/components/TagTabs.js +101 -0
  467. package/src/components/TaskListV2.js +333 -0
  468. package/src/components/TeammateViewHeader.js +88 -0
  469. package/src/components/TeleportError.js +191 -0
  470. package/src/components/TeleportProgress.js +131 -0
  471. package/src/components/TeleportRepoMismatchDialog.js +98 -0
  472. package/src/components/TeleportResumeWrapper.js +158 -0
  473. package/src/components/TeleportStash.js +82 -0
  474. package/src/components/TextInput.js +108 -0
  475. package/src/components/ThaddeusHint/PluginHintMenu.js +37 -0
  476. package/src/components/ThemePicker.js +331 -0
  477. package/src/components/ThinkingToggle.js +154 -0
  478. package/src/components/TokenWarning.js +171 -0
  479. package/src/components/ToolUseLoader.js +35 -0
  480. package/src/components/TrustDialog/TrustDialog.js +301 -0
  481. package/src/components/TrustDialog/utils.js +199 -0
  482. package/src/components/UndercoverAutoCallout.js +5 -0
  483. package/src/components/ValidationErrorsList.js +147 -0
  484. package/src/components/VimTextInput.js +136 -0
  485. package/src/components/VirtualMessageList.js +893 -0
  486. package/src/components/WorkflowMultiselectDialog.js +118 -0
  487. package/src/components/WorktreeExitDialog.js +220 -0
  488. package/src/components/agents/AgentDetail.js +227 -0
  489. package/src/components/agents/AgentEditor.js +147 -0
  490. package/src/components/agents/AgentNavigationFooter.js +22 -0
  491. package/src/components/agents/AgentsList.js +436 -0
  492. package/src/components/agents/AgentsMenu.js +849 -0
  493. package/src/components/agents/ColorPicker.js +110 -0
  494. package/src/components/agents/ModelSelector.js +63 -0
  495. package/src/components/agents/SnapshotUpdateDialog.js +14 -0
  496. package/src/components/agents/ToolSelector.js +557 -0
  497. package/src/components/agents/agentFileUtils.js +179 -0
  498. package/src/components/agents/generateAgent.js +161 -0
  499. package/src/components/agents/new-agent-creation/CreateAgentWizard.js +89 -0
  500. package/src/components/agents/new-agent-creation/wizard-steps/ColorStep.js +81 -0
  501. package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStep.js +387 -0
  502. package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.js +63 -0
  503. package/src/components/agents/new-agent-creation/wizard-steps/DescriptionStep.js +126 -0
  504. package/src/components/agents/new-agent-creation/wizard-steps/GenerateStep.js +118 -0
  505. package/src/components/agents/new-agent-creation/wizard-steps/LocationStep.js +80 -0
  506. package/src/components/agents/new-agent-creation/wizard-steps/MemoryStep.js +108 -0
  507. package/src/components/agents/new-agent-creation/wizard-steps/MethodStep.js +80 -0
  508. package/src/components/agents/new-agent-creation/wizard-steps/ModelStep.js +49 -0
  509. package/src/components/agents/new-agent-creation/wizard-steps/PromptStep.js +131 -0
  510. package/src/components/agents/new-agent-creation/wizard-steps/ToolsStep.js +52 -0
  511. package/src/components/agents/new-agent-creation/wizard-steps/TypeStep.js +100 -0
  512. package/src/components/agents/types.js +4 -0
  513. package/src/components/agents/utils.js +14 -0
  514. package/src/components/agents/validateAgent.js +79 -0
  515. package/src/components/design-system/Byline.js +72 -0
  516. package/src/components/design-system/Dialog.js +117 -0
  517. package/src/components/design-system/Divider.js +110 -0
  518. package/src/components/design-system/FuzzyPicker.js +191 -0
  519. package/src/components/design-system/KeyboardShortcutHint.js +68 -0
  520. package/src/components/design-system/ListItem.js +184 -0
  521. package/src/components/design-system/LoadingState.js +69 -0
  522. package/src/components/design-system/Pane.js +69 -0
  523. package/src/components/design-system/ProgressBar.js +63 -0
  524. package/src/components/design-system/Ratchet.js +71 -0
  525. package/src/components/design-system/StatusIcon.js +70 -0
  526. package/src/components/design-system/Tabs.js +269 -0
  527. package/src/components/design-system/ThemeProvider.js +137 -0
  528. package/src/components/design-system/ThemedBox.js +126 -0
  529. package/src/components/design-system/ThemedText.js +60 -0
  530. package/src/components/design-system/color.js +22 -0
  531. package/src/components/diff/DiffDetailView.js +285 -0
  532. package/src/components/diff/DiffDialog.js +387 -0
  533. package/src/components/diff/DiffFileList.js +292 -0
  534. package/src/components/grove/Grove.js +483 -0
  535. package/src/components/hooks/HooksConfigMenu.js +583 -0
  536. package/src/components/hooks/PromptDialog.js +82 -0
  537. package/src/components/hooks/SelectEventMode.js +118 -0
  538. package/src/components/hooks/SelectHookMode.js +101 -0
  539. package/src/components/hooks/SelectMatcherMode.js +131 -0
  540. package/src/components/hooks/ViewHookMode.js +204 -0
  541. package/src/components/mcp/CapabilitiesSection.js +56 -0
  542. package/src/components/mcp/ElicitationDialog.js +945 -0
  543. package/src/components/mcp/MCPAgentServerMenu.js +95 -0
  544. package/src/components/mcp/MCPListPanel.js +505 -0
  545. package/src/components/mcp/MCPReconnect.js +168 -0
  546. package/src/components/mcp/MCPRemoteServerMenu.js +460 -0
  547. package/src/components/mcp/MCPSettings.js +414 -0
  548. package/src/components/mcp/MCPStdioServerMenu.js +95 -0
  549. package/src/components/mcp/MCPToolDetailView.js +219 -0
  550. package/src/components/mcp/MCPToolListView.js +137 -0
  551. package/src/components/mcp/McpParsingWarnings.js +212 -0
  552. package/src/components/mcp/index.js +8 -0
  553. package/src/components/mcp/utils/reconnectHelpers.js +35 -0
  554. package/src/components/memory/MemoryFileSelector.js +454 -0
  555. package/src/components/memory/MemoryUpdateNotification.js +43 -0
  556. package/src/components/messageActions.js +418 -0
  557. package/src/components/messages/AdvisorMessage.js +152 -0
  558. package/src/components/messages/AssistantRedactedThinkingMessage.js +28 -0
  559. package/src/components/messages/AssistantTextMessage.js +287 -0
  560. package/src/components/messages/AssistantThinkingMessage.js +70 -0
  561. package/src/components/messages/AssistantToolUseMessage.js +324 -0
  562. package/src/components/messages/AttachmentMessage.js +418 -0
  563. package/src/components/messages/CollapsedReadSearchContent.js +363 -0
  564. package/src/components/messages/CompactBoundaryMessage.js +19 -0
  565. package/src/components/messages/GroupedToolUseContent.js +37 -0
  566. package/src/components/messages/HighlightedThinkingText.js +165 -0
  567. package/src/components/messages/HookProgressMessage.js +111 -0
  568. package/src/components/messages/PlanApprovalMessage.js +213 -0
  569. package/src/components/messages/RateLimitMessage.js +149 -0
  570. package/src/components/messages/ShutdownMessage.js +124 -0
  571. package/src/components/messages/SnipBoundaryMessage.js +7 -0
  572. package/src/components/messages/SystemAPIErrorMessage.js +136 -0
  573. package/src/components/messages/SystemTextMessage.js +842 -0
  574. package/src/components/messages/TaskAssignmentMessage.js +72 -0
  575. package/src/components/messages/UserAgentNotificationMessage.js +78 -0
  576. package/src/components/messages/UserBashInputMessage.js +52 -0
  577. package/src/components/messages/UserBashOutputMessage.js +55 -0
  578. package/src/components/messages/UserChannelMessage.js +130 -0
  579. package/src/components/messages/UserCommandMessage.js +107 -0
  580. package/src/components/messages/UserCrossSessionMessage.js +11 -0
  581. package/src/components/messages/UserForkBoilerplateMessage.js +11 -0
  582. package/src/components/messages/UserGitHubWebhookMessage.js +12 -0
  583. package/src/components/messages/UserImageMessage.js +54 -0
  584. package/src/components/messages/UserLocalCommandOutputMessage.js +170 -0
  585. package/src/components/messages/UserMemoryInputMessage.js +73 -0
  586. package/src/components/messages/UserPlanMessage.js +38 -0
  587. package/src/components/messages/UserPromptMessage.js +63 -0
  588. package/src/components/messages/UserResourceUpdateMessage.js +102 -0
  589. package/src/components/messages/UserTeammateMessage.js +156 -0
  590. package/src/components/messages/UserTextMessage.js +270 -0
  591. package/src/components/messages/UserToolResultMessage/RejectedPlanMessage.js +28 -0
  592. package/src/components/messages/UserToolResultMessage/RejectedToolUseMessage.js +17 -0
  593. package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.js +17 -0
  594. package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.js +92 -0
  595. package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.js +74 -0
  596. package/src/components/messages/UserToolResultMessage/UserToolResultMessage.js +84 -0
  597. package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +58 -0
  598. package/src/components/messages/UserToolResultMessage/utils.js +43 -0
  599. package/src/components/messages/nullRenderingAttachments.js +58 -0
  600. package/src/components/messages/teamMemCollapsed.js +142 -0
  601. package/src/components/messages/teamMemSaved.js +16 -0
  602. package/src/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.js +659 -0
  603. package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.js +219 -0
  604. package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.js +227 -0
  605. package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.js +175 -0
  606. package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionView.js +444 -0
  607. package/src/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.js +137 -0
  608. package/src/components/permissions/AskUserQuestionPermissionRequest/use-multiple-choice-state.js +100 -0
  609. package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.js +404 -0
  610. package/src/components/permissions/BashPermissionRequest/bashToolUseOptions.js +110 -0
  611. package/src/components/permissions/ComputerUseApproval/ComputerUseApproval.js +449 -0
  612. package/src/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.js +126 -0
  613. package/src/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.js +653 -0
  614. package/src/components/permissions/FallbackPermissionRequest.js +349 -0
  615. package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +185 -0
  616. package/src/components/permissions/FilePermissionDialog/FilePermissionDialog.js +108 -0
  617. package/src/components/permissions/FilePermissionDialog/ideDiffConfig.js +13 -0
  618. package/src/components/permissions/FilePermissionDialog/permissionOptions.js +137 -0
  619. package/src/components/permissions/FilePermissionDialog/useFilePermissionDialog.js +131 -0
  620. package/src/components/permissions/FilePermissionDialog/usePermissionHandler.js +86 -0
  621. package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +164 -0
  622. package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +79 -0
  623. package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +113 -0
  624. package/src/components/permissions/MonitorPermissionRequest/MonitorPermissionRequest.js +7 -0
  625. package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.js +164 -0
  626. package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.js +218 -0
  627. package/src/components/permissions/PermissionDecisionDebugInfo.js +467 -0
  628. package/src/components/permissions/PermissionDialog.js +55 -0
  629. package/src/components/permissions/PermissionExplanation.js +269 -0
  630. package/src/components/permissions/PermissionPrompt.js +316 -0
  631. package/src/components/permissions/PermissionRequest.js +159 -0
  632. package/src/components/permissions/PermissionRequestTitle.js +58 -0
  633. package/src/components/permissions/PermissionRuleExplanation.js +110 -0
  634. package/src/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.js +178 -0
  635. package/src/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.js +73 -0
  636. package/src/components/permissions/ReviewArtifactPermissionRequest/ReviewArtifactPermissionRequest.js +7 -0
  637. package/src/components/permissions/SandboxPermissionRequest.js +162 -0
  638. package/src/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.js +228 -0
  639. package/src/components/permissions/SkillPermissionRequest/SkillPermissionRequest.js +385 -0
  640. package/src/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.js +259 -0
  641. package/src/components/permissions/WorkerBadge.js +44 -0
  642. package/src/components/permissions/WorkerPendingPermission.js +107 -0
  643. package/src/components/permissions/hooks.js +163 -0
  644. package/src/components/permissions/rules/AddPermissionRules.js +171 -0
  645. package/src/components/permissions/rules/AddWorkspaceDirectory.js +335 -0
  646. package/src/components/permissions/rules/PermissionRuleDescription.js +78 -0
  647. package/src/components/permissions/rules/PermissionRuleInput.js +136 -0
  648. package/src/components/permissions/rules/PermissionRuleList.js +1190 -0
  649. package/src/components/permissions/rules/RecentDenialsTab.js +205 -0
  650. package/src/components/permissions/rules/RemoveWorkspaceDirectory.js +103 -0
  651. package/src/components/permissions/rules/WorkspaceTab.js +133 -0
  652. package/src/components/permissions/shellPermissionHelpers.js +112 -0
  653. package/src/components/permissions/useShellPermissionFeedback.js +108 -0
  654. package/src/components/permissions/utils.js +14 -0
  655. package/src/components/sandbox/SandboxConfigTab.js +48 -0
  656. package/src/components/sandbox/SandboxDependenciesTab.js +123 -0
  657. package/src/components/sandbox/SandboxDoctorSection.js +47 -0
  658. package/src/components/sandbox/SandboxOverridesTab.js +193 -0
  659. package/src/components/sandbox/SandboxSettings.js +297 -0
  660. package/src/components/shell/ExpandShellOutputContext.js +33 -0
  661. package/src/components/shell/OutputLine.js +110 -0
  662. package/src/components/shell/ShellProgressMessage.js +144 -0
  663. package/src/components/shell/ShellTimeDisplay.js +72 -0
  664. package/src/components/skills/SkillsMenu.js +239 -0
  665. package/src/components/tasks/AsyncAgentDetailDialog.js +235 -0
  666. package/src/components/tasks/BackgroundTask.js +364 -0
  667. package/src/components/tasks/BackgroundTaskStatus.js +419 -0
  668. package/src/components/tasks/BackgroundTasksDialog.js +494 -0
  669. package/src/components/tasks/DreamDetailDialog.js +251 -0
  670. package/src/components/tasks/InProcessTeammateDetailDialog.js +275 -0
  671. package/src/components/tasks/MonitorMcpDetailDialog.js +7 -0
  672. package/src/components/tasks/RemoteSessionDetailDialog.js +868 -0
  673. package/src/components/tasks/RemoteSessionProgress.js +249 -0
  674. package/src/components/tasks/ShellDetailDialog.js +403 -0
  675. package/src/components/tasks/ShellProgress.js +77 -0
  676. package/src/components/tasks/WorkflowDetailDialog.js +7 -0
  677. package/src/components/tasks/renderToolActivity.js +29 -0
  678. package/src/components/tasks/taskStatusUtils.js +94 -0
  679. package/src/components/teams/TeamStatus.js +77 -0
  680. package/src/components/teams/TeamsDialog.js +673 -0
  681. package/src/components/ui/OrderedList.js +66 -0
  682. package/src/components/ui/OrderedListItem.js +41 -0
  683. package/src/components/ui/TreeSelect.js +300 -0
  684. package/src/components/wizard/WizardDialogLayout.js +48 -0
  685. package/src/components/wizard/WizardNavigationFooter.js +11 -0
  686. package/src/components/wizard/WizardProvider.js +217 -0
  687. package/src/components/wizard/index.js +4 -0
  688. package/src/components/wizard/useWizard.js +9 -0
  689. package/src/constants/apiLimits.js +81 -0
  690. package/src/constants/betas.js +45 -0
  691. package/src/constants/common.js +29 -0
  692. package/src/constants/cyberRiskInstruction.js +23 -0
  693. package/src/constants/errorIds.js +14 -0
  694. package/src/constants/figures.js +38 -0
  695. package/src/constants/files.js +150 -0
  696. package/src/constants/github-app.js +139 -0
  697. package/src/constants/identity.js +112 -0
  698. package/src/constants/keys.js +10 -0
  699. package/src/constants/messages.js +1 -0
  700. package/src/constants/oauth.js +175 -0
  701. package/src/constants/outputStyles.js +162 -0
  702. package/src/constants/product.js +54 -0
  703. package/src/constants/prompts.js +994 -0
  704. package/src/constants/spinnerVerbs.js +98 -0
  705. package/src/constants/system.js +77 -0
  706. package/src/constants/systemPromptSections.js +39 -0
  707. package/src/constants/toolLimits.js +50 -0
  708. package/src/constants/tools.js +103 -0
  709. package/src/constants/turnCompletionVerbs.js +12 -0
  710. package/src/constants/xml.js +73 -0
  711. package/src/context/QueuedMessageContext.js +51 -0
  712. package/src/context/fpsMetrics.js +22 -0
  713. package/src/context/mailbox.js +35 -0
  714. package/src/context/modalContext.js +34 -0
  715. package/src/context/notifications.js +199 -0
  716. package/src/context/overlayContext.js +149 -0
  717. package/src/context/promptOverlayContext.js +118 -0
  718. package/src/context/stats.js +207 -0
  719. package/src/context/voice.js +74 -0
  720. package/src/context.js +146 -0
  721. package/src/coordinator/coordinatorMode.js +345 -0
  722. package/src/coordinator/workerAgent.js +24 -0
  723. package/src/cost-tracker.js +208 -0
  724. package/src/costHook.js +17 -0
  725. package/src/daemon/main.js +19 -0
  726. package/src/dialogLaunchers.js +77 -0
  727. package/src/entrypoints/agentSdkTypes.js +202 -0
  728. package/src/entrypoints/cli.js +226 -0
  729. package/src/entrypoints/init.js +265 -0
  730. package/src/entrypoints/mcp.js +141 -0
  731. package/src/entrypoints/sandboxTypes.js +112 -0
  732. package/src/entrypoints/sdk/controlSchemas.js +452 -0
  733. package/src/entrypoints/sdk/controlTypes.js +1 -0
  734. package/src/entrypoints/sdk/coreSchemas.js +1331 -0
  735. package/src/entrypoints/sdk/coreTypes.generated.js +3 -0
  736. package/src/entrypoints/sdk/coreTypes.js +49 -0
  737. package/src/entrypoints/sdk/runtimeTypes.js +1 -0
  738. package/src/entrypoints/sdk/sdkUtilityTypes.js +1 -0
  739. package/src/entrypoints/sdk/settingsTypes.generated.js +1 -0
  740. package/src/entrypoints/sdk/toolTypes.js +1 -0
  741. package/src/environment-runner/main.js +8 -0
  742. package/src/history.js +386 -0
  743. package/src/hooks/fileSuggestions.js +635 -0
  744. package/src/hooks/notifs/useAntOrgWarningNotification.js +5 -0
  745. package/src/hooks/notifs/useAutoModeUnavailableNotification.js +47 -0
  746. package/src/hooks/notifs/useCanSwitchToExistingSubscription.js +58 -0
  747. package/src/hooks/notifs/useDeprecationWarningNotification.js +43 -0
  748. package/src/hooks/notifs/useFastModeNotification.js +164 -0
  749. package/src/hooks/notifs/useIDEStatusIndicator.js +174 -0
  750. package/src/hooks/notifs/useInstallMessages.js +27 -0
  751. package/src/hooks/notifs/useLspInitializationNotification.js +144 -0
  752. package/src/hooks/notifs/useMcpConnectivityStatus.js +81 -0
  753. package/src/hooks/notifs/useModelMigrationNotifications.js +53 -0
  754. package/src/hooks/notifs/useNpmDeprecationNotification.js +25 -0
  755. package/src/hooks/notifs/usePluginAutoupdateNotification.js +83 -0
  756. package/src/hooks/notifs/usePluginInstallationStatus.js +128 -0
  757. package/src/hooks/notifs/useRateLimitWarningNotification.js +119 -0
  758. package/src/hooks/notifs/useSettingsErrors.js +64 -0
  759. package/src/hooks/notifs/useStartupNotification.js +33 -0
  760. package/src/hooks/notifs/useTeammateShutdownNotification.js +64 -0
  761. package/src/hooks/renderPlaceholder.js +26 -0
  762. package/src/hooks/toolPermission/PermissionContext.js +211 -0
  763. package/src/hooks/toolPermission/handlers/coordinatorHandler.js +44 -0
  764. package/src/hooks/toolPermission/handlers/interactiveHandler.js +397 -0
  765. package/src/hooks/toolPermission/handlers/swarmWorkerHandler.js +108 -0
  766. package/src/hooks/toolPermission/permissionLogging.js +145 -0
  767. package/src/hooks/unifiedSuggestions.js +130 -0
  768. package/src/hooks/useAfterFirstRender.js +12 -0
  769. package/src/hooks/useApiKeyVerification.js +63 -0
  770. package/src/hooks/useArrowKeyHistory.js +203 -0
  771. package/src/hooks/useAssistantHistory.js +193 -0
  772. package/src/hooks/useAwaySummary.js +105 -0
  773. package/src/hooks/useBackgroundTaskNavigation.js +204 -0
  774. package/src/hooks/useBlink.js +28 -0
  775. package/src/hooks/useCanUseTool.js +193 -0
  776. package/src/hooks/useCancelRequest.js +195 -0
  777. package/src/hooks/useChromeExtensionNotification.js +50 -0
  778. package/src/hooks/useClipboardImageHint.js +59 -0
  779. package/src/hooks/useCommandKeybindings.js +87 -0
  780. package/src/hooks/useCommandQueue.js +10 -0
  781. package/src/hooks/useCopyOnSelect.js +88 -0
  782. package/src/hooks/useDeferredHookMessages.js +43 -0
  783. package/src/hooks/useDiffData.js +69 -0
  784. package/src/hooks/useDiffInIDE.js +252 -0
  785. package/src/hooks/useDirectConnect.js +150 -0
  786. package/src/hooks/useDoublePress.js +44 -0
  787. package/src/hooks/useDynamicConfig.js +17 -0
  788. package/src/hooks/useElapsedTime.js +25 -0
  789. package/src/hooks/useExitOnCtrlCD.js +57 -0
  790. package/src/hooks/useExitOnCtrlCDWithKeybindings.js +17 -0
  791. package/src/hooks/useFileHistorySnapshotInit.js +14 -0
  792. package/src/hooks/useGlobalKeybindings.js +213 -0
  793. package/src/hooks/useHistorySearch.js +241 -0
  794. package/src/hooks/useIDEIntegration.js +56 -0
  795. package/src/hooks/useIdeAtMentioned.js +51 -0
  796. package/src/hooks/useIdeConnectionStatus.js +21 -0
  797. package/src/hooks/useIdeLogging.js +29 -0
  798. package/src/hooks/useIdeSelection.js +106 -0
  799. package/src/hooks/useInboxPoller.js +709 -0
  800. package/src/hooks/useInputBuffer.js +73 -0
  801. package/src/hooks/useIssueFlagBanner.js +115 -0
  802. package/src/hooks/useLogMessages.js +98 -0
  803. package/src/hooks/useLspPluginRecommendation.js +176 -0
  804. package/src/hooks/useMailboxBridge.js +15 -0
  805. package/src/hooks/useMainLoopModel.js +25 -0
  806. package/src/hooks/useManagePlugins.js +261 -0
  807. package/src/hooks/useMemoryUsage.js +28 -0
  808. package/src/hooks/useMergedClients.js +11 -0
  809. package/src/hooks/useMergedCommands.js +10 -0
  810. package/src/hooks/useMergedTools.js +32 -0
  811. package/src/hooks/useMinDisplayTime.js +26 -0
  812. package/src/hooks/useNotifyAfterTimeout.js +51 -0
  813. package/src/hooks/useOfficialMarketplaceNotification.js +47 -0
  814. package/src/hooks/usePasteHandler.js +195 -0
  815. package/src/hooks/usePluginRecommendationBase.js +101 -0
  816. package/src/hooks/usePrStatus.js +91 -0
  817. package/src/hooks/usePromptSuggestion.js +128 -0
  818. package/src/hooks/usePromptsFromClaudeInChrome.js +66 -0
  819. package/src/hooks/useQueueProcessor.js +46 -0
  820. package/src/hooks/useRemoteSession.js +431 -0
  821. package/src/hooks/useReplBridge.js +715 -0
  822. package/src/hooks/useSSHSession.js +167 -0
  823. package/src/hooks/useScheduledTasks.js +104 -0
  824. package/src/hooks/useSearchInput.js +302 -0
  825. package/src/hooks/useSessionBackgrounding.js +132 -0
  826. package/src/hooks/useSettings.js +10 -0
  827. package/src/hooks/useSettingsChange.js +13 -0
  828. package/src/hooks/useSkillImprovementSurvey.js +69 -0
  829. package/src/hooks/useSkillsChange.js +51 -0
  830. package/src/hooks/useSwarmInitialization.js +67 -0
  831. package/src/hooks/useSwarmPermissionPoller.js +215 -0
  832. package/src/hooks/useTaskListWatcher.js +157 -0
  833. package/src/hooks/useTasksV2.js +220 -0
  834. package/src/hooks/useTeammateViewAutoExit.js +55 -0
  835. package/src/hooks/useTeleportResume.js +81 -0
  836. package/src/hooks/useTerminalSize.js +9 -0
  837. package/src/hooks/useTextInput.js +397 -0
  838. package/src/hooks/useThaddeusHintRecommendation.js +117 -0
  839. package/src/hooks/useTimeout.js +10 -0
  840. package/src/hooks/useTurnDiffs.js +160 -0
  841. package/src/hooks/useTypeahead.js +1250 -0
  842. package/src/hooks/useUpdateNotification.js +21 -0
  843. package/src/hooks/useVimInput.js +232 -0
  844. package/src/hooks/useVirtualScroll.js +627 -0
  845. package/src/hooks/useVoice.js +952 -0
  846. package/src/hooks/useVoiceEnabled.js +21 -0
  847. package/src/hooks/useVoiceIntegration.js +629 -0
  848. package/src/infrastructure/audit.js +210 -0
  849. package/src/infrastructure/guardrails.js +513 -0
  850. package/src/infrastructure/index.js +11 -0
  851. package/src/ink/Ansi.js +269 -0
  852. package/src/ink/bidi.js +117 -0
  853. package/src/ink/clearTerminal.js +58 -0
  854. package/src/ink/colorize.js +198 -0
  855. package/src/ink/components/AlternateScreen.js +74 -0
  856. package/src/ink/components/App.js +562 -0
  857. package/src/ink/components/AppContext.js +11 -0
  858. package/src/ink/components/Box.js +155 -0
  859. package/src/ink/components/Button.js +166 -0
  860. package/src/ink/components/ClockContext.js +108 -0
  861. package/src/ink/components/CursorDeclarationContext.js +3 -0
  862. package/src/ink/components/ErrorOverview.js +50 -0
  863. package/src/ink/components/Link.js +34 -0
  864. package/src/ink/components/Newline.js +30 -0
  865. package/src/ink/components/NoSelect.js +57 -0
  866. package/src/ink/components/RawAnsi.js +46 -0
  867. package/src/ink/components/ScrollBox.js +171 -0
  868. package/src/ink/components/Spacer.js +20 -0
  869. package/src/ink/components/StdinContext.js +16 -0
  870. package/src/ink/components/TerminalFocusContext.js +45 -0
  871. package/src/ink/components/TerminalSizeContext.js +3 -0
  872. package/src/ink/components/Text.js +195 -0
  873. package/src/ink/constants.js +2 -0
  874. package/src/ink/dom.js +298 -0
  875. package/src/ink/events/click-event.js +36 -0
  876. package/src/ink/events/dispatcher.js +172 -0
  877. package/src/ink/events/emitter.js +31 -0
  878. package/src/ink/events/event-handlers.js +30 -0
  879. package/src/ink/events/event.js +9 -0
  880. package/src/ink/events/focus-event.js +16 -0
  881. package/src/ink/events/input-event.js +161 -0
  882. package/src/ink/events/keyboard-event.js +46 -0
  883. package/src/ink/events/terminal-event.js +78 -0
  884. package/src/ink/events/terminal-focus-event.js +15 -0
  885. package/src/ink/focus.js +158 -0
  886. package/src/ink/frame.js +30 -0
  887. package/src/ink/get-max-width.js +23 -0
  888. package/src/ink/hit-test.js +113 -0
  889. package/src/ink/hooks/use-animation-frame.js +48 -0
  890. package/src/ink/hooks/use-app.js +7 -0
  891. package/src/ink/hooks/use-declared-cursor.js +60 -0
  892. package/src/ink/hooks/use-input.js +70 -0
  893. package/src/ink/hooks/use-interval.js +54 -0
  894. package/src/ink/hooks/use-search-highlight.js +32 -0
  895. package/src/ink/hooks/use-selection.js +60 -0
  896. package/src/ink/hooks/use-stdin.js +7 -0
  897. package/src/ink/hooks/use-tab-status.js +57 -0
  898. package/src/ink/hooks/use-terminal-focus.js +15 -0
  899. package/src/ink/hooks/use-terminal-title.js +29 -0
  900. package/src/ink/hooks/use-terminal-viewport.js +77 -0
  901. package/src/ink/ink.js +1645 -0
  902. package/src/ink/instances.js +7 -0
  903. package/src/ink/layout/engine.js +4 -0
  904. package/src/ink/layout/geometry.js +61 -0
  905. package/src/ink/layout/node.js +62 -0
  906. package/src/ink/layout/yoga.js +237 -0
  907. package/src/ink/line-width-cache.js +19 -0
  908. package/src/ink/log-update.js +583 -0
  909. package/src/ink/measure-element.js +8 -0
  910. package/src/ink/measure-text.js +35 -0
  911. package/src/ink/node-cache.js +30 -0
  912. package/src/ink/optimizer.js +81 -0
  913. package/src/ink/output.js +556 -0
  914. package/src/ink/parse-keypress.js +695 -0
  915. package/src/ink/reconciler.js +384 -0
  916. package/src/ink/render-border.js +134 -0
  917. package/src/ink/render-node-to-output.js +1216 -0
  918. package/src/ink/render-to-screen.js +171 -0
  919. package/src/ink/renderer.js +129 -0
  920. package/src/ink/root.js +80 -0
  921. package/src/ink/screen.js +1132 -0
  922. package/src/ink/searchHighlight.js +78 -0
  923. package/src/ink/selection.js +792 -0
  924. package/src/ink/squash-text-nodes.js +56 -0
  925. package/src/ink/stringWidth.js +200 -0
  926. package/src/ink/styles.js +299 -0
  927. package/src/ink/supports-hyperlinks.js +40 -0
  928. package/src/ink/tabstops.js +39 -0
  929. package/src/ink/terminal-focus-state.js +35 -0
  930. package/src/ink/terminal-querier.js +173 -0
  931. package/src/ink/terminal.js +208 -0
  932. package/src/ink/termio/ansi.js +70 -0
  933. package/src/ink/termio/csi.js +260 -0
  934. package/src/ink/termio/dec.js +53 -0
  935. package/src/ink/termio/esc.js +55 -0
  936. package/src/ink/termio/osc.js +432 -0
  937. package/src/ink/termio/parser.js +356 -0
  938. package/src/ink/termio/sgr.js +292 -0
  939. package/src/ink/termio/tokenize.js +264 -0
  940. package/src/ink/termio/types.js +55 -0
  941. package/src/ink/termio.js +24 -0
  942. package/src/ink/useTerminalNotification.js +57 -0
  943. package/src/ink/warn.js +10 -0
  944. package/src/ink/widest-line.js +14 -0
  945. package/src/ink/wrap-text.js +54 -0
  946. package/src/ink/wrapAnsi.js +6 -0
  947. package/src/ink.js +50 -0
  948. package/src/integrations/credentialStore.js +176 -0
  949. package/src/integrations/index.js +5 -0
  950. package/src/integrations/integrationManager.js +180 -0
  951. package/src/integrations/providers/BaseProvider.js +180 -0
  952. package/src/integrations/providers/GitHubProvider.js +217 -0
  953. package/src/integrations/providers/GmailProvider.js +204 -0
  954. package/src/integrations/providers/GoogleCalendarProvider.js +113 -0
  955. package/src/integrations/providers/HubSpotProvider.js +159 -0
  956. package/src/integrations/providers/JiraProvider.js +216 -0
  957. package/src/integrations/providers/NotionProvider.js +221 -0
  958. package/src/integrations/providers/QuickBooksProvider.js +176 -0
  959. package/src/integrations/providers/SlackProvider.js +174 -0
  960. package/src/integrations/providers/StripeProvider.js +206 -0
  961. package/src/integrations/providers/TwilioProvider.js +239 -0
  962. package/src/integrations/providers/_template.js +112 -0
  963. package/src/integrations/types.js +7 -0
  964. package/src/interactiveHelpers.js +308 -0
  965. package/src/jobs/classifier.js +6 -0
  966. package/src/keybindings/KeybindingContext.js +184 -0
  967. package/src/keybindings/KeybindingProviderSetup.js +259 -0
  968. package/src/keybindings/defaultBindings.js +333 -0
  969. package/src/keybindings/loadUserBindings.js +393 -0
  970. package/src/keybindings/match.js +111 -0
  971. package/src/keybindings/parser.js +184 -0
  972. package/src/keybindings/reservedShortcuts.js +109 -0
  973. package/src/keybindings/resolver.js +182 -0
  974. package/src/keybindings/schema.js +205 -0
  975. package/src/keybindings/shortcutFormat.js +48 -0
  976. package/src/keybindings/template.js +40 -0
  977. package/src/keybindings/useKeybinding.js +161 -0
  978. package/src/keybindings/useShortcutDisplay.js +43 -0
  979. package/src/keybindings/validate.js +395 -0
  980. package/src/main.js +4128 -0
  981. package/src/memdir/findRelevantMemories.js +99 -0
  982. package/src/memdir/memdir.js +406 -0
  983. package/src/memdir/memoryAge.js +52 -0
  984. package/src/memdir/memoryScan.js +65 -0
  985. package/src/memdir/memoryShapeTelemetry.js +8 -0
  986. package/src/memdir/memoryTypes.js +260 -0
  987. package/src/memdir/paths.js +235 -0
  988. package/src/memdir/teamMemPaths.js +261 -0
  989. package/src/memdir/teamMemPrompts.js +82 -0
  990. package/src/migrations/migrateAutoUpdatesToSettings.js +47 -0
  991. package/src/migrations/migrateBypassPermissionsAcceptedToSettings.js +32 -0
  992. package/src/migrations/migrateEnableAllProjectMcpServersToSettings.js +83 -0
  993. package/src/migrations/migrateFennecToOpus.js +39 -0
  994. package/src/migrations/migrateLegacyOpusToCurrent.js +44 -0
  995. package/src/migrations/migrateOpusToOpus1m.js +31 -0
  996. package/src/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.js +23 -0
  997. package/src/migrations/migrateSonnet1mToSonnet45.js +38 -0
  998. package/src/migrations/migrateSonnet45ToSonnet46.js +48 -0
  999. package/src/migrations/resetAutoModeOptInForDefaultOffer.js +47 -0
  1000. package/src/migrations/resetProToOpusDefault.js +46 -0
  1001. package/src/moreright/useMoreRight.js +13 -0
  1002. package/src/native-ts/color-diff/index.js +819 -0
  1003. package/src/native-ts/file-index/index.js +328 -0
  1004. package/src/native-ts/yoga-layout/enums.js +101 -0
  1005. package/src/native-ts/yoga-layout/index.js +2113 -0
  1006. package/src/outputStyles/loadOutputStylesDir.js +71 -0
  1007. package/src/plugins/builtinPlugins.js +132 -0
  1008. package/src/plugins/bundled/index.js +22 -0
  1009. package/src/proactive/index.js +138 -0
  1010. package/src/proactive/useProactive.js +82 -0
  1011. package/src/projectOnboardingState.js +61 -0
  1012. package/src/query/config.js +17 -0
  1013. package/src/query/deps.js +12 -0
  1014. package/src/query/stopHooks.js +332 -0
  1015. package/src/query/tokenBudget.js +49 -0
  1016. package/src/query.js +1264 -0
  1017. package/src/remote/RemoteSessionManager.js +172 -0
  1018. package/src/remote/SessionsWebSocket.js +308 -0
  1019. package/src/remote/remotePermissionBridge.js +70 -0
  1020. package/src/remote/sdkMessageAdapter.js +227 -0
  1021. package/src/replLauncher.js +7 -0
  1022. package/src/schemas/hooks.js +174 -0
  1023. package/src/screens/Doctor.js +580 -0
  1024. package/src/screens/REPL.js +4500 -0
  1025. package/src/screens/ResumeConversation.js +339 -0
  1026. package/src/self-hosted-runner/main.js +8 -0
  1027. package/src/server/backends/dangerousBackend.js +8 -0
  1028. package/src/server/connectHeadless.js +6 -0
  1029. package/src/server/createDirectConnectSession.js +62 -0
  1030. package/src/server/directConnectManager.js +153 -0
  1031. package/src/server/lockfile.js +11 -0
  1032. package/src/server/parseConnectUrl.js +20 -0
  1033. package/src/server/server.js +12 -0
  1034. package/src/server/serverBanner.js +9 -0
  1035. package/src/server/serverLog.js +11 -0
  1036. package/src/server/sessionManager.js +19 -0
  1037. package/src/server/types.js +7 -0
  1038. package/src/services/AgentSummary/agentSummary.js +147 -0
  1039. package/src/services/MagicDocs/magicDocs.js +193 -0
  1040. package/src/services/MagicDocs/prompts.js +110 -0
  1041. package/src/services/PromptSuggestion/promptSuggestion.js +402 -0
  1042. package/src/services/PromptSuggestion/speculation.js +643 -0
  1043. package/src/services/SessionMemory/prompts.js +254 -0
  1044. package/src/services/SessionMemory/sessionMemory.js +358 -0
  1045. package/src/services/SessionMemory/sessionMemoryUtils.js +157 -0
  1046. package/src/services/analytics/config.js +27 -0
  1047. package/src/services/analytics/datadog.js +26 -0
  1048. package/src/services/analytics/firstPartyEventLogger.js +65 -0
  1049. package/src/services/analytics/firstPartyEventLoggingExporter.js +595 -0
  1050. package/src/services/analytics/growthbook.js +103 -0
  1051. package/src/services/analytics/index.js +91 -0
  1052. package/src/services/analytics/metadata.js +696 -0
  1053. package/src/services/analytics/sink.js +19 -0
  1054. package/src/services/analytics/sinkKillswitch.js +19 -0
  1055. package/src/services/api/adminRequests.js +57 -0
  1056. package/src/services/api/bootstrap.js +118 -0
  1057. package/src/services/api/claude.js +2466 -0
  1058. package/src/services/api/client.js +335 -0
  1059. package/src/services/api/dumpPrompts.js +174 -0
  1060. package/src/services/api/emptyUsage.js +20 -0
  1061. package/src/services/api/errorUtils.js +203 -0
  1062. package/src/services/api/errors.js +926 -0
  1063. package/src/services/api/filesApi.js +523 -0
  1064. package/src/services/api/firstTokenDate.js +49 -0
  1065. package/src/services/api/grove.js +44 -0
  1066. package/src/services/api/logging.js +484 -0
  1067. package/src/services/api/metricsOptOut.js +15 -0
  1068. package/src/services/api/overageCreditGrant.js +123 -0
  1069. package/src/services/api/promptCacheBreakDetection.js +510 -0
  1070. package/src/services/api/referral.js +219 -0
  1071. package/src/services/api/sessionIngress.js +358 -0
  1072. package/src/services/api/ultrareviewQuota.js +29 -0
  1073. package/src/services/api/usage.js +31 -0
  1074. package/src/services/api/withRetry.js +587 -0
  1075. package/src/services/api/xai/anthropic-shim.js +885 -0
  1076. package/src/services/api/xai/brightDataSearch.js +161 -0
  1077. package/src/services/api/xai/thaddeus-engine.js +605 -0
  1078. package/src/services/api/xai/xai-client.js +276 -0
  1079. package/src/services/autoDream/autoDream.js +244 -0
  1080. package/src/services/autoDream/config.js +17 -0
  1081. package/src/services/autoDream/consolidationLock.js +122 -0
  1082. package/src/services/autoDream/consolidationPrompt.js +55 -0
  1083. package/src/services/awaySummary.js +61 -0
  1084. package/src/services/claudeAiLimits.js +331 -0
  1085. package/src/services/claudeAiLimitsHook.js +15 -0
  1086. package/src/services/compact/apiMicrocompact.js +97 -0
  1087. package/src/services/compact/autoCompact.js +234 -0
  1088. package/src/services/compact/cachedMCConfig.js +5 -0
  1089. package/src/services/compact/compact.js +1256 -0
  1090. package/src/services/compact/compactWarningHook.js +12 -0
  1091. package/src/services/compact/compactWarningState.js +15 -0
  1092. package/src/services/compact/grouping.js +58 -0
  1093. package/src/services/compact/microCompact.js +414 -0
  1094. package/src/services/compact/postCompactCleanup.js +70 -0
  1095. package/src/services/compact/prompt.js +325 -0
  1096. package/src/services/compact/reactiveCompact.js +20 -0
  1097. package/src/services/compact/sessionMemoryCompact.js +467 -0
  1098. package/src/services/compact/snipCompact.js +23 -0
  1099. package/src/services/compact/snipProjection.js +11 -0
  1100. package/src/services/compact/timeBasedMCConfig.js +11 -0
  1101. package/src/services/contextCollapse/index.js +33 -0
  1102. package/src/services/contextCollapse/operations.js +5 -0
  1103. package/src/services/contextCollapse/persist.js +5 -0
  1104. package/src/services/diagnosticTracking.js +282 -0
  1105. package/src/services/elevenlabsTTS.js +245 -0
  1106. package/src/services/extractMemories/extractMemories.js +442 -0
  1107. package/src/services/extractMemories/prompts.js +129 -0
  1108. package/src/services/internalLogging.js +68 -0
  1109. package/src/services/lsp/LSPClient.js +306 -0
  1110. package/src/services/lsp/LSPDiagnosticRegistry.js +277 -0
  1111. package/src/services/lsp/LSPServerInstance.js +388 -0
  1112. package/src/services/lsp/LSPServerManager.js +305 -0
  1113. package/src/services/lsp/config.js +57 -0
  1114. package/src/services/lsp/manager.js +246 -0
  1115. package/src/services/lsp/passiveFeedback.js +226 -0
  1116. package/src/services/mcp/InProcessTransport.js +54 -0
  1117. package/src/services/mcp/MCPConnectionManager.js +50 -0
  1118. package/src/services/mcp/SdkControlTransport.js +115 -0
  1119. package/src/services/mcp/auth.js +1882 -0
  1120. package/src/services/mcp/channelAllowlist.js +57 -0
  1121. package/src/services/mcp/channelNotification.js +235 -0
  1122. package/src/services/mcp/channelPermissions.js +192 -0
  1123. package/src/services/mcp/claudeai.js +123 -0
  1124. package/src/services/mcp/client.js +2478 -0
  1125. package/src/services/mcp/config.js +1271 -0
  1126. package/src/services/mcp/elicitationHandler.js +192 -0
  1127. package/src/services/mcp/envExpansion.js +30 -0
  1128. package/src/services/mcp/headersHelper.js +93 -0
  1129. package/src/services/mcp/mcpStringUtils.js +85 -0
  1130. package/src/services/mcp/normalization.js +21 -0
  1131. package/src/services/mcp/oauthPort.js +69 -0
  1132. package/src/services/mcp/officialRegistry.js +20 -0
  1133. package/src/services/mcp/types.js +94 -0
  1134. package/src/services/mcp/useManageMCPConnections.js +818 -0
  1135. package/src/services/mcp/utils.js +433 -0
  1136. package/src/services/mcp/vscodeSdkMcp.js +69 -0
  1137. package/src/services/mcp/xaa.js +342 -0
  1138. package/src/services/mcp/xaaIdpLogin.js +377 -0
  1139. package/src/services/mcpServerApproval.js +30 -0
  1140. package/src/services/mockRateLimits.js +666 -0
  1141. package/src/services/notifier.js +114 -0
  1142. package/src/services/oauth/auth-code-listener.js +165 -0
  1143. package/src/services/oauth/client.js +397 -0
  1144. package/src/services/oauth/crypto.js +19 -0
  1145. package/src/services/oauth/getOauthProfile.js +48 -0
  1146. package/src/services/oauth/index.js +133 -0
  1147. package/src/services/plugins/PluginInstallationManager.js +139 -0
  1148. package/src/services/plugins/pluginCliCommands.js +230 -0
  1149. package/src/services/plugins/pluginOperations.js +826 -0
  1150. package/src/services/policyLimits/index.js +547 -0
  1151. package/src/services/policyLimits/types.js +9 -0
  1152. package/src/services/preventSleep.js +143 -0
  1153. package/src/services/rateLimitMessages.js +271 -0
  1154. package/src/services/rateLimitMocking.js +91 -0
  1155. package/src/services/remoteManagedSettings/index.js +534 -0
  1156. package/src/services/remoteManagedSettings/securityCheck.js +60 -0
  1157. package/src/services/remoteManagedSettings/syncCache.js +90 -0
  1158. package/src/services/remoteManagedSettings/syncCacheState.js +89 -0
  1159. package/src/services/remoteManagedSettings/types.js +12 -0
  1160. package/src/services/sessionTranscript/sessionTranscript.js +5 -0
  1161. package/src/services/settingsSync/index.js +478 -0
  1162. package/src/services/settingsSync/types.js +35 -0
  1163. package/src/services/skillSearch/featureCheck.js +8 -0
  1164. package/src/services/skillSearch/localSearch.js +5 -0
  1165. package/src/services/skillSearch/prefetch.js +8 -0
  1166. package/src/services/skillSearch/remoteSkillLoader.js +8 -0
  1167. package/src/services/skillSearch/remoteSkillState.js +11 -0
  1168. package/src/services/skillSearch/signals.js +3 -0
  1169. package/src/services/skillSearch/telemetry.js +8 -0
  1170. package/src/services/teamMemorySync/index.js +976 -0
  1171. package/src/services/teamMemorySync/secretScanner.js +275 -0
  1172. package/src/services/teamMemorySync/teamMemSecretGuard.js +33 -0
  1173. package/src/services/teamMemorySync/types.js +47 -0
  1174. package/src/services/teamMemorySync/watcher.js +326 -0
  1175. package/src/services/thaddeusAuth.js +485 -0
  1176. package/src/services/thaddeusAuthTypes.js +9 -0
  1177. package/src/services/thaddeusLoginFlow.js +236 -0
  1178. package/src/services/tips/tipHistory.js +17 -0
  1179. package/src/services/tips/tipRegistry.js +593 -0
  1180. package/src/services/tips/tipScheduler.js +40 -0
  1181. package/src/services/tokenEstimation.js +365 -0
  1182. package/src/services/toolUseSummary/toolUseSummaryGenerator.js +87 -0
  1183. package/src/services/tools/StreamingToolExecutor.js +413 -0
  1184. package/src/services/tools/toolExecution.js +1309 -0
  1185. package/src/services/tools/toolHooks.js +454 -0
  1186. package/src/services/tools/toolOrchestration.js +110 -0
  1187. package/src/services/vcr.js +291 -0
  1188. package/src/services/voice.js +392 -0
  1189. package/src/services/voiceKeyterms.js +94 -0
  1190. package/src/services/voiceStreamSTT.js +405 -0
  1191. package/src/setup.js +310 -0
  1192. package/src/skills/bundled/batch.js +114 -0
  1193. package/src/skills/bundled/claudeApi.js +145 -0
  1194. package/src/skills/bundled/claudeApiContent.js +71 -0
  1195. package/src/skills/bundled/claudeInChrome.js +27 -0
  1196. package/src/skills/bundled/debug.js +99 -0
  1197. package/src/skills/bundled/dream.js +49 -0
  1198. package/src/skills/bundled/emailSetup.js +196 -0
  1199. package/src/skills/bundled/hunter.js +28 -0
  1200. package/src/skills/bundled/index.js +80 -0
  1201. package/src/skills/bundled/keybindings.js +292 -0
  1202. package/src/skills/bundled/loop.js +81 -0
  1203. package/src/skills/bundled/loremIpsum.js +264 -0
  1204. package/src/skills/bundled/reactor.js +31 -0
  1205. package/src/skills/bundled/remember.js +73 -0
  1206. package/src/skills/bundled/runSkillGenerator.js +12 -0
  1207. package/src/skills/bundled/scheduleRemoteAgents.js +373 -0
  1208. package/src/skills/bundled/simplify.js +66 -0
  1209. package/src/skills/bundled/skillify.js +182 -0
  1210. package/src/skills/bundled/stuck.js +69 -0
  1211. package/src/skills/bundled/updateConfig.js +463 -0
  1212. package/src/skills/bundled/verify.js +23 -0
  1213. package/src/skills/bundled/verifyContent.js +10 -0
  1214. package/src/skills/bundledSkills.js +159 -0
  1215. package/src/skills/loadSkillsDir.js +736 -0
  1216. package/src/skills/mcpSkillBuilders.js +10 -0
  1217. package/src/skills/mcpSkills.js +5 -0
  1218. package/src/state/AppState.js +182 -0
  1219. package/src/state/AppStateStore.js +117 -0
  1220. package/src/state/onChangeAppState.js +132 -0
  1221. package/src/state/selectors.js +51 -0
  1222. package/src/state/store.js +21 -0
  1223. package/src/state/teammateViewHelpers.js +124 -0
  1224. package/src/stubs/ant-chrome-mcp/index.js +4 -0
  1225. package/src/stubs/ant-computer-use-input/index.js +2 -0
  1226. package/src/stubs/ant-computer-use-mcp/index.js +7 -0
  1227. package/src/stubs/ant-computer-use-mcp/sentinelApps.js +2 -0
  1228. package/src/stubs/ant-computer-use-mcp/types.js +3 -0
  1229. package/src/stubs/ant-computer-use-swift/index.js +1 -0
  1230. package/src/stubs/anthropic-sandbox/index.js +34 -0
  1231. package/src/tasks/DreamTask/DreamTask.js +99 -0
  1232. package/src/tasks/InProcessTeammateTask/InProcessTeammateTask.js +116 -0
  1233. package/src/tasks/InProcessTeammateTask/types.js +35 -0
  1234. package/src/tasks/LocalAgentTask/LocalAgentTask.js +507 -0
  1235. package/src/tasks/LocalMainSessionTask.js +338 -0
  1236. package/src/tasks/LocalShellTask/LocalShellTask.js +475 -0
  1237. package/src/tasks/LocalShellTask/guards.js +9 -0
  1238. package/src/tasks/LocalShellTask/killShellTasks.js +59 -0
  1239. package/src/tasks/LocalWorkflowTask/LocalWorkflowTask.js +7 -0
  1240. package/src/tasks/MonitorMcpTask/MonitorMcpTask.js +20 -0
  1241. package/src/tasks/RemoteAgentTask/RemoteAgentTask.js +742 -0
  1242. package/src/tasks/pillLabel.js +69 -0
  1243. package/src/tasks/stopTask.js +67 -0
  1244. package/src/tasks/types.js +18 -0
  1245. package/src/tasks.js +37 -0
  1246. package/src/tools/AIEmployeesTool/AIEmployeesTool.js +674 -0
  1247. package/src/tools/AIEmployeesTool/constants.js +1 -0
  1248. package/src/tools/AIEmployeesTool/prompt.js +56 -0
  1249. package/src/tools/AgentTool/AgentTool.js +1221 -0
  1250. package/src/tools/AgentTool/UI.js +593 -0
  1251. package/src/tools/AgentTool/agentColorManager.js +43 -0
  1252. package/src/tools/AgentTool/agentDisplay.js +72 -0
  1253. package/src/tools/AgentTool/agentMemory.js +125 -0
  1254. package/src/tools/AgentTool/agentMemorySnapshot.js +136 -0
  1255. package/src/tools/AgentTool/agentToolUtils.js +456 -0
  1256. package/src/tools/AgentTool/built-in/exploreAgent.js +76 -0
  1257. package/src/tools/AgentTool/built-in/generalPurposeAgent.js +28 -0
  1258. package/src/tools/AgentTool/built-in/planAgent.js +87 -0
  1259. package/src/tools/AgentTool/built-in/statuslineSetup.js +140 -0
  1260. package/src/tools/AgentTool/built-in/thaddeusGuideAgent.js +174 -0
  1261. package/src/tools/AgentTool/built-in/verificationAgent.js +146 -0
  1262. package/src/tools/AgentTool/builtInAgents.js +56 -0
  1263. package/src/tools/AgentTool/constants.js +11 -0
  1264. package/src/tools/AgentTool/forkSubagent.js +177 -0
  1265. package/src/tools/AgentTool/loadAgentsDir.js +497 -0
  1266. package/src/tools/AgentTool/prompt.js +260 -0
  1267. package/src/tools/AgentTool/resumeAgent.js +182 -0
  1268. package/src/tools/AgentTool/runAgent.js +627 -0
  1269. package/src/tools/AppointmentsTool/AppointmentsTool.js +628 -0
  1270. package/src/tools/AppointmentsTool/constants.js +1 -0
  1271. package/src/tools/AppointmentsTool/prompt.js +15 -0
  1272. package/src/tools/AskUserQuestionTool/AskUserQuestionTool.js +238 -0
  1273. package/src/tools/AskUserQuestionTool/prompt.js +38 -0
  1274. package/src/tools/BashTool/BashTool.js +1009 -0
  1275. package/src/tools/BashTool/BashToolResultMessage.js +169 -0
  1276. package/src/tools/BashTool/UI.js +134 -0
  1277. package/src/tools/BashTool/bashCommandHelpers.js +184 -0
  1278. package/src/tools/BashTool/bashPermissions.js +2023 -0
  1279. package/src/tools/BashTool/bashSecurity.js +2267 -0
  1280. package/src/tools/BashTool/commandSemantics.js +105 -0
  1281. package/src/tools/BashTool/commentLabel.js +14 -0
  1282. package/src/tools/BashTool/destructiveCommandWarning.js +88 -0
  1283. package/src/tools/BashTool/modeValidation.js +86 -0
  1284. package/src/tools/BashTool/pathValidation.js +1079 -0
  1285. package/src/tools/BashTool/prompt.js +333 -0
  1286. package/src/tools/BashTool/readOnlyValidation.js +1794 -0
  1287. package/src/tools/BashTool/sedEditParser.js +282 -0
  1288. package/src/tools/BashTool/sedValidation.js +580 -0
  1289. package/src/tools/BashTool/shouldUseSandbox.js +125 -0
  1290. package/src/tools/BashTool/toolName.js +2 -0
  1291. package/src/tools/BashTool/utils.js +180 -0
  1292. package/src/tools/BriefTool/BriefTool.js +173 -0
  1293. package/src/tools/BriefTool/UI.js +67 -0
  1294. package/src/tools/BriefTool/attachments.js +86 -0
  1295. package/src/tools/BriefTool/prompt.js +19 -0
  1296. package/src/tools/BriefTool/upload.js +136 -0
  1297. package/src/tools/CalendarTool/CalendarTool.js +498 -0
  1298. package/src/tools/CalendarTool/constants.js +1 -0
  1299. package/src/tools/CalendarTool/prompt.js +11 -0
  1300. package/src/tools/ConfigTool/ConfigTool.js +398 -0
  1301. package/src/tools/ConfigTool/UI.js +25 -0
  1302. package/src/tools/ConfigTool/constants.js +1 -0
  1303. package/src/tools/ConfigTool/prompt.js +82 -0
  1304. package/src/tools/ConfigTool/supportedSettings.js +180 -0
  1305. package/src/tools/ContactsTool/ContactsTool.js +648 -0
  1306. package/src/tools/ContactsTool/constants.js +1 -0
  1307. package/src/tools/ContactsTool/prompt.js +15 -0
  1308. package/src/tools/CtxInspectTool/CtxInspectTool.js +44 -0
  1309. package/src/tools/DiscoverSkillsTool/prompt.js +4 -0
  1310. package/src/tools/EmailReadTool/index.js +410 -0
  1311. package/src/tools/EmailSendTool/index.js +178 -0
  1312. package/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +98 -0
  1313. package/src/tools/EnterPlanModeTool/UI.js +14 -0
  1314. package/src/tools/EnterPlanModeTool/constants.js +1 -0
  1315. package/src/tools/EnterPlanModeTool/prompt.js +164 -0
  1316. package/src/tools/EnterWorktreeTool/EnterWorktreeTool.js +104 -0
  1317. package/src/tools/EnterWorktreeTool/UI.js +9 -0
  1318. package/src/tools/EnterWorktreeTool/constants.js +1 -0
  1319. package/src/tools/EnterWorktreeTool/prompt.js +30 -0
  1320. package/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +383 -0
  1321. package/src/tools/ExitPlanModeTool/UI.js +32 -0
  1322. package/src/tools/ExitPlanModeTool/constants.js +2 -0
  1323. package/src/tools/ExitPlanModeTool/prompt.js +27 -0
  1324. package/src/tools/ExitWorktreeTool/ExitWorktreeTool.js +257 -0
  1325. package/src/tools/ExitWorktreeTool/UI.js +10 -0
  1326. package/src/tools/ExitWorktreeTool/constants.js +1 -0
  1327. package/src/tools/ExitWorktreeTool/prompt.js +32 -0
  1328. package/src/tools/FileEditTool/FileEditTool.js +480 -0
  1329. package/src/tools/FileEditTool/UI.js +202 -0
  1330. package/src/tools/FileEditTool/constants.js +7 -0
  1331. package/src/tools/FileEditTool/prompt.js +24 -0
  1332. package/src/tools/FileEditTool/types.js +50 -0
  1333. package/src/tools/FileEditTool/utils.js +579 -0
  1334. package/src/tools/FileReadTool/FileReadTool.js +889 -0
  1335. package/src/tools/FileReadTool/UI.js +126 -0
  1336. package/src/tools/FileReadTool/imageProcessor.js +46 -0
  1337. package/src/tools/FileReadTool/limits.js +70 -0
  1338. package/src/tools/FileReadTool/prompt.js +31 -0
  1339. package/src/tools/FileWriteTool/FileWriteTool.js +341 -0
  1340. package/src/tools/FileWriteTool/UI.js +339 -0
  1341. package/src/tools/FileWriteTool/prompt.js +15 -0
  1342. package/src/tools/GlobTool/GlobTool.js +161 -0
  1343. package/src/tools/GlobTool/UI.js +40 -0
  1344. package/src/tools/GlobTool/prompt.js +6 -0
  1345. package/src/tools/GrepTool/GrepTool.js +439 -0
  1346. package/src/tools/GrepTool/UI.js +155 -0
  1347. package/src/tools/GrepTool/prompt.js +16 -0
  1348. package/src/tools/IntegrationsTool/IntegrationsTool.js +217 -0
  1349. package/src/tools/IntegrationsTool/constants.js +1 -0
  1350. package/src/tools/IntegrationsTool/prompt.js +41 -0
  1351. package/src/tools/InteractionsTool/InteractionsTool.js +525 -0
  1352. package/src/tools/InteractionsTool/constants.js +1 -0
  1353. package/src/tools/InteractionsTool/prompt.js +14 -0
  1354. package/src/tools/InvoicesTool/InvoicesTool.js +581 -0
  1355. package/src/tools/InvoicesTool/constants.js +1 -0
  1356. package/src/tools/InvoicesTool/prompt.js +15 -0
  1357. package/src/tools/LSPTool/LSPTool.js +660 -0
  1358. package/src/tools/LSPTool/UI.js +205 -0
  1359. package/src/tools/LSPTool/formatters.js +445 -0
  1360. package/src/tools/LSPTool/prompt.js +20 -0
  1361. package/src/tools/LSPTool/schemas.js +197 -0
  1362. package/src/tools/LSPTool/symbolContext.js +75 -0
  1363. package/src/tools/LeadScorerTool/LeadScorerTool.js +509 -0
  1364. package/src/tools/LeadScorerTool/constants.js +1 -0
  1365. package/src/tools/LeadScorerTool/prompt.js +11 -0
  1366. package/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +100 -0
  1367. package/src/tools/ListMcpResourcesTool/UI.js +17 -0
  1368. package/src/tools/ListMcpResourcesTool/prompt.js +18 -0
  1369. package/src/tools/ListPeersTool/ListPeersTool.js +45 -0
  1370. package/src/tools/MCPTool/MCPTool.js +60 -0
  1371. package/src/tools/MCPTool/UI.js +343 -0
  1372. package/src/tools/MCPTool/classifyForCollapse.js +597 -0
  1373. package/src/tools/MCPTool/prompt.js +3 -0
  1374. package/src/tools/McpAuthTool/McpAuthTool.js +162 -0
  1375. package/src/tools/MonitorTool/MonitorTool.js +55 -0
  1376. package/src/tools/NotebookEditTool/NotebookEditTool.js +421 -0
  1377. package/src/tools/NotebookEditTool/UI.js +41 -0
  1378. package/src/tools/NotebookEditTool/constants.js +2 -0
  1379. package/src/tools/NotebookEditTool/prompt.js +2 -0
  1380. package/src/tools/OverflowTestTool/OverflowTestTool.js +51 -0
  1381. package/src/tools/PhoneBridgeTool/PhoneBridgeTool.js +301 -0
  1382. package/src/tools/PhoneBridgeTool/constants.js +1 -0
  1383. package/src/tools/PhoneBridgeTool/prompt.js +26 -0
  1384. package/src/tools/PowerShellTool/PowerShellTool.js +900 -0
  1385. package/src/tools/PowerShellTool/UI.js +58 -0
  1386. package/src/tools/PowerShellTool/clmTypes.js +207 -0
  1387. package/src/tools/PowerShellTool/commandSemantics.js +115 -0
  1388. package/src/tools/PowerShellTool/commonParameters.js +27 -0
  1389. package/src/tools/PowerShellTool/destructiveCommandWarning.js +92 -0
  1390. package/src/tools/PowerShellTool/gitSafety.js +185 -0
  1391. package/src/tools/PowerShellTool/modeValidation.js +357 -0
  1392. package/src/tools/PowerShellTool/pathValidation.js +1712 -0
  1393. package/src/tools/PowerShellTool/powershellPermissions.js +1351 -0
  1394. package/src/tools/PowerShellTool/powershellSecurity.js +942 -0
  1395. package/src/tools/PowerShellTool/prompt.js +132 -0
  1396. package/src/tools/PowerShellTool/readOnlyValidation.js +1633 -0
  1397. package/src/tools/PowerShellTool/toolName.js +2 -0
  1398. package/src/tools/PushNotificationTool/PushNotificationTool.js +35 -0
  1399. package/src/tools/REPLTool/REPLTool.js +44 -0
  1400. package/src/tools/REPLTool/constants.js +43 -0
  1401. package/src/tools/REPLTool/primitiveTools.js +36 -0
  1402. package/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +112 -0
  1403. package/src/tools/ReadMcpResourceTool/UI.js +24 -0
  1404. package/src/tools/ReadMcpResourceTool/prompt.js +15 -0
  1405. package/src/tools/RemoteTriggerTool/RemoteTriggerTool.js +142 -0
  1406. package/src/tools/RemoteTriggerTool/UI.js +12 -0
  1407. package/src/tools/RemoteTriggerTool/prompt.js +12 -0
  1408. package/src/tools/ReviewArtifactTool/ReviewArtifactTool.js +51 -0
  1409. package/src/tools/ScheduleCronTool/CronCreateTool.js +120 -0
  1410. package/src/tools/ScheduleCronTool/CronDeleteTool.js +74 -0
  1411. package/src/tools/ScheduleCronTool/CronListTool.js +77 -0
  1412. package/src/tools/ScheduleCronTool/UI.js +29 -0
  1413. package/src/tools/ScheduleCronTool/prompt.js +115 -0
  1414. package/src/tools/SendMessageTool/SendMessageTool.js +673 -0
  1415. package/src/tools/SendMessageTool/UI.js +24 -0
  1416. package/src/tools/SendMessageTool/constants.js +1 -0
  1417. package/src/tools/SendMessageTool/prompt.js +47 -0
  1418. package/src/tools/SendUserFileTool/SendUserFileTool.js +35 -0
  1419. package/src/tools/SendUserFileTool/prompt.js +5 -0
  1420. package/src/tools/SkillTool/SkillTool.js +825 -0
  1421. package/src/tools/SkillTool/UI.js +61 -0
  1422. package/src/tools/SkillTool/constants.js +1 -0
  1423. package/src/tools/SkillTool/prompt.js +184 -0
  1424. package/src/tools/SleepTool/SleepTool.js +42 -0
  1425. package/src/tools/SleepTool/prompt.js +14 -0
  1426. package/src/tools/SnipTool/SnipTool.js +47 -0
  1427. package/src/tools/SnipTool/prompt.js +5 -0
  1428. package/src/tools/SubscribePRTool/SubscribePRTool.js +49 -0
  1429. package/src/tools/SuggestBackgroundPRTool/SuggestBackgroundPRTool.js +44 -0
  1430. package/src/tools/SyntheticOutputTool/SyntheticOutputTool.js +138 -0
  1431. package/src/tools/SyntheticOutputTool/SyntheticOutputTool.ts +1 -1
  1432. package/src/tools/TaskCreateTool/TaskCreateTool.js +104 -0
  1433. package/src/tools/TaskCreateTool/constants.js +1 -0
  1434. package/src/tools/TaskCreateTool/prompt.js +52 -0
  1435. package/src/tools/TaskGetTool/TaskGetTool.js +106 -0
  1436. package/src/tools/TaskGetTool/constants.js +1 -0
  1437. package/src/tools/TaskGetTool/prompt.js +23 -0
  1438. package/src/tools/TaskListTool/TaskListTool.js +89 -0
  1439. package/src/tools/TaskListTool/constants.js +1 -0
  1440. package/src/tools/TaskListTool/prompt.js +44 -0
  1441. package/src/tools/TaskOutputTool/TaskOutputTool.js +536 -0
  1442. package/src/tools/TaskOutputTool/constants.js +1 -0
  1443. package/src/tools/TaskStopTool/TaskStopTool.js +110 -0
  1444. package/src/tools/TaskStopTool/UI.js +31 -0
  1445. package/src/tools/TaskStopTool/prompt.js +7 -0
  1446. package/src/tools/TaskUpdateTool/TaskUpdateTool.js +301 -0
  1447. package/src/tools/TaskUpdateTool/constants.js +1 -0
  1448. package/src/tools/TaskUpdateTool/prompt.js +76 -0
  1449. package/src/tools/TeamCreateTool/TeamCreateTool.js +177 -0
  1450. package/src/tools/TeamCreateTool/UI.js +4 -0
  1451. package/src/tools/TeamCreateTool/constants.js +1 -0
  1452. package/src/tools/TeamCreateTool/prompt.js +113 -0
  1453. package/src/tools/TeamDeleteTool/TeamDeleteTool.js +102 -0
  1454. package/src/tools/TeamDeleteTool/UI.js +13 -0
  1455. package/src/tools/TeamDeleteTool/constants.js +1 -0
  1456. package/src/tools/TeamDeleteTool/prompt.js +16 -0
  1457. package/src/tools/TerminalCaptureTool/TerminalCaptureTool.js +47 -0
  1458. package/src/tools/TerminalCaptureTool/prompt.js +11 -0
  1459. package/src/tools/TodoWriteTool/TodoWriteTool.js +99 -0
  1460. package/src/tools/TodoWriteTool/constants.js +1 -0
  1461. package/src/tools/TodoWriteTool/prompt.js +181 -0
  1462. package/src/tools/ToolSearchTool/ToolSearchTool.js +357 -0
  1463. package/src/tools/ToolSearchTool/constants.js +1 -0
  1464. package/src/tools/ToolSearchTool/prompt.js +97 -0
  1465. package/src/tools/TungstenTool/TungstenLiveMonitor.js +7 -0
  1466. package/src/tools/TungstenTool/TungstenTool.js +3 -0
  1467. package/src/tools/VerifyPlanExecutionTool/VerifyPlanExecutionTool.js +45 -0
  1468. package/src/tools/VerifyPlanExecutionTool/constants.js +2 -0
  1469. package/src/tools/WebBrowserTool/WebBrowserPanel.js +5 -0
  1470. package/src/tools/WebBrowserTool/WebBrowserTool.js +58 -0
  1471. package/src/tools/WebFetchTool/UI.js +31 -0
  1472. package/src/tools/WebFetchTool/WebFetchTool.js +246 -0
  1473. package/src/tools/WebFetchTool/preapproved.js +154 -0
  1474. package/src/tools/WebFetchTool/prompt.js +39 -0
  1475. package/src/tools/WebFetchTool/utils.js +368 -0
  1476. package/src/tools/WebSearchTool/UI.js +67 -0
  1477. package/src/tools/WebSearchTool/WebSearchTool.js +396 -0
  1478. package/src/tools/WebSearchTool/prompt.js +32 -0
  1479. package/src/tools/WorkflowTool/WorkflowPermissionRequest.js +7 -0
  1480. package/src/tools/WorkflowTool/WorkflowTool.js +51 -0
  1481. package/src/tools/WorkflowTool/bundled/index.js +5 -0
  1482. package/src/tools/WorkflowTool/constants.js +1 -0
  1483. package/src/tools/WorkflowTool/createWorkflowCommand.js +5 -0
  1484. package/src/tools/shared/gitOperationTracking.js +220 -0
  1485. package/src/tools/shared/spawnMultiAgent.js +805 -0
  1486. package/src/tools/testing/TestingPermissionTool.js +72 -0
  1487. package/src/tools/utils.js +24 -0
  1488. package/src/tools.js +365 -0
  1489. package/src/types/command.js +8 -0
  1490. package/src/types/connectorText.js +3 -0
  1491. package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.js +673 -0
  1492. package/src/types/generated/events_mono/common/v1/auth.js +49 -0
  1493. package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.js +147 -0
  1494. package/src/types/generated/google/protobuf/timestamp.js +38 -0
  1495. package/src/types/hooks.js +153 -0
  1496. package/src/types/ids.js +27 -0
  1497. package/src/types/logs.js +11 -0
  1498. package/src/types/permissions.js +25 -0
  1499. package/src/types/plugin.js +72 -0
  1500. package/src/types/textInputTypes.js +20 -0
  1501. package/src/upstreamproxy/relay.js +346 -0
  1502. package/src/upstreamproxy/upstreamproxy.js +234 -0
  1503. package/src/utils/CircularBuffer.js +75 -0
  1504. package/src/utils/Cursor.js +1229 -0
  1505. package/src/utils/QueryGuard.js +115 -0
  1506. package/src/utils/Shell.js +374 -0
  1507. package/src/utils/ShellCommand.js +336 -0
  1508. package/src/utils/abortController.js +74 -0
  1509. package/src/utils/activityManager.js +127 -0
  1510. package/src/utils/advisor.js +77 -0
  1511. package/src/utils/agentContext.js +91 -0
  1512. package/src/utils/agentId.js +83 -0
  1513. package/src/utils/agentSwarmsEnabled.js +37 -0
  1514. package/src/utils/agenticSessionSearch.js +255 -0
  1515. package/src/utils/analyzeContext.js +846 -0
  1516. package/src/utils/ansiToPng.js +259 -0
  1517. package/src/utils/ansiToSvg.js +207 -0
  1518. package/src/utils/api.js +555 -0
  1519. package/src/utils/apiPreconnect.js +62 -0
  1520. package/src/utils/appleTerminalBackup.js +95 -0
  1521. package/src/utils/argumentSubstitution.js +114 -0
  1522. package/src/utils/array.js +12 -0
  1523. package/src/utils/asciicast.js +200 -0
  1524. package/src/utils/attachments.js +2518 -0
  1525. package/src/utils/attribution.js +308 -0
  1526. package/src/utils/auth.js +1598 -0
  1527. package/src/utils/authFileDescriptor.js +152 -0
  1528. package/src/utils/authPortable.js +14 -0
  1529. package/src/utils/autoModeDenials.js +15 -0
  1530. package/src/utils/autoRunIssue.js +113 -0
  1531. package/src/utils/autoUpdater.js +457 -0
  1532. package/src/utils/aws.js +44 -0
  1533. package/src/utils/awsAuthStatusManager.js +66 -0
  1534. package/src/utils/background/remote/preconditions.js +175 -0
  1535. package/src/utils/background/remote/remoteSession.js +53 -0
  1536. package/src/utils/backgroundHousekeeping.js +64 -0
  1537. package/src/utils/bash/ParsedCommand.js +241 -0
  1538. package/src/utils/bash/ShellSnapshot.js +489 -0
  1539. package/src/utils/bash/ast.js +2590 -0
  1540. package/src/utils/bash/bashParser.js +4355 -0
  1541. package/src/utils/bash/bashPipeCommand.js +249 -0
  1542. package/src/utils/bash/commands.js +1131 -0
  1543. package/src/utils/bash/heredoc.js +647 -0
  1544. package/src/utils/bash/parser.js +195 -0
  1545. package/src/utils/bash/prefix.js +154 -0
  1546. package/src/utils/bash/registry.js +23 -0
  1547. package/src/utils/bash/shellCompletion.js +196 -0
  1548. package/src/utils/bash/shellPrefix.js +25 -0
  1549. package/src/utils/bash/shellQuote.js +253 -0
  1550. package/src/utils/bash/shellQuoting.js +106 -0
  1551. package/src/utils/bash/specs/alias.js +11 -0
  1552. package/src/utils/bash/specs/index.js +16 -0
  1553. package/src/utils/bash/specs/nohup.js +10 -0
  1554. package/src/utils/bash/specs/pyright.js +88 -0
  1555. package/src/utils/bash/specs/sleep.js +10 -0
  1556. package/src/utils/bash/specs/srun.js +28 -0
  1557. package/src/utils/bash/specs/time.js +10 -0
  1558. package/src/utils/bash/specs/timeout.js +17 -0
  1559. package/src/utils/bash/treeSitterAnalysis.js +407 -0
  1560. package/src/utils/betas.js +331 -0
  1561. package/src/utils/billing.js +54 -0
  1562. package/src/utils/binaryCheck.js +40 -0
  1563. package/src/utils/browser.js +58 -0
  1564. package/src/utils/bufferedWriter.js +77 -0
  1565. package/src/utils/bundledMode.js +19 -0
  1566. package/src/utils/businessDb.js +390 -0
  1567. package/src/utils/caCerts.js +91 -0
  1568. package/src/utils/caCertsConfig.js +77 -0
  1569. package/src/utils/cachePaths.js +28 -0
  1570. package/src/utils/classifierApprovals.js +66 -0
  1571. package/src/utils/classifierApprovalsHook.js +10 -0
  1572. package/src/utils/claudeDesktop.js +108 -0
  1573. package/src/utils/claudeInChrome/chromeNativeHost.js +416 -0
  1574. package/src/utils/claudeInChrome/common.js +466 -0
  1575. package/src/utils/claudeInChrome/mcpServer.js +237 -0
  1576. package/src/utils/claudeInChrome/prompt.js +79 -0
  1577. package/src/utils/claudeInChrome/setup.js +304 -0
  1578. package/src/utils/claudeInChrome/setupPortable.js +172 -0
  1579. package/src/utils/claudeInChrome/toolRendering.js +235 -0
  1580. package/src/utils/claudemd.js +1052 -0
  1581. package/src/utils/cleanup.js +514 -0
  1582. package/src/utils/cleanupRegistry.js +22 -0
  1583. package/src/utils/cliArgs.js +53 -0
  1584. package/src/utils/cliHighlight.js +45 -0
  1585. package/src/utils/codeIndexing.js +149 -0
  1586. package/src/utils/collapseBackgroundBashNotifications.js +70 -0
  1587. package/src/utils/collapseHookSummaries.js +48 -0
  1588. package/src/utils/collapseReadSearch.js +869 -0
  1589. package/src/utils/collapseTeammateShutdowns.js +44 -0
  1590. package/src/utils/combinedAbortSignal.js +40 -0
  1591. package/src/utils/commandLifecycle.js +7 -0
  1592. package/src/utils/commitAttribution.js +718 -0
  1593. package/src/utils/completionCache.js +138 -0
  1594. package/src/utils/computerUse/appNames.js +170 -0
  1595. package/src/utils/computerUse/cleanup.js +65 -0
  1596. package/src/utils/computerUse/common.js +56 -0
  1597. package/src/utils/computerUse/computerUseLock.js +183 -0
  1598. package/src/utils/computerUse/drainRunLoop.js +71 -0
  1599. package/src/utils/computerUse/escHotkey.js +53 -0
  1600. package/src/utils/computerUse/executor.js +480 -0
  1601. package/src/utils/computerUse/gates.js +55 -0
  1602. package/src/utils/computerUse/hostAdapter.js +62 -0
  1603. package/src/utils/computerUse/inputLoader.js +25 -0
  1604. package/src/utils/computerUse/mcpServer.js +84 -0
  1605. package/src/utils/computerUse/setup.js +42 -0
  1606. package/src/utils/computerUse/swiftLoader.js +18 -0
  1607. package/src/utils/computerUse/toolRendering.js +101 -0
  1608. package/src/utils/computerUse/wrapper.js +317 -0
  1609. package/src/utils/concurrentSessions.js +179 -0
  1610. package/src/utils/config.js +1078 -0
  1611. package/src/utils/configConstants.js +18 -0
  1612. package/src/utils/contentArray.js +45 -0
  1613. package/src/utils/context.js +185 -0
  1614. package/src/utils/contextAnalysis.js +171 -0
  1615. package/src/utils/contextSuggestions.js +158 -0
  1616. package/src/utils/controlMessageCompat.js +31 -0
  1617. package/src/utils/conversationRecovery.js +434 -0
  1618. package/src/utils/cron.js +260 -0
  1619. package/src/utils/cronJitterConfig.js +62 -0
  1620. package/src/utils/cronScheduler.js +388 -0
  1621. package/src/utils/cronTasks.js +328 -0
  1622. package/src/utils/cronTasksLock.js +159 -0
  1623. package/src/utils/crossProjectResume.js +46 -0
  1624. package/src/utils/crypto.js +13 -0
  1625. package/src/utils/cwd.js +29 -0
  1626. package/src/utils/debug.js +220 -0
  1627. package/src/utils/debugFilter.js +125 -0
  1628. package/src/utils/deepLink/banner.js +103 -0
  1629. package/src/utils/deepLink/parseDeepLink.js +138 -0
  1630. package/src/utils/deepLink/protocolHandler.js +119 -0
  1631. package/src/utils/deepLink/registerProtocol.js +291 -0
  1632. package/src/utils/deepLink/terminalLauncher.js +455 -0
  1633. package/src/utils/deepLink/terminalPreference.js +51 -0
  1634. package/src/utils/desktopDeepLink.js +208 -0
  1635. package/src/utils/detectRepository.js +157 -0
  1636. package/src/utils/diagLogs.js +74 -0
  1637. package/src/utils/diff.js +108 -0
  1638. package/src/utils/directMemberMessage.js +34 -0
  1639. package/src/utils/displayTags.js +46 -0
  1640. package/src/utils/doctorContextWarnings.js +179 -0
  1641. package/src/utils/doctorDiagnostic.js +494 -0
  1642. package/src/utils/dxt/helpers.js +64 -0
  1643. package/src/utils/dxt/zip.js +167 -0
  1644. package/src/utils/earlyInput.js +166 -0
  1645. package/src/utils/editor.js +163 -0
  1646. package/src/utils/effort.js +271 -0
  1647. package/src/utils/embeddedTools.js +26 -0
  1648. package/src/utils/employeeChat.js +271 -0
  1649. package/src/utils/employeeDb.js +326 -0
  1650. package/src/utils/env.js +358 -0
  1651. package/src/utils/envDynamic.js +130 -0
  1652. package/src/utils/envUtils.js +161 -0
  1653. package/src/utils/envValidation.js +26 -0
  1654. package/src/utils/errorLogSink.js +196 -0
  1655. package/src/utils/errors.js +207 -0
  1656. package/src/utils/exampleCommands.js +165 -0
  1657. package/src/utils/execFileNoThrow.js +93 -0
  1658. package/src/utils/execFileNoThrowPortable.js +49 -0
  1659. package/src/utils/execSyncWrapper.js +6 -0
  1660. package/src/utils/exportRenderer.js +71 -0
  1661. package/src/utils/extraUsage.js +19 -0
  1662. package/src/utils/fastMode.js +393 -0
  1663. package/src/utils/file.js +467 -0
  1664. package/src/utils/fileHistory.js +851 -0
  1665. package/src/utils/fileOperationAnalytics.js +45 -0
  1666. package/src/utils/filePersistence/filePersistence.js +212 -0
  1667. package/src/utils/filePersistence/outputsScanner.js +104 -0
  1668. package/src/utils/filePersistence/types.js +4 -0
  1669. package/src/utils/fileRead.js +81 -0
  1670. package/src/utils/fileReadCache.js +78 -0
  1671. package/src/utils/fileStateCache.js +99 -0
  1672. package/src/utils/findExecutable.js +13 -0
  1673. package/src/utils/fingerprint.js +58 -0
  1674. package/src/utils/forkedAgent.js +410 -0
  1675. package/src/utils/format.js +238 -0
  1676. package/src/utils/formatBriefTimestamp.js +72 -0
  1677. package/src/utils/fpsTracker.js +34 -0
  1678. package/src/utils/frontmatterParser.js +260 -0
  1679. package/src/utils/fsOperations.js +555 -0
  1680. package/src/utils/fullscreen.js +194 -0
  1681. package/src/utils/generatedFiles.js +122 -0
  1682. package/src/utils/generators.js +67 -0
  1683. package/src/utils/genericProcessUtils.js +155 -0
  1684. package/src/utils/getWorktreePaths.js +56 -0
  1685. package/src/utils/getWorktreePathsPortable.js +23 -0
  1686. package/src/utils/ghPrStatus.js +71 -0
  1687. package/src/utils/git/gitConfigParser.js +226 -0
  1688. package/src/utils/git/gitFilesystem.js +606 -0
  1689. package/src/utils/git/gitignore.js +84 -0
  1690. package/src/utils/git.js +725 -0
  1691. package/src/utils/gitDiff.js +395 -0
  1692. package/src/utils/gitSettings.js +18 -0
  1693. package/src/utils/github/ghAuthStatus.js +23 -0
  1694. package/src/utils/githubRepoPathMapping.js +135 -0
  1695. package/src/utils/glob.js +90 -0
  1696. package/src/utils/gracefulShutdown.js +447 -0
  1697. package/src/utils/groupToolUses.js +126 -0
  1698. package/src/utils/handlePromptSubmit.js +398 -0
  1699. package/src/utils/hash.js +44 -0
  1700. package/src/utils/headlessProfiler.js +147 -0
  1701. package/src/utils/heapDumpService.js +201 -0
  1702. package/src/utils/heatmap.js +151 -0
  1703. package/src/utils/highlightMatch.js +29 -0
  1704. package/src/utils/hooks/AsyncHookRegistry.js +187 -0
  1705. package/src/utils/hooks/apiQueryHookHelper.js +77 -0
  1706. package/src/utils/hooks/execAgentHook.js +257 -0
  1707. package/src/utils/hooks/execHttpHook.js +184 -0
  1708. package/src/utils/hooks/execPromptHook.js +171 -0
  1709. package/src/utils/hooks/fileChangedWatcher.js +161 -0
  1710. package/src/utils/hooks/hookEvents.js +111 -0
  1711. package/src/utils/hooks/hookHelpers.js +60 -0
  1712. package/src/utils/hooks/hooksConfigManager.js +323 -0
  1713. package/src/utils/hooks/hooksConfigSnapshot.js +114 -0
  1714. package/src/utils/hooks/hooksSettings.js +204 -0
  1715. package/src/utils/hooks/postSamplingHooks.js +39 -0
  1716. package/src/utils/hooks/registerFrontmatterHooks.js +47 -0
  1717. package/src/utils/hooks/registerSkillHooks.js +40 -0
  1718. package/src/utils/hooks/sessionHooks.js +252 -0
  1719. package/src/utils/hooks/skillImprovement.js +211 -0
  1720. package/src/utils/hooks/ssrfGuard.js +258 -0
  1721. package/src/utils/hooks.js +3668 -0
  1722. package/src/utils/horizontalScroll.js +108 -0
  1723. package/src/utils/http.js +120 -0
  1724. package/src/utils/hyperlink.js +28 -0
  1725. package/src/utils/iTermBackup.js +48 -0
  1726. package/src/utils/ide.js +1195 -0
  1727. package/src/utils/idePathConversion.js +66 -0
  1728. package/src/utils/idleTimeout.js +44 -0
  1729. package/src/utils/imagePaste.js +343 -0
  1730. package/src/utils/imageResizer.js +664 -0
  1731. package/src/utils/imageStore.js +150 -0
  1732. package/src/utils/imageValidation.js +92 -0
  1733. package/src/utils/immediateCommand.js +12 -0
  1734. package/src/utils/inProcessTeammateHelpers.js +71 -0
  1735. package/src/utils/ink.js +20 -0
  1736. package/src/utils/intl.js +83 -0
  1737. package/src/utils/jetbrains.js +152 -0
  1738. package/src/utils/json.js +231 -0
  1739. package/src/utils/jsonRead.js +14 -0
  1740. package/src/utils/keyboardShortcuts.js +11 -0
  1741. package/src/utils/lazySchema.js +8 -0
  1742. package/src/utils/listSessionsImpl.js +332 -0
  1743. package/src/utils/localInstaller.js +130 -0
  1744. package/src/utils/lockfile.js +30 -0
  1745. package/src/utils/log.js +280 -0
  1746. package/src/utils/logoV2Utils.js +256 -0
  1747. package/src/utils/mailbox.js +50 -0
  1748. package/src/utils/managedEnv.js +160 -0
  1749. package/src/utils/managedEnvConstants.js +185 -0
  1750. package/src/utils/markdown.js +315 -0
  1751. package/src/utils/markdownConfigLoader.js +480 -0
  1752. package/src/utils/mcp/dateTimeParser.js +102 -0
  1753. package/src/utils/mcp/elicitationValidation.js +259 -0
  1754. package/src/utils/mcpInstructionsDelta.js +97 -0
  1755. package/src/utils/mcpOutputStorage.js +159 -0
  1756. package/src/utils/mcpValidation.js +165 -0
  1757. package/src/utils/mcpWebSocketTransport.js +180 -0
  1758. package/src/utils/memoize.js +205 -0
  1759. package/src/utils/memory/types.js +9 -0
  1760. package/src/utils/memory/versions.js +7 -0
  1761. package/src/utils/memoryFileDetection.js +245 -0
  1762. package/src/utils/messagePredicates.js +6 -0
  1763. package/src/utils/messageQueueManager.js +430 -0
  1764. package/src/utils/messages/mappers.js +240 -0
  1765. package/src/utils/messages/systemInit.js +72 -0
  1766. package/src/utils/messages.js +4286 -0
  1767. package/src/utils/model/agent.js +128 -0
  1768. package/src/utils/model/aliases.js +21 -0
  1769. package/src/utils/model/antModels.js +25 -0
  1770. package/src/utils/model/bedrock.js +220 -0
  1771. package/src/utils/model/check1mAccess.js +64 -0
  1772. package/src/utils/model/configs.js +86 -0
  1773. package/src/utils/model/contextWindowUpgradeCheck.js +41 -0
  1774. package/src/utils/model/deprecation.js +72 -0
  1775. package/src/utils/model/model.js +533 -0
  1776. package/src/utils/model/modelAllowlist.js +148 -0
  1777. package/src/utils/model/modelCapabilities.js +105 -0
  1778. package/src/utils/model/modelOptions.js +450 -0
  1779. package/src/utils/model/modelStrings.js +144 -0
  1780. package/src/utils/model/modelSupportOverrides.js +40 -0
  1781. package/src/utils/model/providers.js +35 -0
  1782. package/src/utils/model/validateModel.js +131 -0
  1783. package/src/utils/modelCost.js +160 -0
  1784. package/src/utils/modifiers.js +39 -0
  1785. package/src/utils/mtls.js +132 -0
  1786. package/src/utils/nativeInstaller/download.js +370 -0
  1787. package/src/utils/nativeInstaller/index.js +8 -0
  1788. package/src/utils/nativeInstaller/installer.js +1395 -0
  1789. package/src/utils/nativeInstaller/packageManagers.js +258 -0
  1790. package/src/utils/nativeInstaller/pidLock.js +347 -0
  1791. package/src/utils/notebook.js +176 -0
  1792. package/src/utils/objectGroupBy.js +15 -0
  1793. package/src/utils/pasteStore.js +93 -0
  1794. package/src/utils/path.js +140 -0
  1795. package/src/utils/pdf.js +236 -0
  1796. package/src/utils/pdfUtils.js +61 -0
  1797. package/src/utils/peerAddress.js +20 -0
  1798. package/src/utils/permissions/PermissionMode.js +95 -0
  1799. package/src/utils/permissions/PermissionPromptToolResultSchema.js +85 -0
  1800. package/src/utils/permissions/PermissionResult.js +11 -0
  1801. package/src/utils/permissions/PermissionRule.js +19 -0
  1802. package/src/utils/permissions/PermissionUpdate.js +268 -0
  1803. package/src/utils/permissions/PermissionUpdateSchema.js +61 -0
  1804. package/src/utils/permissions/autoModeState.js +31 -0
  1805. package/src/utils/permissions/bashClassifier.js +30 -0
  1806. package/src/utils/permissions/bypassPermissionsKillswitch.js +115 -0
  1807. package/src/utils/permissions/classifierDecision.js +86 -0
  1808. package/src/utils/permissions/classifierShared.js +28 -0
  1809. package/src/utils/permissions/dangerousPatterns.js +78 -0
  1810. package/src/utils/permissions/denialTracking.js +34 -0
  1811. package/src/utils/permissions/filesystem.js +1411 -0
  1812. package/src/utils/permissions/getNextPermissionMode.js +74 -0
  1813. package/src/utils/permissions/pathValidation.js +351 -0
  1814. package/src/utils/permissions/permissionExplainer.js +188 -0
  1815. package/src/utils/permissions/permissionRuleParser.js +175 -0
  1816. package/src/utils/permissions/permissionSetup.js +1162 -0
  1817. package/src/utils/permissions/permissions.js +1063 -0
  1818. package/src/utils/permissions/permissionsLoader.js +217 -0
  1819. package/src/utils/permissions/shadowedRuleDetection.js +149 -0
  1820. package/src/utils/permissions/shellRuleMatching.js +174 -0
  1821. package/src/utils/permissions/yoloClassifier.js +1193 -0
  1822. package/src/utils/planModeV2.js +75 -0
  1823. package/src/utils/plans.js +334 -0
  1824. package/src/utils/platform.js +122 -0
  1825. package/src/utils/plugins/addDirPluginSettings.js +53 -0
  1826. package/src/utils/plugins/cacheUtils.js +174 -0
  1827. package/src/utils/plugins/dependencyResolver.js +244 -0
  1828. package/src/utils/plugins/fetchTelemetry.js +108 -0
  1829. package/src/utils/plugins/gitAvailability.js +65 -0
  1830. package/src/utils/plugins/headlessPluginInstall.js +136 -0
  1831. package/src/utils/plugins/hintRecommendation.js +136 -0
  1832. package/src/utils/plugins/installCounts.js +221 -0
  1833. package/src/utils/plugins/installedPluginsManager.js +1003 -0
  1834. package/src/utils/plugins/loadPluginAgents.js +219 -0
  1835. package/src/utils/plugins/loadPluginCommands.js +595 -0
  1836. package/src/utils/plugins/loadPluginHooks.js +239 -0
  1837. package/src/utils/plugins/loadPluginOutputStyles.js +112 -0
  1838. package/src/utils/plugins/lspPluginIntegration.js +293 -0
  1839. package/src/utils/plugins/lspRecommendation.js +278 -0
  1840. package/src/utils/plugins/managedPlugins.js +26 -0
  1841. package/src/utils/plugins/marketplaceHelpers.js +470 -0
  1842. package/src/utils/plugins/marketplaceManager.js +1939 -0
  1843. package/src/utils/plugins/mcpPluginIntegration.js +465 -0
  1844. package/src/utils/plugins/mcpbHandler.js +708 -0
  1845. package/src/utils/plugins/officialMarketplace.js +19 -0
  1846. package/src/utils/plugins/officialMarketplaceGcs.js +202 -0
  1847. package/src/utils/plugins/officialMarketplaceStartupCheck.js +344 -0
  1848. package/src/utils/plugins/orphanedPluginFilter.js +96 -0
  1849. package/src/utils/plugins/parseMarketplaceInput.js +143 -0
  1850. package/src/utils/plugins/performStartupChecks.js +66 -0
  1851. package/src/utils/plugins/pluginAutoupdate.js +210 -0
  1852. package/src/utils/plugins/pluginBlocklist.js +93 -0
  1853. package/src/utils/plugins/pluginDirectories.js +170 -0
  1854. package/src/utils/plugins/pluginFlagging.js +173 -0
  1855. package/src/utils/plugins/pluginIdentifier.js +78 -0
  1856. package/src/utils/plugins/pluginInstallationHelpers.js +400 -0
  1857. package/src/utils/plugins/pluginLoader.js +2426 -0
  1858. package/src/utils/plugins/pluginOptionsStorage.js +311 -0
  1859. package/src/utils/plugins/pluginPolicy.js +18 -0
  1860. package/src/utils/plugins/pluginStartupCheck.js +261 -0
  1861. package/src/utils/plugins/pluginVersioning.js +128 -0
  1862. package/src/utils/plugins/reconciler.js +181 -0
  1863. package/src/utils/plugins/refresh.js +162 -0
  1864. package/src/utils/plugins/schemas.js +1283 -0
  1865. package/src/utils/plugins/validatePlugin.js +765 -0
  1866. package/src/utils/plugins/walkPluginMarkdown.js +49 -0
  1867. package/src/utils/plugins/zipCache.js +346 -0
  1868. package/src/utils/plugins/zipCacheAdapters.js +133 -0
  1869. package/src/utils/powershell/dangerousCmdlets.js +174 -0
  1870. package/src/utils/powershell/parser.js +1357 -0
  1871. package/src/utils/powershell/staticPrefix.js +277 -0
  1872. package/src/utils/preflightChecks.js +147 -0
  1873. package/src/utils/privacyLevel.js +49 -0
  1874. package/src/utils/process.js +56 -0
  1875. package/src/utils/processUserInput/processBashCommand.js +118 -0
  1876. package/src/utils/processUserInput/processSlashCommand.js +845 -0
  1877. package/src/utils/processUserInput/processTextPrompt.js +68 -0
  1878. package/src/utils/processUserInput/processUserInput.js +344 -0
  1879. package/src/utils/profilerBase.js +32 -0
  1880. package/src/utils/promptCategory.js +39 -0
  1881. package/src/utils/promptEditor.js +151 -0
  1882. package/src/utils/promptShellExecution.js +117 -0
  1883. package/src/utils/protectedNamespace.js +4 -0
  1884. package/src/utils/proxy.js +345 -0
  1885. package/src/utils/queryContext.js +110 -0
  1886. package/src/utils/queryHelpers.js +436 -0
  1887. package/src/utils/queryProfiler.js +242 -0
  1888. package/src/utils/queueProcessor.js +70 -0
  1889. package/src/utils/readEditContext.js +176 -0
  1890. package/src/utils/readFileInRange.js +278 -0
  1891. package/src/utils/releaseNotes.js +307 -0
  1892. package/src/utils/renderOptions.js +67 -0
  1893. package/src/utils/ripgrep.js +521 -0
  1894. package/src/utils/sandbox/sandbox-adapter.js +750 -0
  1895. package/src/utils/sandbox/sandbox-ui-utils.js +11 -0
  1896. package/src/utils/sanitization.js +72 -0
  1897. package/src/utils/screenshotClipboard.js +89 -0
  1898. package/src/utils/sdkEventQueue.js +49 -0
  1899. package/src/utils/secureStorage/fallbackStorage.js +59 -0
  1900. package/src/utils/secureStorage/index.js +13 -0
  1901. package/src/utils/secureStorage/keychainPrefetch.js +91 -0
  1902. package/src/utils/secureStorage/macOsKeychainHelpers.js +91 -0
  1903. package/src/utils/secureStorage/macOsKeychainStorage.js +192 -0
  1904. package/src/utils/secureStorage/plainTextStorage.js +81 -0
  1905. package/src/utils/semanticBoolean.js +23 -0
  1906. package/src/utils/semanticNumber.js +34 -0
  1907. package/src/utils/semver.js +51 -0
  1908. package/src/utils/sequential.js +43 -0
  1909. package/src/utils/sessionActivity.js +120 -0
  1910. package/src/utils/sessionEnvVars.js +18 -0
  1911. package/src/utils/sessionEnvironment.js +131 -0
  1912. package/src/utils/sessionFileAccessHooks.js +205 -0
  1913. package/src/utils/sessionIngressAuth.js +113 -0
  1914. package/src/utils/sessionRestore.js +357 -0
  1915. package/src/utils/sessionStart.js +165 -0
  1916. package/src/utils/sessionState.js +76 -0
  1917. package/src/utils/sessionStorage.js +4162 -0
  1918. package/src/utils/sessionStoragePortable.js +665 -0
  1919. package/src/utils/sessionTitle.js +120 -0
  1920. package/src/utils/sessionUrl.js +50 -0
  1921. package/src/utils/set.js +50 -0
  1922. package/src/utils/settings/allErrors.js +29 -0
  1923. package/src/utils/settings/applySettingsChange.js +65 -0
  1924. package/src/utils/settings/changeDetector.js +409 -0
  1925. package/src/utils/settings/constants.js +166 -0
  1926. package/src/utils/settings/internalWrites.js +33 -0
  1927. package/src/utils/settings/managedPath.js +29 -0
  1928. package/src/utils/settings/mdm/constants.js +62 -0
  1929. package/src/utils/settings/mdm/rawRead.js +97 -0
  1930. package/src/utils/settings/mdm/settings.js +254 -0
  1931. package/src/utils/settings/permissionValidation.js +224 -0
  1932. package/src/utils/settings/pluginOnlyPolicy.js +53 -0
  1933. package/src/utils/settings/schemaOutput.js +7 -0
  1934. package/src/utils/settings/settings.js +791 -0
  1935. package/src/utils/settings/settingsCache.js +47 -0
  1936. package/src/utils/settings/toolValidationConfig.js +76 -0
  1937. package/src/utils/settings/types.js +846 -0
  1938. package/src/utils/settings/validateEditTool.js +34 -0
  1939. package/src/utils/settings/validation.js +192 -0
  1940. package/src/utils/settings/validationTips.js +111 -0
  1941. package/src/utils/shell/bashProvider.js +202 -0
  1942. package/src/utils/shell/outputLimits.js +7 -0
  1943. package/src/utils/shell/powershellDetection.js +96 -0
  1944. package/src/utils/shell/powershellProvider.js +104 -0
  1945. package/src/utils/shell/prefix.js +246 -0
  1946. package/src/utils/shell/readOnlyCommandValidation.js +1776 -0
  1947. package/src/utils/shell/resolveDefaultShell.js +13 -0
  1948. package/src/utils/shell/shellProvider.js +2 -0
  1949. package/src/utils/shell/shellToolUtils.js +21 -0
  1950. package/src/utils/shell/specPrefix.js +198 -0
  1951. package/src/utils/shellConfig.js +136 -0
  1952. package/src/utils/sideQuery.js +134 -0
  1953. package/src/utils/sideQuestion.js +121 -0
  1954. package/src/utils/signal.js +34 -0
  1955. package/src/utils/sinks.js +15 -0
  1956. package/src/utils/skills/skillChangeDetector.js +264 -0
  1957. package/src/utils/slashCommandParsing.js +46 -0
  1958. package/src/utils/sleep.js +72 -0
  1959. package/src/utils/sliceAnsi.js +74 -0
  1960. package/src/utils/slowOperations.js +216 -0
  1961. package/src/utils/standaloneAgent.js +20 -0
  1962. package/src/utils/startupProfiler.js +149 -0
  1963. package/src/utils/staticRender.js +104 -0
  1964. package/src/utils/stats.js +802 -0
  1965. package/src/utils/statsCache.js +330 -0
  1966. package/src/utils/status.js +359 -0
  1967. package/src/utils/statusNoticeDefinitions.js +123 -0
  1968. package/src/utils/statusNoticeHelpers.js +15 -0
  1969. package/src/utils/stream.js +73 -0
  1970. package/src/utils/streamJsonStdoutGuard.js +107 -0
  1971. package/src/utils/streamlinedTransform.js +162 -0
  1972. package/src/utils/stringUtils.js +202 -0
  1973. package/src/utils/subprocessEnv.js +87 -0
  1974. package/src/utils/suggestions/commandSuggestions.js +458 -0
  1975. package/src/utils/suggestions/directoryCompletion.js +191 -0
  1976. package/src/utils/suggestions/shellHistoryCompletion.js +95 -0
  1977. package/src/utils/suggestions/skillUsageTracking.js +50 -0
  1978. package/src/utils/suggestions/slackChannelSuggestions.js +169 -0
  1979. package/src/utils/swarm/It2SetupPrompt.js +386 -0
  1980. package/src/utils/swarm/backends/ITermBackend.js +276 -0
  1981. package/src/utils/swarm/backends/InProcessBackend.js +237 -0
  1982. package/src/utils/swarm/backends/PaneBackendExecutor.js +250 -0
  1983. package/src/utils/swarm/backends/TmuxBackend.js +574 -0
  1984. package/src/utils/swarm/backends/detection.js +112 -0
  1985. package/src/utils/swarm/backends/it2Setup.js +185 -0
  1986. package/src/utils/swarm/backends/registry.js +369 -0
  1987. package/src/utils/swarm/backends/teammateModeSnapshot.js +68 -0
  1988. package/src/utils/swarm/backends/types.js +9 -0
  1989. package/src/utils/swarm/constants.js +29 -0
  1990. package/src/utils/swarm/inProcessRunner.js +1021 -0
  1991. package/src/utils/swarm/leaderPermissionBridge.js +31 -0
  1992. package/src/utils/swarm/permissionSync.js +667 -0
  1993. package/src/utils/swarm/reconnection.js +82 -0
  1994. package/src/utils/swarm/spawnInProcess.js +218 -0
  1995. package/src/utils/swarm/spawnUtils.js +123 -0
  1996. package/src/utils/swarm/teamHelpers.js +484 -0
  1997. package/src/utils/swarm/teammateInit.js +87 -0
  1998. package/src/utils/swarm/teammateLayoutManager.js +82 -0
  1999. package/src/utils/swarm/teammateModel.js +9 -0
  2000. package/src/utils/swarm/teammatePromptAddendum.js +17 -0
  2001. package/src/utils/systemDirectories.js +51 -0
  2002. package/src/utils/systemPrompt.js +88 -0
  2003. package/src/utils/systemPromptType.js +9 -0
  2004. package/src/utils/systemTheme.js +108 -0
  2005. package/src/utils/taggedId.js +49 -0
  2006. package/src/utils/task/TaskOutput.js +320 -0
  2007. package/src/utils/task/diskOutput.js +387 -0
  2008. package/src/utils/task/framework.js +236 -0
  2009. package/src/utils/task/outputFormatting.js +24 -0
  2010. package/src/utils/task/sdkProgress.js +24 -0
  2011. package/src/utils/taskSummary.js +3 -0
  2012. package/src/utils/tasks.js +672 -0
  2013. package/src/utils/teamDiscovery.js +48 -0
  2014. package/src/utils/teamMemoryOps.js +67 -0
  2015. package/src/utils/teammate.js +237 -0
  2016. package/src/utils/teammateContext.js +56 -0
  2017. package/src/utils/teammateMailbox.js +793 -0
  2018. package/src/utils/telemetry/betaSessionTracing.js +25 -0
  2019. package/src/utils/telemetry/bigqueryExporter.js +17 -0
  2020. package/src/utils/telemetry/events.js +7 -0
  2021. package/src/utils/telemetry/instrumentation.js +16 -0
  2022. package/src/utils/telemetry/logger.js +25 -0
  2023. package/src/utils/telemetry/perfettoTracing.js +882 -0
  2024. package/src/utils/telemetry/pluginTelemetry.js +76 -0
  2025. package/src/utils/telemetry/sessionTracing.js +62 -0
  2026. package/src/utils/telemetry/skillLoadedEvent.js +4 -0
  2027. package/src/utils/telemetryAttributes.js +56 -0
  2028. package/src/utils/teleport/api.js +299 -0
  2029. package/src/utils/teleport/environmentSelection.js +55 -0
  2030. package/src/utils/teleport/environments.js +84 -0
  2031. package/src/utils/teleport/gitBundle.js +192 -0
  2032. package/src/utils/teleport.js +1047 -0
  2033. package/src/utils/tempfile.js +26 -0
  2034. package/src/utils/terminal.js +105 -0
  2035. package/src/utils/terminalPanel.js +155 -0
  2036. package/src/utils/textHighlighting.js +113 -0
  2037. package/src/utils/thaddeusHints.js +142 -0
  2038. package/src/utils/theme.js +525 -0
  2039. package/src/utils/thinking.js +130 -0
  2040. package/src/utils/timeouts.js +35 -0
  2041. package/src/utils/tmuxSocket.js +373 -0
  2042. package/src/utils/todo/types.js +9 -0
  2043. package/src/utils/tokenBudget.js +62 -0
  2044. package/src/utils/tokens.js +223 -0
  2045. package/src/utils/toolErrors.js +101 -0
  2046. package/src/utils/toolPool.js +61 -0
  2047. package/src/utils/toolResultStorage.js +768 -0
  2048. package/src/utils/toolSchemaCache.js +7 -0
  2049. package/src/utils/toolSearch.js +551 -0
  2050. package/src/utils/transcriptSearch.js +200 -0
  2051. package/src/utils/treeify.js +111 -0
  2052. package/src/utils/truncate.js +164 -0
  2053. package/src/utils/udsClient.js +5 -0
  2054. package/src/utils/udsMessaging.js +23 -0
  2055. package/src/utils/ultraplan/ccrSession.js +264 -0
  2056. package/src/utils/ultraplan/keyword.js +122 -0
  2057. package/src/utils/unaryLogging.js +16 -0
  2058. package/src/utils/undercover.js +89 -0
  2059. package/src/utils/user.js +137 -0
  2060. package/src/utils/userAgent.js +9 -0
  2061. package/src/utils/userPromptKeywords.js +21 -0
  2062. package/src/utils/uuid.js +22 -0
  2063. package/src/utils/warningHandler.js +97 -0
  2064. package/src/utils/which.js +75 -0
  2065. package/src/utils/windowsPaths.js +146 -0
  2066. package/src/utils/withResolvers.js +13 -0
  2067. package/src/utils/words.js +793 -0
  2068. package/src/utils/workforceIntent.js +192 -0
  2069. package/src/utils/workloadContext.js +42 -0
  2070. package/src/utils/worktree.js +1142 -0
  2071. package/src/utils/worktreeModeEnabled.js +11 -0
  2072. package/src/utils/xdg.js +52 -0
  2073. package/src/utils/xml.js +15 -0
  2074. package/src/utils/yaml.js +14 -0
  2075. package/src/utils/zodToJsonSchema.js +19 -0
  2076. package/src/vim/motions.js +73 -0
  2077. package/src/vim/operators.js +401 -0
  2078. package/src/vim/textObjects.js +153 -0
  2079. package/src/vim/transitions.js +340 -0
  2080. package/src/vim/types.js +93 -0
  2081. package/src/voice/voiceModeEnabled.js +20 -0
  2082. package/thaddeus-terminal.ts +401 -3
@@ -0,0 +1,2426 @@
1
+ /**
2
+ * Plugin Loader Module
3
+ *
4
+ * This module is responsible for discovering, loading, and validating Claude Code plugins
5
+ * from various sources including marketplaces and git repositories.
6
+ *
7
+ * NPM packages are also supported but must be referenced through marketplaces - the marketplace
8
+ * entry contains the NPM package information.
9
+ *
10
+ * Plugin Discovery Sources (in order of precedence):
11
+ * 1. Marketplace-based plugins (plugin@marketplace format in settings)
12
+ * 2. Session-only plugins (from --plugin-dir CLI flag or SDK plugins option)
13
+ *
14
+ * Plugin Directory Structure:
15
+ * ```
16
+ * my-plugin/
17
+ * ├── plugin.json # Optional manifest with metadata
18
+ * ├── commands/ # Custom slash commands
19
+ * │ ├── build.md
20
+ * │ └── deploy.md
21
+ * ├── agents/ # Custom AI agents
22
+ * │ └── test-runner.md
23
+ * └── hooks/ # Hook configurations
24
+ * └── hooks.json # Hook definitions
25
+ * ```
26
+ *
27
+ * The loader handles:
28
+ * - Plugin manifest validation
29
+ * - Hooks configuration loading and variable resolution
30
+ * - Duplicate name detection
31
+ * - Enable/disable state management
32
+ * - Error collection and reporting
33
+ */
34
+ import { copyFile, readdir, readFile, readlink, realpath, rename, rm, rmdir, stat, symlink, } from 'fs/promises';
35
+ import memoize from 'lodash-es/memoize.js';
36
+ import { basename, dirname, join, relative, resolve, sep } from 'path';
37
+ import { getInlinePlugins } from '../../bootstrap/state.js';
38
+ import { BUILTIN_MARKETPLACE_NAME, getBuiltinPlugins, } from '../../plugins/builtinPlugins.js';
39
+ import { logForDebugging } from '../debug.js';
40
+ import { isEnvTruthy } from '../envUtils.js';
41
+ import { errorMessage, getErrnoPath, isENOENT, isFsInaccessible, toError, } from '../errors.js';
42
+ import { execFileNoThrow, execFileNoThrowWithCwd } from '../execFileNoThrow.js';
43
+ import { pathExists } from '../file.js';
44
+ import { getFsImplementation } from '../fsOperations.js';
45
+ import { gitExe } from '../git.js';
46
+ import { lazySchema } from '../lazySchema.js';
47
+ import { logError } from '../log.js';
48
+ import { getSettings_DEPRECATED } from '../settings/settings.js';
49
+ import { clearPluginSettingsBase, getPluginSettingsBase, resetSettingsCache, setPluginSettingsBase, } from '../settings/settingsCache.js';
50
+ import { SettingsSchema } from '../settings/types.js';
51
+ import { jsonParse, jsonStringify } from '../slowOperations.js';
52
+ import { getAddDirEnabledPlugins } from './addDirPluginSettings.js';
53
+ import { verifyAndDemote } from './dependencyResolver.js';
54
+ import { classifyFetchError, logPluginFetch } from './fetchTelemetry.js';
55
+ import { checkGitAvailable } from './gitAvailability.js';
56
+ import { getInMemoryInstalledPlugins } from './installedPluginsManager.js';
57
+ import { getManagedPluginNames } from './managedPlugins.js';
58
+ import { formatSourceForDisplay, getBlockedMarketplaces, getStrictKnownMarketplaces, isSourceAllowedByPolicy, isSourceInBlocklist, } from './marketplaceHelpers.js';
59
+ import { getMarketplaceCacheOnly, getPluginByIdCacheOnly, loadKnownMarketplacesConfigSafe, } from './marketplaceManager.js';
60
+ import { getPluginSeedDirs, getPluginsDirectory } from './pluginDirectories.js';
61
+ import { parsePluginIdentifier } from './pluginIdentifier.js';
62
+ import { validatePathWithinBase } from './pluginInstallationHelpers.js';
63
+ import { calculatePluginVersion } from './pluginVersioning.js';
64
+ import { PluginHooksSchema, PluginIdSchema, PluginManifestSchema, } from './schemas.js';
65
+ import { convertDirectoryToZipInPlace, extractZipToDirectory, getSessionPluginCachePath, isPluginZipCacheEnabled, } from './zipCache.js';
66
+ /**
67
+ * Get the path where plugin cache is stored
68
+ */
69
+ export function getPluginCachePath() {
70
+ return join(getPluginsDirectory(), 'cache');
71
+ }
72
+ /**
73
+ * Compute the versioned cache path under a specific base plugins directory.
74
+ * Used to probe both primary and seed caches.
75
+ *
76
+ * @param baseDir - Base plugins directory (e.g. getPluginsDirectory() or seed dir)
77
+ * @param pluginId - Plugin identifier in format "name@marketplace"
78
+ * @param version - Version string (semver, git SHA, etc.)
79
+ * @returns Absolute path to versioned plugin directory under baseDir
80
+ */
81
+ export function getVersionedCachePathIn(baseDir, pluginId, version) {
82
+ const { name: pluginName, marketplace } = parsePluginIdentifier(pluginId);
83
+ const sanitizedMarketplace = (marketplace || 'unknown').replace(/[^a-zA-Z0-9\-_]/g, '-');
84
+ const sanitizedPlugin = (pluginName || pluginId).replace(/[^a-zA-Z0-9\-_]/g, '-');
85
+ // Sanitize version to prevent path traversal attacks
86
+ const sanitizedVersion = version.replace(/[^a-zA-Z0-9\-_.]/g, '-');
87
+ return join(baseDir, 'cache', sanitizedMarketplace, sanitizedPlugin, sanitizedVersion);
88
+ }
89
+ /**
90
+ * Get versioned cache path for a plugin under the primary plugins directory.
91
+ * Format: ~/.claude/plugins/cache/{marketplace}/{plugin}/{version}/
92
+ *
93
+ * @param pluginId - Plugin identifier in format "name@marketplace"
94
+ * @param version - Version string (semver, git SHA, etc.)
95
+ * @returns Absolute path to versioned plugin directory
96
+ */
97
+ export function getVersionedCachePath(pluginId, version) {
98
+ return getVersionedCachePathIn(getPluginsDirectory(), pluginId, version);
99
+ }
100
+ /**
101
+ * Get versioned ZIP cache path for a plugin.
102
+ * This is the zip cache variant of getVersionedCachePath.
103
+ */
104
+ export function getVersionedZipCachePath(pluginId, version) {
105
+ return `${getVersionedCachePath(pluginId, version)}.zip`;
106
+ }
107
+ /**
108
+ * Probe seed directories for a populated cache at this plugin version.
109
+ * Seeds are checked in precedence order; first hit wins. Returns null if no
110
+ * seed is configured or none contains a populated directory at this version.
111
+ */
112
+ async function probeSeedCache(pluginId, version) {
113
+ for (const seedDir of getPluginSeedDirs()) {
114
+ const seedPath = getVersionedCachePathIn(seedDir, pluginId, version);
115
+ try {
116
+ const entries = await readdir(seedPath);
117
+ if (entries.length > 0)
118
+ return seedPath;
119
+ }
120
+ catch {
121
+ // Try next seed
122
+ }
123
+ }
124
+ return null;
125
+ }
126
+ /**
127
+ * When the computed version is 'unknown', probe seed/cache/<m>/<p>/ for an
128
+ * actual version dir. Handles the first-boot chicken-and-egg where the
129
+ * version can only be known after cloning, but seed already has the clone.
130
+ *
131
+ * Per seed, only matches when exactly one version exists (typical BYOC case).
132
+ * Multiple versions within a single seed → ambiguous → try next seed.
133
+ * Seeds are checked in precedence order; first match wins.
134
+ */
135
+ export async function probeSeedCacheAnyVersion(pluginId) {
136
+ for (const seedDir of getPluginSeedDirs()) {
137
+ // The parent of the version dir — computed the same way as
138
+ // getVersionedCachePathIn, just without the version component.
139
+ const pluginDir = dirname(getVersionedCachePathIn(seedDir, pluginId, '_'));
140
+ try {
141
+ const versions = await readdir(pluginDir);
142
+ if (versions.length !== 1)
143
+ continue;
144
+ const versionDir = join(pluginDir, versions[0]);
145
+ const entries = await readdir(versionDir);
146
+ if (entries.length > 0)
147
+ return versionDir;
148
+ }
149
+ catch {
150
+ // Try next seed
151
+ }
152
+ }
153
+ return null;
154
+ }
155
+ /**
156
+ * Get legacy (non-versioned) cache path for a plugin.
157
+ * Format: ~/.claude/plugins/cache/{plugin-name}/
158
+ *
159
+ * Used for backward compatibility with existing installations.
160
+ *
161
+ * @param pluginName - Plugin name (without marketplace suffix)
162
+ * @returns Absolute path to legacy plugin directory
163
+ */
164
+ export function getLegacyCachePath(pluginName) {
165
+ const cachePath = getPluginCachePath();
166
+ return join(cachePath, pluginName.replace(/[^a-zA-Z0-9\-_]/g, '-'));
167
+ }
168
+ /**
169
+ * Resolve plugin path with fallback to legacy location.
170
+ *
171
+ * Always:
172
+ * 1. Try versioned path first if version is provided
173
+ * 2. Fall back to legacy path for existing installations
174
+ * 3. Return versioned path for new installations
175
+ *
176
+ * @param pluginId - Plugin identifier in format "name@marketplace"
177
+ * @param version - Optional version string
178
+ * @returns Absolute path to plugin directory
179
+ */
180
+ export async function resolvePluginPath(pluginId, version) {
181
+ // Try versioned path first
182
+ if (version) {
183
+ const versionedPath = getVersionedCachePath(pluginId, version);
184
+ if (await pathExists(versionedPath)) {
185
+ return versionedPath;
186
+ }
187
+ }
188
+ // Fall back to legacy path for existing installations
189
+ const pluginName = parsePluginIdentifier(pluginId).name || pluginId;
190
+ const legacyPath = getLegacyCachePath(pluginName);
191
+ if (await pathExists(legacyPath)) {
192
+ return legacyPath;
193
+ }
194
+ // Return versioned path for new installations
195
+ return version ? getVersionedCachePath(pluginId, version) : legacyPath;
196
+ }
197
+ /**
198
+ * Recursively copy a directory.
199
+ * Exported for testing purposes.
200
+ */
201
+ export async function copyDir(src, dest) {
202
+ await getFsImplementation().mkdir(dest);
203
+ const entries = await readdir(src, { withFileTypes: true });
204
+ for (const entry of entries) {
205
+ const srcPath = join(src, entry.name);
206
+ const destPath = join(dest, entry.name);
207
+ if (entry.isDirectory()) {
208
+ await copyDir(srcPath, destPath);
209
+ }
210
+ else if (entry.isFile()) {
211
+ await copyFile(srcPath, destPath);
212
+ }
213
+ else if (entry.isSymbolicLink()) {
214
+ const linkTarget = await readlink(srcPath);
215
+ // Resolve the symlink to get the actual target path
216
+ // This prevents circular symlinks when src and dest overlap (e.g., via symlink chains)
217
+ let resolvedTarget;
218
+ try {
219
+ resolvedTarget = await realpath(srcPath);
220
+ }
221
+ catch {
222
+ // Broken symlink - copy the raw link target as-is
223
+ await symlink(linkTarget, destPath);
224
+ continue;
225
+ }
226
+ // Resolve the source directory to handle symlinked source dirs
227
+ let resolvedSrc;
228
+ try {
229
+ resolvedSrc = await realpath(src);
230
+ }
231
+ catch {
232
+ resolvedSrc = src;
233
+ }
234
+ // Check if target is within the source tree (using proper path prefix matching)
235
+ const srcPrefix = resolvedSrc.endsWith(sep)
236
+ ? resolvedSrc
237
+ : resolvedSrc + sep;
238
+ if (resolvedTarget.startsWith(srcPrefix) ||
239
+ resolvedTarget === resolvedSrc) {
240
+ // Target is within source tree - create relative symlink that preserves
241
+ // the same structure in the destination
242
+ const targetRelativeToSrc = relative(resolvedSrc, resolvedTarget);
243
+ const destTargetPath = join(dest, targetRelativeToSrc);
244
+ const relativeLinkPath = relative(dirname(destPath), destTargetPath);
245
+ await symlink(relativeLinkPath, destPath);
246
+ }
247
+ else {
248
+ // Target is outside source tree - use absolute resolved path
249
+ await symlink(resolvedTarget, destPath);
250
+ }
251
+ }
252
+ }
253
+ }
254
+ /**
255
+ * Copy plugin files to versioned cache directory.
256
+ *
257
+ * For local plugins: Uses entry.source from marketplace.json as the single source of truth.
258
+ * For remote plugins: Falls back to copying sourcePath (the downloaded content).
259
+ *
260
+ * @param sourcePath - Path to the plugin source (used as fallback for remote plugins)
261
+ * @param pluginId - Plugin identifier in format "name@marketplace"
262
+ * @param version - Version string for versioned path
263
+ * @param entry - Optional marketplace entry containing the source field
264
+ * @param marketplaceDir - Marketplace directory for resolving entry.source (undefined for remote plugins)
265
+ * @returns Path to the cached plugin directory
266
+ * @throws Error if the source directory is not found
267
+ * @throws Error if the destination directory is empty after copy
268
+ */
269
+ export async function copyPluginToVersionedCache(sourcePath, pluginId, version, entry, marketplaceDir) {
270
+ // When zip cache is enabled, the canonical format is a ZIP file
271
+ const zipCacheMode = isPluginZipCacheEnabled();
272
+ const cachePath = getVersionedCachePath(pluginId, version);
273
+ const zipPath = getVersionedZipCachePath(pluginId, version);
274
+ // If cache already exists (directory or ZIP), return it
275
+ if (zipCacheMode) {
276
+ if (await pathExists(zipPath)) {
277
+ logForDebugging(`Plugin ${pluginId} version ${version} already cached at ${zipPath}`);
278
+ return zipPath;
279
+ }
280
+ }
281
+ else if (await pathExists(cachePath)) {
282
+ const entries = await readdir(cachePath);
283
+ if (entries.length > 0) {
284
+ logForDebugging(`Plugin ${pluginId} version ${version} already cached at ${cachePath}`);
285
+ return cachePath;
286
+ }
287
+ // Directory exists but is empty, remove it so we can recreate with content
288
+ logForDebugging(`Removing empty cache directory for ${pluginId} at ${cachePath}`);
289
+ await rmdir(cachePath);
290
+ }
291
+ // Seed cache hit — return seed path in place (read-only, no copy).
292
+ // Callers handle both directory and .zip paths; this returns a directory.
293
+ const seedPath = await probeSeedCache(pluginId, version);
294
+ if (seedPath) {
295
+ logForDebugging(`Using seed cache for ${pluginId}@${version} at ${seedPath}`);
296
+ return seedPath;
297
+ }
298
+ // Create parent directories
299
+ await getFsImplementation().mkdir(dirname(cachePath));
300
+ // For local plugins: copy entry.source directory (the single source of truth)
301
+ // For remote plugins: marketplaceDir is undefined, fall back to copying sourcePath
302
+ if (entry && typeof entry.source === 'string' && marketplaceDir) {
303
+ const sourceDir = validatePathWithinBase(marketplaceDir, entry.source);
304
+ logForDebugging(`Copying source directory ${entry.source} for plugin ${pluginId}`);
305
+ try {
306
+ await copyDir(sourceDir, cachePath);
307
+ }
308
+ catch (e) {
309
+ // Only remap ENOENT from the top-level sourceDir itself — nested ENOENTs
310
+ // from recursive copyDir (broken symlinks, raced deletes) should preserve
311
+ // their original path in the error.
312
+ if (isENOENT(e) && getErrnoPath(e) === sourceDir) {
313
+ throw new Error(`Plugin source directory not found: ${sourceDir} (from entry.source: ${entry.source})`);
314
+ }
315
+ throw e;
316
+ }
317
+ }
318
+ else {
319
+ // Fallback for remote plugins (already downloaded) or plugins without entry.source
320
+ logForDebugging(`Copying plugin ${pluginId} to versioned cache (fallback to full copy)`);
321
+ await copyDir(sourcePath, cachePath);
322
+ }
323
+ // Remove .git directory from cache if present
324
+ const gitPath = join(cachePath, '.git');
325
+ await rm(gitPath, { recursive: true, force: true });
326
+ // Validate that cache has content - if empty, throw so fallback can be used
327
+ const cacheEntries = await readdir(cachePath);
328
+ if (cacheEntries.length === 0) {
329
+ throw new Error(`Failed to copy plugin ${pluginId} to versioned cache: destination is empty after copy`);
330
+ }
331
+ // Zip cache mode: convert directory to ZIP and remove the directory
332
+ if (zipCacheMode) {
333
+ await convertDirectoryToZipInPlace(cachePath, zipPath);
334
+ logForDebugging(`Successfully cached plugin ${pluginId} as ZIP at ${zipPath}`);
335
+ return zipPath;
336
+ }
337
+ logForDebugging(`Successfully cached plugin ${pluginId} at ${cachePath}`);
338
+ return cachePath;
339
+ }
340
+ /**
341
+ * Validate a git URL using Node.js URL parsing
342
+ */
343
+ function validateGitUrl(url) {
344
+ try {
345
+ const parsed = new URL(url);
346
+ if (!['https:', 'http:', 'file:'].includes(parsed.protocol)) {
347
+ if (!/^git@[a-zA-Z0-9.-]+:/.test(url)) {
348
+ throw new Error(`Invalid git URL protocol: ${parsed.protocol}. Only HTTPS, HTTP, file:// and SSH (git@) URLs are supported.`);
349
+ }
350
+ }
351
+ return url;
352
+ }
353
+ catch {
354
+ if (/^git@[a-zA-Z0-9.-]+:/.test(url)) {
355
+ return url;
356
+ }
357
+ throw new Error(`Invalid git URL: ${url}`);
358
+ }
359
+ }
360
+ /**
361
+ * Install a plugin from npm using a global cache (exported for testing)
362
+ */
363
+ export async function installFromNpm(packageName, targetPath, options = {}) {
364
+ const npmCachePath = join(getPluginsDirectory(), 'npm-cache');
365
+ await getFsImplementation().mkdir(npmCachePath);
366
+ const packageSpec = options.version
367
+ ? `${packageName}@${options.version}`
368
+ : packageName;
369
+ const packagePath = join(npmCachePath, 'node_modules', packageName);
370
+ const needsInstall = !(await pathExists(packagePath));
371
+ if (needsInstall) {
372
+ logForDebugging(`Installing npm package ${packageSpec} to cache`);
373
+ const args = ['install', packageSpec, '--prefix', npmCachePath];
374
+ if (options.registry) {
375
+ args.push('--registry', options.registry);
376
+ }
377
+ const result = await execFileNoThrow('npm', args, { useCwd: false });
378
+ if (result.code !== 0) {
379
+ throw new Error(`Failed to install npm package: ${result.stderr}`);
380
+ }
381
+ }
382
+ await copyDir(packagePath, targetPath);
383
+ logForDebugging(`Copied npm package ${packageName} from cache to ${targetPath}`);
384
+ }
385
+ /**
386
+ * Clone a git repository (exported for testing)
387
+ *
388
+ * @param gitUrl - The git URL to clone
389
+ * @param targetPath - Where to clone the repository
390
+ * @param ref - Optional branch or tag to checkout
391
+ * @param sha - Optional specific commit SHA to checkout
392
+ */
393
+ export async function gitClone(gitUrl, targetPath, ref, sha) {
394
+ // Use --recurse-submodules to initialize submodules
395
+ // Always start with shallow clone for efficiency
396
+ const args = [
397
+ 'clone',
398
+ '--depth',
399
+ '1',
400
+ '--recurse-submodules',
401
+ '--shallow-submodules',
402
+ ];
403
+ // Add --branch flag for specific ref (works for both branches and tags)
404
+ if (ref) {
405
+ args.push('--branch', ref);
406
+ }
407
+ // If sha is specified, use --no-checkout since we'll checkout the SHA separately
408
+ if (sha) {
409
+ args.push('--no-checkout');
410
+ }
411
+ args.push(gitUrl, targetPath);
412
+ const cloneStarted = performance.now();
413
+ const cloneResult = await execFileNoThrow(gitExe(), args);
414
+ if (cloneResult.code !== 0) {
415
+ logPluginFetch('plugin_clone', gitUrl, 'failure', performance.now() - cloneStarted, classifyFetchError(cloneResult.stderr));
416
+ throw new Error(`Failed to clone repository: ${cloneResult.stderr}`);
417
+ }
418
+ // If sha is specified, fetch and checkout that specific commit
419
+ if (sha) {
420
+ // Try shallow fetch of the specific SHA first (most efficient)
421
+ const shallowFetchResult = await execFileNoThrowWithCwd(gitExe(), ['fetch', '--depth', '1', 'origin', sha], { cwd: targetPath });
422
+ if (shallowFetchResult.code !== 0) {
423
+ // Some servers don't support fetching arbitrary SHAs
424
+ // Fall back to unshallow fetch to get full history
425
+ logForDebugging(`Shallow fetch of SHA ${sha} failed, falling back to unshallow fetch`);
426
+ const unshallowResult = await execFileNoThrowWithCwd(gitExe(), ['fetch', '--unshallow'], { cwd: targetPath });
427
+ if (unshallowResult.code !== 0) {
428
+ logPluginFetch('plugin_clone', gitUrl, 'failure', performance.now() - cloneStarted, classifyFetchError(unshallowResult.stderr));
429
+ throw new Error(`Failed to fetch commit ${sha}: ${unshallowResult.stderr}`);
430
+ }
431
+ }
432
+ // Checkout the specific commit
433
+ const checkoutResult = await execFileNoThrowWithCwd(gitExe(), ['checkout', sha], { cwd: targetPath });
434
+ if (checkoutResult.code !== 0) {
435
+ logPluginFetch('plugin_clone', gitUrl, 'failure', performance.now() - cloneStarted, classifyFetchError(checkoutResult.stderr));
436
+ throw new Error(`Failed to checkout commit ${sha}: ${checkoutResult.stderr}`);
437
+ }
438
+ }
439
+ // Fire success only after ALL network ops (clone + optional SHA fetch)
440
+ // complete — same telemetry-scope discipline as mcpb and marketplace_url.
441
+ logPluginFetch('plugin_clone', gitUrl, 'success', performance.now() - cloneStarted);
442
+ }
443
+ /**
444
+ * Install a plugin from a git URL
445
+ */
446
+ async function installFromGit(gitUrl, targetPath, ref, sha) {
447
+ const safeUrl = validateGitUrl(gitUrl);
448
+ await gitClone(safeUrl, targetPath, ref, sha);
449
+ const refMessage = ref ? ` (ref: ${ref})` : '';
450
+ logForDebugging(`Cloned repository from ${safeUrl}${refMessage} to ${targetPath}`);
451
+ }
452
+ /**
453
+ * Install a plugin from GitHub
454
+ */
455
+ async function installFromGitHub(repo, targetPath, ref, sha) {
456
+ if (!/^[a-zA-Z0-9-_.]+\/[a-zA-Z0-9-_.]+$/.test(repo)) {
457
+ throw new Error(`Invalid GitHub repository format: ${repo}. Expected format: owner/repo`);
458
+ }
459
+ // Use HTTPS for CCR (no SSH keys), SSH for normal CLI
460
+ const gitUrl = isEnvTruthy(process.env.THADDEUS_REMOTE)
461
+ ? `https://github.com/${repo}.git`
462
+ : `git@github.com:${repo}.git`;
463
+ return installFromGit(gitUrl, targetPath, ref, sha);
464
+ }
465
+ /**
466
+ * Resolve a git-subdir `url` field to a clonable git URL.
467
+ * Accepts GitHub owner/repo shorthand (converted to ssh or https depending on
468
+ * THADDEUS_REMOTE) or any URL that passes validateGitUrl (https, http,
469
+ * file, git@ ssh).
470
+ */
471
+ function resolveGitSubdirUrl(url) {
472
+ if (/^[a-zA-Z0-9-_.]+\/[a-zA-Z0-9-_.]+$/.test(url)) {
473
+ return isEnvTruthy(process.env.THADDEUS_REMOTE)
474
+ ? `https://github.com/${url}.git`
475
+ : `git@github.com:${url}.git`;
476
+ }
477
+ return validateGitUrl(url);
478
+ }
479
+ /**
480
+ * Install a plugin from a subdirectory of a git repository (exported for
481
+ * testing).
482
+ *
483
+ * Uses partial clone (--filter=tree:0) + sparse-checkout so only the tree
484
+ * objects along the path and the blobs under it are downloaded. For large
485
+ * monorepos this is dramatically cheaper than a full clone — the tree objects
486
+ * for a million-file repo can be hundreds of MB, all avoided here.
487
+ *
488
+ * Sequence:
489
+ * 1. clone --depth 1 --filter=tree:0 --no-checkout [--branch ref]
490
+ * 2. sparse-checkout set --cone -- <path>
491
+ * 3. If sha: fetch --depth 1 origin <sha> (fallback: --unshallow), then
492
+ * checkout <sha>. The partial-clone filter is stored in remote config so
493
+ * subsequent fetches respect it; --unshallow gets all commits but trees
494
+ * and blobs remain lazy.
495
+ * If no sha: checkout HEAD (points to ref if --branch was used).
496
+ * 4. Move <cloneDir>/<path> to targetPath and discard the clone.
497
+ *
498
+ * The clone is ephemeral — it goes into a sibling temp directory and is
499
+ * removed after the subdir is extracted. targetPath ends up containing only
500
+ * the plugin files with no .git directory.
501
+ */
502
+ export async function installFromGitSubdir(url, targetPath, subdirPath, ref, sha) {
503
+ if (!(await checkGitAvailable())) {
504
+ throw new Error('git-subdir plugin source requires git to be installed and on PATH. ' +
505
+ 'Install git (version 2.25 or later for sparse-checkout cone mode) and try again.');
506
+ }
507
+ const gitUrl = resolveGitSubdirUrl(url);
508
+ // Clone into a sibling temp dir (same filesystem → rename works, no EXDEV).
509
+ const cloneDir = `${targetPath}.clone`;
510
+ const cloneArgs = [
511
+ 'clone',
512
+ '--depth',
513
+ '1',
514
+ '--filter=tree:0',
515
+ '--no-checkout',
516
+ ];
517
+ if (ref) {
518
+ cloneArgs.push('--branch', ref);
519
+ }
520
+ cloneArgs.push(gitUrl, cloneDir);
521
+ const cloneResult = await execFileNoThrow(gitExe(), cloneArgs);
522
+ if (cloneResult.code !== 0) {
523
+ throw new Error(`Failed to clone repository for git-subdir source: ${cloneResult.stderr}`);
524
+ }
525
+ try {
526
+ const sparseResult = await execFileNoThrowWithCwd(gitExe(), ['sparse-checkout', 'set', '--cone', '--', subdirPath], { cwd: cloneDir });
527
+ if (sparseResult.code !== 0) {
528
+ throw new Error(`git sparse-checkout set failed (git >= 2.25 required for cone mode): ${sparseResult.stderr}`);
529
+ }
530
+ // Capture the resolved commit SHA before discarding the clone. The
531
+ // extracted subdir has no .git, so the caller can't rev-parse it later.
532
+ // If the source specified a full 40-char sha we already know it; otherwise
533
+ // read HEAD (which points to ref's tip after --branch, or the remote
534
+ // default branch if no ref was given).
535
+ let resolvedSha;
536
+ if (sha) {
537
+ const fetchSha = await execFileNoThrowWithCwd(gitExe(), ['fetch', '--depth', '1', 'origin', sha], { cwd: cloneDir });
538
+ if (fetchSha.code !== 0) {
539
+ logForDebugging(`Shallow fetch of SHA ${sha} failed for git-subdir, falling back to unshallow fetch`);
540
+ const unshallow = await execFileNoThrowWithCwd(gitExe(), ['fetch', '--unshallow'], { cwd: cloneDir });
541
+ if (unshallow.code !== 0) {
542
+ throw new Error(`Failed to fetch commit ${sha}: ${unshallow.stderr}`);
543
+ }
544
+ }
545
+ const checkout = await execFileNoThrowWithCwd(gitExe(), ['checkout', sha], { cwd: cloneDir });
546
+ if (checkout.code !== 0) {
547
+ throw new Error(`Failed to checkout commit ${sha}: ${checkout.stderr}`);
548
+ }
549
+ resolvedSha = sha;
550
+ }
551
+ else {
552
+ // checkout HEAD materializes the working tree (this is where blobs are
553
+ // lazy-fetched — the slow, network-bound step). It doesn't move HEAD;
554
+ // --branch at clone time already positioned it. rev-parse HEAD is a
555
+ // purely read-only ref lookup (no index lock), so it runs safely in
556
+ // parallel with checkout and we avoid waiting on the network for it.
557
+ const [checkout, revParse] = await Promise.all([
558
+ execFileNoThrowWithCwd(gitExe(), ['checkout', 'HEAD'], {
559
+ cwd: cloneDir,
560
+ }),
561
+ execFileNoThrowWithCwd(gitExe(), ['rev-parse', 'HEAD'], {
562
+ cwd: cloneDir,
563
+ }),
564
+ ]);
565
+ if (checkout.code !== 0) {
566
+ throw new Error(`git checkout after sparse-checkout failed: ${checkout.stderr}`);
567
+ }
568
+ if (revParse.code === 0) {
569
+ resolvedSha = revParse.stdout.trim();
570
+ }
571
+ }
572
+ // Path traversal guard: resolve+verify the subdir stays inside cloneDir
573
+ // before moving it out. rename ENOENT is wrapped with a friendlier
574
+ // message that references the source path, not internal temp dirs.
575
+ const resolvedSubdir = validatePathWithinBase(cloneDir, subdirPath);
576
+ try {
577
+ await rename(resolvedSubdir, targetPath);
578
+ }
579
+ catch (e) {
580
+ if (isENOENT(e)) {
581
+ throw new Error(`Subdirectory '${subdirPath}' not found in repository ${gitUrl}${ref ? ` (ref: ${ref})` : ''}. ` +
582
+ 'Check that the path is correct and exists at the specified ref/sha.');
583
+ }
584
+ throw e;
585
+ }
586
+ const refMsg = ref ? ` ref=${ref}` : '';
587
+ const shaMsg = resolvedSha ? ` sha=${resolvedSha}` : '';
588
+ logForDebugging(`Extracted subdir ${subdirPath} from ${gitUrl}${refMsg}${shaMsg} to ${targetPath}`);
589
+ return resolvedSha;
590
+ }
591
+ finally {
592
+ await rm(cloneDir, { recursive: true, force: true });
593
+ }
594
+ }
595
+ /**
596
+ * Install a plugin from a local path
597
+ */
598
+ async function installFromLocal(sourcePath, targetPath) {
599
+ if (!(await pathExists(sourcePath))) {
600
+ throw new Error(`Source path does not exist: ${sourcePath}`);
601
+ }
602
+ await copyDir(sourcePath, targetPath);
603
+ const gitPath = join(targetPath, '.git');
604
+ await rm(gitPath, { recursive: true, force: true });
605
+ }
606
+ /**
607
+ * Generate a temporary cache name for a plugin
608
+ */
609
+ export function generateTemporaryCacheNameForPlugin(source) {
610
+ const timestamp = Date.now();
611
+ const random = Math.random().toString(36).substring(2, 8);
612
+ let prefix;
613
+ if (typeof source === 'string') {
614
+ prefix = 'local';
615
+ }
616
+ else {
617
+ switch (source.source) {
618
+ case 'npm':
619
+ prefix = 'npm';
620
+ break;
621
+ case 'pip':
622
+ prefix = 'pip';
623
+ break;
624
+ case 'github':
625
+ prefix = 'github';
626
+ break;
627
+ case 'url':
628
+ prefix = 'git';
629
+ break;
630
+ case 'git-subdir':
631
+ prefix = 'subdir';
632
+ break;
633
+ default:
634
+ prefix = 'unknown';
635
+ }
636
+ }
637
+ return `temp_${prefix}_${timestamp}_${random}`;
638
+ }
639
+ /**
640
+ * Cache a plugin from an external source
641
+ */
642
+ export async function cachePlugin(source, options) {
643
+ const cachePath = getPluginCachePath();
644
+ await getFsImplementation().mkdir(cachePath);
645
+ const tempName = generateTemporaryCacheNameForPlugin(source);
646
+ const tempPath = join(cachePath, tempName);
647
+ let shouldCleanup = false;
648
+ let gitCommitSha;
649
+ try {
650
+ logForDebugging(`Caching plugin from source: ${jsonStringify(source)} to temporary path ${tempPath}`);
651
+ shouldCleanup = true;
652
+ if (typeof source === 'string') {
653
+ await installFromLocal(source, tempPath);
654
+ }
655
+ else {
656
+ switch (source.source) {
657
+ case 'npm':
658
+ await installFromNpm(source.package, tempPath, {
659
+ registry: source.registry,
660
+ version: source.version,
661
+ });
662
+ break;
663
+ case 'github':
664
+ await installFromGitHub(source.repo, tempPath, source.ref, source.sha);
665
+ break;
666
+ case 'url':
667
+ await installFromGit(source.url, tempPath, source.ref, source.sha);
668
+ break;
669
+ case 'git-subdir':
670
+ gitCommitSha = await installFromGitSubdir(source.url, tempPath, source.path, source.ref, source.sha);
671
+ break;
672
+ case 'pip':
673
+ throw new Error('Python package plugins are not yet supported');
674
+ default:
675
+ throw new Error(`Unsupported plugin source type`);
676
+ }
677
+ }
678
+ }
679
+ catch (error) {
680
+ if (shouldCleanup && (await pathExists(tempPath))) {
681
+ logForDebugging(`Cleaning up failed installation at ${tempPath}`);
682
+ try {
683
+ await rm(tempPath, { recursive: true, force: true });
684
+ }
685
+ catch (cleanupError) {
686
+ logForDebugging(`Failed to clean up installation: ${cleanupError}`, {
687
+ level: 'error',
688
+ });
689
+ }
690
+ }
691
+ throw error;
692
+ }
693
+ const manifestPath = join(tempPath, '.claude-plugin', 'plugin.json');
694
+ const legacyManifestPath = join(tempPath, 'plugin.json');
695
+ let manifest;
696
+ if (await pathExists(manifestPath)) {
697
+ try {
698
+ const content = await readFile(manifestPath, { encoding: 'utf-8' });
699
+ const parsed = jsonParse(content);
700
+ const result = PluginManifestSchema().safeParse(parsed);
701
+ if (result.success) {
702
+ manifest = result.data;
703
+ }
704
+ else {
705
+ // Manifest exists but is invalid - throw error
706
+ const errors = result.error.issues
707
+ .map(err => `${err.path.join('.')}: ${err.message}`)
708
+ .join(', ');
709
+ logForDebugging(`Invalid manifest at ${manifestPath}: ${errors}`, {
710
+ level: 'error',
711
+ });
712
+ throw new Error(`Plugin has an invalid manifest file at ${manifestPath}. Validation errors: ${errors}`);
713
+ }
714
+ }
715
+ catch (error) {
716
+ // Check if this is a validation error we just threw
717
+ if (error instanceof Error &&
718
+ error.message.includes('invalid manifest file')) {
719
+ throw error;
720
+ }
721
+ // JSON parse error
722
+ const errorMsg = errorMessage(error);
723
+ logForDebugging(`Failed to parse manifest at ${manifestPath}: ${errorMsg}`, {
724
+ level: 'error',
725
+ });
726
+ throw new Error(`Plugin has a corrupt manifest file at ${manifestPath}. JSON parse error: ${errorMsg}`);
727
+ }
728
+ }
729
+ else if (await pathExists(legacyManifestPath)) {
730
+ try {
731
+ const content = await readFile(legacyManifestPath, {
732
+ encoding: 'utf-8',
733
+ });
734
+ const parsed = jsonParse(content);
735
+ const result = PluginManifestSchema().safeParse(parsed);
736
+ if (result.success) {
737
+ manifest = result.data;
738
+ }
739
+ else {
740
+ // Manifest exists but is invalid - throw error
741
+ const errors = result.error.issues
742
+ .map(err => `${err.path.join('.')}: ${err.message}`)
743
+ .join(', ');
744
+ logForDebugging(`Invalid legacy manifest at ${legacyManifestPath}: ${errors}`, { level: 'error' });
745
+ throw new Error(`Plugin has an invalid manifest file at ${legacyManifestPath}. Validation errors: ${errors}`);
746
+ }
747
+ }
748
+ catch (error) {
749
+ // Check if this is a validation error we just threw
750
+ if (error instanceof Error &&
751
+ error.message.includes('invalid manifest file')) {
752
+ throw error;
753
+ }
754
+ // JSON parse error
755
+ const errorMsg = errorMessage(error);
756
+ logForDebugging(`Failed to parse legacy manifest at ${legacyManifestPath}: ${errorMsg}`, {
757
+ level: 'error',
758
+ });
759
+ throw new Error(`Plugin has a corrupt manifest file at ${legacyManifestPath}. JSON parse error: ${errorMsg}`);
760
+ }
761
+ }
762
+ else {
763
+ manifest = options?.manifest || {
764
+ name: tempName,
765
+ description: `Plugin cached from ${typeof source === 'string' ? source : source.source}`,
766
+ };
767
+ }
768
+ const finalName = manifest.name.replace(/[^a-zA-Z0-9-_]/g, '-');
769
+ const finalPath = join(cachePath, finalName);
770
+ if (await pathExists(finalPath)) {
771
+ logForDebugging(`Removing old cached version at ${finalPath}`);
772
+ await rm(finalPath, { recursive: true, force: true });
773
+ }
774
+ await rename(tempPath, finalPath);
775
+ logForDebugging(`Successfully cached plugin ${manifest.name} to ${finalPath}`);
776
+ return {
777
+ path: finalPath,
778
+ manifest,
779
+ ...(gitCommitSha && { gitCommitSha }),
780
+ };
781
+ }
782
+ /**
783
+ * Loads and validates a plugin manifest from a JSON file.
784
+ *
785
+ * The manifest provides metadata about the plugin including name, version,
786
+ * description, author, and other optional fields. If no manifest exists,
787
+ * a minimal one is created to allow the plugin to function.
788
+ *
789
+ * Example plugin.json:
790
+ * ```json
791
+ * {
792
+ * "name": "code-assistant",
793
+ * "version": "1.2.0",
794
+ * "description": "AI-powered code assistance tools",
795
+ * "author": {
796
+ * "name": "John Doe",
797
+ * "email": "john@example.com"
798
+ * },
799
+ * "keywords": ["coding", "ai", "assistant"],
800
+ * "homepage": "https://example.com/code-assistant",
801
+ * "hooks": "./custom-hooks.json",
802
+ * "commands": ["./extra-commands/*.md"]
803
+ * }
804
+ * ```
805
+ */
806
+ /**
807
+ * Loads and validates a plugin manifest from a JSON file.
808
+ *
809
+ * The manifest provides metadata about the plugin including name, version,
810
+ * description, author, and other optional fields. If no manifest exists,
811
+ * a minimal one is created to allow the plugin to function.
812
+ *
813
+ * Unknown keys in the manifest are silently stripped (PluginManifestSchema
814
+ * uses zod's default strip behavior, not .strict()). Type mismatches and
815
+ * other validation errors still fail.
816
+ *
817
+ * Behavior:
818
+ * - Missing file: Creates default with provided name and source
819
+ * - Invalid JSON: Throws error with parse details
820
+ * - Schema validation failure: Throws error with validation details
821
+ *
822
+ * @param manifestPath - Full path to the plugin.json file
823
+ * @param pluginName - Name to use in default manifest (e.g., "my-plugin")
824
+ * @param source - Source description for default manifest (e.g., "git:repo" or ".claude-plugin/name")
825
+ * @returns A valid PluginManifest object (either loaded or default)
826
+ * @throws Error if manifest exists but is invalid (corrupt JSON or schema validation failure)
827
+ */
828
+ export async function loadPluginManifest(manifestPath, pluginName, source) {
829
+ // Check if manifest file exists
830
+ // If not, create a minimal manifest to allow plugin to function
831
+ if (!(await pathExists(manifestPath))) {
832
+ // Return default manifest with provided name and source
833
+ return {
834
+ name: pluginName,
835
+ description: `Plugin from ${source}`,
836
+ };
837
+ }
838
+ try {
839
+ // Read and parse the manifest JSON file
840
+ const content = await readFile(manifestPath, { encoding: 'utf-8' });
841
+ const parsedJson = jsonParse(content);
842
+ // Validate against the PluginManifest schema
843
+ const result = PluginManifestSchema().safeParse(parsedJson);
844
+ if (result.success) {
845
+ // Valid manifest - return the validated data
846
+ return result.data;
847
+ }
848
+ // Schema validation failed but JSON was valid
849
+ const errors = result.error.issues
850
+ .map(err => err.path.length > 0
851
+ ? `${err.path.join('.')}: ${err.message}`
852
+ : err.message)
853
+ .join(', ');
854
+ logForDebugging(`Plugin ${pluginName} has an invalid manifest file at ${manifestPath}. Validation errors: ${errors}`, { level: 'error' });
855
+ throw new Error(`Plugin ${pluginName} has an invalid manifest file at ${manifestPath}.\n\nValidation errors: ${errors}`);
856
+ }
857
+ catch (error) {
858
+ // Check if this is the error we just threw (validation error)
859
+ if (error instanceof Error &&
860
+ error.message.includes('invalid manifest file')) {
861
+ throw error;
862
+ }
863
+ // JSON parsing failed or file read error
864
+ const errorMsg = errorMessage(error);
865
+ logForDebugging(`Plugin ${pluginName} has a corrupt manifest file at ${manifestPath}. Parse error: ${errorMsg}`, { level: 'error' });
866
+ throw new Error(`Plugin ${pluginName} has a corrupt manifest file at ${manifestPath}.\n\nJSON parse error: ${errorMsg}`);
867
+ }
868
+ }
869
+ /**
870
+ * Loads and validates plugin hooks configuration from a JSON file.
871
+ * IMPORTANT: Only call this when the hooks file is expected to exist.
872
+ *
873
+ * @param hooksConfigPath - Full path to the hooks.json file
874
+ * @param pluginName - Plugin name for error messages
875
+ * @returns Validated HooksSettings
876
+ * @throws Error if file doesn't exist or is invalid
877
+ */
878
+ async function loadPluginHooks(hooksConfigPath, pluginName) {
879
+ if (!(await pathExists(hooksConfigPath))) {
880
+ throw new Error(`Hooks file not found at ${hooksConfigPath} for plugin ${pluginName}. If the manifest declares hooks, the file must exist.`);
881
+ }
882
+ const content = await readFile(hooksConfigPath, { encoding: 'utf-8' });
883
+ const rawHooksConfig = jsonParse(content);
884
+ // The hooks.json file has a wrapper structure with description and hooks
885
+ // Use PluginHooksSchema to validate and extract the hooks property
886
+ const validatedPluginHooks = PluginHooksSchema().parse(rawHooksConfig);
887
+ return validatedPluginHooks.hooks;
888
+ }
889
+ /**
890
+ * Validate a list of plugin component relative paths by checking existence in parallel.
891
+ *
892
+ * This helper parallelizes the pathExists checks (the expensive async part) while
893
+ * preserving deterministic error/log ordering by iterating results sequentially.
894
+ *
895
+ * Introduced to fix a perf regression from the sync→async fs migration: sequential
896
+ * `for { await pathExists }` loops add ~1-5ms of event-loop overhead per iteration.
897
+ * With many plugins × several component types, this compounds to hundreds of ms.
898
+ *
899
+ * @param relPaths - Relative paths from the manifest/marketplace entry to validate
900
+ * @param pluginPath - Plugin root directory to resolve relative paths against
901
+ * @param pluginName - Plugin name for error messages
902
+ * @param source - Source identifier for PluginError records
903
+ * @param component - Which component these paths belong to (for error records)
904
+ * @param componentLabel - Human-readable label for log messages (e.g. "Agent", "Skill")
905
+ * @param contextLabel - Where the path came from, for log messages
906
+ * (e.g. "specified in manifest but", "from marketplace entry")
907
+ * @param errors - Error array to push path-not-found errors into (mutated)
908
+ * @returns Array of full paths that exist on disk, in original order
909
+ */
910
+ async function validatePluginPaths(relPaths, pluginPath, pluginName, source, component, componentLabel, contextLabel, errors) {
911
+ // Parallelize the async pathExists checks
912
+ const checks = await Promise.all(relPaths.map(async (relPath) => {
913
+ const fullPath = join(pluginPath, relPath);
914
+ return { relPath, fullPath, exists: await pathExists(fullPath) };
915
+ }));
916
+ // Process results in original order to keep error/log ordering deterministic
917
+ const validPaths = [];
918
+ for (const { relPath, fullPath, exists } of checks) {
919
+ if (exists) {
920
+ validPaths.push(fullPath);
921
+ }
922
+ else {
923
+ logForDebugging(`${componentLabel} path ${relPath} ${contextLabel} not found at ${fullPath} for ${pluginName}`, { level: 'warn' });
924
+ logError(new Error(`Plugin component file not found: ${fullPath} for ${pluginName}`));
925
+ errors.push({
926
+ type: 'path-not-found',
927
+ source,
928
+ plugin: pluginName,
929
+ path: fullPath,
930
+ component,
931
+ });
932
+ }
933
+ }
934
+ return validPaths;
935
+ }
936
+ /**
937
+ * Creates a LoadedPlugin object from a plugin directory path.
938
+ *
939
+ * This is the central function that assembles a complete plugin representation
940
+ * by scanning the plugin directory structure and loading all components.
941
+ * It handles both fully-featured plugins with manifests and minimal plugins
942
+ * with just commands or agents directories.
943
+ *
944
+ * Directory structure it looks for:
945
+ * ```
946
+ * plugin-directory/
947
+ * ├── plugin.json # Optional: Plugin manifest
948
+ * ├── commands/ # Optional: Custom slash commands
949
+ * │ ├── build.md # /build command
950
+ * │ └── test.md # /test command
951
+ * ├── agents/ # Optional: Custom AI agents
952
+ * │ ├── reviewer.md # Code review agent
953
+ * │ └── optimizer.md # Performance optimization agent
954
+ * └── hooks/ # Optional: Hook configurations
955
+ * └── hooks.json # Hook definitions
956
+ * ```
957
+ *
958
+ * Component detection:
959
+ * - Manifest: Loaded from plugin.json if present, otherwise creates default
960
+ * - Commands: Sets commandsPath if commands/ directory exists
961
+ * - Agents: Sets agentsPath if agents/ directory exists
962
+ * - Hooks: Loads from hooks/hooks.json if present
963
+ *
964
+ * The function is tolerant of missing components - a plugin can have
965
+ * any combination of the above directories/files. Missing component files
966
+ * are reported as errors but don't prevent plugin loading.
967
+ *
968
+ * @param pluginPath - Absolute path to the plugin directory
969
+ * @param source - Source identifier (e.g., "git:repo", ".claude-plugin/my-plugin")
970
+ * @param enabled - Initial enabled state (may be overridden by settings)
971
+ * @param fallbackName - Name to use if manifest doesn't specify one
972
+ * @param strict - When true, adds errors for duplicate hook files (default: true)
973
+ * @returns Object containing the LoadedPlugin and any errors encountered
974
+ */
975
+ export async function createPluginFromPath(pluginPath, source, enabled, fallbackName, strict = true) {
976
+ const errors = [];
977
+ // Step 1: Load or create the plugin manifest
978
+ // This provides metadata about the plugin (name, version, etc.)
979
+ const manifestPath = join(pluginPath, '.claude-plugin', 'plugin.json');
980
+ const manifest = await loadPluginManifest(manifestPath, fallbackName, source);
981
+ // Step 2: Create the base plugin object
982
+ // Start with required fields from manifest and parameters
983
+ const plugin = {
984
+ name: manifest.name, // Use name from manifest (or fallback)
985
+ manifest, // Store full manifest for later use
986
+ path: pluginPath, // Absolute path to plugin directory
987
+ source, // Source identifier (e.g., "git:repo" or ".claude-plugin/name")
988
+ repository: source, // For backward compatibility with Plugin Repository
989
+ enabled, // Current enabled state
990
+ };
991
+ // Step 3: Auto-detect optional directories in parallel
992
+ const [commandsDirExists, agentsDirExists, skillsDirExists, outputStylesDirExists,] = await Promise.all([
993
+ !manifest.commands ? pathExists(join(pluginPath, 'commands')) : false,
994
+ !manifest.agents ? pathExists(join(pluginPath, 'agents')) : false,
995
+ !manifest.skills ? pathExists(join(pluginPath, 'skills')) : false,
996
+ !manifest.outputStyles
997
+ ? pathExists(join(pluginPath, 'output-styles'))
998
+ : false,
999
+ ]);
1000
+ const commandsPath = join(pluginPath, 'commands');
1001
+ if (commandsDirExists) {
1002
+ plugin.commandsPath = commandsPath;
1003
+ }
1004
+ // Step 3a: Process additional command paths from manifest
1005
+ if (manifest.commands) {
1006
+ // Check if it's an object mapping (record of command name → metadata)
1007
+ const firstValue = Object.values(manifest.commands)[0];
1008
+ if (typeof manifest.commands === 'object' &&
1009
+ !Array.isArray(manifest.commands) &&
1010
+ firstValue &&
1011
+ typeof firstValue === 'object' &&
1012
+ ('source' in firstValue || 'content' in firstValue)) {
1013
+ // Object mapping format: { "about": { "source": "./README.md", ... } }
1014
+ const commandsMetadata = {};
1015
+ const validPaths = [];
1016
+ // Parallelize pathExists checks; process results in order to keep
1017
+ // error/log ordering deterministic.
1018
+ const entries = Object.entries(manifest.commands);
1019
+ const checks = await Promise.all(entries.map(async ([commandName, metadata]) => {
1020
+ if (!metadata || typeof metadata !== 'object') {
1021
+ return { commandName, metadata, kind: 'skip' };
1022
+ }
1023
+ if (metadata.source) {
1024
+ const fullPath = join(pluginPath, metadata.source);
1025
+ return {
1026
+ commandName,
1027
+ metadata,
1028
+ kind: 'source',
1029
+ fullPath,
1030
+ exists: await pathExists(fullPath),
1031
+ };
1032
+ }
1033
+ if (metadata.content) {
1034
+ return { commandName, metadata, kind: 'content' };
1035
+ }
1036
+ return { commandName, metadata, kind: 'skip' };
1037
+ }));
1038
+ for (const check of checks) {
1039
+ if (check.kind === 'skip')
1040
+ continue;
1041
+ if (check.kind === 'content') {
1042
+ // For inline content commands, add metadata without path
1043
+ commandsMetadata[check.commandName] = check.metadata;
1044
+ continue;
1045
+ }
1046
+ // kind === 'source'
1047
+ if (check.exists) {
1048
+ validPaths.push(check.fullPath);
1049
+ commandsMetadata[check.commandName] = check.metadata;
1050
+ }
1051
+ else {
1052
+ logForDebugging(`Command ${check.commandName} path ${check.metadata.source} specified in manifest but not found at ${check.fullPath} for ${manifest.name}`, { level: 'warn' });
1053
+ logError(new Error(`Plugin component file not found: ${check.fullPath} for ${manifest.name}`));
1054
+ errors.push({
1055
+ type: 'path-not-found',
1056
+ source,
1057
+ plugin: manifest.name,
1058
+ path: check.fullPath,
1059
+ component: 'commands',
1060
+ });
1061
+ }
1062
+ }
1063
+ // Set commandsPaths if there are file-based commands
1064
+ if (validPaths.length > 0) {
1065
+ plugin.commandsPaths = validPaths;
1066
+ }
1067
+ // Set commandsMetadata if there are any commands (file-based or inline)
1068
+ if (Object.keys(commandsMetadata).length > 0) {
1069
+ plugin.commandsMetadata = commandsMetadata;
1070
+ }
1071
+ }
1072
+ else {
1073
+ // Path or array of paths format
1074
+ const commandPaths = Array.isArray(manifest.commands)
1075
+ ? manifest.commands
1076
+ : [manifest.commands];
1077
+ // Parallelize pathExists checks; process results in order.
1078
+ const checks = await Promise.all(commandPaths.map(async (cmdPath) => {
1079
+ if (typeof cmdPath !== 'string') {
1080
+ return { cmdPath, kind: 'invalid' };
1081
+ }
1082
+ const fullPath = join(pluginPath, cmdPath);
1083
+ return {
1084
+ cmdPath,
1085
+ kind: 'path',
1086
+ fullPath,
1087
+ exists: await pathExists(fullPath),
1088
+ };
1089
+ }));
1090
+ const validPaths = [];
1091
+ for (const check of checks) {
1092
+ if (check.kind === 'invalid') {
1093
+ logForDebugging(`Unexpected command format in manifest for ${manifest.name}`, { level: 'error' });
1094
+ continue;
1095
+ }
1096
+ if (check.exists) {
1097
+ validPaths.push(check.fullPath);
1098
+ }
1099
+ else {
1100
+ logForDebugging(`Command path ${check.cmdPath} specified in manifest but not found at ${check.fullPath} for ${manifest.name}`, { level: 'warn' });
1101
+ logError(new Error(`Plugin component file not found: ${check.fullPath} for ${manifest.name}`));
1102
+ errors.push({
1103
+ type: 'path-not-found',
1104
+ source,
1105
+ plugin: manifest.name,
1106
+ path: check.fullPath,
1107
+ component: 'commands',
1108
+ });
1109
+ }
1110
+ }
1111
+ if (validPaths.length > 0) {
1112
+ plugin.commandsPaths = validPaths;
1113
+ }
1114
+ }
1115
+ }
1116
+ // Step 4: Register agents directory if detected
1117
+ const agentsPath = join(pluginPath, 'agents');
1118
+ if (agentsDirExists) {
1119
+ plugin.agentsPath = agentsPath;
1120
+ }
1121
+ // Step 4a: Process additional agent paths from manifest
1122
+ if (manifest.agents) {
1123
+ const agentPaths = Array.isArray(manifest.agents)
1124
+ ? manifest.agents
1125
+ : [manifest.agents];
1126
+ const validPaths = await validatePluginPaths(agentPaths, pluginPath, manifest.name, source, 'agents', 'Agent', 'specified in manifest but', errors);
1127
+ if (validPaths.length > 0) {
1128
+ plugin.agentsPaths = validPaths;
1129
+ }
1130
+ }
1131
+ // Step 4b: Register skills directory if detected
1132
+ const skillsPath = join(pluginPath, 'skills');
1133
+ if (skillsDirExists) {
1134
+ plugin.skillsPath = skillsPath;
1135
+ }
1136
+ // Step 4c: Process additional skill paths from manifest
1137
+ if (manifest.skills) {
1138
+ const skillPaths = Array.isArray(manifest.skills)
1139
+ ? manifest.skills
1140
+ : [manifest.skills];
1141
+ const validPaths = await validatePluginPaths(skillPaths, pluginPath, manifest.name, source, 'skills', 'Skill', 'specified in manifest but', errors);
1142
+ if (validPaths.length > 0) {
1143
+ plugin.skillsPaths = validPaths;
1144
+ }
1145
+ }
1146
+ // Step 4d: Register output-styles directory if detected
1147
+ const outputStylesPath = join(pluginPath, 'output-styles');
1148
+ if (outputStylesDirExists) {
1149
+ plugin.outputStylesPath = outputStylesPath;
1150
+ }
1151
+ // Step 4e: Process additional output style paths from manifest
1152
+ if (manifest.outputStyles) {
1153
+ const outputStylePaths = Array.isArray(manifest.outputStyles)
1154
+ ? manifest.outputStyles
1155
+ : [manifest.outputStyles];
1156
+ const validPaths = await validatePluginPaths(outputStylePaths, pluginPath, manifest.name, source, 'output-styles', 'Output style', 'specified in manifest but', errors);
1157
+ if (validPaths.length > 0) {
1158
+ plugin.outputStylesPaths = validPaths;
1159
+ }
1160
+ }
1161
+ // Step 5: Load hooks configuration
1162
+ let mergedHooks;
1163
+ const loadedHookPaths = new Set(); // Track loaded hook files
1164
+ // Load from standard hooks/hooks.json if it exists
1165
+ const standardHooksPath = join(pluginPath, 'hooks', 'hooks.json');
1166
+ if (await pathExists(standardHooksPath)) {
1167
+ try {
1168
+ mergedHooks = await loadPluginHooks(standardHooksPath, manifest.name);
1169
+ // Track the normalized path to prevent duplicate loading
1170
+ try {
1171
+ loadedHookPaths.add(await realpath(standardHooksPath));
1172
+ }
1173
+ catch {
1174
+ // If realpathSync fails, use original path
1175
+ loadedHookPaths.add(standardHooksPath);
1176
+ }
1177
+ logForDebugging(`Loaded hooks from standard location for plugin ${manifest.name}: ${standardHooksPath}`);
1178
+ }
1179
+ catch (error) {
1180
+ const errorMsg = errorMessage(error);
1181
+ logForDebugging(`Failed to load hooks for ${manifest.name}: ${errorMsg}`, {
1182
+ level: 'error',
1183
+ });
1184
+ logError(toError(error));
1185
+ errors.push({
1186
+ type: 'hook-load-failed',
1187
+ source,
1188
+ plugin: manifest.name,
1189
+ hookPath: standardHooksPath,
1190
+ reason: errorMsg,
1191
+ });
1192
+ }
1193
+ }
1194
+ // Load and merge hooks from manifest.hooks if specified
1195
+ if (manifest.hooks) {
1196
+ const manifestHooksArray = Array.isArray(manifest.hooks)
1197
+ ? manifest.hooks
1198
+ : [manifest.hooks];
1199
+ for (const hookSpec of manifestHooksArray) {
1200
+ if (typeof hookSpec === 'string') {
1201
+ // Path to additional hooks file
1202
+ const hookFilePath = join(pluginPath, hookSpec);
1203
+ if (!(await pathExists(hookFilePath))) {
1204
+ logForDebugging(`Hooks file ${hookSpec} specified in manifest but not found at ${hookFilePath} for ${manifest.name}`, { level: 'error' });
1205
+ logError(new Error(`Plugin component file not found: ${hookFilePath} for ${manifest.name}`));
1206
+ errors.push({
1207
+ type: 'path-not-found',
1208
+ source,
1209
+ plugin: manifest.name,
1210
+ path: hookFilePath,
1211
+ component: 'hooks',
1212
+ });
1213
+ continue;
1214
+ }
1215
+ // Check if this path resolves to an already-loaded hooks file
1216
+ let normalizedPath;
1217
+ try {
1218
+ normalizedPath = await realpath(hookFilePath);
1219
+ }
1220
+ catch {
1221
+ // If realpathSync fails, use original path
1222
+ normalizedPath = hookFilePath;
1223
+ }
1224
+ if (loadedHookPaths.has(normalizedPath)) {
1225
+ logForDebugging(`Skipping duplicate hooks file for plugin ${manifest.name}: ${hookSpec} ` +
1226
+ `(resolves to already-loaded file: ${normalizedPath})`);
1227
+ if (strict) {
1228
+ const errorMsg = `Duplicate hooks file detected: ${hookSpec} resolves to already-loaded file ${normalizedPath}. The standard hooks/hooks.json is loaded automatically, so manifest.hooks should only reference additional hook files.`;
1229
+ logError(new Error(errorMsg));
1230
+ errors.push({
1231
+ type: 'hook-load-failed',
1232
+ source,
1233
+ plugin: manifest.name,
1234
+ hookPath: hookFilePath,
1235
+ reason: errorMsg,
1236
+ });
1237
+ }
1238
+ continue;
1239
+ }
1240
+ try {
1241
+ const additionalHooks = await loadPluginHooks(hookFilePath, manifest.name);
1242
+ try {
1243
+ mergedHooks = mergeHooksSettings(mergedHooks, additionalHooks);
1244
+ loadedHookPaths.add(normalizedPath);
1245
+ logForDebugging(`Loaded and merged hooks from manifest for plugin ${manifest.name}: ${hookSpec}`);
1246
+ }
1247
+ catch (mergeError) {
1248
+ const mergeErrorMsg = errorMessage(mergeError);
1249
+ logForDebugging(`Failed to merge hooks from ${hookSpec} for ${manifest.name}: ${mergeErrorMsg}`, { level: 'error' });
1250
+ logError(toError(mergeError));
1251
+ errors.push({
1252
+ type: 'hook-load-failed',
1253
+ source,
1254
+ plugin: manifest.name,
1255
+ hookPath: hookFilePath,
1256
+ reason: `Failed to merge: ${mergeErrorMsg}`,
1257
+ });
1258
+ }
1259
+ }
1260
+ catch (error) {
1261
+ const errorMsg = errorMessage(error);
1262
+ logForDebugging(`Failed to load hooks from ${hookSpec} for ${manifest.name}: ${errorMsg}`, { level: 'error' });
1263
+ logError(toError(error));
1264
+ errors.push({
1265
+ type: 'hook-load-failed',
1266
+ source,
1267
+ plugin: manifest.name,
1268
+ hookPath: hookFilePath,
1269
+ reason: errorMsg,
1270
+ });
1271
+ }
1272
+ }
1273
+ else if (typeof hookSpec === 'object') {
1274
+ // Inline hooks
1275
+ mergedHooks = mergeHooksSettings(mergedHooks, hookSpec);
1276
+ }
1277
+ }
1278
+ }
1279
+ if (mergedHooks) {
1280
+ plugin.hooksConfig = mergedHooks;
1281
+ }
1282
+ // Step 6: Load plugin settings
1283
+ // Settings can come from settings.json in the plugin directory or from manifest.settings
1284
+ // Only allowlisted keys are kept (currently: agent)
1285
+ const pluginSettings = await loadPluginSettings(pluginPath, manifest);
1286
+ if (pluginSettings) {
1287
+ plugin.settings = pluginSettings;
1288
+ }
1289
+ return { plugin, errors };
1290
+ }
1291
+ /**
1292
+ * Schema derived from SettingsSchema that only keeps keys plugins are allowed to set.
1293
+ * Uses .strip() so unknown keys are silently removed during parsing.
1294
+ */
1295
+ const PluginSettingsSchema = lazySchema(() => SettingsSchema()
1296
+ .pick({
1297
+ agent: true,
1298
+ })
1299
+ .strip());
1300
+ /**
1301
+ * Parse raw settings through PluginSettingsSchema, returning only allowlisted keys.
1302
+ * Returns undefined if parsing fails or all keys are filtered out.
1303
+ */
1304
+ function parsePluginSettings(raw) {
1305
+ const result = PluginSettingsSchema().safeParse(raw);
1306
+ if (!result.success) {
1307
+ return undefined;
1308
+ }
1309
+ const data = result.data;
1310
+ if (Object.keys(data).length === 0) {
1311
+ return undefined;
1312
+ }
1313
+ return data;
1314
+ }
1315
+ /**
1316
+ * Load plugin settings from settings.json file or manifest.settings.
1317
+ * settings.json takes priority over manifest.settings when both exist.
1318
+ * Only allowlisted keys are included in the result.
1319
+ */
1320
+ async function loadPluginSettings(pluginPath, manifest) {
1321
+ // Try loading settings.json from the plugin directory
1322
+ const settingsJsonPath = join(pluginPath, 'settings.json');
1323
+ try {
1324
+ const content = await readFile(settingsJsonPath, { encoding: 'utf-8' });
1325
+ const parsed = jsonParse(content);
1326
+ if (isRecord(parsed)) {
1327
+ const filtered = parsePluginSettings(parsed);
1328
+ if (filtered) {
1329
+ logForDebugging(`Loaded settings from settings.json for plugin ${manifest.name}`);
1330
+ return filtered;
1331
+ }
1332
+ }
1333
+ }
1334
+ catch (e) {
1335
+ // Missing/inaccessible is expected - settings.json is optional
1336
+ if (!isFsInaccessible(e)) {
1337
+ logForDebugging(`Failed to parse settings.json for plugin ${manifest.name}: ${e}`, { level: 'warn' });
1338
+ }
1339
+ }
1340
+ // Fall back to manifest.settings
1341
+ if (manifest.settings) {
1342
+ const filtered = parsePluginSettings(manifest.settings);
1343
+ if (filtered) {
1344
+ logForDebugging(`Loaded settings from manifest for plugin ${manifest.name}`);
1345
+ return filtered;
1346
+ }
1347
+ }
1348
+ return undefined;
1349
+ }
1350
+ /**
1351
+ * Merge two HooksSettings objects
1352
+ */
1353
+ function mergeHooksSettings(base, additional) {
1354
+ if (!base) {
1355
+ return additional;
1356
+ }
1357
+ const merged = { ...base };
1358
+ for (const [event, matchers] of Object.entries(additional)) {
1359
+ if (!merged[event]) {
1360
+ merged[event] = matchers;
1361
+ }
1362
+ else {
1363
+ // Merge matchers for this event
1364
+ merged[event] = [
1365
+ ...(merged[event] || []),
1366
+ ...matchers,
1367
+ ];
1368
+ }
1369
+ }
1370
+ return merged;
1371
+ }
1372
+ /**
1373
+ * Shared discovery/policy/merge pipeline for both load modes.
1374
+ *
1375
+ * Resolves enabledPlugins → marketplace entries, runs enterprise policy
1376
+ * checks, pre-loads catalogs, then dispatches each entry to the full or
1377
+ * cache-only per-entry loader. The ONLY difference between loadAllPlugins
1378
+ * and loadAllPluginsCacheOnly is which loader runs — discovery and policy
1379
+ * are identical.
1380
+ */
1381
+ async function loadPluginsFromMarketplaces({ cacheOnly, }) {
1382
+ const settings = getSettings_DEPRECATED();
1383
+ // Merge --add-dir plugins at lowest priority; standard settings win on conflict
1384
+ const enabledPlugins = {
1385
+ ...getAddDirEnabledPlugins(),
1386
+ ...(settings.enabledPlugins || {}),
1387
+ };
1388
+ const plugins = [];
1389
+ const errors = [];
1390
+ // Filter to plugin@marketplace format and validate
1391
+ const marketplacePluginEntries = Object.entries(enabledPlugins).filter(([key, value]) => {
1392
+ // Check if it's in plugin@marketplace format (includes both enabled and disabled)
1393
+ const isValidFormat = PluginIdSchema().safeParse(key).success;
1394
+ if (!isValidFormat || value === undefined)
1395
+ return false;
1396
+ // Skip built-in plugins — handled separately by getBuiltinPlugins()
1397
+ const { marketplace } = parsePluginIdentifier(key);
1398
+ return marketplace !== BUILTIN_MARKETPLACE_NAME;
1399
+ });
1400
+ // Load known marketplaces config to look up sources for policy checking.
1401
+ // Use the Safe variant so a corrupted config file doesn't crash all plugin
1402
+ // loading — this is a read-only path, so returning {} degrades gracefully.
1403
+ const knownMarketplaces = await loadKnownMarketplacesConfigSafe();
1404
+ // Fail-closed guard for enterprise policy: if a policy IS configured and we
1405
+ // cannot resolve a marketplace's source (config returned {} due to corruption,
1406
+ // or entry missing), we must NOT silently skip the policy check and load the
1407
+ // plugin anyway. Before Safe, a corrupted config crashed everything (loud,
1408
+ // fail-closed). With Safe + no guard, the policy check short-circuits on
1409
+ // undefined marketplaceConfig and the fallback path (getPluginByIdCacheOnly)
1410
+ // loads the plugin unchecked — a silent fail-open. This guard restores
1411
+ // fail-closed: unknown source + active policy → block.
1412
+ //
1413
+ // Allowlist: any value (including []) is active — empty allowlist = deny all.
1414
+ // Blocklist: empty [] is a semantic no-op — only non-empty counts as active.
1415
+ const strictAllowlist = getStrictKnownMarketplaces();
1416
+ const blocklist = getBlockedMarketplaces();
1417
+ const hasEnterprisePolicy = strictAllowlist !== null || (blocklist !== null && blocklist.length > 0);
1418
+ // Pre-load marketplace catalogs once per marketplace rather than re-reading
1419
+ // known_marketplaces.json + marketplace.json for every plugin. This is the
1420
+ // hot path — with N plugins across M marketplaces, the old per-plugin
1421
+ // getPluginByIdCacheOnly() did 2N config reads + N catalog reads; this does M.
1422
+ const uniqueMarketplaces = new Set(marketplacePluginEntries
1423
+ .map(([pluginId]) => parsePluginIdentifier(pluginId).marketplace)
1424
+ .filter((m) => !!m));
1425
+ const marketplaceCatalogs = new Map();
1426
+ await Promise.all([...uniqueMarketplaces].map(async (name) => {
1427
+ marketplaceCatalogs.set(name, await getMarketplaceCacheOnly(name));
1428
+ }));
1429
+ // Look up installed versions once so the first-pass ZIP cache check
1430
+ // can hit even when the marketplace entry omits `version`.
1431
+ const installedPluginsData = getInMemoryInstalledPlugins();
1432
+ // Load all marketplace plugins in parallel for faster startup
1433
+ const results = await Promise.allSettled(marketplacePluginEntries.map(async ([pluginId, enabledValue]) => {
1434
+ const { name: pluginName, marketplace: marketplaceName } = parsePluginIdentifier(pluginId);
1435
+ // Check if marketplace source is allowed by enterprise policy
1436
+ const marketplaceConfig = knownMarketplaces[marketplaceName];
1437
+ // Fail-closed: if enterprise policy is active and we can't look up the
1438
+ // marketplace source (config corrupted/empty, or entry missing), block
1439
+ // rather than silently skip the policy check. See hasEnterprisePolicy
1440
+ // comment above for the fail-open hazard this guards against.
1441
+ //
1442
+ // This also fires for the "stale enabledPlugins entry with no registered
1443
+ // marketplace" case, which is a UX trade-off: the user gets a policy
1444
+ // error instead of plugin-not-found. Accepted because the fallback path
1445
+ // (getPluginByIdCacheOnly) does a raw cast of known_marketplaces.json
1446
+ // with NO schema validation — if one entry is malformed enough to fail
1447
+ // our validation but readable enough for the raw cast, it would load
1448
+ // unchecked. Unverifiable source + active policy → block, always.
1449
+ if (!marketplaceConfig && hasEnterprisePolicy) {
1450
+ // We can't know whether the unverifiable source would actually be in
1451
+ // the blocklist or not in the allowlist — so pick the error variant
1452
+ // that matches whichever policy IS configured. If an allowlist exists,
1453
+ // "not in allowed list" is the right framing; if only a blocklist
1454
+ // exists, "blocked by blocklist" is less misleading than showing an
1455
+ // empty allowed-sources list.
1456
+ errors.push({
1457
+ type: 'marketplace-blocked-by-policy',
1458
+ source: pluginId,
1459
+ plugin: pluginName,
1460
+ marketplace: marketplaceName,
1461
+ blockedByBlocklist: strictAllowlist === null,
1462
+ allowedSources: (strictAllowlist ?? []).map(s => formatSourceForDisplay(s)),
1463
+ });
1464
+ return null;
1465
+ }
1466
+ if (marketplaceConfig &&
1467
+ !isSourceAllowedByPolicy(marketplaceConfig.source)) {
1468
+ // Check if explicitly blocked vs not in allowlist for better error context
1469
+ const isBlocked = isSourceInBlocklist(marketplaceConfig.source);
1470
+ const allowlist = getStrictKnownMarketplaces() || [];
1471
+ errors.push({
1472
+ type: 'marketplace-blocked-by-policy',
1473
+ source: pluginId,
1474
+ plugin: pluginName,
1475
+ marketplace: marketplaceName,
1476
+ blockedByBlocklist: isBlocked,
1477
+ allowedSources: isBlocked
1478
+ ? []
1479
+ : allowlist.map(s => formatSourceForDisplay(s)),
1480
+ });
1481
+ return null;
1482
+ }
1483
+ // Look up plugin entry from pre-loaded marketplace catalog (no per-plugin I/O).
1484
+ // Fall back to getPluginByIdCacheOnly if the catalog couldn't be pre-loaded.
1485
+ let result = null;
1486
+ const marketplace = marketplaceCatalogs.get(marketplaceName);
1487
+ if (marketplace && marketplaceConfig) {
1488
+ const entry = marketplace.plugins.find(p => p.name === pluginName);
1489
+ if (entry) {
1490
+ result = {
1491
+ entry,
1492
+ marketplaceInstallLocation: marketplaceConfig.installLocation,
1493
+ };
1494
+ }
1495
+ }
1496
+ else {
1497
+ result = await getPluginByIdCacheOnly(pluginId);
1498
+ }
1499
+ if (!result) {
1500
+ errors.push({
1501
+ type: 'plugin-not-found',
1502
+ source: pluginId,
1503
+ pluginId: pluginName,
1504
+ marketplace: marketplaceName,
1505
+ });
1506
+ return null;
1507
+ }
1508
+ // installed_plugins.json records what's actually cached on disk
1509
+ // (version for the full loader's first-pass probe, installPath for
1510
+ // the cache-only loader's direct read).
1511
+ const installEntry = installedPluginsData.plugins[pluginId]?.[0];
1512
+ return cacheOnly
1513
+ ? loadPluginFromMarketplaceEntryCacheOnly(result.entry, result.marketplaceInstallLocation, pluginId, enabledValue === true, errors, installEntry?.installPath)
1514
+ : loadPluginFromMarketplaceEntry(result.entry, result.marketplaceInstallLocation, pluginId, enabledValue === true, errors, installEntry?.version);
1515
+ }));
1516
+ for (const [i, result] of results.entries()) {
1517
+ if (result.status === 'fulfilled' && result.value) {
1518
+ plugins.push(result.value);
1519
+ }
1520
+ else if (result.status === 'rejected') {
1521
+ const err = toError(result.reason);
1522
+ logError(err);
1523
+ const pluginId = marketplacePluginEntries[i][0];
1524
+ errors.push({
1525
+ type: 'generic-error',
1526
+ source: pluginId,
1527
+ plugin: pluginId.split('@')[0],
1528
+ error: err.message,
1529
+ });
1530
+ }
1531
+ }
1532
+ return { plugins, errors };
1533
+ }
1534
+ /**
1535
+ * Cache-only variant of loadPluginFromMarketplaceEntry.
1536
+ *
1537
+ * Skips network (cachePlugin) and disk-copy (copyPluginToVersionedCache).
1538
+ * Reads directly from the recorded installPath; if missing, emits
1539
+ * 'plugin-cache-miss'. Still extracts ZIP-cached plugins (local, fast).
1540
+ */
1541
+ async function loadPluginFromMarketplaceEntryCacheOnly(entry, marketplaceInstallLocation, pluginId, enabled, errorsOut, installPath) {
1542
+ let pluginPath;
1543
+ if (typeof entry.source === 'string') {
1544
+ // Local relative path — read from the marketplace source dir directly.
1545
+ // Skip copyPluginToVersionedCache; startup doesn't need a fresh copy.
1546
+ let marketplaceDir;
1547
+ try {
1548
+ marketplaceDir = (await stat(marketplaceInstallLocation)).isDirectory()
1549
+ ? marketplaceInstallLocation
1550
+ : join(marketplaceInstallLocation, '..');
1551
+ }
1552
+ catch {
1553
+ errorsOut.push({
1554
+ type: 'plugin-cache-miss',
1555
+ source: pluginId,
1556
+ plugin: entry.name,
1557
+ installPath: marketplaceInstallLocation,
1558
+ });
1559
+ return null;
1560
+ }
1561
+ pluginPath = join(marketplaceDir, entry.source);
1562
+ // finishLoadingPluginFromPath reads pluginPath — its error handling
1563
+ // surfaces ENOENT as a load failure, no need to pre-check here.
1564
+ }
1565
+ else {
1566
+ // External source (npm/github/url/git-subdir) — use recorded installPath.
1567
+ if (!installPath || !(await pathExists(installPath))) {
1568
+ errorsOut.push({
1569
+ type: 'plugin-cache-miss',
1570
+ source: pluginId,
1571
+ plugin: entry.name,
1572
+ installPath: installPath ?? '(not recorded)',
1573
+ });
1574
+ return null;
1575
+ }
1576
+ pluginPath = installPath;
1577
+ }
1578
+ // Zip cache extraction — must still happen in cacheOnly mode (invariant 4)
1579
+ if (isPluginZipCacheEnabled() && pluginPath.endsWith('.zip')) {
1580
+ const sessionDir = await getSessionPluginCachePath();
1581
+ const extractDir = join(sessionDir, pluginId.replace(/[^a-zA-Z0-9@\-_]/g, '-'));
1582
+ try {
1583
+ await extractZipToDirectory(pluginPath, extractDir);
1584
+ pluginPath = extractDir;
1585
+ }
1586
+ catch (error) {
1587
+ logForDebugging(`Failed to extract plugin ZIP ${pluginPath}: ${error}`, {
1588
+ level: 'error',
1589
+ });
1590
+ errorsOut.push({
1591
+ type: 'plugin-cache-miss',
1592
+ source: pluginId,
1593
+ plugin: entry.name,
1594
+ installPath: pluginPath,
1595
+ });
1596
+ return null;
1597
+ }
1598
+ }
1599
+ // Delegate to the shared tail — identical to the full loader from here
1600
+ return finishLoadingPluginFromPath(entry, pluginId, enabled, errorsOut, pluginPath);
1601
+ }
1602
+ /**
1603
+ * Load a plugin from a marketplace entry based on its source configuration.
1604
+ *
1605
+ * Handles different source types:
1606
+ * - Relative path: Loads from marketplace repo directory
1607
+ * - npm/github/url: Caches then loads from cache
1608
+ *
1609
+ * @param installedVersion - Version from installed_plugins.json, used as a
1610
+ * first-pass hint for the versioned cache lookup when the marketplace entry
1611
+ * omits `version`. Avoids re-cloning external plugins just to discover the
1612
+ * version we already recorded at install time.
1613
+ *
1614
+ * Returns both the loaded plugin and any errors encountered during loading.
1615
+ * Errors include missing component files and hook load failures.
1616
+ */
1617
+ async function loadPluginFromMarketplaceEntry(entry, marketplaceInstallLocation, pluginId, enabled, errorsOut, installedVersion) {
1618
+ logForDebugging(`Loading plugin ${entry.name} from source: ${jsonStringify(entry.source)}`);
1619
+ let pluginPath;
1620
+ if (typeof entry.source === 'string') {
1621
+ // Relative path - resolve relative to marketplace install location
1622
+ const marketplaceDir = (await stat(marketplaceInstallLocation)).isDirectory()
1623
+ ? marketplaceInstallLocation
1624
+ : join(marketplaceInstallLocation, '..');
1625
+ const sourcePluginPath = join(marketplaceDir, entry.source);
1626
+ if (!(await pathExists(sourcePluginPath))) {
1627
+ const error = new Error(`Plugin path not found: ${sourcePluginPath}`);
1628
+ logForDebugging(`Plugin path not found: ${sourcePluginPath}`, {
1629
+ level: 'error',
1630
+ });
1631
+ logError(error);
1632
+ errorsOut.push({
1633
+ type: 'generic-error',
1634
+ source: pluginId,
1635
+ error: `Plugin directory not found at path: ${sourcePluginPath}. Check that the marketplace entry has the correct path.`,
1636
+ });
1637
+ return null;
1638
+ }
1639
+ // Always copy local plugins to versioned cache
1640
+ try {
1641
+ // Try to load manifest from plugin directory to check for version field first
1642
+ const manifestPath = join(sourcePluginPath, '.claude-plugin', 'plugin.json');
1643
+ let pluginManifest;
1644
+ try {
1645
+ pluginManifest = await loadPluginManifest(manifestPath, entry.name, entry.source);
1646
+ }
1647
+ catch {
1648
+ // Manifest loading failed - will fall back to provided version or git SHA
1649
+ }
1650
+ // Calculate version with fallback order:
1651
+ // 1. Plugin manifest version, 2. Marketplace entry version, 3. Git SHA, 4. 'unknown'
1652
+ const version = await calculatePluginVersion(pluginId, entry.source, pluginManifest, marketplaceDir, entry.version);
1653
+ // Copy to versioned cache
1654
+ pluginPath = await copyPluginToVersionedCache(sourcePluginPath, pluginId, version, entry, marketplaceDir);
1655
+ logForDebugging(`Resolved local plugin ${entry.name} to versioned cache: ${pluginPath}`);
1656
+ }
1657
+ catch (error) {
1658
+ // If copy fails, fall back to loading from marketplace directly
1659
+ const errorMsg = errorMessage(error);
1660
+ logForDebugging(`Failed to copy plugin ${entry.name} to versioned cache: ${errorMsg}. Using marketplace path.`, { level: 'warn' });
1661
+ pluginPath = sourcePluginPath;
1662
+ }
1663
+ }
1664
+ else {
1665
+ // External source (npm, github, url, pip) - always use versioned cache
1666
+ try {
1667
+ // Calculate version with fallback order:
1668
+ // 1. No manifest yet, 2. installed_plugins.json version,
1669
+ // 3. Marketplace entry version, 4. source.sha (pinned commits — the
1670
+ // exact value the post-clone call at cached.gitCommitSha would see),
1671
+ // 5. 'unknown' → ref-tracked, falls through to clone by design.
1672
+ const version = await calculatePluginVersion(pluginId, entry.source, undefined, undefined, installedVersion ?? entry.version, 'sha' in entry.source ? entry.source.sha : undefined);
1673
+ const versionedPath = getVersionedCachePath(pluginId, version);
1674
+ // Check for cached version — ZIP file (zip cache mode) or directory
1675
+ const zipPath = getVersionedZipCachePath(pluginId, version);
1676
+ if (isPluginZipCacheEnabled() && (await pathExists(zipPath))) {
1677
+ logForDebugging(`Using versioned cached plugin ZIP ${entry.name} from ${zipPath}`);
1678
+ pluginPath = zipPath;
1679
+ }
1680
+ else if (await pathExists(versionedPath)) {
1681
+ logForDebugging(`Using versioned cached plugin ${entry.name} from ${versionedPath}`);
1682
+ pluginPath = versionedPath;
1683
+ }
1684
+ else {
1685
+ // Seed cache probe (CCR pre-baked images, read-only). Seed content is
1686
+ // frozen at image build time — no freshness concern, 'whatever's there'
1687
+ // is what the image builder put there. Primary cache is NOT probed
1688
+ // here; ref-tracked sources fall through to clone (the re-clone IS
1689
+ // the freshness mechanism). If the clone fails, the plugin is simply
1690
+ // disabled for this session — errorsOut.push below surfaces it.
1691
+ const seedPath = (await probeSeedCache(pluginId, version)) ??
1692
+ (version === 'unknown'
1693
+ ? await probeSeedCacheAnyVersion(pluginId)
1694
+ : null);
1695
+ if (seedPath) {
1696
+ pluginPath = seedPath;
1697
+ logForDebugging(`Using seed cache for external plugin ${entry.name} at ${seedPath}`);
1698
+ }
1699
+ else {
1700
+ // Download to temp location, then copy to versioned cache
1701
+ const cached = await cachePlugin(entry.source, {
1702
+ manifest: { name: entry.name },
1703
+ });
1704
+ // If the pre-clone version was deterministic (source.sha /
1705
+ // entry.version / installedVersion), REUSE it. The post-clone
1706
+ // recomputation with cached.manifest can return a DIFFERENT value
1707
+ // — manifest.version (step 1) outranks gitCommitSha (step 3) —
1708
+ // which would cache at e.g. "2.0.0/" while every warm start
1709
+ // probes "{sha12}-{hash}/". Mismatched keys = re-clone forever.
1710
+ // Recomputation is only needed when pre-clone was 'unknown'
1711
+ // (ref-tracked, no hints) — the clone is the ONLY way to learn.
1712
+ const actualVersion = version !== 'unknown'
1713
+ ? version
1714
+ : await calculatePluginVersion(pluginId, entry.source, cached.manifest, cached.path, installedVersion ?? entry.version, cached.gitCommitSha);
1715
+ // Copy to versioned cache
1716
+ // For external sources, marketplaceDir is not applicable (already downloaded)
1717
+ pluginPath = await copyPluginToVersionedCache(cached.path, pluginId, actualVersion, entry, undefined);
1718
+ // Clean up temp path
1719
+ if (cached.path !== pluginPath) {
1720
+ await rm(cached.path, { recursive: true, force: true });
1721
+ }
1722
+ }
1723
+ }
1724
+ }
1725
+ catch (error) {
1726
+ const errorMsg = errorMessage(error);
1727
+ logForDebugging(`Failed to cache plugin ${entry.name}: ${errorMsg}`, {
1728
+ level: 'error',
1729
+ });
1730
+ logError(toError(error));
1731
+ errorsOut.push({
1732
+ type: 'generic-error',
1733
+ source: pluginId,
1734
+ error: `Failed to download/cache plugin ${entry.name}: ${errorMsg}`,
1735
+ });
1736
+ return null;
1737
+ }
1738
+ }
1739
+ // Zip cache mode: extract ZIP to session temp dir before loading
1740
+ if (isPluginZipCacheEnabled() && pluginPath.endsWith('.zip')) {
1741
+ const sessionDir = await getSessionPluginCachePath();
1742
+ const extractDir = join(sessionDir, pluginId.replace(/[^a-zA-Z0-9@\-_]/g, '-'));
1743
+ try {
1744
+ await extractZipToDirectory(pluginPath, extractDir);
1745
+ logForDebugging(`Extracted plugin ZIP to session dir: ${extractDir}`);
1746
+ pluginPath = extractDir;
1747
+ }
1748
+ catch (error) {
1749
+ // Corrupt ZIP: delete it so next install attempt re-creates it
1750
+ logForDebugging(`Failed to extract plugin ZIP ${pluginPath}, deleting corrupt file: ${error}`);
1751
+ await rm(pluginPath, { force: true }).catch(() => { });
1752
+ throw error;
1753
+ }
1754
+ }
1755
+ return finishLoadingPluginFromPath(entry, pluginId, enabled, errorsOut, pluginPath);
1756
+ }
1757
+ /**
1758
+ * Shared tail of both loadPluginFromMarketplaceEntry variants.
1759
+ *
1760
+ * Once pluginPath is resolved (via clone, cache, or installPath lookup),
1761
+ * the rest of the load — manifest probe, createPluginFromPath, marketplace
1762
+ * entry supplementation — is identical. Extracted so the cache-only path
1763
+ * doesn't duplicate ~500 lines.
1764
+ */
1765
+ async function finishLoadingPluginFromPath(entry, pluginId, enabled, errorsOut, pluginPath) {
1766
+ const errors = [];
1767
+ // Check if plugin.json exists to determine if we should use marketplace manifest
1768
+ const manifestPath = join(pluginPath, '.claude-plugin', 'plugin.json');
1769
+ const hasManifest = await pathExists(manifestPath);
1770
+ const { plugin, errors: pluginErrors } = await createPluginFromPath(pluginPath, pluginId, enabled, entry.name, entry.strict ?? true);
1771
+ errors.push(...pluginErrors);
1772
+ // Set sha from source if available (for github and url source types)
1773
+ if (typeof entry.source === 'object' &&
1774
+ 'sha' in entry.source &&
1775
+ entry.source.sha) {
1776
+ plugin.sha = entry.source.sha;
1777
+ }
1778
+ // If there's no plugin.json, use marketplace entry as manifest (regardless of strict mode)
1779
+ if (!hasManifest) {
1780
+ plugin.manifest = {
1781
+ ...entry,
1782
+ id: undefined,
1783
+ source: undefined,
1784
+ strict: undefined,
1785
+ };
1786
+ plugin.name = plugin.manifest.name;
1787
+ // Process commands from marketplace entry
1788
+ if (entry.commands) {
1789
+ // Check if it's an object mapping
1790
+ const firstValue = Object.values(entry.commands)[0];
1791
+ if (typeof entry.commands === 'object' &&
1792
+ !Array.isArray(entry.commands) &&
1793
+ firstValue &&
1794
+ typeof firstValue === 'object' &&
1795
+ ('source' in firstValue || 'content' in firstValue)) {
1796
+ // Object mapping format
1797
+ const commandsMetadata = {};
1798
+ const validPaths = [];
1799
+ // Parallelize pathExists checks; process results in order.
1800
+ const entries = Object.entries(entry.commands);
1801
+ const checks = await Promise.all(entries.map(async ([commandName, metadata]) => {
1802
+ if (!metadata || typeof metadata !== 'object' || !metadata.source) {
1803
+ return { commandName, metadata, skip: true };
1804
+ }
1805
+ const fullPath = join(pluginPath, metadata.source);
1806
+ return {
1807
+ commandName,
1808
+ metadata,
1809
+ skip: false,
1810
+ fullPath,
1811
+ exists: await pathExists(fullPath),
1812
+ };
1813
+ }));
1814
+ for (const check of checks) {
1815
+ if (check.skip)
1816
+ continue;
1817
+ if (check.exists) {
1818
+ validPaths.push(check.fullPath);
1819
+ commandsMetadata[check.commandName] = check.metadata;
1820
+ }
1821
+ else {
1822
+ logForDebugging(`Command ${check.commandName} path ${check.metadata.source} from marketplace entry not found at ${check.fullPath} for ${entry.name}`, { level: 'warn' });
1823
+ logError(new Error(`Plugin component file not found: ${check.fullPath} for ${entry.name}`));
1824
+ errors.push({
1825
+ type: 'path-not-found',
1826
+ source: pluginId,
1827
+ plugin: entry.name,
1828
+ path: check.fullPath,
1829
+ component: 'commands',
1830
+ });
1831
+ }
1832
+ }
1833
+ if (validPaths.length > 0) {
1834
+ plugin.commandsPaths = validPaths;
1835
+ plugin.commandsMetadata = commandsMetadata;
1836
+ }
1837
+ }
1838
+ else {
1839
+ // Path or array of paths format
1840
+ const commandPaths = Array.isArray(entry.commands)
1841
+ ? entry.commands
1842
+ : [entry.commands];
1843
+ // Parallelize pathExists checks; process results in order.
1844
+ const checks = await Promise.all(commandPaths.map(async (cmdPath) => {
1845
+ if (typeof cmdPath !== 'string') {
1846
+ return { cmdPath, kind: 'invalid' };
1847
+ }
1848
+ const fullPath = join(pluginPath, cmdPath);
1849
+ return {
1850
+ cmdPath,
1851
+ kind: 'path',
1852
+ fullPath,
1853
+ exists: await pathExists(fullPath),
1854
+ };
1855
+ }));
1856
+ const validPaths = [];
1857
+ for (const check of checks) {
1858
+ if (check.kind === 'invalid') {
1859
+ logForDebugging(`Unexpected command format in marketplace entry for ${entry.name}`, { level: 'error' });
1860
+ continue;
1861
+ }
1862
+ if (check.exists) {
1863
+ validPaths.push(check.fullPath);
1864
+ }
1865
+ else {
1866
+ logForDebugging(`Command path ${check.cmdPath} from marketplace entry not found at ${check.fullPath} for ${entry.name}`, { level: 'warn' });
1867
+ logError(new Error(`Plugin component file not found: ${check.fullPath} for ${entry.name}`));
1868
+ errors.push({
1869
+ type: 'path-not-found',
1870
+ source: pluginId,
1871
+ plugin: entry.name,
1872
+ path: check.fullPath,
1873
+ component: 'commands',
1874
+ });
1875
+ }
1876
+ }
1877
+ if (validPaths.length > 0) {
1878
+ plugin.commandsPaths = validPaths;
1879
+ }
1880
+ }
1881
+ }
1882
+ // Process agents from marketplace entry
1883
+ if (entry.agents) {
1884
+ const agentPaths = Array.isArray(entry.agents)
1885
+ ? entry.agents
1886
+ : [entry.agents];
1887
+ const validPaths = await validatePluginPaths(agentPaths, pluginPath, entry.name, pluginId, 'agents', 'Agent', 'from marketplace entry', errors);
1888
+ if (validPaths.length > 0) {
1889
+ plugin.agentsPaths = validPaths;
1890
+ }
1891
+ }
1892
+ // Process skills from marketplace entry
1893
+ if (entry.skills) {
1894
+ logForDebugging(`Processing ${Array.isArray(entry.skills) ? entry.skills.length : 1} skill paths for plugin ${entry.name}`);
1895
+ const skillPaths = Array.isArray(entry.skills)
1896
+ ? entry.skills
1897
+ : [entry.skills];
1898
+ // Parallelize pathExists checks; process results in order.
1899
+ // Note: previously this loop called pathExists() TWICE per iteration
1900
+ // (once in a debug log template, once in the if) — now called once.
1901
+ const checks = await Promise.all(skillPaths.map(async (skillPath) => {
1902
+ const fullPath = join(pluginPath, skillPath);
1903
+ return { skillPath, fullPath, exists: await pathExists(fullPath) };
1904
+ }));
1905
+ const validPaths = [];
1906
+ for (const { skillPath, fullPath, exists } of checks) {
1907
+ logForDebugging(`Checking skill path: ${skillPath} -> ${fullPath} (exists: ${exists})`);
1908
+ if (exists) {
1909
+ validPaths.push(fullPath);
1910
+ }
1911
+ else {
1912
+ logForDebugging(`Skill path ${skillPath} from marketplace entry not found at ${fullPath} for ${entry.name}`, { level: 'warn' });
1913
+ logError(new Error(`Plugin component file not found: ${fullPath} for ${entry.name}`));
1914
+ errors.push({
1915
+ type: 'path-not-found',
1916
+ source: pluginId,
1917
+ plugin: entry.name,
1918
+ path: fullPath,
1919
+ component: 'skills',
1920
+ });
1921
+ }
1922
+ }
1923
+ logForDebugging(`Found ${validPaths.length} valid skill paths for plugin ${entry.name}, setting skillsPaths`);
1924
+ if (validPaths.length > 0) {
1925
+ plugin.skillsPaths = validPaths;
1926
+ }
1927
+ }
1928
+ else {
1929
+ logForDebugging(`Plugin ${entry.name} has no entry.skills defined`);
1930
+ }
1931
+ // Process output styles from marketplace entry
1932
+ if (entry.outputStyles) {
1933
+ const outputStylePaths = Array.isArray(entry.outputStyles)
1934
+ ? entry.outputStyles
1935
+ : [entry.outputStyles];
1936
+ const validPaths = await validatePluginPaths(outputStylePaths, pluginPath, entry.name, pluginId, 'output-styles', 'Output style', 'from marketplace entry', errors);
1937
+ if (validPaths.length > 0) {
1938
+ plugin.outputStylesPaths = validPaths;
1939
+ }
1940
+ }
1941
+ // Process inline hooks from marketplace entry
1942
+ if (entry.hooks) {
1943
+ plugin.hooksConfig = entry.hooks;
1944
+ }
1945
+ }
1946
+ else if (!entry.strict &&
1947
+ hasManifest &&
1948
+ (entry.commands ||
1949
+ entry.agents ||
1950
+ entry.skills ||
1951
+ entry.hooks ||
1952
+ entry.outputStyles)) {
1953
+ // In non-strict mode with plugin.json, marketplace entries for commands/agents/skills/hooks/outputStyles are conflicts
1954
+ const error = new Error(`Plugin ${entry.name} has both plugin.json and marketplace manifest entries for commands/agents/skills/hooks/outputStyles. This is a conflict.`);
1955
+ logForDebugging(`Plugin ${entry.name} has both plugin.json and marketplace manifest entries for commands/agents/skills/hooks/outputStyles. This is a conflict.`, { level: 'error' });
1956
+ logError(error);
1957
+ errorsOut.push({
1958
+ type: 'generic-error',
1959
+ source: pluginId,
1960
+ error: `Plugin ${entry.name} has conflicting manifests: both plugin.json and marketplace entry specify components. Set strict: true in marketplace entry or remove component specs from one location.`,
1961
+ });
1962
+ return null;
1963
+ }
1964
+ else if (hasManifest) {
1965
+ // Has plugin.json - marketplace can supplement commands/agents/skills/hooks/outputStyles
1966
+ // Supplement commands from marketplace entry
1967
+ if (entry.commands) {
1968
+ // Check if it's an object mapping
1969
+ const firstValue = Object.values(entry.commands)[0];
1970
+ if (typeof entry.commands === 'object' &&
1971
+ !Array.isArray(entry.commands) &&
1972
+ firstValue &&
1973
+ typeof firstValue === 'object' &&
1974
+ ('source' in firstValue || 'content' in firstValue)) {
1975
+ // Object mapping format - merge metadata
1976
+ const commandsMetadata = {
1977
+ ...(plugin.commandsMetadata || {}),
1978
+ };
1979
+ const validPaths = [];
1980
+ // Parallelize pathExists checks; process results in order.
1981
+ const entries = Object.entries(entry.commands);
1982
+ const checks = await Promise.all(entries.map(async ([commandName, metadata]) => {
1983
+ if (!metadata || typeof metadata !== 'object' || !metadata.source) {
1984
+ return { commandName, metadata, skip: true };
1985
+ }
1986
+ const fullPath = join(pluginPath, metadata.source);
1987
+ return {
1988
+ commandName,
1989
+ metadata,
1990
+ skip: false,
1991
+ fullPath,
1992
+ exists: await pathExists(fullPath),
1993
+ };
1994
+ }));
1995
+ for (const check of checks) {
1996
+ if (check.skip)
1997
+ continue;
1998
+ if (check.exists) {
1999
+ validPaths.push(check.fullPath);
2000
+ commandsMetadata[check.commandName] = check.metadata;
2001
+ }
2002
+ else {
2003
+ logForDebugging(`Command ${check.commandName} path ${check.metadata.source} from marketplace entry not found at ${check.fullPath} for ${entry.name}`, { level: 'warn' });
2004
+ logError(new Error(`Plugin component file not found: ${check.fullPath} for ${entry.name}`));
2005
+ errors.push({
2006
+ type: 'path-not-found',
2007
+ source: pluginId,
2008
+ plugin: entry.name,
2009
+ path: check.fullPath,
2010
+ component: 'commands',
2011
+ });
2012
+ }
2013
+ }
2014
+ if (validPaths.length > 0) {
2015
+ plugin.commandsPaths = [
2016
+ ...(plugin.commandsPaths || []),
2017
+ ...validPaths,
2018
+ ];
2019
+ plugin.commandsMetadata = commandsMetadata;
2020
+ }
2021
+ }
2022
+ else {
2023
+ // Path or array of paths format
2024
+ const commandPaths = Array.isArray(entry.commands)
2025
+ ? entry.commands
2026
+ : [entry.commands];
2027
+ // Parallelize pathExists checks; process results in order.
2028
+ const checks = await Promise.all(commandPaths.map(async (cmdPath) => {
2029
+ if (typeof cmdPath !== 'string') {
2030
+ return { cmdPath, kind: 'invalid' };
2031
+ }
2032
+ const fullPath = join(pluginPath, cmdPath);
2033
+ return {
2034
+ cmdPath,
2035
+ kind: 'path',
2036
+ fullPath,
2037
+ exists: await pathExists(fullPath),
2038
+ };
2039
+ }));
2040
+ const validPaths = [];
2041
+ for (const check of checks) {
2042
+ if (check.kind === 'invalid') {
2043
+ logForDebugging(`Unexpected command format in marketplace entry for ${entry.name}`, { level: 'error' });
2044
+ continue;
2045
+ }
2046
+ if (check.exists) {
2047
+ validPaths.push(check.fullPath);
2048
+ }
2049
+ else {
2050
+ logForDebugging(`Command path ${check.cmdPath} from marketplace entry not found at ${check.fullPath} for ${entry.name}`, { level: 'warn' });
2051
+ logError(new Error(`Plugin component file not found: ${check.fullPath} for ${entry.name}`));
2052
+ errors.push({
2053
+ type: 'path-not-found',
2054
+ source: pluginId,
2055
+ plugin: entry.name,
2056
+ path: check.fullPath,
2057
+ component: 'commands',
2058
+ });
2059
+ }
2060
+ }
2061
+ if (validPaths.length > 0) {
2062
+ plugin.commandsPaths = [
2063
+ ...(plugin.commandsPaths || []),
2064
+ ...validPaths,
2065
+ ];
2066
+ }
2067
+ }
2068
+ }
2069
+ // Supplement agents from marketplace entry
2070
+ if (entry.agents) {
2071
+ const agentPaths = Array.isArray(entry.agents)
2072
+ ? entry.agents
2073
+ : [entry.agents];
2074
+ const validPaths = await validatePluginPaths(agentPaths, pluginPath, entry.name, pluginId, 'agents', 'Agent', 'from marketplace entry', errors);
2075
+ if (validPaths.length > 0) {
2076
+ plugin.agentsPaths = [...(plugin.agentsPaths || []), ...validPaths];
2077
+ }
2078
+ }
2079
+ // Supplement skills from marketplace entry
2080
+ if (entry.skills) {
2081
+ const skillPaths = Array.isArray(entry.skills)
2082
+ ? entry.skills
2083
+ : [entry.skills];
2084
+ const validPaths = await validatePluginPaths(skillPaths, pluginPath, entry.name, pluginId, 'skills', 'Skill', 'from marketplace entry', errors);
2085
+ if (validPaths.length > 0) {
2086
+ plugin.skillsPaths = [...(plugin.skillsPaths || []), ...validPaths];
2087
+ }
2088
+ }
2089
+ // Supplement output styles from marketplace entry
2090
+ if (entry.outputStyles) {
2091
+ const outputStylePaths = Array.isArray(entry.outputStyles)
2092
+ ? entry.outputStyles
2093
+ : [entry.outputStyles];
2094
+ const validPaths = await validatePluginPaths(outputStylePaths, pluginPath, entry.name, pluginId, 'output-styles', 'Output style', 'from marketplace entry', errors);
2095
+ if (validPaths.length > 0) {
2096
+ plugin.outputStylesPaths = [
2097
+ ...(plugin.outputStylesPaths || []),
2098
+ ...validPaths,
2099
+ ];
2100
+ }
2101
+ }
2102
+ // Supplement hooks from marketplace entry
2103
+ if (entry.hooks) {
2104
+ plugin.hooksConfig = {
2105
+ ...(plugin.hooksConfig || {}),
2106
+ ...entry.hooks,
2107
+ };
2108
+ }
2109
+ }
2110
+ errorsOut.push(...errors);
2111
+ return plugin;
2112
+ }
2113
+ /**
2114
+ * Load session-only plugins from --plugin-dir CLI flag.
2115
+ *
2116
+ * These plugins are loaded directly without going through the marketplace system.
2117
+ * They appear with source='plugin-name@inline' and are always enabled for the current session.
2118
+ *
2119
+ * @param sessionPluginPaths - Array of plugin directory paths from CLI
2120
+ * @returns LoadedPlugin objects and any errors encountered
2121
+ */
2122
+ async function loadSessionOnlyPlugins(sessionPluginPaths) {
2123
+ if (sessionPluginPaths.length === 0) {
2124
+ return { plugins: [], errors: [] };
2125
+ }
2126
+ const plugins = [];
2127
+ const errors = [];
2128
+ for (const [index, pluginPath] of sessionPluginPaths.entries()) {
2129
+ try {
2130
+ const resolvedPath = resolve(pluginPath);
2131
+ if (!(await pathExists(resolvedPath))) {
2132
+ logForDebugging(`Plugin path does not exist: ${resolvedPath}, skipping`, { level: 'warn' });
2133
+ errors.push({
2134
+ type: 'path-not-found',
2135
+ source: `inline[${index}]`,
2136
+ path: resolvedPath,
2137
+ component: 'commands',
2138
+ });
2139
+ continue;
2140
+ }
2141
+ const dirName = basename(resolvedPath);
2142
+ const { plugin, errors: pluginErrors } = await createPluginFromPath(resolvedPath, `${dirName}@inline`, // temporary, will be updated after we know the real name
2143
+ true, // always enabled
2144
+ dirName);
2145
+ // Update source to use the actual plugin name from manifest
2146
+ plugin.source = `${plugin.name}@inline`;
2147
+ plugin.repository = `${plugin.name}@inline`;
2148
+ plugins.push(plugin);
2149
+ errors.push(...pluginErrors);
2150
+ logForDebugging(`Loaded inline plugin from path: ${plugin.name}`);
2151
+ }
2152
+ catch (error) {
2153
+ const errorMsg = errorMessage(error);
2154
+ logForDebugging(`Failed to load session plugin from ${pluginPath}: ${errorMsg}`, { level: 'warn' });
2155
+ errors.push({
2156
+ type: 'generic-error',
2157
+ source: `inline[${index}]`,
2158
+ error: `Failed to load plugin: ${errorMsg}`,
2159
+ });
2160
+ }
2161
+ }
2162
+ if (plugins.length > 0) {
2163
+ logForDebugging(`Loaded ${plugins.length} session-only plugins from --plugin-dir`);
2164
+ }
2165
+ return { plugins, errors };
2166
+ }
2167
+ /**
2168
+ * Merge plugins from session (--plugin-dir), marketplace (installed), and
2169
+ * builtin sources. Session plugins override marketplace plugins with the
2170
+ * same name — the user explicitly pointed at a directory for this session.
2171
+ *
2172
+ * Exception: marketplace plugins locked by managed settings (policySettings)
2173
+ * cannot be overridden. Enterprise admin intent beats local dev convenience.
2174
+ * When a session plugin collides with a managed one, the session copy is
2175
+ * dropped and an error is returned for surfacing.
2176
+ *
2177
+ * Without this dedup, both versions sat in the array and marketplace won
2178
+ * on first-match, making --plugin-dir useless for iterating on an
2179
+ * installed plugin.
2180
+ */
2181
+ export function mergePluginSources(sources) {
2182
+ const errors = [];
2183
+ const managed = sources.managedNames;
2184
+ // Managed settings win over --plugin-dir. Drop session plugins whose
2185
+ // name appears in policySettings.enabledPlugins (whether force-enabled
2186
+ // OR force-disabled — both are admin intent that --plugin-dir must not
2187
+ // bypass). Surface an error so the user knows why their dev copy was
2188
+ // ignored.
2189
+ //
2190
+ // NOTE: managedNames contains the pluginId prefix (entry.name), which is
2191
+ // expected to equal manifest.name by convention (schema description at
2192
+ // schemas.ts PluginMarketplaceEntry.name). If a marketplace publishes a
2193
+ // plugin where entry.name ≠ manifest.name, this guard will silently miss —
2194
+ // but that's a marketplace misconfiguration that breaks other things too
2195
+ // (e.g., ManagePlugins constructs pluginIds from manifest.name).
2196
+ const sessionPlugins = sources.session.filter(p => {
2197
+ if (managed?.has(p.name)) {
2198
+ logForDebugging(`Plugin "${p.name}" from --plugin-dir is blocked by managed settings`, { level: 'warn' });
2199
+ errors.push({
2200
+ type: 'generic-error',
2201
+ source: p.source,
2202
+ plugin: p.name,
2203
+ error: `--plugin-dir copy of "${p.name}" ignored: plugin is locked by managed settings`,
2204
+ });
2205
+ return false;
2206
+ }
2207
+ return true;
2208
+ });
2209
+ const sessionNames = new Set(sessionPlugins.map(p => p.name));
2210
+ const marketplacePlugins = sources.marketplace.filter(p => {
2211
+ if (sessionNames.has(p.name)) {
2212
+ logForDebugging(`Plugin "${p.name}" from --plugin-dir overrides installed version`);
2213
+ return false;
2214
+ }
2215
+ return true;
2216
+ });
2217
+ // Session first, then non-overridden marketplace, then builtin.
2218
+ // Downstream first-match consumers see session plugins before
2219
+ // installed ones for any that slipped past the name filter.
2220
+ return {
2221
+ plugins: [...sessionPlugins, ...marketplacePlugins, ...sources.builtin],
2222
+ errors,
2223
+ };
2224
+ }
2225
+ /**
2226
+ * Main plugin loading function that discovers and loads all plugins.
2227
+ *
2228
+ * This function is memoized to avoid repeated filesystem scanning and is
2229
+ * the primary entry point for the plugin system. It discovers plugins from
2230
+ * multiple sources and returns categorized results.
2231
+ *
2232
+ * Loading order and precedence (see mergePluginSources):
2233
+ * 1. Session-only plugins (from --plugin-dir CLI flag) — override
2234
+ * installed plugins with the same name, UNLESS that plugin is
2235
+ * locked by managed settings (policySettings, either force-enabled
2236
+ * or force-disabled)
2237
+ * 2. Marketplace-based plugins (plugin@marketplace format from settings)
2238
+ * 3. Built-in plugins shipped with the CLI
2239
+ *
2240
+ * Name collision: session plugin wins over installed. The user explicitly
2241
+ * pointed at a directory for this session — that intent beats whatever
2242
+ * is installed. Exception: managed settings (enterprise policy) win over
2243
+ * --plugin-dir. Admin intent beats local dev convenience.
2244
+ *
2245
+ * Error collection:
2246
+ * - Non-fatal errors are collected and returned
2247
+ * - System continues loading other plugins on errors
2248
+ * - Errors include source information for debugging
2249
+ *
2250
+ * @returns Promise resolving to categorized plugin results:
2251
+ * - enabled: Array of enabled LoadedPlugin objects
2252
+ * - disabled: Array of disabled LoadedPlugin objects
2253
+ * - errors: Array of loading errors with source information
2254
+ */
2255
+ export const loadAllPlugins = memoize(async () => {
2256
+ const result = await assemblePluginLoadResult(() => loadPluginsFromMarketplaces({ cacheOnly: false }));
2257
+ // A fresh full-load result is strictly valid for cache-only callers
2258
+ // (both variants share assemblePluginLoadResult). Warm the separate
2259
+ // memoize so refreshActivePlugins()'s downstream getPluginCommands() /
2260
+ // getAgentDefinitionsWithOverrides() — which now call
2261
+ // loadAllPluginsCacheOnly — see just-cloned plugins instead of reading
2262
+ // an installed_plugins.json that nothing writes mid-session.
2263
+ loadAllPluginsCacheOnly.cache?.set(undefined, Promise.resolve(result));
2264
+ return result;
2265
+ });
2266
+ /**
2267
+ * Cache-only variant of loadAllPlugins.
2268
+ *
2269
+ * Same merge/dependency/settings logic, but the marketplace loader never
2270
+ * hits the network (no cachePlugin, no copyPluginToVersionedCache). Reads
2271
+ * from installed_plugins.json's installPath. Plugins not on disk emit
2272
+ * 'plugin-cache-miss' and are skipped.
2273
+ *
2274
+ * Use this in startup consumers (getCommands, loadPluginAgents, MCP/LSP
2275
+ * config) so interactive startup never blocks on git clones for ref-tracked
2276
+ * plugins. Use loadAllPlugins() in explicit refresh paths (/plugins,
2277
+ * refresh.ts, headlessPluginInstall) where fresh source is the intent.
2278
+ *
2279
+ * THADDEUS_SYNC_PLUGIN_INSTALL=1 delegates to the full loader — that
2280
+ * mode explicitly opts into blocking install before first query, and
2281
+ * main.tsx's getThaddeusMcpConfigs()/getInitialSettings().agent run
2282
+ * BEFORE runHeadless() can warm this cache. First-run CCR/headless has
2283
+ * no installed_plugins.json, so cache-only would miss plugin MCP servers
2284
+ * and plugin settings (the agent key). The interactive startup win is
2285
+ * preserved since interactive mode doesn't set SYNC_PLUGIN_INSTALL.
2286
+ *
2287
+ * Separate memoize cache from loadAllPlugins — a cache-only result must
2288
+ * never satisfy a caller that wants fresh source. The reverse IS valid:
2289
+ * loadAllPlugins warms this cache on completion so refresh paths that run
2290
+ * the full loader don't get plugin-cache-miss from their downstream
2291
+ * cache-only consumers.
2292
+ */
2293
+ export const loadAllPluginsCacheOnly = memoize(async () => {
2294
+ if (isEnvTruthy(process.env.THADDEUS_SYNC_PLUGIN_INSTALL)) {
2295
+ return loadAllPlugins();
2296
+ }
2297
+ return assemblePluginLoadResult(() => loadPluginsFromMarketplaces({ cacheOnly: true }));
2298
+ });
2299
+ /**
2300
+ * Shared body of loadAllPlugins and loadAllPluginsCacheOnly.
2301
+ *
2302
+ * The only difference between the two is which marketplace loader runs —
2303
+ * session plugins, builtins, merge, verifyAndDemote, and cachePluginSettings
2304
+ * are identical (invariants 1-3).
2305
+ */
2306
+ async function assemblePluginLoadResult(marketplaceLoader) {
2307
+ // Load marketplace plugins and session-only plugins in parallel.
2308
+ // getInlinePlugins() is a synchronous state read with no dependency on
2309
+ // marketplace loading, so these two sources can be fetched concurrently.
2310
+ const inlinePlugins = getInlinePlugins();
2311
+ const [marketplaceResult, sessionResult] = await Promise.all([
2312
+ marketplaceLoader(),
2313
+ inlinePlugins.length > 0
2314
+ ? loadSessionOnlyPlugins(inlinePlugins)
2315
+ : Promise.resolve({ plugins: [], errors: [] }),
2316
+ ]);
2317
+ // 3. Load built-in plugins that ship with the CLI
2318
+ const builtinResult = getBuiltinPlugins();
2319
+ // Session plugins (--plugin-dir) override installed ones by name,
2320
+ // UNLESS the installed plugin is locked by managed settings
2321
+ // (policySettings). See mergePluginSources() for details.
2322
+ const { plugins: allPlugins, errors: mergeErrors } = mergePluginSources({
2323
+ session: sessionResult.plugins,
2324
+ marketplace: marketplaceResult.plugins,
2325
+ builtin: [...builtinResult.enabled, ...builtinResult.disabled],
2326
+ managedNames: getManagedPluginNames(),
2327
+ });
2328
+ const allErrors = [
2329
+ ...marketplaceResult.errors,
2330
+ ...sessionResult.errors,
2331
+ ...mergeErrors,
2332
+ ];
2333
+ // Verify dependencies. Runs AFTER the parallel load — deps are presence
2334
+ // checks, not load-order, so no topological sort needed. Demotion is
2335
+ // session-local: does NOT write settings (user fixes intent via /doctor).
2336
+ const { demoted, errors: depErrors } = verifyAndDemote(allPlugins);
2337
+ for (const p of allPlugins) {
2338
+ if (demoted.has(p.source))
2339
+ p.enabled = false;
2340
+ }
2341
+ allErrors.push(...depErrors);
2342
+ const enabledPlugins = allPlugins.filter(p => p.enabled);
2343
+ logForDebugging(`Found ${allPlugins.length} plugins (${enabledPlugins.length} enabled, ${allPlugins.length - enabledPlugins.length} disabled)`);
2344
+ // 3. Cache plugin settings for synchronous access by the settings cascade
2345
+ cachePluginSettings(enabledPlugins);
2346
+ return {
2347
+ enabled: enabledPlugins,
2348
+ disabled: allPlugins.filter(p => !p.enabled),
2349
+ errors: allErrors,
2350
+ };
2351
+ }
2352
+ /**
2353
+ * Clears the memoized plugin cache.
2354
+ *
2355
+ * Call this when plugins are installed, removed, or settings change
2356
+ * to force a fresh scan on the next loadAllPlugins call.
2357
+ *
2358
+ * Use cases:
2359
+ * - After installing/uninstalling plugins
2360
+ * - After modifying .claude-plugin/ directory (for export)
2361
+ * - After changing enabledPlugins settings
2362
+ * - When debugging plugin loading issues
2363
+ */
2364
+ export function clearPluginCache(reason) {
2365
+ if (reason) {
2366
+ logForDebugging(`clearPluginCache: invalidating loadAllPlugins cache (${reason})`);
2367
+ }
2368
+ loadAllPlugins.cache?.clear?.();
2369
+ loadAllPluginsCacheOnly.cache?.clear?.();
2370
+ // If a plugin previously contributed settings, the session settings cache
2371
+ // holds a merged result that includes them. cachePluginSettings() on reload
2372
+ // won't bust the cache when the new base is empty (the startup perf win),
2373
+ // so bust it here to drop stale plugin overrides. When the base is already
2374
+ // undefined (startup, or no prior plugin settings) this is a no-op.
2375
+ if (getPluginSettingsBase() !== undefined) {
2376
+ resetSettingsCache();
2377
+ }
2378
+ clearPluginSettingsBase();
2379
+ // TODO: Clear installed plugins cache when installedPluginsManager is implemented
2380
+ }
2381
+ /**
2382
+ * Merge settings from all enabled plugins into a single record.
2383
+ * Later plugins override earlier ones for the same key.
2384
+ * Only allowlisted keys are included (filtering happens at load time).
2385
+ */
2386
+ function mergePluginSettings(plugins) {
2387
+ let merged;
2388
+ for (const plugin of plugins) {
2389
+ if (!plugin.settings) {
2390
+ continue;
2391
+ }
2392
+ if (!merged) {
2393
+ merged = {};
2394
+ }
2395
+ for (const [key, value] of Object.entries(plugin.settings)) {
2396
+ if (key in merged) {
2397
+ logForDebugging(`Plugin "${plugin.name}" overrides setting "${key}" (previously set by another plugin)`);
2398
+ }
2399
+ merged[key] = value;
2400
+ }
2401
+ }
2402
+ return merged;
2403
+ }
2404
+ /**
2405
+ * Store merged plugin settings in the synchronous cache.
2406
+ * Called after loadAllPlugins resolves.
2407
+ */
2408
+ export function cachePluginSettings(plugins) {
2409
+ const settings = mergePluginSettings(plugins);
2410
+ setPluginSettingsBase(settings);
2411
+ // Only bust the session settings cache if there are actually plugin settings
2412
+ // to merge. In the common case (no plugins, or plugins without settings) the
2413
+ // base layer is empty and loadSettingsFromDisk would produce the same result
2414
+ // anyway — resetting here would waste ~17ms on startup re-reading and
2415
+ // re-validating every settings file on the next getSettingsWithErrors() call.
2416
+ if (settings && Object.keys(settings).length > 0) {
2417
+ resetSettingsCache();
2418
+ logForDebugging(`Cached plugin settings with keys: ${Object.keys(settings).join(', ')}`);
2419
+ }
2420
+ }
2421
+ /**
2422
+ * Type predicate: check if a value is a non-null, non-array object (i.e., a record).
2423
+ */
2424
+ function isRecord(value) {
2425
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
2426
+ }