@iaforged/context-code 1.0.72 → 1.0.74

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 (2050) hide show
  1. package/context-bootstrap.js +7 -8
  2. package/dist/src/QueryEngine.js +928 -0
  3. package/dist/src/Task.js +49 -0
  4. package/dist/src/Tool.js +56 -0
  5. package/dist/src/assistant/AssistantSessionChooser.js +16 -0
  6. package/dist/src/assistant/index.js +16 -0
  7. package/dist/src/assistant/sessionDiscovery.js +16 -0
  8. package/dist/src/assistant/sessionHistory.js +47 -0
  9. package/dist/src/bootstrap/state.js +1165 -0
  10. package/dist/src/bridge/bridgeApi.js +304 -0
  11. package/dist/src/bridge/bridgeConfig.js +39 -0
  12. package/dist/src/bridge/bridgeDebug.js +73 -0
  13. package/dist/src/bridge/bridgeEnabled.js +187 -0
  14. package/dist/src/bridge/bridgeMain.js +2289 -0
  15. package/dist/src/bridge/bridgeMessaging.js +353 -0
  16. package/dist/src/bridge/bridgePermissionCallbacks.js +10 -0
  17. package/dist/src/bridge/bridgePointer.js +175 -0
  18. package/dist/src/bridge/bridgeStatusUtil.js +105 -0
  19. package/dist/src/bridge/bridgeUI.js +412 -0
  20. package/dist/src/bridge/capacityWake.js +35 -0
  21. package/dist/src/bridge/codeSessionApi.js +111 -0
  22. package/dist/src/bridge/createSession.js +273 -0
  23. package/dist/src/bridge/debugUtils.js +115 -0
  24. package/dist/src/bridge/envLessBridgeConfig.js +121 -0
  25. package/dist/src/bridge/flushGate.js +65 -0
  26. package/dist/src/bridge/inboundAttachments.js +152 -0
  27. package/dist/src/bridge/inboundMessages.js +63 -0
  28. package/dist/src/bridge/initReplBridge.js +428 -0
  29. package/dist/src/bridge/jwtUtils.js +185 -0
  30. package/dist/src/bridge/pollConfig.js +85 -0
  31. package/dist/src/bridge/pollConfigDefaults.js +62 -0
  32. package/dist/src/bridge/remoteBridgeCore.js +712 -0
  33. package/dist/src/bridge/replBridge.js +1720 -0
  34. package/dist/src/bridge/replBridgeHandle.js +30 -0
  35. package/dist/src/bridge/replBridgeTransport.js +236 -0
  36. package/dist/src/bridge/sessionIdCompat.js +56 -0
  37. package/dist/src/bridge/sessionRunner.js +421 -0
  38. package/dist/src/bridge/trustedDevice.js +172 -0
  39. package/dist/src/bridge/types.js +9 -0
  40. package/dist/src/bridge/workSecret.js +99 -0
  41. package/dist/src/buddy/CompanionSprite.js +349 -0
  42. package/dist/src/buddy/companion.js +107 -0
  43. package/dist/src/buddy/prompt.js +33 -0
  44. package/dist/src/buddy/sprites.js +488 -0
  45. package/dist/src/buddy/types.js +90 -0
  46. package/dist/src/buddy/useBuddyNotification.js +90 -0
  47. package/dist/src/cli/bg.js +16 -0
  48. package/dist/src/cli/exit.js +30 -0
  49. package/dist/src/cli/handlers/agents.js +55 -0
  50. package/dist/src/cli/handlers/ant.js +16 -0
  51. package/dist/src/cli/handlers/auth.js +315 -0
  52. package/dist/src/cli/handlers/autoMode.js +128 -0
  53. package/dist/src/cli/handlers/mcp.js +334 -0
  54. package/dist/src/cli/handlers/plugins.js +634 -0
  55. package/dist/src/cli/handlers/projects_bridge.js +40 -0
  56. package/dist/src/cli/handlers/provider.js +42 -0
  57. package/dist/src/cli/handlers/templateJobs.js +16 -0
  58. package/dist/src/cli/handlers/util.js +76 -0
  59. package/dist/src/cli/ndjsonSafeStringify.js +27 -0
  60. package/dist/src/cli/print.js +4225 -0
  61. package/dist/src/cli/remoteIO.js +208 -0
  62. package/dist/src/cli/rollback.js +16 -0
  63. package/dist/src/cli/structuredIO.js +644 -0
  64. package/dist/src/cli/transports/HybridTransport.js +233 -0
  65. package/dist/src/cli/transports/SSETransport.js +538 -0
  66. package/dist/src/cli/transports/SerialBatchEventUploader.js +224 -0
  67. package/dist/src/cli/transports/Transport.js +1 -0
  68. package/dist/src/cli/transports/WebSocketTransport.js +613 -0
  69. package/dist/src/cli/transports/WorkerStateUploader.js +88 -0
  70. package/dist/src/cli/transports/ccrClient.js +711 -0
  71. package/dist/src/cli/transports/transportUtils.js +39 -0
  72. package/dist/src/cli/up.js +16 -0
  73. package/dist/src/cli/update.js +315 -0
  74. package/dist/src/commands/add-dir/add-dir.js +121 -0
  75. package/dist/src/commands/add-dir/index.js +8 -0
  76. package/dist/src/commands/add-dir/validation.js +76 -0
  77. package/dist/src/commands/advisor.js +88 -0
  78. package/dist/src/commands/agent/agent.js +283 -0
  79. package/dist/src/commands/agent/agentStore.js +120 -0
  80. package/dist/src/commands/agent/index.js +9 -0
  81. package/dist/src/commands/agents/agents.js +9 -0
  82. package/dist/src/commands/agents/index.js +7 -0
  83. package/dist/src/commands/ant-trace/index.js +1 -0
  84. package/dist/src/commands/assistant/assistant.js +16 -0
  85. package/dist/src/commands/autofix-pr/index.js +1 -0
  86. package/dist/src/commands/backfill-sessions/index.js +1 -0
  87. package/dist/src/commands/branch/branch.js +205 -0
  88. package/dist/src/commands/branch/index.js +11 -0
  89. package/dist/src/commands/break-cache/index.js +1 -0
  90. package/dist/src/commands/bridge/bridge.js +512 -0
  91. package/dist/src/commands/bridge/index.js +22 -0
  92. package/dist/src/commands/bridge-kick.js +179 -0
  93. package/dist/src/commands/brief.js +94 -0
  94. package/dist/src/commands/btw/btw.js +234 -0
  95. package/dist/src/commands/btw/index.js +9 -0
  96. package/dist/src/commands/bughunter/index.js +1 -0
  97. package/dist/src/commands/chrome/chrome.js +291 -0
  98. package/dist/src/commands/chrome/index.js +11 -0
  99. package/dist/src/commands/clear/caches.js +116 -0
  100. package/dist/src/commands/clear/clear.js +5 -0
  101. package/dist/src/commands/clear/conversation.js +191 -0
  102. package/dist/src/commands/clear/index.js +9 -0
  103. package/dist/src/commands/color/color.js +58 -0
  104. package/dist/src/commands/color/index.js +9 -0
  105. package/dist/src/commands/commit-push-pr.js +137 -0
  106. package/dist/src/commands/commit.js +80 -0
  107. package/dist/src/commands/compact/compact.js +196 -0
  108. package/dist/src/commands/compact/index.js +11 -0
  109. package/dist/src/commands/config/config.js +5 -0
  110. package/dist/src/commands/config/index.js +8 -0
  111. package/dist/src/commands/context/context-noninteractive.js +221 -0
  112. package/dist/src/commands/context/context.js +46 -0
  113. package/dist/src/commands/context/index.js +21 -0
  114. package/dist/src/commands/copy/copy.js +366 -0
  115. package/dist/src/commands/copy/index.js +7 -0
  116. package/dist/src/commands/cost/cost.js +21 -0
  117. package/dist/src/commands/cost/index.js +16 -0
  118. package/dist/src/commands/createMovedToPluginCommand.js +33 -0
  119. package/dist/src/commands/ctx_viz/index.js +1 -0
  120. package/dist/src/commands/debug-tool-call/index.js +1 -0
  121. package/dist/src/commands/desktop/desktop.js +5 -0
  122. package/dist/src/commands/desktop/index.js +22 -0
  123. package/dist/src/commands/diff/diff.js +5 -0
  124. package/dist/src/commands/diff/index.js +6 -0
  125. package/dist/src/commands/doctor/doctor.js +5 -0
  126. package/dist/src/commands/doctor/index.js +9 -0
  127. package/dist/src/commands/effort/effort.js +166 -0
  128. package/dist/src/commands/effort/index.js +11 -0
  129. package/dist/src/commands/env/index.js +1 -0
  130. package/dist/src/commands/exit/exit.js +31 -0
  131. package/dist/src/commands/exit/index.js +9 -0
  132. package/dist/src/commands/export/export.js +86 -0
  133. package/dist/src/commands/export/index.js +8 -0
  134. package/dist/src/commands/extra-usage/extra-usage-core.js +99 -0
  135. package/dist/src/commands/extra-usage/extra-usage-noninteractive.js +13 -0
  136. package/dist/src/commands/extra-usage/extra-usage.js +14 -0
  137. package/dist/src/commands/extra-usage/index.js +27 -0
  138. package/dist/src/commands/fast/fast.js +275 -0
  139. package/dist/src/commands/fast/index.js +20 -0
  140. package/dist/src/commands/feedback/feedback.js +10 -0
  141. package/dist/src/commands/feedback/index.js +21 -0
  142. package/dist/src/commands/files/files.js +11 -0
  143. package/dist/src/commands/files/index.js +9 -0
  144. package/dist/src/commands/good-claude/index.js +1 -0
  145. package/dist/src/commands/heapdump/heapdump.js +14 -0
  146. package/dist/src/commands/heapdump/index.js +9 -0
  147. package/dist/src/commands/help/help.js +5 -0
  148. package/dist/src/commands/help/index.js +7 -0
  149. package/dist/src/commands/hooks/hooks.js +11 -0
  150. package/dist/src/commands/hooks/index.js +8 -0
  151. package/dist/src/commands/ide/ide.js +615 -0
  152. package/dist/src/commands/ide/index.js +8 -0
  153. package/dist/src/commands/init-verifiers.js +258 -0
  154. package/dist/src/commands/init.js +249 -0
  155. package/dist/src/commands/insights.js +2555 -0
  156. package/dist/src/commands/install-github-app/ApiKeyStep.js +230 -0
  157. package/dist/src/commands/install-github-app/CheckExistingSecretStep.js +194 -0
  158. package/dist/src/commands/install-github-app/CheckGitHubStep.js +15 -0
  159. package/dist/src/commands/install-github-app/ChooseRepoStep.js +211 -0
  160. package/dist/src/commands/install-github-app/CreatingStep.js +52 -0
  161. package/dist/src/commands/install-github-app/ErrorStep.js +83 -0
  162. package/dist/src/commands/install-github-app/ExistingWorkflowStep.js +104 -0
  163. package/dist/src/commands/install-github-app/InstallAppStep.js +96 -0
  164. package/dist/src/commands/install-github-app/OAuthFlowStep.js +190 -0
  165. package/dist/src/commands/install-github-app/SuccessStep.js +93 -0
  166. package/dist/src/commands/install-github-app/WarningsStep.js +70 -0
  167. package/dist/src/commands/install-github-app/index.js +10 -0
  168. package/dist/src/commands/install-github-app/install-github-app.js +593 -0
  169. package/dist/src/commands/install-github-app/setupGitHubActions.js +227 -0
  170. package/dist/src/commands/install-slack-app/index.js +9 -0
  171. package/dist/src/commands/install-slack-app/install-slack-app.js +25 -0
  172. package/dist/src/commands/install.js +118 -0
  173. package/dist/src/commands/issue/index.js +1 -0
  174. package/dist/src/commands/keybindings/index.js +10 -0
  175. package/dist/src/commands/keybindings/keybindings.js +47 -0
  176. package/dist/src/commands/limites/index.js +8 -0
  177. package/dist/src/commands/limites/limites.js +214 -0
  178. package/dist/src/commands/login/index.js +11 -0
  179. package/dist/src/commands/login/login.js +120 -0
  180. package/dist/src/commands/login-openai/index.js +7 -0
  181. package/dist/src/commands/login-openai/login-openai.js +54 -0
  182. package/dist/src/commands/logout/index.js +8 -0
  183. package/dist/src/commands/logout/logout.js +72 -0
  184. package/dist/src/commands/mcp/addCommand.js +183 -0
  185. package/dist/src/commands/mcp/index.js +9 -0
  186. package/dist/src/commands/mcp/mcp.js +78 -0
  187. package/dist/src/commands/mcp/xaaIdpCommand.js +193 -0
  188. package/dist/src/commands/memory/index.js +7 -0
  189. package/dist/src/commands/memory/memory.js +71 -0
  190. package/dist/src/commands/mobile/index.js +9 -0
  191. package/dist/src/commands/mobile/mobile.js +278 -0
  192. package/dist/src/commands/mock-limits/index.js +1 -0
  193. package/dist/src/commands/model/index.js +14 -0
  194. package/dist/src/commands/model/model.js +297 -0
  195. package/dist/src/commands/oauth-refresh/index.js +1 -0
  196. package/dist/src/commands/onboarding/index.js +1 -0
  197. package/dist/src/commands/orchestrate/index.js +8 -0
  198. package/dist/src/commands/orchestrate/orchestrate.js +542 -0
  199. package/dist/src/commands/output-style/index.js +8 -0
  200. package/dist/src/commands/output-style/output-style.js +6 -0
  201. package/dist/src/commands/passes/index.js +17 -0
  202. package/dist/src/commands/passes/passes.js +22 -0
  203. package/dist/src/commands/perf-issue/index.js +1 -0
  204. package/dist/src/commands/permissions/index.js +8 -0
  205. package/dist/src/commands/permissions/permissions.js +8 -0
  206. package/dist/src/commands/plan/index.js +8 -0
  207. package/dist/src/commands/plan/plan.js +115 -0
  208. package/dist/src/commands/plugin/AddMarketplace.js +95 -0
  209. package/dist/src/commands/plugin/BrowseMarketplace.js +576 -0
  210. package/dist/src/commands/plugin/DiscoverPlugins.js +613 -0
  211. package/dist/src/commands/plugin/ManageMarketplaces.js +582 -0
  212. package/dist/src/commands/plugin/ManagePlugins.js +1783 -0
  213. package/dist/src/commands/plugin/PluginErrors.js +124 -0
  214. package/dist/src/commands/plugin/PluginOptionsDialog.js +367 -0
  215. package/dist/src/commands/plugin/PluginOptionsFlow.js +97 -0
  216. package/dist/src/commands/plugin/PluginSettings.js +1042 -0
  217. package/dist/src/commands/plugin/PluginTrustWarning.js +34 -0
  218. package/dist/src/commands/plugin/UnifiedInstalledCell.js +615 -0
  219. package/dist/src/commands/plugin/ValidatePlugin.js +95 -0
  220. package/dist/src/commands/plugin/index.js +10 -0
  221. package/dist/src/commands/plugin/parseArgs.js +71 -0
  222. package/dist/src/commands/plugin/plugin.js +5 -0
  223. package/dist/src/commands/plugin/pluginDetailsHelpers.js +89 -0
  224. package/dist/src/commands/plugin/usePagination.js +89 -0
  225. package/dist/src/commands/policy/index.js +9 -0
  226. package/dist/src/commands/policy/policy.js +84 -0
  227. package/dist/src/commands/pr_comments/index.js +49 -0
  228. package/dist/src/commands/privacy-settings/index.js +11 -0
  229. package/dist/src/commands/privacy-settings/privacy-settings.js +54 -0
  230. package/dist/src/commands/profile/index.js +9 -0
  231. package/dist/src/commands/profile/profile.js +482 -0
  232. package/dist/src/commands/provider/index.js +8 -0
  233. package/dist/src/commands/provider/provider.js +457 -0
  234. package/dist/src/commands/rate-limit-options/index.js +15 -0
  235. package/dist/src/commands/rate-limit-options/rate-limit-options.js +213 -0
  236. package/dist/src/commands/release-notes/index.js +9 -0
  237. package/dist/src/commands/release-notes/release-notes.js +38 -0
  238. package/dist/src/commands/reload-plugins/index.js +11 -0
  239. package/dist/src/commands/reload-plugins/reload-plugins.js +52 -0
  240. package/dist/src/commands/remote-env/index.js +12 -0
  241. package/dist/src/commands/remote-env/remote-env.js +5 -0
  242. package/dist/src/commands/remote-setup/api.js +155 -0
  243. package/dist/src/commands/remote-setup/index.js +15 -0
  244. package/dist/src/commands/remote-setup/remote-setup.js +149 -0
  245. package/dist/src/commands/rename/generateSessionName.js +58 -0
  246. package/dist/src/commands/rename/index.js +9 -0
  247. package/dist/src/commands/rename/rename.js +52 -0
  248. package/dist/src/commands/reset-limits/index.js +4 -0
  249. package/dist/src/commands/resume/index.js +9 -0
  250. package/dist/src/commands/resume/resume.js +239 -0
  251. package/dist/src/commands/review/UltrareviewOverageDialog.js +97 -0
  252. package/dist/src/commands/review/reviewRemote.js +259 -0
  253. package/dist/src/commands/review/ultrareviewCommand.js +57 -0
  254. package/dist/src/commands/review/ultrareviewEnabled.js +10 -0
  255. package/dist/src/commands/review.js +50 -0
  256. package/dist/src/commands/rewind/index.js +10 -0
  257. package/dist/src/commands/rewind/rewind.js +7 -0
  258. package/dist/src/commands/run/index.js +9 -0
  259. package/dist/src/commands/run/run.js +1126 -0
  260. package/dist/src/commands/sandbox-toggle/index.js +41 -0
  261. package/dist/src/commands/sandbox-toggle/sandbox-toggle.js +72 -0
  262. package/dist/src/commands/security-review.js +231 -0
  263. package/dist/src/commands/session/index.js +13 -0
  264. package/dist/src/commands/session/session.js +142 -0
  265. package/dist/src/commands/share/index.js +1 -0
  266. package/dist/src/commands/skills/index.js +8 -0
  267. package/dist/src/commands/skills/skills.js +97 -0
  268. package/dist/src/commands/stats/index.js +7 -0
  269. package/dist/src/commands/stats/stats.js +5 -0
  270. package/dist/src/commands/status/index.js +8 -0
  271. package/dist/src/commands/status/status.js +5 -0
  272. package/dist/src/commands/statusline.js +22 -0
  273. package/dist/src/commands/stickers/index.js +9 -0
  274. package/dist/src/commands/stickers/stickers.js +14 -0
  275. package/dist/src/commands/summary/index.js +1 -0
  276. package/dist/src/commands/tag/index.js +9 -0
  277. package/dist/src/commands/tag/tag.js +215 -0
  278. package/dist/src/commands/tasks/index.js +8 -0
  279. package/dist/src/commands/tasks/tasks.js +5 -0
  280. package/dist/src/commands/team/index.js +9 -0
  281. package/dist/src/commands/team/team.js +582 -0
  282. package/dist/src/commands/team-auto/index.js +9 -0
  283. package/dist/src/commands/team-auto/teamAuto.js +340 -0
  284. package/dist/src/commands/telegram/index.js +9 -0
  285. package/dist/src/commands/telegram/telegram.js +118 -0
  286. package/dist/src/commands/teleport/index.js +1 -0
  287. package/dist/src/commands/terminalSetup/index.js +18 -0
  288. package/dist/src/commands/terminalSetup/terminalSetup.js +491 -0
  289. package/dist/src/commands/theme/index.js +7 -0
  290. package/dist/src/commands/theme/theme.js +50 -0
  291. package/dist/src/commands/thinkback/index.js +9 -0
  292. package/dist/src/commands/thinkback/thinkback.js +527 -0
  293. package/dist/src/commands/thinkback-play/index.js +13 -0
  294. package/dist/src/commands/thinkback-play/thinkback-play.js +34 -0
  295. package/dist/src/commands/ultraplan.js +418 -0
  296. package/dist/src/commands/upgrade/index.js +12 -0
  297. package/dist/src/commands/upgrade/upgrade.js +37 -0
  298. package/dist/src/commands/version.js +18 -0
  299. package/dist/src/commands/vim/index.js +8 -0
  300. package/dist/src/commands/vim/vim.js +25 -0
  301. package/dist/src/commands/voice/index.js +14 -0
  302. package/dist/src/commands/voice/voice.js +130 -0
  303. package/dist/src/commands/whatsapp/index.js +9 -0
  304. package/dist/src/commands/whatsapp/whatsapp.js +326 -0
  305. package/dist/src/commands/workspace/index.js +9 -0
  306. package/dist/src/commands/workspace/workspace.js +701 -0
  307. package/dist/src/commands.js +635 -0
  308. package/dist/src/components/AgentProgressLine.js +111 -0
  309. package/dist/src/components/App.js +45 -0
  310. package/dist/src/components/ApproveApiKey.js +124 -0
  311. package/dist/src/components/AutoModeOptInDialog.js +140 -0
  312. package/dist/src/components/AutoUpdater.js +157 -0
  313. package/dist/src/components/AutoUpdaterWrapper.js +78 -0
  314. package/dist/src/components/AwsAuthStatusBox.js +88 -0
  315. package/dist/src/components/BaseTextInput.js +105 -0
  316. package/dist/src/components/BashModeProgress.js +48 -0
  317. package/dist/src/components/BridgeDialog.js +414 -0
  318. package/dist/src/components/BypassPermissionsModeDialog.js +87 -0
  319. package/dist/src/components/ChannelDowngradeDialog.js +100 -0
  320. package/dist/src/components/ClaudeCodeHint/PluginHintMenu.js +37 -0
  321. package/dist/src/components/ClaudeInChromeOnboarding.js +126 -0
  322. package/dist/src/components/ClaudeMdExternalIncludesDialog.js +137 -0
  323. package/dist/src/components/ClickableImageRef.js +64 -0
  324. package/dist/src/components/CompactSummary.js +119 -0
  325. package/dist/src/components/ConfigurableShortcutHint.js +34 -0
  326. package/dist/src/components/ConsoleOAuthFlow.js +758 -0
  327. package/dist/src/components/ContextSuggestions.js +43 -0
  328. package/dist/src/components/ContextVisualization.js +483 -0
  329. package/dist/src/components/CoordinatorAgentStatus.js +261 -0
  330. package/dist/src/components/CostThresholdDialog.js +48 -0
  331. package/dist/src/components/CtrlOToExpand.js +50 -0
  332. package/dist/src/components/CustomSelect/SelectMulti.js +149 -0
  333. package/dist/src/components/CustomSelect/index.js +2 -0
  334. package/dist/src/components/CustomSelect/option-map.js +32 -0
  335. package/dist/src/components/CustomSelect/select-input-option.js +426 -0
  336. package/dist/src/components/CustomSelect/select-option.js +23 -0
  337. package/dist/src/components/CustomSelect/select.js +518 -0
  338. package/dist/src/components/CustomSelect/use-multi-select-state.js +214 -0
  339. package/dist/src/components/CustomSelect/use-select-input.js +170 -0
  340. package/dist/src/components/CustomSelect/use-select-navigation.js +366 -0
  341. package/dist/src/components/CustomSelect/use-select-state.js +22 -0
  342. package/dist/src/components/DesktopHandoff.js +195 -0
  343. package/dist/src/components/DesktopUpsell/DesktopUpsellStartup.js +173 -0
  344. package/dist/src/components/DevBar.js +50 -0
  345. package/dist/src/components/DevChannelsDialog.js +103 -0
  346. package/dist/src/components/DiagnosticsDisplay.js +91 -0
  347. package/dist/src/components/EffortCallout.js +264 -0
  348. package/dist/src/components/EffortIndicator.js +29 -0
  349. package/dist/src/components/ExitFlow.js +40 -0
  350. package/dist/src/components/ExportDialog.js +101 -0
  351. package/dist/src/components/FallbackToolUseErrorMessage.js +115 -0
  352. package/dist/src/components/FallbackToolUseRejectedMessage.js +16 -0
  353. package/dist/src/components/FastIcon.js +42 -0
  354. package/dist/src/components/Feedback.js +439 -0
  355. package/dist/src/components/FeedbackSurvey/FeedbackSurvey.js +150 -0
  356. package/dist/src/components/FeedbackSurvey/FeedbackSurveyView.js +103 -0
  357. package/dist/src/components/FeedbackSurvey/TranscriptSharePrompt.js +83 -0
  358. package/dist/src/components/FeedbackSurvey/submitTranscriptShare.js +81 -0
  359. package/dist/src/components/FeedbackSurvey/useDebouncedDigitInput.js +51 -0
  360. package/dist/src/components/FeedbackSurvey/useFeedbackSurvey.js +258 -0
  361. package/dist/src/components/FeedbackSurvey/useMemorySurvey.js +191 -0
  362. package/dist/src/components/FeedbackSurvey/usePostCompactSurvey.js +202 -0
  363. package/dist/src/components/FeedbackSurvey/useSurveyState.js +80 -0
  364. package/dist/src/components/FileEditToolDiff.js +166 -0
  365. package/dist/src/components/FileEditToolUpdatedMessage.js +111 -0
  366. package/dist/src/components/FileEditToolUseRejectedMessage.js +157 -0
  367. package/dist/src/components/FilePathLink.js +34 -0
  368. package/dist/src/components/FullscreenLayout.js +578 -0
  369. package/dist/src/components/GlobalSearchDialog.js +339 -0
  370. package/dist/src/components/HelpV2/Commands.js +65 -0
  371. package/dist/src/components/HelpV2/General.js +24 -0
  372. package/dist/src/components/HelpV2/HelpV2.js +186 -0
  373. package/dist/src/components/HighlightedCode/Fallback.js +193 -0
  374. package/dist/src/components/HighlightedCode.js +184 -0
  375. package/dist/src/components/HistorySearchDialog.js +92 -0
  376. package/dist/src/components/IdeAutoConnectDialog.js +153 -0
  377. package/dist/src/components/IdeOnboardingDialog.js +174 -0
  378. package/dist/src/components/IdeStatusIndicator.js +49 -0
  379. package/dist/src/components/IdleReturnDialog.js +116 -0
  380. package/dist/src/components/InterruptedByUser.js +15 -0
  381. package/dist/src/components/InvalidConfigDialog.js +134 -0
  382. package/dist/src/components/InvalidSettingsDialog.js +84 -0
  383. package/dist/src/components/KeybindingWarnings.js +54 -0
  384. package/dist/src/components/LanguagePicker.js +84 -0
  385. package/dist/src/components/LogSelector.js +1579 -0
  386. package/dist/src/components/LogoV2/AnimatedAsterisk.js +42 -0
  387. package/dist/src/components/LogoV2/AnimatedClawd.js +111 -0
  388. package/dist/src/components/LogoV2/ChannelsNotice.js +258 -0
  389. package/dist/src/components/LogoV2/Clawd.js +12 -0
  390. package/dist/src/components/LogoV2/CondensedLogo.js +144 -0
  391. package/dist/src/components/LogoV2/EmergencyTip.js +47 -0
  392. package/dist/src/components/LogoV2/Feed.js +84 -0
  393. package/dist/src/components/LogoV2/FeedColumn.js +55 -0
  394. package/dist/src/components/LogoV2/GuestPassesUpsell.js +71 -0
  395. package/dist/src/components/LogoV2/LogoV2.js +564 -0
  396. package/dist/src/components/LogoV2/Opus1mMergeNotice.js +56 -0
  397. package/dist/src/components/LogoV2/OverageCreditUpsell.js +160 -0
  398. package/dist/src/components/LogoV2/VoiceModeNotice.js +70 -0
  399. package/dist/src/components/LogoV2/WelcomeV2.js +8 -0
  400. package/dist/src/components/LogoV2/feedConfigs.js +78 -0
  401. package/dist/src/components/LspRecommendation/LspRecommendationMenu.js +46 -0
  402. package/dist/src/components/MCPServerApprovalDialog.js +113 -0
  403. package/dist/src/components/MCPServerDesktopImportDialog.js +206 -0
  404. package/dist/src/components/MCPServerDialogCopy.js +15 -0
  405. package/dist/src/components/MCPServerMultiselectDialog.js +133 -0
  406. package/dist/src/components/ManagedSettingsSecurityDialog/ManagedSettingsSecurityDialog.js +149 -0
  407. package/dist/src/components/ManagedSettingsSecurityDialog/utils.js +105 -0
  408. package/dist/src/components/Markdown.js +217 -0
  409. package/dist/src/components/MarkdownTable.js +279 -0
  410. package/dist/src/components/MemoryUsageIndicator.js +27 -0
  411. package/dist/src/components/Message.js +566 -0
  412. package/dist/src/components/MessageModel.js +36 -0
  413. package/dist/src/components/MessageResponse.js +73 -0
  414. package/dist/src/components/MessageRow.js +346 -0
  415. package/dist/src/components/MessageSelector.js +743 -0
  416. package/dist/src/components/MessageTimestamp.js +57 -0
  417. package/dist/src/components/Messages.js +637 -0
  418. package/dist/src/components/ModelPicker.js +493 -0
  419. package/dist/src/components/NativeAutoUpdater.js +153 -0
  420. package/dist/src/components/NotebookEditToolUseRejectedMessage.js +83 -0
  421. package/dist/src/components/OffscreenFreeze.js +35 -0
  422. package/dist/src/components/Onboarding.js +174 -0
  423. package/dist/src/components/OutputStylePicker.js +102 -0
  424. package/dist/src/components/PackageManagerAutoUpdater.js +100 -0
  425. package/dist/src/components/Passes/Passes.js +113 -0
  426. package/dist/src/components/PrBadge.js +90 -0
  427. package/dist/src/components/PressEnterToContinue.js +15 -0
  428. package/dist/src/components/PromptInput/HistorySearchInput.js +44 -0
  429. package/dist/src/components/PromptInput/IssueFlagBanner.js +8 -0
  430. package/dist/src/components/PromptInput/Notifications.js +221 -0
  431. package/dist/src/components/PromptInput/PromptInput.js +1998 -0
  432. package/dist/src/components/PromptInput/PromptInputFooter.js +84 -0
  433. package/dist/src/components/PromptInput/PromptInputFooterLeftSide.js +409 -0
  434. package/dist/src/components/PromptInput/PromptInputFooterSuggestions.js +280 -0
  435. package/dist/src/components/PromptInput/PromptInputHelpMenu.js +379 -0
  436. package/dist/src/components/PromptInput/PromptInputModeIndicator.js +72 -0
  437. package/dist/src/components/PromptInput/PromptInputQueuedCommands.js +105 -0
  438. package/dist/src/components/PromptInput/PromptInputStashNotice.js +20 -0
  439. package/dist/src/components/PromptInput/SandboxPromptFooterHint.js +65 -0
  440. package/dist/src/components/PromptInput/ShimmeredInput.js +132 -0
  441. package/dist/src/components/PromptInput/VoiceIndicator.js +136 -0
  442. package/dist/src/components/PromptInput/inputModes.js +24 -0
  443. package/dist/src/components/PromptInput/inputPaste.js +62 -0
  444. package/dist/src/components/PromptInput/useMaybeTruncateInput.js +33 -0
  445. package/dist/src/components/PromptInput/usePromptInputPlaceholder.js +55 -0
  446. package/dist/src/components/PromptInput/useShowFastIconHint.js +23 -0
  447. package/dist/src/components/PromptInput/useSwarmBanner.js +112 -0
  448. package/dist/src/components/PromptInput/utils.js +50 -0
  449. package/dist/src/components/QuickOpenDialog.js +243 -0
  450. package/dist/src/components/RemoteCallout.js +53 -0
  451. package/dist/src/components/RemoteEnvironmentDialog.js +345 -0
  452. package/dist/src/components/ResumeTask.js +173 -0
  453. package/dist/src/components/SandboxViolationExpandedView.js +102 -0
  454. package/dist/src/components/ScrollKeybindingHandler.js +982 -0
  455. package/dist/src/components/SearchBox.js +55 -0
  456. package/dist/src/components/SentryErrorBoundary.js +16 -0
  457. package/dist/src/components/SessionBackgroundHint.js +104 -0
  458. package/dist/src/components/SessionPreview.js +200 -0
  459. package/dist/src/components/Settings/Config.js +1628 -0
  460. package/dist/src/components/Settings/Settings.js +129 -0
  461. package/dist/src/components/Settings/Status.js +239 -0
  462. package/dist/src/components/Settings/Usage.js +341 -0
  463. package/dist/src/components/ShowInIDEPrompt.js +151 -0
  464. package/dist/src/components/SkillImprovementSurvey.js +130 -0
  465. package/dist/src/components/Spinner/FlashingChar.js +51 -0
  466. package/dist/src/components/Spinner/GlimmerMessage.js +328 -0
  467. package/dist/src/components/Spinner/ShimmerChar.js +22 -0
  468. package/dist/src/components/Spinner/SpinnerAnimationRow.js +169 -0
  469. package/dist/src/components/Spinner/SpinnerGlyph.js +69 -0
  470. package/dist/src/components/Spinner/TeammateSpinnerLine.js +170 -0
  471. package/dist/src/components/Spinner/TeammateSpinnerTree.js +268 -0
  472. package/dist/src/components/Spinner/index.js +11 -0
  473. package/dist/src/components/Spinner/teammateSelectHint.js +1 -0
  474. package/dist/src/components/Spinner/useShimmerAnimation.js +22 -0
  475. package/dist/src/components/Spinner/useStalledAnimation.js +63 -0
  476. package/dist/src/components/Spinner/utils.js +77 -0
  477. package/dist/src/components/Spinner.js +470 -0
  478. package/dist/src/components/Stats.js +1000 -0
  479. package/dist/src/components/StatusLine.js +288 -0
  480. package/dist/src/components/StatusNotices.js +50 -0
  481. package/dist/src/components/StructuredDiff/Fallback.js +335 -0
  482. package/dist/src/components/StructuredDiff/colorDiff.js +26 -0
  483. package/dist/src/components/StructuredDiff.js +152 -0
  484. package/dist/src/components/StructuredDiffList.js +8 -0
  485. package/dist/src/components/TagTabs.js +100 -0
  486. package/dist/src/components/TaskListV2.js +333 -0
  487. package/dist/src/components/TeammateViewHeader.js +87 -0
  488. package/dist/src/components/TeleportError.js +191 -0
  489. package/dist/src/components/TeleportProgress.js +130 -0
  490. package/dist/src/components/TeleportRepoMismatchDialog.js +98 -0
  491. package/dist/src/components/TeleportResumeWrapper.js +158 -0
  492. package/dist/src/components/TeleportStash.js +82 -0
  493. package/dist/src/components/TextInput.js +108 -0
  494. package/dist/src/components/ThemePicker.js +330 -0
  495. package/dist/src/components/ThinkingToggle.js +153 -0
  496. package/dist/src/components/TokenWarning.js +172 -0
  497. package/dist/src/components/ToolUseLoader.js +34 -0
  498. package/dist/src/components/TrustDialog/TrustDialog.js +113 -0
  499. package/dist/src/components/TrustDialog/utils.js +199 -0
  500. package/dist/src/components/ValidationErrorsList.js +146 -0
  501. package/dist/src/components/VimTextInput.js +136 -0
  502. package/dist/src/components/VirtualMessageList.js +892 -0
  503. package/dist/src/components/WorkflowMultiselectDialog.js +118 -0
  504. package/dist/src/components/WorktreeExitDialog.js +222 -0
  505. package/dist/src/components/agents/AgentDetail.js +226 -0
  506. package/dist/src/components/agents/AgentEditor.js +146 -0
  507. package/dist/src/components/agents/AgentNavigationFooter.js +21 -0
  508. package/dist/src/components/agents/AgentsList.js +436 -0
  509. package/dist/src/components/agents/AgentsMenu.js +848 -0
  510. package/dist/src/components/agents/ColorPicker.js +110 -0
  511. package/dist/src/components/agents/ModelSelector.js +62 -0
  512. package/dist/src/components/agents/SnapshotUpdateDialog.js +16 -0
  513. package/dist/src/components/agents/ToolSelector.js +557 -0
  514. package/dist/src/components/agents/agentFileUtils.js +187 -0
  515. package/dist/src/components/agents/generateAgent.js +161 -0
  516. package/dist/src/components/agents/new-agent-creation/CreateAgentWizard.js +88 -0
  517. package/dist/src/components/agents/new-agent-creation/wizard-steps/ColorStep.js +80 -0
  518. package/dist/src/components/agents/new-agent-creation/wizard-steps/ConfirmStep.js +386 -0
  519. package/dist/src/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.js +63 -0
  520. package/dist/src/components/agents/new-agent-creation/wizard-steps/DescriptionStep.js +126 -0
  521. package/dist/src/components/agents/new-agent-creation/wizard-steps/GenerateStep.js +118 -0
  522. package/dist/src/components/agents/new-agent-creation/wizard-steps/LocationStep.js +92 -0
  523. package/dist/src/components/agents/new-agent-creation/wizard-steps/MemoryStep.js +120 -0
  524. package/dist/src/components/agents/new-agent-creation/wizard-steps/MethodStep.js +79 -0
  525. package/dist/src/components/agents/new-agent-creation/wizard-steps/ModelStep.js +48 -0
  526. package/dist/src/components/agents/new-agent-creation/wizard-steps/PromptStep.js +131 -0
  527. package/dist/src/components/agents/new-agent-creation/wizard-steps/ToolsStep.js +51 -0
  528. package/dist/src/components/agents/new-agent-creation/wizard-steps/TypeStep.js +100 -0
  529. package/dist/src/components/agents/types.js +4 -0
  530. package/dist/src/components/agents/utils.js +14 -0
  531. package/dist/src/components/agents/validateAgent.js +79 -0
  532. package/dist/src/components/design-system/Byline.js +72 -0
  533. package/dist/src/components/design-system/Dialog.js +116 -0
  534. package/dist/src/components/design-system/Divider.js +109 -0
  535. package/dist/src/components/design-system/FuzzyPicker.js +187 -0
  536. package/dist/src/components/design-system/KeyboardShortcutHint.js +67 -0
  537. package/dist/src/components/design-system/ListItem.js +183 -0
  538. package/dist/src/components/design-system/LoadingState.js +68 -0
  539. package/dist/src/components/design-system/Pane.js +68 -0
  540. package/dist/src/components/design-system/ProgressBar.js +62 -0
  541. package/dist/src/components/design-system/Ratchet.js +71 -0
  542. package/dist/src/components/design-system/StatusIcon.js +69 -0
  543. package/dist/src/components/design-system/Tabs.js +269 -0
  544. package/dist/src/components/design-system/ThemeProvider.js +137 -0
  545. package/dist/src/components/design-system/ThemedBox.js +125 -0
  546. package/dist/src/components/design-system/ThemedText.js +60 -0
  547. package/dist/src/components/design-system/color.js +22 -0
  548. package/dist/src/components/diff/DiffDetailView.js +284 -0
  549. package/dist/src/components/diff/DiffDialog.js +387 -0
  550. package/dist/src/components/diff/DiffFileList.js +291 -0
  551. package/dist/src/components/grove/Grove.js +483 -0
  552. package/dist/src/components/hooks/HooksConfigMenu.js +570 -0
  553. package/dist/src/components/hooks/PromptDialog.js +81 -0
  554. package/dist/src/components/hooks/SelectEventMode.js +117 -0
  555. package/dist/src/components/hooks/SelectHookMode.js +93 -0
  556. package/dist/src/components/hooks/SelectMatcherMode.js +124 -0
  557. package/dist/src/components/hooks/ViewHookMode.js +197 -0
  558. package/dist/src/components/mcp/CapabilitiesSection.js +55 -0
  559. package/dist/src/components/mcp/ElicitationDialog.js +945 -0
  560. package/dist/src/components/mcp/MCPAgentServerMenu.js +95 -0
  561. package/dist/src/components/mcp/MCPListPanel.js +504 -0
  562. package/dist/src/components/mcp/MCPReconnect.js +168 -0
  563. package/dist/src/components/mcp/MCPRemoteServerMenu.js +460 -0
  564. package/dist/src/components/mcp/MCPSettings.js +414 -0
  565. package/dist/src/components/mcp/MCPStdioServerMenu.js +95 -0
  566. package/dist/src/components/mcp/MCPToolDetailView.js +219 -0
  567. package/dist/src/components/mcp/MCPToolListView.js +136 -0
  568. package/dist/src/components/mcp/McpParsingWarnings.js +211 -0
  569. package/dist/src/components/mcp/index.js +8 -0
  570. package/dist/src/components/mcp/types.js +3 -0
  571. package/dist/src/components/mcp/utils/reconnectHelpers.js +35 -0
  572. package/dist/src/components/memory/MemoryFileSelector.js +455 -0
  573. package/dist/src/components/memory/MemoryUpdateNotification.js +42 -0
  574. package/dist/src/components/messageActions.js +418 -0
  575. package/dist/src/components/messages/AdvisorMessage.js +151 -0
  576. package/dist/src/components/messages/AssistantRedactedThinkingMessage.js +27 -0
  577. package/dist/src/components/messages/AssistantTextMessage.js +274 -0
  578. package/dist/src/components/messages/AssistantThinkingMessage.js +69 -0
  579. package/dist/src/components/messages/AssistantToolUseMessage.js +323 -0
  580. package/dist/src/components/messages/AttachmentMessage.js +418 -0
  581. package/dist/src/components/messages/CollapsedReadSearchContent.js +362 -0
  582. package/dist/src/components/messages/CompactBoundaryMessage.js +18 -0
  583. package/dist/src/components/messages/GroupedToolUseContent.js +37 -0
  584. package/dist/src/components/messages/HighlightedThinkingText.js +164 -0
  585. package/dist/src/components/messages/HookProgressMessage.js +110 -0
  586. package/dist/src/components/messages/PlanApprovalMessage.js +212 -0
  587. package/dist/src/components/messages/RateLimitMessage.js +149 -0
  588. package/dist/src/components/messages/ShutdownMessage.js +123 -0
  589. package/dist/src/components/messages/SystemAPIErrorMessage.js +135 -0
  590. package/dist/src/components/messages/SystemTextMessage.js +843 -0
  591. package/dist/src/components/messages/TaskAssignmentMessage.js +71 -0
  592. package/dist/src/components/messages/UserAgentNotificationMessage.js +77 -0
  593. package/dist/src/components/messages/UserBashInputMessage.js +51 -0
  594. package/dist/src/components/messages/UserBashOutputMessage.js +54 -0
  595. package/dist/src/components/messages/UserChannelMessage.js +129 -0
  596. package/dist/src/components/messages/UserCommandMessage.js +106 -0
  597. package/dist/src/components/messages/UserImageMessage.js +53 -0
  598. package/dist/src/components/messages/UserLocalCommandOutputMessage.js +169 -0
  599. package/dist/src/components/messages/UserMemoryInputMessage.js +72 -0
  600. package/dist/src/components/messages/UserPlanMessage.js +37 -0
  601. package/dist/src/components/messages/UserPromptMessage.js +63 -0
  602. package/dist/src/components/messages/UserResourceUpdateMessage.js +101 -0
  603. package/dist/src/components/messages/UserTeammateMessage.js +156 -0
  604. package/dist/src/components/messages/UserTextMessage.js +271 -0
  605. package/dist/src/components/messages/UserToolResultMessage/RejectedPlanMessage.js +27 -0
  606. package/dist/src/components/messages/UserToolResultMessage/RejectedToolUseMessage.js +16 -0
  607. package/dist/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.js +16 -0
  608. package/dist/src/components/messages/UserToolResultMessage/UserToolErrorMessage.js +91 -0
  609. package/dist/src/components/messages/UserToolResultMessage/UserToolRejectMessage.js +73 -0
  610. package/dist/src/components/messages/UserToolResultMessage/UserToolResultMessage.js +83 -0
  611. package/dist/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +58 -0
  612. package/dist/src/components/messages/UserToolResultMessage/utils.js +43 -0
  613. package/dist/src/components/messages/nullRenderingAttachments.js +58 -0
  614. package/dist/src/components/messages/teamMemCollapsed.js +142 -0
  615. package/dist/src/components/messages/teamMemSaved.js +17 -0
  616. package/dist/src/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.js +654 -0
  617. package/dist/src/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.js +219 -0
  618. package/dist/src/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.js +227 -0
  619. package/dist/src/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.js +174 -0
  620. package/dist/src/components/permissions/AskUserQuestionPermissionRequest/QuestionView.js +444 -0
  621. package/dist/src/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.js +136 -0
  622. package/dist/src/components/permissions/AskUserQuestionPermissionRequest/use-multiple-choice-state.js +100 -0
  623. package/dist/src/components/permissions/BashPermissionRequest/BashPermissionRequest.js +404 -0
  624. package/dist/src/components/permissions/BashPermissionRequest/bashToolUseOptions.js +110 -0
  625. package/dist/src/components/permissions/ComputerUseApproval/ComputerUseApproval.js +448 -0
  626. package/dist/src/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.js +125 -0
  627. package/dist/src/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.js +649 -0
  628. package/dist/src/components/permissions/FallbackPermissionRequest.js +348 -0
  629. package/dist/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +184 -0
  630. package/dist/src/components/permissions/FilePermissionDialog/FilePermissionDialog.js +108 -0
  631. package/dist/src/components/permissions/FilePermissionDialog/ideDiffConfig.js +13 -0
  632. package/dist/src/components/permissions/FilePermissionDialog/permissionOptions.js +136 -0
  633. package/dist/src/components/permissions/FilePermissionDialog/useFilePermissionDialog.js +131 -0
  634. package/dist/src/components/permissions/FilePermissionDialog/usePermissionHandler.js +86 -0
  635. package/dist/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +163 -0
  636. package/dist/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +78 -0
  637. package/dist/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +112 -0
  638. package/dist/src/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.js +163 -0
  639. package/dist/src/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.js +217 -0
  640. package/dist/src/components/permissions/PermissionDecisionDebugInfo.js +466 -0
  641. package/dist/src/components/permissions/PermissionDialog.js +54 -0
  642. package/dist/src/components/permissions/PermissionExplanation.js +269 -0
  643. package/dist/src/components/permissions/PermissionPrompt.js +316 -0
  644. package/dist/src/components/permissions/PermissionRequest.js +160 -0
  645. package/dist/src/components/permissions/PermissionRequestTitle.js +57 -0
  646. package/dist/src/components/permissions/PermissionRuleExplanation.js +116 -0
  647. package/dist/src/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.js +178 -0
  648. package/dist/src/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.js +73 -0
  649. package/dist/src/components/permissions/SandboxPermissionRequest.js +161 -0
  650. package/dist/src/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.js +228 -0
  651. package/dist/src/components/permissions/SkillPermissionRequest/SkillPermissionRequest.js +384 -0
  652. package/dist/src/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.js +258 -0
  653. package/dist/src/components/permissions/WorkerBadge.js +43 -0
  654. package/dist/src/components/permissions/WorkerPendingPermission.js +106 -0
  655. package/dist/src/components/permissions/hooks.js +163 -0
  656. package/dist/src/components/permissions/rules/AddPermissionRules.js +172 -0
  657. package/dist/src/components/permissions/rules/AddWorkspaceDirectory.js +334 -0
  658. package/dist/src/components/permissions/rules/PermissionRuleDescription.js +77 -0
  659. package/dist/src/components/permissions/rules/PermissionRuleInput.js +135 -0
  660. package/dist/src/components/permissions/rules/PermissionRuleList.js +1189 -0
  661. package/dist/src/components/permissions/rules/RecentDenialsTab.js +204 -0
  662. package/dist/src/components/permissions/rules/RemoveWorkspaceDirectory.js +102 -0
  663. package/dist/src/components/permissions/rules/WorkspaceTab.js +132 -0
  664. package/dist/src/components/permissions/shellPermissionHelpers.js +111 -0
  665. package/dist/src/components/permissions/useShellPermissionFeedback.js +108 -0
  666. package/dist/src/components/permissions/utils.js +14 -0
  667. package/dist/src/components/sandbox/SandboxConfigTab.js +47 -0
  668. package/dist/src/components/sandbox/SandboxDependenciesTab.js +122 -0
  669. package/dist/src/components/sandbox/SandboxDoctorSection.js +46 -0
  670. package/dist/src/components/sandbox/SandboxOverridesTab.js +192 -0
  671. package/dist/src/components/sandbox/SandboxSettings.js +296 -0
  672. package/dist/src/components/shell/ExpandShellOutputContext.js +33 -0
  673. package/dist/src/components/shell/OutputLine.js +110 -0
  674. package/dist/src/components/shell/ShellProgressMessage.js +143 -0
  675. package/dist/src/components/shell/ShellTimeDisplay.js +71 -0
  676. package/dist/src/components/skills/SkillsMenu.js +238 -0
  677. package/dist/src/components/tasks/AsyncAgentDetailDialog.js +234 -0
  678. package/dist/src/components/tasks/BackgroundTask.js +363 -0
  679. package/dist/src/components/tasks/BackgroundTaskStatus.js +419 -0
  680. package/dist/src/components/tasks/BackgroundTasksDialog.js +496 -0
  681. package/dist/src/components/tasks/DreamDetailDialog.js +250 -0
  682. package/dist/src/components/tasks/InProcessTeammateDetailDialog.js +274 -0
  683. package/dist/src/components/tasks/RemoteSessionDetailDialog.js +868 -0
  684. package/dist/src/components/tasks/RemoteSessionProgress.js +249 -0
  685. package/dist/src/components/tasks/ShellDetailDialog.js +403 -0
  686. package/dist/src/components/tasks/ShellProgress.js +76 -0
  687. package/dist/src/components/tasks/renderToolActivity.js +28 -0
  688. package/dist/src/components/tasks/taskStatusUtils.js +94 -0
  689. package/dist/src/components/teams/TeamStatus.js +76 -0
  690. package/dist/src/components/teams/TeamsDialog.js +672 -0
  691. package/dist/src/components/ui/ContextCard.js +5 -0
  692. package/dist/src/components/ui/OrderedList.js +66 -0
  693. package/dist/src/components/ui/OrderedListItem.js +41 -0
  694. package/dist/src/components/ui/TreeSelect.js +300 -0
  695. package/dist/src/components/wizard/WizardDialogLayout.js +47 -0
  696. package/dist/src/components/wizard/WizardNavigationFooter.js +10 -0
  697. package/dist/src/components/wizard/WizardProvider.js +217 -0
  698. package/dist/src/components/wizard/index.js +4 -0
  699. package/dist/src/components/wizard/useWizard.js +9 -0
  700. package/dist/src/constants/apiLimits.js +81 -0
  701. package/dist/src/constants/betas.js +45 -0
  702. package/dist/src/constants/common.js +29 -0
  703. package/dist/src/constants/cyberRiskInstruction.js +24 -0
  704. package/dist/src/constants/errorIds.js +14 -0
  705. package/dist/src/constants/figures.js +38 -0
  706. package/dist/src/constants/files.js +150 -0
  707. package/dist/src/constants/github-app.js +139 -0
  708. package/dist/src/constants/keys.js +10 -0
  709. package/dist/src/constants/messages.js +1 -0
  710. package/dist/src/constants/oauth.js +221 -0
  711. package/dist/src/constants/outputStyles.js +162 -0
  712. package/dist/src/constants/product.js +56 -0
  713. package/dist/src/constants/prompts.js +752 -0
  714. package/dist/src/constants/spinnerVerbs.js +202 -0
  715. package/dist/src/constants/system.js +77 -0
  716. package/dist/src/constants/systemPromptSections.js +39 -0
  717. package/dist/src/constants/toolLimits.js +50 -0
  718. package/dist/src/constants/tools.js +103 -0
  719. package/dist/src/constants/turnCompletionVerbs.js +12 -0
  720. package/dist/src/constants/xml.js +73 -0
  721. package/dist/src/context/QueuedMessageContext.js +51 -0
  722. package/dist/src/context/fpsMetrics.js +22 -0
  723. package/dist/src/context/mailbox.js +35 -0
  724. package/dist/src/context/modalContext.js +34 -0
  725. package/dist/src/context/notifications.js +199 -0
  726. package/dist/src/context/overlayContext.js +149 -0
  727. package/dist/src/context/promptOverlayContext.js +118 -0
  728. package/dist/src/context/stats.js +207 -0
  729. package/dist/src/context/voice.js +74 -0
  730. package/dist/src/context.js +146 -0
  731. package/dist/src/coordinator/coordinatorMode.js +349 -0
  732. package/dist/src/cost-tracker.js +208 -0
  733. package/dist/src/costHook.js +17 -0
  734. package/dist/src/daemon/main.js +16 -0
  735. package/dist/src/daemon/workerRegistry.js +16 -0
  736. package/dist/src/dialogLaunchers.js +68 -0
  737. package/dist/src/entrypoints/agentSdkTypes.js +202 -0
  738. package/dist/src/entrypoints/cli.js +252 -0
  739. package/dist/src/entrypoints/init.js +265 -0
  740. package/dist/src/entrypoints/mcp.js +142 -0
  741. package/dist/src/entrypoints/sandboxTypes.js +112 -0
  742. package/dist/src/entrypoints/sdk/controlSchemas.js +452 -0
  743. package/dist/src/entrypoints/sdk/controlTypes.js +1 -0
  744. package/dist/src/entrypoints/sdk/coreSchemas.js +1331 -0
  745. package/dist/src/entrypoints/sdk/coreTypes.generated.js +1 -0
  746. package/dist/src/entrypoints/sdk/coreTypes.js +49 -0
  747. package/dist/src/entrypoints/sdk/runtimeTypes.js +1 -0
  748. package/dist/src/entrypoints/sdk/toolTypes.js +1 -0
  749. package/dist/src/environment-runner/main.js +16 -0
  750. package/dist/src/history.js +386 -0
  751. package/dist/src/hooks/fileSuggestions.js +635 -0
  752. package/dist/src/hooks/notifs/useAutoModeUnavailableNotification.js +47 -0
  753. package/dist/src/hooks/notifs/useCanSwitchToExistingSubscription.js +57 -0
  754. package/dist/src/hooks/notifs/useDeprecationWarningNotification.js +43 -0
  755. package/dist/src/hooks/notifs/useFastModeNotification.js +164 -0
  756. package/dist/src/hooks/notifs/useIDEStatusIndicator.js +174 -0
  757. package/dist/src/hooks/notifs/useInstallMessages.js +27 -0
  758. package/dist/src/hooks/notifs/useLspInitializationNotification.js +144 -0
  759. package/dist/src/hooks/notifs/useMcpConnectivityStatus.js +80 -0
  760. package/dist/src/hooks/notifs/useModelMigrationNotifications.js +53 -0
  761. package/dist/src/hooks/notifs/useNpmDeprecationNotification.js +24 -0
  762. package/dist/src/hooks/notifs/usePluginAutoupdateNotification.js +82 -0
  763. package/dist/src/hooks/notifs/usePluginInstallationStatus.js +127 -0
  764. package/dist/src/hooks/notifs/useRateLimitWarningNotification.js +118 -0
  765. package/dist/src/hooks/notifs/useSettingsErrors.js +64 -0
  766. package/dist/src/hooks/notifs/useStartupNotification.js +33 -0
  767. package/dist/src/hooks/notifs/useTeammateShutdownNotification.js +64 -0
  768. package/dist/src/hooks/renderPlaceholder.js +26 -0
  769. package/dist/src/hooks/toolPermission/PermissionContext.js +211 -0
  770. package/dist/src/hooks/toolPermission/handlers/coordinatorHandler.js +44 -0
  771. package/dist/src/hooks/toolPermission/handlers/interactiveHandler.js +397 -0
  772. package/dist/src/hooks/toolPermission/handlers/swarmWorkerHandler.js +108 -0
  773. package/dist/src/hooks/toolPermission/permissionLogging.js +145 -0
  774. package/dist/src/hooks/unifiedSuggestions.js +130 -0
  775. package/dist/src/hooks/useAfterFirstRender.js +12 -0
  776. package/dist/src/hooks/useApiKeyVerification.js +63 -0
  777. package/dist/src/hooks/useArrowKeyHistory.js +203 -0
  778. package/dist/src/hooks/useAssistantHistory.js +194 -0
  779. package/dist/src/hooks/useAwaySummary.js +105 -0
  780. package/dist/src/hooks/useBackgroundTaskNavigation.js +204 -0
  781. package/dist/src/hooks/useBlink.js +28 -0
  782. package/dist/src/hooks/useCanUseTool.js +192 -0
  783. package/dist/src/hooks/useCancelRequest.js +195 -0
  784. package/dist/src/hooks/useChromeExtensionNotification.js +49 -0
  785. package/dist/src/hooks/useClaudeCodeHintRecommendation.js +117 -0
  786. package/dist/src/hooks/useClipboardImageHint.js +59 -0
  787. package/dist/src/hooks/useCommandKeybindings.js +87 -0
  788. package/dist/src/hooks/useCommandQueue.js +10 -0
  789. package/dist/src/hooks/useCopyOnSelect.js +88 -0
  790. package/dist/src/hooks/useDeferredHookMessages.js +43 -0
  791. package/dist/src/hooks/useDiffData.js +69 -0
  792. package/dist/src/hooks/useDiffInIDE.js +252 -0
  793. package/dist/src/hooks/useDirectConnect.js +150 -0
  794. package/dist/src/hooks/useDoublePress.js +44 -0
  795. package/dist/src/hooks/useDynamicConfig.js +17 -0
  796. package/dist/src/hooks/useElapsedTime.js +25 -0
  797. package/dist/src/hooks/useExitOnCtrlCD.js +57 -0
  798. package/dist/src/hooks/useExitOnCtrlCDWithKeybindings.js +17 -0
  799. package/dist/src/hooks/useFileHistorySnapshotInit.js +14 -0
  800. package/dist/src/hooks/useGlobalKeybindings.js +215 -0
  801. package/dist/src/hooks/useHistorySearch.js +241 -0
  802. package/dist/src/hooks/useIDEIntegration.js +56 -0
  803. package/dist/src/hooks/useIdeAtMentioned.js +51 -0
  804. package/dist/src/hooks/useIdeConnectionStatus.js +21 -0
  805. package/dist/src/hooks/useIdeLogging.js +29 -0
  806. package/dist/src/hooks/useIdeSelection.js +106 -0
  807. package/dist/src/hooks/useInboxPoller.js +709 -0
  808. package/dist/src/hooks/useInputBuffer.js +73 -0
  809. package/dist/src/hooks/useIssueFlagBanner.js +115 -0
  810. package/dist/src/hooks/useLogMessages.js +98 -0
  811. package/dist/src/hooks/useLspPluginRecommendation.js +176 -0
  812. package/dist/src/hooks/useMailboxBridge.js +15 -0
  813. package/dist/src/hooks/useMainLoopModel.js +25 -0
  814. package/dist/src/hooks/useManagePlugins.js +261 -0
  815. package/dist/src/hooks/useMemoryUsage.js +28 -0
  816. package/dist/src/hooks/useMergedClients.js +11 -0
  817. package/dist/src/hooks/useMergedCommands.js +10 -0
  818. package/dist/src/hooks/useMergedTools.js +32 -0
  819. package/dist/src/hooks/useMinDisplayTime.js +26 -0
  820. package/dist/src/hooks/useNotifyAfterTimeout.js +51 -0
  821. package/dist/src/hooks/useOfficialMarketplaceNotification.js +46 -0
  822. package/dist/src/hooks/usePasteHandler.js +188 -0
  823. package/dist/src/hooks/usePluginRecommendationBase.js +101 -0
  824. package/dist/src/hooks/usePrStatus.js +91 -0
  825. package/dist/src/hooks/usePromptSuggestion.js +128 -0
  826. package/dist/src/hooks/usePromptsFromClaudeInChrome.js +66 -0
  827. package/dist/src/hooks/useQueueProcessor.js +46 -0
  828. package/dist/src/hooks/useRemoteSession.js +431 -0
  829. package/dist/src/hooks/useReplBridge.js +717 -0
  830. package/dist/src/hooks/useSSHSession.js +167 -0
  831. package/dist/src/hooks/useScheduledTasks.js +104 -0
  832. package/dist/src/hooks/useSearchInput.js +302 -0
  833. package/dist/src/hooks/useSessionBackgrounding.js +132 -0
  834. package/dist/src/hooks/useSettings.js +10 -0
  835. package/dist/src/hooks/useSettingsChange.js +13 -0
  836. package/dist/src/hooks/useSkillImprovementSurvey.js +69 -0
  837. package/dist/src/hooks/useSkillsChange.js +51 -0
  838. package/dist/src/hooks/useSwarmInitialization.js +67 -0
  839. package/dist/src/hooks/useSwarmPermissionPoller.js +215 -0
  840. package/dist/src/hooks/useTaskListWatcher.js +157 -0
  841. package/dist/src/hooks/useTasksV2.js +220 -0
  842. package/dist/src/hooks/useTeammateViewAutoExit.js +55 -0
  843. package/dist/src/hooks/useTelegramMirror.js +47 -0
  844. package/dist/src/hooks/useTeleportResume.js +81 -0
  845. package/dist/src/hooks/useTerminalSize.js +9 -0
  846. package/dist/src/hooks/useTextInput.js +397 -0
  847. package/dist/src/hooks/useTimeout.js +10 -0
  848. package/dist/src/hooks/useTurnDiffs.js +160 -0
  849. package/dist/src/hooks/useTypeahead.js +1617 -0
  850. package/dist/src/hooks/useUpdateNotification.js +22 -0
  851. package/dist/src/hooks/useVimInput.js +232 -0
  852. package/dist/src/hooks/useVirtualScroll.js +627 -0
  853. package/dist/src/hooks/useVoice.js +954 -0
  854. package/dist/src/hooks/useVoiceEnabled.js +21 -0
  855. package/dist/src/hooks/useVoiceIntegration.js +631 -0
  856. package/dist/src/hooks/useWhatsAppMirror.js +46 -0
  857. package/dist/src/index.js +18 -0
  858. package/dist/src/ink/Ansi.js +269 -0
  859. package/dist/src/ink/bidi.js +117 -0
  860. package/dist/src/ink/clearTerminal.js +58 -0
  861. package/dist/src/ink/colorize.js +198 -0
  862. package/dist/src/ink/components/AlternateScreen.js +74 -0
  863. package/dist/src/ink/components/App.js +558 -0
  864. package/dist/src/ink/components/AppContext.js +11 -0
  865. package/dist/src/ink/components/Box.js +153 -0
  866. package/dist/src/ink/components/Button.js +166 -0
  867. package/dist/src/ink/components/ClockContext.js +108 -0
  868. package/dist/src/ink/components/CursorDeclarationContext.js +3 -0
  869. package/dist/src/ink/components/ErrorOverview.js +49 -0
  870. package/dist/src/ink/components/Link.js +33 -0
  871. package/dist/src/ink/components/Newline.js +29 -0
  872. package/dist/src/ink/components/NoSelect.js +56 -0
  873. package/dist/src/ink/components/RawAnsi.js +45 -0
  874. package/dist/src/ink/components/ScrollBox.js +170 -0
  875. package/dist/src/ink/components/Spacer.js +19 -0
  876. package/dist/src/ink/components/StdinContext.js +16 -0
  877. package/dist/src/ink/components/TerminalFocusContext.js +45 -0
  878. package/dist/src/ink/components/TerminalSizeContext.js +3 -0
  879. package/dist/src/ink/components/Text.js +194 -0
  880. package/dist/src/ink/constants.js +2 -0
  881. package/dist/src/ink/devtools.js +16 -0
  882. package/dist/src/ink/dom.js +298 -0
  883. package/dist/src/ink/events/click-event.js +36 -0
  884. package/dist/src/ink/events/dispatcher.js +172 -0
  885. package/dist/src/ink/events/emitter.js +31 -0
  886. package/dist/src/ink/events/event-handlers.js +30 -0
  887. package/dist/src/ink/events/event.js +9 -0
  888. package/dist/src/ink/events/focus-event.js +16 -0
  889. package/dist/src/ink/events/input-event.js +161 -0
  890. package/dist/src/ink/events/keyboard-event.js +45 -0
  891. package/dist/src/ink/events/terminal-event.js +78 -0
  892. package/dist/src/ink/events/terminal-focus-event.js +15 -0
  893. package/dist/src/ink/focus.js +158 -0
  894. package/dist/src/ink/frame.js +30 -0
  895. package/dist/src/ink/get-max-width.js +23 -0
  896. package/dist/src/ink/hit-test.js +113 -0
  897. package/dist/src/ink/hooks/use-animation-frame.js +48 -0
  898. package/dist/src/ink/hooks/use-app.js +7 -0
  899. package/dist/src/ink/hooks/use-declared-cursor.js +60 -0
  900. package/dist/src/ink/hooks/use-input.js +70 -0
  901. package/dist/src/ink/hooks/use-interval.js +54 -0
  902. package/dist/src/ink/hooks/use-search-highlight.js +32 -0
  903. package/dist/src/ink/hooks/use-selection.js +60 -0
  904. package/dist/src/ink/hooks/use-stdin.js +7 -0
  905. package/dist/src/ink/hooks/use-tab-status.js +57 -0
  906. package/dist/src/ink/hooks/use-terminal-focus.js +15 -0
  907. package/dist/src/ink/hooks/use-terminal-title.js +29 -0
  908. package/dist/src/ink/hooks/use-terminal-viewport.js +77 -0
  909. package/dist/src/ink/ink.js +1644 -0
  910. package/dist/src/ink/instances.js +7 -0
  911. package/dist/src/ink/layout/engine.js +4 -0
  912. package/dist/src/ink/layout/geometry.js +61 -0
  913. package/dist/src/ink/layout/node.js +62 -0
  914. package/dist/src/ink/layout/yoga.js +237 -0
  915. package/dist/src/ink/line-width-cache.js +19 -0
  916. package/dist/src/ink/log-update.js +583 -0
  917. package/dist/src/ink/measure-element.js +8 -0
  918. package/dist/src/ink/measure-text.js +35 -0
  919. package/dist/src/ink/node-cache.js +30 -0
  920. package/dist/src/ink/optimizer.js +81 -0
  921. package/dist/src/ink/output.js +556 -0
  922. package/dist/src/ink/parse-keypress.js +695 -0
  923. package/dist/src/ink/reconciler.js +384 -0
  924. package/dist/src/ink/render-border.js +134 -0
  925. package/dist/src/ink/render-node-to-output.js +1216 -0
  926. package/dist/src/ink/render-to-screen.js +171 -0
  927. package/dist/src/ink/renderer.js +129 -0
  928. package/dist/src/ink/root.js +80 -0
  929. package/dist/src/ink/screen.js +1132 -0
  930. package/dist/src/ink/searchHighlight.js +78 -0
  931. package/dist/src/ink/selection.js +792 -0
  932. package/dist/src/ink/squash-text-nodes.js +56 -0
  933. package/dist/src/ink/stringWidth.js +200 -0
  934. package/dist/src/ink/styles.js +299 -0
  935. package/dist/src/ink/supports-hyperlinks.js +40 -0
  936. package/dist/src/ink/tabstops.js +39 -0
  937. package/dist/src/ink/terminal-focus-state.js +35 -0
  938. package/dist/src/ink/terminal-querier.js +173 -0
  939. package/dist/src/ink/terminal.js +208 -0
  940. package/dist/src/ink/termio/ansi.js +70 -0
  941. package/dist/src/ink/termio/csi.js +260 -0
  942. package/dist/src/ink/termio/dec.js +53 -0
  943. package/dist/src/ink/termio/esc.js +55 -0
  944. package/dist/src/ink/termio/osc.js +432 -0
  945. package/dist/src/ink/termio/parser.js +356 -0
  946. package/dist/src/ink/termio/sgr.js +292 -0
  947. package/dist/src/ink/termio/tokenize.js +264 -0
  948. package/dist/src/ink/termio/types.js +55 -0
  949. package/dist/src/ink/termio.js +24 -0
  950. package/dist/src/ink/useTerminalNotification.js +57 -0
  951. package/dist/src/ink/warn.js +10 -0
  952. package/dist/src/ink/widest-line.js +14 -0
  953. package/dist/src/ink/wrap-text.js +54 -0
  954. package/dist/src/ink/wrapAnsi.js +6 -0
  955. package/dist/src/ink.js +50 -0
  956. package/dist/src/interactiveHelpers.js +317 -0
  957. package/dist/src/keybindings/KeybindingContext.js +184 -0
  958. package/dist/src/keybindings/KeybindingProviderSetup.js +259 -0
  959. package/dist/src/keybindings/defaultBindings.js +333 -0
  960. package/dist/src/keybindings/loadUserBindings.js +393 -0
  961. package/dist/src/keybindings/match.js +111 -0
  962. package/dist/src/keybindings/parser.js +184 -0
  963. package/dist/src/keybindings/reservedShortcuts.js +109 -0
  964. package/dist/src/keybindings/resolver.js +182 -0
  965. package/dist/src/keybindings/schema.js +205 -0
  966. package/dist/src/keybindings/shortcutFormat.js +48 -0
  967. package/dist/src/keybindings/template.js +40 -0
  968. package/dist/src/keybindings/useKeybinding.js +161 -0
  969. package/dist/src/keybindings/useShortcutDisplay.js +43 -0
  970. package/dist/src/keybindings/validate.js +395 -0
  971. package/dist/src/main.js +4080 -0
  972. package/dist/src/memdir/findRelevantMemories.js +101 -0
  973. package/dist/src/memdir/memdir.js +408 -0
  974. package/dist/src/memdir/memoryAge.js +52 -0
  975. package/dist/src/memdir/memoryScan.js +65 -0
  976. package/dist/src/memdir/memoryTypes.js +260 -0
  977. package/dist/src/memdir/paths.js +236 -0
  978. package/dist/src/memdir/teamMemPaths.js +261 -0
  979. package/dist/src/memdir/teamMemPrompts.js +82 -0
  980. package/dist/src/migrations/migrateAutoUpdatesToSettings.js +47 -0
  981. package/dist/src/migrations/migrateBypassPermissionsAcceptedToSettings.js +32 -0
  982. package/dist/src/migrations/migrateEnableAllProjectMcpServersToSettings.js +83 -0
  983. package/dist/src/migrations/migrateFennecToOpus.js +39 -0
  984. package/dist/src/migrations/migrateLegacyOpusToCurrent.js +44 -0
  985. package/dist/src/migrations/migrateOpusToOpus1m.js +31 -0
  986. package/dist/src/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.js +23 -0
  987. package/dist/src/migrations/migrateSonnet1mToSonnet45.js +38 -0
  988. package/dist/src/migrations/migrateSonnet45ToSonnet46.js +48 -0
  989. package/dist/src/migrations/resetAutoModeOptInForDefaultOffer.js +47 -0
  990. package/dist/src/migrations/resetProToOpusDefault.js +46 -0
  991. package/dist/src/mirrors/shared.js +186 -0
  992. package/dist/src/moreright/useMoreRight.js +13 -0
  993. package/dist/src/native-ts/color-diff/index.js +821 -0
  994. package/dist/src/native-ts/file-index/index.js +328 -0
  995. package/dist/src/native-ts/yoga-layout/enums.js +101 -0
  996. package/dist/src/native-ts/yoga-layout/index.js +2113 -0
  997. package/dist/src/outputStyles/loadOutputStylesDir.js +73 -0
  998. package/dist/src/plugins/builtinPlugins.js +132 -0
  999. package/dist/src/plugins/bundled/index.js +22 -0
  1000. package/dist/src/projectOnboardingState.js +61 -0
  1001. package/dist/src/query/config.js +17 -0
  1002. package/dist/src/query/deps.js +12 -0
  1003. package/dist/src/query/stopHooks.js +334 -0
  1004. package/dist/src/query/tokenBudget.js +49 -0
  1005. package/dist/src/query.js +1330 -0
  1006. package/dist/src/recovery/bunBundleShim.js +11 -0
  1007. package/dist/src/remote/RemoteSessionManager.js +195 -0
  1008. package/dist/src/remote/SessionsWebSocket.js +305 -0
  1009. package/dist/src/remote/remotePermissionBridge.js +70 -0
  1010. package/dist/src/remote/sdkMessageAdapter.js +227 -0
  1011. package/dist/src/replLauncher.js +6 -0
  1012. package/dist/src/schemas/hooks.js +174 -0
  1013. package/dist/src/screens/Doctor.js +581 -0
  1014. package/dist/src/screens/REPL.js +4434 -0
  1015. package/dist/src/screens/ResumeConversation.js +341 -0
  1016. package/dist/src/self-hosted-runner/main.js +16 -0
  1017. package/dist/src/server/backends/dangerousBackend.js +16 -0
  1018. package/dist/src/server/connectHeadless.js +16 -0
  1019. package/dist/src/server/createDirectConnectSession.js +62 -0
  1020. package/dist/src/server/directConnectManager.js +153 -0
  1021. package/dist/src/server/lockfile.js +16 -0
  1022. package/dist/src/server/parseConnectUrl.js +16 -0
  1023. package/dist/src/server/server.js +16 -0
  1024. package/dist/src/server/serverBanner.js +16 -0
  1025. package/dist/src/server/serverLog.js +16 -0
  1026. package/dist/src/server/sessionManager.js +16 -0
  1027. package/dist/src/server/types.js +7 -0
  1028. package/dist/src/services/AgentSummary/agentSummary.js +147 -0
  1029. package/dist/src/services/MagicDocs/magicDocs.js +193 -0
  1030. package/dist/src/services/MagicDocs/prompts.js +110 -0
  1031. package/dist/src/services/PromptSuggestion/promptSuggestion.js +402 -0
  1032. package/dist/src/services/PromptSuggestion/speculation.js +643 -0
  1033. package/dist/src/services/SessionMemory/prompts.js +254 -0
  1034. package/dist/src/services/SessionMemory/sessionMemory.js +358 -0
  1035. package/dist/src/services/SessionMemory/sessionMemoryUtils.js +157 -0
  1036. package/dist/src/services/analytics/config.js +33 -0
  1037. package/dist/src/services/analytics/datadog.js +259 -0
  1038. package/dist/src/services/analytics/firstPartyEventLogger.js +342 -0
  1039. package/dist/src/services/analytics/firstPartyEventLoggingExporter.js +594 -0
  1040. package/dist/src/services/analytics/growthbook.js +952 -0
  1041. package/dist/src/services/analytics/index.js +114 -0
  1042. package/dist/src/services/analytics/metadata.js +698 -0
  1043. package/dist/src/services/analytics/sink.js +95 -0
  1044. package/dist/src/services/analytics/sinkKillswitch.js +19 -0
  1045. package/dist/src/services/api/adminRequests.js +57 -0
  1046. package/dist/src/services/api/bootstrap.js +149 -0
  1047. package/dist/src/services/api/claude.js +2461 -0
  1048. package/dist/src/services/api/client.js +325 -0
  1049. package/dist/src/services/api/dumpPrompts.js +174 -0
  1050. package/dist/src/services/api/emptyUsage.js +20 -0
  1051. package/dist/src/services/api/errorUtils.js +203 -0
  1052. package/dist/src/services/api/errors.js +934 -0
  1053. package/dist/src/services/api/filesApi.js +523 -0
  1054. package/dist/src/services/api/firstTokenDate.js +49 -0
  1055. package/dist/src/services/api/grove.js +272 -0
  1056. package/dist/src/services/api/index.js +23 -0
  1057. package/dist/src/services/api/logging.js +484 -0
  1058. package/dist/src/services/api/metricsOptOut.js +129 -0
  1059. package/dist/src/services/api/openai.js +1187 -0
  1060. package/dist/src/services/api/openrouter.js +30 -0
  1061. package/dist/src/services/api/overageCreditGrant.js +123 -0
  1062. package/dist/src/services/api/promptCacheBreakDetection.js +510 -0
  1063. package/dist/src/services/api/referral.js +219 -0
  1064. package/dist/src/services/api/sessionIngress.js +358 -0
  1065. package/dist/src/services/api/ultrareviewQuota.js +29 -0
  1066. package/dist/src/services/api/usage.js +31 -0
  1067. package/dist/src/services/api/withRetry.js +599 -0
  1068. package/dist/src/services/autoDream/autoDream.js +244 -0
  1069. package/dist/src/services/autoDream/config.js +17 -0
  1070. package/dist/src/services/autoDream/consolidationLock.js +122 -0
  1071. package/dist/src/services/autoDream/consolidationPrompt.js +56 -0
  1072. package/dist/src/services/awaySummary.js +61 -0
  1073. package/dist/src/services/claudeAiLimits.js +331 -0
  1074. package/dist/src/services/claudeAiLimitsHook.js +15 -0
  1075. package/dist/src/services/compact/apiMicrocompact.js +97 -0
  1076. package/dist/src/services/compact/autoCompact.js +236 -0
  1077. package/dist/src/services/compact/cachedMicrocompact.js +16 -0
  1078. package/dist/src/services/compact/compact.js +1258 -0
  1079. package/dist/src/services/compact/compactWarningHook.js +12 -0
  1080. package/dist/src/services/compact/compactWarningState.js +15 -0
  1081. package/dist/src/services/compact/grouping.js +58 -0
  1082. package/dist/src/services/compact/microCompact.js +414 -0
  1083. package/dist/src/services/compact/postCompactCleanup.js +72 -0
  1084. package/dist/src/services/compact/prompt.js +327 -0
  1085. package/dist/src/services/compact/sessionMemoryCompact.js +467 -0
  1086. package/dist/src/services/compact/timeBasedMCConfig.js +11 -0
  1087. package/dist/src/services/diagnosticTracking.js +282 -0
  1088. package/dist/src/services/extractMemories/extractMemories.js +444 -0
  1089. package/dist/src/services/extractMemories/prompts.js +129 -0
  1090. package/dist/src/services/internalLogging.js +68 -0
  1091. package/dist/src/services/limits/adapters/claude.js +219 -0
  1092. package/dist/src/services/limits/adapters/minimax.js +177 -0
  1093. package/dist/src/services/limits/adapters/ollama.js +189 -0
  1094. package/dist/src/services/limits/adapters/openai.js +167 -0
  1095. package/dist/src/services/limits/adapters/openrouter.js +166 -0
  1096. package/dist/src/services/limits/adapters/zai.js +154 -0
  1097. package/dist/src/services/limits/index.js +2 -0
  1098. package/dist/src/services/limits/registry.js +179 -0
  1099. package/dist/src/services/limits/sessionCounter.js +168 -0
  1100. package/dist/src/services/limits/types.js +1 -0
  1101. package/dist/src/services/lsp/LSPClient.js +306 -0
  1102. package/dist/src/services/lsp/LSPDiagnosticRegistry.js +277 -0
  1103. package/dist/src/services/lsp/LSPServerInstance.js +390 -0
  1104. package/dist/src/services/lsp/LSPServerManager.js +305 -0
  1105. package/dist/src/services/lsp/config.js +57 -0
  1106. package/dist/src/services/lsp/manager.js +246 -0
  1107. package/dist/src/services/lsp/passiveFeedback.js +226 -0
  1108. package/dist/src/services/mcp/InProcessTransport.js +54 -0
  1109. package/dist/src/services/mcp/MCPConnectionManager.js +50 -0
  1110. package/dist/src/services/mcp/SdkControlTransport.js +115 -0
  1111. package/dist/src/services/mcp/auth.js +1882 -0
  1112. package/dist/src/services/mcp/channelAllowlist.js +57 -0
  1113. package/dist/src/services/mcp/channelNotification.js +236 -0
  1114. package/dist/src/services/mcp/channelPermissions.js +192 -0
  1115. package/dist/src/services/mcp/claudeai.js +123 -0
  1116. package/dist/src/services/mcp/client.js +2480 -0
  1117. package/dist/src/services/mcp/config.js +1277 -0
  1118. package/dist/src/services/mcp/elicitationHandler.js +192 -0
  1119. package/dist/src/services/mcp/envExpansion.js +30 -0
  1120. package/dist/src/services/mcp/headersHelper.js +94 -0
  1121. package/dist/src/services/mcp/mcpStringUtils.js +85 -0
  1122. package/dist/src/services/mcp/normalization.js +21 -0
  1123. package/dist/src/services/mcp/oauthPort.js +69 -0
  1124. package/dist/src/services/mcp/officialRegistry.js +58 -0
  1125. package/dist/src/services/mcp/types.js +94 -0
  1126. package/dist/src/services/mcp/useManageMCPConnections.js +820 -0
  1127. package/dist/src/services/mcp/utils.js +433 -0
  1128. package/dist/src/services/mcp/vscodeSdkMcp.js +69 -0
  1129. package/dist/src/services/mcp/xaa.js +342 -0
  1130. package/dist/src/services/mcp/xaaIdpLogin.js +377 -0
  1131. package/dist/src/services/mcpServerApproval.js +29 -0
  1132. package/dist/src/services/mockRateLimits.js +666 -0
  1133. package/dist/src/services/notifier.js +114 -0
  1134. package/dist/src/services/oauth/auth-code-listener.js +236 -0
  1135. package/dist/src/services/oauth/client.js +545 -0
  1136. package/dist/src/services/oauth/crypto.js +19 -0
  1137. package/dist/src/services/oauth/getOauthProfile.js +48 -0
  1138. package/dist/src/services/oauth/index.js +152 -0
  1139. package/dist/src/services/oauth/types.js +1 -0
  1140. package/dist/src/services/orchestration/execution/AgentTaskExecutor.js +315 -0
  1141. package/dist/src/services/orchestration/execution/OrchestrationExecutionRuntime.js +1147 -0
  1142. package/dist/src/services/orchestration/execution/index.js +2 -0
  1143. package/dist/src/services/orchestration/execution/types.js +1 -0
  1144. package/dist/src/services/orchestration/global/GlobalOrchestratorRuntime.js +140 -0
  1145. package/dist/src/services/orchestration/global/index.js +3 -0
  1146. package/dist/src/services/orchestration/global/reporting.js +541 -0
  1147. package/dist/src/services/orchestration/global/types.js +1 -0
  1148. package/dist/src/services/orchestration/index.js +4 -0
  1149. package/dist/src/services/orchestration/policy/index.js +2 -0
  1150. package/dist/src/services/orchestration/policy/scoring.js +291 -0
  1151. package/dist/src/services/orchestration/policy/types.js +1 -0
  1152. package/dist/src/services/orchestration/squad/SquadOrchestratorRuntime.js +198 -0
  1153. package/dist/src/services/orchestration/squad/index.js +3 -0
  1154. package/dist/src/services/orchestration/squad/reporting.js +525 -0
  1155. package/dist/src/services/orchestration/squad/types.js +1 -0
  1156. package/dist/src/services/plugins/PluginInstallationManager.js +139 -0
  1157. package/dist/src/services/plugins/pluginCliCommands.js +230 -0
  1158. package/dist/src/services/plugins/pluginOperations.js +826 -0
  1159. package/dist/src/services/policyLimits/index.js +547 -0
  1160. package/dist/src/services/policyLimits/types.js +9 -0
  1161. package/dist/src/services/preventSleep.js +143 -0
  1162. package/dist/src/services/rateLimitMessages.js +271 -0
  1163. package/dist/src/services/rateLimitMocking.js +91 -0
  1164. package/dist/src/services/remoteManagedSettings/index.js +534 -0
  1165. package/dist/src/services/remoteManagedSettings/securityCheck.js +59 -0
  1166. package/dist/src/services/remoteManagedSettings/syncCache.js +90 -0
  1167. package/dist/src/services/remoteManagedSettings/syncCacheState.js +89 -0
  1168. package/dist/src/services/remoteManagedSettings/types.js +12 -0
  1169. package/dist/src/services/settingsSync/index.js +478 -0
  1170. package/dist/src/services/settingsSync/types.js +35 -0
  1171. package/dist/src/services/teamMemorySync/index.js +976 -0
  1172. package/dist/src/services/teamMemorySync/secretScanner.js +275 -0
  1173. package/dist/src/services/teamMemorySync/teamMemSecretGuard.js +35 -0
  1174. package/dist/src/services/teamMemorySync/types.js +47 -0
  1175. package/dist/src/services/teamMemorySync/watcher.js +326 -0
  1176. package/dist/src/services/tips/tipHistory.js +17 -0
  1177. package/dist/src/services/tips/tipRegistry.js +589 -0
  1178. package/dist/src/services/tips/tipScheduler.js +40 -0
  1179. package/dist/src/services/tokenEstimation.js +365 -0
  1180. package/dist/src/services/toolUseSummary/toolUseSummaryGenerator.js +87 -0
  1181. package/dist/src/services/tools/StreamingToolExecutor.js +413 -0
  1182. package/dist/src/services/tools/toolExecution.js +1218 -0
  1183. package/dist/src/services/tools/toolHooks.js +454 -0
  1184. package/dist/src/services/tools/toolOrchestration.js +110 -0
  1185. package/dist/src/services/vcr.js +291 -0
  1186. package/dist/src/services/voice.js +394 -0
  1187. package/dist/src/services/voiceKeyterms.js +94 -0
  1188. package/dist/src/services/voiceStreamSTT.js +406 -0
  1189. package/dist/src/setup.js +349 -0
  1190. package/dist/src/skills/bundled/batch.js +114 -0
  1191. package/dist/src/skills/bundled/claudeApi.js +145 -0
  1192. package/dist/src/skills/bundled/claudeApiContent.js +14 -0
  1193. package/dist/src/skills/bundled/claudeInChrome.js +27 -0
  1194. package/dist/src/skills/bundled/debug.js +99 -0
  1195. package/dist/src/skills/bundled/index.js +5 -0
  1196. package/dist/src/skills/bundled/keybindings.js +292 -0
  1197. package/dist/src/skills/bundled/loop.js +81 -0
  1198. package/dist/src/skills/bundled/loremIpsum.js +266 -0
  1199. package/dist/src/skills/bundled/remember.js +75 -0
  1200. package/dist/src/skills/bundled/scheduleRemoteAgents.js +373 -0
  1201. package/dist/src/skills/bundled/simplify.js +66 -0
  1202. package/dist/src/skills/bundled/skillify.js +184 -0
  1203. package/dist/src/skills/bundled/stuck.js +75 -0
  1204. package/dist/src/skills/bundled/updateConfig.js +463 -0
  1205. package/dist/src/skills/bundled/verify.js +25 -0
  1206. package/dist/src/skills/bundled/verifyContent.js +7 -0
  1207. package/dist/src/skills/bundledSkills.js +159 -0
  1208. package/dist/src/skills/loadSkillsDir.js +751 -0
  1209. package/dist/src/skills/mcpSkillBuilders.js +10 -0
  1210. package/dist/src/ssh/createSSHSession.js +16 -0
  1211. package/dist/src/state/AppState.js +184 -0
  1212. package/dist/src/state/AppStateStore.js +120 -0
  1213. package/dist/src/state/onChangeAppState.js +132 -0
  1214. package/dist/src/state/selectors.js +51 -0
  1215. package/dist/src/state/store.js +21 -0
  1216. package/dist/src/state/teammateViewHelpers.js +124 -0
  1217. package/dist/src/tasks/DreamTask/DreamTask.js +99 -0
  1218. package/dist/src/tasks/InProcessTeammateTask/InProcessTeammateTask.js +116 -0
  1219. package/dist/src/tasks/InProcessTeammateTask/types.js +35 -0
  1220. package/dist/src/tasks/LocalAgentTask/LocalAgentTask.js +507 -0
  1221. package/dist/src/tasks/LocalMainSessionTask.js +338 -0
  1222. package/dist/src/tasks/LocalShellTask/LocalShellTask.js +475 -0
  1223. package/dist/src/tasks/LocalShellTask/guards.js +9 -0
  1224. package/dist/src/tasks/LocalShellTask/killShellTasks.js +59 -0
  1225. package/dist/src/tasks/RemoteAgentTask/RemoteAgentTask.js +742 -0
  1226. package/dist/src/tasks/pillLabel.js +69 -0
  1227. package/dist/src/tasks/stopTask.js +67 -0
  1228. package/dist/src/tasks/types.js +18 -0
  1229. package/dist/src/tasks.js +39 -0
  1230. package/dist/src/telegram/bridge.js +329 -0
  1231. package/dist/src/telegram/config.js +89 -0
  1232. package/dist/src/telegram/mirror.js +91 -0
  1233. package/dist/src/tools/AgentTool/AgentTool.js +1222 -0
  1234. package/dist/src/tools/AgentTool/UI.js +592 -0
  1235. package/dist/src/tools/AgentTool/agentColorManager.js +43 -0
  1236. package/dist/src/tools/AgentTool/agentDisplay.js +72 -0
  1237. package/dist/src/tools/AgentTool/agentMemory.js +139 -0
  1238. package/dist/src/tools/AgentTool/agentMemorySnapshot.js +136 -0
  1239. package/dist/src/tools/AgentTool/agentToolUtils.js +456 -0
  1240. package/dist/src/tools/AgentTool/built-in/claudeCodeGuideAgent.js +175 -0
  1241. package/dist/src/tools/AgentTool/built-in/exploreAgent.js +76 -0
  1242. package/dist/src/tools/AgentTool/built-in/generalPurposeAgent.js +28 -0
  1243. package/dist/src/tools/AgentTool/built-in/planAgent.js +87 -0
  1244. package/dist/src/tools/AgentTool/built-in/statuslineSetup.js +140 -0
  1245. package/dist/src/tools/AgentTool/built-in/verificationAgent.js +146 -0
  1246. package/dist/src/tools/AgentTool/builtInAgents.js +59 -0
  1247. package/dist/src/tools/AgentTool/constants.js +11 -0
  1248. package/dist/src/tools/AgentTool/forkSubagent.js +177 -0
  1249. package/dist/src/tools/AgentTool/loadAgentsDir.js +497 -0
  1250. package/dist/src/tools/AgentTool/prompt.js +262 -0
  1251. package/dist/src/tools/AgentTool/resumeAgent.js +182 -0
  1252. package/dist/src/tools/AgentTool/runAgent.js +629 -0
  1253. package/dist/src/tools/AskUserQuestionTool/AskUserQuestionTool.js +237 -0
  1254. package/dist/src/tools/AskUserQuestionTool/prompt.js +38 -0
  1255. package/dist/src/tools/BashTool/BashTool.js +1008 -0
  1256. package/dist/src/tools/BashTool/BashToolResultMessage.js +168 -0
  1257. package/dist/src/tools/BashTool/UI.js +133 -0
  1258. package/dist/src/tools/BashTool/bashCommandHelpers.js +184 -0
  1259. package/dist/src/tools/BashTool/bashPermissions.js +2023 -0
  1260. package/dist/src/tools/BashTool/bashSecurity.js +2267 -0
  1261. package/dist/src/tools/BashTool/commandSemantics.js +105 -0
  1262. package/dist/src/tools/BashTool/commentLabel.js +14 -0
  1263. package/dist/src/tools/BashTool/destructiveCommandWarning.js +88 -0
  1264. package/dist/src/tools/BashTool/modeValidation.js +86 -0
  1265. package/dist/src/tools/BashTool/pathValidation.js +1080 -0
  1266. package/dist/src/tools/BashTool/prompt.js +334 -0
  1267. package/dist/src/tools/BashTool/readOnlyValidation.js +1794 -0
  1268. package/dist/src/tools/BashTool/sedEditParser.js +282 -0
  1269. package/dist/src/tools/BashTool/sedValidation.js +580 -0
  1270. package/dist/src/tools/BashTool/shouldUseSandbox.js +125 -0
  1271. package/dist/src/tools/BashTool/toolName.js +2 -0
  1272. package/dist/src/tools/BashTool/utils.js +180 -0
  1273. package/dist/src/tools/BriefTool/BriefTool.js +172 -0
  1274. package/dist/src/tools/BriefTool/UI.js +66 -0
  1275. package/dist/src/tools/BriefTool/attachments.js +86 -0
  1276. package/dist/src/tools/BriefTool/prompt.js +19 -0
  1277. package/dist/src/tools/BriefTool/upload.js +136 -0
  1278. package/dist/src/tools/ConfigTool/ConfigTool.js +398 -0
  1279. package/dist/src/tools/ConfigTool/UI.js +24 -0
  1280. package/dist/src/tools/ConfigTool/constants.js +1 -0
  1281. package/dist/src/tools/ConfigTool/prompt.js +82 -0
  1282. package/dist/src/tools/ConfigTool/supportedSettings.js +180 -0
  1283. package/dist/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +98 -0
  1284. package/dist/src/tools/EnterPlanModeTool/UI.js +13 -0
  1285. package/dist/src/tools/EnterPlanModeTool/constants.js +1 -0
  1286. package/dist/src/tools/EnterPlanModeTool/prompt.js +164 -0
  1287. package/dist/src/tools/EnterWorktreeTool/EnterWorktreeTool.js +104 -0
  1288. package/dist/src/tools/EnterWorktreeTool/UI.js +8 -0
  1289. package/dist/src/tools/EnterWorktreeTool/constants.js +1 -0
  1290. package/dist/src/tools/EnterWorktreeTool/prompt.js +30 -0
  1291. package/dist/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +385 -0
  1292. package/dist/src/tools/ExitPlanModeTool/UI.js +31 -0
  1293. package/dist/src/tools/ExitPlanModeTool/constants.js +2 -0
  1294. package/dist/src/tools/ExitPlanModeTool/prompt.js +27 -0
  1295. package/dist/src/tools/ExitWorktreeTool/ExitWorktreeTool.js +257 -0
  1296. package/dist/src/tools/ExitWorktreeTool/UI.js +9 -0
  1297. package/dist/src/tools/ExitWorktreeTool/constants.js +1 -0
  1298. package/dist/src/tools/ExitWorktreeTool/prompt.js +32 -0
  1299. package/dist/src/tools/FileEditTool/FileEditTool.js +480 -0
  1300. package/dist/src/tools/FileEditTool/UI.js +201 -0
  1301. package/dist/src/tools/FileEditTool/constants.js +7 -0
  1302. package/dist/src/tools/FileEditTool/prompt.js +24 -0
  1303. package/dist/src/tools/FileEditTool/types.js +50 -0
  1304. package/dist/src/tools/FileEditTool/utils.js +579 -0
  1305. package/dist/src/tools/FileReadTool/FileReadTool.js +889 -0
  1306. package/dist/src/tools/FileReadTool/UI.js +125 -0
  1307. package/dist/src/tools/FileReadTool/imageProcessor.js +46 -0
  1308. package/dist/src/tools/FileReadTool/limits.js +70 -0
  1309. package/dist/src/tools/FileReadTool/prompt.js +31 -0
  1310. package/dist/src/tools/FileWriteTool/FileWriteTool.js +341 -0
  1311. package/dist/src/tools/FileWriteTool/UI.js +338 -0
  1312. package/dist/src/tools/FileWriteTool/prompt.js +15 -0
  1313. package/dist/src/tools/GlobTool/GlobTool.js +161 -0
  1314. package/dist/src/tools/GlobTool/UI.js +39 -0
  1315. package/dist/src/tools/GlobTool/prompt.js +6 -0
  1316. package/dist/src/tools/GrepTool/GrepTool.js +439 -0
  1317. package/dist/src/tools/GrepTool/UI.js +154 -0
  1318. package/dist/src/tools/GrepTool/prompt.js +16 -0
  1319. package/dist/src/tools/LSPTool/LSPTool.js +660 -0
  1320. package/dist/src/tools/LSPTool/UI.js +204 -0
  1321. package/dist/src/tools/LSPTool/formatters.js +445 -0
  1322. package/dist/src/tools/LSPTool/prompt.js +20 -0
  1323. package/dist/src/tools/LSPTool/schemas.js +197 -0
  1324. package/dist/src/tools/LSPTool/symbolContext.js +75 -0
  1325. package/dist/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +100 -0
  1326. package/dist/src/tools/ListMcpResourcesTool/UI.js +16 -0
  1327. package/dist/src/tools/ListMcpResourcesTool/prompt.js +18 -0
  1328. package/dist/src/tools/MCPTool/MCPTool.js +60 -0
  1329. package/dist/src/tools/MCPTool/UI.js +342 -0
  1330. package/dist/src/tools/MCPTool/classifyForCollapse.js +597 -0
  1331. package/dist/src/tools/MCPTool/prompt.js +3 -0
  1332. package/dist/src/tools/McpAuthTool/McpAuthTool.js +162 -0
  1333. package/dist/src/tools/NotebookEditTool/NotebookEditTool.js +421 -0
  1334. package/dist/src/tools/NotebookEditTool/UI.js +40 -0
  1335. package/dist/src/tools/NotebookEditTool/constants.js +2 -0
  1336. package/dist/src/tools/NotebookEditTool/prompt.js +2 -0
  1337. package/dist/src/tools/PowerShellTool/PowerShellTool.js +899 -0
  1338. package/dist/src/tools/PowerShellTool/UI.js +57 -0
  1339. package/dist/src/tools/PowerShellTool/clmTypes.js +207 -0
  1340. package/dist/src/tools/PowerShellTool/commandSemantics.js +115 -0
  1341. package/dist/src/tools/PowerShellTool/commonParameters.js +27 -0
  1342. package/dist/src/tools/PowerShellTool/destructiveCommandWarning.js +92 -0
  1343. package/dist/src/tools/PowerShellTool/gitSafety.js +185 -0
  1344. package/dist/src/tools/PowerShellTool/modeValidation.js +357 -0
  1345. package/dist/src/tools/PowerShellTool/pathValidation.js +1712 -0
  1346. package/dist/src/tools/PowerShellTool/powershellPermissions.js +1351 -0
  1347. package/dist/src/tools/PowerShellTool/powershellSecurity.js +942 -0
  1348. package/dist/src/tools/PowerShellTool/prompt.js +134 -0
  1349. package/dist/src/tools/PowerShellTool/readOnlyValidation.js +1633 -0
  1350. package/dist/src/tools/PowerShellTool/toolName.js +2 -0
  1351. package/dist/src/tools/REPLTool/constants.js +43 -0
  1352. package/dist/src/tools/REPLTool/primitiveTools.js +36 -0
  1353. package/dist/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +112 -0
  1354. package/dist/src/tools/ReadMcpResourceTool/UI.js +23 -0
  1355. package/dist/src/tools/ReadMcpResourceTool/prompt.js +15 -0
  1356. package/dist/src/tools/RemoteTriggerTool/RemoteTriggerTool.js +142 -0
  1357. package/dist/src/tools/RemoteTriggerTool/UI.js +11 -0
  1358. package/dist/src/tools/RemoteTriggerTool/prompt.js +12 -0
  1359. package/dist/src/tools/ScheduleCronTool/CronCreateTool.js +120 -0
  1360. package/dist/src/tools/ScheduleCronTool/CronDeleteTool.js +74 -0
  1361. package/dist/src/tools/ScheduleCronTool/CronListTool.js +77 -0
  1362. package/dist/src/tools/ScheduleCronTool/UI.js +28 -0
  1363. package/dist/src/tools/ScheduleCronTool/prompt.js +115 -0
  1364. package/dist/src/tools/SendMessageTool/SendMessageTool.js +675 -0
  1365. package/dist/src/tools/SendMessageTool/UI.js +23 -0
  1366. package/dist/src/tools/SendMessageTool/constants.js +1 -0
  1367. package/dist/src/tools/SendMessageTool/prompt.js +47 -0
  1368. package/dist/src/tools/SkillTool/SkillTool.js +827 -0
  1369. package/dist/src/tools/SkillTool/UI.js +60 -0
  1370. package/dist/src/tools/SkillTool/constants.js +1 -0
  1371. package/dist/src/tools/SkillTool/prompt.js +184 -0
  1372. package/dist/src/tools/SleepTool/prompt.js +14 -0
  1373. package/dist/src/tools/SyntheticOutputTool/SyntheticOutputTool.js +138 -0
  1374. package/dist/src/tools/TaskCreateTool/TaskCreateTool.js +104 -0
  1375. package/dist/src/tools/TaskCreateTool/constants.js +1 -0
  1376. package/dist/src/tools/TaskCreateTool/prompt.js +52 -0
  1377. package/dist/src/tools/TaskGetTool/TaskGetTool.js +106 -0
  1378. package/dist/src/tools/TaskGetTool/constants.js +1 -0
  1379. package/dist/src/tools/TaskGetTool/prompt.js +23 -0
  1380. package/dist/src/tools/TaskListTool/TaskListTool.js +89 -0
  1381. package/dist/src/tools/TaskListTool/constants.js +1 -0
  1382. package/dist/src/tools/TaskListTool/prompt.js +44 -0
  1383. package/dist/src/tools/TaskOutputTool/TaskOutputTool.js +535 -0
  1384. package/dist/src/tools/TaskOutputTool/constants.js +1 -0
  1385. package/dist/src/tools/TaskStopTool/TaskStopTool.js +110 -0
  1386. package/dist/src/tools/TaskStopTool/UI.js +30 -0
  1387. package/dist/src/tools/TaskStopTool/prompt.js +7 -0
  1388. package/dist/src/tools/TaskUpdateTool/TaskUpdateTool.js +301 -0
  1389. package/dist/src/tools/TaskUpdateTool/constants.js +1 -0
  1390. package/dist/src/tools/TaskUpdateTool/prompt.js +76 -0
  1391. package/dist/src/tools/TeamCreateTool/TeamCreateTool.js +177 -0
  1392. package/dist/src/tools/TeamCreateTool/UI.js +4 -0
  1393. package/dist/src/tools/TeamCreateTool/constants.js +1 -0
  1394. package/dist/src/tools/TeamCreateTool/prompt.js +113 -0
  1395. package/dist/src/tools/TeamDeleteTool/TeamDeleteTool.js +102 -0
  1396. package/dist/src/tools/TeamDeleteTool/UI.js +13 -0
  1397. package/dist/src/tools/TeamDeleteTool/constants.js +1 -0
  1398. package/dist/src/tools/TeamDeleteTool/prompt.js +16 -0
  1399. package/dist/src/tools/TodoWriteTool/TodoWriteTool.js +99 -0
  1400. package/dist/src/tools/TodoWriteTool/constants.js +1 -0
  1401. package/dist/src/tools/TodoWriteTool/prompt.js +181 -0
  1402. package/dist/src/tools/ToolSearchTool/ToolSearchTool.js +357 -0
  1403. package/dist/src/tools/ToolSearchTool/constants.js +1 -0
  1404. package/dist/src/tools/ToolSearchTool/prompt.js +99 -0
  1405. package/dist/src/tools/TungstenTool/TungstenLiveMonitor.js +7 -0
  1406. package/dist/src/tools/TungstenTool/TungstenTool.js +3 -0
  1407. package/dist/src/tools/WebFetchTool/UI.js +30 -0
  1408. package/dist/src/tools/WebFetchTool/WebFetchTool.js +246 -0
  1409. package/dist/src/tools/WebFetchTool/preapproved.js +155 -0
  1410. package/dist/src/tools/WebFetchTool/prompt.js +39 -0
  1411. package/dist/src/tools/WebFetchTool/utils.js +381 -0
  1412. package/dist/src/tools/WebSearchTool/UI.js +66 -0
  1413. package/dist/src/tools/WebSearchTool/WebSearchTool.js +352 -0
  1414. package/dist/src/tools/WebSearchTool/prompt.js +32 -0
  1415. package/dist/src/tools/WorkflowTool/constants.js +2 -0
  1416. package/dist/src/tools/shared/gitOperationTracking.js +220 -0
  1417. package/dist/src/tools/shared/spawnMultiAgent.js +805 -0
  1418. package/dist/src/tools/testing/TestingPermissionTool.js +72 -0
  1419. package/dist/src/tools/utils.js +24 -0
  1420. package/dist/src/tools.js +332 -0
  1421. package/dist/src/types/command.js +10 -0
  1422. package/dist/src/types/connectorText.js +2 -0
  1423. package/dist/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.js +673 -0
  1424. package/dist/src/types/generated/events_mono/common/v1/auth.js +49 -0
  1425. package/dist/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.js +147 -0
  1426. package/dist/src/types/generated/google/protobuf/timestamp.js +38 -0
  1427. package/dist/src/types/hooks.js +153 -0
  1428. package/dist/src/types/ids.js +27 -0
  1429. package/dist/src/types/logs.js +11 -0
  1430. package/dist/src/types/message.js +1 -0
  1431. package/dist/src/types/permissions.js +25 -0
  1432. package/dist/src/types/plugin.js +72 -0
  1433. package/dist/src/types/textInputTypes.js +20 -0
  1434. package/dist/src/types/utils.js +5 -0
  1435. package/dist/src/upstreamproxy/relay.js +346 -0
  1436. package/dist/src/upstreamproxy/upstreamproxy.js +236 -0
  1437. package/dist/src/utils/CircularBuffer.js +75 -0
  1438. package/dist/src/utils/Cursor.js +1229 -0
  1439. package/dist/src/utils/QueryGuard.js +115 -0
  1440. package/dist/src/utils/Shell.js +374 -0
  1441. package/dist/src/utils/ShellCommand.js +338 -0
  1442. package/dist/src/utils/abortController.js +74 -0
  1443. package/dist/src/utils/activityManager.js +127 -0
  1444. package/dist/src/utils/advisor.js +77 -0
  1445. package/dist/src/utils/agentContext.js +91 -0
  1446. package/dist/src/utils/agentId.js +83 -0
  1447. package/dist/src/utils/agentSwarmsEnabled.js +37 -0
  1448. package/dist/src/utils/agenticSessionSearch.js +255 -0
  1449. package/dist/src/utils/analyzeContext.js +848 -0
  1450. package/dist/src/utils/ansiToPng.js +259 -0
  1451. package/dist/src/utils/ansiToSvg.js +207 -0
  1452. package/dist/src/utils/api.js +555 -0
  1453. package/dist/src/utils/apiPreconnect.js +62 -0
  1454. package/dist/src/utils/appleTerminalBackup.js +95 -0
  1455. package/dist/src/utils/argumentSubstitution.js +114 -0
  1456. package/dist/src/utils/array.js +12 -0
  1457. package/dist/src/utils/asciicast.js +200 -0
  1458. package/dist/src/utils/attachments.js +2514 -0
  1459. package/dist/src/utils/attribution.js +308 -0
  1460. package/dist/src/utils/attributionHooks.js +16 -0
  1461. package/dist/src/utils/attributionTrailer.js +16 -0
  1462. package/dist/src/utils/auth.js +2022 -0
  1463. package/dist/src/utils/authFileDescriptor.js +152 -0
  1464. package/dist/src/utils/authPortable.js +14 -0
  1465. package/dist/src/utils/autoModeDenials.js +15 -0
  1466. package/dist/src/utils/autoRunIssue.js +112 -0
  1467. package/dist/src/utils/autoUpdater.js +461 -0
  1468. package/dist/src/utils/aws.js +44 -0
  1469. package/dist/src/utils/awsAuthStatusManager.js +66 -0
  1470. package/dist/src/utils/background/remote/preconditions.js +175 -0
  1471. package/dist/src/utils/background/remote/remoteSession.js +53 -0
  1472. package/dist/src/utils/backgroundHousekeeping.js +66 -0
  1473. package/dist/src/utils/bash/ParsedCommand.js +241 -0
  1474. package/dist/src/utils/bash/ShellSnapshot.js +489 -0
  1475. package/dist/src/utils/bash/ast.js +2590 -0
  1476. package/dist/src/utils/bash/bashParser.js +4355 -0
  1477. package/dist/src/utils/bash/bashPipeCommand.js +249 -0
  1478. package/dist/src/utils/bash/commands.js +1131 -0
  1479. package/dist/src/utils/bash/heredoc.js +647 -0
  1480. package/dist/src/utils/bash/parser.js +195 -0
  1481. package/dist/src/utils/bash/prefix.js +154 -0
  1482. package/dist/src/utils/bash/registry.js +23 -0
  1483. package/dist/src/utils/bash/shellCompletion.js +196 -0
  1484. package/dist/src/utils/bash/shellPrefix.js +25 -0
  1485. package/dist/src/utils/bash/shellQuote.js +253 -0
  1486. package/dist/src/utils/bash/shellQuoting.js +106 -0
  1487. package/dist/src/utils/bash/specs/alias.js +11 -0
  1488. package/dist/src/utils/bash/specs/index.js +16 -0
  1489. package/dist/src/utils/bash/specs/nohup.js +10 -0
  1490. package/dist/src/utils/bash/specs/pyright.js +88 -0
  1491. package/dist/src/utils/bash/specs/sleep.js +10 -0
  1492. package/dist/src/utils/bash/specs/srun.js +28 -0
  1493. package/dist/src/utils/bash/specs/time.js +10 -0
  1494. package/dist/src/utils/bash/specs/timeout.js +17 -0
  1495. package/dist/src/utils/bash/treeSitterAnalysis.js +407 -0
  1496. package/dist/src/utils/betas.js +332 -0
  1497. package/dist/src/utils/billing.js +54 -0
  1498. package/dist/src/utils/binaryCheck.js +40 -0
  1499. package/dist/src/utils/browser.js +58 -0
  1500. package/dist/src/utils/bufferedWriter.js +77 -0
  1501. package/dist/src/utils/bundledMode.js +19 -0
  1502. package/dist/src/utils/caCerts.js +93 -0
  1503. package/dist/src/utils/caCertsConfig.js +77 -0
  1504. package/dist/src/utils/cachePaths.js +28 -0
  1505. package/dist/src/utils/ccshareResume.js +16 -0
  1506. package/dist/src/utils/classifierApprovals.js +66 -0
  1507. package/dist/src/utils/classifierApprovalsHook.js +10 -0
  1508. package/dist/src/utils/claudeCodeHints.js +142 -0
  1509. package/dist/src/utils/claudeDesktop.js +108 -0
  1510. package/dist/src/utils/claudeInChrome/chromeNativeHost.js +416 -0
  1511. package/dist/src/utils/claudeInChrome/common.js +466 -0
  1512. package/dist/src/utils/claudeInChrome/mcpServer.js +237 -0
  1513. package/dist/src/utils/claudeInChrome/prompt.js +79 -0
  1514. package/dist/src/utils/claudeInChrome/setup.js +320 -0
  1515. package/dist/src/utils/claudeInChrome/setupPortable.js +172 -0
  1516. package/dist/src/utils/claudeInChrome/toolRendering.js +234 -0
  1517. package/dist/src/utils/claudemd.js +1054 -0
  1518. package/dist/src/utils/cleanup.js +514 -0
  1519. package/dist/src/utils/cleanupRegistry.js +22 -0
  1520. package/dist/src/utils/cliArgs.js +53 -0
  1521. package/dist/src/utils/cliHighlight.js +45 -0
  1522. package/dist/src/utils/codeIndexing.js +149 -0
  1523. package/dist/src/utils/collapseBackgroundBashNotifications.js +70 -0
  1524. package/dist/src/utils/collapseHookSummaries.js +48 -0
  1525. package/dist/src/utils/collapseReadSearch.js +871 -0
  1526. package/dist/src/utils/collapseTeammateShutdowns.js +44 -0
  1527. package/dist/src/utils/combinedAbortSignal.js +40 -0
  1528. package/dist/src/utils/commandLifecycle.js +7 -0
  1529. package/dist/src/utils/commitAttribution.js +720 -0
  1530. package/dist/src/utils/completionCache.js +138 -0
  1531. package/dist/src/utils/computerUse/appNames.js +170 -0
  1532. package/dist/src/utils/computerUse/cleanup.js +66 -0
  1533. package/dist/src/utils/computerUse/common.js +56 -0
  1534. package/dist/src/utils/computerUse/computerUseLock.js +183 -0
  1535. package/dist/src/utils/computerUse/drainRunLoop.js +71 -0
  1536. package/dist/src/utils/computerUse/escHotkey.js +53 -0
  1537. package/dist/src/utils/computerUse/executor.js +480 -0
  1538. package/dist/src/utils/computerUse/gates.js +55 -0
  1539. package/dist/src/utils/computerUse/hostAdapter.js +62 -0
  1540. package/dist/src/utils/computerUse/inputLoader.js +27 -0
  1541. package/dist/src/utils/computerUse/mcpServer.js +84 -0
  1542. package/dist/src/utils/computerUse/setup.js +42 -0
  1543. package/dist/src/utils/computerUse/swiftLoader.js +20 -0
  1544. package/dist/src/utils/computerUse/toolRendering.js +100 -0
  1545. package/dist/src/utils/computerUse/wrapper.js +318 -0
  1546. package/dist/src/utils/concurrentSessions.js +179 -0
  1547. package/dist/src/utils/config.js +1084 -0
  1548. package/dist/src/utils/configConstants.js +18 -0
  1549. package/dist/src/utils/contentArray.js +45 -0
  1550. package/dist/src/utils/context.js +185 -0
  1551. package/dist/src/utils/contextAnalysis.js +171 -0
  1552. package/dist/src/utils/contextSuggestions.js +158 -0
  1553. package/dist/src/utils/controlMessageCompat.js +31 -0
  1554. package/dist/src/utils/conversationRecovery.js +436 -0
  1555. package/dist/src/utils/cron.js +260 -0
  1556. package/dist/src/utils/cronJitterConfig.js +62 -0
  1557. package/dist/src/utils/cronScheduler.js +388 -0
  1558. package/dist/src/utils/cronTasks.js +332 -0
  1559. package/dist/src/utils/cronTasksLock.js +164 -0
  1560. package/dist/src/utils/crossProjectResume.js +46 -0
  1561. package/dist/src/utils/crypto.js +13 -0
  1562. package/dist/src/utils/cwd.js +29 -0
  1563. package/dist/src/utils/databaseMcp/common.js +48 -0
  1564. package/dist/src/utils/databaseMcp/mcpServer.js +2 -0
  1565. package/dist/src/utils/databaseMcp/server/connection.js +243 -0
  1566. package/dist/src/utils/databaseMcp/server/index.js +1442 -0
  1567. package/dist/src/utils/databaseMcp/server/queries.js +683 -0
  1568. package/dist/src/utils/databaseMcp/server/types.js +7 -0
  1569. package/dist/src/utils/databaseMcp/setup.js +28 -0
  1570. package/dist/src/utils/debug.js +220 -0
  1571. package/dist/src/utils/debugFilter.js +125 -0
  1572. package/dist/src/utils/deepLink/banner.js +103 -0
  1573. package/dist/src/utils/deepLink/parseDeepLink.js +138 -0
  1574. package/dist/src/utils/deepLink/protocolHandler.js +119 -0
  1575. package/dist/src/utils/deepLink/registerProtocol.js +291 -0
  1576. package/dist/src/utils/deepLink/terminalLauncher.js +455 -0
  1577. package/dist/src/utils/deepLink/terminalPreference.js +51 -0
  1578. package/dist/src/utils/desktopDeepLink.js +208 -0
  1579. package/dist/src/utils/detectRepository.js +157 -0
  1580. package/dist/src/utils/diagLogs.js +74 -0
  1581. package/dist/src/utils/diff.js +108 -0
  1582. package/dist/src/utils/directMemberMessage.js +34 -0
  1583. package/dist/src/utils/displayTags.js +46 -0
  1584. package/dist/src/utils/doctorContextWarnings.js +179 -0
  1585. package/dist/src/utils/doctorDiagnostic.js +495 -0
  1586. package/dist/src/utils/dxt/helpers.js +64 -0
  1587. package/dist/src/utils/dxt/zip.js +167 -0
  1588. package/dist/src/utils/earlyInput.js +166 -0
  1589. package/dist/src/utils/editor.js +163 -0
  1590. package/dist/src/utils/effort.js +278 -0
  1591. package/dist/src/utils/embeddedTools.js +26 -0
  1592. package/dist/src/utils/env.js +358 -0
  1593. package/dist/src/utils/envDynamic.js +130 -0
  1594. package/dist/src/utils/envUtils.js +192 -0
  1595. package/dist/src/utils/envValidation.js +26 -0
  1596. package/dist/src/utils/errorLogSink.js +197 -0
  1597. package/dist/src/utils/errors.js +207 -0
  1598. package/dist/src/utils/eventLoopStallDetector.js +16 -0
  1599. package/dist/src/utils/exampleCommands.js +165 -0
  1600. package/dist/src/utils/execFileNoThrow.js +93 -0
  1601. package/dist/src/utils/execFileNoThrowPortable.js +111 -0
  1602. package/dist/src/utils/execSyncWrapper.js +68 -0
  1603. package/dist/src/utils/exportRenderer.js +71 -0
  1604. package/dist/src/utils/extraUsage.js +19 -0
  1605. package/dist/src/utils/fastMode.js +393 -0
  1606. package/dist/src/utils/file.js +467 -0
  1607. package/dist/src/utils/fileHistory.js +851 -0
  1608. package/dist/src/utils/fileOperationAnalytics.js +45 -0
  1609. package/dist/src/utils/filePersistence/filePersistence.js +212 -0
  1610. package/dist/src/utils/filePersistence/outputsScanner.js +104 -0
  1611. package/dist/src/utils/filePersistence/types.js +5 -0
  1612. package/dist/src/utils/fileRead.js +81 -0
  1613. package/dist/src/utils/fileReadCache.js +78 -0
  1614. package/dist/src/utils/fileStateCache.js +99 -0
  1615. package/dist/src/utils/findExecutable.js +13 -0
  1616. package/dist/src/utils/fingerprint.js +59 -0
  1617. package/dist/src/utils/forkedAgent.js +410 -0
  1618. package/dist/src/utils/format.js +238 -0
  1619. package/dist/src/utils/formatBriefTimestamp.js +72 -0
  1620. package/dist/src/utils/fpsTracker.js +34 -0
  1621. package/dist/src/utils/frontmatterParser.js +260 -0
  1622. package/dist/src/utils/fsOperations.js +834 -0
  1623. package/dist/src/utils/fullscreen.js +194 -0
  1624. package/dist/src/utils/generatedFiles.js +122 -0
  1625. package/dist/src/utils/generators.js +67 -0
  1626. package/dist/src/utils/genericProcessUtils.js +155 -0
  1627. package/dist/src/utils/getWorktreePaths.js +56 -0
  1628. package/dist/src/utils/getWorktreePathsPortable.js +23 -0
  1629. package/dist/src/utils/ghPrStatus.js +71 -0
  1630. package/dist/src/utils/git/gitConfigParser.js +226 -0
  1631. package/dist/src/utils/git/gitFilesystem.js +606 -0
  1632. package/dist/src/utils/git/gitignore.js +84 -0
  1633. package/dist/src/utils/git.js +725 -0
  1634. package/dist/src/utils/gitDiff.js +395 -0
  1635. package/dist/src/utils/gitSettings.js +18 -0
  1636. package/dist/src/utils/github/ghAuthStatus.js +23 -0
  1637. package/dist/src/utils/githubRepoPathMapping.js +135 -0
  1638. package/dist/src/utils/glob.js +90 -0
  1639. package/dist/src/utils/gracefulShutdown.js +447 -0
  1640. package/dist/src/utils/groupToolUses.js +126 -0
  1641. package/dist/src/utils/handlePromptSubmit.js +398 -0
  1642. package/dist/src/utils/hash.js +46 -0
  1643. package/dist/src/utils/headlessProfiler.js +147 -0
  1644. package/dist/src/utils/heapDumpService.js +202 -0
  1645. package/dist/src/utils/heatmap.js +151 -0
  1646. package/dist/src/utils/highlightMatch.js +28 -0
  1647. package/dist/src/utils/hooks/AsyncHookRegistry.js +187 -0
  1648. package/dist/src/utils/hooks/apiQueryHookHelper.js +77 -0
  1649. package/dist/src/utils/hooks/execAgentHook.js +257 -0
  1650. package/dist/src/utils/hooks/execHttpHook.js +184 -0
  1651. package/dist/src/utils/hooks/execPromptHook.js +171 -0
  1652. package/dist/src/utils/hooks/fileChangedWatcher.js +161 -0
  1653. package/dist/src/utils/hooks/hookEvents.js +111 -0
  1654. package/dist/src/utils/hooks/hookHelpers.js +60 -0
  1655. package/dist/src/utils/hooks/hooksConfigManager.js +323 -0
  1656. package/dist/src/utils/hooks/hooksConfigSnapshot.js +114 -0
  1657. package/dist/src/utils/hooks/hooksSettings.js +204 -0
  1658. package/dist/src/utils/hooks/postSamplingHooks.js +39 -0
  1659. package/dist/src/utils/hooks/registerFrontmatterHooks.js +47 -0
  1660. package/dist/src/utils/hooks/registerSkillHooks.js +40 -0
  1661. package/dist/src/utils/hooks/sessionHooks.js +252 -0
  1662. package/dist/src/utils/hooks/skillImprovement.js +211 -0
  1663. package/dist/src/utils/hooks/ssrfGuard.js +258 -0
  1664. package/dist/src/utils/hooks.js +3668 -0
  1665. package/dist/src/utils/horizontalScroll.js +108 -0
  1666. package/dist/src/utils/http.js +121 -0
  1667. package/dist/src/utils/hyperlink.js +28 -0
  1668. package/dist/src/utils/iTermBackup.js +48 -0
  1669. package/dist/src/utils/ide.js +1235 -0
  1670. package/dist/src/utils/idePathConversion.js +66 -0
  1671. package/dist/src/utils/idleTimeout.js +44 -0
  1672. package/dist/src/utils/imagePaste.js +329 -0
  1673. package/dist/src/utils/imageResizer.js +664 -0
  1674. package/dist/src/utils/imageStore.js +150 -0
  1675. package/dist/src/utils/imageValidation.js +92 -0
  1676. package/dist/src/utils/immediateCommand.js +12 -0
  1677. package/dist/src/utils/inProcessTeammateHelpers.js +71 -0
  1678. package/dist/src/utils/ink.js +20 -0
  1679. package/dist/src/utils/intl.js +83 -0
  1680. package/dist/src/utils/jetbrains.js +152 -0
  1681. package/dist/src/utils/json.js +295 -0
  1682. package/dist/src/utils/jsonRead.js +14 -0
  1683. package/dist/src/utils/keyboardShortcuts.js +11 -0
  1684. package/dist/src/utils/lazySchema.js +8 -0
  1685. package/dist/src/utils/listSessionsImpl.js +332 -0
  1686. package/dist/src/utils/localInstaller.js +131 -0
  1687. package/dist/src/utils/lockfile.js +22 -0
  1688. package/dist/src/utils/log.js +280 -0
  1689. package/dist/src/utils/logoV2Utils.js +290 -0
  1690. package/dist/src/utils/mailbox.js +50 -0
  1691. package/dist/src/utils/managedEnv.js +160 -0
  1692. package/dist/src/utils/managedEnvConstants.js +200 -0
  1693. package/dist/src/utils/markdown.js +300 -0
  1694. package/dist/src/utils/markdownConfigLoader.js +494 -0
  1695. package/dist/src/utils/mcp/dateTimeParser.js +102 -0
  1696. package/dist/src/utils/mcp/elicitationValidation.js +259 -0
  1697. package/dist/src/utils/mcpInstructionsDelta.js +97 -0
  1698. package/dist/src/utils/mcpOutputStorage.js +159 -0
  1699. package/dist/src/utils/mcpValidation.js +165 -0
  1700. package/dist/src/utils/mcpWebSocketTransport.js +180 -0
  1701. package/dist/src/utils/memoize.js +205 -0
  1702. package/dist/src/utils/memory/types.js +9 -0
  1703. package/dist/src/utils/memory/versions.js +7 -0
  1704. package/dist/src/utils/memoryFileDetection.js +247 -0
  1705. package/dist/src/utils/messagePredicates.js +6 -0
  1706. package/dist/src/utils/messageQueueManager.js +430 -0
  1707. package/dist/src/utils/messages/mappers.js +240 -0
  1708. package/dist/src/utils/messages/systemInit.js +74 -0
  1709. package/dist/src/utils/messages.js +4273 -0
  1710. package/dist/src/utils/model/agent.js +128 -0
  1711. package/dist/src/utils/model/aliases.js +21 -0
  1712. package/dist/src/utils/model/antModels.js +25 -0
  1713. package/dist/src/utils/model/bedrock.js +220 -0
  1714. package/dist/src/utils/model/check1mAccess.js +64 -0
  1715. package/dist/src/utils/model/configs.js +93 -0
  1716. package/dist/src/utils/model/contextWindowUpgradeCheck.js +41 -0
  1717. package/dist/src/utils/model/deprecation.js +72 -0
  1718. package/dist/src/utils/model/model.js +641 -0
  1719. package/dist/src/utils/model/modelAllowlist.js +148 -0
  1720. package/dist/src/utils/model/modelCapabilities.js +107 -0
  1721. package/dist/src/utils/model/modelOptions.js +645 -0
  1722. package/dist/src/utils/model/modelStrings.js +144 -0
  1723. package/dist/src/utils/model/modelSupportOverrides.js +40 -0
  1724. package/dist/src/utils/model/openrouter.js +51 -0
  1725. package/dist/src/utils/model/providerBaseUrls.js +77 -0
  1726. package/dist/src/utils/model/providerCatalog.js +81 -0
  1727. package/dist/src/utils/model/providerModels.js +334 -0
  1728. package/dist/src/utils/model/providerProfiles.js +392 -0
  1729. package/dist/src/utils/model/providerProfilesDb.js +886 -0
  1730. package/dist/src/utils/model/providerSwitch.js +50 -0
  1731. package/dist/src/utils/model/providerWorkspaces.js +36 -0
  1732. package/dist/src/utils/model/providers.js +199 -0
  1733. package/dist/src/utils/model/validateModel.js +257 -0
  1734. package/dist/src/utils/modelCost.js +160 -0
  1735. package/dist/src/utils/modifiers.js +35 -0
  1736. package/dist/src/utils/mtls.js +134 -0
  1737. package/dist/src/utils/nativeInstaller/download.js +370 -0
  1738. package/dist/src/utils/nativeInstaller/index.js +8 -0
  1739. package/dist/src/utils/nativeInstaller/installer.js +1396 -0
  1740. package/dist/src/utils/nativeInstaller/packageManagers.js +258 -0
  1741. package/dist/src/utils/nativeInstaller/pidLock.js +347 -0
  1742. package/dist/src/utils/notebook.js +176 -0
  1743. package/dist/src/utils/objectGroupBy.js +15 -0
  1744. package/dist/src/utils/orchestration/store/index.js +6 -0
  1745. package/dist/src/utils/orchestration/store/orchestrationDb.js +42 -0
  1746. package/dist/src/utils/orchestration/store/providerAgentStore.js +244 -0
  1747. package/dist/src/utils/orchestration/store/providerWorkspaceStore.js +125 -0
  1748. package/dist/src/utils/orchestration/store/runStore.js +486 -0
  1749. package/dist/src/utils/orchestration/store/teamStore.js +285 -0
  1750. package/dist/src/utils/orchestration/store/types.js +1 -0
  1751. package/dist/src/utils/pasteStore.js +93 -0
  1752. package/dist/src/utils/path.js +140 -0
  1753. package/dist/src/utils/pdf.js +236 -0
  1754. package/dist/src/utils/pdfUtils.js +61 -0
  1755. package/dist/src/utils/peerAddress.js +20 -0
  1756. package/dist/src/utils/permissions/PermissionMode.js +95 -0
  1757. package/dist/src/utils/permissions/PermissionPromptToolResultSchema.js +85 -0
  1758. package/dist/src/utils/permissions/PermissionResult.js +11 -0
  1759. package/dist/src/utils/permissions/PermissionRule.js +19 -0
  1760. package/dist/src/utils/permissions/PermissionUpdate.js +330 -0
  1761. package/dist/src/utils/permissions/PermissionUpdateSchema.js +61 -0
  1762. package/dist/src/utils/permissions/autoModeState.js +34 -0
  1763. package/dist/src/utils/permissions/bashClassifier.js +30 -0
  1764. package/dist/src/utils/permissions/bypassPermissionsKillswitch.js +115 -0
  1765. package/dist/src/utils/permissions/classifierDecision.js +88 -0
  1766. package/dist/src/utils/permissions/classifierShared.js +28 -0
  1767. package/dist/src/utils/permissions/dangerousPatterns.js +78 -0
  1768. package/dist/src/utils/permissions/denialTracking.js +34 -0
  1769. package/dist/src/utils/permissions/filesystem.js +1426 -0
  1770. package/dist/src/utils/permissions/getNextPermissionMode.js +74 -0
  1771. package/dist/src/utils/permissions/pathValidation.js +351 -0
  1772. package/dist/src/utils/permissions/permissionExplainer.js +188 -0
  1773. package/dist/src/utils/permissions/permissionRuleParser.js +177 -0
  1774. package/dist/src/utils/permissions/permissionSetup.js +1164 -0
  1775. package/dist/src/utils/permissions/permissions.js +1106 -0
  1776. package/dist/src/utils/permissions/permissionsDb.js +322 -0
  1777. package/dist/src/utils/permissions/permissionsLoader.js +217 -0
  1778. package/dist/src/utils/permissions/shadowedRuleDetection.js +149 -0
  1779. package/dist/src/utils/permissions/shellRuleMatching.js +174 -0
  1780. package/dist/src/utils/permissions/yoloClassifier.js +1195 -0
  1781. package/dist/src/utils/planModeV2.js +75 -0
  1782. package/dist/src/utils/plans.js +334 -0
  1783. package/dist/src/utils/platform.js +122 -0
  1784. package/dist/src/utils/plugins/addDirPluginSettings.js +53 -0
  1785. package/dist/src/utils/plugins/cacheUtils.js +174 -0
  1786. package/dist/src/utils/plugins/dependencyResolver.js +244 -0
  1787. package/dist/src/utils/plugins/fetchTelemetry.js +108 -0
  1788. package/dist/src/utils/plugins/gitAvailability.js +65 -0
  1789. package/dist/src/utils/plugins/headlessPluginInstall.js +136 -0
  1790. package/dist/src/utils/plugins/hintRecommendation.js +136 -0
  1791. package/dist/src/utils/plugins/installCounts.js +218 -0
  1792. package/dist/src/utils/plugins/installedPluginsManager.js +1003 -0
  1793. package/dist/src/utils/plugins/loadPluginAgents.js +219 -0
  1794. package/dist/src/utils/plugins/loadPluginCommands.js +595 -0
  1795. package/dist/src/utils/plugins/loadPluginHooks.js +239 -0
  1796. package/dist/src/utils/plugins/loadPluginOutputStyles.js +112 -0
  1797. package/dist/src/utils/plugins/lspPluginIntegration.js +293 -0
  1798. package/dist/src/utils/plugins/lspRecommendation.js +278 -0
  1799. package/dist/src/utils/plugins/managedPlugins.js +26 -0
  1800. package/dist/src/utils/plugins/marketplaceHelpers.js +470 -0
  1801. package/dist/src/utils/plugins/marketplaceManager.js +1939 -0
  1802. package/dist/src/utils/plugins/mcpPluginIntegration.js +465 -0
  1803. package/dist/src/utils/plugins/mcpbHandler.js +708 -0
  1804. package/dist/src/utils/plugins/officialMarketplace.js +21 -0
  1805. package/dist/src/utils/plugins/officialMarketplaceGcs.js +195 -0
  1806. package/dist/src/utils/plugins/officialMarketplaceStartupCheck.js +338 -0
  1807. package/dist/src/utils/plugins/orphanedPluginFilter.js +96 -0
  1808. package/dist/src/utils/plugins/parseMarketplaceInput.js +143 -0
  1809. package/dist/src/utils/plugins/performStartupChecks.js +66 -0
  1810. package/dist/src/utils/plugins/pluginAutoupdate.js +210 -0
  1811. package/dist/src/utils/plugins/pluginBlocklist.js +93 -0
  1812. package/dist/src/utils/plugins/pluginDirectories.js +172 -0
  1813. package/dist/src/utils/plugins/pluginFlagging.js +173 -0
  1814. package/dist/src/utils/plugins/pluginIdentifier.js +78 -0
  1815. package/dist/src/utils/plugins/pluginInstallationHelpers.js +400 -0
  1816. package/dist/src/utils/plugins/pluginLoader.js +2426 -0
  1817. package/dist/src/utils/plugins/pluginOptionsStorage.js +311 -0
  1818. package/dist/src/utils/plugins/pluginPolicy.js +18 -0
  1819. package/dist/src/utils/plugins/pluginStartupCheck.js +261 -0
  1820. package/dist/src/utils/plugins/pluginVersioning.js +128 -0
  1821. package/dist/src/utils/plugins/reconciler.js +181 -0
  1822. package/dist/src/utils/plugins/refresh.js +162 -0
  1823. package/dist/src/utils/plugins/schemas.js +1283 -0
  1824. package/dist/src/utils/plugins/validatePlugin.js +765 -0
  1825. package/dist/src/utils/plugins/walkPluginMarkdown.js +49 -0
  1826. package/dist/src/utils/plugins/zipCache.js +346 -0
  1827. package/dist/src/utils/plugins/zipCacheAdapters.js +133 -0
  1828. package/dist/src/utils/postCommitAttribution.js +16 -0
  1829. package/dist/src/utils/powershell/dangerousCmdlets.js +174 -0
  1830. package/dist/src/utils/powershell/parser.js +1357 -0
  1831. package/dist/src/utils/powershell/staticPrefix.js +277 -0
  1832. package/dist/src/utils/preflightChecks.js +147 -0
  1833. package/dist/src/utils/privacyLevel.js +49 -0
  1834. package/dist/src/utils/process.js +56 -0
  1835. package/dist/src/utils/processUserInput/processBashCommand.js +119 -0
  1836. package/dist/src/utils/processUserInput/processSlashCommand.js +859 -0
  1837. package/dist/src/utils/processUserInput/processTextPrompt.js +68 -0
  1838. package/dist/src/utils/processUserInput/processUserInput.js +326 -0
  1839. package/dist/src/utils/profilerBase.js +29 -0
  1840. package/dist/src/utils/promptCategory.js +39 -0
  1841. package/dist/src/utils/promptEditor.js +151 -0
  1842. package/dist/src/utils/promptShellExecution.js +119 -0
  1843. package/dist/src/utils/proxy.js +347 -0
  1844. package/dist/src/utils/queryContext.js +110 -0
  1845. package/dist/src/utils/queryHelpers.js +436 -0
  1846. package/dist/src/utils/queryProfiler.js +242 -0
  1847. package/dist/src/utils/queueProcessor.js +70 -0
  1848. package/dist/src/utils/readEditContext.js +176 -0
  1849. package/dist/src/utils/readFileInRange.js +278 -0
  1850. package/dist/src/utils/releaseNotes.js +304 -0
  1851. package/dist/src/utils/renderOptions.js +67 -0
  1852. package/dist/src/utils/ripgrep.js +540 -0
  1853. package/dist/src/utils/sandbox/sandbox-adapter.js +751 -0
  1854. package/dist/src/utils/sandbox/sandbox-ui-utils.js +11 -0
  1855. package/dist/src/utils/sanitization.js +72 -0
  1856. package/dist/src/utils/screenshotClipboard.js +89 -0
  1857. package/dist/src/utils/sdkEventQueue.js +49 -0
  1858. package/dist/src/utils/sdkHeapDumpMonitor.js +16 -0
  1859. package/dist/src/utils/secureStorage/fallbackStorage.js +59 -0
  1860. package/dist/src/utils/secureStorage/index.js +14 -0
  1861. package/dist/src/utils/secureStorage/keychainPrefetch.js +91 -0
  1862. package/dist/src/utils/secureStorage/macOsKeychainHelpers.js +91 -0
  1863. package/dist/src/utils/secureStorage/macOsKeychainStorage.js +192 -0
  1864. package/dist/src/utils/secureStorage/plainTextStorage.js +81 -0
  1865. package/dist/src/utils/secureStorage/secureStoreDefs.js +1 -0
  1866. package/dist/src/utils/secureStorage/sqliteStorage.js +224 -0
  1867. package/dist/src/utils/secureStorage/types.js +1 -0
  1868. package/dist/src/utils/semanticBoolean.js +23 -0
  1869. package/dist/src/utils/semanticNumber.js +34 -0
  1870. package/dist/src/utils/semver.js +53 -0
  1871. package/dist/src/utils/sequential.js +43 -0
  1872. package/dist/src/utils/sessionActivity.js +120 -0
  1873. package/dist/src/utils/sessionDataUploader.js +16 -0
  1874. package/dist/src/utils/sessionEnvVars.js +18 -0
  1875. package/dist/src/utils/sessionEnvironment.js +131 -0
  1876. package/dist/src/utils/sessionFileAccessHooks.js +207 -0
  1877. package/dist/src/utils/sessionIngressAuth.js +113 -0
  1878. package/dist/src/utils/sessionRestore.js +359 -0
  1879. package/dist/src/utils/sessionStart.js +165 -0
  1880. package/dist/src/utils/sessionState.js +76 -0
  1881. package/dist/src/utils/sessionStorage.js +4162 -0
  1882. package/dist/src/utils/sessionStoragePortable.js +665 -0
  1883. package/dist/src/utils/sessionTitle.js +120 -0
  1884. package/dist/src/utils/sessionUrl.js +50 -0
  1885. package/dist/src/utils/set.js +50 -0
  1886. package/dist/src/utils/settings/allErrors.js +29 -0
  1887. package/dist/src/utils/settings/applySettingsChange.js +65 -0
  1888. package/dist/src/utils/settings/changeDetector.js +409 -0
  1889. package/dist/src/utils/settings/constants.js +166 -0
  1890. package/dist/src/utils/settings/internalWrites.js +33 -0
  1891. package/dist/src/utils/settings/managedPath.js +29 -0
  1892. package/dist/src/utils/settings/mdm/constants.js +62 -0
  1893. package/dist/src/utils/settings/mdm/rawRead.js +97 -0
  1894. package/dist/src/utils/settings/mdm/settings.js +254 -0
  1895. package/dist/src/utils/settings/permissionValidation.js +224 -0
  1896. package/dist/src/utils/settings/pluginOnlyPolicy.js +53 -0
  1897. package/dist/src/utils/settings/schemaOutput.js +7 -0
  1898. package/dist/src/utils/settings/settings.js +844 -0
  1899. package/dist/src/utils/settings/settingsCache.js +47 -0
  1900. package/dist/src/utils/settings/toolValidationConfig.js +76 -0
  1901. package/dist/src/utils/settings/types.js +846 -0
  1902. package/dist/src/utils/settings/validateEditTool.js +34 -0
  1903. package/dist/src/utils/settings/validation.js +192 -0
  1904. package/dist/src/utils/settings/validationTips.js +111 -0
  1905. package/dist/src/utils/shell/bashProvider.js +202 -0
  1906. package/dist/src/utils/shell/outputLimits.js +7 -0
  1907. package/dist/src/utils/shell/powershellDetection.js +96 -0
  1908. package/dist/src/utils/shell/powershellProvider.js +104 -0
  1909. package/dist/src/utils/shell/prefix.js +246 -0
  1910. package/dist/src/utils/shell/readOnlyCommandValidation.js +1776 -0
  1911. package/dist/src/utils/shell/resolveDefaultShell.js +13 -0
  1912. package/dist/src/utils/shell/shellProvider.js +2 -0
  1913. package/dist/src/utils/shell/shellToolUtils.js +21 -0
  1914. package/dist/src/utils/shell/specPrefix.js +198 -0
  1915. package/dist/src/utils/shellConfig.js +136 -0
  1916. package/dist/src/utils/sideQuery.js +195 -0
  1917. package/dist/src/utils/sideQuestion.js +121 -0
  1918. package/dist/src/utils/signal.js +34 -0
  1919. package/dist/src/utils/sinks.js +15 -0
  1920. package/dist/src/utils/skills/skillChangeDetector.js +266 -0
  1921. package/dist/src/utils/slashCommandParsing.js +46 -0
  1922. package/dist/src/utils/sleep.js +72 -0
  1923. package/dist/src/utils/sliceAnsi.js +74 -0
  1924. package/dist/src/utils/slowOperations.js +323 -0
  1925. package/dist/src/utils/standaloneAgent.js +20 -0
  1926. package/dist/src/utils/startupProfiler.js +158 -0
  1927. package/dist/src/utils/staticRender.js +103 -0
  1928. package/dist/src/utils/stats.js +802 -0
  1929. package/dist/src/utils/statsCache.js +330 -0
  1930. package/dist/src/utils/status.js +552 -0
  1931. package/dist/src/utils/statusNoticeDefinitions.js +112 -0
  1932. package/dist/src/utils/statusNoticeHelpers.js +15 -0
  1933. package/dist/src/utils/stream.js +73 -0
  1934. package/dist/src/utils/streamJsonStdoutGuard.js +107 -0
  1935. package/dist/src/utils/streamlinedTransform.js +162 -0
  1936. package/dist/src/utils/stringUtils.js +202 -0
  1937. package/dist/src/utils/subprocessEnv.js +87 -0
  1938. package/dist/src/utils/suggestions/commandSuggestions.js +458 -0
  1939. package/dist/src/utils/suggestions/directoryCompletion.js +191 -0
  1940. package/dist/src/utils/suggestions/shellHistoryCompletion.js +95 -0
  1941. package/dist/src/utils/suggestions/skillUsageTracking.js +50 -0
  1942. package/dist/src/utils/suggestions/slackChannelSuggestions.js +169 -0
  1943. package/dist/src/utils/swarm/It2SetupPrompt.js +386 -0
  1944. package/dist/src/utils/swarm/backends/ITermBackend.js +276 -0
  1945. package/dist/src/utils/swarm/backends/InProcessBackend.js +237 -0
  1946. package/dist/src/utils/swarm/backends/PaneBackendExecutor.js +250 -0
  1947. package/dist/src/utils/swarm/backends/TmuxBackend.js +574 -0
  1948. package/dist/src/utils/swarm/backends/detection.js +112 -0
  1949. package/dist/src/utils/swarm/backends/it2Setup.js +185 -0
  1950. package/dist/src/utils/swarm/backends/registry.js +369 -0
  1951. package/dist/src/utils/swarm/backends/teammateModeSnapshot.js +68 -0
  1952. package/dist/src/utils/swarm/backends/types.js +9 -0
  1953. package/dist/src/utils/swarm/constants.js +29 -0
  1954. package/dist/src/utils/swarm/inProcessRunner.js +1021 -0
  1955. package/dist/src/utils/swarm/leaderPermissionBridge.js +31 -0
  1956. package/dist/src/utils/swarm/permissionSync.js +667 -0
  1957. package/dist/src/utils/swarm/reconnection.js +82 -0
  1958. package/dist/src/utils/swarm/spawnInProcess.js +218 -0
  1959. package/dist/src/utils/swarm/spawnUtils.js +123 -0
  1960. package/dist/src/utils/swarm/teamHelpers.js +484 -0
  1961. package/dist/src/utils/swarm/teammateInit.js +87 -0
  1962. package/dist/src/utils/swarm/teammateLayoutManager.js +82 -0
  1963. package/dist/src/utils/swarm/teammateModel.js +9 -0
  1964. package/dist/src/utils/swarm/teammatePromptAddendum.js +17 -0
  1965. package/dist/src/utils/systemDirectories.js +51 -0
  1966. package/dist/src/utils/systemPrompt.js +91 -0
  1967. package/dist/src/utils/systemPromptType.js +9 -0
  1968. package/dist/src/utils/systemTheme.js +108 -0
  1969. package/dist/src/utils/systemThemeWatcher.js +16 -0
  1970. package/dist/src/utils/taggedId.js +49 -0
  1971. package/dist/src/utils/task/TaskOutput.js +320 -0
  1972. package/dist/src/utils/task/diskOutput.js +387 -0
  1973. package/dist/src/utils/task/framework.js +236 -0
  1974. package/dist/src/utils/task/outputFormatting.js +24 -0
  1975. package/dist/src/utils/task/sdkProgress.js +24 -0
  1976. package/dist/src/utils/tasks.js +672 -0
  1977. package/dist/src/utils/teamDiscovery.js +48 -0
  1978. package/dist/src/utils/teamMemoryOps.js +67 -0
  1979. package/dist/src/utils/teammate.js +237 -0
  1980. package/dist/src/utils/teammateContext.js +56 -0
  1981. package/dist/src/utils/teammateMailbox.js +793 -0
  1982. package/dist/src/utils/telemetry/betaSessionTracing.js +371 -0
  1983. package/dist/src/utils/telemetry/bigqueryExporter.js +181 -0
  1984. package/dist/src/utils/telemetry/events.js +57 -0
  1985. package/dist/src/utils/telemetry/instrumentation.js +617 -0
  1986. package/dist/src/utils/telemetry/logger.js +25 -0
  1987. package/dist/src/utils/telemetry/perfettoTracing.js +882 -0
  1988. package/dist/src/utils/telemetry/pluginTelemetry.js +157 -0
  1989. package/dist/src/utils/telemetry/sessionTracing.js +693 -0
  1990. package/dist/src/utils/telemetry/skillLoadedEvent.js +26 -0
  1991. package/dist/src/utils/telemetryAttributes.js +57 -0
  1992. package/dist/src/utils/teleport/api.js +299 -0
  1993. package/dist/src/utils/teleport/environmentSelection.js +55 -0
  1994. package/dist/src/utils/teleport/environments.js +84 -0
  1995. package/dist/src/utils/teleport/gitBundle.js +192 -0
  1996. package/dist/src/utils/teleport.js +1041 -0
  1997. package/dist/src/utils/tempfile.js +26 -0
  1998. package/dist/src/utils/terminal.js +105 -0
  1999. package/dist/src/utils/terminalPanel.js +155 -0
  2000. package/dist/src/utils/textHighlighting.js +113 -0
  2001. package/dist/src/utils/theme.js +525 -0
  2002. package/dist/src/utils/thinking.js +130 -0
  2003. package/dist/src/utils/timeouts.js +35 -0
  2004. package/dist/src/utils/tmuxSocket.js +373 -0
  2005. package/dist/src/utils/todo/types.js +9 -0
  2006. package/dist/src/utils/tokenBudget.js +62 -0
  2007. package/dist/src/utils/tokens.js +223 -0
  2008. package/dist/src/utils/toolErrors.js +101 -0
  2009. package/dist/src/utils/toolPool.js +63 -0
  2010. package/dist/src/utils/toolResultStorage.js +769 -0
  2011. package/dist/src/utils/toolSchemaCache.js +7 -0
  2012. package/dist/src/utils/toolSearch.js +551 -0
  2013. package/dist/src/utils/transcriptSearch.js +200 -0
  2014. package/dist/src/utils/treeify.js +111 -0
  2015. package/dist/src/utils/truncate.js +164 -0
  2016. package/dist/src/utils/udsClient.js +16 -0
  2017. package/dist/src/utils/udsMessaging.js +16 -0
  2018. package/dist/src/utils/ultraplan/ccrSession.js +264 -0
  2019. package/dist/src/utils/ultraplan/keyword.js +122 -0
  2020. package/dist/src/utils/ultraplan/prompt.txt +1 -0
  2021. package/dist/src/utils/unaryLogging.js +16 -0
  2022. package/dist/src/utils/undercover.js +89 -0
  2023. package/dist/src/utils/user.js +138 -0
  2024. package/dist/src/utils/userAgent.js +13 -0
  2025. package/dist/src/utils/userPromptKeywords.js +21 -0
  2026. package/dist/src/utils/uuid.js +22 -0
  2027. package/dist/src/utils/warningHandler.js +97 -0
  2028. package/dist/src/utils/which.js +75 -0
  2029. package/dist/src/utils/windowsPaths.js +150 -0
  2030. package/dist/src/utils/withResolvers.js +13 -0
  2031. package/dist/src/utils/words.js +793 -0
  2032. package/dist/src/utils/workloadContext.js +42 -0
  2033. package/dist/src/utils/worktree.js +1145 -0
  2034. package/dist/src/utils/worktreeModeEnabled.js +11 -0
  2035. package/dist/src/utils/xdg.js +52 -0
  2036. package/dist/src/utils/xml.js +15 -0
  2037. package/dist/src/utils/yaml.js +16 -0
  2038. package/dist/src/utils/zodToJsonSchema.js +19 -0
  2039. package/dist/src/vim/motions.js +73 -0
  2040. package/dist/src/vim/operators.js +401 -0
  2041. package/dist/src/vim/textObjects.js +153 -0
  2042. package/dist/src/vim/transitions.js +340 -0
  2043. package/dist/src/vim/types.js +93 -0
  2044. package/dist/src/voice/voiceModeEnabled.js +48 -0
  2045. package/dist/src/whatsapp/bridge.js +267 -0
  2046. package/dist/src/whatsapp/config.js +153 -0
  2047. package/dist/src/whatsapp/markdown.js +37 -0
  2048. package/dist/src/whatsapp/mirror.js +74 -0
  2049. package/dist/src/whatsapp/session.js +142 -0
  2050. package/package.json +2 -1
@@ -0,0 +1,2590 @@
1
+ /**
2
+ * AST-based bash command analysis using tree-sitter.
3
+ *
4
+ * This module replaces the shell-quote + hand-rolled char-walker approach in
5
+ * bashSecurity.ts / commands.ts. Instead of detecting parser differentials
6
+ * one-by-one, we parse with tree-sitter-bash and walk the tree with an
7
+ * EXPLICIT allowlist of node types. Any node type not in the allowlist causes
8
+ * the entire command to be classified as 'too-complex', which means it goes
9
+ * through the normal permission prompt flow.
10
+ *
11
+ * The key design property is FAIL-CLOSED: we never interpret structure we
12
+ * don't understand. If tree-sitter produces a node we haven't explicitly
13
+ * allowlisted, we refuse to extract argv and the caller must ask the user.
14
+ *
15
+ * This is NOT a sandbox. It does not prevent dangerous commands from running.
16
+ * It answers exactly one question: "Can we produce a trustworthy argv[] for
17
+ * each simple command in this string?" If yes, downstream code can match
18
+ * argv[0] against permission rules and flag allowlists. If no, ask the user.
19
+ */
20
+ import { SHELL_KEYWORDS } from './bashParser.js';
21
+ import { PARSE_ABORTED, parseCommandRaw } from './parser.js';
22
+ /**
23
+ * Structural node types that represent composition of commands. We recurse
24
+ * through these to find the leaf `command` nodes. `program` is the root;
25
+ * `list` is `a && b || c`; `pipeline` is `a | b`; `redirected_statement`
26
+ * wraps a command with its redirects. Semicolon-separated commands appear
27
+ * as direct siblings under `program` (no wrapper node).
28
+ */
29
+ const STRUCTURAL_TYPES = new Set([
30
+ 'program',
31
+ 'list',
32
+ 'pipeline',
33
+ 'redirected_statement',
34
+ ]);
35
+ /**
36
+ * Operator tokens that separate commands. These are leaf nodes that appear
37
+ * between commands in `list`/`pipeline`/`program` and carry no payload.
38
+ */
39
+ const SEPARATOR_TYPES = new Set(['&&', '||', '|', ';', '&', '|&', '\n']);
40
+ /**
41
+ * Placeholder string used in outer argv when a $() is recursively extracted.
42
+ * The actual $() output is runtime-determined; the inner command(s) are
43
+ * checked against permission rules separately. Using a placeholder keeps
44
+ * the outer argv clean (no multi-line heredoc bodies polluting path
45
+ * extraction or triggering newline checks).
46
+ */
47
+ const CMDSUB_PLACEHOLDER = '__CMDSUB_OUTPUT__';
48
+ /**
49
+ * Placeholder for simple_expansion ($VAR) references to variables set earlier
50
+ * in the same command via variable_assignment. Since we tracked the assignment,
51
+ * we know the var exists and its value is either a static string or
52
+ * __CMDSUB_OUTPUT__ (if set via $()). Either way, safe to substitute.
53
+ */
54
+ const VAR_PLACEHOLDER = '__TRACKED_VAR__';
55
+ /**
56
+ * All placeholder strings. Used for defense-in-depth: if a varScope value
57
+ * contains ANY placeholder (exact or embedded), the value is NOT a pure
58
+ * literal and cannot be trusted as a bare argument. Covers composites like
59
+ * `VAR="prefix$(cmd)"` → `"prefix__CMDSUB_OUTPUT__"` — the substring check
60
+ * catches these where exact-match Set.has() would miss.
61
+ *
62
+ * Also catches user-typed literals that collide with placeholder strings:
63
+ * `VAR=__TRACKED_VAR__ && rm $VAR` — treated as non-literal (conservative).
64
+ */
65
+ function containsAnyPlaceholder(value) {
66
+ return value.includes(CMDSUB_PLACEHOLDER) || value.includes(VAR_PLACEHOLDER);
67
+ }
68
+ /**
69
+ * Unquoted $VAR in bash undergoes word-splitting (on $IFS: space/tab/NL)
70
+ * and pathname expansion (glob matching on * ? [). Our argv stores a
71
+ * single string — but at runtime bash may produce MULTIPLE args, or paths
72
+ * matched by a glob. A value containing these metacharacters cannot be
73
+ * trusted as a bare arg: `VAR="-rf /" && rm $VAR` → bash runs `rm -rf /`
74
+ * (two args) but our argv would have `['rm', '-rf /']` (one arg). Similarly
75
+ * `VAR="/etc/*" && cat $VAR` → bash expands to all /etc files.
76
+ *
77
+ * Inside double-quotes ("$VAR"), neither splitting nor globbing applies —
78
+ * the value IS a single literal argument.
79
+ */
80
+ const BARE_VAR_UNSAFE_RE = /[ \t\n*?[]/;
81
+ // stdbuf flag forms — hoisted from the wrapper-stripping while-loop
82
+ const STDBUF_SHORT_SEP_RE = /^-[ioe]$/;
83
+ const STDBUF_SHORT_FUSED_RE = /^-[ioe]./;
84
+ const STDBUF_LONG_RE = /^--(input|output|error)=/;
85
+ /**
86
+ * Known-safe environment variables that bash sets automatically. Their values
87
+ * are controlled by the shell/OS, not arbitrary user input. Referencing these
88
+ * via $VAR is safe — the expansion is deterministic and doesn't introduce
89
+ * injection risk. Covers `$HOME`, `$PWD`, `$USER`, `$PATH`, `$SHELL`, etc.
90
+ * Intentionally small: only vars that are always set by bash/login and whose
91
+ * values are paths/names (not arbitrary content).
92
+ */
93
+ const SAFE_ENV_VARS = new Set([
94
+ 'HOME', // user's home directory
95
+ 'PWD', // current working directory (bash maintains)
96
+ 'OLDPWD', // previous directory
97
+ 'USER', // current username
98
+ 'LOGNAME', // login name
99
+ 'SHELL', // user's login shell
100
+ 'PATH', // executable search path
101
+ 'HOSTNAME', // machine hostname
102
+ 'UID', // user id
103
+ 'EUID', // effective user id
104
+ 'PPID', // parent process id
105
+ 'RANDOM', // random number (bash builtin)
106
+ 'SECONDS', // seconds since shell start
107
+ 'LINENO', // current line number
108
+ 'TMPDIR', // temp directory
109
+ // Special bash variables — always set, values are shell-controlled:
110
+ 'BASH_VERSION', // bash version string
111
+ 'BASHPID', // current bash process id
112
+ 'SHLVL', // shell nesting level
113
+ 'HISTFILE', // history file path
114
+ 'IFS', // field separator (NOTE: only safe INSIDE strings; as bare arg
115
+ // $IFS is the classic injection primitive and the insideString
116
+ // gate in resolveSimpleExpansion correctly blocks it)
117
+ ]);
118
+ /**
119
+ * Special shell variables ($?, $$, $!, $#, $0-$9). tree-sitter uses
120
+ * `special_variable_name` for these (not `variable_name`). Values are
121
+ * shell-controlled: exit status, PIDs, positional args. Safe to resolve
122
+ * ONLY inside strings (same rationale as SAFE_ENV_VARS — as bare args
123
+ * their value IS the argument and might be a path/flag from $1 etc.).
124
+ *
125
+ * SECURITY: '@' and '*' are NOT in this set. Inside "...", they expand to
126
+ * the positional params — which are EMPTY in a fresh BashTool shell (how we
127
+ * always spawn). Returning VAR_PLACEHOLDER would lie: `git "push$*"` gives
128
+ * argv ['git','push__TRACKED_VAR__'] while bash passes ['git','push']. Deny
129
+ * rule Bash(git push:*) fails on both .text (raw `$*`) AND rebuilt argv
130
+ * (placeholder). With them removed, resolveSimpleExpansion falls through to
131
+ * tooComplex for `$*` / `$@`. `echo "args: $*"` becomes too-complex —
132
+ * acceptable (rare in BashTool usage; `"$@"` even rarer).
133
+ */
134
+ const SPECIAL_VAR_NAMES = new Set([
135
+ '?', // exit status of last command
136
+ '$', // current shell PID
137
+ '!', // last background PID
138
+ '#', // number of positional params
139
+ '0', // script name
140
+ '-', // shell option flags
141
+ ]);
142
+ /**
143
+ * Node types that mean "this command cannot be statically analyzed." These
144
+ * either execute arbitrary code (substitutions, subshells, control flow) or
145
+ * expand to values we can't determine statically (parameter/arithmetic
146
+ * expansion, brace expressions).
147
+ *
148
+ * This set is not exhaustive — it documents KNOWN dangerous types. The real
149
+ * safety property is the allowlist in walkArgument/walkCommand: any type NOT
150
+ * explicitly handled there also triggers too-complex.
151
+ */
152
+ const DANGEROUS_TYPES = new Set([
153
+ 'command_substitution',
154
+ 'process_substitution',
155
+ 'expansion',
156
+ 'simple_expansion',
157
+ 'brace_expression',
158
+ 'subshell',
159
+ 'compound_statement',
160
+ 'for_statement',
161
+ 'while_statement',
162
+ 'until_statement',
163
+ 'if_statement',
164
+ 'case_statement',
165
+ 'function_definition',
166
+ 'test_command',
167
+ 'ansi_c_string',
168
+ 'translated_string',
169
+ 'herestring_redirect',
170
+ 'heredoc_redirect',
171
+ ]);
172
+ /**
173
+ * Numeric IDs for analytics (logEvent doesn't accept strings). Index into
174
+ * DANGEROUS_TYPES. Append new entries at the end to keep IDs stable.
175
+ * 0 = unknown/other, -1 = ERROR (parse failure), -2 = pre-check.
176
+ */
177
+ const DANGEROUS_TYPE_IDS = [...DANGEROUS_TYPES];
178
+ export function nodeTypeId(nodeType) {
179
+ if (!nodeType)
180
+ return -2;
181
+ if (nodeType === 'ERROR')
182
+ return -1;
183
+ const i = DANGEROUS_TYPE_IDS.indexOf(nodeType);
184
+ return i >= 0 ? i + 1 : 0;
185
+ }
186
+ /**
187
+ * Redirect operator tokens → canonical operator. tree-sitter produces these
188
+ * as child nodes of `file_redirect`.
189
+ */
190
+ const REDIRECT_OPS = {
191
+ '>': '>',
192
+ '>>': '>>',
193
+ '<': '<',
194
+ '>&': '>&',
195
+ '<&': '<&',
196
+ '>|': '>|',
197
+ '&>': '&>',
198
+ '&>>': '&>>',
199
+ '<<<': '<<<',
200
+ };
201
+ /**
202
+ * Brace expansion pattern: {a,b} or {a..b}. Must have , or .. inside
203
+ * braces. We deliberately do NOT try to determine whether the opening brace
204
+ * is backslash-escaped: tree-sitter doesn't unescape backslashes, so
205
+ * distinguishing `\{a,b}` (escaped, literal) from `\\{a,b}` (literal
206
+ * backslash + expansion) would require reimplementing bash quote removal.
207
+ * Reject both — the escaped-brace case is rare and trivially rewritten
208
+ * with single quotes.
209
+ */
210
+ const BRACE_EXPANSION_RE = /\{[^{}\s]*(,|\.\.)[^{}\s]*\}/;
211
+ /**
212
+ * Control characters that bash silently drops but confuse static analysis.
213
+ * Includes CR (0x0D): tree-sitter treats CR as a word separator but bash's
214
+ * default IFS does not include CR, so tree-sitter and bash disagree on
215
+ * word boundaries.
216
+ */
217
+ // eslint-disable-next-line no-control-regex
218
+ const CONTROL_CHAR_RE = /[\x00-\x08\x0B-\x1F\x7F]/;
219
+ /**
220
+ * Unicode whitespace beyond ASCII. These render invisibly (or as regular
221
+ * spaces) in terminals so a user reviewing the command can't see them, but
222
+ * bash treats them as literal word characters. Blocks NBSP, zero-width
223
+ * spaces, line/paragraph separators, BOM.
224
+ */
225
+ const UNICODE_WHITESPACE_RE = /[\u00A0\u1680\u2000-\u200B\u2028\u2029\u202F\u205F\u3000\uFEFF]/;
226
+ /**
227
+ * Backslash immediately before whitespace. bash treats `\ ` as a literal
228
+ * space inside the current word, but tree-sitter returns the raw text with
229
+ * the backslash still present. argv[0] from tree-sitter is `cat\ test`
230
+ * while bash runs `cat test` (with a literal space). Rather than
231
+ * reimplement bash's unescaping rules, we reject these — they're rare in
232
+ * practice and trivial to rewrite with quotes.
233
+ *
234
+ * Also matches `\` before newline (line continuation) when adjacent to a
235
+ * non-whitespace char. `tr\<NL>aceroute` — bash joins to `traceroute`, but
236
+ * tree-sitter splits into two words (differential). When `\<NL>` is preceded
237
+ * by whitespace (e.g. `foo && \<NL>bar`), there's no word to join — both
238
+ * parsers agree, so we allow it.
239
+ */
240
+ const BACKSLASH_WHITESPACE_RE = /\\[ \t]|[^ \t\n\\]\\\n/;
241
+ /**
242
+ * Zsh dynamic named directory expansion: ~[name]. In zsh this invokes the
243
+ * zsh_directory_name hook, which can run arbitrary code. bash treats it as
244
+ * a literal tilde followed by a glob character class. Since BashTool runs
245
+ * via the user's default shell (often zsh), reject conservatively.
246
+ */
247
+ const ZSH_TILDE_BRACKET_RE = /~\[/;
248
+ /**
249
+ * Zsh EQUALS expansion: word-initial `=cmd` expands to the absolute path of
250
+ * `cmd` (equivalent to `$(which cmd)`). `=curl evil.com` runs as
251
+ * `/usr/bin/curl evil.com`. tree-sitter parses `=curl` as a literal word, so
252
+ * a `Bash(curl:*)` deny rule matching on base command name won't see `curl`.
253
+ * Only matches word-initial `=` followed by a command-name char — `VAR=val`
254
+ * and `--flag=val` have `=` mid-word and are not expanded by zsh.
255
+ */
256
+ const ZSH_EQUALS_EXPANSION_RE = /(?:^|[\s;&|])=[a-zA-Z_]/;
257
+ /**
258
+ * Brace character combined with quote characters. Constructions like
259
+ * `{a'}',b}` use quoted braces inside brace expansion context to obfuscate
260
+ * the expansion from regex-based detection. In bash, `{a'}',b}` expands to
261
+ * `a} b` (the quoted `}` becomes literal inside the first alternative).
262
+ * These are hard to analyze correctly and have no legitimate use in
263
+ * commands we'd want to auto-allow.
264
+ *
265
+ * This check runs on a version of the command with `{` masked out of
266
+ * single-quoted and double-quoted spans, so JSON payloads like
267
+ * `curl -d '{"k":"v"}'` don't trigger a false positive. Brace expansion
268
+ * cannot occur inside quotes, so a `{` there can never start an obfuscation
269
+ * pattern. The quote characters themselves stay visible so `{a'}',b}` and
270
+ * `{@'{'0},...}` still match via the outer unquoted `{`.
271
+ */
272
+ const BRACE_WITH_QUOTE_RE = /\{[^}]*['"]/;
273
+ /**
274
+ * Mask `{` characters that appear inside single- or double-quoted contexts.
275
+ * Uses a single-pass bash-aware quote-state scanner instead of a regex.
276
+ *
277
+ * A naive regex (`/'[^']*'/g`) mis-detects spans when a `'` appears inside
278
+ * a double-quoted string: for `echo "it's" {a'}',b}`, it matches from the
279
+ * `'` in `it's` across to the `'` in `{a'}`, masking the unquoted `{` and
280
+ * producing a false negative. The scanner tracks actual bash quote state:
281
+ * `'` toggles single-quote only in unquoted context; `"` toggles
282
+ * double-quote only outside single quotes; `\` escapes the next char in
283
+ * unquoted context and escapes `"` / `\\` inside double quotes.
284
+ *
285
+ * Brace expansion is impossible in both quote contexts, so masking `{` in
286
+ * either is safe. Secondary defense: BRACE_EXPANSION_RE in walkArgument.
287
+ */
288
+ function maskBracesInQuotedContexts(cmd) {
289
+ // Fast path: no `{` → nothing to mask. Skips the char-by-char scan for
290
+ // the >90% of commands with no braces (`ls -la`, `git status`, etc).
291
+ if (!cmd.includes('{'))
292
+ return cmd;
293
+ const out = [];
294
+ let inSingle = false;
295
+ let inDouble = false;
296
+ let i = 0;
297
+ while (i < cmd.length) {
298
+ const c = cmd[i];
299
+ if (inSingle) {
300
+ // Bash single quotes: no escapes, `'` always terminates.
301
+ if (c === "'")
302
+ inSingle = false;
303
+ out.push(c === '{' ? ' ' : c);
304
+ i++;
305
+ }
306
+ else if (inDouble) {
307
+ // Bash double quotes: `\` escapes `"` and `\` (also `$`, backtick,
308
+ // newline — but those don't affect quote state so we let them pass).
309
+ if (c === '\\' && (cmd[i + 1] === '"' || cmd[i + 1] === '\\')) {
310
+ out.push(c, cmd[i + 1]);
311
+ i += 2;
312
+ }
313
+ else {
314
+ if (c === '"')
315
+ inDouble = false;
316
+ out.push(c === '{' ? ' ' : c);
317
+ i++;
318
+ }
319
+ }
320
+ else {
321
+ // Unquoted: `\` escapes any next char.
322
+ if (c === '\\' && i + 1 < cmd.length) {
323
+ out.push(c, cmd[i + 1]);
324
+ i += 2;
325
+ }
326
+ else {
327
+ if (c === "'")
328
+ inSingle = true;
329
+ else if (c === '"')
330
+ inDouble = true;
331
+ out.push(c);
332
+ i++;
333
+ }
334
+ }
335
+ }
336
+ return out.join('');
337
+ }
338
+ const DOLLAR = String.fromCharCode(0x24);
339
+ /**
340
+ * Parse a bash command string and extract a flat list of simple commands.
341
+ * Returns 'too-complex' if the command uses any shell feature we can't
342
+ * statically analyze. Returns 'parse-unavailable' if tree-sitter WASM isn't
343
+ * loaded — caller should fall back to conservative behavior.
344
+ */
345
+ export async function parseForSecurity(cmd) {
346
+ // parseCommandRaw('') returns null (falsy check), so short-circuit here.
347
+ // Don't use .trim() — it strips Unicode whitespace (\u00a0 etc.) which the
348
+ // pre-checks in parseForSecurityFromAst need to see and reject.
349
+ if (cmd === '')
350
+ return { kind: 'simple', commands: [] };
351
+ const root = await parseCommandRaw(cmd);
352
+ return root === null
353
+ ? { kind: 'parse-unavailable' }
354
+ : parseForSecurityFromAst(cmd, root);
355
+ }
356
+ /**
357
+ * Same as parseForSecurity but takes a pre-parsed AST root so callers that
358
+ * need the tree for other purposes can parse once and share. Pre-checks
359
+ * still run on `cmd` — they catch tree-sitter/bash differentials that a
360
+ * successful parse doesn't.
361
+ */
362
+ export function parseForSecurityFromAst(cmd, root) {
363
+ // Pre-checks: characters that cause tree-sitter and bash to disagree on
364
+ // word boundaries. These run before tree-sitter because they're the known
365
+ // tree-sitter/bash differentials. Everything after this point trusts
366
+ // tree-sitter's tokenization.
367
+ if (CONTROL_CHAR_RE.test(cmd)) {
368
+ return { kind: 'too-complex', reason: 'Contains control characters' };
369
+ }
370
+ if (UNICODE_WHITESPACE_RE.test(cmd)) {
371
+ return { kind: 'too-complex', reason: 'Contains Unicode whitespace' };
372
+ }
373
+ if (BACKSLASH_WHITESPACE_RE.test(cmd)) {
374
+ return {
375
+ kind: 'too-complex',
376
+ reason: 'Contains backslash-escaped whitespace',
377
+ };
378
+ }
379
+ if (ZSH_TILDE_BRACKET_RE.test(cmd)) {
380
+ return {
381
+ kind: 'too-complex',
382
+ reason: 'Contains zsh ~[ dynamic directory syntax',
383
+ };
384
+ }
385
+ if (ZSH_EQUALS_EXPANSION_RE.test(cmd)) {
386
+ return {
387
+ kind: 'too-complex',
388
+ reason: 'Contains zsh =cmd equals expansion',
389
+ };
390
+ }
391
+ if (BRACE_WITH_QUOTE_RE.test(maskBracesInQuotedContexts(cmd))) {
392
+ return {
393
+ kind: 'too-complex',
394
+ reason: 'Contains brace with quote character (expansion obfuscation)',
395
+ };
396
+ }
397
+ const trimmed = cmd.trim();
398
+ if (trimmed === '') {
399
+ return { kind: 'simple', commands: [] };
400
+ }
401
+ if (root === PARSE_ABORTED) {
402
+ // SECURITY: module loaded but parse aborted (timeout / node budget /
403
+ // panic). Adversarially triggerable — `(( a[0][0]... ))` with ~2800
404
+ // subscripts hits PARSE_TIMEOUT_MICROS under the 10K length limit.
405
+ // Previously indistinguishable from module-not-loaded → routed to
406
+ // legacy (parse-unavailable), which lacks EVAL_LIKE_BUILTINS — `trap`,
407
+ // `enable`, `hash` leaked with Bash(*). Fail closed: too-complex → ask.
408
+ return {
409
+ kind: 'too-complex',
410
+ reason: 'Parser aborted (timeout or resource limit) — possible adversarial input',
411
+ nodeType: 'PARSE_ABORT',
412
+ };
413
+ }
414
+ return walkProgram(root);
415
+ }
416
+ function walkProgram(root) {
417
+ // ERROR-node check folded into collectCommands — any unhandled node type
418
+ // (including ERROR) falls through to tooComplex() in the default branch.
419
+ // Avoids a separate full-tree walk for error detection.
420
+ const commands = [];
421
+ // Track variables assigned earlier in the same command. When a
422
+ // simple_expansion ($VAR) references a tracked var, we can substitute
423
+ // a placeholder instead of returning too-complex. Enables patterns like
424
+ // `NOW=$(date) && jq --arg now "$NOW" ...` — $NOW is known to be the
425
+ // $(date) output (already extracted as inner command).
426
+ const varScope = new Map();
427
+ const err = collectCommands(root, commands, varScope);
428
+ if (err)
429
+ return err;
430
+ return { kind: 'simple', commands };
431
+ }
432
+ /**
433
+ * Recursively collect leaf `command` nodes from a structural wrapper node.
434
+ * Returns an error result on any disallowed node type, or null on success.
435
+ */
436
+ function collectCommands(node, commands, varScope) {
437
+ if (node.type === 'command') {
438
+ // Pass `commands` as the innerCommands accumulator — any $() extracted
439
+ // during walkCommand gets appended alongside the outer command.
440
+ const result = walkCommand(node, [], commands, varScope);
441
+ if (result.kind !== 'simple')
442
+ return result;
443
+ commands.push(...result.commands);
444
+ return null;
445
+ }
446
+ if (node.type === 'redirected_statement') {
447
+ return walkRedirectedStatement(node, commands, varScope);
448
+ }
449
+ if (node.type === 'comment') {
450
+ return null;
451
+ }
452
+ if (STRUCTURAL_TYPES.has(node.type)) {
453
+ // SECURITY: `||`, `|`, `|&`, `&` must NOT carry varScope linearly. In bash:
454
+ // `||` RHS runs conditionally → vars set there MAY not be set
455
+ // `|`/`|&` stages run in subshells → vars set there are NEVER visible after
456
+ // `&` LHS runs in a background subshell → same as above
457
+ // Flag-omission attack: `true || FLAG=--dry-run && cmd $FLAG` — bash skips
458
+ // the `||` RHS (FLAG unset → $FLAG empty), runs `cmd` WITHOUT --dry-run.
459
+ // With linear scope, our argv has ['cmd','--dry-run'] → looks SAFE → bypass.
460
+ //
461
+ // Fix: snapshot incoming scope at entry. After these separators, reset to
462
+ // the snapshot — vars set in clauses between separators don't leak. `scope`
463
+ // for clauses BETWEEN `&&`/`;` chains shares state (common `VAR=x && cmd
464
+ // $VAR`). `scope` crosses `||`/`|`/`&` as the pre-structure snapshot only.
465
+ //
466
+ // `&&` and `;` DO carry scope: `VAR=x && cmd $VAR` is sequential, VAR is set.
467
+ //
468
+ // NOTE: `scope` and `varScope` diverge after the first `||`/`|`/`&`. The
469
+ // caller's varScope is only mutated for the `&&`/`;` prefix — this is
470
+ // conservative (vars set in `A && B | C && D` leak A+B into caller, not
471
+ // C+D) but safe.
472
+ //
473
+ // Efficiency: snapshot is only needed if we hit `||`/`|`/`|&`/`&`. For
474
+ // the dominant case (`ls`, `git status` — no such separators), skip the
475
+ // Map alloc via a cheap pre-scan. For `pipeline`, node.type already tells
476
+ // us stages are subshells — copy once at entry, no snapshot needed (each
477
+ // reset uses the entry copy pattern via varScope, which is untouched).
478
+ const isPipeline = node.type === 'pipeline';
479
+ let needsSnapshot = false;
480
+ if (!isPipeline) {
481
+ for (const c of node.children) {
482
+ if (c && (c.type === '||' || c.type === '&')) {
483
+ needsSnapshot = true;
484
+ break;
485
+ }
486
+ }
487
+ }
488
+ const snapshot = needsSnapshot ? new Map(varScope) : null;
489
+ // For `pipeline`, ALL stages run in subshells — start with a copy so
490
+ // nothing mutates caller's scope. For `list`/`program`, the `&&`/`;`
491
+ // chain mutates caller's scope (sequential); fork only on `||`/`&`.
492
+ let scope = isPipeline ? new Map(varScope) : varScope;
493
+ for (const child of node.children) {
494
+ if (!child)
495
+ continue;
496
+ if (SEPARATOR_TYPES.has(child.type)) {
497
+ if (child.type === '||' ||
498
+ child.type === '|' ||
499
+ child.type === '|&' ||
500
+ child.type === '&') {
501
+ // For pipeline: varScope is untouched (we started with a copy).
502
+ // For list/program: snapshot is non-null (pre-scan set it).
503
+ // `|`/`|&` only appear under `pipeline` nodes; `||`/`&` under list.
504
+ scope = new Map(snapshot ?? varScope);
505
+ }
506
+ continue;
507
+ }
508
+ const err = collectCommands(child, commands, scope);
509
+ if (err)
510
+ return err;
511
+ }
512
+ return null;
513
+ }
514
+ if (node.type === 'negated_command') {
515
+ // `! cmd` inverts exit code only — doesn't execute code or affect
516
+ // argv. Recurse into the wrapped command. Common in CI: `! grep err`,
517
+ // `! test -f lock`, `! git diff --quiet`.
518
+ for (const child of node.children) {
519
+ if (!child)
520
+ continue;
521
+ if (child.type === '!')
522
+ continue;
523
+ return collectCommands(child, commands, varScope);
524
+ }
525
+ return null;
526
+ }
527
+ if (node.type === 'declaration_command') {
528
+ // `export`/`local`/`readonly`/`declare`/`typeset`. tree-sitter emits
529
+ // these as declaration_command, not command, so they previously fell
530
+ // through to tooComplex. Values are validated via walkVariableAssignment:
531
+ // `$()` in the value is recursively extracted (inner command pushed to
532
+ // commands[], outer argv gets CMDSUB_PLACEHOLDER); other disallowed
533
+ // expansions still reject via walkArgument. argv[0] is the builtin name so
534
+ // `Bash(export:*)` rules match.
535
+ const argv = [];
536
+ for (const child of node.children) {
537
+ if (!child)
538
+ continue;
539
+ switch (child.type) {
540
+ case 'export':
541
+ case 'local':
542
+ case 'readonly':
543
+ case 'declare':
544
+ case 'typeset':
545
+ argv.push(child.text);
546
+ break;
547
+ case 'word':
548
+ case 'number':
549
+ case 'raw_string':
550
+ case 'string':
551
+ case 'concatenation': {
552
+ // Flags (`declare -r`), quoted names (`export "FOO=bar"`), numbers
553
+ // (`declare -i 42`). Mirrors walkCommand's argv handling — before
554
+ // this, `export "FOO=bar"` hit tooComplex on the `string` child.
555
+ // walkArgument validates each (expansions still reject).
556
+ const arg = walkArgument(child, commands, varScope);
557
+ if (typeof arg !== 'string')
558
+ return arg;
559
+ // SECURITY: declare/typeset/local flags that change assignment
560
+ // semantics break our static model. -n (nameref): `declare -n X=Y`
561
+ // then `$X` dereferences to $Y's VALUE — varScope stores 'Y'
562
+ // (target NAME), argv[0] shows 'Y' while bash runs whatever $Y
563
+ // holds. -i (integer): `declare -i X='a[$(cmd)]'` arithmetically
564
+ // evaluates the RHS at assignment time, running $(cmd) even from
565
+ // a single-quoted raw_string (same primitive walkArithmetic
566
+ // guards in $((…))). -a/-A (array): subscript arithmetic on
567
+ // assignment. -r/-x/-g/-p/-f/-F are inert. Check the resolved
568
+ // arg (not child.text) so `\-n` and quoted `-n` are caught.
569
+ // Scope to declare/typeset/local only: `export -n` means "remove
570
+ // export attribute" (not nameref), and export/readonly don't
571
+ // accept -i; readonly -a/-A rejects subscripted args as invalid
572
+ // identifiers so subscript-arith doesn't fire.
573
+ if ((argv[0] === 'declare' ||
574
+ argv[0] === 'typeset' ||
575
+ argv[0] === 'local') &&
576
+ /^-[a-zA-Z]*[niaA]/.test(arg)) {
577
+ return {
578
+ kind: 'too-complex',
579
+ reason: `declare flag ${arg} changes assignment semantics (nameref/integer/array)`,
580
+ nodeType: 'declaration_command',
581
+ };
582
+ }
583
+ // SECURITY: bare positional assignment with a subscript also
584
+ // evaluates — no -a/-i flag needed. `declare 'x[$(id)]=val'`
585
+ // implicitly creates an array element, arithmetically evaluating
586
+ // the subscript and running $(id). tree-sitter delivers the
587
+ // single-quoted form as a raw_string leaf so walkArgument sees
588
+ // only the literal text. Scoped to declare/typeset/local:
589
+ // export/readonly reject `[` in identifiers before eval.
590
+ if ((argv[0] === 'declare' ||
591
+ argv[0] === 'typeset' ||
592
+ argv[0] === 'local') &&
593
+ arg[0] !== '-' &&
594
+ /^[^=]*\[/.test(arg)) {
595
+ return {
596
+ kind: 'too-complex',
597
+ reason: `declare positional '${arg}' contains array subscript — bash evaluates $(cmd) in subscripts`,
598
+ nodeType: 'declaration_command',
599
+ };
600
+ }
601
+ argv.push(arg);
602
+ break;
603
+ }
604
+ case 'variable_assignment': {
605
+ const ev = walkVariableAssignment(child, commands, varScope);
606
+ if ('kind' in ev)
607
+ return ev;
608
+ // export/declare assignments populate the scope so later $VAR refs resolve.
609
+ applyVarToScope(varScope, ev);
610
+ argv.push(`${ev.name}=${ev.value}`);
611
+ break;
612
+ }
613
+ case 'variable_name':
614
+ // `export FOO` — bare name, no assignment.
615
+ argv.push(child.text);
616
+ break;
617
+ default:
618
+ return tooComplex(child);
619
+ }
620
+ }
621
+ commands.push({ argv, envVars: [], redirects: [], text: node.text });
622
+ return null;
623
+ }
624
+ if (node.type === 'variable_assignment') {
625
+ // Bare `VAR=value` at statement level (not a command env prefix).
626
+ // Sets a shell variable — no code execution, no filesystem I/O.
627
+ // The value is validated via walkVariableAssignment → walkArgument,
628
+ // so `VAR=$(evil)` still recursively extracts/rejects based on the
629
+ // inner command. Does NOT push to commands — a bare assignment needs
630
+ // no permission rule (it's inert). Common pattern: `VAR=x && cmd`
631
+ // where cmd references $VAR. ~35% of too-complex in top-5k ant cmds.
632
+ const ev = walkVariableAssignment(node, commands, varScope);
633
+ if ('kind' in ev)
634
+ return ev;
635
+ // Populate scope so later `$VAR` references resolve.
636
+ applyVarToScope(varScope, ev);
637
+ return null;
638
+ }
639
+ if (node.type === 'for_statement') {
640
+ // `for VAR in WORD...; do BODY; done` — iterate BODY once per word.
641
+ // Body commands extracted once; every iteration runs the same commands.
642
+ //
643
+ // SECURITY: Loop var is ALWAYS treated as unknown-value (VAR_PLACEHOLDER).
644
+ // Even "static" iteration words can be:
645
+ // - Absolute paths: `for i in /etc/passwd; do rm $i; done` — body argv
646
+ // would have placeholder, path validation never sees /etc/passwd.
647
+ // - Globs: `for i in /etc/*; do rm $i; done` — `/etc/*` is a static word
648
+ // at parse time but bash expands it at runtime.
649
+ // - Flags: `for i in -rf /; do rm $i; done` — flag smuggling.
650
+ //
651
+ // VAR_PLACEHOLDER means bare `$i` in body → too-complex. Only
652
+ // string-embedding (`echo "item: $i"`) stays simple. This reverts some
653
+ // of the too-complex→simple rescues in the original PR — each one was a
654
+ // potential path-validation bypass.
655
+ let loopVar = null;
656
+ let doGroup = null;
657
+ for (const child of node.children) {
658
+ if (!child)
659
+ continue;
660
+ if (child.type === 'variable_name') {
661
+ loopVar = child.text;
662
+ }
663
+ else if (child.type === 'do_group') {
664
+ doGroup = child;
665
+ }
666
+ else if (child.type === 'for' ||
667
+ child.type === 'in' ||
668
+ child.type === 'select' ||
669
+ child.type === ';') {
670
+ continue; // structural tokens
671
+ }
672
+ else if (child.type === 'command_substitution') {
673
+ // `for i in $(seq 1 3)` — inner cmd IS extracted and rule-checked.
674
+ const err = collectCommandSubstitution(child, commands, varScope);
675
+ if (err)
676
+ return err;
677
+ }
678
+ else {
679
+ // Iteration values — validated via walkArgument. Value discarded:
680
+ // body argv gets VAR_PLACEHOLDER regardless of the iteration words,
681
+ // and bare `$i` in body → too-complex (see SECURITY comment above).
682
+ // We still validate to reject e.g. `for i in $(cmd); do ...; done`
683
+ // where the iteration word itself is a disallowed expansion.
684
+ const arg = walkArgument(child, commands, varScope);
685
+ if (typeof arg !== 'string')
686
+ return arg;
687
+ }
688
+ }
689
+ if (loopVar === null || doGroup === null)
690
+ return tooComplex(node);
691
+ // SECURITY: `for PS4 in '$(id)'; do set -x; :; done` sets PS4 directly
692
+ // via varScope.set below — walkVariableAssignment's PS4/IFS checks never
693
+ // fire. Trace-time RCE (PS4) or word-split bypass (IFS). No legit use.
694
+ if (loopVar === 'PS4' || loopVar === 'IFS') {
695
+ return {
696
+ kind: 'too-complex',
697
+ reason: `${loopVar} as loop variable bypasses assignment validation`,
698
+ nodeType: 'for_statement',
699
+ };
700
+ }
701
+ // SECURITY: Body uses a scope COPY — vars assigned inside the loop
702
+ // body don't leak to commands after `done`. The loop var itself is
703
+ // set in the REAL scope (bash semantics: $i still set after loop)
704
+ // and copied into the body scope. ALWAYS VAR_PLACEHOLDER — see above.
705
+ varScope.set(loopVar, VAR_PLACEHOLDER);
706
+ const bodyScope = new Map(varScope);
707
+ for (const c of doGroup.children) {
708
+ if (!c)
709
+ continue;
710
+ if (c.type === 'do' || c.type === 'done' || c.type === ';')
711
+ continue;
712
+ const err = collectCommands(c, commands, bodyScope);
713
+ if (err)
714
+ return err;
715
+ }
716
+ return null;
717
+ }
718
+ if (node.type === 'if_statement' || node.type === 'while_statement') {
719
+ // `if COND; then BODY; [elif...; else...;] fi`
720
+ // `while COND; do BODY; done`
721
+ // Extract condition command(s) + all branch/body commands. All get
722
+ // checked against permission rules. `while read VAR` tracks VAR so
723
+ // body can reference $VAR.
724
+ //
725
+ // SECURITY: Branch bodies use scope COPIES — vars assigned inside a
726
+ // conditional branch (which may not execute) must not leak to commands
727
+ // after fi/done. `if false; then T=safe; fi && rm $T` must reject $T.
728
+ // Condition commands use the REAL varScope (they always run for the
729
+ // check, so assignments there are unconditional — e.g., `while read V`
730
+ // tracking must persist to the body copy).
731
+ //
732
+ // tree-sitter if_statement children: if, COND..., then, THEN-BODY...,
733
+ // [elif_clause...], [else_clause], fi. We distinguish condition from
734
+ // then-body by tracking whether we've seen the `then` token.
735
+ let seenThen = false;
736
+ for (const child of node.children) {
737
+ if (!child)
738
+ continue;
739
+ if (child.type === 'if' ||
740
+ child.type === 'fi' ||
741
+ child.type === 'else' ||
742
+ child.type === 'elif' ||
743
+ child.type === 'while' ||
744
+ child.type === 'until' ||
745
+ child.type === ';') {
746
+ continue;
747
+ }
748
+ if (child.type === 'then') {
749
+ seenThen = true;
750
+ continue;
751
+ }
752
+ if (child.type === 'do_group') {
753
+ // while body: recurse with scope COPY (body assignments don't leak
754
+ // past done). The COPY contains any `read VAR` tracking from the
755
+ // condition (already in real varScope at this point).
756
+ const bodyScope = new Map(varScope);
757
+ for (const c of child.children) {
758
+ if (!c)
759
+ continue;
760
+ if (c.type === 'do' || c.type === 'done' || c.type === ';')
761
+ continue;
762
+ const err = collectCommands(c, commands, bodyScope);
763
+ if (err)
764
+ return err;
765
+ }
766
+ continue;
767
+ }
768
+ if (child.type === 'elif_clause' || child.type === 'else_clause') {
769
+ // elif_clause: elif, cond, ;, then, body... / else_clause: else, body...
770
+ // Scope COPY — elif/else branch assignments don't leak past fi.
771
+ const branchScope = new Map(varScope);
772
+ for (const c of child.children) {
773
+ if (!c)
774
+ continue;
775
+ if (c.type === 'elif' ||
776
+ c.type === 'else' ||
777
+ c.type === 'then' ||
778
+ c.type === ';') {
779
+ continue;
780
+ }
781
+ const err = collectCommands(c, commands, branchScope);
782
+ if (err)
783
+ return err;
784
+ }
785
+ continue;
786
+ }
787
+ // Condition (seenThen=false) or then-body (seenThen=true).
788
+ // Condition uses REAL varScope (always runs). Then-body uses a COPY.
789
+ // Special-case `while read VAR`: after condition `read VAR` is
790
+ // collected, track VAR in the REAL scope so the body COPY inherits it.
791
+ const targetScope = seenThen ? new Map(varScope) : varScope;
792
+ const before = commands.length;
793
+ const err = collectCommands(child, commands, targetScope);
794
+ if (err)
795
+ return err;
796
+ // If condition included `read VAR...`, track vars in REAL scope.
797
+ // read var value is UNKNOWN (stdin input) → use VAR_PLACEHOLDER
798
+ // (unknown-value sentinel, string-only).
799
+ if (!seenThen) {
800
+ for (let i = before; i < commands.length; i++) {
801
+ const c = commands[i];
802
+ if (c?.argv[0] === 'read') {
803
+ for (const a of c.argv.slice(1)) {
804
+ // Skip flags (-r, -d, etc.); track bare identifier args as var names.
805
+ if (!a.startsWith('-') && /^[A-Za-z_][A-Za-z0-9_]*$/.test(a)) {
806
+ // SECURITY: commands[] is a flat accumulator. `true || read
807
+ // VAR` in the condition: the list handler correctly uses a
808
+ // scope COPY for the ||-RHS (may not run), but `read VAR`
809
+ // IS still pushed to commands[] — we can't tell it was
810
+ // scope-isolated from here. Same for `echo | read VAR`
811
+ // (pipeline, subshell in bash) and `(read VAR)` (subshell).
812
+ // Overwriting a tracked literal with VAR_PLACEHOLDER hides
813
+ // path traversal: `VAR=../../etc/passwd && if true || read
814
+ // VAR; then cat "/tmp/$VAR"; fi` — parser would see
815
+ // /tmp/__TRACKED_VAR__, bash reads /etc/passwd. Fail closed
816
+ // when a tracked literal would be overwritten. Safe case
817
+ // (no prior value or already a placeholder) → proceed.
818
+ const existing = varScope.get(a);
819
+ if (existing !== undefined &&
820
+ !containsAnyPlaceholder(existing)) {
821
+ return {
822
+ kind: 'too-complex',
823
+ reason: `'read ${a}' in condition may not execute (||/pipeline/subshell); cannot prove it overwrites tracked literal '${existing}'`,
824
+ nodeType: 'if_statement',
825
+ };
826
+ }
827
+ varScope.set(a, VAR_PLACEHOLDER);
828
+ }
829
+ }
830
+ }
831
+ }
832
+ }
833
+ }
834
+ return null;
835
+ }
836
+ if (node.type === 'subshell') {
837
+ // `(cmd1; cmd2)` — run commands in a subshell. Inner commands ARE
838
+ // executed, so extract them for permission checking. Subshell has
839
+ // isolated scope: vars set inside don't leak out. Use a COPY of
840
+ // varScope (outer vars visible, inner changes discarded).
841
+ const innerScope = new Map(varScope);
842
+ for (const child of node.children) {
843
+ if (!child)
844
+ continue;
845
+ if (child.type === '(' || child.type === ')')
846
+ continue;
847
+ const err = collectCommands(child, commands, innerScope);
848
+ if (err)
849
+ return err;
850
+ }
851
+ return null;
852
+ }
853
+ if (node.type === 'test_command') {
854
+ // `[[ EXPR ]]` or `[ EXPR ]` — conditional test. Evaluates to true/false
855
+ // based on file tests (-f, -d), string comparisons (==, !=), etc.
856
+ // No code execution (no command_substitution inside — that would be a
857
+ // child and we'd recurse into it via walkArgument and reject it).
858
+ // Push as a synthetic command with argv[0]='[[' so permission rules
859
+ // can match — `Bash([[ :*)` would be unusual but legal.
860
+ // Walk arguments to validate (no cmdsub/expansion inside operands).
861
+ const argv = ['[['];
862
+ for (const child of node.children) {
863
+ if (!child)
864
+ continue;
865
+ if (child.type === '[[' || child.type === ']]')
866
+ continue;
867
+ if (child.type === '[' || child.type === ']')
868
+ continue;
869
+ // Recurse into test expression structure: unary_expression,
870
+ // binary_expression, parenthesized_expression, negated_expression.
871
+ // The leaves are test_operator (-f, -d, ==) and operand words.
872
+ const err = walkTestExpr(child, argv, commands, varScope);
873
+ if (err)
874
+ return err;
875
+ }
876
+ commands.push({ argv, envVars: [], redirects: [], text: node.text });
877
+ return null;
878
+ }
879
+ if (node.type === 'unset_command') {
880
+ // `unset FOO BAR`, `unset -f func`. Safe: only removes shell
881
+ // variables/functions from the current shell — no code execution, no
882
+ // filesystem I/O. tree-sitter emits a dedicated node type so it
883
+ // previously fell through to tooComplex. Children: `unset` keyword,
884
+ // `variable_name` for each name, `word` for flags like `-f`/`-v`.
885
+ const argv = [];
886
+ for (const child of node.children) {
887
+ if (!child)
888
+ continue;
889
+ switch (child.type) {
890
+ case 'unset':
891
+ argv.push(child.text);
892
+ break;
893
+ case 'variable_name':
894
+ argv.push(child.text);
895
+ // SECURITY: unset removes the var from bash's scope. Remove from
896
+ // varScope so subsequent `$VAR` references correctly reject.
897
+ // `VAR=safe && unset VAR && rm $VAR` must NOT resolve $VAR.
898
+ varScope.delete(child.text);
899
+ break;
900
+ case 'word': {
901
+ const arg = walkArgument(child, commands, varScope);
902
+ if (typeof arg !== 'string')
903
+ return arg;
904
+ argv.push(arg);
905
+ break;
906
+ }
907
+ default:
908
+ return tooComplex(child);
909
+ }
910
+ }
911
+ commands.push({ argv, envVars: [], redirects: [], text: node.text });
912
+ return null;
913
+ }
914
+ return tooComplex(node);
915
+ }
916
+ /**
917
+ * Recursively walk a test_command expression tree (unary/binary/negated/
918
+ * parenthesized expressions). Leaves are test_operator tokens and operands
919
+ * (word/string/number/etc). Operands are validated via walkArgument.
920
+ */
921
+ function walkTestExpr(node, argv, innerCommands, varScope) {
922
+ switch (node.type) {
923
+ case 'unary_expression':
924
+ case 'binary_expression':
925
+ case 'negated_expression':
926
+ case 'parenthesized_expression': {
927
+ for (const c of node.children) {
928
+ if (!c)
929
+ continue;
930
+ const err = walkTestExpr(c, argv, innerCommands, varScope);
931
+ if (err)
932
+ return err;
933
+ }
934
+ return null;
935
+ }
936
+ case 'test_operator':
937
+ case '!':
938
+ case '(':
939
+ case ')':
940
+ case '&&':
941
+ case '||':
942
+ case '==':
943
+ case '=':
944
+ case '!=':
945
+ case '<':
946
+ case '>':
947
+ case '=~':
948
+ argv.push(node.text);
949
+ return null;
950
+ case 'regex':
951
+ case 'extglob_pattern':
952
+ // RHS of =~ or ==/!= in [[ ]]. Pattern text only — no code execution.
953
+ // Parser emits these as leaf nodes with no children (any $(...) or ${...}
954
+ // inside the pattern is a sibling, not a child, and is walked separately).
955
+ argv.push(node.text);
956
+ return null;
957
+ default: {
958
+ // Operand — word, string, number, etc. Validate via walkArgument.
959
+ const arg = walkArgument(node, innerCommands, varScope);
960
+ if (typeof arg !== 'string')
961
+ return arg;
962
+ argv.push(arg);
963
+ return null;
964
+ }
965
+ }
966
+ }
967
+ /**
968
+ * A `redirected_statement` wraps a command (or pipeline) plus one or more
969
+ * `file_redirect`/`heredoc_redirect` nodes. Extract redirects, walk the
970
+ * inner command, attach redirects to the LAST command (the one whose output
971
+ * is being redirected).
972
+ */
973
+ function walkRedirectedStatement(node, commands, varScope) {
974
+ const redirects = [];
975
+ let innerCommand = null;
976
+ for (const child of node.children) {
977
+ if (!child)
978
+ continue;
979
+ if (child.type === 'file_redirect') {
980
+ // Thread `commands` so $() in redirect targets (e.g., `> $(mktemp)`)
981
+ // extracts the inner command for permission checking.
982
+ const r = walkFileRedirect(child, commands, varScope);
983
+ if ('kind' in r)
984
+ return r;
985
+ redirects.push(r);
986
+ }
987
+ else if (child.type === 'heredoc_redirect') {
988
+ const r = walkHeredocRedirect(child);
989
+ if (r)
990
+ return r;
991
+ }
992
+ else if (child.type === 'command' ||
993
+ child.type === 'pipeline' ||
994
+ child.type === 'list' ||
995
+ child.type === 'negated_command' ||
996
+ child.type === 'declaration_command' ||
997
+ child.type === 'unset_command') {
998
+ innerCommand = child;
999
+ }
1000
+ else {
1001
+ return tooComplex(child);
1002
+ }
1003
+ }
1004
+ if (!innerCommand) {
1005
+ // `> file` alone is valid bash (truncates file). Represent as a command
1006
+ // with empty argv so downstream sees the write.
1007
+ commands.push({ argv: [], envVars: [], redirects, text: node.text });
1008
+ return null;
1009
+ }
1010
+ const before = commands.length;
1011
+ const err = collectCommands(innerCommand, commands, varScope);
1012
+ if (err)
1013
+ return err;
1014
+ if (commands.length > before && redirects.length > 0) {
1015
+ const last = commands[commands.length - 1];
1016
+ if (last)
1017
+ last.redirects.push(...redirects);
1018
+ }
1019
+ return null;
1020
+ }
1021
+ /**
1022
+ * Extract operator + target from a `file_redirect` node. The target must be
1023
+ * a static word or string.
1024
+ */
1025
+ function walkFileRedirect(node, innerCommands, varScope) {
1026
+ let op = null;
1027
+ let target = null;
1028
+ let fd;
1029
+ for (const child of node.children) {
1030
+ if (!child)
1031
+ continue;
1032
+ if (child.type === 'file_descriptor') {
1033
+ fd = Number(child.text);
1034
+ }
1035
+ else if (child.type in REDIRECT_OPS) {
1036
+ op = REDIRECT_OPS[child.type] ?? null;
1037
+ }
1038
+ else if (child.type === 'word' || child.type === 'number') {
1039
+ // SECURITY: `number` nodes can contain expansion children via the
1040
+ // `NN#<expansion>` arithmetic-base grammar quirk — same issue as
1041
+ // walkArgument's number case. `> 10#$(cmd)` runs cmd at runtime.
1042
+ // Plain word/number nodes have zero children.
1043
+ if (child.children.length > 0)
1044
+ return tooComplex(child);
1045
+ // Symmetry with walkArgument (~608): `echo foo > {a,b}` is an
1046
+ // ambiguous redirect in bash. tree-sitter actually emits a
1047
+ // `concatenation` node for brace targets (caught by the default
1048
+ // branch below), but check `word` text too for defense-in-depth.
1049
+ if (BRACE_EXPANSION_RE.test(child.text))
1050
+ return tooComplex(child);
1051
+ // Unescape backslash sequences — same as walkArgument. Bash quote
1052
+ // removal turns `\X` → `X`. Without this, `cat < /proc/self/\environ`
1053
+ // stores target `/proc/self/\environ` which evades PROC_ENVIRON_RE,
1054
+ // but bash reads /proc/self/environ.
1055
+ target = child.text.replace(/\\(.)/g, '$1');
1056
+ }
1057
+ else if (child.type === 'raw_string') {
1058
+ target = stripRawString(child.text);
1059
+ }
1060
+ else if (child.type === 'string') {
1061
+ const s = walkString(child, innerCommands, varScope);
1062
+ if (typeof s !== 'string')
1063
+ return s;
1064
+ target = s;
1065
+ }
1066
+ else if (child.type === 'concatenation') {
1067
+ // `echo > "foo"bar` — tree-sitter produces a concatenation of string +
1068
+ // word children. walkArgument already validates concatenation (rejects
1069
+ // expansions, checks brace syntax) and returns the joined text.
1070
+ const s = walkArgument(child, innerCommands, varScope);
1071
+ if (typeof s !== 'string')
1072
+ return s;
1073
+ target = s;
1074
+ }
1075
+ else {
1076
+ return tooComplex(child);
1077
+ }
1078
+ }
1079
+ if (!op || target === null) {
1080
+ return {
1081
+ kind: 'too-complex',
1082
+ reason: 'Unrecognized redirect shape',
1083
+ nodeType: node.type,
1084
+ };
1085
+ }
1086
+ return { op, target, fd };
1087
+ }
1088
+ /**
1089
+ * Heredoc redirect. Only quoted-delimiter heredocs (<<'EOF') are safe —
1090
+ * their bodies are literal text. Unquoted-delimiter heredocs (<<EOF)
1091
+ * undergo full parameter/command/arithmetic expansion in the body.
1092
+ *
1093
+ * SECURITY: tree-sitter-bash has a grammar gap — backticks (`...`) inside
1094
+ * an unquoted heredoc body are NOT parsed as command_substitution nodes
1095
+ * (body.children is empty, backticks are in body.text). But bash DOES
1096
+ * execute them. We cannot safely relax the quoted-delimiter requirement
1097
+ * by checking body children for expansion nodes — we'd miss backtick
1098
+ * substitution. Keep rejecting all unquoted heredocs. Users should use
1099
+ * <<'EOF' to get a literal body, which the model already prefers.
1100
+ */
1101
+ function walkHeredocRedirect(node) {
1102
+ let startText = null;
1103
+ let body = null;
1104
+ for (const child of node.children) {
1105
+ if (!child)
1106
+ continue;
1107
+ if (child.type === 'heredoc_start')
1108
+ startText = child.text;
1109
+ else if (child.type === 'heredoc_body')
1110
+ body = child;
1111
+ else if (child.type === '<<' ||
1112
+ child.type === '<<-' ||
1113
+ child.type === 'heredoc_end' ||
1114
+ child.type === 'file_descriptor') {
1115
+ // expected structural tokens — safe to skip. file_descriptor
1116
+ // covers fd-prefixed heredocs (`cat 3<<'EOF'`) — walkFileRedirect
1117
+ // already treats it as a benign structural token.
1118
+ }
1119
+ else {
1120
+ // SECURITY: tree-sitter places pipeline / command / file_redirect /
1121
+ // && / etc. as children of heredoc_redirect when they follow the
1122
+ // delimiter on the same line (e.g. `ls <<'EOF' | rm x`). Previously
1123
+ // these were silently skipped, hiding the piped command from
1124
+ // permission checks. Fail closed like every other walker.
1125
+ return tooComplex(child);
1126
+ }
1127
+ }
1128
+ const isQuoted = startText !== null &&
1129
+ ((startText.startsWith("'") && startText.endsWith("'")) ||
1130
+ (startText.startsWith('"') && startText.endsWith('"')) ||
1131
+ startText.startsWith('\\'));
1132
+ if (!isQuoted) {
1133
+ return {
1134
+ kind: 'too-complex',
1135
+ reason: 'Heredoc with unquoted delimiter undergoes shell expansion',
1136
+ nodeType: 'heredoc_redirect',
1137
+ };
1138
+ }
1139
+ if (body) {
1140
+ for (const child of body.children) {
1141
+ if (!child)
1142
+ continue;
1143
+ if (child.type !== 'heredoc_content') {
1144
+ return tooComplex(child);
1145
+ }
1146
+ }
1147
+ }
1148
+ return null;
1149
+ }
1150
+ /**
1151
+ * Here-string redirect (`<<< content`). The content becomes stdin — not
1152
+ * argv, not a path. Safe when content is a literal word, raw_string, or
1153
+ * string with no expansions. Reject when content contains $()/${}/$VAR —
1154
+ * those execute arbitrary code or inject runtime values.
1155
+ *
1156
+ * Reuses walkArgument for content validation: it already rejects
1157
+ * command_substitution, expansion, and (for strings) simple_expansion
1158
+ * unless the var is tracked/safe. The result string is discarded — we only
1159
+ * care that it's statically resolvable.
1160
+ *
1161
+ * NOTE: `VAR=$(cmd) && cat <<< "$VAR"` would be safe in principle (inner
1162
+ * cmd is extracted separately, herestring content is stdin) but is
1163
+ * currently rejected conservatively — walkString's solo-placeholder guard
1164
+ * fires because it has no awareness of herestring vs argv context.
1165
+ */
1166
+ function walkHerestringRedirect(node, innerCommands, varScope) {
1167
+ for (const child of node.children) {
1168
+ if (!child)
1169
+ continue;
1170
+ if (child.type === '<<<')
1171
+ continue;
1172
+ // Content node: reuse walkArgument. It returns a string on success
1173
+ // (which we discard — content is stdin, irrelevant to permissions) or
1174
+ // a too-complex result on failure (expansion found, unresolvable var).
1175
+ const content = walkArgument(child, innerCommands, varScope);
1176
+ if (typeof content !== 'string')
1177
+ return content;
1178
+ // Herestring content is discarded (not in argv/envVars/redirects) but
1179
+ // remains in .text via raw node.text. Scan it here so checkSemantics's
1180
+ // NEWLINE_HASH invariant (bashPermissions.ts relies on it) still holds.
1181
+ if (NEWLINE_HASH_RE.test(content))
1182
+ return tooComplex(child);
1183
+ }
1184
+ return null;
1185
+ }
1186
+ /**
1187
+ * Walk a `command` node and extract argv. Children appear in order:
1188
+ * [variable_assignment...] command_name [argument...] [file_redirect...]
1189
+ * Any child type not explicitly handled triggers too-complex.
1190
+ */
1191
+ function walkCommand(node, extraRedirects, innerCommands, varScope) {
1192
+ const argv = [];
1193
+ const envVars = [];
1194
+ const redirects = [...extraRedirects];
1195
+ for (const child of node.children) {
1196
+ if (!child)
1197
+ continue;
1198
+ switch (child.type) {
1199
+ case 'variable_assignment': {
1200
+ const ev = walkVariableAssignment(child, innerCommands, varScope);
1201
+ if ('kind' in ev)
1202
+ return ev;
1203
+ // SECURITY: Env-prefix assignments (`VAR=x cmd`) are command-local in
1204
+ // bash — VAR is only visible to `cmd` as an env var, NOT to
1205
+ // subsequent commands. Do NOT add to global varScope — that would
1206
+ // let `VAR=safe cmd1 && rm $VAR` resolve $VAR when bash has unset it.
1207
+ envVars.push({ name: ev.name, value: ev.value });
1208
+ break;
1209
+ }
1210
+ case 'command_name': {
1211
+ const arg = walkArgument(child.children[0] ?? child, innerCommands, varScope);
1212
+ if (typeof arg !== 'string')
1213
+ return arg;
1214
+ argv.push(arg);
1215
+ break;
1216
+ }
1217
+ case 'word':
1218
+ case 'number':
1219
+ case 'raw_string':
1220
+ case 'string':
1221
+ case 'concatenation':
1222
+ case 'arithmetic_expansion': {
1223
+ const arg = walkArgument(child, innerCommands, varScope);
1224
+ if (typeof arg !== 'string')
1225
+ return arg;
1226
+ argv.push(arg);
1227
+ break;
1228
+ }
1229
+ // NOTE: command_substitution as a BARE argument (not inside a string)
1230
+ // is intentionally NOT handled here — the $() output IS the argument,
1231
+ // and for path-sensitive commands (cd, rm, chmod) the placeholder would
1232
+ // hide the real path from downstream checks. `cd $(echo /etc)` must
1233
+ // stay too-complex so the path-check can't be bypassed. $() inside
1234
+ // strings ("Timer: $(date)") is handled in walkString where the output
1235
+ // is embedded in a longer string (safer).
1236
+ case 'simple_expansion': {
1237
+ // Bare `$VAR` as an argument. Tracked static vars return the ACTUAL
1238
+ // value (e.g. VAR=/etc → '/etc'). Values with IFS/glob chars or
1239
+ // placeholders reject. See resolveSimpleExpansion.
1240
+ const v = resolveSimpleExpansion(child, varScope, false);
1241
+ if (typeof v !== 'string')
1242
+ return v;
1243
+ argv.push(v);
1244
+ break;
1245
+ }
1246
+ case 'file_redirect': {
1247
+ const r = walkFileRedirect(child, innerCommands, varScope);
1248
+ if ('kind' in r)
1249
+ return r;
1250
+ redirects.push(r);
1251
+ break;
1252
+ }
1253
+ case 'herestring_redirect': {
1254
+ // `cmd <<< "content"` — content is stdin, not argv. Validate it's
1255
+ // literal (no expansion); discard the content string.
1256
+ const err = walkHerestringRedirect(child, innerCommands, varScope);
1257
+ if (err)
1258
+ return err;
1259
+ break;
1260
+ }
1261
+ default:
1262
+ return tooComplex(child);
1263
+ }
1264
+ }
1265
+ // .text is the raw source span. Downstream (bashToolCheckPermission →
1266
+ // splitCommand_DEPRECATED) re-tokenizes it via shell-quote. Normally .text
1267
+ // is used unchanged — but if we resolved a $VAR into argv, .text diverges
1268
+ // (has raw `$VAR`) and downstream RULE MATCHING would miss deny rules.
1269
+ //
1270
+ // SECURITY: `SUB=push && git $SUB --force` with `Bash(git push:*)` deny:
1271
+ // argv = ['git', 'push', '--force'] ← correct, path validation sees 'push'
1272
+ // .text = 'git $SUB --force' ← deny rule 'git push:*' doesn't match
1273
+ //
1274
+ // Detection: any `$<identifier>` in node.text means a simple_expansion was
1275
+ // resolved (or we'd have returned too-complex). This catches $VAR at any
1276
+ // position — command_name, word, string interior, concatenation part.
1277
+ // `$(...)` doesn't match (paren, not identifier start). `'$VAR'` in single
1278
+ // quotes: tree-sitter's .text includes the quotes, so a naive check would
1279
+ // FP on `echo '$VAR'`. But single-quoted $ is LITERAL in bash — argv has
1280
+ // the literal `$VAR` string, so rebuilding from argv produces `'$VAR'`
1281
+ // anyway (shell-escape wraps it). Same net .text. No rule-matching error.
1282
+ //
1283
+ // Rebuild .text from argv. Shell-escape each arg: single-quote wrap with
1284
+ // `'\''` for embedded single quotes. Empty string, metacharacters, and
1285
+ // placeholders all get quoted. Downstream shell-quote re-parse is correct.
1286
+ //
1287
+ // NOTE: This does NOT include redirects/envVars in the rebuilt .text —
1288
+ // walkFileRedirect rejects simple_expansion, and envVars aren't used for
1289
+ // rule matching. If either changes, this rebuild must include them.
1290
+ //
1291
+ // SECURITY: also rebuild when node.text contains a newline. Line
1292
+ // continuations `<space>\<LF>` are invisible to argv (tree-sitter collapses
1293
+ // them) but preserved in node.text. `timeout 5 \<LF>curl evil.com` → argv
1294
+ // is correct, but raw .text → stripSafeWrappers matches `timeout 5 ` (the
1295
+ // space before \), leaving `\<LF>curl evil.com` — Bash(curl:*) deny doesn't
1296
+ // prefix-match. Rebuilt .text joins argv with ' ' → no newlines →
1297
+ // stripSafeWrappers works. Also covers heredoc-body leakage.
1298
+ const text = /\$[A-Za-z_]/.test(node.text) || node.text.includes('\n')
1299
+ ? argv
1300
+ .map(a => a === '' || /["'\\ \t\n$`;|&<>(){}*?[\]~#]/.test(a)
1301
+ ? `'${a.replace(/'/g, "'\\''")}'`
1302
+ : a)
1303
+ .join(' ')
1304
+ : node.text;
1305
+ return {
1306
+ kind: 'simple',
1307
+ commands: [{ argv, envVars, redirects, text }],
1308
+ };
1309
+ }
1310
+ /**
1311
+ * Recurse into a command_substitution node's inner command(s). If the inner
1312
+ * command(s) parse cleanly (simple), add them to the innerCommands
1313
+ * accumulator and return null (success). If the inner command is itself
1314
+ * too-complex (e.g., nested arith expansion, process sub), return the error.
1315
+ * This enables recursive permission checking: `echo $(git rev-parse HEAD)`
1316
+ * extracts BOTH `echo $(git rev-parse HEAD)` (outer) AND `git rev-parse HEAD`
1317
+ * (inner) — permission rules must match BOTH for the whole command to allow.
1318
+ */
1319
+ function collectCommandSubstitution(csNode, innerCommands, varScope) {
1320
+ // Vars set BEFORE the $() are visible inside (bash subshell semantics),
1321
+ // but vars set INSIDE don't leak out. Pass a COPY of the outer scope so
1322
+ // inner assignments don't mutate the outer map.
1323
+ const innerScope = new Map(varScope);
1324
+ // command_substitution children: `$(` or `` ` ``, inner statement(s), `)`
1325
+ for (const child of csNode.children) {
1326
+ if (!child)
1327
+ continue;
1328
+ if (child.type === '$(' || child.type === '`' || child.type === ')') {
1329
+ continue;
1330
+ }
1331
+ const err = collectCommands(child, innerCommands, innerScope);
1332
+ if (err)
1333
+ return err;
1334
+ }
1335
+ return null;
1336
+ }
1337
+ /**
1338
+ * Convert an argument node to its literal string value. Quotes are resolved.
1339
+ * This function implements the argument-position allowlist.
1340
+ */
1341
+ function walkArgument(node, innerCommands, varScope) {
1342
+ if (!node) {
1343
+ return { kind: 'too-complex', reason: 'Null argument node' };
1344
+ }
1345
+ switch (node.type) {
1346
+ case 'word': {
1347
+ // Unescape backslash sequences. In unquoted context, bash's quote
1348
+ // removal turns `\X` → `X` for any character X. tree-sitter preserves
1349
+ // the raw text. Required for checkSemantics: `\eval` must match
1350
+ // EVAL_LIKE_BUILTINS, `\zmodload` must match ZSH_DANGEROUS_BUILTINS.
1351
+ // Also makes argv accurate: `find -exec {} \;` → argv has `;` not
1352
+ // `\;`. (Deny-rule matching on .text already worked via downstream
1353
+ // splitCommand_DEPRECATED unescaping — see walkCommand comment.) `\<whitespace>`
1354
+ // is already rejected by BACKSLASH_WHITESPACE_RE.
1355
+ if (BRACE_EXPANSION_RE.test(node.text)) {
1356
+ return {
1357
+ kind: 'too-complex',
1358
+ reason: 'Word contains brace expansion syntax',
1359
+ nodeType: 'word',
1360
+ };
1361
+ }
1362
+ return node.text.replace(/\\(.)/g, '$1');
1363
+ }
1364
+ case 'number':
1365
+ // SECURITY: tree-sitter-bash parses `NN#<expansion>` (arithmetic base
1366
+ // syntax) as a `number` node with the expansion as a CHILD. `10#$(cmd)`
1367
+ // is a number node whose .text is the full literal but whose child is a
1368
+ // command_substitution — bash runs the substitution. .text on a node
1369
+ // with children would smuggle the expansion past permission checks.
1370
+ // Plain numbers (`10`, `16#ff`) have zero children.
1371
+ if (node.children.length > 0) {
1372
+ return {
1373
+ kind: 'too-complex',
1374
+ reason: 'Number node contains expansion (NN# arithmetic base syntax)',
1375
+ nodeType: node.children[0]?.type,
1376
+ };
1377
+ }
1378
+ return node.text;
1379
+ case 'raw_string':
1380
+ return stripRawString(node.text);
1381
+ case 'string':
1382
+ return walkString(node, innerCommands, varScope);
1383
+ case 'concatenation': {
1384
+ if (BRACE_EXPANSION_RE.test(node.text)) {
1385
+ return {
1386
+ kind: 'too-complex',
1387
+ reason: 'Brace expansion',
1388
+ nodeType: 'concatenation',
1389
+ };
1390
+ }
1391
+ let result = '';
1392
+ for (const child of node.children) {
1393
+ if (!child)
1394
+ continue;
1395
+ const part = walkArgument(child, innerCommands, varScope);
1396
+ if (typeof part !== 'string')
1397
+ return part;
1398
+ result += part;
1399
+ }
1400
+ return result;
1401
+ }
1402
+ case 'arithmetic_expansion': {
1403
+ const err = walkArithmetic(node);
1404
+ if (err)
1405
+ return err;
1406
+ return node.text;
1407
+ }
1408
+ case 'simple_expansion': {
1409
+ // `$VAR` inside a concatenation (e.g., `prefix$VAR`). Same rules
1410
+ // as the bare case in walkCommand: must be tracked or SAFE_ENV_VARS.
1411
+ // inside-concatenation counts as bare arg (the whole concat IS the arg)
1412
+ return resolveSimpleExpansion(node, varScope, false);
1413
+ }
1414
+ // NOTE: command_substitution at arg position (bare or inside concatenation)
1415
+ // is intentionally NOT handled — the output is/becomes-part-of a positional
1416
+ // argument which might be a path or flag. `rm $(foo)` or `rm $(foo)bar`
1417
+ // would hide the real path behind the placeholder. Only $() inside a
1418
+ // `string` node (walkString) is extracted, since the output is embedded
1419
+ // in a longer string rather than BEING the argument.
1420
+ default:
1421
+ return tooComplex(node);
1422
+ }
1423
+ }
1424
+ /**
1425
+ * Extract literal content from a double-quoted string node. A `string` node's
1426
+ * children are `"` delimiters, `string_content` literals, and possibly
1427
+ * expansion nodes.
1428
+ *
1429
+ * tree-sitter quirk: literal newlines inside double quotes are NOT included
1430
+ * in `string_content` node text. bash preserves them. For `"a\nb"`,
1431
+ * tree-sitter produces two `string_content` children (`"a"`, `"b"`) with the
1432
+ * newline in neither. For `"\n#"`, it produces ONE child (`"#"`) with the
1433
+ * leading newline eaten. Concatenating children therefore loses newlines.
1434
+ *
1435
+ * Fix: track child `startIndex` and insert one `\n` per index gap. The gap
1436
+ * between children IS the dropped newline(s). This makes the argv value
1437
+ * match what bash actually sees.
1438
+ */
1439
+ function walkString(node, innerCommands, varScope) {
1440
+ let result = '';
1441
+ let cursor = -1;
1442
+ // SECURITY: Track whether the string contains a runtime-unknown
1443
+ // placeholder ($() output or unknown-value tracked var) vs any literal
1444
+ // content. A string that is ONLY a placeholder (`"$(cmd)"`, `"$VAR"`
1445
+ // where VAR holds an unknown sentinel) produces an argv element that IS
1446
+ // the placeholder — which downstream path validation resolves as a
1447
+ // relative filename within cwd, bypassing the check. `cd "$(echo /etc)"`
1448
+ // would pass validation but runtime-cd into /etc. We reject
1449
+ // solo-placeholder strings; placeholders mixed with literal content
1450
+ // (`"prefix: $(cmd)"`) are safe — runtime value can't equal a bare path.
1451
+ let sawDynamicPlaceholder = false;
1452
+ let sawLiteralContent = false;
1453
+ for (const child of node.children) {
1454
+ if (!child)
1455
+ continue;
1456
+ // Index gap between this child and the previous one = dropped newline(s).
1457
+ // Ignore the gap before the first non-delimiter child (cursor === -1).
1458
+ // Skip gap-fill for `"` delimiters: a gap before the closing `"` is the
1459
+ // tree-sitter whitespace-only-string quirk (space/tab, not newline) — let
1460
+ // the Fix C check below catch it as too-complex instead of mis-filling
1461
+ // with `\n` and diverging from bash.
1462
+ if (cursor !== -1 && child.startIndex > cursor && child.type !== '"') {
1463
+ result += '\n'.repeat(child.startIndex - cursor);
1464
+ sawLiteralContent = true;
1465
+ }
1466
+ cursor = child.endIndex;
1467
+ switch (child.type) {
1468
+ case '"':
1469
+ // Reset cursor after opening quote so the gap between `"` and the
1470
+ // first content child is captured.
1471
+ cursor = child.endIndex;
1472
+ break;
1473
+ case 'string_content':
1474
+ // Bash double-quote escape rules (NOT the generic /\\(.)/g used for
1475
+ // unquoted words in walkArgument): inside "...", a backslash only
1476
+ // escapes $ ` " \ — other sequences like \n stay literal. So
1477
+ // `"fix \"bug\""` → `fix "bug"`, but `"a\nb"` → `a\nb` (backslash
1478
+ // kept). tree-sitter preserves the raw escapes in .text; we resolve
1479
+ // them here so argv matches what bash actually passes.
1480
+ result += child.text.replace(/\\([$`"\\])/g, '$1');
1481
+ sawLiteralContent = true;
1482
+ break;
1483
+ case DOLLAR:
1484
+ // A bare dollar sign before closing quote or a non-name char is
1485
+ // literal in bash. tree-sitter emits it as a standalone node.
1486
+ result += DOLLAR;
1487
+ sawLiteralContent = true;
1488
+ break;
1489
+ case 'command_substitution': {
1490
+ // Carve-out: `$(cat <<'EOF' ... EOF)` is safe. The quoted-delimiter
1491
+ // heredoc body is literal (no expansion), and `cat` just prints it.
1492
+ // The substitution result is therefore a known static string. This
1493
+ // pattern is the idiomatic way to pass multi-line content to tools
1494
+ // like `gh pr create --body`. We replace the substitution with a
1495
+ // placeholder argv value — the actual content doesn't matter for
1496
+ // permission checking, only that it IS static.
1497
+ const heredocBody = extractSafeCatHeredoc(child);
1498
+ if (heredocBody === 'DANGEROUS')
1499
+ return tooComplex(child);
1500
+ if (heredocBody !== null) {
1501
+ // SECURITY: the body IS the substitution result. Previously we
1502
+ // dropped it → `rm "$(cat <<'EOF'\n/etc/passwd\nEOF)"` produced
1503
+ // argv ['rm',''] while bash runs `rm /etc/passwd`. validatePath('')
1504
+ // resolves to cwd → allowed. Every path-constrained command
1505
+ // bypassed via this. Now: append the body (trailing LF trimmed —
1506
+ // bash $() strips trailing newlines).
1507
+ //
1508
+ // Tradeoff: bodies with internal newlines are multi-line text
1509
+ // (markdown, scripts) which cannot be valid paths — safe to drop
1510
+ // to avoid NEWLINE_HASH_RE false positives on `## Summary`. A
1511
+ // single-line body (like `/etc/passwd`) MUST go into argv so
1512
+ // downstream path validation sees the real target.
1513
+ const trimmed = heredocBody.replace(/\n+$/, '');
1514
+ if (trimmed.includes('\n')) {
1515
+ sawLiteralContent = true;
1516
+ break;
1517
+ }
1518
+ result += trimmed;
1519
+ sawLiteralContent = true;
1520
+ break;
1521
+ }
1522
+ // General $() inside "...": recurse into inner command(s). If they
1523
+ // parse cleanly, they become additional subcommands that the
1524
+ // permission system must match rules against. The outer argv gets
1525
+ // the original $() text as placeholder (runtime-determined value).
1526
+ // `echo "SHA: $(git rev-parse HEAD)"` → extracts BOTH
1527
+ // `echo "SHA: $(...)"` AND `git rev-parse HEAD` — both must match
1528
+ // permission rules. ~27% of too-complex in top-5k ant cmds.
1529
+ const err = collectCommandSubstitution(child, innerCommands, varScope);
1530
+ if (err)
1531
+ return err;
1532
+ result += CMDSUB_PLACEHOLDER;
1533
+ sawDynamicPlaceholder = true;
1534
+ break;
1535
+ }
1536
+ case 'simple_expansion': {
1537
+ // `$VAR` inside "...". Tracked/safe vars resolve; untracked reject.
1538
+ const v = resolveSimpleExpansion(child, varScope, true);
1539
+ if (typeof v !== 'string')
1540
+ return v;
1541
+ // VAR_PLACEHOLDER = runtime-unknown (loop var, read var, $() output,
1542
+ // SAFE_ENV_VARS, special vars). Any other string = actual literal
1543
+ // value from a tracked static var (e.g. VAR=/tmp → v='/tmp').
1544
+ if (v === VAR_PLACEHOLDER)
1545
+ sawDynamicPlaceholder = true;
1546
+ else
1547
+ sawLiteralContent = true;
1548
+ result += v;
1549
+ break;
1550
+ }
1551
+ case 'arithmetic_expansion': {
1552
+ const err = walkArithmetic(child);
1553
+ if (err)
1554
+ return err;
1555
+ result += child.text;
1556
+ // Validated to be literal-numeric — static content.
1557
+ sawLiteralContent = true;
1558
+ break;
1559
+ }
1560
+ default:
1561
+ // expansion (${...}) inside "..."
1562
+ return tooComplex(child);
1563
+ }
1564
+ }
1565
+ // SECURITY: Reject solo-placeholder strings. `"$(cmd)"` or `"$VAR"` (where
1566
+ // VAR holds an unknown value) would produce an argv element that IS the
1567
+ // placeholder — which bypasses downstream path validation (validatePath
1568
+ // resolves placeholders as relative filenames within cwd). Only allow
1569
+ // placeholders embedded alongside literal content (`"prefix: $(cmd)"`).
1570
+ if (sawDynamicPlaceholder && !sawLiteralContent) {
1571
+ return tooComplex(node);
1572
+ }
1573
+ // SECURITY: tree-sitter-bash quirk — a double-quoted string containing
1574
+ // ONLY whitespace (` "`, `" "`, `"\t"`) produces NO string_content child;
1575
+ // the whitespace is attributed to the closing `"` node's text. Our loop
1576
+ // only adds to `result` from string_content/expansion children, so we'd
1577
+ // return "" when bash sees " ". Detect: we saw no content children
1578
+ // (both flags false — neither literal nor placeholder added) but the
1579
+ // source span is longer than bare `""`. Genuine `""` has text.length==2.
1580
+ // `"$V"` with V="" doesn't hit this — the simple_expansion child sets
1581
+ // sawLiteralContent via the `else` branch even when v is empty.
1582
+ if (!sawLiteralContent && !sawDynamicPlaceholder && node.text.length > 2) {
1583
+ return tooComplex(node);
1584
+ }
1585
+ return result;
1586
+ }
1587
+ /**
1588
+ * Safe leaf nodes inside arithmetic expansion: integer literals (decimal,
1589
+ * hex, octal, bash base#digits) and operator/paren tokens. Anything else at
1590
+ * leaf position (notably variable_name that isn't a numeric literal) rejects.
1591
+ */
1592
+ const ARITH_LEAF_RE = /^(?:[0-9]+|0[xX][0-9a-fA-F]+|[0-9]+#[0-9a-zA-Z]+|[-+*/%^&|~!<>=?:(),]+|<<|>>|\*\*|&&|\|\||[<>=!]=|\$\(\(|\)\))$/;
1593
+ /**
1594
+ * Recursively validate an arithmetic_expansion node. Allows only literal
1595
+ * numeric expressions — no variables, no substitutions. Returns null if
1596
+ * safe, or a too-complex result if not.
1597
+ *
1598
+ * Variables are rejected because bash arithmetic recursively evaluates
1599
+ * variable values: if x='a[$(cmd)]' then $((x)) executes cmd. See
1600
+ * https://www.vidarholen.net/contents/blog/?p=716 (arithmetic injection).
1601
+ *
1602
+ * When safe, the caller puts the full `$((…))` span into argv as a literal
1603
+ * string. bash will expand it to an integer at runtime; the static string
1604
+ * won't match any sensitive path/deny patterns.
1605
+ */
1606
+ function walkArithmetic(node) {
1607
+ for (const child of node.children) {
1608
+ if (!child)
1609
+ continue;
1610
+ if (child.children.length === 0) {
1611
+ if (!ARITH_LEAF_RE.test(child.text)) {
1612
+ return {
1613
+ kind: 'too-complex',
1614
+ reason: `Arithmetic expansion references variable or non-literal: ${child.text}`,
1615
+ nodeType: 'arithmetic_expansion',
1616
+ };
1617
+ }
1618
+ continue;
1619
+ }
1620
+ switch (child.type) {
1621
+ case 'binary_expression':
1622
+ case 'unary_expression':
1623
+ case 'ternary_expression':
1624
+ case 'parenthesized_expression': {
1625
+ const err = walkArithmetic(child);
1626
+ if (err)
1627
+ return err;
1628
+ break;
1629
+ }
1630
+ default:
1631
+ return tooComplex(child);
1632
+ }
1633
+ }
1634
+ return null;
1635
+ }
1636
+ /**
1637
+ * Check if a command_substitution node is exactly `$(cat <<'DELIM'...DELIM)`
1638
+ * and return the heredoc body if so. Any deviation (extra args to cat,
1639
+ * unquoted delimiter, additional commands) returns null.
1640
+ *
1641
+ * tree-sitter structure:
1642
+ * command_substitution
1643
+ * $(
1644
+ * redirected_statement
1645
+ * command → command_name → word "cat" (exactly one child)
1646
+ * heredoc_redirect
1647
+ * <<
1648
+ * heredoc_start 'DELIM' (quoted)
1649
+ * heredoc_body (pure heredoc_content)
1650
+ * heredoc_end
1651
+ * )
1652
+ */
1653
+ function extractSafeCatHeredoc(subNode) {
1654
+ // Expect exactly: $( + one redirected_statement + )
1655
+ let stmt = null;
1656
+ for (const child of subNode.children) {
1657
+ if (!child)
1658
+ continue;
1659
+ if (child.type === '$(' || child.type === ')')
1660
+ continue;
1661
+ if (child.type === 'redirected_statement' && stmt === null) {
1662
+ stmt = child;
1663
+ }
1664
+ else {
1665
+ return null;
1666
+ }
1667
+ }
1668
+ if (!stmt)
1669
+ return null;
1670
+ // redirected_statement must be: command(cat) + heredoc_redirect (quoted)
1671
+ let sawCat = false;
1672
+ let body = null;
1673
+ for (const child of stmt.children) {
1674
+ if (!child)
1675
+ continue;
1676
+ if (child.type === 'command') {
1677
+ // Must be bare `cat` — no args, no env vars
1678
+ const cmdChildren = child.children.filter(c => c);
1679
+ if (cmdChildren.length !== 1)
1680
+ return null;
1681
+ const nameNode = cmdChildren[0];
1682
+ if (nameNode?.type !== 'command_name' || nameNode.text !== 'cat') {
1683
+ return null;
1684
+ }
1685
+ sawCat = true;
1686
+ }
1687
+ else if (child.type === 'heredoc_redirect') {
1688
+ // Reuse the existing validator: quoted delimiter, body is pure text.
1689
+ // walkHeredocRedirect returns null on success, non-null on rejection.
1690
+ if (walkHeredocRedirect(child) !== null)
1691
+ return null;
1692
+ for (const hc of child.children) {
1693
+ if (hc?.type === 'heredoc_body')
1694
+ body = hc.text;
1695
+ }
1696
+ }
1697
+ else {
1698
+ return null;
1699
+ }
1700
+ }
1701
+ if (!sawCat || body === null)
1702
+ return null;
1703
+ // SECURITY: the heredoc body becomes the outer command's argv value via
1704
+ // substitution, so a body like `/proc/self/environ` is semantically
1705
+ // `cat /proc/self/environ`. checkSemantics never sees the body (we drop it
1706
+ // at the walkString call site to avoid newline+# FPs). Returning `null`
1707
+ // here would fall through to collectCommandSubstitution in walkString,
1708
+ // which would extract the inner `cat` via walkHeredocRedirect (body text
1709
+ // not inspected there) — effectively bypassing this check. Return a
1710
+ // distinct sentinel so the caller can reject instead of falling through.
1711
+ if (PROC_ENVIRON_RE.test(body))
1712
+ return 'DANGEROUS';
1713
+ // Same for jq system(): checkSemantics checks argv but never sees the
1714
+ // heredoc body. Check unconditionally (we don't know the outer command).
1715
+ if (/\bsystem\s*\(/.test(body))
1716
+ return 'DANGEROUS';
1717
+ return body;
1718
+ }
1719
+ function walkVariableAssignment(node, innerCommands, varScope) {
1720
+ let name = null;
1721
+ let value = '';
1722
+ let isAppend = false;
1723
+ for (const child of node.children) {
1724
+ if (!child)
1725
+ continue;
1726
+ if (child.type === 'variable_name') {
1727
+ name = child.text;
1728
+ }
1729
+ else if (child.type === '=' || child.type === '+=') {
1730
+ // `PATH+=":/new"` — tree-sitter emits `+=` as a distinct operator
1731
+ // node. Without this case it falls through to walkArgument below
1732
+ // → tooComplex on unknown type `+=`.
1733
+ isAppend = child.type === '+=';
1734
+ continue;
1735
+ }
1736
+ else if (child.type === 'command_substitution') {
1737
+ // $() as the variable's value. The output becomes a STRING stored in
1738
+ // the variable — it's NOT a positional argument (no path/flag concern).
1739
+ // `VAR=$(date)` runs `date`, stores output. `VAR=$(rm -rf /)` runs
1740
+ // `rm` — the inner command IS checked against permission rules, so
1741
+ // `rm` must match a rule. The variable just holds whatever `rm` prints.
1742
+ const err = collectCommandSubstitution(child, innerCommands, varScope);
1743
+ if (err)
1744
+ return err;
1745
+ value = CMDSUB_PLACEHOLDER;
1746
+ }
1747
+ else if (child.type === 'simple_expansion') {
1748
+ // `VAR=$OTHER` — assignment RHS does NOT word-split or glob-expand
1749
+ // in bash (unlike command arguments). So `A="a b"; B=$A` sets B to
1750
+ // the literal "a b". Resolve as if inside a string (insideString=true)
1751
+ // so BARE_VAR_UNSAFE_RE doesn't over-reject. The resulting value may
1752
+ // contain spaces/globs — if B is later used as a bare arg, THAT use
1753
+ // will correctly reject via BARE_VAR_UNSAFE_RE.
1754
+ const v = resolveSimpleExpansion(child, varScope, true);
1755
+ if (typeof v !== 'string')
1756
+ return v;
1757
+ // If v is VAR_PLACEHOLDER (OTHER holds unknown), store it — combined
1758
+ // with containsAnyPlaceholder in the caller to treat as unknown.
1759
+ value = v;
1760
+ }
1761
+ else {
1762
+ const v = walkArgument(child, innerCommands, varScope);
1763
+ if (typeof v !== 'string')
1764
+ return v;
1765
+ value = v;
1766
+ }
1767
+ }
1768
+ if (name === null) {
1769
+ return {
1770
+ kind: 'too-complex',
1771
+ reason: 'Variable assignment without name',
1772
+ nodeType: 'variable_assignment',
1773
+ };
1774
+ }
1775
+ // SECURITY: tree-sitter-bash accepts invalid var names (e.g. `1VAR=value`)
1776
+ // as variable_assignment. Bash only recognizes [A-Za-z_][A-Za-z0-9_]* —
1777
+ // anything else is run as a COMMAND. `1VAR=value` → bash tries to execute
1778
+ // `1VAR=value` from PATH. We must not treat it as an inert assignment.
1779
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {
1780
+ return {
1781
+ kind: 'too-complex',
1782
+ reason: `Invalid variable name (bash treats as command): ${name}`,
1783
+ nodeType: 'variable_assignment',
1784
+ };
1785
+ }
1786
+ // SECURITY: Setting IFS changes word-splitting behavior for subsequent
1787
+ // unquoted $VAR expansions. `IFS=: && VAR=a:b && rm $VAR` → bash splits
1788
+ // on `:` → `rm a b`. Our BARE_VAR_UNSAFE_RE only checks default IFS
1789
+ // chars (space/tab/NL) — we can't model custom IFS. Reject.
1790
+ if (name === 'IFS') {
1791
+ return {
1792
+ kind: 'too-complex',
1793
+ reason: 'IFS assignment changes word-splitting — cannot model statically',
1794
+ nodeType: 'variable_assignment',
1795
+ };
1796
+ }
1797
+ // SECURITY: PS4 is expanded via promptvars (default on) on every command
1798
+ // traced after `set -x`. A raw_string value containing $(cmd) or `cmd`
1799
+ // executes at trace time: `PS4='$(id)' && set -x && :` runs id, but our
1800
+ // argv is only [["set","-x"],[":"]] — the payload is invisible to
1801
+ // permission checks. PS0-3 and PROMPT_COMMAND are not expanded in
1802
+ // non-interactive shells (BashTool).
1803
+ //
1804
+ // ALLOWLIST, not blocklist. 5 rounds of bypass patches taught us that a
1805
+ // value-dependent blocklist is structurally fragile:
1806
+ // - `+=` effective-value computation diverges from bash in multiple
1807
+ // scope-model gaps: `||` reset, env-prefix chain (PS4='' && PS4='$'
1808
+ // PS4+='(id)' cmd reads stale parent value), subshell.
1809
+ // - bash's decode_prompt_string runs BEFORE promptvars, so `\044(id)`
1810
+ // (octal for `$`) becomes `$(id)` at trace time — any literal-char
1811
+ // check must model prompt-escape decoding exactly.
1812
+ // - assignment paths exist outside walkVariableAssignment (for_statement
1813
+ // sets loopVar directly, see that handler's PS4 check).
1814
+ //
1815
+ // Policy: (1) reject += outright — no scope-tracking dependency; user can
1816
+ // combine into one PS4=... (2) reject placeholders — runtime unknowable.
1817
+ // (3) allowlist remaining value: ${identifier} refs (value-read only, safe)
1818
+ // plus [A-Za-z0-9 _+:.\/=[\]-]. No bare `$` (blocks split primitive), no
1819
+ // `\` (blocks octal \044/\140), no backtick, no parens. Covers all known
1820
+ // encoding vectors and future ones — anything off the allowlist fails.
1821
+ // Legit `PS4='+${BASH_SOURCE}:${LINENO}: '` still passes.
1822
+ if (name === 'PS4') {
1823
+ if (isAppend) {
1824
+ return {
1825
+ kind: 'too-complex',
1826
+ reason: 'PS4 += cannot be statically verified — combine into a single PS4= assignment',
1827
+ nodeType: 'variable_assignment',
1828
+ };
1829
+ }
1830
+ if (containsAnyPlaceholder(value)) {
1831
+ return {
1832
+ kind: 'too-complex',
1833
+ reason: 'PS4 value derived from cmdsub/variable — runtime unknowable',
1834
+ nodeType: 'variable_assignment',
1835
+ };
1836
+ }
1837
+ if (!/^[A-Za-z0-9 _+:./=[\]-]*$/.test(value.replace(/\$\{[A-Za-z_][A-Za-z0-9_]*\}/g, ''))) {
1838
+ return {
1839
+ kind: 'too-complex',
1840
+ reason: 'PS4 value outside safe charset — only ${VAR} refs and [A-Za-z0-9 _+:.=/[]-] allowed',
1841
+ nodeType: 'variable_assignment',
1842
+ };
1843
+ }
1844
+ }
1845
+ // SECURITY: Tilde expansion in assignment RHS. `VAR=~/x` (unquoted) →
1846
+ // bash expands `~` at ASSIGNMENT time → VAR='/home/user/x'. We see the
1847
+ // literal `~/x`. Later `cd $VAR` → our argv `['cd','~/x']`, bash runs
1848
+ // `cd /home/user/x`. Tilde expansion also happens after `=` and `:` in
1849
+ // assignment values (e.g. PATH=~/bin:~/sbin). We can't model it — reject
1850
+ // any value containing `~` that isn't already quoted-literal (where bash
1851
+ // doesn't expand). Conservative: any `~` in value → reject.
1852
+ if (value.includes('~')) {
1853
+ return {
1854
+ kind: 'too-complex',
1855
+ reason: 'Tilde in assignment value — bash may expand at assignment time',
1856
+ nodeType: 'variable_assignment',
1857
+ };
1858
+ }
1859
+ return { name, value, isAppend };
1860
+ }
1861
+ /**
1862
+ * Resolve a `simple_expansion` ($VAR) node. Returns VAR_PLACEHOLDER if
1863
+ * resolvable, too-complex otherwise.
1864
+ *
1865
+ * @param insideString true when $VAR is inside a `string` node ("...$VAR...")
1866
+ * rather than a bare/concatenation argument. SAFE_ENV_VARS and unknown-value
1867
+ * tracked vars are only allowed inside strings — as bare args their runtime
1868
+ * value IS the argument and we don't know it statically.
1869
+ * `cd $HOME/../x` would hide the real path behind the placeholder;
1870
+ * `echo "Home: $HOME"` just embeds text in a string. Tracked vars holding
1871
+ * STATIC strings (VAR=literal) are allowed in both positions since their
1872
+ * value IS known.
1873
+ */
1874
+ function resolveSimpleExpansion(node, varScope, insideString) {
1875
+ let varName = null;
1876
+ let isSpecial = false;
1877
+ for (const c of node.children) {
1878
+ if (c?.type === 'variable_name') {
1879
+ varName = c.text;
1880
+ break;
1881
+ }
1882
+ if (c?.type === 'special_variable_name') {
1883
+ varName = c.text;
1884
+ isSpecial = true;
1885
+ break;
1886
+ }
1887
+ }
1888
+ if (varName === null)
1889
+ return tooComplex(node);
1890
+ // Tracked vars: check stored value. Literal strings (VAR=/tmp) are
1891
+ // returned DIRECTLY so downstream path validation sees the real path.
1892
+ // Non-literal values (containing any placeholder — loop vars, $() output,
1893
+ // read vars, composites like `VAR="prefix$(cmd)"`) are ONLY safe inside
1894
+ // strings; as bare args they'd hide the runtime path/flag from validation.
1895
+ //
1896
+ // SECURITY: Returning the actual trackedValue (not a placeholder) is the
1897
+ // critical fix. `VAR=/etc && rm $VAR` → argv ['rm', '/etc'] → validatePath
1898
+ // correctly rejects. Previously returned a placeholder → validatePath saw
1899
+ // '__LOOP_STATIC__', resolved as cwd-relative → PASSED → bypass.
1900
+ const trackedValue = varScope.get(varName);
1901
+ if (trackedValue !== undefined) {
1902
+ if (containsAnyPlaceholder(trackedValue)) {
1903
+ // Non-literal: bare → reject, inside string → VAR_PLACEHOLDER
1904
+ // (walkString's solo-placeholder gate rejects `"$VAR"` alone).
1905
+ if (!insideString)
1906
+ return tooComplex(node);
1907
+ return VAR_PLACEHOLDER;
1908
+ }
1909
+ // Pure literal (e.g. '/tmp', 'foo') — return it directly. Downstream
1910
+ // path validation / checkSemantics operate on the REAL value.
1911
+ //
1912
+ // SECURITY: For BARE args (not inside a string), bash word-splits on
1913
+ // $IFS and glob-expands the result. `VAR="-rf /" && rm $VAR` → bash
1914
+ // runs `rm -rf /` (two args); `VAR="/etc/*" && cat $VAR` → expands to
1915
+ // all files. Reject values containing IFS/glob chars unless in "...".
1916
+ //
1917
+ // SECURITY: Empty value as bare arg. Bash word-splitting on "" produces
1918
+ // ZERO fields — the expansion disappears. `V="" && $V eval x` → bash
1919
+ // runs `eval x` (our argv would be ["","eval","x"] with name="" —
1920
+ // every EVAL_LIKE/ZSH/keyword check misses). `V="" && ls $V /etc` →
1921
+ // bash runs `ls /etc`, our argv has a phantom "" shifting positions.
1922
+ // Inside "...": `"$V"` → bash produces one empty-string arg → our ""
1923
+ // is correct, keep allowing.
1924
+ if (!insideString) {
1925
+ if (trackedValue === '')
1926
+ return tooComplex(node);
1927
+ if (BARE_VAR_UNSAFE_RE.test(trackedValue))
1928
+ return tooComplex(node);
1929
+ }
1930
+ return trackedValue;
1931
+ }
1932
+ // SAFE_ENV_VARS + special vars ($?, $$, $@, $1, etc.): value unknown
1933
+ // (shell-controlled). Only safe when embedded in a string, NOT as a
1934
+ // bare argument to a path-sensitive command.
1935
+ if (insideString) {
1936
+ if (SAFE_ENV_VARS.has(varName))
1937
+ return VAR_PLACEHOLDER;
1938
+ if (isSpecial &&
1939
+ (SPECIAL_VAR_NAMES.has(varName) || /^[0-9]+$/.test(varName))) {
1940
+ return VAR_PLACEHOLDER;
1941
+ }
1942
+ }
1943
+ return tooComplex(node);
1944
+ }
1945
+ /**
1946
+ * Apply a variable assignment to the scope, handling `+=` append semantics.
1947
+ * SECURITY: If EITHER side (existing value or appended value) contains a
1948
+ * placeholder, the result is non-literal — store VAR_PLACEHOLDER so later
1949
+ * $VAR correctly rejects as bare arg.
1950
+ * `VAR=/etc && VAR+=$(cmd)` must not leave VAR looking static.
1951
+ */
1952
+ function applyVarToScope(varScope, ev) {
1953
+ const existing = varScope.get(ev.name) ?? '';
1954
+ const combined = ev.isAppend ? existing + ev.value : ev.value;
1955
+ varScope.set(ev.name, containsAnyPlaceholder(combined) ? VAR_PLACEHOLDER : combined);
1956
+ }
1957
+ function stripRawString(text) {
1958
+ return text.slice(1, -1);
1959
+ }
1960
+ function tooComplex(node) {
1961
+ const reason = node.type === 'ERROR'
1962
+ ? 'Parse error'
1963
+ : DANGEROUS_TYPES.has(node.type)
1964
+ ? `Contains ${node.type}`
1965
+ : `Unhandled node type: ${node.type}`;
1966
+ return { kind: 'too-complex', reason, nodeType: node.type };
1967
+ }
1968
+ // ────────────────────────────────────────────────────────────────────────────
1969
+ // Post-argv semantic checks
1970
+ //
1971
+ // Everything above answers "can we tokenize?". Everything below answers
1972
+ // "is the resulting argv dangerous in ways that don't involve parsing?".
1973
+ // These are checks on argv[0] or argv content that the old bashSecurity.ts
1974
+ // validators performed but which have nothing to do with parser
1975
+ // differentials. They're here (not in bashSecurity.ts) because they operate
1976
+ // on SimpleCommand and need to run for every extracted command.
1977
+ // ────────────────────────────────────────────────────────────────────────────
1978
+ /**
1979
+ * Zsh module builtins. These are not binaries on PATH — they're zsh
1980
+ * internals loaded via zmodload. Since BashTool runs via the user's default
1981
+ * shell (often zsh), and these parse as plain `command` nodes with no
1982
+ * distinguishing syntax, we can only catch them by name.
1983
+ */
1984
+ const ZSH_DANGEROUS_BUILTINS = new Set([
1985
+ 'zmodload',
1986
+ 'emulate',
1987
+ 'sysopen',
1988
+ 'sysread',
1989
+ 'syswrite',
1990
+ 'sysseek',
1991
+ 'zpty',
1992
+ 'ztcp',
1993
+ 'zsocket',
1994
+ 'zf_rm',
1995
+ 'zf_mv',
1996
+ 'zf_ln',
1997
+ 'zf_chmod',
1998
+ 'zf_chown',
1999
+ 'zf_mkdir',
2000
+ 'zf_rmdir',
2001
+ 'zf_chgrp',
2002
+ ]);
2003
+ /**
2004
+ * Shell builtins that evaluate their arguments as code or otherwise escape
2005
+ * the argv abstraction. A command like `eval "rm -rf /"` has argv
2006
+ * ['eval', 'rm -rf /'] which looks inert to flag validation but executes
2007
+ * the string. Treat these the same as command substitution.
2008
+ */
2009
+ const EVAL_LIKE_BUILTINS = new Set([
2010
+ 'eval',
2011
+ 'source',
2012
+ '.',
2013
+ 'exec',
2014
+ 'command',
2015
+ 'builtin',
2016
+ 'fc',
2017
+ // `coproc rm -rf /` spawns rm as a coprocess. tree-sitter parses it as
2018
+ // a plain command with argv[0]='coproc', so permission rules and path
2019
+ // validation would check 'coproc' not 'rm'.
2020
+ 'coproc',
2021
+ // Zsh precommand modifiers: `noglob cmd args` runs cmd with globbing off.
2022
+ // They parse as ordinary commands (noglob is argv[0], the real command is
2023
+ // argv[1]) so permission matching against argv[0] would see 'noglob', not
2024
+ // the wrapped command.
2025
+ 'noglob',
2026
+ 'nocorrect',
2027
+ // `trap 'cmd' SIGNAL` — cmd runs as shell code on signal/exit. EXIT fires
2028
+ // at end of every BashTool invocation, so this is guaranteed execution.
2029
+ 'trap',
2030
+ // `enable -f /path/lib.so name` — dlopen arbitrary .so as a builtin.
2031
+ // Native code execution.
2032
+ 'enable',
2033
+ // `mapfile -C callback -c N` / `readarray -C callback` — callback runs as
2034
+ // shell code every N input lines.
2035
+ 'mapfile',
2036
+ 'readarray',
2037
+ // `hash -p /path cmd` — poisons bash's command-lookup cache. Subsequent
2038
+ // `cmd` in the same command resolves to /path instead of PATH lookup.
2039
+ 'hash',
2040
+ // `bind -x '"key":cmd'` / `complete -C cmd` — interactive-only callbacks
2041
+ // but still code-string arguments. Low impact in non-interactive BashTool
2042
+ // shells, blocked for consistency. `compgen -C cmd` is NOT interactive-only:
2043
+ // it immediately executes the -C argument to generate completions.
2044
+ 'bind',
2045
+ 'complete',
2046
+ 'compgen',
2047
+ // `alias name='cmd'` — aliases not expanded in non-interactive bash by
2048
+ // default, but `shopt -s expand_aliases` enables them. Also blocked as
2049
+ // defense-in-depth (alias followed by name use in same command).
2050
+ 'alias',
2051
+ // `let EXPR` arithmetically evaluates EXPR — identical to $(( EXPR )).
2052
+ // Array subscripts in the expression expand $(cmd) at eval time even when
2053
+ // the argument arrived single-quoted: `let 'x=a[$(id)]'` executes id.
2054
+ // tree-sitter sees the raw_string as an opaque leaf. Same primitive
2055
+ // walkArithmetic guards, but `let` is a plain command node.
2056
+ 'let',
2057
+ ]);
2058
+ /**
2059
+ * Builtins that re-parse a NAME operand internally and arithmetically
2060
+ * evaluate `arr[EXPR]` subscripts — including $(cmd) in the subscript —
2061
+ * even when the argv element arrived from a single-quoted raw_string.
2062
+ * `test -v 'a[$(id)]'` → tree-sitter sees an opaque leaf, bash runs id.
2063
+ * Maps: builtin name → set of flags whose next argument is a NAME.
2064
+ */
2065
+ const SUBSCRIPT_EVAL_FLAGS = {
2066
+ test: new Set(['-v', '-R']),
2067
+ '[': new Set(['-v', '-R']),
2068
+ '[[': new Set(['-v', '-R']),
2069
+ printf: new Set(['-v']),
2070
+ read: new Set(['-a']),
2071
+ unset: new Set(['-v']),
2072
+ // bash 5.1+: `wait -p VAR [id...]` stores the waited PID into VAR. When VAR
2073
+ // is `arr[EXPR]`, bash arithmetically evaluates the subscript — running
2074
+ // $(cmd) even from a single-quoted raw_string. Verified bash 5.3.9:
2075
+ // `: & wait -p 'a[$(id)]' %1` executes id.
2076
+ wait: new Set(['-p']),
2077
+ };
2078
+ /**
2079
+ * `[[ ARG1 OP ARG2 ]]` where OP is an arithmetic comparison. bash manual:
2080
+ * "When used with [[, Arg1 and Arg2 are evaluated as arithmetic
2081
+ * expressions." Arithmetic evaluation recursively expands array subscripts,
2082
+ * so `[[ 'a[$(id)]' -eq 0 ]]` executes `id` even though tree-sitter sees
2083
+ * the operand as an opaque raw_string leaf. Unlike -v/-R (unary, NAME after
2084
+ * flag), these are binary — the subscript can appear on EITHER side, so
2085
+ * SUBSCRIPT_EVAL_FLAGS's "next arg" logic is insufficient.
2086
+ * `[` / `test` are not vulnerable (bash errors with "integer expression
2087
+ * expected"), but the test_command handler normalizes argv[0]='[[' for
2088
+ * both forms, so they get this check too — mild over-blocking, safe side.
2089
+ */
2090
+ const TEST_ARITH_CMP_OPS = new Set(['-eq', '-ne', '-lt', '-le', '-gt', '-ge']);
2091
+ /**
2092
+ * Builtins where EVERY non-flag positional argument is a NAME that bash
2093
+ * re-parses and arithmetically evaluates subscripts on — no flag required.
2094
+ * `read 'a[$(id)]'` executes id: each positional is a variable name to
2095
+ * assign into, and `arr[EXPR]` is valid syntax there. `unset NAME...` is
2096
+ * the same (though tree-sitter's unset_command handler currently rejects
2097
+ * raw_string children before reaching here — this is defense-in-depth).
2098
+ * NOT printf (positional args are FORMAT/data), NOT test/[ (operands are
2099
+ * values, only -v/-R take a NAME). declare/typeset/local handled in
2100
+ * declaration_command since they never reach here as plain commands.
2101
+ */
2102
+ const BARE_SUBSCRIPT_NAME_BUILTINS = new Set(['read', 'unset']);
2103
+ /**
2104
+ * `read` flags whose NEXT argument is data (prompt/delimiter/count/fd),
2105
+ * not a NAME. `read -p '[foo] ' var` must not trip on the `[` in the
2106
+ * prompt string. `-a` is intentionally absent — its operand IS a NAME.
2107
+ */
2108
+ const READ_DATA_FLAGS = new Set(['-p', '-d', '-n', '-N', '-t', '-u', '-i']);
2109
+ // SHELL_KEYWORDS imported from bashParser.ts — shell reserved words can never
2110
+ // be legitimate argv[0]; if they appear, the parser mis-parsed a compound
2111
+ // command. Reject to avoid nonsense argv reaching downstream.
2112
+ // Use `.*` not `[^/]*` — Linux resolves `..` in procfs, so
2113
+ // `/proc/self/../self/environ` works and must be caught.
2114
+ const PROC_ENVIRON_RE = /\/proc\/.*\/environ/;
2115
+ /**
2116
+ * Newline followed by `#` in an argv element, env var value, or redirect target.
2117
+ * Downstream stripSafeWrappers re-tokenizes .text line-by-line and treats `#`
2118
+ * after a newline as a comment, hiding arguments that follow.
2119
+ */
2120
+ const NEWLINE_HASH_RE = /\n[ \t]*#/;
2121
+ /**
2122
+ * Post-argv semantic checks. Run after parseForSecurity returns 'simple' to
2123
+ * catch commands that tokenize fine but are dangerous by name or argument
2124
+ * content. Returns the first failure or {ok: true}.
2125
+ */
2126
+ export function checkSemantics(commands) {
2127
+ for (const cmd of commands) {
2128
+ // Strip safe wrapper commands (nohup, time, timeout N, nice -n N) so
2129
+ // `nohup eval "..."` and `timeout 5 jq 'system(...)'` are checked
2130
+ // against the wrapped command, not the wrapper. Inlined here to avoid
2131
+ // circular import with bashPermissions.ts.
2132
+ let a = cmd.argv;
2133
+ for (;;) {
2134
+ if (a[0] === 'time' || a[0] === 'nohup') {
2135
+ a = a.slice(1);
2136
+ }
2137
+ else if (a[0] === 'timeout') {
2138
+ // `timeout 5`, `timeout 5s`, `timeout 5.5`, plus optional GNU flags
2139
+ // preceding the duration. Long: --foreground, --kill-after=N,
2140
+ // --signal=SIG, --preserve-status. Short: -k DUR, -s SIG, -v (also
2141
+ // fused: -k5, -sTERM).
2142
+ // SECURITY (SAST Mar 2026): the previous loop only skipped `--long`
2143
+ // flags, so `timeout -k 5 10 eval ...` broke out with name='timeout'
2144
+ // and the wrapped eval was never checked. Now handle known short
2145
+ // flags AND fail closed on any unrecognized flag — an unknown flag
2146
+ // means we can't locate the wrapped command, so we must not silently
2147
+ // fall through to name='timeout'.
2148
+ let i = 1;
2149
+ while (i < a.length) {
2150
+ const arg = a[i];
2151
+ if (arg === '--foreground' ||
2152
+ arg === '--preserve-status' ||
2153
+ arg === '--verbose') {
2154
+ i++; // known no-value long flags
2155
+ }
2156
+ else if (/^--(?:kill-after|signal)=[A-Za-z0-9_.+-]+$/.test(arg)) {
2157
+ i++; // --kill-after=5, --signal=TERM (value fused with =)
2158
+ }
2159
+ else if ((arg === '--kill-after' || arg === '--signal') &&
2160
+ a[i + 1] &&
2161
+ /^[A-Za-z0-9_.+-]+$/.test(a[i + 1])) {
2162
+ i += 2; // --kill-after 5, --signal TERM (space-separated)
2163
+ }
2164
+ else if (arg.startsWith('--')) {
2165
+ // Unknown long flag, OR --kill-after/--signal with non-allowlisted
2166
+ // value (e.g. placeholder from $() substitution). Fail closed.
2167
+ return {
2168
+ ok: false,
2169
+ reason: `timeout with ${arg} flag cannot be statically analyzed`,
2170
+ };
2171
+ }
2172
+ else if (arg === '-v') {
2173
+ i++; // --verbose, no argument
2174
+ }
2175
+ else if ((arg === '-k' || arg === '-s') &&
2176
+ a[i + 1] &&
2177
+ /^[A-Za-z0-9_.+-]+$/.test(a[i + 1])) {
2178
+ i += 2; // -k DURATION / -s SIGNAL — separate value
2179
+ }
2180
+ else if (/^-[ks][A-Za-z0-9_.+-]+$/.test(arg)) {
2181
+ i++; // fused: -k5, -sTERM
2182
+ }
2183
+ else if (arg.startsWith('-')) {
2184
+ // Unknown flag OR -k/-s with non-allowlisted value — can't locate
2185
+ // wrapped cmd. Reject, don't fall through to name='timeout'.
2186
+ return {
2187
+ ok: false,
2188
+ reason: `timeout with ${arg} flag cannot be statically analyzed`,
2189
+ };
2190
+ }
2191
+ else {
2192
+ break; // non-flag — should be the duration
2193
+ }
2194
+ }
2195
+ if (a[i] && /^\d+(?:\.\d+)?[smhd]?$/.test(a[i])) {
2196
+ a = a.slice(i + 1);
2197
+ }
2198
+ else if (a[i]) {
2199
+ // SECURITY (PR #21503 round 3): a[i] exists but doesn't match our
2200
+ // duration regex. GNU timeout parses via xstrtod() (libc strtod) and
2201
+ // accepts `.5`, `+5`, `5e-1`, `inf`, `infinity`, hex floats — none
2202
+ // of which match `/^\d+(\.\d+)?[smhd]?$/`. Empirically verified:
2203
+ // `timeout .5 echo ok` works. Previously this branch `break`ed
2204
+ // (fail-OPEN) so `timeout .5 eval "id"` with `Bash(timeout:*)` left
2205
+ // name='timeout' and eval was never checked. Now fail CLOSED —
2206
+ // consistent with the unknown-FLAG handling above (lines ~1895,1912).
2207
+ return {
2208
+ ok: false,
2209
+ reason: `timeout duration '${a[i]}' cannot be statically analyzed`,
2210
+ };
2211
+ }
2212
+ else {
2213
+ break; // no more args — `timeout` alone, inert
2214
+ }
2215
+ }
2216
+ else if (a[0] === 'nice') {
2217
+ // `nice cmd`, `nice -n N cmd`, `nice -N cmd` (legacy). All run cmd
2218
+ // at a lower priority. argv[0] check must see the wrapped cmd.
2219
+ if (a[1] === '-n' && a[2] && /^-?\d+$/.test(a[2])) {
2220
+ a = a.slice(3);
2221
+ }
2222
+ else if (a[1] && /^-\d+$/.test(a[1])) {
2223
+ a = a.slice(2); // `nice -10 cmd`
2224
+ }
2225
+ else if (a[1] && /[$(`]/.test(a[1])) {
2226
+ // SECURITY: walkArgument returns node.text for arithmetic_expansion,
2227
+ // so `nice $((0-5)) jq ...` has a[1]='$((0-5))'. Bash expands it to
2228
+ // '-5' (legacy nice syntax) and execs jq; we'd slice(1) here and
2229
+ // set name='$((0-5))' which skips the jq system() check entirely.
2230
+ // Fail closed — mirrors the timeout-duration fail-closed above.
2231
+ return {
2232
+ ok: false,
2233
+ reason: `nice argument '${a[1]}' contains expansion — cannot statically determine wrapped command`,
2234
+ };
2235
+ }
2236
+ else {
2237
+ a = a.slice(1); // bare `nice cmd`
2238
+ }
2239
+ }
2240
+ else if (a[0] === 'env') {
2241
+ // `env [VAR=val...] [-i] [-0] [-v] [-u NAME...] cmd args` runs cmd.
2242
+ // argv[0] check must see cmd, not env. Skip known-safe forms only.
2243
+ // SECURITY: -S splits a string into argv (mini-shell) — must reject.
2244
+ // -C/-P change cwd/PATH — wrapped cmd runs elsewhere, reject.
2245
+ // Any OTHER flag → reject (fail-closed, not fail-open to name='env').
2246
+ let i = 1;
2247
+ while (i < a.length) {
2248
+ const arg = a[i];
2249
+ if (arg.includes('=') && !arg.startsWith('-')) {
2250
+ i++; // VAR=val assignment
2251
+ }
2252
+ else if (arg === '-i' || arg === '-0' || arg === '-v') {
2253
+ i++; // flags with no argument
2254
+ }
2255
+ else if (arg === '-u' && a[i + 1]) {
2256
+ i += 2; // -u NAME unsets; takes one arg
2257
+ }
2258
+ else if (arg.startsWith('-')) {
2259
+ // -S (argv splitter), -C (altwd), -P (altpath), --anything,
2260
+ // or unknown flag. Can't model — reject the whole command.
2261
+ return {
2262
+ ok: false,
2263
+ reason: `env with ${arg} flag cannot be statically analyzed`,
2264
+ };
2265
+ }
2266
+ else {
2267
+ break; // the wrapped command
2268
+ }
2269
+ }
2270
+ if (i < a.length) {
2271
+ a = a.slice(i);
2272
+ }
2273
+ else {
2274
+ break; // `env` alone (no wrapped cmd) — inert, name='env'
2275
+ }
2276
+ }
2277
+ else if (a[0] === 'stdbuf') {
2278
+ // `stdbuf -o0 cmd` (fused), `stdbuf -o 0 cmd` (space-separated),
2279
+ // multiple flags (`stdbuf -o0 -eL cmd`), long forms (`--output=0`).
2280
+ // SECURITY: previous handling only stripped ONE flag and fell through
2281
+ // to slice(2) for anything unrecognized, so `stdbuf --output 0 eval`
2282
+ // → ['0','eval',...] → name='0' hid eval. Now iterate all known flag
2283
+ // forms and fail closed on any unknown flag.
2284
+ let i = 1;
2285
+ while (i < a.length) {
2286
+ const arg = a[i];
2287
+ if (STDBUF_SHORT_SEP_RE.test(arg) && a[i + 1]) {
2288
+ i += 2; // -o MODE (space-separated)
2289
+ }
2290
+ else if (STDBUF_SHORT_FUSED_RE.test(arg)) {
2291
+ i++; // -o0 (fused)
2292
+ }
2293
+ else if (STDBUF_LONG_RE.test(arg)) {
2294
+ i++; // --output=MODE (fused long)
2295
+ }
2296
+ else if (arg.startsWith('-')) {
2297
+ // --output MODE (space-separated long) or unknown flag. GNU
2298
+ // stdbuf long options use `=` syntax, but getopt_long also
2299
+ // accepts space-separated — we can't enumerate safely, reject.
2300
+ return {
2301
+ ok: false,
2302
+ reason: `stdbuf with ${arg} flag cannot be statically analyzed`,
2303
+ };
2304
+ }
2305
+ else {
2306
+ break; // the wrapped command
2307
+ }
2308
+ }
2309
+ if (i > 1 && i < a.length) {
2310
+ a = a.slice(i);
2311
+ }
2312
+ else {
2313
+ break; // `stdbuf` with no flags or no wrapped cmd — inert
2314
+ }
2315
+ }
2316
+ else {
2317
+ break;
2318
+ }
2319
+ }
2320
+ const name = a[0];
2321
+ if (name === undefined)
2322
+ continue;
2323
+ // SECURITY: Empty command name. Quoted empty (`"" cmd`) is harmless —
2324
+ // bash tries to exec "" and fails with "command not found". But an
2325
+ // UNQUOTED empty expansion at command position (`V="" && $V cmd`) is a
2326
+ // bypass: bash drops the empty field and runs `cmd` as argv[0], while
2327
+ // our name="" skips every builtin check below. resolveSimpleExpansion
2328
+ // rejects the $V case; this catches any other path to empty argv[0]
2329
+ // (concatenation of empties, walkString whitespace-quirk, future bugs).
2330
+ if (name === '') {
2331
+ return {
2332
+ ok: false,
2333
+ reason: 'Empty command name — argv[0] may not reflect what bash runs',
2334
+ };
2335
+ }
2336
+ // Defense-in-depth: argv[0] should never be a placeholder after the
2337
+ // var-tracking fix (static vars return real value, unknown vars reject).
2338
+ // But if a bug upstream ever lets one through, catch it here — a
2339
+ // placeholder-as-command-name means runtime-determined command → unsafe.
2340
+ if (name.includes(CMDSUB_PLACEHOLDER) || name.includes(VAR_PLACEHOLDER)) {
2341
+ return {
2342
+ ok: false,
2343
+ reason: 'Command name is runtime-determined (placeholder argv[0])',
2344
+ };
2345
+ }
2346
+ // argv[0] starts with an operator/flag: this is a fragment, not a
2347
+ // command. Likely a line-continuation leak or a mistake.
2348
+ if (name.startsWith('-') || name.startsWith('|') || name.startsWith('&')) {
2349
+ return {
2350
+ ok: false,
2351
+ reason: 'Command appears to be an incomplete fragment',
2352
+ };
2353
+ }
2354
+ // SECURITY: builtins that re-parse a NAME operand internally. bash
2355
+ // arithmetically evaluates `arr[EXPR]` in NAME position, running $(cmd)
2356
+ // in the subscript even when the argv element arrived from a
2357
+ // single-quoted raw_string (opaque leaf to tree-sitter). Two forms:
2358
+ // separate (`printf -v NAME`) and fused (`printf -vNAME`, getopt-style).
2359
+ // `printf '[%s]' x` stays safe — `[` in format string, not after `-v`.
2360
+ const dangerFlags = SUBSCRIPT_EVAL_FLAGS[name];
2361
+ if (dangerFlags !== undefined) {
2362
+ for (let i = 1; i < a.length; i++) {
2363
+ const arg = a[i];
2364
+ // Separate form: `-v` then NAME in next arg.
2365
+ if (dangerFlags.has(arg) && a[i + 1]?.includes('[')) {
2366
+ return {
2367
+ ok: false,
2368
+ reason: `'${name} ${arg}' operand contains array subscript — bash evaluates $(cmd) in subscripts`,
2369
+ };
2370
+ }
2371
+ // Combined short flags: `-ra` is bash shorthand for `-r -a`.
2372
+ // Check if any danger flag character appears in a combined flag
2373
+ // string. The danger flag's NAME operand is the next argument.
2374
+ if (arg.length > 2 &&
2375
+ arg[0] === '-' &&
2376
+ arg[1] !== '-' &&
2377
+ !arg.includes('[')) {
2378
+ for (const flag of dangerFlags) {
2379
+ if (flag.length === 2 && arg.includes(flag[1])) {
2380
+ if (a[i + 1]?.includes('[')) {
2381
+ return {
2382
+ ok: false,
2383
+ reason: `'${name} ${flag}' (combined in '${arg}') operand contains array subscript — bash evaluates $(cmd) in subscripts`,
2384
+ };
2385
+ }
2386
+ }
2387
+ }
2388
+ }
2389
+ // Fused form: `-vNAME` in one arg. Only short-option flags fuse
2390
+ // (getopt), so check -v/-a/-R. `[[` uses test_operator nodes only.
2391
+ for (const flag of dangerFlags) {
2392
+ if (flag.length === 2 &&
2393
+ arg.startsWith(flag) &&
2394
+ arg.length > 2 &&
2395
+ arg.includes('[')) {
2396
+ return {
2397
+ ok: false,
2398
+ reason: `'${name} ${flag}' (fused) operand contains array subscript — bash evaluates $(cmd) in subscripts`,
2399
+ };
2400
+ }
2401
+ }
2402
+ }
2403
+ }
2404
+ // SECURITY: `[[ ARG OP ARG ]]` arithmetic comparison. bash evaluates
2405
+ // BOTH operands as arithmetic expressions, recursively expanding
2406
+ // `arr[$(cmd)]` subscripts even from single-quoted raw_string. Check
2407
+ // the operand adjacent to each arith-cmp operator on BOTH sides —
2408
+ // SUBSCRIPT_EVAL_FLAGS's "flag then next-arg" pattern can't express
2409
+ // "either side of a binary op". String comparisons (==/!=/=~) do NOT
2410
+ // trigger arithmetic eval — `[[ 'a[x]' == y ]]` is a literal string cmp.
2411
+ if (name === '[[') {
2412
+ // i starts at 2: a[0]='[[' (contains '['), a[1] is the first real
2413
+ // operand. A binary op can't appear before index 2.
2414
+ for (let i = 2; i < a.length; i++) {
2415
+ if (!TEST_ARITH_CMP_OPS.has(a[i]))
2416
+ continue;
2417
+ if (a[i - 1]?.includes('[') || a[i + 1]?.includes('[')) {
2418
+ return {
2419
+ ok: false,
2420
+ reason: `'[[ ... ${a[i]} ... ]]' operand contains array subscript — bash arithmetically evaluates $(cmd) in subscripts`,
2421
+ };
2422
+ }
2423
+ }
2424
+ }
2425
+ // SECURITY: `read`/`unset` treat EVERY bare positional as a NAME —
2426
+ // no flag needed. `read 'a[$(id)]' <<< data` executes id even though
2427
+ // argv[1] arrived from a single-quoted raw_string and no -a flag is
2428
+ // present. Same primitive as SUBSCRIPT_EVAL_FLAGS but the trigger is
2429
+ // positional, not flag-gated. Skip operands of read's data-taking
2430
+ // flags (-p PROMPT etc.) to avoid blocking `read -p '[foo] ' var`.
2431
+ if (BARE_SUBSCRIPT_NAME_BUILTINS.has(name)) {
2432
+ let skipNext = false;
2433
+ for (let i = 1; i < a.length; i++) {
2434
+ const arg = a[i];
2435
+ if (skipNext) {
2436
+ skipNext = false;
2437
+ continue;
2438
+ }
2439
+ if (arg[0] === '-') {
2440
+ if (name === 'read') {
2441
+ if (READ_DATA_FLAGS.has(arg)) {
2442
+ skipNext = true;
2443
+ }
2444
+ else if (arg.length > 2 && arg[1] !== '-') {
2445
+ // Combined short flag like `-rp`. Getopt-style: first
2446
+ // data-flag char consumes rest-of-arg as its operand
2447
+ // (`-p[foo]` → prompt=`[foo]`), or next-arg if last
2448
+ // (`-rp '[foo]'` → prompt=`[foo]`). So skipNext iff a
2449
+ // data-flag char appears at the END after only no-arg
2450
+ // flags like `-r`/`-s`.
2451
+ for (let j = 1; j < arg.length; j++) {
2452
+ if (READ_DATA_FLAGS.has('-' + arg[j])) {
2453
+ if (j === arg.length - 1)
2454
+ skipNext = true;
2455
+ break;
2456
+ }
2457
+ }
2458
+ }
2459
+ }
2460
+ continue;
2461
+ }
2462
+ if (arg.includes('[')) {
2463
+ return {
2464
+ ok: false,
2465
+ reason: `'${name}' positional NAME '${arg}' contains array subscript — bash evaluates $(cmd) in subscripts`,
2466
+ };
2467
+ }
2468
+ }
2469
+ }
2470
+ // SECURITY: Shell reserved keywords as argv[0] indicate a tree-sitter
2471
+ // mis-parse. `! for i in a; do :; done` parses as `command "for i in a"`
2472
+ // + `command "do :"` + `command "done"` — tree-sitter fails to recognize
2473
+ // `for` after `!` as a compound command start. Reject: keywords can never
2474
+ // be legitimate command names, and argv like ['do','false'] is nonsense.
2475
+ if (SHELL_KEYWORDS.has(name)) {
2476
+ return {
2477
+ ok: false,
2478
+ reason: `Shell keyword '${name}' as command name — tree-sitter mis-parse`,
2479
+ };
2480
+ }
2481
+ // Check argv (not .text) to catch both single-quote (`'\n#'`) and
2482
+ // double-quote (`"\n#"`) variants. Env vars and redirects are also
2483
+ // part of the .text span so the same downstream bug applies.
2484
+ // Heredoc bodies are excluded from argv so markdown `##` headers
2485
+ // don't trigger this.
2486
+ // TODO: remove once downstream path validation operates on argv.
2487
+ for (const arg of cmd.argv) {
2488
+ if (arg.includes('\n') && NEWLINE_HASH_RE.test(arg)) {
2489
+ return {
2490
+ ok: false,
2491
+ reason: 'Newline followed by # inside a quoted argument can hide arguments from path validation',
2492
+ };
2493
+ }
2494
+ }
2495
+ for (const ev of cmd.envVars) {
2496
+ if (ev.value.includes('\n') && NEWLINE_HASH_RE.test(ev.value)) {
2497
+ return {
2498
+ ok: false,
2499
+ reason: 'Newline followed by # inside an env var value can hide arguments from path validation',
2500
+ };
2501
+ }
2502
+ }
2503
+ for (const r of cmd.redirects) {
2504
+ if (r.target.includes('\n') && NEWLINE_HASH_RE.test(r.target)) {
2505
+ return {
2506
+ ok: false,
2507
+ reason: 'Newline followed by # inside a redirect target can hide arguments from path validation',
2508
+ };
2509
+ }
2510
+ }
2511
+ // jq's system() built-in executes arbitrary shell commands, and flags
2512
+ // like --from-file can read arbitrary files into jq variables. On the
2513
+ // legacy path these are caught by validateJqCommand in bashSecurity.ts,
2514
+ // but that validator is gated behind `astSubcommands === null` and
2515
+ // never runs when the AST parse succeeds. Mirror the checks here so
2516
+ // the AST path has the same defence.
2517
+ if (name === 'jq') {
2518
+ for (const arg of a) {
2519
+ if (/\bsystem\s*\(/.test(arg)) {
2520
+ return {
2521
+ ok: false,
2522
+ reason: 'jq command contains system() function which executes arbitrary commands',
2523
+ };
2524
+ }
2525
+ }
2526
+ if (a.some(arg => /^(?:-[fL](?:$|[^A-Za-z])|--(?:from-file|rawfile|slurpfile|library-path)(?:$|=))/.test(arg))) {
2527
+ return {
2528
+ ok: false,
2529
+ reason: 'jq command contains dangerous flags that could execute code or read arbitrary files',
2530
+ };
2531
+ }
2532
+ }
2533
+ if (ZSH_DANGEROUS_BUILTINS.has(name)) {
2534
+ return {
2535
+ ok: false,
2536
+ reason: `Zsh builtin '${name}' can bypass security checks`,
2537
+ };
2538
+ }
2539
+ if (EVAL_LIKE_BUILTINS.has(name)) {
2540
+ // `command -v foo` / `command -V foo` are POSIX existence checks that
2541
+ // only print paths — they never execute argv[1]. Bare `command foo`
2542
+ // does bypass function/alias lookup (the concern), so keep blocking it.
2543
+ if (name === 'command' && (a[1] === '-v' || a[1] === '-V')) {
2544
+ // fall through to remaining checks
2545
+ }
2546
+ else if (name === 'fc' &&
2547
+ !a.slice(1).some(arg => /^-[^-]*[es]/.test(arg))) {
2548
+ // `fc -l`, `fc -ln` list history — safe. `fc -e ed` invokes an
2549
+ // editor then executes. `fc -s [pat=rep]` RE-EXECUTES the last
2550
+ // matching command (optionally with substitution) — as dangerous
2551
+ // as eval. Block any short-opt containing `e` or `s`.
2552
+ // to avoid introducing FPs for `fc -l` (list history).
2553
+ }
2554
+ else if (name === 'compgen' &&
2555
+ !a.slice(1).some(arg => /^-[^-]*[CFW]/.test(arg))) {
2556
+ // `compgen -c/-f/-v` only list completions — safe. `compgen -C cmd`
2557
+ // immediately executes cmd; `-F func` calls a shell function; `-W list`
2558
+ // word-expands its argument (including $(cmd) even from single-quoted
2559
+ // raw_string). Block any short-opt containing C/F/W (case-sensitive:
2560
+ // -c/-f are safe).
2561
+ }
2562
+ else {
2563
+ return {
2564
+ ok: false,
2565
+ reason: `'${name}' evaluates arguments as shell code`,
2566
+ };
2567
+ }
2568
+ }
2569
+ // /proc/*/environ exposes env vars (including secrets) of other processes.
2570
+ // Check argv and redirect targets — `cat /proc/self/environ` and
2571
+ // `cat < /proc/self/environ` both read it.
2572
+ for (const arg of cmd.argv) {
2573
+ if (arg.includes('/proc/') && PROC_ENVIRON_RE.test(arg)) {
2574
+ return {
2575
+ ok: false,
2576
+ reason: 'Accesses /proc/*/environ which may expose secrets',
2577
+ };
2578
+ }
2579
+ }
2580
+ for (const r of cmd.redirects) {
2581
+ if (r.target.includes('/proc/') && PROC_ENVIRON_RE.test(r.target)) {
2582
+ return {
2583
+ ok: false,
2584
+ reason: 'Accesses /proc/*/environ which may expose secrets',
2585
+ };
2586
+ }
2587
+ }
2588
+ }
2589
+ return { ok: true };
2590
+ }