thaddeus 1.0.18 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2084) hide show
  1. package/package.json +14 -5
  2. package/src/QueryEngine.js +926 -0
  3. package/src/Task.js +49 -0
  4. package/src/Tool.js +61 -0
  5. package/src/assistant/gate.js +5 -0
  6. package/src/assistant/index.js +106 -0
  7. package/src/assistant/sessionHistory.js +145 -0
  8. package/src/bootstrap/state.js +1163 -0
  9. package/src/bridge/bridgeApi.js +304 -0
  10. package/src/bridge/bridgeConfig.js +39 -0
  11. package/src/bridge/bridgeDebug.js +73 -0
  12. package/src/bridge/bridgeEnabled.js +185 -0
  13. package/src/bridge/bridgeMain.js +2289 -0
  14. package/src/bridge/bridgeMessaging.js +353 -0
  15. package/src/bridge/bridgePermissionCallbacks.js +10 -0
  16. package/src/bridge/bridgePointer.js +175 -0
  17. package/src/bridge/bridgeStatusUtil.js +105 -0
  18. package/src/bridge/bridgeUI.js +411 -0
  19. package/src/bridge/capacityWake.js +35 -0
  20. package/src/bridge/codeSessionApi.js +111 -0
  21. package/src/bridge/createSession.js +273 -0
  22. package/src/bridge/debugUtils.js +115 -0
  23. package/src/bridge/envLessBridgeConfig.js +120 -0
  24. package/src/bridge/flushGate.js +65 -0
  25. package/src/bridge/inboundAttachments.js +152 -0
  26. package/src/bridge/inboundMessages.js +63 -0
  27. package/src/bridge/initReplBridge.js +431 -0
  28. package/src/bridge/jwtUtils.js +185 -0
  29. package/src/bridge/peerSessions.js +5 -0
  30. package/src/bridge/pollConfig.js +85 -0
  31. package/src/bridge/pollConfigDefaults.js +62 -0
  32. package/src/bridge/remoteBridgeCore.js +712 -0
  33. package/src/bridge/replBridge.js +1719 -0
  34. package/src/bridge/replBridgeHandle.js +30 -0
  35. package/src/bridge/replBridgeTransport.js +236 -0
  36. package/src/bridge/sessionIdCompat.js +56 -0
  37. package/src/bridge/sessionRunner.js +421 -0
  38. package/src/bridge/trustedDevice.js +170 -0
  39. package/src/bridge/types.js +9 -0
  40. package/src/bridge/webhookSanitizer.js +6 -0
  41. package/src/bridge/workSecret.js +99 -0
  42. package/src/buddy/CompanionSprite.js +348 -0
  43. package/src/buddy/companion.js +107 -0
  44. package/src/buddy/prompt.js +33 -0
  45. package/src/buddy/sprites.js +488 -0
  46. package/src/buddy/types.js +90 -0
  47. package/src/buddy/useBuddyNotification.js +85 -0
  48. package/src/cli/bg.js +17 -0
  49. package/src/cli/exit.js +30 -0
  50. package/src/cli/handlers/agents.js +55 -0
  51. package/src/cli/handlers/auth.js +249 -0
  52. package/src/cli/handlers/autoMode.js +128 -0
  53. package/src/cli/handlers/mcp.js +335 -0
  54. package/src/cli/handlers/plugins.js +634 -0
  55. package/src/cli/handlers/templateJobs.js +19 -0
  56. package/src/cli/handlers/util.js +76 -0
  57. package/src/cli/ndjsonSafeStringify.js +27 -0
  58. package/src/cli/print.js +4294 -0
  59. package/src/cli/remoteIO.js +208 -0
  60. package/src/cli/structuredIO.js +644 -0
  61. package/src/cli/transports/HybridTransport.js +233 -0
  62. package/src/cli/transports/SSETransport.js +538 -0
  63. package/src/cli/transports/SerialBatchEventUploader.js +224 -0
  64. package/src/cli/transports/WebSocketTransport.js +613 -0
  65. package/src/cli/transports/WorkerStateUploader.js +88 -0
  66. package/src/cli/transports/ccrClient.js +711 -0
  67. package/src/cli/transports/transportUtils.js +39 -0
  68. package/src/cli/update.js +314 -0
  69. package/src/commandCenter/launch.js +39 -0
  70. package/src/commandCenter/phoneApi.js +168 -0
  71. package/src/commandCenter/phoneStore.js +159 -0
  72. package/src/commandCenter/reactorBus.js +130 -0
  73. package/src/commandCenter/server.js +288 -0
  74. package/src/commandCenter/server.ts +42 -7
  75. package/src/commandCenter/tunnel.js +199 -0
  76. package/src/commands/add-dir/add-dir.js +121 -0
  77. package/src/commands/add-dir/index.js +8 -0
  78. package/src/commands/add-dir/validation.js +76 -0
  79. package/src/commands/advisor.js +88 -0
  80. package/src/commands/agents/agents.js +10 -0
  81. package/src/commands/agents/index.js +7 -0
  82. package/src/commands/agents-platform/index.js +2 -0
  83. package/src/commands/assistant/index.js +86 -0
  84. package/src/commands/backup/index.js +31 -0
  85. package/src/commands/branch/branch.js +205 -0
  86. package/src/commands/branch/index.js +11 -0
  87. package/src/commands/bridge/bridge.js +513 -0
  88. package/src/commands/bridge/index.js +22 -0
  89. package/src/commands/bridge-kick.js +179 -0
  90. package/src/commands/brief.js +89 -0
  91. package/src/commands/btw/btw.js +235 -0
  92. package/src/commands/btw/index.js +9 -0
  93. package/src/commands/buddy/buddy.js +100 -0
  94. package/src/commands/buddy/index.js +11 -0
  95. package/src/commands/chrome/chrome.js +291 -0
  96. package/src/commands/chrome/index.js +10 -0
  97. package/src/commands/clear/caches.js +116 -0
  98. package/src/commands/clear/clear.js +5 -0
  99. package/src/commands/clear/conversation.js +189 -0
  100. package/src/commands/clear/index.js +9 -0
  101. package/src/commands/color/color.js +58 -0
  102. package/src/commands/color/index.js +9 -0
  103. package/src/commands/commit-push-pr.js +137 -0
  104. package/src/commands/commit.js +80 -0
  105. package/src/commands/compact/compact.js +194 -0
  106. package/src/commands/compact/index.js +11 -0
  107. package/src/commands/config/config.js +6 -0
  108. package/src/commands/config/index.js +8 -0
  109. package/src/commands/context/context-noninteractive.js +219 -0
  110. package/src/commands/context/context.js +45 -0
  111. package/src/commands/context/index.js +21 -0
  112. package/src/commands/coordinator.js +34 -0
  113. package/src/commands/copy/copy.js +366 -0
  114. package/src/commands/copy/index.js +7 -0
  115. package/src/commands/cost/cost.js +21 -0
  116. package/src/commands/cost/index.js +16 -0
  117. package/src/commands/createMovedToPluginCommand.js +33 -0
  118. package/src/commands/desktop/desktop.js +6 -0
  119. package/src/commands/desktop/index.js +22 -0
  120. package/src/commands/diff/diff.js +6 -0
  121. package/src/commands/diff/index.js +6 -0
  122. package/src/commands/doctor/doctor.js +6 -0
  123. package/src/commands/doctor/index.js +9 -0
  124. package/src/commands/effort/effort.js +166 -0
  125. package/src/commands/effort/index.js +11 -0
  126. package/src/commands/exit/exit.js +32 -0
  127. package/src/commands/exit/index.js +9 -0
  128. package/src/commands/export/export.js +87 -0
  129. package/src/commands/export/index.js +8 -0
  130. package/src/commands/extra-usage/extra-usage-core.js +99 -0
  131. package/src/commands/extra-usage/extra-usage-noninteractive.js +13 -0
  132. package/src/commands/extra-usage/extra-usage.js +15 -0
  133. package/src/commands/extra-usage/index.js +29 -0
  134. package/src/commands/fast/fast.js +276 -0
  135. package/src/commands/fast/index.js +19 -0
  136. package/src/commands/feedback/feedback.js +11 -0
  137. package/src/commands/feedback/index.js +20 -0
  138. package/src/commands/files/files.js +11 -0
  139. package/src/commands/files/index.js +9 -0
  140. package/src/commands/force-snip.js +19 -0
  141. package/src/commands/fork/index.js +67 -0
  142. package/src/commands/heapdump/heapdump.js +14 -0
  143. package/src/commands/heapdump/index.js +9 -0
  144. package/src/commands/help/help.js +6 -0
  145. package/src/commands/help/index.js +7 -0
  146. package/src/commands/hooks/hooks.js +12 -0
  147. package/src/commands/hooks/index.js +8 -0
  148. package/src/commands/ide/ide.js +615 -0
  149. package/src/commands/ide/index.js +8 -0
  150. package/src/commands/init-verifiers.js +258 -0
  151. package/src/commands/init.js +248 -0
  152. package/src/commands/insights.js +2554 -0
  153. package/src/commands/install-github-app/ApiKeyStep.js +230 -0
  154. package/src/commands/install-github-app/CheckExistingSecretStep.js +194 -0
  155. package/src/commands/install-github-app/CheckGitHubStep.js +16 -0
  156. package/src/commands/install-github-app/ChooseRepoStep.js +211 -0
  157. package/src/commands/install-github-app/CreatingStep.js +53 -0
  158. package/src/commands/install-github-app/ErrorStep.js +84 -0
  159. package/src/commands/install-github-app/ExistingWorkflowStep.js +105 -0
  160. package/src/commands/install-github-app/InstallAppStep.js +97 -0
  161. package/src/commands/install-github-app/OAuthFlowStep.js +190 -0
  162. package/src/commands/install-github-app/SuccessStep.js +94 -0
  163. package/src/commands/install-github-app/WarningsStep.js +71 -0
  164. package/src/commands/install-github-app/index.js +10 -0
  165. package/src/commands/install-github-app/install-github-app.js +593 -0
  166. package/src/commands/install-github-app/setupGitHubActions.js +227 -0
  167. package/src/commands/install-slack-app/index.js +9 -0
  168. package/src/commands/install-slack-app/install-slack-app.js +25 -0
  169. package/src/commands/install.js +198 -0
  170. package/src/commands/keybindings/index.js +10 -0
  171. package/src/commands/keybindings/keybindings.js +47 -0
  172. package/src/commands/login/index.js +21 -0
  173. package/src/commands/login/login.js +135 -0
  174. package/src/commands/logout/index.js +11 -0
  175. package/src/commands/logout/logout.js +75 -0
  176. package/src/commands/mcp/addCommand.js +183 -0
  177. package/src/commands/mcp/index.js +9 -0
  178. package/src/commands/mcp/mcp.js +78 -0
  179. package/src/commands/mcp/xaaIdpCommand.js +193 -0
  180. package/src/commands/memories/index.js +9 -0
  181. package/src/commands/memories/index.ts +12 -0
  182. package/src/commands/memories/memories.tsx +950 -0
  183. package/src/commands/memory/index.js +7 -0
  184. package/src/commands/memory/memory.js +71 -0
  185. package/src/commands/mobile/index.js +9 -0
  186. package/src/commands/mobile/mobile.js +279 -0
  187. package/src/commands/model/index.js +14 -0
  188. package/src/commands/model/model.js +284 -0
  189. package/src/commands/output-style/index.js +8 -0
  190. package/src/commands/output-style/output-style.js +6 -0
  191. package/src/commands/passes/index.js +17 -0
  192. package/src/commands/passes/passes.js +23 -0
  193. package/src/commands/peers/index.js +68 -0
  194. package/src/commands/permissions/index.js +8 -0
  195. package/src/commands/permissions/permissions.js +9 -0
  196. package/src/commands/plan/index.js +8 -0
  197. package/src/commands/plan/plan.js +116 -0
  198. package/src/commands/plugin/AddMarketplace.js +96 -0
  199. package/src/commands/plugin/BrowseMarketplace.js +582 -0
  200. package/src/commands/plugin/DiscoverPlugins.js +613 -0
  201. package/src/commands/plugin/ManageMarketplaces.js +583 -0
  202. package/src/commands/plugin/ManagePlugins.js +1783 -0
  203. package/src/commands/plugin/PluginErrors.js +124 -0
  204. package/src/commands/plugin/PluginOptionsDialog.js +367 -0
  205. package/src/commands/plugin/PluginOptionsFlow.js +97 -0
  206. package/src/commands/plugin/PluginSettings.js +1041 -0
  207. package/src/commands/plugin/PluginTrustWarning.js +35 -0
  208. package/src/commands/plugin/UnifiedInstalledCell.js +616 -0
  209. package/src/commands/plugin/ValidatePlugin.js +96 -0
  210. package/src/commands/plugin/index.js +10 -0
  211. package/src/commands/plugin/parseArgs.js +71 -0
  212. package/src/commands/plugin/plugin.js +6 -0
  213. package/src/commands/plugin/pluginDetailsHelpers.js +95 -0
  214. package/src/commands/plugin/usePagination.js +89 -0
  215. package/src/commands/pr_comments/index.js +49 -0
  216. package/src/commands/privacy-settings/index.js +11 -0
  217. package/src/commands/privacy-settings/privacy-settings.js +55 -0
  218. package/src/commands/proactive.js +29 -0
  219. package/src/commands/rate-limit-options/index.js +15 -0
  220. package/src/commands/rate-limit-options/rate-limit-options.js +213 -0
  221. package/src/commands/release-notes/index.js +8 -0
  222. package/src/commands/release-notes/release-notes.js +38 -0
  223. package/src/commands/reload-plugins/index.js +11 -0
  224. package/src/commands/reload-plugins/reload-plugins.js +52 -0
  225. package/src/commands/remote-env/index.js +12 -0
  226. package/src/commands/remote-env/remote-env.js +6 -0
  227. package/src/commands/remote-setup/api.js +155 -0
  228. package/src/commands/remote-setup/index.js +15 -0
  229. package/src/commands/remote-setup/remote-setup.js +150 -0
  230. package/src/commands/remoteControlServer/index.js +58 -0
  231. package/src/commands/rename/generateSessionName.js +58 -0
  232. package/src/commands/rename/index.js +9 -0
  233. package/src/commands/rename/rename.js +52 -0
  234. package/src/commands/resume/index.js +9 -0
  235. package/src/commands/resume/resume.js +239 -0
  236. package/src/commands/review/UltrareviewOverageDialog.js +97 -0
  237. package/src/commands/review/reviewRemote.js +259 -0
  238. package/src/commands/review/ultrareviewCommand.js +58 -0
  239. package/src/commands/review/ultrareviewEnabled.js +10 -0
  240. package/src/commands/review.js +53 -0
  241. package/src/commands/rewind/index.js +10 -0
  242. package/src/commands/rewind/rewind.js +7 -0
  243. package/src/commands/sandbox-toggle/index.js +41 -0
  244. package/src/commands/sandbox-toggle/sandbox-toggle.js +73 -0
  245. package/src/commands/security-review.js +231 -0
  246. package/src/commands/session/index.js +13 -0
  247. package/src/commands/session/session.js +143 -0
  248. package/src/commands/skills/index.js +7 -0
  249. package/src/commands/skills/skills.js +6 -0
  250. package/src/commands/speak.js +21 -0
  251. package/src/commands/start-business.js +1575 -0
  252. package/src/commands/start-business.ts +1581 -0
  253. package/src/commands/stats/index.js +7 -0
  254. package/src/commands/stats/stats.js +6 -0
  255. package/src/commands/status/index.js +8 -0
  256. package/src/commands/status/status.js +6 -0
  257. package/src/commands/statusline.js +22 -0
  258. package/src/commands/stickers/index.js +8 -0
  259. package/src/commands/stickers/stickers.js +14 -0
  260. package/src/commands/subscribe-pr.js +131 -0
  261. package/src/commands/tag/index.js +9 -0
  262. package/src/commands/tag/tag.js +215 -0
  263. package/src/commands/tasks/index.js +8 -0
  264. package/src/commands/tasks/tasks.js +6 -0
  265. package/src/commands/terminalSetup/index.js +18 -0
  266. package/src/commands/terminalSetup/terminalSetup.js +491 -0
  267. package/src/commands/thaddeus-usage/index.js +17 -0
  268. package/src/commands/theme/index.js +7 -0
  269. package/src/commands/theme/theme.js +51 -0
  270. package/src/commands/thinkback/index.js +9 -0
  271. package/src/commands/thinkback/thinkback.js +528 -0
  272. package/src/commands/thinkback-play/index.js +13 -0
  273. package/src/commands/thinkback-play/thinkback-play.js +34 -0
  274. package/src/commands/torch.js +122 -0
  275. package/src/commands/ultraplan.js +416 -0
  276. package/src/commands/upgrade/index.js +12 -0
  277. package/src/commands/upgrade/upgrade.js +38 -0
  278. package/src/commands/usage/index.js +7 -0
  279. package/src/commands/usage/usage.js +6 -0
  280. package/src/commands/version.js +17 -0
  281. package/src/commands/vim/index.js +8 -0
  282. package/src/commands/vim/vim.js +25 -0
  283. package/src/commands/voice/index.js +13 -0
  284. package/src/commands/voice/voice.js +44 -0
  285. package/src/commands/workflows/index.js +123 -0
  286. package/src/commands.js +614 -0
  287. package/src/commands.ts +4 -0
  288. package/src/components/AgentProgressLine.js +112 -0
  289. package/src/components/AntModelSwitchCallout.js +8 -0
  290. package/src/components/App.js +46 -0
  291. package/src/components/ApproveApiKey.js +125 -0
  292. package/src/components/AutoModeOptInDialog.js +140 -0
  293. package/src/components/AutoUpdater.js +156 -0
  294. package/src/components/AutoUpdaterWrapper.js +78 -0
  295. package/src/components/AwsAuthStatusBox.js +88 -0
  296. package/src/components/BaseTextInput.js +105 -0
  297. package/src/components/BashModeProgress.js +49 -0
  298. package/src/components/BridgeDialog.js +415 -0
  299. package/src/components/BypassPermissionsModeDialog.js +87 -0
  300. package/src/components/ChannelDowngradeDialog.js +101 -0
  301. package/src/components/ClaudeInChromeOnboarding.js +126 -0
  302. package/src/components/ClaudeMdExternalIncludesDialog.js +137 -0
  303. package/src/components/ClickableImageRef.js +65 -0
  304. package/src/components/CompactSummary.js +120 -0
  305. package/src/components/ConfigurableShortcutHint.js +35 -0
  306. package/src/components/ConsoleOAuthFlow.js +554 -0
  307. package/src/components/ContextSuggestions.js +44 -0
  308. package/src/components/ContextVisualization.js +482 -0
  309. package/src/components/CoordinatorAgentStatus.js +261 -0
  310. package/src/components/CostThresholdDialog.js +49 -0
  311. package/src/components/CtrlOToExpand.js +50 -0
  312. package/src/components/CustomSelect/SelectMulti.js +150 -0
  313. package/src/components/CustomSelect/index.js +2 -0
  314. package/src/components/CustomSelect/option-map.js +32 -0
  315. package/src/components/CustomSelect/select-input-option.js +426 -0
  316. package/src/components/CustomSelect/select-option.js +24 -0
  317. package/src/components/CustomSelect/select.js +518 -0
  318. package/src/components/CustomSelect/use-multi-select-state.js +214 -0
  319. package/src/components/CustomSelect/use-select-input.js +170 -0
  320. package/src/components/CustomSelect/use-select-navigation.js +366 -0
  321. package/src/components/CustomSelect/use-select-state.js +22 -0
  322. package/src/components/DesktopHandoff.js +195 -0
  323. package/src/components/DesktopUpsell/DesktopUpsellStartup.js +174 -0
  324. package/src/components/DevBar.js +51 -0
  325. package/src/components/DevChannelsDialog.js +104 -0
  326. package/src/components/DiagnosticsDisplay.js +91 -0
  327. package/src/components/EffortCallout.js +264 -0
  328. package/src/components/EffortIndicator.js +28 -0
  329. package/src/components/ExitFlow.js +41 -0
  330. package/src/components/ExportDialog.js +101 -0
  331. package/src/components/FallbackToolUseErrorMessage.js +116 -0
  332. package/src/components/FallbackToolUseRejectedMessage.js +17 -0
  333. package/src/components/FastIcon.js +43 -0
  334. package/src/components/Feedback.js +369 -0
  335. package/src/components/FeedbackSurvey/FeedbackSurvey.js +151 -0
  336. package/src/components/FeedbackSurvey/FeedbackSurveyView.js +104 -0
  337. package/src/components/FeedbackSurvey/TranscriptSharePrompt.js +84 -0
  338. package/src/components/FeedbackSurvey/submitTranscriptShare.js +10 -0
  339. package/src/components/FeedbackSurvey/useDebouncedDigitInput.js +51 -0
  340. package/src/components/FeedbackSurvey/useFeedbackSurvey.js +258 -0
  341. package/src/components/FeedbackSurvey/useFrustrationDetection.js +8 -0
  342. package/src/components/FeedbackSurvey/useMemorySurvey.js +191 -0
  343. package/src/components/FeedbackSurvey/usePostCompactSurvey.js +202 -0
  344. package/src/components/FeedbackSurvey/useSurveyState.js +80 -0
  345. package/src/components/FileEditToolDiff.js +167 -0
  346. package/src/components/FileEditToolUpdatedMessage.js +112 -0
  347. package/src/components/FileEditToolUseRejectedMessage.js +158 -0
  348. package/src/components/FilePathLink.js +35 -0
  349. package/src/components/FullscreenLayout.js +578 -0
  350. package/src/components/GlobalSearchDialog.js +340 -0
  351. package/src/components/HelpV2/Commands.js +66 -0
  352. package/src/components/HelpV2/General.js +25 -0
  353. package/src/components/HelpV2/HelpV2.js +186 -0
  354. package/src/components/HighlightedCode/Fallback.js +193 -0
  355. package/src/components/HighlightedCode.js +185 -0
  356. package/src/components/HistorySearchDialog.js +93 -0
  357. package/src/components/IdeAutoConnectDialog.js +154 -0
  358. package/src/components/IdeOnboardingDialog.js +175 -0
  359. package/src/components/IdeStatusIndicator.js +50 -0
  360. package/src/components/IdleReturnDialog.js +117 -0
  361. package/src/components/InterruptedByUser.js +16 -0
  362. package/src/components/InvalidConfigDialog.js +135 -0
  363. package/src/components/InvalidSettingsDialog.js +85 -0
  364. package/src/components/KeybindingWarnings.js +55 -0
  365. package/src/components/LanguagePicker.js +84 -0
  366. package/src/components/LogSelector.js +1579 -0
  367. package/src/components/LogoV2/AnimatedAsterisk.js +43 -0
  368. package/src/components/LogoV2/AnimatedClawd.js +64 -0
  369. package/src/components/LogoV2/ChannelsNotice.js +262 -0
  370. package/src/components/LogoV2/Clawd.js +33 -0
  371. package/src/components/LogoV2/CondensedLogo.js +160 -0
  372. package/src/components/LogoV2/EmergencyTip.js +48 -0
  373. package/src/components/LogoV2/Feed.js +85 -0
  374. package/src/components/LogoV2/FeedColumn.js +55 -0
  375. package/src/components/LogoV2/GuestPassesUpsell.js +71 -0
  376. package/src/components/LogoV2/LogoV2.js +565 -0
  377. package/src/components/LogoV2/Opus1mMergeNotice.js +57 -0
  378. package/src/components/LogoV2/OverageCreditUpsell.js +161 -0
  379. package/src/components/LogoV2/VoiceModeNotice.js +71 -0
  380. package/src/components/LogoV2/WelcomeV2.js +14 -0
  381. package/src/components/LogoV2/feedConfigs.js +79 -0
  382. package/src/components/LspRecommendation/LspRecommendationMenu.js +46 -0
  383. package/src/components/MCPServerApprovalDialog.js +114 -0
  384. package/src/components/MCPServerDesktopImportDialog.js +206 -0
  385. package/src/components/MCPServerDialogCopy.js +16 -0
  386. package/src/components/MCPServerMultiselectDialog.js +134 -0
  387. package/src/components/ManagedSettingsSecurityDialog/ManagedSettingsSecurityDialog.js +150 -0
  388. package/src/components/ManagedSettingsSecurityDialog/utils.js +105 -0
  389. package/src/components/Markdown.js +233 -0
  390. package/src/components/MarkdownTable.js +280 -0
  391. package/src/components/MemoryUsageIndicator.js +28 -0
  392. package/src/components/Message.js +564 -0
  393. package/src/components/MessageModel.js +37 -0
  394. package/src/components/MessageResponse.js +73 -0
  395. package/src/components/MessageRow.js +346 -0
  396. package/src/components/MessageSelector.js +744 -0
  397. package/src/components/MessageTimestamp.js +58 -0
  398. package/src/components/Messages.js +645 -0
  399. package/src/components/ModelPicker.js +452 -0
  400. package/src/components/NativeAutoUpdater.js +152 -0
  401. package/src/components/NotebookEditToolUseRejectedMessage.js +84 -0
  402. package/src/components/OffscreenFreeze.js +35 -0
  403. package/src/components/Onboarding.js +174 -0
  404. package/src/components/OutputStylePicker.js +103 -0
  405. package/src/components/PackageManagerAutoUpdater.js +99 -0
  406. package/src/components/Passes/Passes.js +114 -0
  407. package/src/components/PrBadge.js +91 -0
  408. package/src/components/PressEnterToContinue.js +16 -0
  409. package/src/components/PromptInput/HistorySearchInput.js +45 -0
  410. package/src/components/PromptInput/IssueFlagBanner.js +8 -0
  411. package/src/components/PromptInput/Notifications.js +220 -0
  412. package/src/components/PromptInput/PromptInput.js +2014 -0
  413. package/src/components/PromptInput/PromptInputFooter.js +85 -0
  414. package/src/components/PromptInput/PromptInputFooterLeftSide.js +408 -0
  415. package/src/components/PromptInput/PromptInputFooterSuggestions.js +281 -0
  416. package/src/components/PromptInput/PromptInputHelpMenu.js +380 -0
  417. package/src/components/PromptInput/PromptInputModeIndicator.js +73 -0
  418. package/src/components/PromptInput/PromptInputQueuedCommands.js +105 -0
  419. package/src/components/PromptInput/PromptInputStashNotice.js +21 -0
  420. package/src/components/PromptInput/SandboxPromptFooterHint.js +66 -0
  421. package/src/components/PromptInput/ShimmeredInput.js +133 -0
  422. package/src/components/PromptInput/VoiceIndicator.js +137 -0
  423. package/src/components/PromptInput/inputModes.js +24 -0
  424. package/src/components/PromptInput/inputPaste.js +62 -0
  425. package/src/components/PromptInput/useMaybeTruncateInput.js +33 -0
  426. package/src/components/PromptInput/usePromptInputPlaceholder.js +53 -0
  427. package/src/components/PromptInput/useShowFastIconHint.js +23 -0
  428. package/src/components/PromptInput/useSwarmBanner.js +112 -0
  429. package/src/components/PromptInput/utils.js +50 -0
  430. package/src/components/QuickOpenDialog.js +244 -0
  431. package/src/components/RemoteCallout.js +53 -0
  432. package/src/components/RemoteEnvironmentDialog.js +346 -0
  433. package/src/components/ResumeTask.js +173 -0
  434. package/src/components/SandboxViolationExpandedView.js +106 -0
  435. package/src/components/SandboxViolationExpandedView.tsx +3 -0
  436. package/src/components/ScrollKeybindingHandler.js +982 -0
  437. package/src/components/SearchBox.js +56 -0
  438. package/src/components/SentryErrorBoundary.js +16 -0
  439. package/src/components/SessionBackgroundHint.js +105 -0
  440. package/src/components/SessionPreview.js +200 -0
  441. package/src/components/Settings/Config.js +1626 -0
  442. package/src/components/Settings/Settings.js +131 -0
  443. package/src/components/Settings/Status.js +230 -0
  444. package/src/components/Settings/Usage.js +341 -0
  445. package/src/components/ShowInIDEPrompt.js +152 -0
  446. package/src/components/SkillImprovementSurvey.js +130 -0
  447. package/src/components/Spinner/FlashingChar.js +52 -0
  448. package/src/components/Spinner/GlimmerMessage.js +329 -0
  449. package/src/components/Spinner/ShimmerChar.js +23 -0
  450. package/src/components/Spinner/SpinnerAnimationRow.js +170 -0
  451. package/src/components/Spinner/SpinnerGlyph.js +70 -0
  452. package/src/components/Spinner/TeammateSpinnerLine.js +171 -0
  453. package/src/components/Spinner/TeammateSpinnerTree.js +269 -0
  454. package/src/components/Spinner/index.js +9 -0
  455. package/src/components/Spinner/teammateSelectHint.js +1 -0
  456. package/src/components/Spinner/useShimmerAnimation.js +22 -0
  457. package/src/components/Spinner/useStalledAnimation.js +63 -0
  458. package/src/components/Spinner/utils.js +78 -0
  459. package/src/components/Spinner.js +474 -0
  460. package/src/components/Stats.js +1000 -0
  461. package/src/components/StatusLine.js +286 -0
  462. package/src/components/StatusNotices.js +50 -0
  463. package/src/components/StructuredDiff/Fallback.js +336 -0
  464. package/src/components/StructuredDiff/colorDiff.js +37 -0
  465. package/src/components/StructuredDiff.js +153 -0
  466. package/src/components/StructuredDiffList.js +9 -0
  467. package/src/components/TagTabs.js +101 -0
  468. package/src/components/TaskListV2.js +333 -0
  469. package/src/components/TeammateViewHeader.js +88 -0
  470. package/src/components/TeleportError.js +191 -0
  471. package/src/components/TeleportProgress.js +131 -0
  472. package/src/components/TeleportRepoMismatchDialog.js +98 -0
  473. package/src/components/TeleportResumeWrapper.js +158 -0
  474. package/src/components/TeleportStash.js +82 -0
  475. package/src/components/TextInput.js +108 -0
  476. package/src/components/ThaddeusHint/PluginHintMenu.js +37 -0
  477. package/src/components/ThemePicker.js +331 -0
  478. package/src/components/ThinkingToggle.js +154 -0
  479. package/src/components/TokenWarning.js +171 -0
  480. package/src/components/ToolUseLoader.js +35 -0
  481. package/src/components/TrustDialog/TrustDialog.js +301 -0
  482. package/src/components/TrustDialog/utils.js +199 -0
  483. package/src/components/UndercoverAutoCallout.js +5 -0
  484. package/src/components/ValidationErrorsList.js +147 -0
  485. package/src/components/VimTextInput.js +136 -0
  486. package/src/components/VirtualMessageList.js +893 -0
  487. package/src/components/WorkflowMultiselectDialog.js +118 -0
  488. package/src/components/WorktreeExitDialog.js +220 -0
  489. package/src/components/agents/AgentDetail.js +227 -0
  490. package/src/components/agents/AgentEditor.js +147 -0
  491. package/src/components/agents/AgentNavigationFooter.js +22 -0
  492. package/src/components/agents/AgentsList.js +436 -0
  493. package/src/components/agents/AgentsMenu.js +849 -0
  494. package/src/components/agents/ColorPicker.js +110 -0
  495. package/src/components/agents/ModelSelector.js +63 -0
  496. package/src/components/agents/SnapshotUpdateDialog.js +14 -0
  497. package/src/components/agents/ToolSelector.js +557 -0
  498. package/src/components/agents/agentFileUtils.js +179 -0
  499. package/src/components/agents/generateAgent.js +161 -0
  500. package/src/components/agents/new-agent-creation/CreateAgentWizard.js +89 -0
  501. package/src/components/agents/new-agent-creation/wizard-steps/ColorStep.js +81 -0
  502. package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStep.js +387 -0
  503. package/src/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.js +63 -0
  504. package/src/components/agents/new-agent-creation/wizard-steps/DescriptionStep.js +126 -0
  505. package/src/components/agents/new-agent-creation/wizard-steps/GenerateStep.js +118 -0
  506. package/src/components/agents/new-agent-creation/wizard-steps/LocationStep.js +80 -0
  507. package/src/components/agents/new-agent-creation/wizard-steps/MemoryStep.js +108 -0
  508. package/src/components/agents/new-agent-creation/wizard-steps/MethodStep.js +80 -0
  509. package/src/components/agents/new-agent-creation/wizard-steps/ModelStep.js +49 -0
  510. package/src/components/agents/new-agent-creation/wizard-steps/PromptStep.js +131 -0
  511. package/src/components/agents/new-agent-creation/wizard-steps/ToolsStep.js +52 -0
  512. package/src/components/agents/new-agent-creation/wizard-steps/TypeStep.js +100 -0
  513. package/src/components/agents/types.js +4 -0
  514. package/src/components/agents/utils.js +14 -0
  515. package/src/components/agents/validateAgent.js +79 -0
  516. package/src/components/design-system/Byline.js +72 -0
  517. package/src/components/design-system/Dialog.js +117 -0
  518. package/src/components/design-system/Divider.js +110 -0
  519. package/src/components/design-system/FuzzyPicker.js +191 -0
  520. package/src/components/design-system/KeyboardShortcutHint.js +68 -0
  521. package/src/components/design-system/ListItem.js +184 -0
  522. package/src/components/design-system/LoadingState.js +69 -0
  523. package/src/components/design-system/Pane.js +69 -0
  524. package/src/components/design-system/ProgressBar.js +63 -0
  525. package/src/components/design-system/Ratchet.js +71 -0
  526. package/src/components/design-system/StatusIcon.js +70 -0
  527. package/src/components/design-system/Tabs.js +269 -0
  528. package/src/components/design-system/ThemeProvider.js +137 -0
  529. package/src/components/design-system/ThemedBox.js +126 -0
  530. package/src/components/design-system/ThemedText.js +60 -0
  531. package/src/components/design-system/color.js +22 -0
  532. package/src/components/diff/DiffDetailView.js +285 -0
  533. package/src/components/diff/DiffDialog.js +387 -0
  534. package/src/components/diff/DiffFileList.js +292 -0
  535. package/src/components/grove/Grove.js +483 -0
  536. package/src/components/hooks/HooksConfigMenu.js +583 -0
  537. package/src/components/hooks/PromptDialog.js +82 -0
  538. package/src/components/hooks/SelectEventMode.js +118 -0
  539. package/src/components/hooks/SelectHookMode.js +101 -0
  540. package/src/components/hooks/SelectMatcherMode.js +131 -0
  541. package/src/components/hooks/ViewHookMode.js +204 -0
  542. package/src/components/mcp/CapabilitiesSection.js +56 -0
  543. package/src/components/mcp/ElicitationDialog.js +945 -0
  544. package/src/components/mcp/MCPAgentServerMenu.js +95 -0
  545. package/src/components/mcp/MCPListPanel.js +505 -0
  546. package/src/components/mcp/MCPReconnect.js +168 -0
  547. package/src/components/mcp/MCPRemoteServerMenu.js +460 -0
  548. package/src/components/mcp/MCPSettings.js +414 -0
  549. package/src/components/mcp/MCPStdioServerMenu.js +95 -0
  550. package/src/components/mcp/MCPToolDetailView.js +219 -0
  551. package/src/components/mcp/MCPToolListView.js +137 -0
  552. package/src/components/mcp/McpParsingWarnings.js +212 -0
  553. package/src/components/mcp/index.js +8 -0
  554. package/src/components/mcp/utils/reconnectHelpers.js +35 -0
  555. package/src/components/memory/MemoryFileSelector.js +454 -0
  556. package/src/components/memory/MemoryUpdateNotification.js +43 -0
  557. package/src/components/messageActions.js +418 -0
  558. package/src/components/messages/AdvisorMessage.js +152 -0
  559. package/src/components/messages/AssistantRedactedThinkingMessage.js +28 -0
  560. package/src/components/messages/AssistantTextMessage.js +287 -0
  561. package/src/components/messages/AssistantThinkingMessage.js +70 -0
  562. package/src/components/messages/AssistantToolUseMessage.js +324 -0
  563. package/src/components/messages/AttachmentMessage.js +418 -0
  564. package/src/components/messages/CollapsedReadSearchContent.js +363 -0
  565. package/src/components/messages/CompactBoundaryMessage.js +19 -0
  566. package/src/components/messages/GroupedToolUseContent.js +37 -0
  567. package/src/components/messages/HighlightedThinkingText.js +165 -0
  568. package/src/components/messages/HookProgressMessage.js +111 -0
  569. package/src/components/messages/PlanApprovalMessage.js +213 -0
  570. package/src/components/messages/RateLimitMessage.js +149 -0
  571. package/src/components/messages/ShutdownMessage.js +124 -0
  572. package/src/components/messages/SnipBoundaryMessage.js +7 -0
  573. package/src/components/messages/SystemAPIErrorMessage.js +136 -0
  574. package/src/components/messages/SystemTextMessage.js +842 -0
  575. package/src/components/messages/TaskAssignmentMessage.js +72 -0
  576. package/src/components/messages/UserAgentNotificationMessage.js +78 -0
  577. package/src/components/messages/UserBashInputMessage.js +52 -0
  578. package/src/components/messages/UserBashOutputMessage.js +55 -0
  579. package/src/components/messages/UserChannelMessage.js +130 -0
  580. package/src/components/messages/UserCommandMessage.js +107 -0
  581. package/src/components/messages/UserCrossSessionMessage.js +11 -0
  582. package/src/components/messages/UserForkBoilerplateMessage.js +11 -0
  583. package/src/components/messages/UserGitHubWebhookMessage.js +12 -0
  584. package/src/components/messages/UserImageMessage.js +54 -0
  585. package/src/components/messages/UserLocalCommandOutputMessage.js +170 -0
  586. package/src/components/messages/UserMemoryInputMessage.js +73 -0
  587. package/src/components/messages/UserPlanMessage.js +38 -0
  588. package/src/components/messages/UserPromptMessage.js +63 -0
  589. package/src/components/messages/UserResourceUpdateMessage.js +102 -0
  590. package/src/components/messages/UserTeammateMessage.js +156 -0
  591. package/src/components/messages/UserTextMessage.js +270 -0
  592. package/src/components/messages/UserToolResultMessage/RejectedPlanMessage.js +28 -0
  593. package/src/components/messages/UserToolResultMessage/RejectedToolUseMessage.js +17 -0
  594. package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.js +17 -0
  595. package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.js +92 -0
  596. package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.js +74 -0
  597. package/src/components/messages/UserToolResultMessage/UserToolResultMessage.js +84 -0
  598. package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.js +58 -0
  599. package/src/components/messages/UserToolResultMessage/utils.js +43 -0
  600. package/src/components/messages/nullRenderingAttachments.js +58 -0
  601. package/src/components/messages/teamMemCollapsed.js +142 -0
  602. package/src/components/messages/teamMemSaved.js +16 -0
  603. package/src/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.js +659 -0
  604. package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.js +219 -0
  605. package/src/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.js +227 -0
  606. package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.js +175 -0
  607. package/src/components/permissions/AskUserQuestionPermissionRequest/QuestionView.js +444 -0
  608. package/src/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.js +137 -0
  609. package/src/components/permissions/AskUserQuestionPermissionRequest/use-multiple-choice-state.js +100 -0
  610. package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.js +404 -0
  611. package/src/components/permissions/BashPermissionRequest/bashToolUseOptions.js +110 -0
  612. package/src/components/permissions/ComputerUseApproval/ComputerUseApproval.js +449 -0
  613. package/src/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.js +126 -0
  614. package/src/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.js +653 -0
  615. package/src/components/permissions/FallbackPermissionRequest.js +349 -0
  616. package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +185 -0
  617. package/src/components/permissions/FilePermissionDialog/FilePermissionDialog.js +108 -0
  618. package/src/components/permissions/FilePermissionDialog/ideDiffConfig.js +13 -0
  619. package/src/components/permissions/FilePermissionDialog/permissionOptions.js +137 -0
  620. package/src/components/permissions/FilePermissionDialog/useFilePermissionDialog.js +131 -0
  621. package/src/components/permissions/FilePermissionDialog/usePermissionHandler.js +86 -0
  622. package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +164 -0
  623. package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +79 -0
  624. package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +113 -0
  625. package/src/components/permissions/MonitorPermissionRequest/MonitorPermissionRequest.js +7 -0
  626. package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.js +164 -0
  627. package/src/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.js +218 -0
  628. package/src/components/permissions/PermissionDecisionDebugInfo.js +467 -0
  629. package/src/components/permissions/PermissionDialog.js +55 -0
  630. package/src/components/permissions/PermissionExplanation.js +269 -0
  631. package/src/components/permissions/PermissionPrompt.js +316 -0
  632. package/src/components/permissions/PermissionRequest.js +159 -0
  633. package/src/components/permissions/PermissionRequestTitle.js +58 -0
  634. package/src/components/permissions/PermissionRuleExplanation.js +110 -0
  635. package/src/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.js +178 -0
  636. package/src/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.js +73 -0
  637. package/src/components/permissions/ReviewArtifactPermissionRequest/ReviewArtifactPermissionRequest.js +7 -0
  638. package/src/components/permissions/SandboxPermissionRequest.js +162 -0
  639. package/src/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.js +228 -0
  640. package/src/components/permissions/SkillPermissionRequest/SkillPermissionRequest.js +385 -0
  641. package/src/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.js +259 -0
  642. package/src/components/permissions/WorkerBadge.js +44 -0
  643. package/src/components/permissions/WorkerPendingPermission.js +107 -0
  644. package/src/components/permissions/hooks.js +163 -0
  645. package/src/components/permissions/rules/AddPermissionRules.js +171 -0
  646. package/src/components/permissions/rules/AddWorkspaceDirectory.js +335 -0
  647. package/src/components/permissions/rules/PermissionRuleDescription.js +78 -0
  648. package/src/components/permissions/rules/PermissionRuleInput.js +136 -0
  649. package/src/components/permissions/rules/PermissionRuleList.js +1190 -0
  650. package/src/components/permissions/rules/RecentDenialsTab.js +205 -0
  651. package/src/components/permissions/rules/RemoveWorkspaceDirectory.js +103 -0
  652. package/src/components/permissions/rules/WorkspaceTab.js +133 -0
  653. package/src/components/permissions/shellPermissionHelpers.js +112 -0
  654. package/src/components/permissions/useShellPermissionFeedback.js +108 -0
  655. package/src/components/permissions/utils.js +14 -0
  656. package/src/components/sandbox/SandboxConfigTab.js +48 -0
  657. package/src/components/sandbox/SandboxDependenciesTab.js +123 -0
  658. package/src/components/sandbox/SandboxDoctorSection.js +47 -0
  659. package/src/components/sandbox/SandboxOverridesTab.js +193 -0
  660. package/src/components/sandbox/SandboxSettings.js +297 -0
  661. package/src/components/shell/ExpandShellOutputContext.js +33 -0
  662. package/src/components/shell/OutputLine.js +110 -0
  663. package/src/components/shell/ShellProgressMessage.js +144 -0
  664. package/src/components/shell/ShellTimeDisplay.js +72 -0
  665. package/src/components/skills/SkillsMenu.js +239 -0
  666. package/src/components/tasks/AsyncAgentDetailDialog.js +235 -0
  667. package/src/components/tasks/BackgroundTask.js +364 -0
  668. package/src/components/tasks/BackgroundTaskStatus.js +419 -0
  669. package/src/components/tasks/BackgroundTasksDialog.js +494 -0
  670. package/src/components/tasks/DreamDetailDialog.js +251 -0
  671. package/src/components/tasks/InProcessTeammateDetailDialog.js +275 -0
  672. package/src/components/tasks/MonitorMcpDetailDialog.js +7 -0
  673. package/src/components/tasks/RemoteSessionDetailDialog.js +868 -0
  674. package/src/components/tasks/RemoteSessionProgress.js +249 -0
  675. package/src/components/tasks/ShellDetailDialog.js +403 -0
  676. package/src/components/tasks/ShellProgress.js +77 -0
  677. package/src/components/tasks/WorkflowDetailDialog.js +7 -0
  678. package/src/components/tasks/renderToolActivity.js +29 -0
  679. package/src/components/tasks/taskStatusUtils.js +94 -0
  680. package/src/components/teams/TeamStatus.js +77 -0
  681. package/src/components/teams/TeamsDialog.js +673 -0
  682. package/src/components/ui/OrderedList.js +66 -0
  683. package/src/components/ui/OrderedListItem.js +41 -0
  684. package/src/components/ui/TreeSelect.js +300 -0
  685. package/src/components/wizard/WizardDialogLayout.js +48 -0
  686. package/src/components/wizard/WizardNavigationFooter.js +11 -0
  687. package/src/components/wizard/WizardProvider.js +217 -0
  688. package/src/components/wizard/index.js +4 -0
  689. package/src/components/wizard/useWizard.js +9 -0
  690. package/src/constants/apiLimits.js +81 -0
  691. package/src/constants/betas.js +45 -0
  692. package/src/constants/common.js +29 -0
  693. package/src/constants/cyberRiskInstruction.js +23 -0
  694. package/src/constants/errorIds.js +14 -0
  695. package/src/constants/figures.js +38 -0
  696. package/src/constants/files.js +150 -0
  697. package/src/constants/github-app.js +139 -0
  698. package/src/constants/identity.js +112 -0
  699. package/src/constants/keys.js +10 -0
  700. package/src/constants/messages.js +1 -0
  701. package/src/constants/oauth.js +175 -0
  702. package/src/constants/outputStyles.js +162 -0
  703. package/src/constants/product.js +54 -0
  704. package/src/constants/prompts.js +994 -0
  705. package/src/constants/spinnerVerbs.js +98 -0
  706. package/src/constants/system.js +77 -0
  707. package/src/constants/systemPromptSections.js +39 -0
  708. package/src/constants/toolLimits.js +50 -0
  709. package/src/constants/tools.js +103 -0
  710. package/src/constants/turnCompletionVerbs.js +12 -0
  711. package/src/constants/xml.js +73 -0
  712. package/src/context/QueuedMessageContext.js +51 -0
  713. package/src/context/fpsMetrics.js +22 -0
  714. package/src/context/mailbox.js +35 -0
  715. package/src/context/modalContext.js +34 -0
  716. package/src/context/notifications.js +199 -0
  717. package/src/context/overlayContext.js +149 -0
  718. package/src/context/promptOverlayContext.js +118 -0
  719. package/src/context/stats.js +207 -0
  720. package/src/context/voice.js +74 -0
  721. package/src/context.js +146 -0
  722. package/src/coordinator/coordinatorMode.js +345 -0
  723. package/src/coordinator/workerAgent.js +24 -0
  724. package/src/cost-tracker.js +208 -0
  725. package/src/costHook.js +17 -0
  726. package/src/daemon/main.js +19 -0
  727. package/src/dialogLaunchers.js +77 -0
  728. package/src/entrypoints/agentSdkTypes.js +202 -0
  729. package/src/entrypoints/cli.js +226 -0
  730. package/src/entrypoints/init.js +265 -0
  731. package/src/entrypoints/mcp.js +141 -0
  732. package/src/entrypoints/sandboxTypes.js +112 -0
  733. package/src/entrypoints/sdk/controlSchemas.js +452 -0
  734. package/src/entrypoints/sdk/controlTypes.js +1 -0
  735. package/src/entrypoints/sdk/coreSchemas.js +1331 -0
  736. package/src/entrypoints/sdk/coreTypes.generated.js +3 -0
  737. package/src/entrypoints/sdk/coreTypes.js +49 -0
  738. package/src/entrypoints/sdk/runtimeTypes.js +1 -0
  739. package/src/entrypoints/sdk/sdkUtilityTypes.js +1 -0
  740. package/src/entrypoints/sdk/settingsTypes.generated.js +1 -0
  741. package/src/entrypoints/sdk/toolTypes.js +1 -0
  742. package/src/environment-runner/main.js +8 -0
  743. package/src/history.js +386 -0
  744. package/src/hooks/fileSuggestions.js +635 -0
  745. package/src/hooks/notifs/useAntOrgWarningNotification.js +5 -0
  746. package/src/hooks/notifs/useAutoModeUnavailableNotification.js +47 -0
  747. package/src/hooks/notifs/useCanSwitchToExistingSubscription.js +58 -0
  748. package/src/hooks/notifs/useDeprecationWarningNotification.js +43 -0
  749. package/src/hooks/notifs/useFastModeNotification.js +164 -0
  750. package/src/hooks/notifs/useIDEStatusIndicator.js +174 -0
  751. package/src/hooks/notifs/useInstallMessages.js +27 -0
  752. package/src/hooks/notifs/useLspInitializationNotification.js +144 -0
  753. package/src/hooks/notifs/useMcpConnectivityStatus.js +81 -0
  754. package/src/hooks/notifs/useModelMigrationNotifications.js +53 -0
  755. package/src/hooks/notifs/useNpmDeprecationNotification.js +25 -0
  756. package/src/hooks/notifs/usePluginAutoupdateNotification.js +83 -0
  757. package/src/hooks/notifs/usePluginInstallationStatus.js +128 -0
  758. package/src/hooks/notifs/useRateLimitWarningNotification.js +119 -0
  759. package/src/hooks/notifs/useSettingsErrors.js +64 -0
  760. package/src/hooks/notifs/useStartupNotification.js +33 -0
  761. package/src/hooks/notifs/useTeammateShutdownNotification.js +64 -0
  762. package/src/hooks/renderPlaceholder.js +26 -0
  763. package/src/hooks/toolPermission/PermissionContext.js +211 -0
  764. package/src/hooks/toolPermission/handlers/coordinatorHandler.js +44 -0
  765. package/src/hooks/toolPermission/handlers/interactiveHandler.js +397 -0
  766. package/src/hooks/toolPermission/handlers/swarmWorkerHandler.js +108 -0
  767. package/src/hooks/toolPermission/permissionLogging.js +145 -0
  768. package/src/hooks/unifiedSuggestions.js +130 -0
  769. package/src/hooks/useAfterFirstRender.js +12 -0
  770. package/src/hooks/useApiKeyVerification.js +63 -0
  771. package/src/hooks/useArrowKeyHistory.js +203 -0
  772. package/src/hooks/useAssistantHistory.js +193 -0
  773. package/src/hooks/useAwaySummary.js +105 -0
  774. package/src/hooks/useBackgroundTaskNavigation.js +204 -0
  775. package/src/hooks/useBlink.js +28 -0
  776. package/src/hooks/useCanUseTool.js +193 -0
  777. package/src/hooks/useCancelRequest.js +195 -0
  778. package/src/hooks/useChromeExtensionNotification.js +50 -0
  779. package/src/hooks/useClipboardImageHint.js +59 -0
  780. package/src/hooks/useCommandKeybindings.js +87 -0
  781. package/src/hooks/useCommandQueue.js +10 -0
  782. package/src/hooks/useCopyOnSelect.js +88 -0
  783. package/src/hooks/useDeferredHookMessages.js +43 -0
  784. package/src/hooks/useDiffData.js +69 -0
  785. package/src/hooks/useDiffInIDE.js +252 -0
  786. package/src/hooks/useDirectConnect.js +150 -0
  787. package/src/hooks/useDoublePress.js +44 -0
  788. package/src/hooks/useDynamicConfig.js +17 -0
  789. package/src/hooks/useElapsedTime.js +25 -0
  790. package/src/hooks/useExitOnCtrlCD.js +57 -0
  791. package/src/hooks/useExitOnCtrlCDWithKeybindings.js +17 -0
  792. package/src/hooks/useFileHistorySnapshotInit.js +14 -0
  793. package/src/hooks/useGlobalKeybindings.js +213 -0
  794. package/src/hooks/useHistorySearch.js +241 -0
  795. package/src/hooks/useIDEIntegration.js +56 -0
  796. package/src/hooks/useIdeAtMentioned.js +51 -0
  797. package/src/hooks/useIdeConnectionStatus.js +21 -0
  798. package/src/hooks/useIdeLogging.js +29 -0
  799. package/src/hooks/useIdeSelection.js +106 -0
  800. package/src/hooks/useInboxPoller.js +709 -0
  801. package/src/hooks/useInputBuffer.js +73 -0
  802. package/src/hooks/useIssueFlagBanner.js +115 -0
  803. package/src/hooks/useLogMessages.js +98 -0
  804. package/src/hooks/useLspPluginRecommendation.js +176 -0
  805. package/src/hooks/useMailboxBridge.js +15 -0
  806. package/src/hooks/useMainLoopModel.js +25 -0
  807. package/src/hooks/useManagePlugins.js +261 -0
  808. package/src/hooks/useMemoryUsage.js +28 -0
  809. package/src/hooks/useMergedClients.js +11 -0
  810. package/src/hooks/useMergedCommands.js +10 -0
  811. package/src/hooks/useMergedTools.js +32 -0
  812. package/src/hooks/useMinDisplayTime.js +26 -0
  813. package/src/hooks/useNotifyAfterTimeout.js +51 -0
  814. package/src/hooks/useOfficialMarketplaceNotification.js +47 -0
  815. package/src/hooks/usePasteHandler.js +195 -0
  816. package/src/hooks/usePluginRecommendationBase.js +101 -0
  817. package/src/hooks/usePrStatus.js +91 -0
  818. package/src/hooks/usePromptSuggestion.js +128 -0
  819. package/src/hooks/usePromptsFromClaudeInChrome.js +66 -0
  820. package/src/hooks/useQueueProcessor.js +46 -0
  821. package/src/hooks/useRemoteSession.js +431 -0
  822. package/src/hooks/useReplBridge.js +715 -0
  823. package/src/hooks/useSSHSession.js +167 -0
  824. package/src/hooks/useScheduledTasks.js +104 -0
  825. package/src/hooks/useSearchInput.js +302 -0
  826. package/src/hooks/useSessionBackgrounding.js +132 -0
  827. package/src/hooks/useSettings.js +10 -0
  828. package/src/hooks/useSettingsChange.js +13 -0
  829. package/src/hooks/useSkillImprovementSurvey.js +69 -0
  830. package/src/hooks/useSkillsChange.js +51 -0
  831. package/src/hooks/useSwarmInitialization.js +67 -0
  832. package/src/hooks/useSwarmPermissionPoller.js +215 -0
  833. package/src/hooks/useTaskListWatcher.js +157 -0
  834. package/src/hooks/useTasksV2.js +220 -0
  835. package/src/hooks/useTeammateViewAutoExit.js +55 -0
  836. package/src/hooks/useTeleportResume.js +81 -0
  837. package/src/hooks/useTerminalSize.js +9 -0
  838. package/src/hooks/useTextInput.js +397 -0
  839. package/src/hooks/useThaddeusHintRecommendation.js +117 -0
  840. package/src/hooks/useTimeout.js +10 -0
  841. package/src/hooks/useTurnDiffs.js +160 -0
  842. package/src/hooks/useTypeahead.js +1250 -0
  843. package/src/hooks/useUpdateNotification.js +21 -0
  844. package/src/hooks/useVimInput.js +232 -0
  845. package/src/hooks/useVirtualScroll.js +627 -0
  846. package/src/hooks/useVoice.js +952 -0
  847. package/src/hooks/useVoiceEnabled.js +21 -0
  848. package/src/hooks/useVoiceIntegration.js +629 -0
  849. package/src/infrastructure/audit.js +210 -0
  850. package/src/infrastructure/guardrails.js +513 -0
  851. package/src/infrastructure/index.js +11 -0
  852. package/src/ink/Ansi.js +269 -0
  853. package/src/ink/bidi.js +117 -0
  854. package/src/ink/clearTerminal.js +58 -0
  855. package/src/ink/colorize.js +198 -0
  856. package/src/ink/components/AlternateScreen.js +74 -0
  857. package/src/ink/components/App.js +562 -0
  858. package/src/ink/components/AppContext.js +11 -0
  859. package/src/ink/components/Box.js +155 -0
  860. package/src/ink/components/Button.js +166 -0
  861. package/src/ink/components/ClockContext.js +108 -0
  862. package/src/ink/components/CursorDeclarationContext.js +3 -0
  863. package/src/ink/components/ErrorOverview.js +50 -0
  864. package/src/ink/components/Link.js +34 -0
  865. package/src/ink/components/Newline.js +30 -0
  866. package/src/ink/components/NoSelect.js +57 -0
  867. package/src/ink/components/RawAnsi.js +46 -0
  868. package/src/ink/components/ScrollBox.js +171 -0
  869. package/src/ink/components/Spacer.js +20 -0
  870. package/src/ink/components/StdinContext.js +16 -0
  871. package/src/ink/components/TerminalFocusContext.js +45 -0
  872. package/src/ink/components/TerminalSizeContext.js +3 -0
  873. package/src/ink/components/Text.js +195 -0
  874. package/src/ink/constants.js +2 -0
  875. package/src/ink/dom.js +298 -0
  876. package/src/ink/events/click-event.js +36 -0
  877. package/src/ink/events/dispatcher.js +172 -0
  878. package/src/ink/events/emitter.js +31 -0
  879. package/src/ink/events/event-handlers.js +30 -0
  880. package/src/ink/events/event.js +9 -0
  881. package/src/ink/events/focus-event.js +16 -0
  882. package/src/ink/events/input-event.js +161 -0
  883. package/src/ink/events/keyboard-event.js +46 -0
  884. package/src/ink/events/terminal-event.js +78 -0
  885. package/src/ink/events/terminal-focus-event.js +15 -0
  886. package/src/ink/focus.js +158 -0
  887. package/src/ink/frame.js +30 -0
  888. package/src/ink/get-max-width.js +23 -0
  889. package/src/ink/hit-test.js +113 -0
  890. package/src/ink/hooks/use-animation-frame.js +48 -0
  891. package/src/ink/hooks/use-app.js +7 -0
  892. package/src/ink/hooks/use-declared-cursor.js +60 -0
  893. package/src/ink/hooks/use-input.js +70 -0
  894. package/src/ink/hooks/use-interval.js +54 -0
  895. package/src/ink/hooks/use-search-highlight.js +32 -0
  896. package/src/ink/hooks/use-selection.js +60 -0
  897. package/src/ink/hooks/use-stdin.js +7 -0
  898. package/src/ink/hooks/use-tab-status.js +57 -0
  899. package/src/ink/hooks/use-terminal-focus.js +15 -0
  900. package/src/ink/hooks/use-terminal-title.js +29 -0
  901. package/src/ink/hooks/use-terminal-viewport.js +77 -0
  902. package/src/ink/ink.js +1645 -0
  903. package/src/ink/instances.js +7 -0
  904. package/src/ink/layout/engine.js +4 -0
  905. package/src/ink/layout/geometry.js +61 -0
  906. package/src/ink/layout/node.js +62 -0
  907. package/src/ink/layout/yoga.js +237 -0
  908. package/src/ink/line-width-cache.js +19 -0
  909. package/src/ink/log-update.js +583 -0
  910. package/src/ink/measure-element.js +8 -0
  911. package/src/ink/measure-text.js +35 -0
  912. package/src/ink/node-cache.js +30 -0
  913. package/src/ink/optimizer.js +81 -0
  914. package/src/ink/output.js +556 -0
  915. package/src/ink/parse-keypress.js +695 -0
  916. package/src/ink/reconciler.js +384 -0
  917. package/src/ink/render-border.js +134 -0
  918. package/src/ink/render-node-to-output.js +1216 -0
  919. package/src/ink/render-to-screen.js +171 -0
  920. package/src/ink/renderer.js +129 -0
  921. package/src/ink/root.js +80 -0
  922. package/src/ink/screen.js +1132 -0
  923. package/src/ink/searchHighlight.js +78 -0
  924. package/src/ink/selection.js +792 -0
  925. package/src/ink/squash-text-nodes.js +56 -0
  926. package/src/ink/stringWidth.js +200 -0
  927. package/src/ink/styles.js +299 -0
  928. package/src/ink/supports-hyperlinks.js +40 -0
  929. package/src/ink/tabstops.js +39 -0
  930. package/src/ink/terminal-focus-state.js +35 -0
  931. package/src/ink/terminal-querier.js +173 -0
  932. package/src/ink/terminal.js +208 -0
  933. package/src/ink/termio/ansi.js +70 -0
  934. package/src/ink/termio/csi.js +260 -0
  935. package/src/ink/termio/dec.js +53 -0
  936. package/src/ink/termio/esc.js +55 -0
  937. package/src/ink/termio/osc.js +432 -0
  938. package/src/ink/termio/parser.js +356 -0
  939. package/src/ink/termio/sgr.js +292 -0
  940. package/src/ink/termio/tokenize.js +264 -0
  941. package/src/ink/termio/types.js +55 -0
  942. package/src/ink/termio.js +24 -0
  943. package/src/ink/useTerminalNotification.js +57 -0
  944. package/src/ink/warn.js +10 -0
  945. package/src/ink/widest-line.js +14 -0
  946. package/src/ink/wrap-text.js +54 -0
  947. package/src/ink/wrapAnsi.js +6 -0
  948. package/src/ink.js +50 -0
  949. package/src/integrations/credentialStore.js +176 -0
  950. package/src/integrations/index.js +5 -0
  951. package/src/integrations/integrationManager.js +180 -0
  952. package/src/integrations/providers/BaseProvider.js +180 -0
  953. package/src/integrations/providers/GitHubProvider.js +217 -0
  954. package/src/integrations/providers/GmailProvider.js +204 -0
  955. package/src/integrations/providers/GoogleCalendarProvider.js +113 -0
  956. package/src/integrations/providers/HubSpotProvider.js +159 -0
  957. package/src/integrations/providers/JiraProvider.js +216 -0
  958. package/src/integrations/providers/NotionProvider.js +221 -0
  959. package/src/integrations/providers/QuickBooksProvider.js +176 -0
  960. package/src/integrations/providers/SlackProvider.js +174 -0
  961. package/src/integrations/providers/StripeProvider.js +206 -0
  962. package/src/integrations/providers/TwilioProvider.js +239 -0
  963. package/src/integrations/providers/_template.js +112 -0
  964. package/src/integrations/types.js +7 -0
  965. package/src/interactiveHelpers.js +308 -0
  966. package/src/jobs/classifier.js +6 -0
  967. package/src/keybindings/KeybindingContext.js +184 -0
  968. package/src/keybindings/KeybindingProviderSetup.js +259 -0
  969. package/src/keybindings/defaultBindings.js +333 -0
  970. package/src/keybindings/loadUserBindings.js +393 -0
  971. package/src/keybindings/match.js +111 -0
  972. package/src/keybindings/parser.js +184 -0
  973. package/src/keybindings/reservedShortcuts.js +109 -0
  974. package/src/keybindings/resolver.js +182 -0
  975. package/src/keybindings/schema.js +205 -0
  976. package/src/keybindings/shortcutFormat.js +48 -0
  977. package/src/keybindings/template.js +40 -0
  978. package/src/keybindings/useKeybinding.js +161 -0
  979. package/src/keybindings/useShortcutDisplay.js +43 -0
  980. package/src/keybindings/validate.js +395 -0
  981. package/src/main.js +4128 -0
  982. package/src/memdir/findRelevantMemories.js +99 -0
  983. package/src/memdir/memdir.js +406 -0
  984. package/src/memdir/memoryAge.js +52 -0
  985. package/src/memdir/memoryScan.js +65 -0
  986. package/src/memdir/memoryShapeTelemetry.js +8 -0
  987. package/src/memdir/memoryTypes.js +260 -0
  988. package/src/memdir/paths.js +235 -0
  989. package/src/memdir/teamMemPaths.js +261 -0
  990. package/src/memdir/teamMemPrompts.js +82 -0
  991. package/src/migrations/migrateAutoUpdatesToSettings.js +47 -0
  992. package/src/migrations/migrateBypassPermissionsAcceptedToSettings.js +32 -0
  993. package/src/migrations/migrateEnableAllProjectMcpServersToSettings.js +83 -0
  994. package/src/migrations/migrateFennecToOpus.js +39 -0
  995. package/src/migrations/migrateLegacyOpusToCurrent.js +44 -0
  996. package/src/migrations/migrateOpusToOpus1m.js +31 -0
  997. package/src/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.js +23 -0
  998. package/src/migrations/migrateSonnet1mToSonnet45.js +38 -0
  999. package/src/migrations/migrateSonnet45ToSonnet46.js +48 -0
  1000. package/src/migrations/resetAutoModeOptInForDefaultOffer.js +47 -0
  1001. package/src/migrations/resetProToOpusDefault.js +46 -0
  1002. package/src/moreright/useMoreRight.js +13 -0
  1003. package/src/native-ts/color-diff/index.js +819 -0
  1004. package/src/native-ts/file-index/index.js +328 -0
  1005. package/src/native-ts/yoga-layout/enums.js +101 -0
  1006. package/src/native-ts/yoga-layout/index.js +2113 -0
  1007. package/src/outputStyles/loadOutputStylesDir.js +71 -0
  1008. package/src/plugins/builtinPlugins.js +132 -0
  1009. package/src/plugins/bundled/index.js +22 -0
  1010. package/src/proactive/index.js +138 -0
  1011. package/src/proactive/useProactive.js +82 -0
  1012. package/src/projectOnboardingState.js +61 -0
  1013. package/src/query/config.js +17 -0
  1014. package/src/query/deps.js +12 -0
  1015. package/src/query/stopHooks.js +332 -0
  1016. package/src/query/tokenBudget.js +49 -0
  1017. package/src/query.js +1264 -0
  1018. package/src/remote/RemoteSessionManager.js +172 -0
  1019. package/src/remote/SessionsWebSocket.js +308 -0
  1020. package/src/remote/remotePermissionBridge.js +70 -0
  1021. package/src/remote/sdkMessageAdapter.js +227 -0
  1022. package/src/replLauncher.js +7 -0
  1023. package/src/schemas/hooks.js +174 -0
  1024. package/src/screens/Doctor.js +580 -0
  1025. package/src/screens/REPL.js +4500 -0
  1026. package/src/screens/ResumeConversation.js +339 -0
  1027. package/src/self-hosted-runner/main.js +8 -0
  1028. package/src/server/backends/dangerousBackend.js +8 -0
  1029. package/src/server/connectHeadless.js +6 -0
  1030. package/src/server/createDirectConnectSession.js +62 -0
  1031. package/src/server/directConnectManager.js +153 -0
  1032. package/src/server/lockfile.js +11 -0
  1033. package/src/server/parseConnectUrl.js +20 -0
  1034. package/src/server/server.js +12 -0
  1035. package/src/server/serverBanner.js +9 -0
  1036. package/src/server/serverLog.js +11 -0
  1037. package/src/server/sessionManager.js +19 -0
  1038. package/src/server/types.js +7 -0
  1039. package/src/services/AgentSummary/agentSummary.js +147 -0
  1040. package/src/services/MagicDocs/magicDocs.js +193 -0
  1041. package/src/services/MagicDocs/prompts.js +110 -0
  1042. package/src/services/PromptSuggestion/promptSuggestion.js +402 -0
  1043. package/src/services/PromptSuggestion/speculation.js +643 -0
  1044. package/src/services/SessionMemory/prompts.js +254 -0
  1045. package/src/services/SessionMemory/sessionMemory.js +358 -0
  1046. package/src/services/SessionMemory/sessionMemoryUtils.js +157 -0
  1047. package/src/services/analytics/config.js +27 -0
  1048. package/src/services/analytics/datadog.js +26 -0
  1049. package/src/services/analytics/firstPartyEventLogger.js +65 -0
  1050. package/src/services/analytics/firstPartyEventLoggingExporter.js +595 -0
  1051. package/src/services/analytics/growthbook.js +103 -0
  1052. package/src/services/analytics/index.js +91 -0
  1053. package/src/services/analytics/metadata.js +696 -0
  1054. package/src/services/analytics/sink.js +19 -0
  1055. package/src/services/analytics/sinkKillswitch.js +19 -0
  1056. package/src/services/api/adminRequests.js +57 -0
  1057. package/src/services/api/bootstrap.js +118 -0
  1058. package/src/services/api/claude.js +2466 -0
  1059. package/src/services/api/client.js +335 -0
  1060. package/src/services/api/dumpPrompts.js +174 -0
  1061. package/src/services/api/emptyUsage.js +20 -0
  1062. package/src/services/api/errorUtils.js +203 -0
  1063. package/src/services/api/errors.js +926 -0
  1064. package/src/services/api/filesApi.js +523 -0
  1065. package/src/services/api/firstTokenDate.js +49 -0
  1066. package/src/services/api/grove.js +44 -0
  1067. package/src/services/api/logging.js +484 -0
  1068. package/src/services/api/metricsOptOut.js +15 -0
  1069. package/src/services/api/overageCreditGrant.js +123 -0
  1070. package/src/services/api/promptCacheBreakDetection.js +510 -0
  1071. package/src/services/api/referral.js +219 -0
  1072. package/src/services/api/sessionIngress.js +358 -0
  1073. package/src/services/api/ultrareviewQuota.js +29 -0
  1074. package/src/services/api/usage.js +31 -0
  1075. package/src/services/api/withRetry.js +587 -0
  1076. package/src/services/api/xai/anthropic-shim.js +885 -0
  1077. package/src/services/api/xai/brightDataSearch.js +161 -0
  1078. package/src/services/api/xai/thaddeus-engine.js +605 -0
  1079. package/src/services/api/xai/xai-client.js +276 -0
  1080. package/src/services/autoDream/autoDream.js +244 -0
  1081. package/src/services/autoDream/config.js +17 -0
  1082. package/src/services/autoDream/consolidationLock.js +122 -0
  1083. package/src/services/autoDream/consolidationPrompt.js +55 -0
  1084. package/src/services/awaySummary.js +61 -0
  1085. package/src/services/claudeAiLimits.js +331 -0
  1086. package/src/services/claudeAiLimitsHook.js +15 -0
  1087. package/src/services/compact/apiMicrocompact.js +97 -0
  1088. package/src/services/compact/autoCompact.js +234 -0
  1089. package/src/services/compact/cachedMCConfig.js +5 -0
  1090. package/src/services/compact/compact.js +1256 -0
  1091. package/src/services/compact/compactWarningHook.js +12 -0
  1092. package/src/services/compact/compactWarningState.js +15 -0
  1093. package/src/services/compact/grouping.js +58 -0
  1094. package/src/services/compact/microCompact.js +414 -0
  1095. package/src/services/compact/postCompactCleanup.js +70 -0
  1096. package/src/services/compact/prompt.js +325 -0
  1097. package/src/services/compact/reactiveCompact.js +20 -0
  1098. package/src/services/compact/sessionMemoryCompact.js +467 -0
  1099. package/src/services/compact/snipCompact.js +23 -0
  1100. package/src/services/compact/snipProjection.js +11 -0
  1101. package/src/services/compact/timeBasedMCConfig.js +11 -0
  1102. package/src/services/contextCollapse/index.js +33 -0
  1103. package/src/services/contextCollapse/operations.js +5 -0
  1104. package/src/services/contextCollapse/persist.js +5 -0
  1105. package/src/services/diagnosticTracking.js +282 -0
  1106. package/src/services/elevenlabsTTS.js +245 -0
  1107. package/src/services/extractMemories/extractMemories.js +442 -0
  1108. package/src/services/extractMemories/prompts.js +129 -0
  1109. package/src/services/internalLogging.js +68 -0
  1110. package/src/services/lsp/LSPClient.js +306 -0
  1111. package/src/services/lsp/LSPDiagnosticRegistry.js +277 -0
  1112. package/src/services/lsp/LSPServerInstance.js +388 -0
  1113. package/src/services/lsp/LSPServerManager.js +305 -0
  1114. package/src/services/lsp/config.js +57 -0
  1115. package/src/services/lsp/manager.js +246 -0
  1116. package/src/services/lsp/passiveFeedback.js +226 -0
  1117. package/src/services/mcp/InProcessTransport.js +54 -0
  1118. package/src/services/mcp/MCPConnectionManager.js +50 -0
  1119. package/src/services/mcp/SdkControlTransport.js +115 -0
  1120. package/src/services/mcp/auth.js +1882 -0
  1121. package/src/services/mcp/channelAllowlist.js +57 -0
  1122. package/src/services/mcp/channelNotification.js +235 -0
  1123. package/src/services/mcp/channelPermissions.js +192 -0
  1124. package/src/services/mcp/claudeai.js +123 -0
  1125. package/src/services/mcp/client.js +2478 -0
  1126. package/src/services/mcp/config.js +1271 -0
  1127. package/src/services/mcp/elicitationHandler.js +192 -0
  1128. package/src/services/mcp/envExpansion.js +30 -0
  1129. package/src/services/mcp/headersHelper.js +93 -0
  1130. package/src/services/mcp/mcpStringUtils.js +85 -0
  1131. package/src/services/mcp/normalization.js +21 -0
  1132. package/src/services/mcp/oauthPort.js +69 -0
  1133. package/src/services/mcp/officialRegistry.js +20 -0
  1134. package/src/services/mcp/types.js +94 -0
  1135. package/src/services/mcp/useManageMCPConnections.js +818 -0
  1136. package/src/services/mcp/utils.js +433 -0
  1137. package/src/services/mcp/vscodeSdkMcp.js +69 -0
  1138. package/src/services/mcp/xaa.js +342 -0
  1139. package/src/services/mcp/xaaIdpLogin.js +377 -0
  1140. package/src/services/mcpServerApproval.js +30 -0
  1141. package/src/services/mockRateLimits.js +666 -0
  1142. package/src/services/notifier.js +114 -0
  1143. package/src/services/oauth/auth-code-listener.js +165 -0
  1144. package/src/services/oauth/client.js +397 -0
  1145. package/src/services/oauth/crypto.js +19 -0
  1146. package/src/services/oauth/getOauthProfile.js +48 -0
  1147. package/src/services/oauth/index.js +133 -0
  1148. package/src/services/plugins/PluginInstallationManager.js +139 -0
  1149. package/src/services/plugins/pluginCliCommands.js +230 -0
  1150. package/src/services/plugins/pluginOperations.js +826 -0
  1151. package/src/services/policyLimits/index.js +547 -0
  1152. package/src/services/policyLimits/types.js +9 -0
  1153. package/src/services/preventSleep.js +143 -0
  1154. package/src/services/rateLimitMessages.js +271 -0
  1155. package/src/services/rateLimitMocking.js +91 -0
  1156. package/src/services/remoteManagedSettings/index.js +534 -0
  1157. package/src/services/remoteManagedSettings/securityCheck.js +60 -0
  1158. package/src/services/remoteManagedSettings/syncCache.js +90 -0
  1159. package/src/services/remoteManagedSettings/syncCacheState.js +89 -0
  1160. package/src/services/remoteManagedSettings/types.js +12 -0
  1161. package/src/services/sessionTranscript/sessionTranscript.js +5 -0
  1162. package/src/services/settingsSync/index.js +478 -0
  1163. package/src/services/settingsSync/types.js +35 -0
  1164. package/src/services/skillSearch/featureCheck.js +8 -0
  1165. package/src/services/skillSearch/localSearch.js +5 -0
  1166. package/src/services/skillSearch/prefetch.js +8 -0
  1167. package/src/services/skillSearch/remoteSkillLoader.js +8 -0
  1168. package/src/services/skillSearch/remoteSkillState.js +11 -0
  1169. package/src/services/skillSearch/signals.js +3 -0
  1170. package/src/services/skillSearch/telemetry.js +8 -0
  1171. package/src/services/teamMemorySync/index.js +976 -0
  1172. package/src/services/teamMemorySync/secretScanner.js +275 -0
  1173. package/src/services/teamMemorySync/teamMemSecretGuard.js +33 -0
  1174. package/src/services/teamMemorySync/types.js +47 -0
  1175. package/src/services/teamMemorySync/watcher.js +326 -0
  1176. package/src/services/thaddeusAuth.js +485 -0
  1177. package/src/services/thaddeusAuthTypes.js +9 -0
  1178. package/src/services/thaddeusLoginFlow.js +236 -0
  1179. package/src/services/tips/tipHistory.js +17 -0
  1180. package/src/services/tips/tipRegistry.js +593 -0
  1181. package/src/services/tips/tipScheduler.js +40 -0
  1182. package/src/services/tokenEstimation.js +365 -0
  1183. package/src/services/toolUseSummary/toolUseSummaryGenerator.js +87 -0
  1184. package/src/services/tools/StreamingToolExecutor.js +413 -0
  1185. package/src/services/tools/toolExecution.js +1309 -0
  1186. package/src/services/tools/toolHooks.js +454 -0
  1187. package/src/services/tools/toolOrchestration.js +110 -0
  1188. package/src/services/vcr.js +291 -0
  1189. package/src/services/voice.js +392 -0
  1190. package/src/services/voiceKeyterms.js +94 -0
  1191. package/src/services/voiceStreamSTT.js +405 -0
  1192. package/src/setup.js +310 -0
  1193. package/src/skills/bundled/batch.js +114 -0
  1194. package/src/skills/bundled/claudeApi.js +145 -0
  1195. package/src/skills/bundled/claudeApiContent.js +71 -0
  1196. package/src/skills/bundled/claudeInChrome.js +27 -0
  1197. package/src/skills/bundled/debug.js +99 -0
  1198. package/src/skills/bundled/dream.js +49 -0
  1199. package/src/skills/bundled/emailSetup.js +196 -0
  1200. package/src/skills/bundled/hunter.js +28 -0
  1201. package/src/skills/bundled/index.js +80 -0
  1202. package/src/skills/bundled/keybindings.js +292 -0
  1203. package/src/skills/bundled/loop.js +81 -0
  1204. package/src/skills/bundled/loremIpsum.js +264 -0
  1205. package/src/skills/bundled/reactor.js +31 -0
  1206. package/src/skills/bundled/remember.js +73 -0
  1207. package/src/skills/bundled/runSkillGenerator.js +12 -0
  1208. package/src/skills/bundled/scheduleRemoteAgents.js +373 -0
  1209. package/src/skills/bundled/simplify.js +66 -0
  1210. package/src/skills/bundled/skillify.js +182 -0
  1211. package/src/skills/bundled/stuck.js +69 -0
  1212. package/src/skills/bundled/updateConfig.js +463 -0
  1213. package/src/skills/bundled/verify.js +23 -0
  1214. package/src/skills/bundled/verifyContent.js +10 -0
  1215. package/src/skills/bundledSkills.js +159 -0
  1216. package/src/skills/loadSkillsDir.js +736 -0
  1217. package/src/skills/mcpSkillBuilders.js +10 -0
  1218. package/src/skills/mcpSkills.js +5 -0
  1219. package/src/state/AppState.js +182 -0
  1220. package/src/state/AppStateStore.js +117 -0
  1221. package/src/state/onChangeAppState.js +132 -0
  1222. package/src/state/selectors.js +51 -0
  1223. package/src/state/store.js +21 -0
  1224. package/src/state/teammateViewHelpers.js +124 -0
  1225. package/src/stubs/ant-chrome-mcp/index.js +4 -0
  1226. package/src/stubs/ant-computer-use-input/index.js +2 -0
  1227. package/src/stubs/ant-computer-use-mcp/index.js +7 -0
  1228. package/src/stubs/ant-computer-use-mcp/sentinelApps.js +2 -0
  1229. package/src/stubs/ant-computer-use-mcp/types.js +3 -0
  1230. package/src/stubs/ant-computer-use-swift/index.js +1 -0
  1231. package/src/stubs/anthropic-sandbox/index.js +34 -0
  1232. package/src/tasks/DreamTask/DreamTask.js +99 -0
  1233. package/src/tasks/InProcessTeammateTask/InProcessTeammateTask.js +116 -0
  1234. package/src/tasks/InProcessTeammateTask/types.js +35 -0
  1235. package/src/tasks/LocalAgentTask/LocalAgentTask.js +507 -0
  1236. package/src/tasks/LocalMainSessionTask.js +338 -0
  1237. package/src/tasks/LocalShellTask/LocalShellTask.js +475 -0
  1238. package/src/tasks/LocalShellTask/guards.js +9 -0
  1239. package/src/tasks/LocalShellTask/killShellTasks.js +59 -0
  1240. package/src/tasks/LocalWorkflowTask/LocalWorkflowTask.js +7 -0
  1241. package/src/tasks/MonitorMcpTask/MonitorMcpTask.js +20 -0
  1242. package/src/tasks/RemoteAgentTask/RemoteAgentTask.js +742 -0
  1243. package/src/tasks/pillLabel.js +69 -0
  1244. package/src/tasks/stopTask.js +67 -0
  1245. package/src/tasks/types.js +18 -0
  1246. package/src/tasks.js +37 -0
  1247. package/src/tools/AIEmployeesTool/AIEmployeesTool.js +674 -0
  1248. package/src/tools/AIEmployeesTool/constants.js +1 -0
  1249. package/src/tools/AIEmployeesTool/prompt.js +56 -0
  1250. package/src/tools/AgentTool/AgentTool.js +1221 -0
  1251. package/src/tools/AgentTool/UI.js +593 -0
  1252. package/src/tools/AgentTool/agentColorManager.js +43 -0
  1253. package/src/tools/AgentTool/agentDisplay.js +72 -0
  1254. package/src/tools/AgentTool/agentMemory.js +125 -0
  1255. package/src/tools/AgentTool/agentMemorySnapshot.js +136 -0
  1256. package/src/tools/AgentTool/agentToolUtils.js +456 -0
  1257. package/src/tools/AgentTool/built-in/exploreAgent.js +76 -0
  1258. package/src/tools/AgentTool/built-in/generalPurposeAgent.js +28 -0
  1259. package/src/tools/AgentTool/built-in/planAgent.js +87 -0
  1260. package/src/tools/AgentTool/built-in/statuslineSetup.js +140 -0
  1261. package/src/tools/AgentTool/built-in/thaddeusGuideAgent.js +174 -0
  1262. package/src/tools/AgentTool/built-in/verificationAgent.js +146 -0
  1263. package/src/tools/AgentTool/builtInAgents.js +56 -0
  1264. package/src/tools/AgentTool/constants.js +11 -0
  1265. package/src/tools/AgentTool/forkSubagent.js +177 -0
  1266. package/src/tools/AgentTool/loadAgentsDir.js +497 -0
  1267. package/src/tools/AgentTool/prompt.js +260 -0
  1268. package/src/tools/AgentTool/resumeAgent.js +182 -0
  1269. package/src/tools/AgentTool/runAgent.js +627 -0
  1270. package/src/tools/AppointmentsTool/AppointmentsTool.js +628 -0
  1271. package/src/tools/AppointmentsTool/constants.js +1 -0
  1272. package/src/tools/AppointmentsTool/prompt.js +15 -0
  1273. package/src/tools/AskUserQuestionTool/AskUserQuestionTool.js +238 -0
  1274. package/src/tools/AskUserQuestionTool/prompt.js +38 -0
  1275. package/src/tools/BashTool/BashTool.js +1009 -0
  1276. package/src/tools/BashTool/BashToolResultMessage.js +169 -0
  1277. package/src/tools/BashTool/UI.js +134 -0
  1278. package/src/tools/BashTool/bashCommandHelpers.js +184 -0
  1279. package/src/tools/BashTool/bashPermissions.js +2023 -0
  1280. package/src/tools/BashTool/bashSecurity.js +2267 -0
  1281. package/src/tools/BashTool/commandSemantics.js +105 -0
  1282. package/src/tools/BashTool/commentLabel.js +14 -0
  1283. package/src/tools/BashTool/destructiveCommandWarning.js +88 -0
  1284. package/src/tools/BashTool/modeValidation.js +86 -0
  1285. package/src/tools/BashTool/pathValidation.js +1079 -0
  1286. package/src/tools/BashTool/prompt.js +333 -0
  1287. package/src/tools/BashTool/readOnlyValidation.js +1794 -0
  1288. package/src/tools/BashTool/sedEditParser.js +282 -0
  1289. package/src/tools/BashTool/sedValidation.js +580 -0
  1290. package/src/tools/BashTool/shouldUseSandbox.js +125 -0
  1291. package/src/tools/BashTool/toolName.js +2 -0
  1292. package/src/tools/BashTool/utils.js +180 -0
  1293. package/src/tools/BriefTool/BriefTool.js +173 -0
  1294. package/src/tools/BriefTool/UI.js +67 -0
  1295. package/src/tools/BriefTool/attachments.js +86 -0
  1296. package/src/tools/BriefTool/prompt.js +19 -0
  1297. package/src/tools/BriefTool/upload.js +136 -0
  1298. package/src/tools/CalendarTool/CalendarTool.js +498 -0
  1299. package/src/tools/CalendarTool/constants.js +1 -0
  1300. package/src/tools/CalendarTool/prompt.js +11 -0
  1301. package/src/tools/ConfigTool/ConfigTool.js +398 -0
  1302. package/src/tools/ConfigTool/UI.js +25 -0
  1303. package/src/tools/ConfigTool/constants.js +1 -0
  1304. package/src/tools/ConfigTool/prompt.js +82 -0
  1305. package/src/tools/ConfigTool/supportedSettings.js +180 -0
  1306. package/src/tools/ContactsTool/ContactsTool.js +648 -0
  1307. package/src/tools/ContactsTool/constants.js +1 -0
  1308. package/src/tools/ContactsTool/prompt.js +15 -0
  1309. package/src/tools/CtxInspectTool/CtxInspectTool.js +44 -0
  1310. package/src/tools/DiscoverSkillsTool/prompt.js +4 -0
  1311. package/src/tools/EmailReadTool/index.js +410 -0
  1312. package/src/tools/EmailSendTool/index.js +178 -0
  1313. package/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +98 -0
  1314. package/src/tools/EnterPlanModeTool/UI.js +14 -0
  1315. package/src/tools/EnterPlanModeTool/constants.js +1 -0
  1316. package/src/tools/EnterPlanModeTool/prompt.js +164 -0
  1317. package/src/tools/EnterWorktreeTool/EnterWorktreeTool.js +104 -0
  1318. package/src/tools/EnterWorktreeTool/UI.js +9 -0
  1319. package/src/tools/EnterWorktreeTool/constants.js +1 -0
  1320. package/src/tools/EnterWorktreeTool/prompt.js +30 -0
  1321. package/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +383 -0
  1322. package/src/tools/ExitPlanModeTool/UI.js +32 -0
  1323. package/src/tools/ExitPlanModeTool/constants.js +2 -0
  1324. package/src/tools/ExitPlanModeTool/prompt.js +27 -0
  1325. package/src/tools/ExitWorktreeTool/ExitWorktreeTool.js +257 -0
  1326. package/src/tools/ExitWorktreeTool/UI.js +10 -0
  1327. package/src/tools/ExitWorktreeTool/constants.js +1 -0
  1328. package/src/tools/ExitWorktreeTool/prompt.js +32 -0
  1329. package/src/tools/FileEditTool/FileEditTool.js +480 -0
  1330. package/src/tools/FileEditTool/UI.js +202 -0
  1331. package/src/tools/FileEditTool/constants.js +7 -0
  1332. package/src/tools/FileEditTool/prompt.js +24 -0
  1333. package/src/tools/FileEditTool/types.js +50 -0
  1334. package/src/tools/FileEditTool/utils.js +579 -0
  1335. package/src/tools/FileReadTool/FileReadTool.js +889 -0
  1336. package/src/tools/FileReadTool/UI.js +126 -0
  1337. package/src/tools/FileReadTool/imageProcessor.js +46 -0
  1338. package/src/tools/FileReadTool/limits.js +70 -0
  1339. package/src/tools/FileReadTool/prompt.js +31 -0
  1340. package/src/tools/FileWriteTool/FileWriteTool.js +341 -0
  1341. package/src/tools/FileWriteTool/UI.js +339 -0
  1342. package/src/tools/FileWriteTool/prompt.js +15 -0
  1343. package/src/tools/GlobTool/GlobTool.js +161 -0
  1344. package/src/tools/GlobTool/UI.js +40 -0
  1345. package/src/tools/GlobTool/prompt.js +6 -0
  1346. package/src/tools/GrepTool/GrepTool.js +439 -0
  1347. package/src/tools/GrepTool/UI.js +155 -0
  1348. package/src/tools/GrepTool/prompt.js +16 -0
  1349. package/src/tools/IntegrationsTool/IntegrationsTool.js +217 -0
  1350. package/src/tools/IntegrationsTool/constants.js +1 -0
  1351. package/src/tools/IntegrationsTool/prompt.js +41 -0
  1352. package/src/tools/InteractionsTool/InteractionsTool.js +525 -0
  1353. package/src/tools/InteractionsTool/constants.js +1 -0
  1354. package/src/tools/InteractionsTool/prompt.js +14 -0
  1355. package/src/tools/InvoicesTool/InvoicesTool.js +581 -0
  1356. package/src/tools/InvoicesTool/constants.js +1 -0
  1357. package/src/tools/InvoicesTool/prompt.js +15 -0
  1358. package/src/tools/LSPTool/LSPTool.js +660 -0
  1359. package/src/tools/LSPTool/UI.js +205 -0
  1360. package/src/tools/LSPTool/formatters.js +445 -0
  1361. package/src/tools/LSPTool/prompt.js +20 -0
  1362. package/src/tools/LSPTool/schemas.js +197 -0
  1363. package/src/tools/LSPTool/symbolContext.js +75 -0
  1364. package/src/tools/LeadScorerTool/LeadScorerTool.js +509 -0
  1365. package/src/tools/LeadScorerTool/constants.js +1 -0
  1366. package/src/tools/LeadScorerTool/prompt.js +11 -0
  1367. package/src/tools/ListMcpResourcesTool/ListMcpResourcesTool.js +100 -0
  1368. package/src/tools/ListMcpResourcesTool/UI.js +17 -0
  1369. package/src/tools/ListMcpResourcesTool/prompt.js +18 -0
  1370. package/src/tools/ListPeersTool/ListPeersTool.js +45 -0
  1371. package/src/tools/MCPTool/MCPTool.js +60 -0
  1372. package/src/tools/MCPTool/UI.js +343 -0
  1373. package/src/tools/MCPTool/classifyForCollapse.js +597 -0
  1374. package/src/tools/MCPTool/prompt.js +3 -0
  1375. package/src/tools/McpAuthTool/McpAuthTool.js +162 -0
  1376. package/src/tools/MonitorTool/MonitorTool.js +55 -0
  1377. package/src/tools/NotebookEditTool/NotebookEditTool.js +421 -0
  1378. package/src/tools/NotebookEditTool/UI.js +41 -0
  1379. package/src/tools/NotebookEditTool/constants.js +2 -0
  1380. package/src/tools/NotebookEditTool/prompt.js +2 -0
  1381. package/src/tools/OverflowTestTool/OverflowTestTool.js +51 -0
  1382. package/src/tools/PhoneBridgeTool/PhoneBridgeTool.js +301 -0
  1383. package/src/tools/PhoneBridgeTool/constants.js +1 -0
  1384. package/src/tools/PhoneBridgeTool/prompt.js +26 -0
  1385. package/src/tools/PowerShellTool/PowerShellTool.js +900 -0
  1386. package/src/tools/PowerShellTool/UI.js +58 -0
  1387. package/src/tools/PowerShellTool/clmTypes.js +207 -0
  1388. package/src/tools/PowerShellTool/commandSemantics.js +115 -0
  1389. package/src/tools/PowerShellTool/commonParameters.js +27 -0
  1390. package/src/tools/PowerShellTool/destructiveCommandWarning.js +92 -0
  1391. package/src/tools/PowerShellTool/gitSafety.js +185 -0
  1392. package/src/tools/PowerShellTool/modeValidation.js +357 -0
  1393. package/src/tools/PowerShellTool/pathValidation.js +1712 -0
  1394. package/src/tools/PowerShellTool/powershellPermissions.js +1351 -0
  1395. package/src/tools/PowerShellTool/powershellSecurity.js +942 -0
  1396. package/src/tools/PowerShellTool/prompt.js +132 -0
  1397. package/src/tools/PowerShellTool/readOnlyValidation.js +1633 -0
  1398. package/src/tools/PowerShellTool/toolName.js +2 -0
  1399. package/src/tools/PushNotificationTool/PushNotificationTool.js +35 -0
  1400. package/src/tools/REPLTool/REPLTool.js +44 -0
  1401. package/src/tools/REPLTool/constants.js +43 -0
  1402. package/src/tools/REPLTool/primitiveTools.js +36 -0
  1403. package/src/tools/ReadMcpResourceTool/ReadMcpResourceTool.js +112 -0
  1404. package/src/tools/ReadMcpResourceTool/UI.js +24 -0
  1405. package/src/tools/ReadMcpResourceTool/prompt.js +15 -0
  1406. package/src/tools/RemoteTriggerTool/RemoteTriggerTool.js +142 -0
  1407. package/src/tools/RemoteTriggerTool/UI.js +12 -0
  1408. package/src/tools/RemoteTriggerTool/prompt.js +12 -0
  1409. package/src/tools/ReviewArtifactTool/ReviewArtifactTool.js +51 -0
  1410. package/src/tools/ScheduleCronTool/CronCreateTool.js +120 -0
  1411. package/src/tools/ScheduleCronTool/CronDeleteTool.js +74 -0
  1412. package/src/tools/ScheduleCronTool/CronListTool.js +77 -0
  1413. package/src/tools/ScheduleCronTool/UI.js +29 -0
  1414. package/src/tools/ScheduleCronTool/prompt.js +115 -0
  1415. package/src/tools/SendMessageTool/SendMessageTool.js +673 -0
  1416. package/src/tools/SendMessageTool/UI.js +24 -0
  1417. package/src/tools/SendMessageTool/constants.js +1 -0
  1418. package/src/tools/SendMessageTool/prompt.js +47 -0
  1419. package/src/tools/SendUserFileTool/SendUserFileTool.js +35 -0
  1420. package/src/tools/SendUserFileTool/prompt.js +5 -0
  1421. package/src/tools/SkillTool/SkillTool.js +825 -0
  1422. package/src/tools/SkillTool/UI.js +61 -0
  1423. package/src/tools/SkillTool/constants.js +1 -0
  1424. package/src/tools/SkillTool/prompt.js +184 -0
  1425. package/src/tools/SleepTool/SleepTool.js +42 -0
  1426. package/src/tools/SleepTool/prompt.js +14 -0
  1427. package/src/tools/SnipTool/SnipTool.js +47 -0
  1428. package/src/tools/SnipTool/prompt.js +5 -0
  1429. package/src/tools/SubscribePRTool/SubscribePRTool.js +49 -0
  1430. package/src/tools/SuggestBackgroundPRTool/SuggestBackgroundPRTool.js +44 -0
  1431. package/src/tools/SyntheticOutputTool/SyntheticOutputTool.js +138 -0
  1432. package/src/tools/SyntheticOutputTool/SyntheticOutputTool.ts +1 -1
  1433. package/src/tools/TaskCreateTool/TaskCreateTool.js +104 -0
  1434. package/src/tools/TaskCreateTool/constants.js +1 -0
  1435. package/src/tools/TaskCreateTool/prompt.js +52 -0
  1436. package/src/tools/TaskGetTool/TaskGetTool.js +106 -0
  1437. package/src/tools/TaskGetTool/constants.js +1 -0
  1438. package/src/tools/TaskGetTool/prompt.js +23 -0
  1439. package/src/tools/TaskListTool/TaskListTool.js +89 -0
  1440. package/src/tools/TaskListTool/constants.js +1 -0
  1441. package/src/tools/TaskListTool/prompt.js +44 -0
  1442. package/src/tools/TaskOutputTool/TaskOutputTool.js +536 -0
  1443. package/src/tools/TaskOutputTool/constants.js +1 -0
  1444. package/src/tools/TaskStopTool/TaskStopTool.js +110 -0
  1445. package/src/tools/TaskStopTool/UI.js +31 -0
  1446. package/src/tools/TaskStopTool/prompt.js +7 -0
  1447. package/src/tools/TaskUpdateTool/TaskUpdateTool.js +301 -0
  1448. package/src/tools/TaskUpdateTool/constants.js +1 -0
  1449. package/src/tools/TaskUpdateTool/prompt.js +76 -0
  1450. package/src/tools/TeamCreateTool/TeamCreateTool.js +177 -0
  1451. package/src/tools/TeamCreateTool/UI.js +4 -0
  1452. package/src/tools/TeamCreateTool/constants.js +1 -0
  1453. package/src/tools/TeamCreateTool/prompt.js +113 -0
  1454. package/src/tools/TeamDeleteTool/TeamDeleteTool.js +102 -0
  1455. package/src/tools/TeamDeleteTool/UI.js +13 -0
  1456. package/src/tools/TeamDeleteTool/constants.js +1 -0
  1457. package/src/tools/TeamDeleteTool/prompt.js +16 -0
  1458. package/src/tools/TerminalCaptureTool/TerminalCaptureTool.js +47 -0
  1459. package/src/tools/TerminalCaptureTool/prompt.js +11 -0
  1460. package/src/tools/TodoWriteTool/TodoWriteTool.js +99 -0
  1461. package/src/tools/TodoWriteTool/constants.js +1 -0
  1462. package/src/tools/TodoWriteTool/prompt.js +181 -0
  1463. package/src/tools/ToolSearchTool/ToolSearchTool.js +357 -0
  1464. package/src/tools/ToolSearchTool/constants.js +1 -0
  1465. package/src/tools/ToolSearchTool/prompt.js +97 -0
  1466. package/src/tools/TungstenTool/TungstenLiveMonitor.js +7 -0
  1467. package/src/tools/TungstenTool/TungstenTool.js +3 -0
  1468. package/src/tools/VerifyPlanExecutionTool/VerifyPlanExecutionTool.js +45 -0
  1469. package/src/tools/VerifyPlanExecutionTool/constants.js +2 -0
  1470. package/src/tools/WebBrowserTool/WebBrowserPanel.js +5 -0
  1471. package/src/tools/WebBrowserTool/WebBrowserTool.js +58 -0
  1472. package/src/tools/WebFetchTool/UI.js +31 -0
  1473. package/src/tools/WebFetchTool/WebFetchTool.js +246 -0
  1474. package/src/tools/WebFetchTool/preapproved.js +154 -0
  1475. package/src/tools/WebFetchTool/prompt.js +39 -0
  1476. package/src/tools/WebFetchTool/utils.js +368 -0
  1477. package/src/tools/WebSearchTool/UI.js +67 -0
  1478. package/src/tools/WebSearchTool/WebSearchTool.js +396 -0
  1479. package/src/tools/WebSearchTool/prompt.js +32 -0
  1480. package/src/tools/WorkflowTool/WorkflowPermissionRequest.js +7 -0
  1481. package/src/tools/WorkflowTool/WorkflowTool.js +51 -0
  1482. package/src/tools/WorkflowTool/bundled/index.js +5 -0
  1483. package/src/tools/WorkflowTool/constants.js +1 -0
  1484. package/src/tools/WorkflowTool/createWorkflowCommand.js +5 -0
  1485. package/src/tools/shared/gitOperationTracking.js +220 -0
  1486. package/src/tools/shared/spawnMultiAgent.js +805 -0
  1487. package/src/tools/testing/TestingPermissionTool.js +72 -0
  1488. package/src/tools/utils.js +24 -0
  1489. package/src/tools.js +365 -0
  1490. package/src/types/command.js +8 -0
  1491. package/src/types/connectorText.js +3 -0
  1492. package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.js +673 -0
  1493. package/src/types/generated/events_mono/common/v1/auth.js +49 -0
  1494. package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.js +147 -0
  1495. package/src/types/generated/google/protobuf/timestamp.js +38 -0
  1496. package/src/types/hooks.js +153 -0
  1497. package/src/types/ids.js +27 -0
  1498. package/src/types/logs.js +11 -0
  1499. package/src/types/permissions.js +25 -0
  1500. package/src/types/plugin.js +72 -0
  1501. package/src/types/textInputTypes.js +20 -0
  1502. package/src/upstreamproxy/relay.js +346 -0
  1503. package/src/upstreamproxy/upstreamproxy.js +234 -0
  1504. package/src/utils/CircularBuffer.js +75 -0
  1505. package/src/utils/Cursor.js +1229 -0
  1506. package/src/utils/QueryGuard.js +115 -0
  1507. package/src/utils/Shell.js +374 -0
  1508. package/src/utils/ShellCommand.js +336 -0
  1509. package/src/utils/abortController.js +74 -0
  1510. package/src/utils/activityManager.js +127 -0
  1511. package/src/utils/advisor.js +77 -0
  1512. package/src/utils/agentContext.js +91 -0
  1513. package/src/utils/agentId.js +83 -0
  1514. package/src/utils/agentSwarmsEnabled.js +37 -0
  1515. package/src/utils/agenticSessionSearch.js +255 -0
  1516. package/src/utils/analyzeContext.js +846 -0
  1517. package/src/utils/ansiToPng.js +259 -0
  1518. package/src/utils/ansiToSvg.js +207 -0
  1519. package/src/utils/api.js +555 -0
  1520. package/src/utils/apiPreconnect.js +62 -0
  1521. package/src/utils/appleTerminalBackup.js +95 -0
  1522. package/src/utils/argumentSubstitution.js +114 -0
  1523. package/src/utils/array.js +12 -0
  1524. package/src/utils/asciicast.js +200 -0
  1525. package/src/utils/attachments.js +2518 -0
  1526. package/src/utils/attribution.js +308 -0
  1527. package/src/utils/auth.js +1598 -0
  1528. package/src/utils/authFileDescriptor.js +152 -0
  1529. package/src/utils/authPortable.js +14 -0
  1530. package/src/utils/autoModeDenials.js +15 -0
  1531. package/src/utils/autoRunIssue.js +113 -0
  1532. package/src/utils/autoUpdater.js +457 -0
  1533. package/src/utils/aws.js +44 -0
  1534. package/src/utils/awsAuthStatusManager.js +66 -0
  1535. package/src/utils/background/remote/preconditions.js +175 -0
  1536. package/src/utils/background/remote/remoteSession.js +53 -0
  1537. package/src/utils/backgroundHousekeeping.js +64 -0
  1538. package/src/utils/bash/ParsedCommand.js +241 -0
  1539. package/src/utils/bash/ShellSnapshot.js +489 -0
  1540. package/src/utils/bash/ast.js +2590 -0
  1541. package/src/utils/bash/bashParser.js +4355 -0
  1542. package/src/utils/bash/bashPipeCommand.js +249 -0
  1543. package/src/utils/bash/commands.js +1131 -0
  1544. package/src/utils/bash/heredoc.js +647 -0
  1545. package/src/utils/bash/parser.js +195 -0
  1546. package/src/utils/bash/prefix.js +154 -0
  1547. package/src/utils/bash/registry.js +23 -0
  1548. package/src/utils/bash/shellCompletion.js +196 -0
  1549. package/src/utils/bash/shellPrefix.js +25 -0
  1550. package/src/utils/bash/shellQuote.js +253 -0
  1551. package/src/utils/bash/shellQuoting.js +106 -0
  1552. package/src/utils/bash/specs/alias.js +11 -0
  1553. package/src/utils/bash/specs/index.js +16 -0
  1554. package/src/utils/bash/specs/nohup.js +10 -0
  1555. package/src/utils/bash/specs/pyright.js +88 -0
  1556. package/src/utils/bash/specs/sleep.js +10 -0
  1557. package/src/utils/bash/specs/srun.js +28 -0
  1558. package/src/utils/bash/specs/time.js +10 -0
  1559. package/src/utils/bash/specs/timeout.js +17 -0
  1560. package/src/utils/bash/treeSitterAnalysis.js +407 -0
  1561. package/src/utils/betas.js +331 -0
  1562. package/src/utils/billing.js +54 -0
  1563. package/src/utils/binaryCheck.js +40 -0
  1564. package/src/utils/browser.js +58 -0
  1565. package/src/utils/bufferedWriter.js +77 -0
  1566. package/src/utils/bundledMode.js +19 -0
  1567. package/src/utils/businessDb.js +390 -0
  1568. package/src/utils/caCerts.js +91 -0
  1569. package/src/utils/caCertsConfig.js +77 -0
  1570. package/src/utils/cachePaths.js +28 -0
  1571. package/src/utils/classifierApprovals.js +66 -0
  1572. package/src/utils/classifierApprovalsHook.js +10 -0
  1573. package/src/utils/claudeDesktop.js +108 -0
  1574. package/src/utils/claudeInChrome/chromeNativeHost.js +416 -0
  1575. package/src/utils/claudeInChrome/common.js +466 -0
  1576. package/src/utils/claudeInChrome/mcpServer.js +237 -0
  1577. package/src/utils/claudeInChrome/prompt.js +79 -0
  1578. package/src/utils/claudeInChrome/setup.js +304 -0
  1579. package/src/utils/claudeInChrome/setupPortable.js +172 -0
  1580. package/src/utils/claudeInChrome/toolRendering.js +235 -0
  1581. package/src/utils/claudemd.js +1052 -0
  1582. package/src/utils/cleanup.js +514 -0
  1583. package/src/utils/cleanupRegistry.js +22 -0
  1584. package/src/utils/cliArgs.js +53 -0
  1585. package/src/utils/cliHighlight.js +45 -0
  1586. package/src/utils/codeIndexing.js +149 -0
  1587. package/src/utils/collapseBackgroundBashNotifications.js +70 -0
  1588. package/src/utils/collapseHookSummaries.js +48 -0
  1589. package/src/utils/collapseReadSearch.js +869 -0
  1590. package/src/utils/collapseTeammateShutdowns.js +44 -0
  1591. package/src/utils/combinedAbortSignal.js +40 -0
  1592. package/src/utils/commandLifecycle.js +7 -0
  1593. package/src/utils/commitAttribution.js +718 -0
  1594. package/src/utils/completionCache.js +138 -0
  1595. package/src/utils/computerUse/appNames.js +170 -0
  1596. package/src/utils/computerUse/cleanup.js +65 -0
  1597. package/src/utils/computerUse/common.js +56 -0
  1598. package/src/utils/computerUse/computerUseLock.js +183 -0
  1599. package/src/utils/computerUse/drainRunLoop.js +71 -0
  1600. package/src/utils/computerUse/escHotkey.js +53 -0
  1601. package/src/utils/computerUse/executor.js +480 -0
  1602. package/src/utils/computerUse/gates.js +55 -0
  1603. package/src/utils/computerUse/hostAdapter.js +62 -0
  1604. package/src/utils/computerUse/inputLoader.js +25 -0
  1605. package/src/utils/computerUse/mcpServer.js +84 -0
  1606. package/src/utils/computerUse/setup.js +42 -0
  1607. package/src/utils/computerUse/swiftLoader.js +18 -0
  1608. package/src/utils/computerUse/toolRendering.js +101 -0
  1609. package/src/utils/computerUse/wrapper.js +317 -0
  1610. package/src/utils/concurrentSessions.js +179 -0
  1611. package/src/utils/config.js +1078 -0
  1612. package/src/utils/configConstants.js +18 -0
  1613. package/src/utils/contentArray.js +45 -0
  1614. package/src/utils/context.js +185 -0
  1615. package/src/utils/contextAnalysis.js +171 -0
  1616. package/src/utils/contextSuggestions.js +158 -0
  1617. package/src/utils/controlMessageCompat.js +31 -0
  1618. package/src/utils/conversationRecovery.js +434 -0
  1619. package/src/utils/cron.js +260 -0
  1620. package/src/utils/cronJitterConfig.js +62 -0
  1621. package/src/utils/cronScheduler.js +388 -0
  1622. package/src/utils/cronTasks.js +328 -0
  1623. package/src/utils/cronTasksLock.js +159 -0
  1624. package/src/utils/crossProjectResume.js +46 -0
  1625. package/src/utils/crypto.js +13 -0
  1626. package/src/utils/cwd.js +29 -0
  1627. package/src/utils/debug.js +220 -0
  1628. package/src/utils/debugFilter.js +125 -0
  1629. package/src/utils/deepLink/banner.js +103 -0
  1630. package/src/utils/deepLink/parseDeepLink.js +138 -0
  1631. package/src/utils/deepLink/protocolHandler.js +119 -0
  1632. package/src/utils/deepLink/registerProtocol.js +291 -0
  1633. package/src/utils/deepLink/terminalLauncher.js +455 -0
  1634. package/src/utils/deepLink/terminalPreference.js +51 -0
  1635. package/src/utils/desktopDeepLink.js +208 -0
  1636. package/src/utils/detectRepository.js +157 -0
  1637. package/src/utils/diagLogs.js +74 -0
  1638. package/src/utils/diff.js +108 -0
  1639. package/src/utils/directMemberMessage.js +34 -0
  1640. package/src/utils/displayTags.js +46 -0
  1641. package/src/utils/doctorContextWarnings.js +179 -0
  1642. package/src/utils/doctorDiagnostic.js +494 -0
  1643. package/src/utils/dxt/helpers.js +64 -0
  1644. package/src/utils/dxt/zip.js +167 -0
  1645. package/src/utils/earlyInput.js +166 -0
  1646. package/src/utils/editor.js +163 -0
  1647. package/src/utils/effort.js +271 -0
  1648. package/src/utils/embeddedTools.js +26 -0
  1649. package/src/utils/employeeChat.js +271 -0
  1650. package/src/utils/employeeDb.js +326 -0
  1651. package/src/utils/env.js +358 -0
  1652. package/src/utils/envDynamic.js +130 -0
  1653. package/src/utils/envUtils.js +161 -0
  1654. package/src/utils/envValidation.js +26 -0
  1655. package/src/utils/errorLogSink.js +196 -0
  1656. package/src/utils/errors.js +207 -0
  1657. package/src/utils/exampleCommands.js +165 -0
  1658. package/src/utils/execFileNoThrow.js +93 -0
  1659. package/src/utils/execFileNoThrowPortable.js +49 -0
  1660. package/src/utils/execSyncWrapper.js +6 -0
  1661. package/src/utils/exportRenderer.js +71 -0
  1662. package/src/utils/extraUsage.js +19 -0
  1663. package/src/utils/fastMode.js +393 -0
  1664. package/src/utils/file.js +467 -0
  1665. package/src/utils/fileHistory.js +851 -0
  1666. package/src/utils/fileOperationAnalytics.js +45 -0
  1667. package/src/utils/filePersistence/filePersistence.js +212 -0
  1668. package/src/utils/filePersistence/outputsScanner.js +104 -0
  1669. package/src/utils/filePersistence/types.js +4 -0
  1670. package/src/utils/fileRead.js +81 -0
  1671. package/src/utils/fileReadCache.js +78 -0
  1672. package/src/utils/fileStateCache.js +99 -0
  1673. package/src/utils/findExecutable.js +13 -0
  1674. package/src/utils/fingerprint.js +58 -0
  1675. package/src/utils/forkedAgent.js +410 -0
  1676. package/src/utils/format.js +238 -0
  1677. package/src/utils/formatBriefTimestamp.js +72 -0
  1678. package/src/utils/fpsTracker.js +34 -0
  1679. package/src/utils/frontmatterParser.js +260 -0
  1680. package/src/utils/fsOperations.js +555 -0
  1681. package/src/utils/fullscreen.js +194 -0
  1682. package/src/utils/generatedFiles.js +122 -0
  1683. package/src/utils/generators.js +67 -0
  1684. package/src/utils/genericProcessUtils.js +155 -0
  1685. package/src/utils/getWorktreePaths.js +56 -0
  1686. package/src/utils/getWorktreePathsPortable.js +23 -0
  1687. package/src/utils/ghPrStatus.js +71 -0
  1688. package/src/utils/git/gitConfigParser.js +226 -0
  1689. package/src/utils/git/gitFilesystem.js +606 -0
  1690. package/src/utils/git/gitignore.js +84 -0
  1691. package/src/utils/git.js +725 -0
  1692. package/src/utils/gitDiff.js +395 -0
  1693. package/src/utils/gitSettings.js +18 -0
  1694. package/src/utils/github/ghAuthStatus.js +23 -0
  1695. package/src/utils/githubRepoPathMapping.js +135 -0
  1696. package/src/utils/glob.js +90 -0
  1697. package/src/utils/gracefulShutdown.js +447 -0
  1698. package/src/utils/groupToolUses.js +126 -0
  1699. package/src/utils/handlePromptSubmit.js +398 -0
  1700. package/src/utils/hash.js +44 -0
  1701. package/src/utils/headlessProfiler.js +147 -0
  1702. package/src/utils/heapDumpService.js +201 -0
  1703. package/src/utils/heatmap.js +151 -0
  1704. package/src/utils/highlightMatch.js +29 -0
  1705. package/src/utils/hooks/AsyncHookRegistry.js +187 -0
  1706. package/src/utils/hooks/apiQueryHookHelper.js +77 -0
  1707. package/src/utils/hooks/execAgentHook.js +257 -0
  1708. package/src/utils/hooks/execHttpHook.js +184 -0
  1709. package/src/utils/hooks/execPromptHook.js +171 -0
  1710. package/src/utils/hooks/fileChangedWatcher.js +161 -0
  1711. package/src/utils/hooks/hookEvents.js +111 -0
  1712. package/src/utils/hooks/hookHelpers.js +60 -0
  1713. package/src/utils/hooks/hooksConfigManager.js +323 -0
  1714. package/src/utils/hooks/hooksConfigSnapshot.js +114 -0
  1715. package/src/utils/hooks/hooksSettings.js +204 -0
  1716. package/src/utils/hooks/postSamplingHooks.js +39 -0
  1717. package/src/utils/hooks/registerFrontmatterHooks.js +47 -0
  1718. package/src/utils/hooks/registerSkillHooks.js +40 -0
  1719. package/src/utils/hooks/sessionHooks.js +252 -0
  1720. package/src/utils/hooks/skillImprovement.js +211 -0
  1721. package/src/utils/hooks/ssrfGuard.js +258 -0
  1722. package/src/utils/hooks.js +3668 -0
  1723. package/src/utils/horizontalScroll.js +108 -0
  1724. package/src/utils/http.js +120 -0
  1725. package/src/utils/hyperlink.js +28 -0
  1726. package/src/utils/iTermBackup.js +48 -0
  1727. package/src/utils/ide.js +1195 -0
  1728. package/src/utils/idePathConversion.js +66 -0
  1729. package/src/utils/idleTimeout.js +44 -0
  1730. package/src/utils/imagePaste.js +343 -0
  1731. package/src/utils/imageResizer.js +664 -0
  1732. package/src/utils/imageStore.js +150 -0
  1733. package/src/utils/imageValidation.js +92 -0
  1734. package/src/utils/immediateCommand.js +12 -0
  1735. package/src/utils/inProcessTeammateHelpers.js +71 -0
  1736. package/src/utils/ink.js +20 -0
  1737. package/src/utils/intl.js +83 -0
  1738. package/src/utils/jetbrains.js +152 -0
  1739. package/src/utils/json.js +231 -0
  1740. package/src/utils/jsonRead.js +14 -0
  1741. package/src/utils/keyboardShortcuts.js +11 -0
  1742. package/src/utils/lazySchema.js +8 -0
  1743. package/src/utils/listSessionsImpl.js +332 -0
  1744. package/src/utils/localInstaller.js +130 -0
  1745. package/src/utils/lockfile.js +30 -0
  1746. package/src/utils/log.js +280 -0
  1747. package/src/utils/logoV2Utils.js +256 -0
  1748. package/src/utils/mailbox.js +50 -0
  1749. package/src/utils/managedEnv.js +160 -0
  1750. package/src/utils/managedEnvConstants.js +185 -0
  1751. package/src/utils/markdown.js +315 -0
  1752. package/src/utils/markdownConfigLoader.js +480 -0
  1753. package/src/utils/mcp/dateTimeParser.js +102 -0
  1754. package/src/utils/mcp/elicitationValidation.js +259 -0
  1755. package/src/utils/mcpInstructionsDelta.js +97 -0
  1756. package/src/utils/mcpOutputStorage.js +159 -0
  1757. package/src/utils/mcpValidation.js +165 -0
  1758. package/src/utils/mcpWebSocketTransport.js +180 -0
  1759. package/src/utils/memoize.js +205 -0
  1760. package/src/utils/memory/types.js +9 -0
  1761. package/src/utils/memory/versions.js +7 -0
  1762. package/src/utils/memoryFileDetection.js +245 -0
  1763. package/src/utils/messagePredicates.js +6 -0
  1764. package/src/utils/messageQueueManager.js +430 -0
  1765. package/src/utils/messages/mappers.js +240 -0
  1766. package/src/utils/messages/systemInit.js +72 -0
  1767. package/src/utils/messages.js +4286 -0
  1768. package/src/utils/model/agent.js +128 -0
  1769. package/src/utils/model/aliases.js +21 -0
  1770. package/src/utils/model/antModels.js +25 -0
  1771. package/src/utils/model/bedrock.js +220 -0
  1772. package/src/utils/model/check1mAccess.js +64 -0
  1773. package/src/utils/model/configs.js +86 -0
  1774. package/src/utils/model/contextWindowUpgradeCheck.js +41 -0
  1775. package/src/utils/model/deprecation.js +72 -0
  1776. package/src/utils/model/model.js +533 -0
  1777. package/src/utils/model/modelAllowlist.js +148 -0
  1778. package/src/utils/model/modelCapabilities.js +105 -0
  1779. package/src/utils/model/modelOptions.js +450 -0
  1780. package/src/utils/model/modelStrings.js +144 -0
  1781. package/src/utils/model/modelSupportOverrides.js +40 -0
  1782. package/src/utils/model/providers.js +35 -0
  1783. package/src/utils/model/validateModel.js +131 -0
  1784. package/src/utils/modelCost.js +160 -0
  1785. package/src/utils/modifiers.js +39 -0
  1786. package/src/utils/mtls.js +132 -0
  1787. package/src/utils/nativeInstaller/download.js +370 -0
  1788. package/src/utils/nativeInstaller/index.js +8 -0
  1789. package/src/utils/nativeInstaller/installer.js +1395 -0
  1790. package/src/utils/nativeInstaller/packageManagers.js +258 -0
  1791. package/src/utils/nativeInstaller/pidLock.js +347 -0
  1792. package/src/utils/notebook.js +176 -0
  1793. package/src/utils/objectGroupBy.js +15 -0
  1794. package/src/utils/pasteStore.js +93 -0
  1795. package/src/utils/path.js +140 -0
  1796. package/src/utils/pdf.js +236 -0
  1797. package/src/utils/pdfUtils.js +61 -0
  1798. package/src/utils/peerAddress.js +20 -0
  1799. package/src/utils/permissions/PermissionMode.js +95 -0
  1800. package/src/utils/permissions/PermissionPromptToolResultSchema.js +85 -0
  1801. package/src/utils/permissions/PermissionResult.js +11 -0
  1802. package/src/utils/permissions/PermissionRule.js +19 -0
  1803. package/src/utils/permissions/PermissionUpdate.js +268 -0
  1804. package/src/utils/permissions/PermissionUpdateSchema.js +61 -0
  1805. package/src/utils/permissions/autoModeState.js +31 -0
  1806. package/src/utils/permissions/bashClassifier.js +30 -0
  1807. package/src/utils/permissions/bypassPermissionsKillswitch.js +115 -0
  1808. package/src/utils/permissions/classifierDecision.js +86 -0
  1809. package/src/utils/permissions/classifierShared.js +28 -0
  1810. package/src/utils/permissions/dangerousPatterns.js +78 -0
  1811. package/src/utils/permissions/denialTracking.js +34 -0
  1812. package/src/utils/permissions/filesystem.js +1411 -0
  1813. package/src/utils/permissions/getNextPermissionMode.js +74 -0
  1814. package/src/utils/permissions/pathValidation.js +351 -0
  1815. package/src/utils/permissions/permissionExplainer.js +188 -0
  1816. package/src/utils/permissions/permissionRuleParser.js +175 -0
  1817. package/src/utils/permissions/permissionSetup.js +1162 -0
  1818. package/src/utils/permissions/permissions.js +1063 -0
  1819. package/src/utils/permissions/permissionsLoader.js +217 -0
  1820. package/src/utils/permissions/shadowedRuleDetection.js +149 -0
  1821. package/src/utils/permissions/shellRuleMatching.js +174 -0
  1822. package/src/utils/permissions/yoloClassifier.js +1193 -0
  1823. package/src/utils/planModeV2.js +75 -0
  1824. package/src/utils/plans.js +334 -0
  1825. package/src/utils/platform.js +122 -0
  1826. package/src/utils/plugins/addDirPluginSettings.js +53 -0
  1827. package/src/utils/plugins/cacheUtils.js +174 -0
  1828. package/src/utils/plugins/dependencyResolver.js +244 -0
  1829. package/src/utils/plugins/fetchTelemetry.js +108 -0
  1830. package/src/utils/plugins/gitAvailability.js +65 -0
  1831. package/src/utils/plugins/headlessPluginInstall.js +136 -0
  1832. package/src/utils/plugins/hintRecommendation.js +136 -0
  1833. package/src/utils/plugins/installCounts.js +221 -0
  1834. package/src/utils/plugins/installedPluginsManager.js +1003 -0
  1835. package/src/utils/plugins/loadPluginAgents.js +219 -0
  1836. package/src/utils/plugins/loadPluginCommands.js +595 -0
  1837. package/src/utils/plugins/loadPluginHooks.js +239 -0
  1838. package/src/utils/plugins/loadPluginOutputStyles.js +112 -0
  1839. package/src/utils/plugins/lspPluginIntegration.js +293 -0
  1840. package/src/utils/plugins/lspRecommendation.js +278 -0
  1841. package/src/utils/plugins/managedPlugins.js +26 -0
  1842. package/src/utils/plugins/marketplaceHelpers.js +470 -0
  1843. package/src/utils/plugins/marketplaceManager.js +1939 -0
  1844. package/src/utils/plugins/mcpPluginIntegration.js +465 -0
  1845. package/src/utils/plugins/mcpbHandler.js +708 -0
  1846. package/src/utils/plugins/officialMarketplace.js +19 -0
  1847. package/src/utils/plugins/officialMarketplaceGcs.js +202 -0
  1848. package/src/utils/plugins/officialMarketplaceStartupCheck.js +344 -0
  1849. package/src/utils/plugins/orphanedPluginFilter.js +96 -0
  1850. package/src/utils/plugins/parseMarketplaceInput.js +143 -0
  1851. package/src/utils/plugins/performStartupChecks.js +66 -0
  1852. package/src/utils/plugins/pluginAutoupdate.js +210 -0
  1853. package/src/utils/plugins/pluginBlocklist.js +93 -0
  1854. package/src/utils/plugins/pluginDirectories.js +170 -0
  1855. package/src/utils/plugins/pluginFlagging.js +173 -0
  1856. package/src/utils/plugins/pluginIdentifier.js +78 -0
  1857. package/src/utils/plugins/pluginInstallationHelpers.js +400 -0
  1858. package/src/utils/plugins/pluginLoader.js +2426 -0
  1859. package/src/utils/plugins/pluginOptionsStorage.js +311 -0
  1860. package/src/utils/plugins/pluginPolicy.js +18 -0
  1861. package/src/utils/plugins/pluginStartupCheck.js +261 -0
  1862. package/src/utils/plugins/pluginVersioning.js +128 -0
  1863. package/src/utils/plugins/reconciler.js +181 -0
  1864. package/src/utils/plugins/refresh.js +162 -0
  1865. package/src/utils/plugins/schemas.js +1283 -0
  1866. package/src/utils/plugins/validatePlugin.js +765 -0
  1867. package/src/utils/plugins/walkPluginMarkdown.js +49 -0
  1868. package/src/utils/plugins/zipCache.js +346 -0
  1869. package/src/utils/plugins/zipCacheAdapters.js +133 -0
  1870. package/src/utils/powershell/dangerousCmdlets.js +174 -0
  1871. package/src/utils/powershell/parser.js +1357 -0
  1872. package/src/utils/powershell/staticPrefix.js +277 -0
  1873. package/src/utils/preflightChecks.js +147 -0
  1874. package/src/utils/privacyLevel.js +49 -0
  1875. package/src/utils/process.js +56 -0
  1876. package/src/utils/processUserInput/processBashCommand.js +118 -0
  1877. package/src/utils/processUserInput/processSlashCommand.js +845 -0
  1878. package/src/utils/processUserInput/processTextPrompt.js +68 -0
  1879. package/src/utils/processUserInput/processUserInput.js +344 -0
  1880. package/src/utils/profilerBase.js +32 -0
  1881. package/src/utils/promptCategory.js +39 -0
  1882. package/src/utils/promptEditor.js +151 -0
  1883. package/src/utils/promptShellExecution.js +117 -0
  1884. package/src/utils/protectedNamespace.js +4 -0
  1885. package/src/utils/proxy.js +345 -0
  1886. package/src/utils/queryContext.js +110 -0
  1887. package/src/utils/queryHelpers.js +436 -0
  1888. package/src/utils/queryProfiler.js +242 -0
  1889. package/src/utils/queueProcessor.js +70 -0
  1890. package/src/utils/readEditContext.js +176 -0
  1891. package/src/utils/readFileInRange.js +278 -0
  1892. package/src/utils/releaseNotes.js +307 -0
  1893. package/src/utils/renderOptions.js +67 -0
  1894. package/src/utils/ripgrep.js +521 -0
  1895. package/src/utils/sandbox/sandbox-adapter.js +750 -0
  1896. package/src/utils/sandbox/sandbox-ui-utils.js +11 -0
  1897. package/src/utils/sanitization.js +72 -0
  1898. package/src/utils/screenshotClipboard.js +89 -0
  1899. package/src/utils/sdkEventQueue.js +49 -0
  1900. package/src/utils/secureStorage/fallbackStorage.js +59 -0
  1901. package/src/utils/secureStorage/index.js +13 -0
  1902. package/src/utils/secureStorage/keychainPrefetch.js +91 -0
  1903. package/src/utils/secureStorage/macOsKeychainHelpers.js +91 -0
  1904. package/src/utils/secureStorage/macOsKeychainStorage.js +192 -0
  1905. package/src/utils/secureStorage/plainTextStorage.js +81 -0
  1906. package/src/utils/semanticBoolean.js +23 -0
  1907. package/src/utils/semanticNumber.js +34 -0
  1908. package/src/utils/semver.js +51 -0
  1909. package/src/utils/sequential.js +43 -0
  1910. package/src/utils/sessionActivity.js +120 -0
  1911. package/src/utils/sessionEnvVars.js +18 -0
  1912. package/src/utils/sessionEnvironment.js +131 -0
  1913. package/src/utils/sessionFileAccessHooks.js +205 -0
  1914. package/src/utils/sessionIngressAuth.js +113 -0
  1915. package/src/utils/sessionRestore.js +357 -0
  1916. package/src/utils/sessionStart.js +165 -0
  1917. package/src/utils/sessionState.js +76 -0
  1918. package/src/utils/sessionStorage.js +4162 -0
  1919. package/src/utils/sessionStoragePortable.js +665 -0
  1920. package/src/utils/sessionTitle.js +120 -0
  1921. package/src/utils/sessionUrl.js +50 -0
  1922. package/src/utils/set.js +50 -0
  1923. package/src/utils/settings/allErrors.js +29 -0
  1924. package/src/utils/settings/applySettingsChange.js +65 -0
  1925. package/src/utils/settings/changeDetector.js +409 -0
  1926. package/src/utils/settings/constants.js +166 -0
  1927. package/src/utils/settings/internalWrites.js +33 -0
  1928. package/src/utils/settings/managedPath.js +29 -0
  1929. package/src/utils/settings/mdm/constants.js +62 -0
  1930. package/src/utils/settings/mdm/rawRead.js +97 -0
  1931. package/src/utils/settings/mdm/settings.js +254 -0
  1932. package/src/utils/settings/permissionValidation.js +224 -0
  1933. package/src/utils/settings/pluginOnlyPolicy.js +53 -0
  1934. package/src/utils/settings/schemaOutput.js +7 -0
  1935. package/src/utils/settings/settings.js +791 -0
  1936. package/src/utils/settings/settingsCache.js +47 -0
  1937. package/src/utils/settings/toolValidationConfig.js +76 -0
  1938. package/src/utils/settings/types.js +846 -0
  1939. package/src/utils/settings/validateEditTool.js +34 -0
  1940. package/src/utils/settings/validation.js +192 -0
  1941. package/src/utils/settings/validationTips.js +111 -0
  1942. package/src/utils/shell/bashProvider.js +202 -0
  1943. package/src/utils/shell/outputLimits.js +7 -0
  1944. package/src/utils/shell/powershellDetection.js +96 -0
  1945. package/src/utils/shell/powershellProvider.js +104 -0
  1946. package/src/utils/shell/prefix.js +246 -0
  1947. package/src/utils/shell/readOnlyCommandValidation.js +1776 -0
  1948. package/src/utils/shell/resolveDefaultShell.js +13 -0
  1949. package/src/utils/shell/shellProvider.js +2 -0
  1950. package/src/utils/shell/shellToolUtils.js +21 -0
  1951. package/src/utils/shell/specPrefix.js +198 -0
  1952. package/src/utils/shellConfig.js +136 -0
  1953. package/src/utils/sideQuery.js +134 -0
  1954. package/src/utils/sideQuestion.js +121 -0
  1955. package/src/utils/signal.js +34 -0
  1956. package/src/utils/sinks.js +15 -0
  1957. package/src/utils/skills/skillChangeDetector.js +264 -0
  1958. package/src/utils/slashCommandParsing.js +46 -0
  1959. package/src/utils/sleep.js +72 -0
  1960. package/src/utils/sliceAnsi.js +74 -0
  1961. package/src/utils/slowOperations.js +216 -0
  1962. package/src/utils/standaloneAgent.js +20 -0
  1963. package/src/utils/startupProfiler.js +149 -0
  1964. package/src/utils/staticRender.js +104 -0
  1965. package/src/utils/stats.js +802 -0
  1966. package/src/utils/statsCache.js +330 -0
  1967. package/src/utils/status.js +359 -0
  1968. package/src/utils/statusNoticeDefinitions.js +123 -0
  1969. package/src/utils/statusNoticeHelpers.js +15 -0
  1970. package/src/utils/stream.js +73 -0
  1971. package/src/utils/streamJsonStdoutGuard.js +107 -0
  1972. package/src/utils/streamlinedTransform.js +162 -0
  1973. package/src/utils/stringUtils.js +202 -0
  1974. package/src/utils/subprocessEnv.js +87 -0
  1975. package/src/utils/suggestions/commandSuggestions.js +458 -0
  1976. package/src/utils/suggestions/directoryCompletion.js +191 -0
  1977. package/src/utils/suggestions/shellHistoryCompletion.js +95 -0
  1978. package/src/utils/suggestions/skillUsageTracking.js +50 -0
  1979. package/src/utils/suggestions/slackChannelSuggestions.js +169 -0
  1980. package/src/utils/swarm/It2SetupPrompt.js +386 -0
  1981. package/src/utils/swarm/backends/ITermBackend.js +276 -0
  1982. package/src/utils/swarm/backends/InProcessBackend.js +237 -0
  1983. package/src/utils/swarm/backends/PaneBackendExecutor.js +250 -0
  1984. package/src/utils/swarm/backends/TmuxBackend.js +574 -0
  1985. package/src/utils/swarm/backends/detection.js +112 -0
  1986. package/src/utils/swarm/backends/it2Setup.js +185 -0
  1987. package/src/utils/swarm/backends/registry.js +369 -0
  1988. package/src/utils/swarm/backends/teammateModeSnapshot.js +68 -0
  1989. package/src/utils/swarm/backends/types.js +9 -0
  1990. package/src/utils/swarm/constants.js +29 -0
  1991. package/src/utils/swarm/inProcessRunner.js +1021 -0
  1992. package/src/utils/swarm/leaderPermissionBridge.js +31 -0
  1993. package/src/utils/swarm/permissionSync.js +667 -0
  1994. package/src/utils/swarm/reconnection.js +82 -0
  1995. package/src/utils/swarm/spawnInProcess.js +218 -0
  1996. package/src/utils/swarm/spawnUtils.js +123 -0
  1997. package/src/utils/swarm/teamHelpers.js +484 -0
  1998. package/src/utils/swarm/teammateInit.js +87 -0
  1999. package/src/utils/swarm/teammateLayoutManager.js +82 -0
  2000. package/src/utils/swarm/teammateModel.js +9 -0
  2001. package/src/utils/swarm/teammatePromptAddendum.js +17 -0
  2002. package/src/utils/systemDirectories.js +51 -0
  2003. package/src/utils/systemPrompt.js +88 -0
  2004. package/src/utils/systemPromptType.js +9 -0
  2005. package/src/utils/systemTheme.js +108 -0
  2006. package/src/utils/taggedId.js +49 -0
  2007. package/src/utils/task/TaskOutput.js +320 -0
  2008. package/src/utils/task/diskOutput.js +387 -0
  2009. package/src/utils/task/framework.js +236 -0
  2010. package/src/utils/task/outputFormatting.js +24 -0
  2011. package/src/utils/task/sdkProgress.js +24 -0
  2012. package/src/utils/taskSummary.js +3 -0
  2013. package/src/utils/tasks.js +672 -0
  2014. package/src/utils/teamDiscovery.js +48 -0
  2015. package/src/utils/teamMemoryOps.js +67 -0
  2016. package/src/utils/teammate.js +237 -0
  2017. package/src/utils/teammateContext.js +56 -0
  2018. package/src/utils/teammateMailbox.js +793 -0
  2019. package/src/utils/telemetry/betaSessionTracing.js +25 -0
  2020. package/src/utils/telemetry/bigqueryExporter.js +17 -0
  2021. package/src/utils/telemetry/events.js +7 -0
  2022. package/src/utils/telemetry/instrumentation.js +16 -0
  2023. package/src/utils/telemetry/logger.js +25 -0
  2024. package/src/utils/telemetry/perfettoTracing.js +882 -0
  2025. package/src/utils/telemetry/pluginTelemetry.js +76 -0
  2026. package/src/utils/telemetry/sessionTracing.js +62 -0
  2027. package/src/utils/telemetry/skillLoadedEvent.js +4 -0
  2028. package/src/utils/telemetryAttributes.js +56 -0
  2029. package/src/utils/teleport/api.js +299 -0
  2030. package/src/utils/teleport/environmentSelection.js +55 -0
  2031. package/src/utils/teleport/environments.js +84 -0
  2032. package/src/utils/teleport/gitBundle.js +192 -0
  2033. package/src/utils/teleport.js +1047 -0
  2034. package/src/utils/tempfile.js +26 -0
  2035. package/src/utils/terminal.js +105 -0
  2036. package/src/utils/terminalPanel.js +155 -0
  2037. package/src/utils/textHighlighting.js +113 -0
  2038. package/src/utils/thaddeusHints.js +142 -0
  2039. package/src/utils/theme.js +525 -0
  2040. package/src/utils/thinking.js +130 -0
  2041. package/src/utils/timeouts.js +35 -0
  2042. package/src/utils/tmuxSocket.js +373 -0
  2043. package/src/utils/todo/types.js +9 -0
  2044. package/src/utils/tokenBudget.js +62 -0
  2045. package/src/utils/tokens.js +223 -0
  2046. package/src/utils/toolErrors.js +101 -0
  2047. package/src/utils/toolPool.js +61 -0
  2048. package/src/utils/toolResultStorage.js +768 -0
  2049. package/src/utils/toolSchemaCache.js +7 -0
  2050. package/src/utils/toolSearch.js +551 -0
  2051. package/src/utils/transcriptSearch.js +200 -0
  2052. package/src/utils/treeify.js +111 -0
  2053. package/src/utils/truncate.js +164 -0
  2054. package/src/utils/udsClient.js +5 -0
  2055. package/src/utils/udsMessaging.js +23 -0
  2056. package/src/utils/ultraplan/ccrSession.js +264 -0
  2057. package/src/utils/ultraplan/keyword.js +122 -0
  2058. package/src/utils/unaryLogging.js +16 -0
  2059. package/src/utils/undercover.js +89 -0
  2060. package/src/utils/user.js +137 -0
  2061. package/src/utils/userAgent.js +9 -0
  2062. package/src/utils/userPromptKeywords.js +21 -0
  2063. package/src/utils/uuid.js +22 -0
  2064. package/src/utils/warningHandler.js +97 -0
  2065. package/src/utils/which.js +75 -0
  2066. package/src/utils/windowsPaths.js +146 -0
  2067. package/src/utils/withResolvers.js +13 -0
  2068. package/src/utils/words.js +793 -0
  2069. package/src/utils/workforceIntent.js +192 -0
  2070. package/src/utils/workloadContext.js +42 -0
  2071. package/src/utils/worktree.js +1142 -0
  2072. package/src/utils/worktreeModeEnabled.js +11 -0
  2073. package/src/utils/xdg.js +52 -0
  2074. package/src/utils/xml.js +15 -0
  2075. package/src/utils/yaml.js +14 -0
  2076. package/src/utils/zodToJsonSchema.js +19 -0
  2077. package/src/vim/motions.js +73 -0
  2078. package/src/vim/operators.js +401 -0
  2079. package/src/vim/textObjects.js +153 -0
  2080. package/src/vim/transitions.js +340 -0
  2081. package/src/vim/types.js +93 -0
  2082. package/src/voice/voiceModeEnabled.js +20 -0
  2083. package/thaddeus-terminal.ts +401 -3
  2084. package/thaddeus.command +1 -1
@@ -0,0 +1,4355 @@
1
+ /**
2
+ * Pure-TypeScript bash parser producing tree-sitter-bash-compatible ASTs.
3
+ *
4
+ * Downstream code in parser.ts, ast.ts, prefix.ts, ParsedCommand.ts walks this
5
+ * by field name. startIndex/endIndex are UTF-8 BYTE offsets (not JS string
6
+ * indices).
7
+ *
8
+ * Grammar reference: tree-sitter-bash. Validated against a 3449-input golden
9
+ * corpus generated from the WASM parser.
10
+ */
11
+ /**
12
+ * 50ms wall-clock cap — bails out on pathological/adversarial input.
13
+ * Pass `Infinity` via `parse(src, Infinity)` to disable (e.g. correctness
14
+ * tests, where CI jitter would otherwise cause spurious null returns).
15
+ */
16
+ const PARSE_TIMEOUT_MS = 50;
17
+ /** Node budget cap — bails out before OOM on deeply nested input. */
18
+ const MAX_NODES = 50_000;
19
+ const MODULE = { parse: parseSource };
20
+ const READY = Promise.resolve();
21
+ /** No-op: pure-TS parser needs no async init. Kept for API compatibility. */
22
+ export function ensureParserInitialized() {
23
+ return READY;
24
+ }
25
+ /** Always succeeds — pure-TS needs no init. */
26
+ export function getParserModule() {
27
+ return MODULE;
28
+ }
29
+ const SPECIAL_VARS = new Set(['?', '$', '@', '*', '#', '-', '!', '_']);
30
+ const DECL_KEYWORDS = new Set([
31
+ 'export',
32
+ 'declare',
33
+ 'typeset',
34
+ 'readonly',
35
+ 'local',
36
+ ]);
37
+ export const SHELL_KEYWORDS = new Set([
38
+ 'if',
39
+ 'then',
40
+ 'elif',
41
+ 'else',
42
+ 'fi',
43
+ 'while',
44
+ 'until',
45
+ 'for',
46
+ 'in',
47
+ 'do',
48
+ 'done',
49
+ 'case',
50
+ 'esac',
51
+ 'function',
52
+ 'select',
53
+ ]);
54
+ function makeLexer(src) {
55
+ return {
56
+ src,
57
+ len: src.length,
58
+ i: 0,
59
+ b: 0,
60
+ heredocs: [],
61
+ byteTable: null,
62
+ };
63
+ }
64
+ /** Advance one JS char, updating byte offset for UTF-8. */
65
+ function advance(L) {
66
+ const c = L.src.charCodeAt(L.i);
67
+ L.i++;
68
+ if (c < 0x80) {
69
+ L.b++;
70
+ }
71
+ else if (c < 0x800) {
72
+ L.b += 2;
73
+ }
74
+ else if (c >= 0xd800 && c <= 0xdbff) {
75
+ // High surrogate — next char completes the pair, total 4 UTF-8 bytes
76
+ L.b += 4;
77
+ L.i++;
78
+ }
79
+ else {
80
+ L.b += 3;
81
+ }
82
+ }
83
+ function peek(L, off = 0) {
84
+ return L.i + off < L.len ? L.src[L.i + off] : '';
85
+ }
86
+ function byteAt(L, charIdx) {
87
+ // Fast path: ASCII-only prefix means char idx == byte idx
88
+ if (L.byteTable)
89
+ return L.byteTable[charIdx];
90
+ // Build table on first non-trivial lookup
91
+ const t = new Uint32Array(L.len + 1);
92
+ let b = 0;
93
+ let i = 0;
94
+ while (i < L.len) {
95
+ t[i] = b;
96
+ const c = L.src.charCodeAt(i);
97
+ if (c < 0x80) {
98
+ b++;
99
+ i++;
100
+ }
101
+ else if (c < 0x800) {
102
+ b += 2;
103
+ i++;
104
+ }
105
+ else if (c >= 0xd800 && c <= 0xdbff) {
106
+ t[i + 1] = b + 2;
107
+ b += 4;
108
+ i += 2;
109
+ }
110
+ else {
111
+ b += 3;
112
+ i++;
113
+ }
114
+ }
115
+ t[L.len] = b;
116
+ L.byteTable = t;
117
+ return t[charIdx];
118
+ }
119
+ function isWordChar(c) {
120
+ // Bash word chars: alphanumeric + various punctuation that doesn't start operators
121
+ return ((c >= 'a' && c <= 'z') ||
122
+ (c >= 'A' && c <= 'Z') ||
123
+ (c >= '0' && c <= '9') ||
124
+ c === '_' ||
125
+ c === '/' ||
126
+ c === '.' ||
127
+ c === '-' ||
128
+ c === '+' ||
129
+ c === ':' ||
130
+ c === '@' ||
131
+ c === '%' ||
132
+ c === ',' ||
133
+ c === '~' ||
134
+ c === '^' ||
135
+ c === '?' ||
136
+ c === '*' ||
137
+ c === '!' ||
138
+ c === '=' ||
139
+ c === '[' ||
140
+ c === ']');
141
+ }
142
+ function isWordStart(c) {
143
+ return isWordChar(c) || c === '\\';
144
+ }
145
+ function isIdentStart(c) {
146
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c === '_';
147
+ }
148
+ function isIdentChar(c) {
149
+ return isIdentStart(c) || (c >= '0' && c <= '9');
150
+ }
151
+ function isDigit(c) {
152
+ return c >= '0' && c <= '9';
153
+ }
154
+ function isHexDigit(c) {
155
+ return isDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
156
+ }
157
+ function isBaseDigit(c) {
158
+ // Bash BASE#DIGITS: digits, letters, @ and _ (up to base 64)
159
+ return isIdentChar(c) || c === '@';
160
+ }
161
+ /**
162
+ * Unquoted heredoc delimiter chars. Bash accepts most non-metacharacters —
163
+ * not just identifiers. Stop at whitespace, redirects, pipe/list operators,
164
+ * and structural tokens. Allows !, -, ., +, etc. (e.g. <<!HEREDOC!).
165
+ */
166
+ function isHeredocDelimChar(c) {
167
+ return (c !== '' &&
168
+ c !== ' ' &&
169
+ c !== '\t' &&
170
+ c !== '\n' &&
171
+ c !== '<' &&
172
+ c !== '>' &&
173
+ c !== '|' &&
174
+ c !== '&' &&
175
+ c !== ';' &&
176
+ c !== '(' &&
177
+ c !== ')' &&
178
+ c !== "'" &&
179
+ c !== '"' &&
180
+ c !== '`' &&
181
+ c !== '\\');
182
+ }
183
+ function skipBlanks(L) {
184
+ while (L.i < L.len) {
185
+ const c = L.src[L.i];
186
+ if (c === ' ' || c === '\t' || c === '\r') {
187
+ // \r is whitespace per tree-sitter-bash extras /\s/ — handles CRLF inputs
188
+ advance(L);
189
+ }
190
+ else if (c === '\\') {
191
+ const nx = L.src[L.i + 1];
192
+ if (nx === '\n' || (nx === '\r' && L.src[L.i + 2] === '\n')) {
193
+ // Line continuation — tree-sitter extras: /\\\r?\n/
194
+ advance(L);
195
+ advance(L);
196
+ if (nx === '\r')
197
+ advance(L);
198
+ }
199
+ else if (nx === ' ' || nx === '\t') {
200
+ // \<space> or \<tab> — tree-sitter's _whitespace is /\\?[ \t\v]+/
201
+ advance(L);
202
+ advance(L);
203
+ }
204
+ else {
205
+ break;
206
+ }
207
+ }
208
+ else {
209
+ break;
210
+ }
211
+ }
212
+ }
213
+ /**
214
+ * Scan next token. Context-sensitive: `cmd` mode treats [ as operator (test
215
+ * command start), `arg` mode treats [ as word char (glob/subscript).
216
+ */
217
+ function nextToken(L, ctx = 'arg') {
218
+ skipBlanks(L);
219
+ const start = L.b;
220
+ if (L.i >= L.len)
221
+ return { type: 'EOF', value: '', start, end: start };
222
+ const c = L.src[L.i];
223
+ const c1 = peek(L, 1);
224
+ const c2 = peek(L, 2);
225
+ if (c === '\n') {
226
+ advance(L);
227
+ return { type: 'NEWLINE', value: '\n', start, end: L.b };
228
+ }
229
+ if (c === '#') {
230
+ const si = L.i;
231
+ while (L.i < L.len && L.src[L.i] !== '\n')
232
+ advance(L);
233
+ return {
234
+ type: 'COMMENT',
235
+ value: L.src.slice(si, L.i),
236
+ start,
237
+ end: L.b,
238
+ };
239
+ }
240
+ // Multi-char operators (longest match first)
241
+ if (c === '&' && c1 === '&') {
242
+ advance(L);
243
+ advance(L);
244
+ return { type: 'OP', value: '&&', start, end: L.b };
245
+ }
246
+ if (c === '|' && c1 === '|') {
247
+ advance(L);
248
+ advance(L);
249
+ return { type: 'OP', value: '||', start, end: L.b };
250
+ }
251
+ if (c === '|' && c1 === '&') {
252
+ advance(L);
253
+ advance(L);
254
+ return { type: 'OP', value: '|&', start, end: L.b };
255
+ }
256
+ if (c === ';' && c1 === ';' && c2 === '&') {
257
+ advance(L);
258
+ advance(L);
259
+ advance(L);
260
+ return { type: 'OP', value: ';;&', start, end: L.b };
261
+ }
262
+ if (c === ';' && c1 === ';') {
263
+ advance(L);
264
+ advance(L);
265
+ return { type: 'OP', value: ';;', start, end: L.b };
266
+ }
267
+ if (c === ';' && c1 === '&') {
268
+ advance(L);
269
+ advance(L);
270
+ return { type: 'OP', value: ';&', start, end: L.b };
271
+ }
272
+ if (c === '>' && c1 === '>') {
273
+ advance(L);
274
+ advance(L);
275
+ return { type: 'OP', value: '>>', start, end: L.b };
276
+ }
277
+ if (c === '>' && c1 === '&' && c2 === '-') {
278
+ advance(L);
279
+ advance(L);
280
+ advance(L);
281
+ return { type: 'OP', value: '>&-', start, end: L.b };
282
+ }
283
+ if (c === '>' && c1 === '&') {
284
+ advance(L);
285
+ advance(L);
286
+ return { type: 'OP', value: '>&', start, end: L.b };
287
+ }
288
+ if (c === '>' && c1 === '|') {
289
+ advance(L);
290
+ advance(L);
291
+ return { type: 'OP', value: '>|', start, end: L.b };
292
+ }
293
+ if (c === '&' && c1 === '>' && c2 === '>') {
294
+ advance(L);
295
+ advance(L);
296
+ advance(L);
297
+ return { type: 'OP', value: '&>>', start, end: L.b };
298
+ }
299
+ if (c === '&' && c1 === '>') {
300
+ advance(L);
301
+ advance(L);
302
+ return { type: 'OP', value: '&>', start, end: L.b };
303
+ }
304
+ if (c === '<' && c1 === '<' && c2 === '<') {
305
+ advance(L);
306
+ advance(L);
307
+ advance(L);
308
+ return { type: 'OP', value: '<<<', start, end: L.b };
309
+ }
310
+ if (c === '<' && c1 === '<' && c2 === '-') {
311
+ advance(L);
312
+ advance(L);
313
+ advance(L);
314
+ return { type: 'OP', value: '<<-', start, end: L.b };
315
+ }
316
+ if (c === '<' && c1 === '<') {
317
+ advance(L);
318
+ advance(L);
319
+ return { type: 'OP', value: '<<', start, end: L.b };
320
+ }
321
+ if (c === '<' && c1 === '&' && c2 === '-') {
322
+ advance(L);
323
+ advance(L);
324
+ advance(L);
325
+ return { type: 'OP', value: '<&-', start, end: L.b };
326
+ }
327
+ if (c === '<' && c1 === '&') {
328
+ advance(L);
329
+ advance(L);
330
+ return { type: 'OP', value: '<&', start, end: L.b };
331
+ }
332
+ if (c === '<' && c1 === '(') {
333
+ advance(L);
334
+ advance(L);
335
+ return { type: 'LT_PAREN', value: '<(', start, end: L.b };
336
+ }
337
+ if (c === '>' && c1 === '(') {
338
+ advance(L);
339
+ advance(L);
340
+ return { type: 'GT_PAREN', value: '>(', start, end: L.b };
341
+ }
342
+ if (c === '(' && c1 === '(') {
343
+ advance(L);
344
+ advance(L);
345
+ return { type: 'OP', value: '((', start, end: L.b };
346
+ }
347
+ if (c === ')' && c1 === ')') {
348
+ advance(L);
349
+ advance(L);
350
+ return { type: 'OP', value: '))', start, end: L.b };
351
+ }
352
+ if (c === '|' || c === '&' || c === ';' || c === '>' || c === '<') {
353
+ advance(L);
354
+ return { type: 'OP', value: c, start, end: L.b };
355
+ }
356
+ if (c === '(' || c === ')') {
357
+ advance(L);
358
+ return { type: 'OP', value: c, start, end: L.b };
359
+ }
360
+ // In cmd position, [ [[ { start test/group; in arg position they're word chars
361
+ if (ctx === 'cmd') {
362
+ if (c === '[' && c1 === '[') {
363
+ advance(L);
364
+ advance(L);
365
+ return { type: 'OP', value: '[[', start, end: L.b };
366
+ }
367
+ if (c === '[') {
368
+ advance(L);
369
+ return { type: 'OP', value: '[', start, end: L.b };
370
+ }
371
+ if (c === '{' && (c1 === ' ' || c1 === '\t' || c1 === '\n')) {
372
+ advance(L);
373
+ return { type: 'OP', value: '{', start, end: L.b };
374
+ }
375
+ if (c === '}') {
376
+ advance(L);
377
+ return { type: 'OP', value: '}', start, end: L.b };
378
+ }
379
+ if (c === '!' && (c1 === ' ' || c1 === '\t')) {
380
+ advance(L);
381
+ return { type: 'OP', value: '!', start, end: L.b };
382
+ }
383
+ }
384
+ if (c === '"') {
385
+ advance(L);
386
+ return { type: 'DQUOTE', value: '"', start, end: L.b };
387
+ }
388
+ if (c === "'") {
389
+ const si = L.i;
390
+ advance(L);
391
+ while (L.i < L.len && L.src[L.i] !== "'")
392
+ advance(L);
393
+ if (L.i < L.len)
394
+ advance(L);
395
+ return {
396
+ type: 'SQUOTE',
397
+ value: L.src.slice(si, L.i),
398
+ start,
399
+ end: L.b,
400
+ };
401
+ }
402
+ if (c === '$') {
403
+ if (c1 === '(' && c2 === '(') {
404
+ advance(L);
405
+ advance(L);
406
+ advance(L);
407
+ return { type: 'DOLLAR_DPAREN', value: '$((', start, end: L.b };
408
+ }
409
+ if (c1 === '(') {
410
+ advance(L);
411
+ advance(L);
412
+ return { type: 'DOLLAR_PAREN', value: '$(', start, end: L.b };
413
+ }
414
+ if (c1 === '{') {
415
+ advance(L);
416
+ advance(L);
417
+ return { type: 'DOLLAR_BRACE', value: '${', start, end: L.b };
418
+ }
419
+ if (c1 === "'") {
420
+ // ANSI-C string $'...'
421
+ const si = L.i;
422
+ advance(L);
423
+ advance(L);
424
+ while (L.i < L.len && L.src[L.i] !== "'") {
425
+ if (L.src[L.i] === '\\' && L.i + 1 < L.len)
426
+ advance(L);
427
+ advance(L);
428
+ }
429
+ if (L.i < L.len)
430
+ advance(L);
431
+ return {
432
+ type: 'ANSI_C',
433
+ value: L.src.slice(si, L.i),
434
+ start,
435
+ end: L.b,
436
+ };
437
+ }
438
+ advance(L);
439
+ return { type: 'DOLLAR', value: '$', start, end: L.b };
440
+ }
441
+ if (c === '`') {
442
+ advance(L);
443
+ return { type: 'BACKTICK', value: '`', start, end: L.b };
444
+ }
445
+ // File descriptor before redirect: digit+ immediately followed by > or <
446
+ if (isDigit(c)) {
447
+ let j = L.i;
448
+ while (j < L.len && isDigit(L.src[j]))
449
+ j++;
450
+ const after = j < L.len ? L.src[j] : '';
451
+ if (after === '>' || after === '<') {
452
+ const si = L.i;
453
+ while (L.i < j)
454
+ advance(L);
455
+ return {
456
+ type: 'WORD',
457
+ value: L.src.slice(si, L.i),
458
+ start,
459
+ end: L.b,
460
+ };
461
+ }
462
+ }
463
+ // Word / number
464
+ if (isWordStart(c) || c === '{' || c === '}') {
465
+ const si = L.i;
466
+ while (L.i < L.len) {
467
+ const ch = L.src[L.i];
468
+ if (ch === '\\') {
469
+ if (L.i + 1 >= L.len) {
470
+ // Trailing `\` at EOF — tree-sitter excludes it from the word and
471
+ // emits a sibling ERROR. Stop here so the word ends before `\`.
472
+ break;
473
+ }
474
+ // Escape next char (including \n for line continuation mid-word)
475
+ if (L.src[L.i + 1] === '\n') {
476
+ advance(L);
477
+ advance(L);
478
+ continue;
479
+ }
480
+ advance(L);
481
+ advance(L);
482
+ continue;
483
+ }
484
+ if (!isWordChar(ch) && ch !== '{' && ch !== '}') {
485
+ break;
486
+ }
487
+ advance(L);
488
+ }
489
+ if (L.i > si) {
490
+ const v = L.src.slice(si, L.i);
491
+ // Number: optional sign then digits only
492
+ if (/^-?\d+$/.test(v)) {
493
+ return { type: 'NUMBER', value: v, start, end: L.b };
494
+ }
495
+ return { type: 'WORD', value: v, start, end: L.b };
496
+ }
497
+ // Empty word (lone `\` at EOF) — fall through to single-char consumer
498
+ }
499
+ // Unknown char — consume as single-char word
500
+ advance(L);
501
+ return { type: 'WORD', value: c, start, end: L.b };
502
+ }
503
+ function parseSource(source, timeoutMs) {
504
+ const L = makeLexer(source);
505
+ const srcBytes = byteLengthUtf8(source);
506
+ const P = {
507
+ L,
508
+ src: source,
509
+ srcBytes,
510
+ isAscii: srcBytes === source.length,
511
+ nodeCount: 0,
512
+ deadline: performance.now() + (timeoutMs ?? PARSE_TIMEOUT_MS),
513
+ aborted: false,
514
+ inBacktick: 0,
515
+ stopToken: null,
516
+ };
517
+ try {
518
+ const program = parseProgram(P);
519
+ if (P.aborted)
520
+ return null;
521
+ return program;
522
+ }
523
+ catch {
524
+ return null;
525
+ }
526
+ }
527
+ function byteLengthUtf8(s) {
528
+ let b = 0;
529
+ for (let i = 0; i < s.length; i++) {
530
+ const c = s.charCodeAt(i);
531
+ if (c < 0x80)
532
+ b++;
533
+ else if (c < 0x800)
534
+ b += 2;
535
+ else if (c >= 0xd800 && c <= 0xdbff) {
536
+ b += 4;
537
+ i++;
538
+ }
539
+ else
540
+ b += 3;
541
+ }
542
+ return b;
543
+ }
544
+ function checkBudget(P) {
545
+ P.nodeCount++;
546
+ if (P.nodeCount > MAX_NODES) {
547
+ P.aborted = true;
548
+ throw new Error('budget');
549
+ }
550
+ if ((P.nodeCount & 0x7f) === 0 && performance.now() > P.deadline) {
551
+ P.aborted = true;
552
+ throw new Error('timeout');
553
+ }
554
+ }
555
+ /** Build a node. Slices text from source by byte range via char-index lookup. */
556
+ function mk(P, type, start, end, children) {
557
+ checkBudget(P);
558
+ return {
559
+ type,
560
+ text: sliceBytes(P, start, end),
561
+ startIndex: start,
562
+ endIndex: end,
563
+ children,
564
+ };
565
+ }
566
+ function sliceBytes(P, startByte, endByte) {
567
+ if (P.isAscii)
568
+ return P.src.slice(startByte, endByte);
569
+ // Find char indices for byte offsets. Build byte table if needed.
570
+ const L = P.L;
571
+ if (!L.byteTable)
572
+ byteAt(L, 0);
573
+ const t = L.byteTable;
574
+ // Binary search for char index where byte offset matches
575
+ let lo = 0;
576
+ let hi = P.src.length;
577
+ while (lo < hi) {
578
+ const m = (lo + hi) >>> 1;
579
+ if (t[m] < startByte)
580
+ lo = m + 1;
581
+ else
582
+ hi = m;
583
+ }
584
+ const sc = lo;
585
+ lo = sc;
586
+ hi = P.src.length;
587
+ while (lo < hi) {
588
+ const m = (lo + hi) >>> 1;
589
+ if (t[m] < endByte)
590
+ lo = m + 1;
591
+ else
592
+ hi = m;
593
+ }
594
+ return P.src.slice(sc, lo);
595
+ }
596
+ function leaf(P, type, tok) {
597
+ return mk(P, type, tok.start, tok.end, []);
598
+ }
599
+ function parseProgram(P) {
600
+ const children = [];
601
+ // Skip leading whitespace & newlines — program start is first content byte
602
+ skipBlanks(P.L);
603
+ while (true) {
604
+ const save = saveLex(P.L);
605
+ const t = nextToken(P.L, 'cmd');
606
+ if (t.type === 'NEWLINE') {
607
+ skipBlanks(P.L);
608
+ continue;
609
+ }
610
+ restoreLex(P.L, save);
611
+ break;
612
+ }
613
+ const progStart = P.L.b;
614
+ while (P.L.i < P.L.len) {
615
+ const save = saveLex(P.L);
616
+ const t = nextToken(P.L, 'cmd');
617
+ if (t.type === 'EOF')
618
+ break;
619
+ if (t.type === 'NEWLINE')
620
+ continue;
621
+ if (t.type === 'COMMENT') {
622
+ children.push(leaf(P, 'comment', t));
623
+ continue;
624
+ }
625
+ restoreLex(P.L, save);
626
+ const stmts = parseStatements(P, null);
627
+ for (const s of stmts)
628
+ children.push(s);
629
+ if (stmts.length === 0) {
630
+ // Couldn't parse — emit ERROR and skip one token
631
+ const errTok = nextToken(P.L, 'cmd');
632
+ if (errTok.type === 'EOF')
633
+ break;
634
+ // Stray `;;` at program level (e.g., `var=;;` outside case) — tree-sitter
635
+ // silently elides. Keep leading `;` as ERROR (security: paste artifact).
636
+ if (errTok.type === 'OP' &&
637
+ errTok.value === ';;' &&
638
+ children.length > 0) {
639
+ continue;
640
+ }
641
+ children.push(mk(P, 'ERROR', errTok.start, errTok.end, []));
642
+ }
643
+ }
644
+ // tree-sitter includes trailing whitespace in program extent
645
+ const progEnd = children.length > 0 ? P.srcBytes : progStart;
646
+ return mk(P, 'program', progStart, progEnd, children);
647
+ }
648
+ function saveLex(L) {
649
+ return L.b * 0x10000 + L.i;
650
+ }
651
+ function restoreLex(L, s) {
652
+ L.i = s & 0xffff;
653
+ L.b = s >>> 16;
654
+ }
655
+ /**
656
+ * Parse a sequence of statements separated by ; & newline. Returns a flat list
657
+ * where ; and & are sibling leaves (NOT wrapped in 'list' — only && || get
658
+ * that). Stops at terminator or EOF.
659
+ */
660
+ function parseStatements(P, terminator) {
661
+ const out = [];
662
+ while (true) {
663
+ skipBlanks(P.L);
664
+ const save = saveLex(P.L);
665
+ const t = nextToken(P.L, 'cmd');
666
+ if (t.type === 'EOF') {
667
+ restoreLex(P.L, save);
668
+ break;
669
+ }
670
+ if (t.type === 'NEWLINE') {
671
+ // Process pending heredocs
672
+ if (P.L.heredocs.length > 0) {
673
+ scanHeredocBodies(P);
674
+ }
675
+ continue;
676
+ }
677
+ if (t.type === 'COMMENT') {
678
+ out.push(leaf(P, 'comment', t));
679
+ continue;
680
+ }
681
+ if (terminator && t.type === 'OP' && t.value === terminator) {
682
+ restoreLex(P.L, save);
683
+ break;
684
+ }
685
+ if (t.type === 'OP' &&
686
+ (t.value === ')' ||
687
+ t.value === '}' ||
688
+ t.value === ';;' ||
689
+ t.value === ';&' ||
690
+ t.value === ';;&' ||
691
+ t.value === '))' ||
692
+ t.value === ']]' ||
693
+ t.value === ']')) {
694
+ restoreLex(P.L, save);
695
+ break;
696
+ }
697
+ if (t.type === 'BACKTICK' && P.inBacktick > 0) {
698
+ restoreLex(P.L, save);
699
+ break;
700
+ }
701
+ if (t.type === 'WORD' &&
702
+ (t.value === 'then' ||
703
+ t.value === 'elif' ||
704
+ t.value === 'else' ||
705
+ t.value === 'fi' ||
706
+ t.value === 'do' ||
707
+ t.value === 'done' ||
708
+ t.value === 'esac')) {
709
+ restoreLex(P.L, save);
710
+ break;
711
+ }
712
+ restoreLex(P.L, save);
713
+ const stmt = parseAndOr(P);
714
+ if (!stmt)
715
+ break;
716
+ out.push(stmt);
717
+ // Look for separator
718
+ skipBlanks(P.L);
719
+ const save2 = saveLex(P.L);
720
+ const sep = nextToken(P.L, 'cmd');
721
+ if (sep.type === 'OP' && (sep.value === ';' || sep.value === '&')) {
722
+ // Check if terminator follows — if so, emit separator but stop
723
+ const save3 = saveLex(P.L);
724
+ const after = nextToken(P.L, 'cmd');
725
+ restoreLex(P.L, save3);
726
+ out.push(leaf(P, sep.value, sep));
727
+ if (after.type === 'EOF' ||
728
+ (after.type === 'OP' &&
729
+ (after.value === ')' ||
730
+ after.value === '}' ||
731
+ after.value === ';;' ||
732
+ after.value === ';&' ||
733
+ after.value === ';;&')) ||
734
+ (after.type === 'WORD' &&
735
+ (after.value === 'then' ||
736
+ after.value === 'elif' ||
737
+ after.value === 'else' ||
738
+ after.value === 'fi' ||
739
+ after.value === 'do' ||
740
+ after.value === 'done' ||
741
+ after.value === 'esac'))) {
742
+ // Trailing separator — don't include it at program level unless
743
+ // there's content after. But at inner levels we keep it.
744
+ continue;
745
+ }
746
+ }
747
+ else if (sep.type === 'NEWLINE') {
748
+ if (P.L.heredocs.length > 0) {
749
+ scanHeredocBodies(P);
750
+ }
751
+ continue;
752
+ }
753
+ else {
754
+ restoreLex(P.L, save2);
755
+ }
756
+ }
757
+ // Trim trailing separator if at program level
758
+ return out;
759
+ }
760
+ /**
761
+ * Parse pipeline chains joined by && ||. Left-associative nesting.
762
+ * tree-sitter quirk: trailing redirect on the last pipeline wraps the ENTIRE
763
+ * list in a redirected_statement — `a > x && b > y` becomes
764
+ * redirected_statement(list(redirected_statement(a,>x), &&, b), >y).
765
+ */
766
+ function parseAndOr(P) {
767
+ let left = parsePipeline(P);
768
+ if (!left)
769
+ return null;
770
+ while (true) {
771
+ const save = saveLex(P.L);
772
+ const t = nextToken(P.L, 'cmd');
773
+ if (t.type === 'OP' && (t.value === '&&' || t.value === '||')) {
774
+ const op = leaf(P, t.value, t);
775
+ skipNewlines(P);
776
+ const right = parsePipeline(P);
777
+ if (!right) {
778
+ left = mk(P, 'list', left.startIndex, op.endIndex, [left, op]);
779
+ break;
780
+ }
781
+ // If right is a redirected_statement, hoist its redirects to wrap the list.
782
+ if (right.type === 'redirected_statement' && right.children.length >= 2) {
783
+ const inner = right.children[0];
784
+ const redirs = right.children.slice(1);
785
+ const listNode = mk(P, 'list', left.startIndex, inner.endIndex, [
786
+ left,
787
+ op,
788
+ inner,
789
+ ]);
790
+ const lastR = redirs[redirs.length - 1];
791
+ left = mk(P, 'redirected_statement', listNode.startIndex, lastR.endIndex, [listNode, ...redirs]);
792
+ }
793
+ else {
794
+ left = mk(P, 'list', left.startIndex, right.endIndex, [left, op, right]);
795
+ }
796
+ }
797
+ else {
798
+ restoreLex(P.L, save);
799
+ break;
800
+ }
801
+ }
802
+ return left;
803
+ }
804
+ function skipNewlines(P) {
805
+ while (true) {
806
+ const save = saveLex(P.L);
807
+ const t = nextToken(P.L, 'cmd');
808
+ if (t.type !== 'NEWLINE') {
809
+ restoreLex(P.L, save);
810
+ break;
811
+ }
812
+ }
813
+ }
814
+ /**
815
+ * Parse commands joined by | or |&. Flat children with operator leaves.
816
+ * tree-sitter quirk: `a | b 2>nul | c` hoists the redirect on `b` to wrap
817
+ * the preceding pipeline fragment — pipeline(redirected_statement(
818
+ * pipeline(a,|,b), 2>nul), |, c).
819
+ */
820
+ function parsePipeline(P) {
821
+ let first = parseCommand(P);
822
+ if (!first)
823
+ return null;
824
+ const parts = [first];
825
+ while (true) {
826
+ const save = saveLex(P.L);
827
+ const t = nextToken(P.L, 'cmd');
828
+ if (t.type === 'OP' && (t.value === '|' || t.value === '|&')) {
829
+ const op = leaf(P, t.value, t);
830
+ skipNewlines(P);
831
+ const next = parseCommand(P);
832
+ if (!next) {
833
+ parts.push(op);
834
+ break;
835
+ }
836
+ // Hoist trailing redirect on `next` to wrap current pipeline fragment
837
+ if (next.type === 'redirected_statement' &&
838
+ next.children.length >= 2 &&
839
+ parts.length >= 1) {
840
+ const inner = next.children[0];
841
+ const redirs = next.children.slice(1);
842
+ // Wrap existing parts + op + inner as a pipeline
843
+ const pipeKids = [...parts, op, inner];
844
+ const pipeNode = mk(P, 'pipeline', pipeKids[0].startIndex, inner.endIndex, pipeKids);
845
+ const lastR = redirs[redirs.length - 1];
846
+ const wrapped = mk(P, 'redirected_statement', pipeNode.startIndex, lastR.endIndex, [pipeNode, ...redirs]);
847
+ parts.length = 0;
848
+ parts.push(wrapped);
849
+ first = wrapped;
850
+ continue;
851
+ }
852
+ parts.push(op, next);
853
+ }
854
+ else {
855
+ restoreLex(P.L, save);
856
+ break;
857
+ }
858
+ }
859
+ if (parts.length === 1)
860
+ return parts[0];
861
+ const last = parts[parts.length - 1];
862
+ return mk(P, 'pipeline', parts[0].startIndex, last.endIndex, parts);
863
+ }
864
+ /** Parse a single command: simple, compound, or control structure. */
865
+ function parseCommand(P) {
866
+ skipBlanks(P.L);
867
+ const save = saveLex(P.L);
868
+ const t = nextToken(P.L, 'cmd');
869
+ if (t.type === 'EOF') {
870
+ restoreLex(P.L, save);
871
+ return null;
872
+ }
873
+ // Negation — tree-sitter wraps just the command, redirects go outside.
874
+ // `! cmd > out` → redirected_statement(negated_command(!, cmd), >out)
875
+ if (t.type === 'OP' && t.value === '!') {
876
+ const bang = leaf(P, '!', t);
877
+ const inner = parseCommand(P);
878
+ if (!inner) {
879
+ restoreLex(P.L, save);
880
+ return null;
881
+ }
882
+ // If inner is a redirected_statement, hoist redirects outside negation
883
+ if (inner.type === 'redirected_statement' && inner.children.length >= 2) {
884
+ const cmd = inner.children[0];
885
+ const redirs = inner.children.slice(1);
886
+ const neg = mk(P, 'negated_command', bang.startIndex, cmd.endIndex, [
887
+ bang,
888
+ cmd,
889
+ ]);
890
+ const lastR = redirs[redirs.length - 1];
891
+ return mk(P, 'redirected_statement', neg.startIndex, lastR.endIndex, [
892
+ neg,
893
+ ...redirs,
894
+ ]);
895
+ }
896
+ return mk(P, 'negated_command', bang.startIndex, inner.endIndex, [
897
+ bang,
898
+ inner,
899
+ ]);
900
+ }
901
+ if (t.type === 'OP' && t.value === '(') {
902
+ const open = leaf(P, '(', t);
903
+ const body = parseStatements(P, ')');
904
+ const closeTok = nextToken(P.L, 'cmd');
905
+ const close = closeTok.type === 'OP' && closeTok.value === ')'
906
+ ? leaf(P, ')', closeTok)
907
+ : mk(P, ')', open.endIndex, open.endIndex, []);
908
+ const node = mk(P, 'subshell', open.startIndex, close.endIndex, [
909
+ open,
910
+ ...body,
911
+ close,
912
+ ]);
913
+ return maybeRedirect(P, node);
914
+ }
915
+ if (t.type === 'OP' && t.value === '((') {
916
+ const open = leaf(P, '((', t);
917
+ const exprs = parseArithCommaList(P, '))', 'var');
918
+ const closeTok = nextToken(P.L, 'cmd');
919
+ const close = closeTok.value === '))'
920
+ ? leaf(P, '))', closeTok)
921
+ : mk(P, '))', open.endIndex, open.endIndex, []);
922
+ return mk(P, 'compound_statement', open.startIndex, close.endIndex, [
923
+ open,
924
+ ...exprs,
925
+ close,
926
+ ]);
927
+ }
928
+ if (t.type === 'OP' && t.value === '{') {
929
+ const open = leaf(P, '{', t);
930
+ const body = parseStatements(P, '}');
931
+ const closeTok = nextToken(P.L, 'cmd');
932
+ const close = closeTok.type === 'OP' && closeTok.value === '}'
933
+ ? leaf(P, '}', closeTok)
934
+ : mk(P, '}', open.endIndex, open.endIndex, []);
935
+ const node = mk(P, 'compound_statement', open.startIndex, close.endIndex, [
936
+ open,
937
+ ...body,
938
+ close,
939
+ ]);
940
+ return maybeRedirect(P, node);
941
+ }
942
+ if (t.type === 'OP' && (t.value === '[' || t.value === '[[')) {
943
+ const open = leaf(P, t.value, t);
944
+ const closer = t.value === '[' ? ']' : ']]';
945
+ // Grammar: `[` can contain choice(_expression, redirected_statement).
946
+ // Try _expression first; if we don't reach `]`, backtrack and parse as
947
+ // redirected_statement (handles `[ ! cmd -v go &>/dev/null ]`).
948
+ const exprSave = saveLex(P.L);
949
+ let expr = parseTestExpr(P, closer);
950
+ skipBlanks(P.L);
951
+ if (t.value === '[' && peek(P.L) !== ']') {
952
+ // Expression parse didn't reach `]` — try as redirected_statement.
953
+ // Thread `]` stop-token so parseSimpleCommand doesn't eat it as arg.
954
+ restoreLex(P.L, exprSave);
955
+ const prevStop = P.stopToken;
956
+ P.stopToken = ']';
957
+ const rstmt = parseCommand(P);
958
+ P.stopToken = prevStop;
959
+ if (rstmt && rstmt.type === 'redirected_statement') {
960
+ expr = rstmt;
961
+ }
962
+ else {
963
+ // Neither worked — restore and keep the expression result
964
+ restoreLex(P.L, exprSave);
965
+ expr = parseTestExpr(P, closer);
966
+ }
967
+ skipBlanks(P.L);
968
+ }
969
+ const closeTok = nextToken(P.L, 'arg');
970
+ let close;
971
+ if (closeTok.value === closer) {
972
+ close = leaf(P, closer, closeTok);
973
+ }
974
+ else {
975
+ close = mk(P, closer, open.endIndex, open.endIndex, []);
976
+ }
977
+ const kids = expr ? [open, expr, close] : [open, close];
978
+ return mk(P, 'test_command', open.startIndex, close.endIndex, kids);
979
+ }
980
+ if (t.type === 'WORD') {
981
+ if (t.value === 'if')
982
+ return maybeRedirect(P, parseIf(P, t), true);
983
+ if (t.value === 'while' || t.value === 'until')
984
+ return maybeRedirect(P, parseWhile(P, t), true);
985
+ if (t.value === 'for')
986
+ return maybeRedirect(P, parseFor(P, t), true);
987
+ if (t.value === 'select')
988
+ return maybeRedirect(P, parseFor(P, t), true);
989
+ if (t.value === 'case')
990
+ return maybeRedirect(P, parseCase(P, t), true);
991
+ if (t.value === 'function')
992
+ return parseFunction(P, t);
993
+ if (DECL_KEYWORDS.has(t.value))
994
+ return maybeRedirect(P, parseDeclaration(P, t));
995
+ if (t.value === 'unset' || t.value === 'unsetenv') {
996
+ return maybeRedirect(P, parseUnset(P, t));
997
+ }
998
+ }
999
+ restoreLex(P.L, save);
1000
+ return parseSimpleCommand(P);
1001
+ }
1002
+ /**
1003
+ * Parse a simple command: [assignment]* word [arg|redirect]*
1004
+ * Returns variable_assignment if only one assignment and no command.
1005
+ */
1006
+ function parseSimpleCommand(P) {
1007
+ const start = P.L.b;
1008
+ const assignments = [];
1009
+ const preRedirects = [];
1010
+ while (true) {
1011
+ skipBlanks(P.L);
1012
+ const a = tryParseAssignment(P);
1013
+ if (a) {
1014
+ assignments.push(a);
1015
+ continue;
1016
+ }
1017
+ const r = tryParseRedirect(P);
1018
+ if (r) {
1019
+ preRedirects.push(r);
1020
+ continue;
1021
+ }
1022
+ break;
1023
+ }
1024
+ skipBlanks(P.L);
1025
+ const save = saveLex(P.L);
1026
+ const nameTok = nextToken(P.L, 'cmd');
1027
+ if (nameTok.type === 'EOF' ||
1028
+ nameTok.type === 'NEWLINE' ||
1029
+ nameTok.type === 'COMMENT' ||
1030
+ (nameTok.type === 'OP' &&
1031
+ nameTok.value !== '{' &&
1032
+ nameTok.value !== '[' &&
1033
+ nameTok.value !== '[[') ||
1034
+ (nameTok.type === 'WORD' &&
1035
+ SHELL_KEYWORDS.has(nameTok.value) &&
1036
+ nameTok.value !== 'in')) {
1037
+ restoreLex(P.L, save);
1038
+ // No command — standalone assignment(s) or redirect
1039
+ if (assignments.length === 1 && preRedirects.length === 0) {
1040
+ return assignments[0];
1041
+ }
1042
+ if (preRedirects.length > 0 && assignments.length === 0) {
1043
+ // Bare redirect → redirected_statement with just file_redirect children
1044
+ const last = preRedirects[preRedirects.length - 1];
1045
+ return mk(P, 'redirected_statement', preRedirects[0].startIndex, last.endIndex, preRedirects);
1046
+ }
1047
+ if (assignments.length > 1 && preRedirects.length === 0) {
1048
+ // `A=1 B=2` with no command → variable_assignments (plural)
1049
+ const last = assignments[assignments.length - 1];
1050
+ return mk(P, 'variable_assignments', assignments[0].startIndex, last.endIndex, assignments);
1051
+ }
1052
+ if (assignments.length > 0 || preRedirects.length > 0) {
1053
+ const all = [...assignments, ...preRedirects];
1054
+ const last = all[all.length - 1];
1055
+ return mk(P, 'command', start, last.endIndex, all);
1056
+ }
1057
+ return null;
1058
+ }
1059
+ restoreLex(P.L, save);
1060
+ // Check for function definition: name() { ... }
1061
+ const fnSave = saveLex(P.L);
1062
+ const nm = parseWord(P, 'cmd');
1063
+ if (nm && nm.type === 'word') {
1064
+ skipBlanks(P.L);
1065
+ if (peek(P.L) === '(' && peek(P.L, 1) === ')') {
1066
+ const oTok = nextToken(P.L, 'cmd');
1067
+ const cTok = nextToken(P.L, 'cmd');
1068
+ const oParen = leaf(P, '(', oTok);
1069
+ const cParen = leaf(P, ')', cTok);
1070
+ skipBlanks(P.L);
1071
+ skipNewlines(P);
1072
+ const body = parseCommand(P);
1073
+ if (body) {
1074
+ // If body is redirected_statement(compound_statement, file_redirect...),
1075
+ // hoist redirects to function_definition level per tree-sitter grammar
1076
+ let bodyKids = [body];
1077
+ if (body.type === 'redirected_statement' &&
1078
+ body.children.length >= 2 &&
1079
+ body.children[0].type === 'compound_statement') {
1080
+ bodyKids = body.children;
1081
+ }
1082
+ const last = bodyKids[bodyKids.length - 1];
1083
+ return mk(P, 'function_definition', nm.startIndex, last.endIndex, [
1084
+ nm,
1085
+ oParen,
1086
+ cParen,
1087
+ ...bodyKids,
1088
+ ]);
1089
+ }
1090
+ }
1091
+ }
1092
+ restoreLex(P.L, fnSave);
1093
+ const nameArg = parseWord(P, 'cmd');
1094
+ if (!nameArg) {
1095
+ if (assignments.length === 1)
1096
+ return assignments[0];
1097
+ return null;
1098
+ }
1099
+ const cmdName = mk(P, 'command_name', nameArg.startIndex, nameArg.endIndex, [
1100
+ nameArg,
1101
+ ]);
1102
+ const args = [];
1103
+ const redirects = [];
1104
+ let heredocRedirect = null;
1105
+ while (true) {
1106
+ skipBlanks(P.L);
1107
+ // Post-command redirects are greedy (repeat1 $._literal) — once a redirect
1108
+ // appears after command_name, subsequent literals attach to it per grammar's
1109
+ // prec.left. `grep 2>/dev/null -q foo` → file_redirect eats `-q foo`.
1110
+ // Args parsed BEFORE the first redirect still go to command (cat a b > out).
1111
+ const r = tryParseRedirect(P, true);
1112
+ if (r) {
1113
+ if (r.type === 'heredoc_redirect') {
1114
+ heredocRedirect = r;
1115
+ }
1116
+ else if (r.type === 'herestring_redirect') {
1117
+ args.push(r);
1118
+ }
1119
+ else {
1120
+ redirects.push(r);
1121
+ }
1122
+ continue;
1123
+ }
1124
+ // Once a file_redirect has been seen, command args are done — grammar's
1125
+ // command rule doesn't allow file_redirect in its post-name choice, so
1126
+ // anything after belongs to redirected_statement's file_redirect children.
1127
+ if (redirects.length > 0)
1128
+ break;
1129
+ // `[` test_command backtrack — stop at `]` so outer handler can consume it
1130
+ if (P.stopToken === ']' && peek(P.L) === ']')
1131
+ break;
1132
+ const save2 = saveLex(P.L);
1133
+ const pk = nextToken(P.L, 'arg');
1134
+ if (pk.type === 'EOF' ||
1135
+ pk.type === 'NEWLINE' ||
1136
+ pk.type === 'COMMENT' ||
1137
+ (pk.type === 'OP' &&
1138
+ (pk.value === '|' ||
1139
+ pk.value === '|&' ||
1140
+ pk.value === '&&' ||
1141
+ pk.value === '||' ||
1142
+ pk.value === ';' ||
1143
+ pk.value === ';;' ||
1144
+ pk.value === ';&' ||
1145
+ pk.value === ';;&' ||
1146
+ pk.value === '&' ||
1147
+ pk.value === ')' ||
1148
+ pk.value === '}' ||
1149
+ pk.value === '))'))) {
1150
+ restoreLex(P.L, save2);
1151
+ break;
1152
+ }
1153
+ restoreLex(P.L, save2);
1154
+ const arg = parseWord(P, 'arg');
1155
+ if (!arg) {
1156
+ // Lone `(` in arg position — tree-sitter parses this as subshell arg
1157
+ // e.g., `echo =(cmd)` → command has ERROR(=), subshell(cmd) as args
1158
+ if (peek(P.L) === '(') {
1159
+ const oTok = nextToken(P.L, 'cmd');
1160
+ const open = leaf(P, '(', oTok);
1161
+ const body = parseStatements(P, ')');
1162
+ const cTok = nextToken(P.L, 'cmd');
1163
+ const close = cTok.type === 'OP' && cTok.value === ')'
1164
+ ? leaf(P, ')', cTok)
1165
+ : mk(P, ')', open.endIndex, open.endIndex, []);
1166
+ args.push(mk(P, 'subshell', open.startIndex, close.endIndex, [
1167
+ open,
1168
+ ...body,
1169
+ close,
1170
+ ]));
1171
+ continue;
1172
+ }
1173
+ break;
1174
+ }
1175
+ // Lone `=` in arg position is a parse error in bash — tree-sitter wraps
1176
+ // it in ERROR for recovery. Happens in `echo =(cmd)` (zsh process-sub).
1177
+ if (arg.type === 'word' && arg.text === '=') {
1178
+ args.push(mk(P, 'ERROR', arg.startIndex, arg.endIndex, [arg]));
1179
+ continue;
1180
+ }
1181
+ // Word immediately followed by `(` (no whitespace) is a parse error —
1182
+ // bash doesn't allow glob-then-subshell adjacency. tree-sitter wraps the
1183
+ // word in ERROR. Catches zsh glob qualifiers like `*.(e:'cmd':)`.
1184
+ if ((arg.type === 'word' || arg.type === 'concatenation') &&
1185
+ peek(P.L) === '(' &&
1186
+ P.L.b === arg.endIndex) {
1187
+ args.push(mk(P, 'ERROR', arg.startIndex, arg.endIndex, [arg]));
1188
+ continue;
1189
+ }
1190
+ args.push(arg);
1191
+ }
1192
+ // preRedirects (e.g., `2>&1 cat`, `<<<str cmd`) go INSIDE the command node
1193
+ // before command_name per tree-sitter grammar, not in redirected_statement
1194
+ const cmdChildren = [...assignments, ...preRedirects, cmdName, ...args];
1195
+ const cmdEnd = cmdChildren.length > 0
1196
+ ? cmdChildren[cmdChildren.length - 1].endIndex
1197
+ : cmdName.endIndex;
1198
+ const cmdStart = cmdChildren[0].startIndex;
1199
+ const cmd = mk(P, 'command', cmdStart, cmdEnd, cmdChildren);
1200
+ if (heredocRedirect) {
1201
+ // Scan heredoc body now
1202
+ scanHeredocBodies(P);
1203
+ const hd = P.L.heredocs.shift();
1204
+ if (hd && heredocRedirect.children.length >= 2) {
1205
+ const bodyNode = mk(P, 'heredoc_body', hd.bodyStart, hd.bodyEnd, hd.quoted ? [] : parseHeredocBodyContent(P, hd.bodyStart, hd.bodyEnd));
1206
+ const endNode = mk(P, 'heredoc_end', hd.endStart, hd.endEnd, []);
1207
+ heredocRedirect.children.push(bodyNode, endNode);
1208
+ heredocRedirect.endIndex = hd.endEnd;
1209
+ heredocRedirect.text = sliceBytes(P, heredocRedirect.startIndex, hd.endEnd);
1210
+ }
1211
+ const allR = [...preRedirects, heredocRedirect, ...redirects];
1212
+ const rStart = preRedirects.length > 0
1213
+ ? Math.min(cmd.startIndex, preRedirects[0].startIndex)
1214
+ : cmd.startIndex;
1215
+ return mk(P, 'redirected_statement', rStart, heredocRedirect.endIndex, [
1216
+ cmd,
1217
+ ...allR,
1218
+ ]);
1219
+ }
1220
+ if (redirects.length > 0) {
1221
+ const last = redirects[redirects.length - 1];
1222
+ return mk(P, 'redirected_statement', cmd.startIndex, last.endIndex, [
1223
+ cmd,
1224
+ ...redirects,
1225
+ ]);
1226
+ }
1227
+ return cmd;
1228
+ }
1229
+ function maybeRedirect(P, node, allowHerestring = false) {
1230
+ const redirects = [];
1231
+ while (true) {
1232
+ skipBlanks(P.L);
1233
+ const save = saveLex(P.L);
1234
+ const r = tryParseRedirect(P);
1235
+ if (!r)
1236
+ break;
1237
+ if (r.type === 'herestring_redirect' && !allowHerestring) {
1238
+ restoreLex(P.L, save);
1239
+ break;
1240
+ }
1241
+ redirects.push(r);
1242
+ }
1243
+ if (redirects.length === 0)
1244
+ return node;
1245
+ const last = redirects[redirects.length - 1];
1246
+ return mk(P, 'redirected_statement', node.startIndex, last.endIndex, [
1247
+ node,
1248
+ ...redirects,
1249
+ ]);
1250
+ }
1251
+ function tryParseAssignment(P) {
1252
+ const save = saveLex(P.L);
1253
+ skipBlanks(P.L);
1254
+ const startB = P.L.b;
1255
+ // Must start with identifier
1256
+ if (!isIdentStart(peek(P.L))) {
1257
+ restoreLex(P.L, save);
1258
+ return null;
1259
+ }
1260
+ while (isIdentChar(peek(P.L)))
1261
+ advance(P.L);
1262
+ const nameEnd = P.L.b;
1263
+ // Optional subscript
1264
+ let subEnd = nameEnd;
1265
+ if (peek(P.L) === '[') {
1266
+ advance(P.L);
1267
+ let depth = 1;
1268
+ while (P.L.i < P.L.len && depth > 0) {
1269
+ const c = peek(P.L);
1270
+ if (c === '[')
1271
+ depth++;
1272
+ else if (c === ']')
1273
+ depth--;
1274
+ advance(P.L);
1275
+ }
1276
+ subEnd = P.L.b;
1277
+ }
1278
+ const c = peek(P.L);
1279
+ const c1 = peek(P.L, 1);
1280
+ let op;
1281
+ if (c === '=' && c1 !== '=') {
1282
+ op = '=';
1283
+ }
1284
+ else if (c === '+' && c1 === '=') {
1285
+ op = '+=';
1286
+ }
1287
+ else {
1288
+ restoreLex(P.L, save);
1289
+ return null;
1290
+ }
1291
+ const nameNode = mk(P, 'variable_name', startB, nameEnd, []);
1292
+ // Subscript handling: wrap in subscript node if present
1293
+ let lhs = nameNode;
1294
+ if (subEnd > nameEnd) {
1295
+ const brOpen = mk(P, '[', nameEnd, nameEnd + 1, []);
1296
+ const idx = parseSubscriptIndex(P, nameEnd + 1, subEnd - 1);
1297
+ const brClose = mk(P, ']', subEnd - 1, subEnd, []);
1298
+ lhs = mk(P, 'subscript', startB, subEnd, [nameNode, brOpen, idx, brClose]);
1299
+ }
1300
+ const opStart = P.L.b;
1301
+ advance(P.L);
1302
+ if (op === '+=')
1303
+ advance(P.L);
1304
+ const opEnd = P.L.b;
1305
+ const opNode = mk(P, op, opStart, opEnd, []);
1306
+ let val = null;
1307
+ if (peek(P.L) === '(') {
1308
+ // Array
1309
+ const aoTok = nextToken(P.L, 'cmd');
1310
+ const aOpen = leaf(P, '(', aoTok);
1311
+ const elems = [aOpen];
1312
+ while (true) {
1313
+ skipBlanks(P.L);
1314
+ if (peek(P.L) === ')')
1315
+ break;
1316
+ const e = parseWord(P, 'arg');
1317
+ if (!e)
1318
+ break;
1319
+ elems.push(e);
1320
+ }
1321
+ const acTok = nextToken(P.L, 'cmd');
1322
+ const aClose = acTok.value === ')'
1323
+ ? leaf(P, ')', acTok)
1324
+ : mk(P, ')', aOpen.endIndex, aOpen.endIndex, []);
1325
+ elems.push(aClose);
1326
+ val = mk(P, 'array', aOpen.startIndex, aClose.endIndex, elems);
1327
+ }
1328
+ else {
1329
+ const c2 = peek(P.L);
1330
+ if (c2 &&
1331
+ c2 !== ' ' &&
1332
+ c2 !== '\t' &&
1333
+ c2 !== '\n' &&
1334
+ c2 !== ';' &&
1335
+ c2 !== '&' &&
1336
+ c2 !== '|' &&
1337
+ c2 !== ')' &&
1338
+ c2 !== '}') {
1339
+ val = parseWord(P, 'arg');
1340
+ }
1341
+ }
1342
+ const kids = val ? [lhs, opNode, val] : [lhs, opNode];
1343
+ const end = val ? val.endIndex : opEnd;
1344
+ return mk(P, 'variable_assignment', startB, end, kids);
1345
+ }
1346
+ /**
1347
+ * Parse subscript index content. Parsed arithmetically per tree-sitter grammar:
1348
+ * `${a[1+2]}` → binary_expression; `${a[++i]}` → unary_expression(word);
1349
+ * `${a[(($n+1))]}` → compound_statement(binary_expression). Falls back to
1350
+ * simple patterns (@, *) as word.
1351
+ */
1352
+ function parseSubscriptIndexInline(P) {
1353
+ skipBlanks(P.L);
1354
+ const c = peek(P.L);
1355
+ // @ or * alone → word (associative array all-keys)
1356
+ if ((c === '@' || c === '*') && peek(P.L, 1) === ']') {
1357
+ const s = P.L.b;
1358
+ advance(P.L);
1359
+ return mk(P, 'word', s, P.L.b, []);
1360
+ }
1361
+ // ((expr)) → compound_statement wrapping the inner arithmetic
1362
+ if (c === '(' && peek(P.L, 1) === '(') {
1363
+ const oStart = P.L.b;
1364
+ advance(P.L);
1365
+ advance(P.L);
1366
+ const open = mk(P, '((', oStart, P.L.b, []);
1367
+ const inner = parseArithExpr(P, '))', 'var');
1368
+ skipBlanks(P.L);
1369
+ let close;
1370
+ if (peek(P.L) === ')' && peek(P.L, 1) === ')') {
1371
+ const cs = P.L.b;
1372
+ advance(P.L);
1373
+ advance(P.L);
1374
+ close = mk(P, '))', cs, P.L.b, []);
1375
+ }
1376
+ else {
1377
+ close = mk(P, '))', P.L.b, P.L.b, []);
1378
+ }
1379
+ const kids = inner ? [open, inner, close] : [open, close];
1380
+ return mk(P, 'compound_statement', open.startIndex, close.endIndex, kids);
1381
+ }
1382
+ // Arithmetic — but bare identifiers in subscript use 'word' mode per
1383
+ // tree-sitter (${words[++counter]} → unary_expression(word)).
1384
+ return parseArithExpr(P, ']', 'word');
1385
+ }
1386
+ /** Legacy byte-range subscript index parser — kept for callers that pre-scan. */
1387
+ function parseSubscriptIndex(P, startB, endB) {
1388
+ const text = sliceBytes(P, startB, endB);
1389
+ if (/^\d+$/.test(text))
1390
+ return mk(P, 'number', startB, endB, []);
1391
+ const m = /^\$([a-zA-Z_]\w*)$/.exec(text);
1392
+ if (m) {
1393
+ const dollar = mk(P, '$', startB, startB + 1, []);
1394
+ const vn = mk(P, 'variable_name', startB + 1, endB, []);
1395
+ return mk(P, 'simple_expansion', startB, endB, [dollar, vn]);
1396
+ }
1397
+ if (text.length === 2 && text[0] === '$' && SPECIAL_VARS.has(text[1])) {
1398
+ const dollar = mk(P, '$', startB, startB + 1, []);
1399
+ const vn = mk(P, 'special_variable_name', startB + 1, endB, []);
1400
+ return mk(P, 'simple_expansion', startB, endB, [dollar, vn]);
1401
+ }
1402
+ return mk(P, 'word', startB, endB, []);
1403
+ }
1404
+ /**
1405
+ * Can the current position start a redirect destination literal?
1406
+ * Returns false at redirect ops, terminators, or file-descriptor-prefixed ops
1407
+ * so file_redirect's repeat1($._literal) stops at the right boundary.
1408
+ */
1409
+ function isRedirectLiteralStart(P) {
1410
+ const c = peek(P.L);
1411
+ if (c === '' || c === '\n')
1412
+ return false;
1413
+ // Shell terminators and operators
1414
+ if (c === '|' || c === '&' || c === ';' || c === '(' || c === ')')
1415
+ return false;
1416
+ // Redirect operators (< > with any suffix; <( >( handled by caller)
1417
+ if (c === '<' || c === '>') {
1418
+ // <( >( are process substitutions — those ARE literals
1419
+ return peek(P.L, 1) === '(';
1420
+ }
1421
+ // N< N> file descriptor prefix — starts a new redirect, not a literal
1422
+ if (isDigit(c)) {
1423
+ let j = P.L.i;
1424
+ while (j < P.L.len && isDigit(P.L.src[j]))
1425
+ j++;
1426
+ const after = j < P.L.len ? P.L.src[j] : '';
1427
+ if (after === '>' || after === '<')
1428
+ return false;
1429
+ }
1430
+ // `}` only terminates if we're in a context where it's a closer — but
1431
+ // file_redirect sees `}` as word char (e.g., `>$HOME}` is valid path char).
1432
+ // Actually `}` at top level terminates compound_statement — need to stop.
1433
+ if (c === '}')
1434
+ return false;
1435
+ // Test command closer — when parseSimpleCommand is called from `[` context,
1436
+ // `]` must terminate so parseCommand can return and `[` handler consume it.
1437
+ if (P.stopToken === ']' && c === ']')
1438
+ return false;
1439
+ return true;
1440
+ }
1441
+ /**
1442
+ * Parse a redirect operator + destination(s).
1443
+ * @param greedy When true, file_redirect consumes repeat1($._literal) per
1444
+ * grammar's prec.left — `cmd >f a b c` attaches `a b c` to the redirect.
1445
+ * When false (preRedirect context), takes only 1 destination because
1446
+ * command's dynamic precedence beats redirected_statement's prec(-1).
1447
+ */
1448
+ function tryParseRedirect(P, greedy = false) {
1449
+ const save = saveLex(P.L);
1450
+ skipBlanks(P.L);
1451
+ // File descriptor prefix?
1452
+ let fd = null;
1453
+ if (isDigit(peek(P.L))) {
1454
+ const startB = P.L.b;
1455
+ let j = P.L.i;
1456
+ while (j < P.L.len && isDigit(P.L.src[j]))
1457
+ j++;
1458
+ const after = j < P.L.len ? P.L.src[j] : '';
1459
+ if (after === '>' || after === '<') {
1460
+ while (P.L.i < j)
1461
+ advance(P.L);
1462
+ fd = mk(P, 'file_descriptor', startB, P.L.b, []);
1463
+ }
1464
+ }
1465
+ const t = nextToken(P.L, 'arg');
1466
+ if (t.type !== 'OP') {
1467
+ restoreLex(P.L, save);
1468
+ return null;
1469
+ }
1470
+ const v = t.value;
1471
+ if (v === '<<<') {
1472
+ const op = leaf(P, '<<<', t);
1473
+ skipBlanks(P.L);
1474
+ const target = parseWord(P, 'arg');
1475
+ const end = target ? target.endIndex : op.endIndex;
1476
+ const kids = target ? [op, target] : [op];
1477
+ return mk(P, 'herestring_redirect', fd ? fd.startIndex : op.startIndex, end, fd ? [fd, ...kids] : kids);
1478
+ }
1479
+ if (v === '<<' || v === '<<-') {
1480
+ const op = leaf(P, v, t);
1481
+ // Heredoc start — delimiter word (may be quoted)
1482
+ skipBlanks(P.L);
1483
+ const dStart = P.L.b;
1484
+ let quoted = false;
1485
+ let delim = '';
1486
+ const dc = peek(P.L);
1487
+ if (dc === "'" || dc === '"') {
1488
+ quoted = true;
1489
+ advance(P.L);
1490
+ while (P.L.i < P.L.len && peek(P.L) !== dc) {
1491
+ delim += peek(P.L);
1492
+ advance(P.L);
1493
+ }
1494
+ if (P.L.i < P.L.len)
1495
+ advance(P.L);
1496
+ }
1497
+ else if (dc === '\\') {
1498
+ // Backslash-escaped delimiter: \X — exactly one escaped char, body is
1499
+ // quoted (literal). Covers <<\EOF <<\' <<\\ etc.
1500
+ quoted = true;
1501
+ advance(P.L);
1502
+ if (P.L.i < P.L.len && peek(P.L) !== '\n') {
1503
+ delim += peek(P.L);
1504
+ advance(P.L);
1505
+ }
1506
+ // May be followed by more ident chars (e.g. <<\EOF → delim "EOF")
1507
+ while (P.L.i < P.L.len && isIdentChar(peek(P.L))) {
1508
+ delim += peek(P.L);
1509
+ advance(P.L);
1510
+ }
1511
+ }
1512
+ else {
1513
+ // Unquoted delimiter: bash accepts most non-metacharacters (not just
1514
+ // identifiers). Allow !, -, ., etc. — stop at shell metachars.
1515
+ while (P.L.i < P.L.len && isHeredocDelimChar(peek(P.L))) {
1516
+ delim += peek(P.L);
1517
+ advance(P.L);
1518
+ }
1519
+ }
1520
+ const dEnd = P.L.b;
1521
+ const startNode = mk(P, 'heredoc_start', dStart, dEnd, []);
1522
+ // Register pending heredoc — body scanned at next newline
1523
+ P.L.heredocs.push({
1524
+ delim,
1525
+ stripTabs: v === '<<-',
1526
+ quoted,
1527
+ bodyStart: 0,
1528
+ bodyEnd: 0,
1529
+ endStart: 0,
1530
+ endEnd: 0,
1531
+ });
1532
+ const kids = fd ? [fd, op, startNode] : [op, startNode];
1533
+ const startIdx = fd ? fd.startIndex : op.startIndex;
1534
+ // SECURITY: tree-sitter nests any pipeline/list/file_redirect appearing
1535
+ // between heredoc_start and the newline as a CHILD of heredoc_redirect.
1536
+ // `ls <<'EOF' | rm -rf /tmp/evil` must not silently drop the rm. Parse
1537
+ // trailing words and file_redirects properly (ast.ts walkHeredocRedirect
1538
+ // fails closed on any unrecognized child via tooComplex). Pipeline / list
1539
+ // operators (| && || ;) are structurally complex — emit ERROR so the same
1540
+ // fail-closed path rejects them.
1541
+ while (true) {
1542
+ skipBlanks(P.L);
1543
+ const tc = peek(P.L);
1544
+ if (tc === '\n' || tc === '' || P.L.i >= P.L.len)
1545
+ break;
1546
+ // File redirect after delimiter: cat <<EOF > out.txt
1547
+ if (tc === '>' || tc === '<' || isDigit(tc)) {
1548
+ const rSave = saveLex(P.L);
1549
+ const r = tryParseRedirect(P);
1550
+ if (r && r.type === 'file_redirect') {
1551
+ kids.push(r);
1552
+ continue;
1553
+ }
1554
+ restoreLex(P.L, rSave);
1555
+ }
1556
+ // Pipeline after heredoc_start: `one <<EOF | grep two` — tree-sitter
1557
+ // nests the pipeline as a child of heredoc_redirect. ast.ts
1558
+ // walkHeredocRedirect fails closed on pipeline/command via tooComplex.
1559
+ if (tc === '|' && peek(P.L, 1) !== '|') {
1560
+ advance(P.L);
1561
+ skipBlanks(P.L);
1562
+ const pipeCmds = [];
1563
+ while (true) {
1564
+ const cmd = parseCommand(P);
1565
+ if (!cmd)
1566
+ break;
1567
+ pipeCmds.push(cmd);
1568
+ skipBlanks(P.L);
1569
+ if (peek(P.L) === '|' && peek(P.L, 1) !== '|') {
1570
+ const ps = P.L.b;
1571
+ advance(P.L);
1572
+ pipeCmds.push(mk(P, '|', ps, P.L.b, []));
1573
+ skipBlanks(P.L);
1574
+ continue;
1575
+ }
1576
+ break;
1577
+ }
1578
+ if (pipeCmds.length > 0) {
1579
+ const pl = pipeCmds[pipeCmds.length - 1];
1580
+ // tree-sitter always wraps in pipeline after `|`, even single command
1581
+ kids.push(mk(P, 'pipeline', pipeCmds[0].startIndex, pl.endIndex, pipeCmds));
1582
+ }
1583
+ continue;
1584
+ }
1585
+ // && / || after heredoc_start: `cat <<-EOF || die "..."` — tree-sitter
1586
+ // nests just the RHS command (not a list) as a child of heredoc_redirect.
1587
+ if ((tc === '&' && peek(P.L, 1) === '&') ||
1588
+ (tc === '|' && peek(P.L, 1) === '|')) {
1589
+ advance(P.L);
1590
+ advance(P.L);
1591
+ skipBlanks(P.L);
1592
+ const rhs = parseCommand(P);
1593
+ if (rhs)
1594
+ kids.push(rhs);
1595
+ continue;
1596
+ }
1597
+ // Terminator / unhandled metachar — consume rest of line as ERROR so
1598
+ // ast.ts rejects it. Covers ; & ( )
1599
+ if (tc === '&' || tc === ';' || tc === '(' || tc === ')') {
1600
+ const eStart = P.L.b;
1601
+ while (P.L.i < P.L.len && peek(P.L) !== '\n')
1602
+ advance(P.L);
1603
+ kids.push(mk(P, 'ERROR', eStart, P.L.b, []));
1604
+ break;
1605
+ }
1606
+ // Trailing word argument: newins <<-EOF - org.freedesktop.service
1607
+ const w = parseWord(P, 'arg');
1608
+ if (w) {
1609
+ kids.push(w);
1610
+ continue;
1611
+ }
1612
+ // Unrecognized — consume rest of line as ERROR
1613
+ const eStart = P.L.b;
1614
+ while (P.L.i < P.L.len && peek(P.L) !== '\n')
1615
+ advance(P.L);
1616
+ if (P.L.b > eStart)
1617
+ kids.push(mk(P, 'ERROR', eStart, P.L.b, []));
1618
+ break;
1619
+ }
1620
+ return mk(P, 'heredoc_redirect', startIdx, P.L.b, kids);
1621
+ }
1622
+ // Close-fd variants: `<&-` `>&-` have OPTIONAL destination (0 or 1)
1623
+ if (v === '<&-' || v === '>&-') {
1624
+ const op = leaf(P, v, t);
1625
+ const kids = [];
1626
+ if (fd)
1627
+ kids.push(fd);
1628
+ kids.push(op);
1629
+ // Optional single destination — only consume if next is a literal
1630
+ skipBlanks(P.L);
1631
+ const dSave = saveLex(P.L);
1632
+ const dest = isRedirectLiteralStart(P) ? parseWord(P, 'arg') : null;
1633
+ if (dest) {
1634
+ kids.push(dest);
1635
+ }
1636
+ else {
1637
+ restoreLex(P.L, dSave);
1638
+ }
1639
+ const startIdx = fd ? fd.startIndex : op.startIndex;
1640
+ const end = dest ? dest.endIndex : op.endIndex;
1641
+ return mk(P, 'file_redirect', startIdx, end, kids);
1642
+ }
1643
+ if (v === '>' ||
1644
+ v === '>>' ||
1645
+ v === '>&' ||
1646
+ v === '>|' ||
1647
+ v === '&>' ||
1648
+ v === '&>>' ||
1649
+ v === '<' ||
1650
+ v === '<&') {
1651
+ const op = leaf(P, v, t);
1652
+ const kids = [];
1653
+ if (fd)
1654
+ kids.push(fd);
1655
+ kids.push(op);
1656
+ // Grammar: destination is repeat1($._literal) — greedily consume literals
1657
+ // until a non-literal (redirect op, terminator, etc). tree-sitter's
1658
+ // prec.left makes `cmd >f a b c` attach `a b c` to the file_redirect,
1659
+ // NOT to the command. Structural quirk but required for corpus parity.
1660
+ // In preRedirect context (greedy=false), take only 1 literal because
1661
+ // command's dynamic precedence beats redirected_statement's prec(-1).
1662
+ let end = op.endIndex;
1663
+ let taken = 0;
1664
+ while (true) {
1665
+ skipBlanks(P.L);
1666
+ if (!isRedirectLiteralStart(P))
1667
+ break;
1668
+ if (!greedy && taken >= 1)
1669
+ break;
1670
+ const tc = peek(P.L);
1671
+ const tc1 = peek(P.L, 1);
1672
+ let target = null;
1673
+ if ((tc === '<' || tc === '>') && tc1 === '(') {
1674
+ target = parseProcessSub(P);
1675
+ }
1676
+ else {
1677
+ target = parseWord(P, 'arg');
1678
+ }
1679
+ if (!target)
1680
+ break;
1681
+ kids.push(target);
1682
+ end = target.endIndex;
1683
+ taken++;
1684
+ }
1685
+ const startIdx = fd ? fd.startIndex : op.startIndex;
1686
+ return mk(P, 'file_redirect', startIdx, end, kids);
1687
+ }
1688
+ restoreLex(P.L, save);
1689
+ return null;
1690
+ }
1691
+ function parseProcessSub(P) {
1692
+ const c = peek(P.L);
1693
+ if ((c !== '<' && c !== '>') || peek(P.L, 1) !== '(')
1694
+ return null;
1695
+ const start = P.L.b;
1696
+ advance(P.L);
1697
+ advance(P.L);
1698
+ const open = mk(P, c + '(', start, P.L.b, []);
1699
+ const body = parseStatements(P, ')');
1700
+ skipBlanks(P.L);
1701
+ let close;
1702
+ if (peek(P.L) === ')') {
1703
+ const cs = P.L.b;
1704
+ advance(P.L);
1705
+ close = mk(P, ')', cs, P.L.b, []);
1706
+ }
1707
+ else {
1708
+ close = mk(P, ')', P.L.b, P.L.b, []);
1709
+ }
1710
+ return mk(P, 'process_substitution', start, close.endIndex, [
1711
+ open,
1712
+ ...body,
1713
+ close,
1714
+ ]);
1715
+ }
1716
+ function scanHeredocBodies(P) {
1717
+ // Skip to newline if not already there
1718
+ while (P.L.i < P.L.len && P.L.src[P.L.i] !== '\n')
1719
+ advance(P.L);
1720
+ if (P.L.i < P.L.len)
1721
+ advance(P.L);
1722
+ for (const hd of P.L.heredocs) {
1723
+ hd.bodyStart = P.L.b;
1724
+ const delimLen = hd.delim.length;
1725
+ while (P.L.i < P.L.len) {
1726
+ const lineStart = P.L.i;
1727
+ const lineStartB = P.L.b;
1728
+ // Skip leading tabs if <<-
1729
+ let checkI = lineStart;
1730
+ if (hd.stripTabs) {
1731
+ while (checkI < P.L.len && P.L.src[checkI] === '\t')
1732
+ checkI++;
1733
+ }
1734
+ // Check if this line is the delimiter
1735
+ if (P.L.src.startsWith(hd.delim, checkI) &&
1736
+ (checkI + delimLen >= P.L.len ||
1737
+ P.L.src[checkI + delimLen] === '\n' ||
1738
+ P.L.src[checkI + delimLen] === '\r')) {
1739
+ hd.bodyEnd = lineStartB;
1740
+ // Advance past tabs
1741
+ while (P.L.i < checkI)
1742
+ advance(P.L);
1743
+ hd.endStart = P.L.b;
1744
+ // Advance past delimiter
1745
+ for (let k = 0; k < delimLen; k++)
1746
+ advance(P.L);
1747
+ hd.endEnd = P.L.b;
1748
+ // Skip trailing newline
1749
+ if (P.L.i < P.L.len && P.L.src[P.L.i] === '\n')
1750
+ advance(P.L);
1751
+ return;
1752
+ }
1753
+ // Consume line
1754
+ while (P.L.i < P.L.len && P.L.src[P.L.i] !== '\n')
1755
+ advance(P.L);
1756
+ if (P.L.i < P.L.len)
1757
+ advance(P.L);
1758
+ }
1759
+ // Unterminated
1760
+ hd.bodyEnd = P.L.b;
1761
+ hd.endStart = P.L.b;
1762
+ hd.endEnd = P.L.b;
1763
+ }
1764
+ }
1765
+ function parseHeredocBodyContent(P, start, end) {
1766
+ // Parse expansions inside an unquoted heredoc body.
1767
+ const saved = saveLex(P.L);
1768
+ // Position lexer at body start
1769
+ restoreLexToByte(P, start);
1770
+ const out = [];
1771
+ let contentStart = P.L.b;
1772
+ // tree-sitter-bash's heredoc_body rule hides the initial text segment
1773
+ // (_heredoc_body_beginning) — only content AFTER the first expansion is
1774
+ // emitted as heredoc_content. Track whether we've seen an expansion yet.
1775
+ let sawExpansion = false;
1776
+ while (P.L.b < end) {
1777
+ const c = peek(P.L);
1778
+ // Backslash escapes suppress expansion: \$ \` stay literal in heredoc.
1779
+ if (c === '\\') {
1780
+ const nxt = peek(P.L, 1);
1781
+ if (nxt === '$' || nxt === '`' || nxt === '\\') {
1782
+ advance(P.L);
1783
+ advance(P.L);
1784
+ continue;
1785
+ }
1786
+ advance(P.L);
1787
+ continue;
1788
+ }
1789
+ if (c === '$' || c === '`') {
1790
+ const preB = P.L.b;
1791
+ const exp = parseDollarLike(P);
1792
+ // Bare `$` followed by non-name (e.g. `$'` in a regex) returns a lone
1793
+ // '$' leaf, not an expansion — treat as literal content, don't split.
1794
+ if (exp &&
1795
+ (exp.type === 'simple_expansion' ||
1796
+ exp.type === 'expansion' ||
1797
+ exp.type === 'command_substitution' ||
1798
+ exp.type === 'arithmetic_expansion')) {
1799
+ if (sawExpansion && preB > contentStart) {
1800
+ out.push(mk(P, 'heredoc_content', contentStart, preB, []));
1801
+ }
1802
+ out.push(exp);
1803
+ contentStart = P.L.b;
1804
+ sawExpansion = true;
1805
+ }
1806
+ continue;
1807
+ }
1808
+ advance(P.L);
1809
+ }
1810
+ // Only emit heredoc_content children if there were expansions — otherwise
1811
+ // the heredoc_body is a leaf node (tree-sitter convention).
1812
+ if (sawExpansion) {
1813
+ out.push(mk(P, 'heredoc_content', contentStart, end, []));
1814
+ }
1815
+ restoreLex(P.L, saved);
1816
+ return out;
1817
+ }
1818
+ function restoreLexToByte(P, targetByte) {
1819
+ if (!P.L.byteTable)
1820
+ byteAt(P.L, 0);
1821
+ const t = P.L.byteTable;
1822
+ let lo = 0;
1823
+ let hi = P.src.length;
1824
+ while (lo < hi) {
1825
+ const m = (lo + hi) >>> 1;
1826
+ if (t[m] < targetByte)
1827
+ lo = m + 1;
1828
+ else
1829
+ hi = m;
1830
+ }
1831
+ P.L.i = lo;
1832
+ P.L.b = targetByte;
1833
+ }
1834
+ /**
1835
+ * Parse a word-position element: bare word, string, expansion, or concatenation
1836
+ * thereof. Returns a single node; if multiple adjacent fragments, wraps in
1837
+ * concatenation.
1838
+ */
1839
+ function parseWord(P, _ctx) {
1840
+ skipBlanks(P.L);
1841
+ const parts = [];
1842
+ while (P.L.i < P.L.len) {
1843
+ const c = peek(P.L);
1844
+ if (c === ' ' ||
1845
+ c === '\t' ||
1846
+ c === '\n' ||
1847
+ c === '\r' ||
1848
+ c === '' ||
1849
+ c === '|' ||
1850
+ c === '&' ||
1851
+ c === ';' ||
1852
+ c === '(' ||
1853
+ c === ')') {
1854
+ break;
1855
+ }
1856
+ // < > are redirect operators unless <( >( (process substitution)
1857
+ if (c === '<' || c === '>') {
1858
+ if (peek(P.L, 1) === '(') {
1859
+ const ps = parseProcessSub(P);
1860
+ if (ps)
1861
+ parts.push(ps);
1862
+ continue;
1863
+ }
1864
+ break;
1865
+ }
1866
+ if (c === '"') {
1867
+ parts.push(parseDoubleQuoted(P));
1868
+ continue;
1869
+ }
1870
+ if (c === "'") {
1871
+ const tok = nextToken(P.L, 'arg');
1872
+ parts.push(leaf(P, 'raw_string', tok));
1873
+ continue;
1874
+ }
1875
+ if (c === '$') {
1876
+ const c1 = peek(P.L, 1);
1877
+ if (c1 === "'") {
1878
+ const tok = nextToken(P.L, 'arg');
1879
+ parts.push(leaf(P, 'ansi_c_string', tok));
1880
+ continue;
1881
+ }
1882
+ if (c1 === '"') {
1883
+ // Translated string: emit $ leaf + string node
1884
+ const dTok = {
1885
+ type: 'DOLLAR',
1886
+ value: '$',
1887
+ start: P.L.b,
1888
+ end: P.L.b + 1,
1889
+ };
1890
+ advance(P.L);
1891
+ parts.push(leaf(P, '$', dTok));
1892
+ parts.push(parseDoubleQuoted(P));
1893
+ continue;
1894
+ }
1895
+ if (c1 === '`') {
1896
+ // `$` followed by backtick — tree-sitter elides the $ entirely
1897
+ // and emits just (command_substitution). Consume $ and let next
1898
+ // iteration handle the backtick.
1899
+ advance(P.L);
1900
+ continue;
1901
+ }
1902
+ const exp = parseDollarLike(P);
1903
+ if (exp)
1904
+ parts.push(exp);
1905
+ continue;
1906
+ }
1907
+ if (c === '`') {
1908
+ if (P.inBacktick > 0)
1909
+ break;
1910
+ const bt = parseBacktick(P);
1911
+ if (bt)
1912
+ parts.push(bt);
1913
+ continue;
1914
+ }
1915
+ // Brace expression {1..5} or {a,b,c} — only if looks like one
1916
+ if (c === '{') {
1917
+ const be = tryParseBraceExpr(P);
1918
+ if (be) {
1919
+ parts.push(be);
1920
+ continue;
1921
+ }
1922
+ // SECURITY: if `{` is immediately followed by a command terminator
1923
+ // (; | & newline or EOF), it's a standalone word — don't slurp the
1924
+ // rest of the line via tryParseBraceLikeCat. `echo {;touch /tmp/evil`
1925
+ // must split on `;` so the security walker sees `touch`.
1926
+ const nc = peek(P.L, 1);
1927
+ if (nc === ';' ||
1928
+ nc === '|' ||
1929
+ nc === '&' ||
1930
+ nc === '\n' ||
1931
+ nc === '' ||
1932
+ nc === ')' ||
1933
+ nc === ' ' ||
1934
+ nc === '\t') {
1935
+ const bStart = P.L.b;
1936
+ advance(P.L);
1937
+ parts.push(mk(P, 'word', bStart, P.L.b, []));
1938
+ continue;
1939
+ }
1940
+ // Otherwise treat { and } as word fragments
1941
+ const cat = tryParseBraceLikeCat(P);
1942
+ if (cat) {
1943
+ for (const p of cat)
1944
+ parts.push(p);
1945
+ continue;
1946
+ }
1947
+ }
1948
+ // Standalone `}` in arg position is a word (e.g., `echo }foo`).
1949
+ // parseBareWord breaks on `}` so handle it here.
1950
+ if (c === '}') {
1951
+ const bStart = P.L.b;
1952
+ advance(P.L);
1953
+ parts.push(mk(P, 'word', bStart, P.L.b, []));
1954
+ continue;
1955
+ }
1956
+ // `[` and `]` are single-char word fragments (tree-sitter splits at
1957
+ // brackets: `[:lower:]` → `[` `:lower:` `]`, `{o[k]}` → 6 words).
1958
+ if (c === '[' || c === ']') {
1959
+ const bStart = P.L.b;
1960
+ advance(P.L);
1961
+ parts.push(mk(P, 'word', bStart, P.L.b, []));
1962
+ continue;
1963
+ }
1964
+ // Bare word fragment
1965
+ const frag = parseBareWord(P);
1966
+ if (!frag)
1967
+ break;
1968
+ // `NN#${...}` or `NN#$(...)` → (number (expansion|command_substitution)).
1969
+ // Grammar: number can be seq(/-?(0x)?[0-9]+#/, choice(expansion, cmd_sub)).
1970
+ // `10#${cmd}` must NOT be concatenation — it's a single number node with
1971
+ // the expansion as child. Detect here: frag ends with `#`, next is $ {/(.
1972
+ if (frag.type === 'word' &&
1973
+ /^-?(0x)?[0-9]+#$/.test(frag.text) &&
1974
+ peek(P.L) === '$' &&
1975
+ (peek(P.L, 1) === '{' || peek(P.L, 1) === '(')) {
1976
+ const exp = parseDollarLike(P);
1977
+ if (exp) {
1978
+ // Prefix `NN#` is an anonymous pattern in grammar — only the
1979
+ // expansion/cmd_sub is a named child.
1980
+ parts.push(mk(P, 'number', frag.startIndex, exp.endIndex, [exp]));
1981
+ continue;
1982
+ }
1983
+ }
1984
+ parts.push(frag);
1985
+ }
1986
+ if (parts.length === 0)
1987
+ return null;
1988
+ if (parts.length === 1)
1989
+ return parts[0];
1990
+ // Concatenation
1991
+ const first = parts[0];
1992
+ const last = parts[parts.length - 1];
1993
+ return mk(P, 'concatenation', first.startIndex, last.endIndex, parts);
1994
+ }
1995
+ function parseBareWord(P) {
1996
+ const start = P.L.b;
1997
+ const startI = P.L.i;
1998
+ while (P.L.i < P.L.len) {
1999
+ const c = peek(P.L);
2000
+ if (c === '\\') {
2001
+ if (P.L.i + 1 >= P.L.len) {
2002
+ // Trailing unpaired `\` at true EOF — tree-sitter emits word WITHOUT
2003
+ // the `\` plus a sibling ERROR node. Stop here; caller emits ERROR.
2004
+ break;
2005
+ }
2006
+ const nx = P.L.src[P.L.i + 1];
2007
+ if (nx === '\n' || (nx === '\r' && P.L.src[P.L.i + 2] === '\n')) {
2008
+ // Line continuation BREAKS the word (tree-sitter quirk) — handles \r?\n
2009
+ break;
2010
+ }
2011
+ advance(P.L);
2012
+ advance(P.L);
2013
+ continue;
2014
+ }
2015
+ if (c === ' ' ||
2016
+ c === '\t' ||
2017
+ c === '\n' ||
2018
+ c === '\r' ||
2019
+ c === '' ||
2020
+ c === '|' ||
2021
+ c === '&' ||
2022
+ c === ';' ||
2023
+ c === '(' ||
2024
+ c === ')' ||
2025
+ c === '<' ||
2026
+ c === '>' ||
2027
+ c === '"' ||
2028
+ c === "'" ||
2029
+ c === '$' ||
2030
+ c === '`' ||
2031
+ c === '{' ||
2032
+ c === '}' ||
2033
+ c === '[' ||
2034
+ c === ']') {
2035
+ break;
2036
+ }
2037
+ advance(P.L);
2038
+ }
2039
+ if (P.L.b === start)
2040
+ return null;
2041
+ const text = P.src.slice(startI, P.L.i);
2042
+ const type = /^-?\d+$/.test(text) ? 'number' : 'word';
2043
+ return mk(P, type, start, P.L.b, []);
2044
+ }
2045
+ function tryParseBraceExpr(P) {
2046
+ // {N..M} where N, M are numbers or single chars
2047
+ const save = saveLex(P.L);
2048
+ if (peek(P.L) !== '{')
2049
+ return null;
2050
+ const oStart = P.L.b;
2051
+ advance(P.L);
2052
+ const oEnd = P.L.b;
2053
+ // First part
2054
+ const p1Start = P.L.b;
2055
+ while (isDigit(peek(P.L)) || isIdentStart(peek(P.L)))
2056
+ advance(P.L);
2057
+ const p1End = P.L.b;
2058
+ if (p1End === p1Start || peek(P.L) !== '.' || peek(P.L, 1) !== '.') {
2059
+ restoreLex(P.L, save);
2060
+ return null;
2061
+ }
2062
+ const dotStart = P.L.b;
2063
+ advance(P.L);
2064
+ advance(P.L);
2065
+ const dotEnd = P.L.b;
2066
+ const p2Start = P.L.b;
2067
+ while (isDigit(peek(P.L)) || isIdentStart(peek(P.L)))
2068
+ advance(P.L);
2069
+ const p2End = P.L.b;
2070
+ if (p2End === p2Start || peek(P.L) !== '}') {
2071
+ restoreLex(P.L, save);
2072
+ return null;
2073
+ }
2074
+ const cStart = P.L.b;
2075
+ advance(P.L);
2076
+ const cEnd = P.L.b;
2077
+ const p1Text = sliceBytes(P, p1Start, p1End);
2078
+ const p2Text = sliceBytes(P, p2Start, p2End);
2079
+ const p1IsNum = /^\d+$/.test(p1Text);
2080
+ const p2IsNum = /^\d+$/.test(p2Text);
2081
+ // Valid brace expression: both numbers OR both single chars. Mixed = reject.
2082
+ if (p1IsNum !== p2IsNum) {
2083
+ restoreLex(P.L, save);
2084
+ return null;
2085
+ }
2086
+ if (!p1IsNum && (p1Text.length !== 1 || p2Text.length !== 1)) {
2087
+ restoreLex(P.L, save);
2088
+ return null;
2089
+ }
2090
+ const p1Type = p1IsNum ? 'number' : 'word';
2091
+ const p2Type = p2IsNum ? 'number' : 'word';
2092
+ return mk(P, 'brace_expression', oStart, cEnd, [
2093
+ mk(P, '{', oStart, oEnd, []),
2094
+ mk(P, p1Type, p1Start, p1End, []),
2095
+ mk(P, '..', dotStart, dotEnd, []),
2096
+ mk(P, p2Type, p2Start, p2End, []),
2097
+ mk(P, '}', cStart, cEnd, []),
2098
+ ]);
2099
+ }
2100
+ function tryParseBraceLikeCat(P) {
2101
+ // {a,b,c} or {} → split into word fragments like tree-sitter does
2102
+ if (peek(P.L) !== '{')
2103
+ return null;
2104
+ const oStart = P.L.b;
2105
+ advance(P.L);
2106
+ const oEnd = P.L.b;
2107
+ const inner = [mk(P, 'word', oStart, oEnd, [])];
2108
+ while (P.L.i < P.L.len) {
2109
+ const bc = peek(P.L);
2110
+ // SECURITY: stop at command terminators so `{foo;rm x` splits correctly.
2111
+ if (bc === '}' ||
2112
+ bc === '\n' ||
2113
+ bc === ';' ||
2114
+ bc === '|' ||
2115
+ bc === '&' ||
2116
+ bc === ' ' ||
2117
+ bc === '\t' ||
2118
+ bc === '<' ||
2119
+ bc === '>' ||
2120
+ bc === '(' ||
2121
+ bc === ')') {
2122
+ break;
2123
+ }
2124
+ // `[` and `]` are single-char words: {o[k]} → { o [ k ] }
2125
+ if (bc === '[' || bc === ']') {
2126
+ const bStart = P.L.b;
2127
+ advance(P.L);
2128
+ inner.push(mk(P, 'word', bStart, P.L.b, []));
2129
+ continue;
2130
+ }
2131
+ const midStart = P.L.b;
2132
+ while (P.L.i < P.L.len) {
2133
+ const mc = peek(P.L);
2134
+ if (mc === '}' ||
2135
+ mc === '\n' ||
2136
+ mc === ';' ||
2137
+ mc === '|' ||
2138
+ mc === '&' ||
2139
+ mc === ' ' ||
2140
+ mc === '\t' ||
2141
+ mc === '<' ||
2142
+ mc === '>' ||
2143
+ mc === '(' ||
2144
+ mc === ')' ||
2145
+ mc === '[' ||
2146
+ mc === ']') {
2147
+ break;
2148
+ }
2149
+ advance(P.L);
2150
+ }
2151
+ const midEnd = P.L.b;
2152
+ if (midEnd > midStart) {
2153
+ const midText = sliceBytes(P, midStart, midEnd);
2154
+ const midType = /^-?\d+$/.test(midText) ? 'number' : 'word';
2155
+ inner.push(mk(P, midType, midStart, midEnd, []));
2156
+ }
2157
+ else {
2158
+ break;
2159
+ }
2160
+ }
2161
+ if (peek(P.L) === '}') {
2162
+ const cStart = P.L.b;
2163
+ advance(P.L);
2164
+ inner.push(mk(P, 'word', cStart, P.L.b, []));
2165
+ }
2166
+ return inner;
2167
+ }
2168
+ function parseDoubleQuoted(P) {
2169
+ const qStart = P.L.b;
2170
+ advance(P.L);
2171
+ const qEnd = P.L.b;
2172
+ const openQ = mk(P, '"', qStart, qEnd, []);
2173
+ const parts = [openQ];
2174
+ let contentStart = P.L.b;
2175
+ let contentStartI = P.L.i;
2176
+ const flushContent = () => {
2177
+ if (P.L.b > contentStart) {
2178
+ // Tree-sitter's extras rule /\s/ has higher precedence than
2179
+ // string_content (prec -1), so whitespace-only segments are elided.
2180
+ // `" ${x} "` → (string (expansion)) not (string (string_content)(expansion)(string_content)).
2181
+ // Note: this intentionally diverges from preserving all content — cc
2182
+ // tests relying on whitespace-only string_content need updating
2183
+ // (CCReconcile).
2184
+ const txt = P.src.slice(contentStartI, P.L.i);
2185
+ if (!/^[ \t]+$/.test(txt)) {
2186
+ parts.push(mk(P, 'string_content', contentStart, P.L.b, []));
2187
+ }
2188
+ }
2189
+ };
2190
+ while (P.L.i < P.L.len) {
2191
+ const c = peek(P.L);
2192
+ if (c === '"')
2193
+ break;
2194
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
2195
+ advance(P.L);
2196
+ advance(P.L);
2197
+ continue;
2198
+ }
2199
+ if (c === '\n') {
2200
+ // Split string_content at newline
2201
+ flushContent();
2202
+ advance(P.L);
2203
+ contentStart = P.L.b;
2204
+ contentStartI = P.L.i;
2205
+ continue;
2206
+ }
2207
+ if (c === '$') {
2208
+ const c1 = peek(P.L, 1);
2209
+ if (c1 === '(' ||
2210
+ c1 === '{' ||
2211
+ isIdentStart(c1) ||
2212
+ SPECIAL_VARS.has(c1) ||
2213
+ isDigit(c1)) {
2214
+ flushContent();
2215
+ const exp = parseDollarLike(P);
2216
+ if (exp)
2217
+ parts.push(exp);
2218
+ contentStart = P.L.b;
2219
+ contentStartI = P.L.i;
2220
+ continue;
2221
+ }
2222
+ // Bare $ not at end-of-string: tree-sitter emits it as an anonymous
2223
+ // '$' token, which splits string_content. $ immediately before the
2224
+ // closing " is absorbed into the preceding string_content.
2225
+ if (c1 !== '"' && c1 !== '') {
2226
+ flushContent();
2227
+ const dS = P.L.b;
2228
+ advance(P.L);
2229
+ parts.push(mk(P, '$', dS, P.L.b, []));
2230
+ contentStart = P.L.b;
2231
+ contentStartI = P.L.i;
2232
+ continue;
2233
+ }
2234
+ }
2235
+ if (c === '`') {
2236
+ flushContent();
2237
+ const bt = parseBacktick(P);
2238
+ if (bt)
2239
+ parts.push(bt);
2240
+ contentStart = P.L.b;
2241
+ contentStartI = P.L.i;
2242
+ continue;
2243
+ }
2244
+ advance(P.L);
2245
+ }
2246
+ flushContent();
2247
+ let close;
2248
+ if (peek(P.L) === '"') {
2249
+ const cStart = P.L.b;
2250
+ advance(P.L);
2251
+ close = mk(P, '"', cStart, P.L.b, []);
2252
+ }
2253
+ else {
2254
+ close = mk(P, '"', P.L.b, P.L.b, []);
2255
+ }
2256
+ parts.push(close);
2257
+ return mk(P, 'string', qStart, close.endIndex, parts);
2258
+ }
2259
+ function parseDollarLike(P) {
2260
+ const c1 = peek(P.L, 1);
2261
+ const dStart = P.L.b;
2262
+ if (c1 === '(' && peek(P.L, 2) === '(') {
2263
+ // $(( arithmetic ))
2264
+ advance(P.L);
2265
+ advance(P.L);
2266
+ advance(P.L);
2267
+ const open = mk(P, '$((', dStart, P.L.b, []);
2268
+ const exprs = parseArithCommaList(P, '))', 'var');
2269
+ skipBlanks(P.L);
2270
+ let close;
2271
+ if (peek(P.L) === ')' && peek(P.L, 1) === ')') {
2272
+ const cStart = P.L.b;
2273
+ advance(P.L);
2274
+ advance(P.L);
2275
+ close = mk(P, '))', cStart, P.L.b, []);
2276
+ }
2277
+ else {
2278
+ close = mk(P, '))', P.L.b, P.L.b, []);
2279
+ }
2280
+ return mk(P, 'arithmetic_expansion', dStart, close.endIndex, [
2281
+ open,
2282
+ ...exprs,
2283
+ close,
2284
+ ]);
2285
+ }
2286
+ if (c1 === '[') {
2287
+ // $[ arithmetic ] — legacy bash syntax, same as $((...))
2288
+ advance(P.L);
2289
+ advance(P.L);
2290
+ const open = mk(P, '$[', dStart, P.L.b, []);
2291
+ const exprs = parseArithCommaList(P, ']', 'var');
2292
+ skipBlanks(P.L);
2293
+ let close;
2294
+ if (peek(P.L) === ']') {
2295
+ const cStart = P.L.b;
2296
+ advance(P.L);
2297
+ close = mk(P, ']', cStart, P.L.b, []);
2298
+ }
2299
+ else {
2300
+ close = mk(P, ']', P.L.b, P.L.b, []);
2301
+ }
2302
+ return mk(P, 'arithmetic_expansion', dStart, close.endIndex, [
2303
+ open,
2304
+ ...exprs,
2305
+ close,
2306
+ ]);
2307
+ }
2308
+ if (c1 === '(') {
2309
+ advance(P.L);
2310
+ advance(P.L);
2311
+ const open = mk(P, '$(', dStart, P.L.b, []);
2312
+ let body = parseStatements(P, ')');
2313
+ skipBlanks(P.L);
2314
+ let close;
2315
+ if (peek(P.L) === ')') {
2316
+ const cStart = P.L.b;
2317
+ advance(P.L);
2318
+ close = mk(P, ')', cStart, P.L.b, []);
2319
+ }
2320
+ else {
2321
+ close = mk(P, ')', P.L.b, P.L.b, []);
2322
+ }
2323
+ // $(< file) shorthand: unwrap redirected_statement → bare file_redirect
2324
+ // tree-sitter emits (command_substitution (file_redirect (word))) directly
2325
+ if (body.length === 1 &&
2326
+ body[0].type === 'redirected_statement' &&
2327
+ body[0].children.length === 1 &&
2328
+ body[0].children[0].type === 'file_redirect') {
2329
+ body = body[0].children;
2330
+ }
2331
+ return mk(P, 'command_substitution', dStart, close.endIndex, [
2332
+ open,
2333
+ ...body,
2334
+ close,
2335
+ ]);
2336
+ }
2337
+ if (c1 === '{') {
2338
+ advance(P.L);
2339
+ advance(P.L);
2340
+ const open = mk(P, '${', dStart, P.L.b, []);
2341
+ const inner = parseExpansionBody(P);
2342
+ let close;
2343
+ if (peek(P.L) === '}') {
2344
+ const cStart = P.L.b;
2345
+ advance(P.L);
2346
+ close = mk(P, '}', cStart, P.L.b, []);
2347
+ }
2348
+ else {
2349
+ close = mk(P, '}', P.L.b, P.L.b, []);
2350
+ }
2351
+ return mk(P, 'expansion', dStart, close.endIndex, [open, ...inner, close]);
2352
+ }
2353
+ // Simple expansion $VAR or $? $$ $@ etc
2354
+ advance(P.L);
2355
+ const dEnd = P.L.b;
2356
+ const dollar = mk(P, '$', dStart, dEnd, []);
2357
+ const nc = peek(P.L);
2358
+ // $_ is special_variable_name only when not followed by more ident chars
2359
+ if (nc === '_' && !isIdentChar(peek(P.L, 1))) {
2360
+ const vStart = P.L.b;
2361
+ advance(P.L);
2362
+ const vn = mk(P, 'special_variable_name', vStart, P.L.b, []);
2363
+ return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
2364
+ }
2365
+ if (isIdentStart(nc)) {
2366
+ const vStart = P.L.b;
2367
+ while (isIdentChar(peek(P.L)))
2368
+ advance(P.L);
2369
+ const vn = mk(P, 'variable_name', vStart, P.L.b, []);
2370
+ return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
2371
+ }
2372
+ if (isDigit(nc)) {
2373
+ const vStart = P.L.b;
2374
+ advance(P.L);
2375
+ const vn = mk(P, 'variable_name', vStart, P.L.b, []);
2376
+ return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
2377
+ }
2378
+ if (SPECIAL_VARS.has(nc)) {
2379
+ const vStart = P.L.b;
2380
+ advance(P.L);
2381
+ const vn = mk(P, 'special_variable_name', vStart, P.L.b, []);
2382
+ return mk(P, 'simple_expansion', dStart, P.L.b, [dollar, vn]);
2383
+ }
2384
+ // Bare $ — just a $ leaf (tree-sitter treats trailing $ as literal)
2385
+ return dollar;
2386
+ }
2387
+ function parseExpansionBody(P) {
2388
+ const out = [];
2389
+ skipBlanks(P.L);
2390
+ // Bizarre cases: ${#!} ${!#} ${!##} ${!# } ${!## } all emit empty (expansion)
2391
+ // — both # and ! become anonymous nodes when only combined with each other
2392
+ // and optional trailing space before }. Note ${!##/} does NOT match (has
2393
+ // content after), so it parses normally as (special_variable_name)(regex).
2394
+ {
2395
+ const c0 = peek(P.L);
2396
+ const c1 = peek(P.L, 1);
2397
+ if (c0 === '#' && c1 === '!' && peek(P.L, 2) === '}') {
2398
+ advance(P.L);
2399
+ advance(P.L);
2400
+ return out;
2401
+ }
2402
+ if (c0 === '!' && c1 === '#') {
2403
+ // ${!#} ${!##} with optional trailing space then }
2404
+ let j = 2;
2405
+ if (peek(P.L, j) === '#')
2406
+ j++;
2407
+ if (peek(P.L, j) === ' ')
2408
+ j++;
2409
+ if (peek(P.L, j) === '}') {
2410
+ while (j-- > 0)
2411
+ advance(P.L);
2412
+ return out;
2413
+ }
2414
+ }
2415
+ }
2416
+ // Optional # prefix for length
2417
+ if (peek(P.L) === '#') {
2418
+ const s = P.L.b;
2419
+ advance(P.L);
2420
+ out.push(mk(P, '#', s, P.L.b, []));
2421
+ }
2422
+ // Optional ! prefix for indirect expansion: ${!varname} ${!prefix*} ${!prefix@}
2423
+ // Only when followed by an identifier — ${!} alone is special var $!
2424
+ // Also = ~ prefixes (zsh-style ${=var} ${~var})
2425
+ const pc = peek(P.L);
2426
+ if ((pc === '!' || pc === '=' || pc === '~') &&
2427
+ (isIdentStart(peek(P.L, 1)) || isDigit(peek(P.L, 1)))) {
2428
+ const s = P.L.b;
2429
+ advance(P.L);
2430
+ out.push(mk(P, pc, s, P.L.b, []));
2431
+ }
2432
+ skipBlanks(P.L);
2433
+ // Variable name
2434
+ if (isIdentStart(peek(P.L))) {
2435
+ const s = P.L.b;
2436
+ while (isIdentChar(peek(P.L)))
2437
+ advance(P.L);
2438
+ out.push(mk(P, 'variable_name', s, P.L.b, []));
2439
+ }
2440
+ else if (isDigit(peek(P.L))) {
2441
+ const s = P.L.b;
2442
+ while (isDigit(peek(P.L)))
2443
+ advance(P.L);
2444
+ out.push(mk(P, 'variable_name', s, P.L.b, []));
2445
+ }
2446
+ else if (SPECIAL_VARS.has(peek(P.L))) {
2447
+ const s = P.L.b;
2448
+ advance(P.L);
2449
+ out.push(mk(P, 'special_variable_name', s, P.L.b, []));
2450
+ }
2451
+ // Optional subscript [idx] — parsed arithmetically
2452
+ if (peek(P.L) === '[') {
2453
+ const varNode = out[out.length - 1];
2454
+ const brOpen = P.L.b;
2455
+ advance(P.L);
2456
+ const brOpenNode = mk(P, '[', brOpen, P.L.b, []);
2457
+ const idx = parseSubscriptIndexInline(P);
2458
+ skipBlanks(P.L);
2459
+ const brClose = P.L.b;
2460
+ if (peek(P.L) === ']')
2461
+ advance(P.L);
2462
+ const brCloseNode = mk(P, ']', brClose, P.L.b, []);
2463
+ if (varNode) {
2464
+ const kids = idx
2465
+ ? [varNode, brOpenNode, idx, brCloseNode]
2466
+ : [varNode, brOpenNode, brCloseNode];
2467
+ out[out.length - 1] = mk(P, 'subscript', varNode.startIndex, P.L.b, kids);
2468
+ }
2469
+ }
2470
+ skipBlanks(P.L);
2471
+ // Trailing * or @ for indirect expansion (${!prefix*} ${!prefix@}) or
2472
+ // @operator for parameter transformation (${var@U} ${var@Q}) — anonymous
2473
+ const tc = peek(P.L);
2474
+ if ((tc === '*' || tc === '@') && peek(P.L, 1) === '}') {
2475
+ const s = P.L.b;
2476
+ advance(P.L);
2477
+ out.push(mk(P, tc, s, P.L.b, []));
2478
+ return out;
2479
+ }
2480
+ if (tc === '@' && isIdentStart(peek(P.L, 1))) {
2481
+ // ${var@U} transformation — @ is anonymous, consume op char(s)
2482
+ const s = P.L.b;
2483
+ advance(P.L);
2484
+ out.push(mk(P, '@', s, P.L.b, []));
2485
+ while (isIdentChar(peek(P.L)))
2486
+ advance(P.L);
2487
+ return out;
2488
+ }
2489
+ // Operator :- := :? :+ - = ? + # ## % %% / // ^ ^^ , ,, etc.
2490
+ const c = peek(P.L);
2491
+ // Bare `:` substring operator ${var:off:len} — offset and length parsed
2492
+ // arithmetically. Must come BEFORE the generic operator handling so `(` after
2493
+ // `:` goes to parenthesized_expression not the array path. `:-` `:=` `:?`
2494
+ // `:+` (no space) remain default-value operators; `: -1` (with space before
2495
+ // -1) is substring with negative offset.
2496
+ if (c === ':') {
2497
+ const c1 = peek(P.L, 1);
2498
+ // `:\n` or `:}` — empty substring expansion, emits nothing (variable_name only)
2499
+ if (c1 === '\n' || c1 === '}') {
2500
+ advance(P.L);
2501
+ while (peek(P.L) === '\n')
2502
+ advance(P.L);
2503
+ return out;
2504
+ }
2505
+ if (c1 !== '-' && c1 !== '=' && c1 !== '?' && c1 !== '+') {
2506
+ advance(P.L);
2507
+ skipBlanks(P.L);
2508
+ // Offset — arithmetic. `-N` at top level is a single number node per
2509
+ // tree-sitter; inside parens it's unary_expression(number).
2510
+ const offC = peek(P.L);
2511
+ let off;
2512
+ if (offC === '-' && isDigit(peek(P.L, 1))) {
2513
+ const ns = P.L.b;
2514
+ advance(P.L);
2515
+ while (isDigit(peek(P.L)))
2516
+ advance(P.L);
2517
+ off = mk(P, 'number', ns, P.L.b, []);
2518
+ }
2519
+ else {
2520
+ off = parseArithExpr(P, ':}', 'var');
2521
+ }
2522
+ if (off)
2523
+ out.push(off);
2524
+ skipBlanks(P.L);
2525
+ if (peek(P.L) === ':') {
2526
+ advance(P.L);
2527
+ skipBlanks(P.L);
2528
+ const lenC = peek(P.L);
2529
+ let len;
2530
+ if (lenC === '-' && isDigit(peek(P.L, 1))) {
2531
+ const ns = P.L.b;
2532
+ advance(P.L);
2533
+ while (isDigit(peek(P.L)))
2534
+ advance(P.L);
2535
+ len = mk(P, 'number', ns, P.L.b, []);
2536
+ }
2537
+ else {
2538
+ len = parseArithExpr(P, '}', 'var');
2539
+ }
2540
+ if (len)
2541
+ out.push(len);
2542
+ }
2543
+ return out;
2544
+ }
2545
+ }
2546
+ if (c === ':' ||
2547
+ c === '#' ||
2548
+ c === '%' ||
2549
+ c === '/' ||
2550
+ c === '^' ||
2551
+ c === ',' ||
2552
+ c === '-' ||
2553
+ c === '=' ||
2554
+ c === '?' ||
2555
+ c === '+') {
2556
+ const s = P.L.b;
2557
+ const c1 = peek(P.L, 1);
2558
+ let op = c;
2559
+ if (c === ':' && (c1 === '-' || c1 === '=' || c1 === '?' || c1 === '+')) {
2560
+ advance(P.L);
2561
+ advance(P.L);
2562
+ op = c + c1;
2563
+ }
2564
+ else if ((c === '#' || c === '%' || c === '/' || c === '^' || c === ',') &&
2565
+ c1 === c) {
2566
+ // Doubled operators: ## %% // ^^ ,,
2567
+ advance(P.L);
2568
+ advance(P.L);
2569
+ op = c + c;
2570
+ }
2571
+ else {
2572
+ advance(P.L);
2573
+ }
2574
+ out.push(mk(P, op, s, P.L.b, []));
2575
+ // Rest is the default/replacement — parse as word or regex until }
2576
+ // Pattern-matching operators (# ## % %% / // ^ ^^ , ,,) emit regex;
2577
+ // value-substitution operators (:- := :? :+ - = ? + :) emit word.
2578
+ // `/` and `//` split at next `/` into (regex)+(word) for pat/repl.
2579
+ const isPattern = op === '#' ||
2580
+ op === '##' ||
2581
+ op === '%' ||
2582
+ op === '%%' ||
2583
+ op === '/' ||
2584
+ op === '//' ||
2585
+ op === '^' ||
2586
+ op === '^^' ||
2587
+ op === ',' ||
2588
+ op === ',,';
2589
+ if (op === '/' || op === '//') {
2590
+ // Optional /# or /% anchor prefix — anonymous node
2591
+ const ac = peek(P.L);
2592
+ if (ac === '#' || ac === '%') {
2593
+ const aStart = P.L.b;
2594
+ advance(P.L);
2595
+ out.push(mk(P, ac, aStart, P.L.b, []));
2596
+ }
2597
+ // Pattern: per grammar _expansion_regex_replacement, pattern is
2598
+ // choice(regex, string, cmd_sub, seq(string, regex)). If it STARTS
2599
+ // with ", emit (string) and any trailing chars become (regex).
2600
+ // `${v//"${old}"/}` → (string(expansion)); `${v//"${c}"\//}` →
2601
+ // (string)(regex).
2602
+ if (peek(P.L) === '"') {
2603
+ out.push(parseDoubleQuoted(P));
2604
+ const tail = parseExpansionRest(P, 'regex', true);
2605
+ if (tail)
2606
+ out.push(tail);
2607
+ }
2608
+ else {
2609
+ const regex = parseExpansionRest(P, 'regex', true);
2610
+ if (regex)
2611
+ out.push(regex);
2612
+ }
2613
+ if (peek(P.L) === '/') {
2614
+ const sepStart = P.L.b;
2615
+ advance(P.L);
2616
+ out.push(mk(P, '/', sepStart, P.L.b, []));
2617
+ // Replacement: per grammar, choice includes `seq(cmd_sub, word)`
2618
+ // which emits TWO siblings (not concatenation). Also `(` at start
2619
+ // of replacement is a regular word char, NOT array — unlike `:-`
2620
+ // default-value context. `${v/(/(Gentoo ${x}, }` replacement
2621
+ // `(Gentoo ${x}, ` is (concatenation (word)(expansion)(word)).
2622
+ const repl = parseExpansionRest(P, 'replword', false);
2623
+ if (repl) {
2624
+ // seq(cmd_sub, word) special case → siblings. Detected when
2625
+ // replacement is a concatenation of exactly 2 parts with first
2626
+ // being command_substitution.
2627
+ if (repl.type === 'concatenation' &&
2628
+ repl.children.length === 2 &&
2629
+ repl.children[0].type === 'command_substitution') {
2630
+ out.push(repl.children[0]);
2631
+ out.push(repl.children[1]);
2632
+ }
2633
+ else {
2634
+ out.push(repl);
2635
+ }
2636
+ }
2637
+ }
2638
+ }
2639
+ else if (op === '#' || op === '##' || op === '%' || op === '%%') {
2640
+ // Pattern-removal: per grammar _expansion_regex, pattern is
2641
+ // repeat(choice(regex, string, raw_string, ')')). Each quote/string
2642
+ // is a SIBLING, not absorbed into one regex. `${f%'str'*}` →
2643
+ // (raw_string)(regex); `${f/'str'*}` (slash) stays single regex.
2644
+ for (const p of parseExpansionRegexSegmented(P))
2645
+ out.push(p);
2646
+ }
2647
+ else {
2648
+ const rest = parseExpansionRest(P, isPattern ? 'regex' : 'word', false);
2649
+ if (rest)
2650
+ out.push(rest);
2651
+ }
2652
+ }
2653
+ return out;
2654
+ }
2655
+ function parseExpansionRest(P, nodeType, stopAtSlash) {
2656
+ // Don't skipBlanks — `${var:- }` space IS the word. Stop at } or newline
2657
+ // (`${var:\n}` emits no word). stopAtSlash=true stops at `/` for pat/repl
2658
+ // split in ${var/pat/repl}. nodeType 'replword' is word-mode for the
2659
+ // replacement in `/` `//` — same as 'word' but `(` is NOT array.
2660
+ const start = P.L.b;
2661
+ // Value-substitution RHS starting with `(` parses as array: ${var:-(x)} →
2662
+ // (expansion (variable_name) (array (word))). Only for 'word' context (not
2663
+ // pattern-matching operators which emit regex, and not 'replword' where `(`
2664
+ // is a regular char per grammar `_expansion_regex_replacement`).
2665
+ if (nodeType === 'word' && peek(P.L) === '(') {
2666
+ advance(P.L);
2667
+ const open = mk(P, '(', start, P.L.b, []);
2668
+ const elems = [open];
2669
+ while (P.L.i < P.L.len) {
2670
+ skipBlanks(P.L);
2671
+ const c = peek(P.L);
2672
+ if (c === ')' || c === '}' || c === '\n' || c === '')
2673
+ break;
2674
+ const wStart = P.L.b;
2675
+ while (P.L.i < P.L.len) {
2676
+ const wc = peek(P.L);
2677
+ if (wc === ')' ||
2678
+ wc === '}' ||
2679
+ wc === ' ' ||
2680
+ wc === '\t' ||
2681
+ wc === '\n' ||
2682
+ wc === '') {
2683
+ break;
2684
+ }
2685
+ advance(P.L);
2686
+ }
2687
+ if (P.L.b > wStart)
2688
+ elems.push(mk(P, 'word', wStart, P.L.b, []));
2689
+ else
2690
+ break;
2691
+ }
2692
+ if (peek(P.L) === ')') {
2693
+ const cStart = P.L.b;
2694
+ advance(P.L);
2695
+ elems.push(mk(P, ')', cStart, P.L.b, []));
2696
+ }
2697
+ while (peek(P.L) === '\n')
2698
+ advance(P.L);
2699
+ return mk(P, 'array', start, P.L.b, elems);
2700
+ }
2701
+ // REGEX mode: flat single-span scan. Quotes are opaque (skipped past so
2702
+ // `/` inside them doesn't break stopAtSlash), but NOT emitted as separate
2703
+ // nodes — the entire range becomes one regex node.
2704
+ if (nodeType === 'regex') {
2705
+ let braceDepth = 0;
2706
+ while (P.L.i < P.L.len) {
2707
+ const c = peek(P.L);
2708
+ if (c === '\n')
2709
+ break;
2710
+ if (braceDepth === 0) {
2711
+ if (c === '}')
2712
+ break;
2713
+ if (stopAtSlash && c === '/')
2714
+ break;
2715
+ }
2716
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
2717
+ advance(P.L);
2718
+ advance(P.L);
2719
+ continue;
2720
+ }
2721
+ if (c === '"' || c === "'") {
2722
+ advance(P.L);
2723
+ while (P.L.i < P.L.len && peek(P.L) !== c) {
2724
+ if (peek(P.L) === '\\' && P.L.i + 1 < P.L.len)
2725
+ advance(P.L);
2726
+ advance(P.L);
2727
+ }
2728
+ if (peek(P.L) === c)
2729
+ advance(P.L);
2730
+ continue;
2731
+ }
2732
+ // Skip past nested ${...} $(...) $[...] so their } / don't terminate us
2733
+ if (c === '$') {
2734
+ const c1 = peek(P.L, 1);
2735
+ if (c1 === '{') {
2736
+ let d = 0;
2737
+ advance(P.L);
2738
+ advance(P.L);
2739
+ d++;
2740
+ while (P.L.i < P.L.len && d > 0) {
2741
+ const nc = peek(P.L);
2742
+ if (nc === '{')
2743
+ d++;
2744
+ else if (nc === '}')
2745
+ d--;
2746
+ advance(P.L);
2747
+ }
2748
+ continue;
2749
+ }
2750
+ if (c1 === '(') {
2751
+ let d = 0;
2752
+ advance(P.L);
2753
+ advance(P.L);
2754
+ d++;
2755
+ while (P.L.i < P.L.len && d > 0) {
2756
+ const nc = peek(P.L);
2757
+ if (nc === '(')
2758
+ d++;
2759
+ else if (nc === ')')
2760
+ d--;
2761
+ advance(P.L);
2762
+ }
2763
+ continue;
2764
+ }
2765
+ }
2766
+ if (c === '{')
2767
+ braceDepth++;
2768
+ else if (c === '}' && braceDepth > 0)
2769
+ braceDepth--;
2770
+ advance(P.L);
2771
+ }
2772
+ const end = P.L.b;
2773
+ while (peek(P.L) === '\n')
2774
+ advance(P.L);
2775
+ if (end === start)
2776
+ return null;
2777
+ return mk(P, 'regex', start, end, []);
2778
+ }
2779
+ // WORD mode: segmenting parser — recognize nested ${...}, $(...), $'...',
2780
+ // "...", '...', $ident, <(...)/>(...); bare chars accumulate into word
2781
+ // segments. Multiple parts → wrapped in concatenation.
2782
+ const parts = [];
2783
+ let segStart = P.L.b;
2784
+ let braceDepth = 0;
2785
+ const flushSeg = () => {
2786
+ if (P.L.b > segStart) {
2787
+ parts.push(mk(P, 'word', segStart, P.L.b, []));
2788
+ }
2789
+ };
2790
+ while (P.L.i < P.L.len) {
2791
+ const c = peek(P.L);
2792
+ if (c === '\n')
2793
+ break;
2794
+ if (braceDepth === 0) {
2795
+ if (c === '}')
2796
+ break;
2797
+ if (stopAtSlash && c === '/')
2798
+ break;
2799
+ }
2800
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
2801
+ advance(P.L);
2802
+ advance(P.L);
2803
+ continue;
2804
+ }
2805
+ const c1 = peek(P.L, 1);
2806
+ if (c === '$') {
2807
+ if (c1 === '{' || c1 === '(' || c1 === '[') {
2808
+ flushSeg();
2809
+ const exp = parseDollarLike(P);
2810
+ if (exp)
2811
+ parts.push(exp);
2812
+ segStart = P.L.b;
2813
+ continue;
2814
+ }
2815
+ if (c1 === "'") {
2816
+ // $'...' ANSI-C string
2817
+ flushSeg();
2818
+ const aStart = P.L.b;
2819
+ advance(P.L);
2820
+ advance(P.L);
2821
+ while (P.L.i < P.L.len && peek(P.L) !== "'") {
2822
+ if (peek(P.L) === '\\' && P.L.i + 1 < P.L.len)
2823
+ advance(P.L);
2824
+ advance(P.L);
2825
+ }
2826
+ if (peek(P.L) === "'")
2827
+ advance(P.L);
2828
+ parts.push(mk(P, 'ansi_c_string', aStart, P.L.b, []));
2829
+ segStart = P.L.b;
2830
+ continue;
2831
+ }
2832
+ if (isIdentStart(c1) || isDigit(c1) || SPECIAL_VARS.has(c1)) {
2833
+ flushSeg();
2834
+ const exp = parseDollarLike(P);
2835
+ if (exp)
2836
+ parts.push(exp);
2837
+ segStart = P.L.b;
2838
+ continue;
2839
+ }
2840
+ }
2841
+ if (c === '"') {
2842
+ flushSeg();
2843
+ parts.push(parseDoubleQuoted(P));
2844
+ segStart = P.L.b;
2845
+ continue;
2846
+ }
2847
+ if (c === "'") {
2848
+ flushSeg();
2849
+ const rStart = P.L.b;
2850
+ advance(P.L);
2851
+ while (P.L.i < P.L.len && peek(P.L) !== "'")
2852
+ advance(P.L);
2853
+ if (peek(P.L) === "'")
2854
+ advance(P.L);
2855
+ parts.push(mk(P, 'raw_string', rStart, P.L.b, []));
2856
+ segStart = P.L.b;
2857
+ continue;
2858
+ }
2859
+ if ((c === '<' || c === '>') && c1 === '(') {
2860
+ flushSeg();
2861
+ const ps = parseProcessSub(P);
2862
+ if (ps)
2863
+ parts.push(ps);
2864
+ segStart = P.L.b;
2865
+ continue;
2866
+ }
2867
+ if (c === '`') {
2868
+ flushSeg();
2869
+ const bt = parseBacktick(P);
2870
+ if (bt)
2871
+ parts.push(bt);
2872
+ segStart = P.L.b;
2873
+ continue;
2874
+ }
2875
+ // Brace tracking so nested {a,b} brace-expansion chars don't prematurely
2876
+ // terminate (rare, but the `?` in `${cond}? (` should be treated as word).
2877
+ if (c === '{')
2878
+ braceDepth++;
2879
+ else if (c === '}' && braceDepth > 0)
2880
+ braceDepth--;
2881
+ advance(P.L);
2882
+ }
2883
+ flushSeg();
2884
+ // Consume trailing newlines before } so caller sees }
2885
+ while (peek(P.L) === '\n')
2886
+ advance(P.L);
2887
+ // Tree-sitter skips leading whitespace (extras) in expansion RHS when
2888
+ // there's content after: `${2+ ${2}}` → just (expansion). But `${v:- }`
2889
+ // (space-only RHS) keeps the space as (word). So drop leading whitespace-
2890
+ // only word segment if it's NOT the only part.
2891
+ if (parts.length > 1 &&
2892
+ parts[0].type === 'word' &&
2893
+ /^[ \t]+$/.test(parts[0].text)) {
2894
+ parts.shift();
2895
+ }
2896
+ if (parts.length === 0)
2897
+ return null;
2898
+ if (parts.length === 1)
2899
+ return parts[0];
2900
+ // Multiple parts: wrap in concatenation (word mode keeps concat wrapping;
2901
+ // regex mode also concats per tree-sitter for mixed quote+glob patterns).
2902
+ const last = parts[parts.length - 1];
2903
+ return mk(P, 'concatenation', parts[0].startIndex, last.endIndex, parts);
2904
+ }
2905
+ // Pattern for # ## % %% operators — per grammar _expansion_regex:
2906
+ // repeat(choice(regex, string, raw_string, ')', /\s+/→regex)). Each quote
2907
+ // becomes a SIBLING node, not absorbed. `${f%'str'*}` → (raw_string)(regex).
2908
+ function parseExpansionRegexSegmented(P) {
2909
+ const out = [];
2910
+ let segStart = P.L.b;
2911
+ const flushRegex = () => {
2912
+ if (P.L.b > segStart)
2913
+ out.push(mk(P, 'regex', segStart, P.L.b, []));
2914
+ };
2915
+ while (P.L.i < P.L.len) {
2916
+ const c = peek(P.L);
2917
+ if (c === '}' || c === '\n')
2918
+ break;
2919
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
2920
+ advance(P.L);
2921
+ advance(P.L);
2922
+ continue;
2923
+ }
2924
+ if (c === '"') {
2925
+ flushRegex();
2926
+ out.push(parseDoubleQuoted(P));
2927
+ segStart = P.L.b;
2928
+ continue;
2929
+ }
2930
+ if (c === "'") {
2931
+ flushRegex();
2932
+ const rStart = P.L.b;
2933
+ advance(P.L);
2934
+ while (P.L.i < P.L.len && peek(P.L) !== "'")
2935
+ advance(P.L);
2936
+ if (peek(P.L) === "'")
2937
+ advance(P.L);
2938
+ out.push(mk(P, 'raw_string', rStart, P.L.b, []));
2939
+ segStart = P.L.b;
2940
+ continue;
2941
+ }
2942
+ // Nested ${...} $(...) — opaque scan so their } doesn't terminate us
2943
+ if (c === '$') {
2944
+ const c1 = peek(P.L, 1);
2945
+ if (c1 === '{') {
2946
+ let d = 1;
2947
+ advance(P.L);
2948
+ advance(P.L);
2949
+ while (P.L.i < P.L.len && d > 0) {
2950
+ const nc = peek(P.L);
2951
+ if (nc === '{')
2952
+ d++;
2953
+ else if (nc === '}')
2954
+ d--;
2955
+ advance(P.L);
2956
+ }
2957
+ continue;
2958
+ }
2959
+ if (c1 === '(') {
2960
+ let d = 1;
2961
+ advance(P.L);
2962
+ advance(P.L);
2963
+ while (P.L.i < P.L.len && d > 0) {
2964
+ const nc = peek(P.L);
2965
+ if (nc === '(')
2966
+ d++;
2967
+ else if (nc === ')')
2968
+ d--;
2969
+ advance(P.L);
2970
+ }
2971
+ continue;
2972
+ }
2973
+ }
2974
+ advance(P.L);
2975
+ }
2976
+ flushRegex();
2977
+ while (peek(P.L) === '\n')
2978
+ advance(P.L);
2979
+ return out;
2980
+ }
2981
+ function parseBacktick(P) {
2982
+ const start = P.L.b;
2983
+ advance(P.L);
2984
+ const open = mk(P, '`', start, P.L.b, []);
2985
+ P.inBacktick++;
2986
+ // Parse statements inline — stop at closing backtick
2987
+ const body = [];
2988
+ while (true) {
2989
+ skipBlanks(P.L);
2990
+ if (peek(P.L) === '`' || peek(P.L) === '')
2991
+ break;
2992
+ const save = saveLex(P.L);
2993
+ const t = nextToken(P.L, 'cmd');
2994
+ if (t.type === 'EOF' || t.type === 'BACKTICK') {
2995
+ restoreLex(P.L, save);
2996
+ break;
2997
+ }
2998
+ if (t.type === 'NEWLINE')
2999
+ continue;
3000
+ restoreLex(P.L, save);
3001
+ const stmt = parseAndOr(P);
3002
+ if (!stmt)
3003
+ break;
3004
+ body.push(stmt);
3005
+ skipBlanks(P.L);
3006
+ if (peek(P.L) === '`')
3007
+ break;
3008
+ const save2 = saveLex(P.L);
3009
+ const sep = nextToken(P.L, 'cmd');
3010
+ if (sep.type === 'OP' && (sep.value === ';' || sep.value === '&')) {
3011
+ body.push(leaf(P, sep.value, sep));
3012
+ }
3013
+ else if (sep.type !== 'NEWLINE') {
3014
+ restoreLex(P.L, save2);
3015
+ }
3016
+ }
3017
+ P.inBacktick--;
3018
+ let close;
3019
+ if (peek(P.L) === '`') {
3020
+ const cStart = P.L.b;
3021
+ advance(P.L);
3022
+ close = mk(P, '`', cStart, P.L.b, []);
3023
+ }
3024
+ else {
3025
+ close = mk(P, '`', P.L.b, P.L.b, []);
3026
+ }
3027
+ // Empty backticks (whitespace/newline only) are elided entirely by
3028
+ // tree-sitter — used as a line-continuation hack: "foo"`<newline>`"bar"
3029
+ // → (concatenation (string) (string)) with no command_substitution.
3030
+ if (body.length === 0)
3031
+ return null;
3032
+ return mk(P, 'command_substitution', start, close.endIndex, [
3033
+ open,
3034
+ ...body,
3035
+ close,
3036
+ ]);
3037
+ }
3038
+ function parseIf(P, ifTok) {
3039
+ const ifKw = leaf(P, 'if', ifTok);
3040
+ const kids = [ifKw];
3041
+ const cond = parseStatements(P, null);
3042
+ kids.push(...cond);
3043
+ consumeKeyword(P, 'then', kids);
3044
+ const body = parseStatements(P, null);
3045
+ kids.push(...body);
3046
+ while (true) {
3047
+ const save = saveLex(P.L);
3048
+ const t = nextToken(P.L, 'cmd');
3049
+ if (t.type === 'WORD' && t.value === 'elif') {
3050
+ const eKw = leaf(P, 'elif', t);
3051
+ const eCond = parseStatements(P, null);
3052
+ const eKids = [eKw, ...eCond];
3053
+ consumeKeyword(P, 'then', eKids);
3054
+ const eBody = parseStatements(P, null);
3055
+ eKids.push(...eBody);
3056
+ const last = eKids[eKids.length - 1];
3057
+ kids.push(mk(P, 'elif_clause', eKw.startIndex, last.endIndex, eKids));
3058
+ }
3059
+ else if (t.type === 'WORD' && t.value === 'else') {
3060
+ const elKw = leaf(P, 'else', t);
3061
+ const elBody = parseStatements(P, null);
3062
+ const last = elBody.length > 0 ? elBody[elBody.length - 1] : elKw;
3063
+ kids.push(mk(P, 'else_clause', elKw.startIndex, last.endIndex, [elKw, ...elBody]));
3064
+ }
3065
+ else {
3066
+ restoreLex(P.L, save);
3067
+ break;
3068
+ }
3069
+ }
3070
+ consumeKeyword(P, 'fi', kids);
3071
+ const last = kids[kids.length - 1];
3072
+ return mk(P, 'if_statement', ifKw.startIndex, last.endIndex, kids);
3073
+ }
3074
+ function parseWhile(P, kwTok) {
3075
+ const kw = leaf(P, kwTok.value, kwTok);
3076
+ const kids = [kw];
3077
+ const cond = parseStatements(P, null);
3078
+ kids.push(...cond);
3079
+ const dg = parseDoGroup(P);
3080
+ if (dg)
3081
+ kids.push(dg);
3082
+ const last = kids[kids.length - 1];
3083
+ return mk(P, 'while_statement', kw.startIndex, last.endIndex, kids);
3084
+ }
3085
+ function parseFor(P, forTok) {
3086
+ const forKw = leaf(P, forTok.value, forTok);
3087
+ skipBlanks(P.L);
3088
+ // C-style for (( ; ; )) — only for `for`, not `select`
3089
+ if (forTok.value === 'for' && peek(P.L) === '(' && peek(P.L, 1) === '(') {
3090
+ const oStart = P.L.b;
3091
+ advance(P.L);
3092
+ advance(P.L);
3093
+ const open = mk(P, '((', oStart, P.L.b, []);
3094
+ const kids = [forKw, open];
3095
+ // init; cond; update — all three use 'assign' mode so `c = expr` emits
3096
+ // variable_assignment, while bare idents (c in `c<=5`) → word. Each
3097
+ // clause may be a comma-separated list.
3098
+ for (let k = 0; k < 3; k++) {
3099
+ skipBlanks(P.L);
3100
+ const es = parseArithCommaList(P, k < 2 ? ';' : '))', 'assign');
3101
+ kids.push(...es);
3102
+ if (k < 2) {
3103
+ if (peek(P.L) === ';') {
3104
+ const s = P.L.b;
3105
+ advance(P.L);
3106
+ kids.push(mk(P, ';', s, P.L.b, []));
3107
+ }
3108
+ }
3109
+ }
3110
+ skipBlanks(P.L);
3111
+ if (peek(P.L) === ')' && peek(P.L, 1) === ')') {
3112
+ const cStart = P.L.b;
3113
+ advance(P.L);
3114
+ advance(P.L);
3115
+ kids.push(mk(P, '))', cStart, P.L.b, []));
3116
+ }
3117
+ // Optional ; or newline
3118
+ const save = saveLex(P.L);
3119
+ const sep = nextToken(P.L, 'cmd');
3120
+ if (sep.type === 'OP' && sep.value === ';') {
3121
+ kids.push(leaf(P, ';', sep));
3122
+ }
3123
+ else if (sep.type !== 'NEWLINE') {
3124
+ restoreLex(P.L, save);
3125
+ }
3126
+ const dg = parseDoGroup(P);
3127
+ if (dg) {
3128
+ kids.push(dg);
3129
+ }
3130
+ else {
3131
+ // C-style for can also use `{ ... }` body instead of `do ... done`
3132
+ skipNewlines(P);
3133
+ skipBlanks(P.L);
3134
+ if (peek(P.L) === '{') {
3135
+ const bOpen = P.L.b;
3136
+ advance(P.L);
3137
+ const brace = mk(P, '{', bOpen, P.L.b, []);
3138
+ const body = parseStatements(P, '}');
3139
+ let bClose;
3140
+ if (peek(P.L) === '}') {
3141
+ const cs = P.L.b;
3142
+ advance(P.L);
3143
+ bClose = mk(P, '}', cs, P.L.b, []);
3144
+ }
3145
+ else {
3146
+ bClose = mk(P, '}', P.L.b, P.L.b, []);
3147
+ }
3148
+ kids.push(mk(P, 'compound_statement', brace.startIndex, bClose.endIndex, [
3149
+ brace,
3150
+ ...body,
3151
+ bClose,
3152
+ ]));
3153
+ }
3154
+ }
3155
+ const last = kids[kids.length - 1];
3156
+ return mk(P, 'c_style_for_statement', forKw.startIndex, last.endIndex, kids);
3157
+ }
3158
+ // Regular for VAR in words; do ... done
3159
+ const kids = [forKw];
3160
+ const varTok = nextToken(P.L, 'arg');
3161
+ kids.push(mk(P, 'variable_name', varTok.start, varTok.end, []));
3162
+ skipBlanks(P.L);
3163
+ const save = saveLex(P.L);
3164
+ const inTok = nextToken(P.L, 'arg');
3165
+ if (inTok.type === 'WORD' && inTok.value === 'in') {
3166
+ kids.push(leaf(P, 'in', inTok));
3167
+ while (true) {
3168
+ skipBlanks(P.L);
3169
+ const c = peek(P.L);
3170
+ if (c === ';' || c === '\n' || c === '')
3171
+ break;
3172
+ const w = parseWord(P, 'arg');
3173
+ if (!w)
3174
+ break;
3175
+ kids.push(w);
3176
+ }
3177
+ }
3178
+ else {
3179
+ restoreLex(P.L, save);
3180
+ }
3181
+ // Separator
3182
+ const save2 = saveLex(P.L);
3183
+ const sep = nextToken(P.L, 'cmd');
3184
+ if (sep.type === 'OP' && sep.value === ';') {
3185
+ kids.push(leaf(P, ';', sep));
3186
+ }
3187
+ else if (sep.type !== 'NEWLINE') {
3188
+ restoreLex(P.L, save2);
3189
+ }
3190
+ const dg = parseDoGroup(P);
3191
+ if (dg)
3192
+ kids.push(dg);
3193
+ const last = kids[kids.length - 1];
3194
+ return mk(P, 'for_statement', forKw.startIndex, last.endIndex, kids);
3195
+ }
3196
+ function parseDoGroup(P) {
3197
+ skipNewlines(P);
3198
+ const save = saveLex(P.L);
3199
+ const doTok = nextToken(P.L, 'cmd');
3200
+ if (doTok.type !== 'WORD' || doTok.value !== 'do') {
3201
+ restoreLex(P.L, save);
3202
+ return null;
3203
+ }
3204
+ const doKw = leaf(P, 'do', doTok);
3205
+ const body = parseStatements(P, null);
3206
+ const kids = [doKw, ...body];
3207
+ consumeKeyword(P, 'done', kids);
3208
+ const last = kids[kids.length - 1];
3209
+ return mk(P, 'do_group', doKw.startIndex, last.endIndex, kids);
3210
+ }
3211
+ function parseCase(P, caseTok) {
3212
+ const caseKw = leaf(P, 'case', caseTok);
3213
+ const kids = [caseKw];
3214
+ skipBlanks(P.L);
3215
+ const word = parseWord(P, 'arg');
3216
+ if (word)
3217
+ kids.push(word);
3218
+ skipBlanks(P.L);
3219
+ consumeKeyword(P, 'in', kids);
3220
+ skipNewlines(P);
3221
+ while (true) {
3222
+ skipBlanks(P.L);
3223
+ skipNewlines(P);
3224
+ const save = saveLex(P.L);
3225
+ const t = nextToken(P.L, 'arg');
3226
+ if (t.type === 'WORD' && t.value === 'esac') {
3227
+ kids.push(leaf(P, 'esac', t));
3228
+ break;
3229
+ }
3230
+ if (t.type === 'EOF')
3231
+ break;
3232
+ restoreLex(P.L, save);
3233
+ const item = parseCaseItem(P);
3234
+ if (!item)
3235
+ break;
3236
+ kids.push(item);
3237
+ }
3238
+ const last = kids[kids.length - 1];
3239
+ return mk(P, 'case_statement', caseKw.startIndex, last.endIndex, kids);
3240
+ }
3241
+ function parseCaseItem(P) {
3242
+ skipBlanks(P.L);
3243
+ const start = P.L.b;
3244
+ const kids = [];
3245
+ // Optional leading '(' before pattern — bash allows (pattern) syntax
3246
+ if (peek(P.L) === '(') {
3247
+ const s = P.L.b;
3248
+ advance(P.L);
3249
+ kids.push(mk(P, '(', s, P.L.b, []));
3250
+ }
3251
+ // Pattern(s)
3252
+ let isFirstAlt = true;
3253
+ while (true) {
3254
+ skipBlanks(P.L);
3255
+ const c = peek(P.L);
3256
+ if (c === ')' || c === '')
3257
+ break;
3258
+ const pats = parseCasePattern(P);
3259
+ if (pats.length === 0)
3260
+ break;
3261
+ // tree-sitter quirk: first alternative with quotes is inlined as flat
3262
+ // siblings; subsequent alternatives are wrapped in (concatenation) with
3263
+ // `word` instead of `extglob_pattern` for bare segments.
3264
+ if (!isFirstAlt && pats.length > 1) {
3265
+ const rewritten = pats.map(p => p.type === 'extglob_pattern'
3266
+ ? mk(P, 'word', p.startIndex, p.endIndex, [])
3267
+ : p);
3268
+ const first = rewritten[0];
3269
+ const last = rewritten[rewritten.length - 1];
3270
+ kids.push(mk(P, 'concatenation', first.startIndex, last.endIndex, rewritten));
3271
+ }
3272
+ else {
3273
+ kids.push(...pats);
3274
+ }
3275
+ isFirstAlt = false;
3276
+ skipBlanks(P.L);
3277
+ // \<newline> line continuation between alternatives
3278
+ if (peek(P.L) === '\\' && peek(P.L, 1) === '\n') {
3279
+ advance(P.L);
3280
+ advance(P.L);
3281
+ skipBlanks(P.L);
3282
+ }
3283
+ if (peek(P.L) === '|') {
3284
+ const s = P.L.b;
3285
+ advance(P.L);
3286
+ kids.push(mk(P, '|', s, P.L.b, []));
3287
+ // \<newline> after | is also a line continuation
3288
+ if (peek(P.L) === '\\' && peek(P.L, 1) === '\n') {
3289
+ advance(P.L);
3290
+ advance(P.L);
3291
+ }
3292
+ }
3293
+ else {
3294
+ break;
3295
+ }
3296
+ }
3297
+ if (peek(P.L) === ')') {
3298
+ const s = P.L.b;
3299
+ advance(P.L);
3300
+ kids.push(mk(P, ')', s, P.L.b, []));
3301
+ }
3302
+ const body = parseStatements(P, null);
3303
+ kids.push(...body);
3304
+ const save = saveLex(P.L);
3305
+ const term = nextToken(P.L, 'cmd');
3306
+ if (term.type === 'OP' &&
3307
+ (term.value === ';;' || term.value === ';&' || term.value === ';;&')) {
3308
+ kids.push(leaf(P, term.value, term));
3309
+ }
3310
+ else {
3311
+ restoreLex(P.L, save);
3312
+ }
3313
+ if (kids.length === 0)
3314
+ return null;
3315
+ // tree-sitter quirk: case_item with EMPTY body and a single pattern matching
3316
+ // extglob-operator-char-prefix (no actual glob metachars) downgrades to word.
3317
+ // `-o) owner=$2 ;;` (has body) → extglob_pattern; `-g) ;;` (empty) → word.
3318
+ if (body.length === 0) {
3319
+ for (let i = 0; i < kids.length; i++) {
3320
+ const k = kids[i];
3321
+ if (k.type !== 'extglob_pattern')
3322
+ continue;
3323
+ const text = sliceBytes(P, k.startIndex, k.endIndex);
3324
+ if (/^[-+?*@!][a-zA-Z]/.test(text) && !/[*?(]/.test(text)) {
3325
+ kids[i] = mk(P, 'word', k.startIndex, k.endIndex, []);
3326
+ }
3327
+ }
3328
+ }
3329
+ const last = kids[kids.length - 1];
3330
+ return mk(P, 'case_item', start, last.endIndex, kids);
3331
+ }
3332
+ function parseCasePattern(P) {
3333
+ skipBlanks(P.L);
3334
+ const save = saveLex(P.L);
3335
+ const start = P.L.b;
3336
+ const startI = P.L.i;
3337
+ let parenDepth = 0;
3338
+ let hasDollar = false;
3339
+ let hasBracketOutsideParen = false;
3340
+ let hasQuote = false;
3341
+ while (P.L.i < P.L.len) {
3342
+ const c = peek(P.L);
3343
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
3344
+ // Escaped char — consume both (handles `bar\ baz` as single pattern)
3345
+ // \<newline> is a line continuation; eat it but stay in pattern.
3346
+ advance(P.L);
3347
+ advance(P.L);
3348
+ continue;
3349
+ }
3350
+ if (c === '"' || c === "'") {
3351
+ hasQuote = true;
3352
+ // Skip past the quoted segment so its content (spaces, |, etc.) doesn't
3353
+ // break the peek-ahead scan.
3354
+ advance(P.L);
3355
+ while (P.L.i < P.L.len && peek(P.L) !== c) {
3356
+ if (peek(P.L) === '\\' && P.L.i + 1 < P.L.len)
3357
+ advance(P.L);
3358
+ advance(P.L);
3359
+ }
3360
+ if (peek(P.L) === c)
3361
+ advance(P.L);
3362
+ continue;
3363
+ }
3364
+ // Paren counting: any ( inside pattern opens a scope; don't break at ) or |
3365
+ // until balanced. Handles extglob *(a|b) and nested shapes *([0-9])([0-9]).
3366
+ if (c === '(') {
3367
+ parenDepth++;
3368
+ advance(P.L);
3369
+ continue;
3370
+ }
3371
+ if (parenDepth > 0) {
3372
+ if (c === ')') {
3373
+ parenDepth--;
3374
+ advance(P.L);
3375
+ continue;
3376
+ }
3377
+ if (c === '\n')
3378
+ break;
3379
+ advance(P.L);
3380
+ continue;
3381
+ }
3382
+ if (c === ')' || c === '|' || c === ' ' || c === '\t' || c === '\n')
3383
+ break;
3384
+ if (c === '$')
3385
+ hasDollar = true;
3386
+ if (c === '[')
3387
+ hasBracketOutsideParen = true;
3388
+ advance(P.L);
3389
+ }
3390
+ if (P.L.b === start)
3391
+ return [];
3392
+ const text = P.src.slice(startI, P.L.i);
3393
+ const hasExtglobParen = /[*?+@!]\(/.test(text);
3394
+ // Quoted segments in pattern: tree-sitter splits at quote boundaries into
3395
+ // multiple sibling nodes. `*"foo"*` → (extglob_pattern)(string)(extglob_pattern).
3396
+ // Re-scan with a segmenting pass.
3397
+ if (hasQuote && !hasExtglobParen) {
3398
+ restoreLex(P.L, save);
3399
+ return parseCasePatternSegmented(P);
3400
+ }
3401
+ // tree-sitter splits patterns with [ or $ into concatenation via word parsing
3402
+ // UNLESS pattern has extglob parens (those override and emit extglob_pattern).
3403
+ // `*.[1357]` → concat(word word number word); `${PN}.pot` → concat(expansion word);
3404
+ // but `*([0-9])` → extglob_pattern (has extglob paren).
3405
+ if (!hasExtglobParen && (hasDollar || hasBracketOutsideParen)) {
3406
+ restoreLex(P.L, save);
3407
+ const w = parseWord(P, 'arg');
3408
+ return w ? [w] : [];
3409
+ }
3410
+ // Patterns starting with extglob operator chars (+ - ? * @ !) followed by
3411
+ // identifier chars are extglob_pattern per tree-sitter, even without parens
3412
+ // or glob metachars. `-o)` → extglob_pattern; plain `foo)` → word.
3413
+ const type = hasExtglobParen || /[*?]/.test(text) || /^[-+?*@!][a-zA-Z]/.test(text)
3414
+ ? 'extglob_pattern'
3415
+ : 'word';
3416
+ return [mk(P, type, start, P.L.b, [])];
3417
+ }
3418
+ // Segmented scan for case patterns containing quotes: `*"foo"*` →
3419
+ // [extglob_pattern, string, extglob_pattern]. Bare segments → extglob_pattern
3420
+ // if they have */?, else word. Stops at ) | space tab newline outside quotes.
3421
+ function parseCasePatternSegmented(P) {
3422
+ const parts = [];
3423
+ let segStart = P.L.b;
3424
+ let segStartI = P.L.i;
3425
+ const flushSeg = () => {
3426
+ if (P.L.i > segStartI) {
3427
+ const t = P.src.slice(segStartI, P.L.i);
3428
+ const type = /[*?]/.test(t) ? 'extglob_pattern' : 'word';
3429
+ parts.push(mk(P, type, segStart, P.L.b, []));
3430
+ }
3431
+ };
3432
+ while (P.L.i < P.L.len) {
3433
+ const c = peek(P.L);
3434
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
3435
+ advance(P.L);
3436
+ advance(P.L);
3437
+ continue;
3438
+ }
3439
+ if (c === '"') {
3440
+ flushSeg();
3441
+ parts.push(parseDoubleQuoted(P));
3442
+ segStart = P.L.b;
3443
+ segStartI = P.L.i;
3444
+ continue;
3445
+ }
3446
+ if (c === "'") {
3447
+ flushSeg();
3448
+ const tok = nextToken(P.L, 'arg');
3449
+ parts.push(leaf(P, 'raw_string', tok));
3450
+ segStart = P.L.b;
3451
+ segStartI = P.L.i;
3452
+ continue;
3453
+ }
3454
+ if (c === ')' || c === '|' || c === ' ' || c === '\t' || c === '\n')
3455
+ break;
3456
+ advance(P.L);
3457
+ }
3458
+ flushSeg();
3459
+ return parts;
3460
+ }
3461
+ function parseFunction(P, fnTok) {
3462
+ const fnKw = leaf(P, 'function', fnTok);
3463
+ skipBlanks(P.L);
3464
+ const nameTok = nextToken(P.L, 'arg');
3465
+ const name = mk(P, 'word', nameTok.start, nameTok.end, []);
3466
+ const kids = [fnKw, name];
3467
+ skipBlanks(P.L);
3468
+ if (peek(P.L) === '(' && peek(P.L, 1) === ')') {
3469
+ const o = nextToken(P.L, 'cmd');
3470
+ const c = nextToken(P.L, 'cmd');
3471
+ kids.push(leaf(P, '(', o));
3472
+ kids.push(leaf(P, ')', c));
3473
+ }
3474
+ skipBlanks(P.L);
3475
+ skipNewlines(P);
3476
+ const body = parseCommand(P);
3477
+ if (body) {
3478
+ // Hoist redirects from redirected_statement(compound_statement, ...) to
3479
+ // function_definition level per tree-sitter grammar
3480
+ if (body.type === 'redirected_statement' &&
3481
+ body.children.length >= 2 &&
3482
+ body.children[0].type === 'compound_statement') {
3483
+ kids.push(...body.children);
3484
+ }
3485
+ else {
3486
+ kids.push(body);
3487
+ }
3488
+ }
3489
+ const last = kids[kids.length - 1];
3490
+ return mk(P, 'function_definition', fnKw.startIndex, last.endIndex, kids);
3491
+ }
3492
+ function parseDeclaration(P, kwTok) {
3493
+ const kw = leaf(P, kwTok.value, kwTok);
3494
+ const kids = [kw];
3495
+ while (true) {
3496
+ skipBlanks(P.L);
3497
+ const c = peek(P.L);
3498
+ if (c === '' ||
3499
+ c === '\n' ||
3500
+ c === ';' ||
3501
+ c === '&' ||
3502
+ c === '|' ||
3503
+ c === ')' ||
3504
+ c === '<' ||
3505
+ c === '>') {
3506
+ break;
3507
+ }
3508
+ const a = tryParseAssignment(P);
3509
+ if (a) {
3510
+ kids.push(a);
3511
+ continue;
3512
+ }
3513
+ // Quoted string or concatenation: `export "FOO=bar"`, `export 'X'`
3514
+ if (c === '"' || c === "'" || c === '$') {
3515
+ const w = parseWord(P, 'arg');
3516
+ if (w) {
3517
+ kids.push(w);
3518
+ continue;
3519
+ }
3520
+ break;
3521
+ }
3522
+ // Flag like -a or bare variable name
3523
+ const save = saveLex(P.L);
3524
+ const tok = nextToken(P.L, 'arg');
3525
+ if (tok.type === 'WORD' || tok.type === 'NUMBER') {
3526
+ if (tok.value.startsWith('-')) {
3527
+ kids.push(leaf(P, 'word', tok));
3528
+ }
3529
+ else if (isIdentStart(tok.value[0] ?? '')) {
3530
+ kids.push(mk(P, 'variable_name', tok.start, tok.end, []));
3531
+ }
3532
+ else {
3533
+ kids.push(leaf(P, 'word', tok));
3534
+ }
3535
+ }
3536
+ else {
3537
+ restoreLex(P.L, save);
3538
+ break;
3539
+ }
3540
+ }
3541
+ const last = kids[kids.length - 1];
3542
+ return mk(P, 'declaration_command', kw.startIndex, last.endIndex, kids);
3543
+ }
3544
+ function parseUnset(P, kwTok) {
3545
+ const kw = leaf(P, 'unset', kwTok);
3546
+ const kids = [kw];
3547
+ while (true) {
3548
+ skipBlanks(P.L);
3549
+ const c = peek(P.L);
3550
+ if (c === '' ||
3551
+ c === '\n' ||
3552
+ c === ';' ||
3553
+ c === '&' ||
3554
+ c === '|' ||
3555
+ c === ')' ||
3556
+ c === '<' ||
3557
+ c === '>') {
3558
+ break;
3559
+ }
3560
+ // SECURITY: use parseWord (not raw nextToken) so quoted strings like
3561
+ // `unset 'a[$(id)]'` emit a raw_string child that ast.ts can reject.
3562
+ // Previously `break` silently dropped non-WORD args — hiding the
3563
+ // arithmetic-subscript code-exec vector from the security walker.
3564
+ const arg = parseWord(P, 'arg');
3565
+ if (!arg)
3566
+ break;
3567
+ if (arg.type === 'word') {
3568
+ if (arg.text.startsWith('-')) {
3569
+ kids.push(arg);
3570
+ }
3571
+ else {
3572
+ kids.push(mk(P, 'variable_name', arg.startIndex, arg.endIndex, []));
3573
+ }
3574
+ }
3575
+ else {
3576
+ kids.push(arg);
3577
+ }
3578
+ }
3579
+ const last = kids[kids.length - 1];
3580
+ return mk(P, 'unset_command', kw.startIndex, last.endIndex, kids);
3581
+ }
3582
+ function consumeKeyword(P, name, kids) {
3583
+ skipNewlines(P);
3584
+ const save = saveLex(P.L);
3585
+ const t = nextToken(P.L, 'cmd');
3586
+ if (t.type === 'WORD' && t.value === name) {
3587
+ kids.push(leaf(P, name, t));
3588
+ }
3589
+ else {
3590
+ restoreLex(P.L, save);
3591
+ }
3592
+ }
3593
+ // ───────────────────── Test & Arithmetic Expressions ─────────────────────
3594
+ function parseTestExpr(P, closer) {
3595
+ return parseTestOr(P, closer);
3596
+ }
3597
+ function parseTestOr(P, closer) {
3598
+ let left = parseTestAnd(P, closer);
3599
+ if (!left)
3600
+ return null;
3601
+ while (true) {
3602
+ skipBlanks(P.L);
3603
+ const save = saveLex(P.L);
3604
+ if (peek(P.L) === '|' && peek(P.L, 1) === '|') {
3605
+ const s = P.L.b;
3606
+ advance(P.L);
3607
+ advance(P.L);
3608
+ const op = mk(P, '||', s, P.L.b, []);
3609
+ const right = parseTestAnd(P, closer);
3610
+ if (!right) {
3611
+ restoreLex(P.L, save);
3612
+ break;
3613
+ }
3614
+ left = mk(P, 'binary_expression', left.startIndex, right.endIndex, [
3615
+ left,
3616
+ op,
3617
+ right,
3618
+ ]);
3619
+ }
3620
+ else {
3621
+ break;
3622
+ }
3623
+ }
3624
+ return left;
3625
+ }
3626
+ function parseTestAnd(P, closer) {
3627
+ let left = parseTestUnary(P, closer);
3628
+ if (!left)
3629
+ return null;
3630
+ while (true) {
3631
+ skipBlanks(P.L);
3632
+ if (peek(P.L) === '&' && peek(P.L, 1) === '&') {
3633
+ const s = P.L.b;
3634
+ advance(P.L);
3635
+ advance(P.L);
3636
+ const op = mk(P, '&&', s, P.L.b, []);
3637
+ const right = parseTestUnary(P, closer);
3638
+ if (!right)
3639
+ break;
3640
+ left = mk(P, 'binary_expression', left.startIndex, right.endIndex, [
3641
+ left,
3642
+ op,
3643
+ right,
3644
+ ]);
3645
+ }
3646
+ else {
3647
+ break;
3648
+ }
3649
+ }
3650
+ return left;
3651
+ }
3652
+ function parseTestUnary(P, closer) {
3653
+ skipBlanks(P.L);
3654
+ const c = peek(P.L);
3655
+ if (c === '(') {
3656
+ const s = P.L.b;
3657
+ advance(P.L);
3658
+ const open = mk(P, '(', s, P.L.b, []);
3659
+ const inner = parseTestOr(P, closer);
3660
+ skipBlanks(P.L);
3661
+ let close;
3662
+ if (peek(P.L) === ')') {
3663
+ const cs = P.L.b;
3664
+ advance(P.L);
3665
+ close = mk(P, ')', cs, P.L.b, []);
3666
+ }
3667
+ else {
3668
+ close = mk(P, ')', P.L.b, P.L.b, []);
3669
+ }
3670
+ const kids = inner ? [open, inner, close] : [open, close];
3671
+ return mk(P, 'parenthesized_expression', open.startIndex, close.endIndex, kids);
3672
+ }
3673
+ return parseTestBinary(P, closer);
3674
+ }
3675
+ /**
3676
+ * Parse `!`-negated or test-operator (`-f`) or parenthesized primary — but NOT
3677
+ * a binary comparison. Used as LHS of binary_expression so `! x =~ y` binds
3678
+ * `!` to `x` only, not the whole `x =~ y`.
3679
+ */
3680
+ function parseTestNegatablePrimary(P, closer) {
3681
+ skipBlanks(P.L);
3682
+ const c = peek(P.L);
3683
+ if (c === '!') {
3684
+ const s = P.L.b;
3685
+ advance(P.L);
3686
+ const bang = mk(P, '!', s, P.L.b, []);
3687
+ const inner = parseTestNegatablePrimary(P, closer);
3688
+ if (!inner)
3689
+ return bang;
3690
+ return mk(P, 'unary_expression', bang.startIndex, inner.endIndex, [
3691
+ bang,
3692
+ inner,
3693
+ ]);
3694
+ }
3695
+ if (c === '-' && isIdentStart(peek(P.L, 1))) {
3696
+ const s = P.L.b;
3697
+ advance(P.L);
3698
+ while (isIdentChar(peek(P.L)))
3699
+ advance(P.L);
3700
+ const op = mk(P, 'test_operator', s, P.L.b, []);
3701
+ skipBlanks(P.L);
3702
+ const arg = parseTestPrimary(P, closer);
3703
+ if (!arg)
3704
+ return op;
3705
+ return mk(P, 'unary_expression', op.startIndex, arg.endIndex, [op, arg]);
3706
+ }
3707
+ return parseTestPrimary(P, closer);
3708
+ }
3709
+ function parseTestBinary(P, closer) {
3710
+ skipBlanks(P.L);
3711
+ // `!` in test context binds tighter than =~/==.
3712
+ // `[[ ! "x" =~ y ]]` → (binary_expression (unary_expression (string)) (regex))
3713
+ // `[[ ! -f x ]]` → (unary_expression ! (unary_expression (test_operator) (word)))
3714
+ const left = parseTestNegatablePrimary(P, closer);
3715
+ if (!left)
3716
+ return null;
3717
+ skipBlanks(P.L);
3718
+ // Binary comparison: == != =~ -eq -lt etc.
3719
+ const c = peek(P.L);
3720
+ const c1 = peek(P.L, 1);
3721
+ let op = null;
3722
+ const os = P.L.b;
3723
+ if (c === '=' && c1 === '=') {
3724
+ advance(P.L);
3725
+ advance(P.L);
3726
+ op = mk(P, '==', os, P.L.b, []);
3727
+ }
3728
+ else if (c === '!' && c1 === '=') {
3729
+ advance(P.L);
3730
+ advance(P.L);
3731
+ op = mk(P, '!=', os, P.L.b, []);
3732
+ }
3733
+ else if (c === '=' && c1 === '~') {
3734
+ advance(P.L);
3735
+ advance(P.L);
3736
+ op = mk(P, '=~', os, P.L.b, []);
3737
+ }
3738
+ else if (c === '=' && c1 !== '=') {
3739
+ advance(P.L);
3740
+ op = mk(P, '=', os, P.L.b, []);
3741
+ }
3742
+ else if (c === '<' && c1 !== '<') {
3743
+ advance(P.L);
3744
+ op = mk(P, '<', os, P.L.b, []);
3745
+ }
3746
+ else if (c === '>' && c1 !== '>') {
3747
+ advance(P.L);
3748
+ op = mk(P, '>', os, P.L.b, []);
3749
+ }
3750
+ else if (c === '-' && isIdentStart(c1)) {
3751
+ advance(P.L);
3752
+ while (isIdentChar(peek(P.L)))
3753
+ advance(P.L);
3754
+ op = mk(P, 'test_operator', os, P.L.b, []);
3755
+ }
3756
+ if (!op)
3757
+ return left;
3758
+ skipBlanks(P.L);
3759
+ // In [[ ]], RHS of ==/!=/=/=~ gets special pattern parsing: paren counting
3760
+ // so @(a|b|c) doesn't break on |, and segments become extglob_pattern/regex.
3761
+ if (closer === ']]') {
3762
+ const opText = op.type;
3763
+ if (opText === '=~') {
3764
+ skipBlanks(P.L);
3765
+ // If the ENTIRE RHS is a quoted string, emit string/raw_string not
3766
+ // regex: `[[ "$x" =~ "$y" ]]` → (binary_expression (string) (string)).
3767
+ // If there's content after the quote (`' boop '(.*)$`), the whole RHS
3768
+ // stays a single (regex). Peek past the quote to check.
3769
+ const rc = peek(P.L);
3770
+ let rhs = null;
3771
+ if (rc === '"' || rc === "'") {
3772
+ const save = saveLex(P.L);
3773
+ const quoted = rc === '"'
3774
+ ? parseDoubleQuoted(P)
3775
+ : leaf(P, 'raw_string', nextToken(P.L, 'arg'));
3776
+ // Check if RHS ends here: only whitespace then ]] or &&/|| or newline
3777
+ let j = P.L.i;
3778
+ while (j < P.L.len && (P.src[j] === ' ' || P.src[j] === '\t'))
3779
+ j++;
3780
+ const nc = P.src[j] ?? '';
3781
+ const nc1 = P.src[j + 1] ?? '';
3782
+ if ((nc === ']' && nc1 === ']') ||
3783
+ (nc === '&' && nc1 === '&') ||
3784
+ (nc === '|' && nc1 === '|') ||
3785
+ nc === '\n' ||
3786
+ nc === '') {
3787
+ rhs = quoted;
3788
+ }
3789
+ else {
3790
+ restoreLex(P.L, save);
3791
+ }
3792
+ }
3793
+ if (!rhs)
3794
+ rhs = parseTestRegexRhs(P);
3795
+ if (!rhs)
3796
+ return left;
3797
+ return mk(P, 'binary_expression', left.startIndex, rhs.endIndex, [
3798
+ left,
3799
+ op,
3800
+ rhs,
3801
+ ]);
3802
+ }
3803
+ // Single `=` emits (regex) per tree-sitter; `==` and `!=` emit extglob_pattern
3804
+ if (opText === '=') {
3805
+ const rhs = parseTestRegexRhs(P);
3806
+ if (!rhs)
3807
+ return left;
3808
+ return mk(P, 'binary_expression', left.startIndex, rhs.endIndex, [
3809
+ left,
3810
+ op,
3811
+ rhs,
3812
+ ]);
3813
+ }
3814
+ if (opText === '==' || opText === '!=') {
3815
+ const parts = parseTestExtglobRhs(P);
3816
+ if (parts.length === 0)
3817
+ return left;
3818
+ const last = parts[parts.length - 1];
3819
+ return mk(P, 'binary_expression', left.startIndex, last.endIndex, [
3820
+ left,
3821
+ op,
3822
+ ...parts,
3823
+ ]);
3824
+ }
3825
+ }
3826
+ const right = parseTestPrimary(P, closer);
3827
+ if (!right)
3828
+ return left;
3829
+ return mk(P, 'binary_expression', left.startIndex, right.endIndex, [
3830
+ left,
3831
+ op,
3832
+ right,
3833
+ ]);
3834
+ }
3835
+ // RHS of =~ in [[ ]] — scan as single (regex) node with paren/bracket counting
3836
+ // so | ( ) inside the regex don't break parsing. Stop at ]] or ws+&&/||.
3837
+ function parseTestRegexRhs(P) {
3838
+ skipBlanks(P.L);
3839
+ const start = P.L.b;
3840
+ let parenDepth = 0;
3841
+ let bracketDepth = 0;
3842
+ while (P.L.i < P.L.len) {
3843
+ const c = peek(P.L);
3844
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
3845
+ advance(P.L);
3846
+ advance(P.L);
3847
+ continue;
3848
+ }
3849
+ if (c === '\n')
3850
+ break;
3851
+ if (parenDepth === 0 && bracketDepth === 0) {
3852
+ if (c === ']' && peek(P.L, 1) === ']')
3853
+ break;
3854
+ if (c === ' ' || c === '\t') {
3855
+ // Peek past blanks for ]] or &&/||
3856
+ let j = P.L.i;
3857
+ while (j < P.L.len && (P.L.src[j] === ' ' || P.L.src[j] === '\t'))
3858
+ j++;
3859
+ const nc = P.L.src[j] ?? '';
3860
+ const nc1 = P.L.src[j + 1] ?? '';
3861
+ if ((nc === ']' && nc1 === ']') ||
3862
+ (nc === '&' && nc1 === '&') ||
3863
+ (nc === '|' && nc1 === '|')) {
3864
+ break;
3865
+ }
3866
+ advance(P.L);
3867
+ continue;
3868
+ }
3869
+ }
3870
+ if (c === '(')
3871
+ parenDepth++;
3872
+ else if (c === ')' && parenDepth > 0)
3873
+ parenDepth--;
3874
+ else if (c === '[')
3875
+ bracketDepth++;
3876
+ else if (c === ']' && bracketDepth > 0)
3877
+ bracketDepth--;
3878
+ advance(P.L);
3879
+ }
3880
+ if (P.L.b === start)
3881
+ return null;
3882
+ return mk(P, 'regex', start, P.L.b, []);
3883
+ }
3884
+ // RHS of ==/!=/= in [[ ]] — returns array of parts. Bare text → extglob_pattern
3885
+ // (with paren counting for @(a|b)); $(...)/${}/quoted → proper node types.
3886
+ // Multiple parts become flat children of binary_expression per tree-sitter.
3887
+ function parseTestExtglobRhs(P) {
3888
+ skipBlanks(P.L);
3889
+ const parts = [];
3890
+ let segStart = P.L.b;
3891
+ let segStartI = P.L.i;
3892
+ let parenDepth = 0;
3893
+ const flushSeg = () => {
3894
+ if (P.L.i > segStartI) {
3895
+ const text = P.src.slice(segStartI, P.L.i);
3896
+ // Pure number stays number; everything else is extglob_pattern
3897
+ const type = /^\d+$/.test(text) ? 'number' : 'extglob_pattern';
3898
+ parts.push(mk(P, type, segStart, P.L.b, []));
3899
+ }
3900
+ };
3901
+ while (P.L.i < P.L.len) {
3902
+ const c = peek(P.L);
3903
+ if (c === '\\' && P.L.i + 1 < P.L.len) {
3904
+ advance(P.L);
3905
+ advance(P.L);
3906
+ continue;
3907
+ }
3908
+ if (c === '\n')
3909
+ break;
3910
+ if (parenDepth === 0) {
3911
+ if (c === ']' && peek(P.L, 1) === ']')
3912
+ break;
3913
+ if (c === ' ' || c === '\t') {
3914
+ let j = P.L.i;
3915
+ while (j < P.L.len && (P.L.src[j] === ' ' || P.L.src[j] === '\t'))
3916
+ j++;
3917
+ const nc = P.L.src[j] ?? '';
3918
+ const nc1 = P.L.src[j + 1] ?? '';
3919
+ if ((nc === ']' && nc1 === ']') ||
3920
+ (nc === '&' && nc1 === '&') ||
3921
+ (nc === '|' && nc1 === '|')) {
3922
+ break;
3923
+ }
3924
+ advance(P.L);
3925
+ continue;
3926
+ }
3927
+ }
3928
+ // $ " ' must be parsed even inside @( ) extglob parens — parseDollarLike
3929
+ // consumes matching ) so parenDepth stays consistent.
3930
+ if (c === '$') {
3931
+ const c1 = peek(P.L, 1);
3932
+ if (c1 === '(' ||
3933
+ c1 === '{' ||
3934
+ isIdentStart(c1) ||
3935
+ SPECIAL_VARS.has(c1)) {
3936
+ flushSeg();
3937
+ const exp = parseDollarLike(P);
3938
+ if (exp)
3939
+ parts.push(exp);
3940
+ segStart = P.L.b;
3941
+ segStartI = P.L.i;
3942
+ continue;
3943
+ }
3944
+ }
3945
+ if (c === '"') {
3946
+ flushSeg();
3947
+ parts.push(parseDoubleQuoted(P));
3948
+ segStart = P.L.b;
3949
+ segStartI = P.L.i;
3950
+ continue;
3951
+ }
3952
+ if (c === "'") {
3953
+ flushSeg();
3954
+ const tok = nextToken(P.L, 'arg');
3955
+ parts.push(leaf(P, 'raw_string', tok));
3956
+ segStart = P.L.b;
3957
+ segStartI = P.L.i;
3958
+ continue;
3959
+ }
3960
+ if (c === '(')
3961
+ parenDepth++;
3962
+ else if (c === ')' && parenDepth > 0)
3963
+ parenDepth--;
3964
+ advance(P.L);
3965
+ }
3966
+ flushSeg();
3967
+ return parts;
3968
+ }
3969
+ function parseTestPrimary(P, closer) {
3970
+ skipBlanks(P.L);
3971
+ // Stop at closer
3972
+ if (closer === ']' && peek(P.L) === ']')
3973
+ return null;
3974
+ if (closer === ']]' && peek(P.L) === ']' && peek(P.L, 1) === ']')
3975
+ return null;
3976
+ return parseWord(P, 'arg');
3977
+ }
3978
+ /** Operator precedence table (higher = tighter binding). */
3979
+ const ARITH_PREC = {
3980
+ '=': 2,
3981
+ '+=': 2,
3982
+ '-=': 2,
3983
+ '*=': 2,
3984
+ '/=': 2,
3985
+ '%=': 2,
3986
+ '<<=': 2,
3987
+ '>>=': 2,
3988
+ '&=': 2,
3989
+ '^=': 2,
3990
+ '|=': 2,
3991
+ '||': 4,
3992
+ '&&': 5,
3993
+ '|': 6,
3994
+ '^': 7,
3995
+ '&': 8,
3996
+ '==': 9,
3997
+ '!=': 9,
3998
+ '<': 10,
3999
+ '>': 10,
4000
+ '<=': 10,
4001
+ '>=': 10,
4002
+ '<<': 11,
4003
+ '>>': 11,
4004
+ '+': 12,
4005
+ '-': 12,
4006
+ '*': 13,
4007
+ '/': 13,
4008
+ '%': 13,
4009
+ '**': 14,
4010
+ };
4011
+ /** Right-associative operators (assignment and exponent). */
4012
+ const ARITH_RIGHT_ASSOC = new Set([
4013
+ '=',
4014
+ '+=',
4015
+ '-=',
4016
+ '*=',
4017
+ '/=',
4018
+ '%=',
4019
+ '<<=',
4020
+ '>>=',
4021
+ '&=',
4022
+ '^=',
4023
+ '|=',
4024
+ '**',
4025
+ ]);
4026
+ function parseArithExpr(P, stop, mode = 'var') {
4027
+ return parseArithTernary(P, stop, mode);
4028
+ }
4029
+ /** Top-level: comma-separated list. arithmetic_expansion emits multiple children. */
4030
+ function parseArithCommaList(P, stop, mode = 'var') {
4031
+ const out = [];
4032
+ while (true) {
4033
+ const e = parseArithTernary(P, stop, mode);
4034
+ if (e)
4035
+ out.push(e);
4036
+ skipBlanks(P.L);
4037
+ if (peek(P.L) === ',' && !isArithStop(P, stop)) {
4038
+ advance(P.L);
4039
+ continue;
4040
+ }
4041
+ break;
4042
+ }
4043
+ return out;
4044
+ }
4045
+ function parseArithTernary(P, stop, mode) {
4046
+ const cond = parseArithBinary(P, stop, 0, mode);
4047
+ if (!cond)
4048
+ return null;
4049
+ skipBlanks(P.L);
4050
+ if (peek(P.L) === '?') {
4051
+ const qs = P.L.b;
4052
+ advance(P.L);
4053
+ const q = mk(P, '?', qs, P.L.b, []);
4054
+ const t = parseArithBinary(P, ':', 0, mode);
4055
+ skipBlanks(P.L);
4056
+ let colon;
4057
+ if (peek(P.L) === ':') {
4058
+ const cs = P.L.b;
4059
+ advance(P.L);
4060
+ colon = mk(P, ':', cs, P.L.b, []);
4061
+ }
4062
+ else {
4063
+ colon = mk(P, ':', P.L.b, P.L.b, []);
4064
+ }
4065
+ const f = parseArithTernary(P, stop, mode);
4066
+ const last = f ?? colon;
4067
+ const kids = [cond, q];
4068
+ if (t)
4069
+ kids.push(t);
4070
+ kids.push(colon);
4071
+ if (f)
4072
+ kids.push(f);
4073
+ return mk(P, 'ternary_expression', cond.startIndex, last.endIndex, kids);
4074
+ }
4075
+ return cond;
4076
+ }
4077
+ /** Scan next arithmetic binary operator; returns [text, length] or null. */
4078
+ function scanArithOp(P) {
4079
+ const c = peek(P.L);
4080
+ const c1 = peek(P.L, 1);
4081
+ const c2 = peek(P.L, 2);
4082
+ // 3-char: <<= >>=
4083
+ if (c === '<' && c1 === '<' && c2 === '=')
4084
+ return ['<<=', 3];
4085
+ if (c === '>' && c1 === '>' && c2 === '=')
4086
+ return ['>>=', 3];
4087
+ // 2-char
4088
+ if (c === '*' && c1 === '*')
4089
+ return ['**', 2];
4090
+ if (c === '<' && c1 === '<')
4091
+ return ['<<', 2];
4092
+ if (c === '>' && c1 === '>')
4093
+ return ['>>', 2];
4094
+ if (c === '=' && c1 === '=')
4095
+ return ['==', 2];
4096
+ if (c === '!' && c1 === '=')
4097
+ return ['!=', 2];
4098
+ if (c === '<' && c1 === '=')
4099
+ return ['<=', 2];
4100
+ if (c === '>' && c1 === '=')
4101
+ return ['>=', 2];
4102
+ if (c === '&' && c1 === '&')
4103
+ return ['&&', 2];
4104
+ if (c === '|' && c1 === '|')
4105
+ return ['||', 2];
4106
+ if (c === '+' && c1 === '=')
4107
+ return ['+=', 2];
4108
+ if (c === '-' && c1 === '=')
4109
+ return ['-=', 2];
4110
+ if (c === '*' && c1 === '=')
4111
+ return ['*=', 2];
4112
+ if (c === '/' && c1 === '=')
4113
+ return ['/=', 2];
4114
+ if (c === '%' && c1 === '=')
4115
+ return ['%=', 2];
4116
+ if (c === '&' && c1 === '=')
4117
+ return ['&=', 2];
4118
+ if (c === '^' && c1 === '=')
4119
+ return ['^=', 2];
4120
+ if (c === '|' && c1 === '=')
4121
+ return ['|=', 2];
4122
+ // 1-char — but NOT ++ -- (those are pre/postfix)
4123
+ if (c === '+' && c1 !== '+')
4124
+ return ['+', 1];
4125
+ if (c === '-' && c1 !== '-')
4126
+ return ['-', 1];
4127
+ if (c === '*')
4128
+ return ['*', 1];
4129
+ if (c === '/')
4130
+ return ['/', 1];
4131
+ if (c === '%')
4132
+ return ['%', 1];
4133
+ if (c === '<')
4134
+ return ['<', 1];
4135
+ if (c === '>')
4136
+ return ['>', 1];
4137
+ if (c === '&')
4138
+ return ['&', 1];
4139
+ if (c === '|')
4140
+ return ['|', 1];
4141
+ if (c === '^')
4142
+ return ['^', 1];
4143
+ if (c === '=')
4144
+ return ['=', 1];
4145
+ return null;
4146
+ }
4147
+ /** Precedence-climbing binary expression parser. */
4148
+ function parseArithBinary(P, stop, minPrec, mode) {
4149
+ let left = parseArithUnary(P, stop, mode);
4150
+ if (!left)
4151
+ return null;
4152
+ while (true) {
4153
+ skipBlanks(P.L);
4154
+ if (isArithStop(P, stop))
4155
+ break;
4156
+ if (peek(P.L) === ',')
4157
+ break;
4158
+ const opInfo = scanArithOp(P);
4159
+ if (!opInfo)
4160
+ break;
4161
+ const [opText, opLen] = opInfo;
4162
+ const prec = ARITH_PREC[opText];
4163
+ if (prec === undefined || prec < minPrec)
4164
+ break;
4165
+ const os = P.L.b;
4166
+ for (let k = 0; k < opLen; k++)
4167
+ advance(P.L);
4168
+ const op = mk(P, opText, os, P.L.b, []);
4169
+ const nextMin = ARITH_RIGHT_ASSOC.has(opText) ? prec : prec + 1;
4170
+ const right = parseArithBinary(P, stop, nextMin, mode);
4171
+ if (!right)
4172
+ break;
4173
+ left = mk(P, 'binary_expression', left.startIndex, right.endIndex, [
4174
+ left,
4175
+ op,
4176
+ right,
4177
+ ]);
4178
+ }
4179
+ return left;
4180
+ }
4181
+ function parseArithUnary(P, stop, mode) {
4182
+ skipBlanks(P.L);
4183
+ if (isArithStop(P, stop))
4184
+ return null;
4185
+ const c = peek(P.L);
4186
+ const c1 = peek(P.L, 1);
4187
+ // Prefix ++ --
4188
+ if ((c === '+' && c1 === '+') || (c === '-' && c1 === '-')) {
4189
+ const s = P.L.b;
4190
+ advance(P.L);
4191
+ advance(P.L);
4192
+ const op = mk(P, c + c1, s, P.L.b, []);
4193
+ const inner = parseArithUnary(P, stop, mode);
4194
+ if (!inner)
4195
+ return op;
4196
+ return mk(P, 'unary_expression', op.startIndex, inner.endIndex, [op, inner]);
4197
+ }
4198
+ if (c === '-' || c === '+' || c === '!' || c === '~') {
4199
+ // In 'word'/'assign' mode (c-style for head), `-N` is a single number
4200
+ // literal per tree-sitter, not unary_expression. 'var' mode uses unary.
4201
+ if (mode !== 'var' && c === '-' && isDigit(c1)) {
4202
+ const s = P.L.b;
4203
+ advance(P.L);
4204
+ while (isDigit(peek(P.L)))
4205
+ advance(P.L);
4206
+ return mk(P, 'number', s, P.L.b, []);
4207
+ }
4208
+ const s = P.L.b;
4209
+ advance(P.L);
4210
+ const op = mk(P, c, s, P.L.b, []);
4211
+ const inner = parseArithUnary(P, stop, mode);
4212
+ if (!inner)
4213
+ return op;
4214
+ return mk(P, 'unary_expression', op.startIndex, inner.endIndex, [op, inner]);
4215
+ }
4216
+ return parseArithPostfix(P, stop, mode);
4217
+ }
4218
+ function parseArithPostfix(P, stop, mode) {
4219
+ const prim = parseArithPrimary(P, stop, mode);
4220
+ if (!prim)
4221
+ return null;
4222
+ const c = peek(P.L);
4223
+ const c1 = peek(P.L, 1);
4224
+ if ((c === '+' && c1 === '+') || (c === '-' && c1 === '-')) {
4225
+ const s = P.L.b;
4226
+ advance(P.L);
4227
+ advance(P.L);
4228
+ const op = mk(P, c + c1, s, P.L.b, []);
4229
+ return mk(P, 'postfix_expression', prim.startIndex, op.endIndex, [prim, op]);
4230
+ }
4231
+ return prim;
4232
+ }
4233
+ function parseArithPrimary(P, stop, mode) {
4234
+ skipBlanks(P.L);
4235
+ if (isArithStop(P, stop))
4236
+ return null;
4237
+ const c = peek(P.L);
4238
+ if (c === '(') {
4239
+ const s = P.L.b;
4240
+ advance(P.L);
4241
+ const open = mk(P, '(', s, P.L.b, []);
4242
+ // Parenthesized expression may contain comma-separated exprs
4243
+ const inners = parseArithCommaList(P, ')', mode);
4244
+ skipBlanks(P.L);
4245
+ let close;
4246
+ if (peek(P.L) === ')') {
4247
+ const cs = P.L.b;
4248
+ advance(P.L);
4249
+ close = mk(P, ')', cs, P.L.b, []);
4250
+ }
4251
+ else {
4252
+ close = mk(P, ')', P.L.b, P.L.b, []);
4253
+ }
4254
+ return mk(P, 'parenthesized_expression', open.startIndex, close.endIndex, [
4255
+ open,
4256
+ ...inners,
4257
+ close,
4258
+ ]);
4259
+ }
4260
+ if (c === '"') {
4261
+ return parseDoubleQuoted(P);
4262
+ }
4263
+ if (c === '$') {
4264
+ return parseDollarLike(P);
4265
+ }
4266
+ if (isDigit(c)) {
4267
+ const s = P.L.b;
4268
+ while (isDigit(peek(P.L)))
4269
+ advance(P.L);
4270
+ // Hex: 0x1f
4271
+ if (P.L.b - s === 1 &&
4272
+ c === '0' &&
4273
+ (peek(P.L) === 'x' || peek(P.L) === 'X')) {
4274
+ advance(P.L);
4275
+ while (isHexDigit(peek(P.L)))
4276
+ advance(P.L);
4277
+ }
4278
+ // Base notation: BASE#DIGITS e.g. 2#1010, 16#ff
4279
+ else if (peek(P.L) === '#') {
4280
+ advance(P.L);
4281
+ while (isBaseDigit(peek(P.L)))
4282
+ advance(P.L);
4283
+ }
4284
+ return mk(P, 'number', s, P.L.b, []);
4285
+ }
4286
+ if (isIdentStart(c)) {
4287
+ const s = P.L.b;
4288
+ while (isIdentChar(peek(P.L)))
4289
+ advance(P.L);
4290
+ const nc = peek(P.L);
4291
+ // Assignment in 'assign' mode (c-style for init): emit variable_assignment
4292
+ // so chained `a = b = c = 1` nests correctly. Other modes treat `=` as a
4293
+ // binary_expression operator via the precedence table.
4294
+ if (mode === 'assign') {
4295
+ skipBlanks(P.L);
4296
+ const ac = peek(P.L);
4297
+ const ac1 = peek(P.L, 1);
4298
+ if (ac === '=' && ac1 !== '=') {
4299
+ const vn = mk(P, 'variable_name', s, P.L.b, []);
4300
+ const es = P.L.b;
4301
+ advance(P.L);
4302
+ const eq = mk(P, '=', es, P.L.b, []);
4303
+ // RHS may itself be another assignment (chained)
4304
+ const val = parseArithTernary(P, stop, mode);
4305
+ const end = val ? val.endIndex : eq.endIndex;
4306
+ const kids = val ? [vn, eq, val] : [vn, eq];
4307
+ return mk(P, 'variable_assignment', s, end, kids);
4308
+ }
4309
+ }
4310
+ // Subscript
4311
+ if (nc === '[') {
4312
+ const vn = mk(P, 'variable_name', s, P.L.b, []);
4313
+ const brS = P.L.b;
4314
+ advance(P.L);
4315
+ const brOpen = mk(P, '[', brS, P.L.b, []);
4316
+ const idx = parseArithTernary(P, ']', 'var') ?? parseDollarLike(P);
4317
+ skipBlanks(P.L);
4318
+ let brClose;
4319
+ if (peek(P.L) === ']') {
4320
+ const cs = P.L.b;
4321
+ advance(P.L);
4322
+ brClose = mk(P, ']', cs, P.L.b, []);
4323
+ }
4324
+ else {
4325
+ brClose = mk(P, ']', P.L.b, P.L.b, []);
4326
+ }
4327
+ const kids = idx ? [vn, brOpen, idx, brClose] : [vn, brOpen, brClose];
4328
+ return mk(P, 'subscript', s, brClose.endIndex, kids);
4329
+ }
4330
+ // Bare identifier: variable_name in 'var' mode, word in 'word'/'assign' mode.
4331
+ // 'assign' mode falls through to word when no `=` follows (c-style for
4332
+ // cond/update clauses: `c<=5` → binary_expression(word, number)).
4333
+ const identType = mode === 'var' ? 'variable_name' : 'word';
4334
+ return mk(P, identType, s, P.L.b, []);
4335
+ }
4336
+ return null;
4337
+ }
4338
+ function isArithStop(P, stop) {
4339
+ const c = peek(P.L);
4340
+ if (stop === '))')
4341
+ return c === ')' && peek(P.L, 1) === ')';
4342
+ if (stop === ')')
4343
+ return c === ')';
4344
+ if (stop === ';')
4345
+ return c === ';';
4346
+ if (stop === ':')
4347
+ return c === ':';
4348
+ if (stop === ']')
4349
+ return c === ']';
4350
+ if (stop === '}')
4351
+ return c === '}';
4352
+ if (stop === ':}')
4353
+ return c === ':' || c === '}';
4354
+ return c === '' || c === '\n';
4355
+ }