yzcode-cli 1.0.2 → 1.0.4

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 (1683) hide show
  1. package/QueryEngine.ts +46 -46
  2. package/README.md +39 -0
  3. package/Task.ts +3 -3
  4. package/Tool.ts +25 -25
  5. package/assistant/gate.ts +2 -0
  6. package/assistant/index.ts +2 -0
  7. package/assistant/sessionHistory.ts +87 -0
  8. package/bin/yzcode.js +16 -9
  9. package/bootstrap/state.ts +1769 -0
  10. package/bridge/bridgeApi.ts +539 -0
  11. package/bridge/bridgeConfig.ts +48 -0
  12. package/bridge/bridgeDebug.ts +135 -0
  13. package/bridge/bridgeEnabled.ts +202 -0
  14. package/bridge/bridgeMain.ts +2999 -0
  15. package/bridge/bridgeMessaging.ts +461 -0
  16. package/bridge/bridgePermissionCallbacks.ts +43 -0
  17. package/bridge/bridgePointer.ts +210 -0
  18. package/bridge/bridgeStatusUtil.ts +163 -0
  19. package/bridge/bridgeUI.ts +530 -0
  20. package/bridge/capacityWake.ts +56 -0
  21. package/bridge/codeSessionApi.ts +168 -0
  22. package/bridge/createSession.ts +384 -0
  23. package/bridge/debugUtils.ts +141 -0
  24. package/bridge/envLessBridgeConfig.ts +165 -0
  25. package/bridge/flushGate.ts +71 -0
  26. package/bridge/inboundAttachments.ts +175 -0
  27. package/bridge/inboundMessages.ts +80 -0
  28. package/bridge/initReplBridge.ts +569 -0
  29. package/bridge/jwtUtils.ts +256 -0
  30. package/bridge/pollConfig.ts +110 -0
  31. package/bridge/pollConfigDefaults.ts +82 -0
  32. package/bridge/remoteBridgeCore.ts +1008 -0
  33. package/bridge/replBridge.ts +2406 -0
  34. package/bridge/replBridgeHandle.ts +36 -0
  35. package/bridge/replBridgeTransport.ts +370 -0
  36. package/bridge/sessionIdCompat.ts +57 -0
  37. package/bridge/sessionRunner.ts +550 -0
  38. package/bridge/trustedDevice.ts +210 -0
  39. package/bridge/types.ts +262 -0
  40. package/bridge/workSecret.ts +127 -0
  41. package/buddy/CompanionSprite.tsx +371 -0
  42. package/buddy/companion.ts +133 -0
  43. package/buddy/prompt.ts +36 -0
  44. package/buddy/sprites.ts +514 -0
  45. package/buddy/types.ts +148 -0
  46. package/buddy/useBuddyNotification.tsx +98 -0
  47. package/cli/handlers/agents.ts +3 -3
  48. package/cli/handlers/auth.ts +18 -18
  49. package/cli/handlers/autoMode.ts +6 -6
  50. package/cli/handlers/mcp.tsx +16 -16
  51. package/cli/handlers/plugins.ts +20 -20
  52. package/cli/handlers/util.tsx +10 -10
  53. package/cli/ndjsonSafeStringify.ts +1 -1
  54. package/cli/print.ts +137 -137
  55. package/cli/remoteIO.ts +21 -21
  56. package/cli/structuredIO.ts +24 -24
  57. package/cli/transports/HybridTransport.ts +6 -6
  58. package/cli/transports/SSETransport.ts +9 -9
  59. package/cli/transports/SerialBatchEventUploader.ts +1 -1
  60. package/cli/transports/WebSocketTransport.ts +11 -11
  61. package/cli/transports/WorkerStateUploader.ts +1 -1
  62. package/cli/transports/ccrClient.ts +14 -14
  63. package/cli/transports/transportUtils.ts +5 -5
  64. package/cli/update.ts +13 -13
  65. package/commands/add-dir/add-dir.tsx +10 -10
  66. package/commands/add-dir/index.ts +1 -1
  67. package/commands/add-dir/validation.ts +4 -4
  68. package/commands/advisor.ts +6 -6
  69. package/commands/agents/agents.tsx +4 -4
  70. package/commands/agents/index.ts +1 -1
  71. package/commands/branch/branch.ts +9 -9
  72. package/commands/branch/index.ts +1 -1
  73. package/commands/bridge/bridge.tsx +15 -15
  74. package/commands/bridge/index.ts +2 -2
  75. package/commands/bridge-kick.ts +3 -3
  76. package/commands/brief.ts +8 -8
  77. package/commands/btw/btw.tsx +21 -21
  78. package/commands/btw/index.ts +1 -1
  79. package/commands/chrome/chrome.tsx +11 -11
  80. package/commands/chrome/index.ts +2 -2
  81. package/commands/clear/caches.ts +20 -20
  82. package/commands/clear/clear.ts +2 -2
  83. package/commands/clear/conversation.ts +19 -19
  84. package/commands/clear/index.ts +3 -3
  85. package/commands/color/color.ts +6 -6
  86. package/commands/color/index.ts +1 -1
  87. package/commands/commit-push-pr.ts +5 -5
  88. package/commands/commit.ts +4 -4
  89. package/commands/compact/compact.ts +20 -20
  90. package/commands/compact/index.ts +2 -2
  91. package/commands/config/config.tsx +2 -2
  92. package/commands/config/index.ts +1 -1
  93. package/commands/context/context-noninteractive.ts +10 -10
  94. package/commands/context/context.tsx +8 -8
  95. package/commands/context/index.ts +2 -2
  96. package/commands/copy/copy.tsx +16 -16
  97. package/commands/copy/index.ts +1 -1
  98. package/commands/cost/cost.ts +4 -4
  99. package/commands/cost/index.ts +2 -2
  100. package/commands/createMovedToPluginCommand.ts +3 -3
  101. package/commands/desktop/desktop.tsx +2 -2
  102. package/commands/desktop/index.ts +1 -1
  103. package/commands/diff/diff.tsx +1 -1
  104. package/commands/diff/index.ts +1 -1
  105. package/commands/doctor/doctor.tsx +2 -2
  106. package/commands/doctor/index.ts +2 -2
  107. package/commands/effort/effort.tsx +6 -6
  108. package/commands/effort/index.ts +2 -2
  109. package/commands/exit/exit.tsx +5 -5
  110. package/commands/exit/index.ts +1 -1
  111. package/commands/export/export.tsx +7 -7
  112. package/commands/export/index.ts +1 -1
  113. package/commands/extra-usage/extra-usage-core.ts +8 -8
  114. package/commands/extra-usage/extra-usage-noninteractive.ts +1 -1
  115. package/commands/extra-usage/extra-usage.tsx +4 -4
  116. package/commands/extra-usage/index.ts +4 -4
  117. package/commands/fast/fast.tsx +12 -12
  118. package/commands/fast/index.ts +3 -3
  119. package/commands/feedback/feedback.tsx +4 -4
  120. package/commands/feedback/index.ts +4 -4
  121. package/commands/files/files.ts +4 -4
  122. package/commands/files/index.ts +1 -1
  123. package/commands/heapdump/heapdump.ts +1 -1
  124. package/commands/heapdump/index.ts +1 -1
  125. package/commands/help/help.tsx +2 -2
  126. package/commands/help/index.ts +1 -1
  127. package/commands/hooks/hooks.tsx +4 -4
  128. package/commands/hooks/index.ts +1 -1
  129. package/commands/ide/ide.tsx +13 -13
  130. package/commands/ide/index.ts +1 -1
  131. package/commands/init-verifiers.ts +2 -2
  132. package/commands/init.ts +3 -3
  133. package/commands/insights.ts +15 -15
  134. package/commands/install-github-app/ApiKeyStep.tsx +4 -4
  135. package/commands/install-github-app/CheckExistingSecretStep.tsx +4 -4
  136. package/commands/install-github-app/CheckGitHubStep.tsx +1 -1
  137. package/commands/install-github-app/ChooseRepoStep.tsx +4 -4
  138. package/commands/install-github-app/CreatingStep.tsx +2 -2
  139. package/commands/install-github-app/ErrorStep.tsx +2 -2
  140. package/commands/install-github-app/ExistingWorkflowStep.tsx +2 -2
  141. package/commands/install-github-app/InstallAppStep.tsx +3 -3
  142. package/commands/install-github-app/OAuthFlowStep.tsx +11 -11
  143. package/commands/install-github-app/SuccessStep.tsx +1 -1
  144. package/commands/install-github-app/WarningsStep.tsx +4 -4
  145. package/commands/install-github-app/index.ts +2 -2
  146. package/commands/install-github-app/install-github-app.tsx +25 -25
  147. package/commands/install-github-app/setupGitHubActions.ts +7 -7
  148. package/commands/install-slack-app/index.ts +1 -1
  149. package/commands/install-slack-app/install-slack-app.ts +4 -4
  150. package/commands/install.tsx +9 -9
  151. package/commands/keybindings/index.ts +2 -2
  152. package/commands/keybindings/keybindings.ts +4 -4
  153. package/commands/login/index.ts +3 -3
  154. package/commands/login/login.tsx +15 -15
  155. package/commands/logout/index.ts +2 -2
  156. package/commands/logout/logout.tsx +13 -13
  157. package/commands/mcp/addCommand.ts +8 -8
  158. package/commands/mcp/index.ts +1 -1
  159. package/commands/mcp/mcp.tsx +6 -6
  160. package/commands/mcp/xaaIdpCommand.ts +4 -4
  161. package/commands/memory/index.ts +1 -1
  162. package/commands/memory/memory.tsx +11 -11
  163. package/commands/mobile/index.ts +1 -1
  164. package/commands/mobile/mobile.tsx +5 -5
  165. package/commands/model/index.ts +3 -3
  166. package/commands/model/model.tsx +14 -14
  167. package/commands/output-style/index.ts +1 -1
  168. package/commands/output-style/output-style.tsx +1 -1
  169. package/commands/passes/index.ts +2 -2
  170. package/commands/passes/passes.tsx +5 -5
  171. package/commands/permissions/index.ts +1 -1
  172. package/commands/permissions/permissions.tsx +3 -3
  173. package/commands/plan/index.ts +1 -1
  174. package/commands/plan/plan.tsx +11 -11
  175. package/commands/plugin/AddMarketplace.tsx +13 -13
  176. package/commands/plugin/BrowseMarketplace.tsx +24 -24
  177. package/commands/plugin/DiscoverPlugins.tsx +27 -27
  178. package/commands/plugin/ManageMarketplaces.tsx +19 -19
  179. package/commands/plugin/ManagePlugins.tsx +46 -46
  180. package/commands/plugin/PluginErrors.tsx +1 -1
  181. package/commands/plugin/PluginOptionsDialog.tsx +6 -6
  182. package/commands/plugin/PluginOptionsFlow.tsx +7 -7
  183. package/commands/plugin/PluginSettings.tsx +25 -25
  184. package/commands/plugin/PluginTrustWarning.tsx +2 -2
  185. package/commands/plugin/UnifiedInstalledCell.tsx +3 -3
  186. package/commands/plugin/ValidatePlugin.tsx +5 -5
  187. package/commands/plugin/index.tsx +1 -1
  188. package/commands/plugin/plugin.tsx +2 -2
  189. package/commands/plugin/pluginDetailsHelpers.tsx +4 -4
  190. package/commands/pr_comments/index.ts +1 -1
  191. package/commands/privacy-settings/index.ts +2 -2
  192. package/commands/privacy-settings/privacy-settings.tsx +4 -4
  193. package/commands/rate-limit-options/index.ts +2 -2
  194. package/commands/rate-limit-options/rate-limit-options.tsx +14 -14
  195. package/commands/release-notes/index.ts +1 -1
  196. package/commands/release-notes/release-notes.ts +2 -2
  197. package/commands/reload-plugins/index.ts +1 -1
  198. package/commands/reload-plugins/reload-plugins.ts +7 -7
  199. package/commands/remote-env/index.ts +3 -3
  200. package/commands/remote-env/remote-env.tsx +2 -2
  201. package/commands/remote-setup/api.ts +4 -4
  202. package/commands/remote-setup/index.ts +3 -3
  203. package/commands/remote-setup/remote-setup.tsx +9 -9
  204. package/commands/rename/generateSessionName.ts +8 -8
  205. package/commands/rename/index.ts +1 -1
  206. package/commands/rename/rename.ts +8 -8
  207. package/commands/resume/index.ts +1 -1
  208. package/commands/resume/resume.tsx +17 -17
  209. package/commands/review/UltrareviewOverageDialog.tsx +3 -3
  210. package/commands/review/reviewRemote.ts +12 -12
  211. package/commands/review/ultrareviewCommand.tsx +4 -4
  212. package/commands/review/ultrareviewEnabled.ts +1 -1
  213. package/commands/review.ts +3 -3
  214. package/commands/rewind/index.ts +1 -1
  215. package/commands/rewind/rewind.ts +2 -2
  216. package/commands/sandbox-toggle/index.ts +2 -2
  217. package/commands/sandbox-toggle/sandbox-toggle.tsx +7 -7
  218. package/commands/security-review.ts +4 -4
  219. package/commands/session/index.ts +2 -2
  220. package/commands/session/session.tsx +6 -6
  221. package/commands/skills/index.ts +1 -1
  222. package/commands/skills/skills.tsx +3 -3
  223. package/commands/stats/index.ts +1 -1
  224. package/commands/stats/stats.tsx +2 -2
  225. package/commands/status/index.ts +1 -1
  226. package/commands/status/status.tsx +3 -3
  227. package/commands/statusline.tsx +2 -2
  228. package/commands/stickers/index.ts +1 -1
  229. package/commands/stickers/stickers.ts +2 -2
  230. package/commands/tag/index.ts +1 -1
  231. package/commands/tag/tag.tsx +10 -10
  232. package/commands/tasks/index.ts +1 -1
  233. package/commands/tasks/tasks.tsx +3 -3
  234. package/commands/terminalSetup/index.ts +2 -2
  235. package/commands/terminalSetup/terminalSetup.tsx +16 -16
  236. package/commands/theme/index.ts +1 -1
  237. package/commands/theme/theme.tsx +5 -5
  238. package/commands/thinkback/index.ts +2 -2
  239. package/commands/thinkback/thinkback.tsx +20 -20
  240. package/commands/thinkback-play/index.ts +2 -2
  241. package/commands/thinkback-play/thinkback-play.ts +4 -4
  242. package/commands/ultraplan.tsx +17 -17
  243. package/commands/upgrade/index.ts +3 -3
  244. package/commands/upgrade/upgrade.tsx +7 -7
  245. package/commands/usage/index.ts +1 -1
  246. package/commands/usage/usage.tsx +2 -2
  247. package/commands/version.ts +1 -1
  248. package/commands/vim/index.ts +1 -1
  249. package/commands/vim/vim.ts +3 -3
  250. package/commands/voice/index.ts +2 -2
  251. package/commands/voice/voice.ts +9 -9
  252. package/commands.ts +105 -105
  253. package/components/AgentProgressLine.tsx +3 -3
  254. package/components/App.tsx +5 -5
  255. package/components/ApproveApiKey.tsx +4 -4
  256. package/components/AutoModeOptInDialog.tsx +5 -5
  257. package/components/AutoUpdater.tsx +11 -11
  258. package/components/AutoUpdaterWrapper.tsx +7 -7
  259. package/components/AwsAuthStatusBox.tsx +2 -2
  260. package/components/BaseTextInput.tsx +7 -7
  261. package/components/BashModeProgress.tsx +5 -5
  262. package/components/BridgeDialog.tsx +10 -10
  263. package/components/BypassPermissionsModeDialog.tsx +6 -6
  264. package/components/ChannelDowngradeDialog.tsx +3 -3
  265. package/components/ClaudeCodeHint/PluginHintMenu.tsx +3 -3
  266. package/components/ClaudeInChromeOnboarding.tsx +5 -5
  267. package/components/ClaudeMdExternalIncludesDialog.tsx +6 -6
  268. package/components/ClickableImageRef.tsx +5 -5
  269. package/components/CompactSummary.tsx +7 -7
  270. package/components/ConfigurableShortcutHint.tsx +3 -3
  271. package/components/ConsoleOAuthFlow.tsx +17 -17
  272. package/components/ContextSuggestions.tsx +4 -4
  273. package/components/ContextVisualization.tsx +9 -9
  274. package/components/CoordinatorAgentStatus.tsx +10 -10
  275. package/components/CostThresholdDialog.tsx +3 -3
  276. package/components/CtrlOToExpand.tsx +5 -5
  277. package/components/CustomSelect/SelectMulti.tsx +7 -7
  278. package/components/CustomSelect/index.ts +3 -3
  279. package/components/CustomSelect/option-map.ts +1 -1
  280. package/components/CustomSelect/select-input-option.tsx +11 -11
  281. package/components/CustomSelect/select-option.tsx +1 -1
  282. package/components/CustomSelect/select.tsx +10 -10
  283. package/components/CustomSelect/use-multi-select-state.ts +6 -6
  284. package/components/CustomSelect/use-select-input.ts +7 -7
  285. package/components/CustomSelect/use-select-navigation.ts +2 -2
  286. package/components/CustomSelect/use-select-state.ts +2 -2
  287. package/components/DesktopHandoff.tsx +8 -8
  288. package/components/DesktopUpsell/DesktopUpsellStartup.tsx +7 -7
  289. package/components/DevBar.tsx +2 -2
  290. package/components/DevChannelsDialog.tsx +5 -5
  291. package/components/DiagnosticsDisplay.tsx +6 -6
  292. package/components/EffortCallout.tsx +11 -11
  293. package/components/EffortIndicator.ts +2 -2
  294. package/components/ExitFlow.tsx +2 -2
  295. package/components/ExportDialog.tsx +13 -13
  296. package/components/FallbackToolUseErrorMessage.tsx +7 -7
  297. package/components/FallbackToolUseRejectedMessage.tsx +2 -2
  298. package/components/FastIcon.tsx +5 -5
  299. package/components/Feedback.tsx +27 -27
  300. package/components/FeedbackSurvey/FeedbackSurvey.tsx +7 -7
  301. package/components/FeedbackSurvey/FeedbackSurveyView.tsx +3 -3
  302. package/components/FeedbackSurvey/TranscriptSharePrompt.tsx +3 -3
  303. package/components/FeedbackSurvey/submitTranscriptShare.ts +9 -9
  304. package/components/FeedbackSurvey/useDebouncedDigitInput.ts +1 -1
  305. package/components/FeedbackSurvey/useFeedbackSurvey.tsx +15 -15
  306. package/components/FeedbackSurvey/useMemorySurvey.tsx +16 -16
  307. package/components/FeedbackSurvey/usePostCompactSurvey.tsx +10 -10
  308. package/components/FeedbackSurvey/useSurveyState.tsx +2 -2
  309. package/components/FileEditToolDiff.tsx +9 -9
  310. package/components/FileEditToolUpdatedMessage.tsx +5 -5
  311. package/components/FileEditToolUseRejectedMessage.tsx +6 -6
  312. package/components/FilePathLink.tsx +1 -1
  313. package/components/FullscreenLayout.tsx +13 -13
  314. package/components/GlobalSearchDialog.tsx +13 -13
  315. package/components/HelpV2/Commands.tsx +5 -5
  316. package/components/HelpV2/General.tsx +2 -2
  317. package/components/HelpV2/HelpV2.tsx +11 -11
  318. package/components/HighlightedCode/Fallback.tsx +5 -5
  319. package/components/HighlightedCode.tsx +7 -7
  320. package/components/HistorySearchDialog.tsx +10 -10
  321. package/components/IdeAutoConnectDialog.tsx +5 -5
  322. package/components/IdeOnboardingDialog.tsx +7 -7
  323. package/components/IdeStatusIndicator.tsx +4 -4
  324. package/components/IdleReturnDialog.tsx +4 -4
  325. package/components/InterruptedByUser.tsx +1 -1
  326. package/components/InvalidConfigDialog.tsx +9 -9
  327. package/components/InvalidSettingsDialog.tsx +5 -5
  328. package/components/KeybindingWarnings.tsx +2 -2
  329. package/components/LanguagePicker.tsx +3 -3
  330. package/components/LogSelector.tsx +28 -28
  331. package/components/LogoV2/AnimatedAsterisk.tsx +4 -4
  332. package/components/LogoV2/AnimatedClawd.tsx +3 -3
  333. package/components/LogoV2/ChannelsNotice.tsx +8 -8
  334. package/components/LogoV2/Clawd.tsx +2 -2
  335. package/components/LogoV2/CondensedLogo.tsx +15 -15
  336. package/components/LogoV2/EmergencyTip.tsx +3 -3
  337. package/components/LogoV2/Feed.tsx +3 -3
  338. package/components/LogoV2/FeedColumn.tsx +4 -4
  339. package/components/LogoV2/GuestPassesUpsell.tsx +4 -4
  340. package/components/LogoV2/LogoV2.tsx +31 -31
  341. package/components/LogoV2/Opus1mMergeNotice.tsx +5 -5
  342. package/components/LogoV2/OverageCreditUpsell.tsx +6 -6
  343. package/components/LogoV2/VoiceModeNotice.tsx +6 -6
  344. package/components/LogoV2/WelcomeV2.tsx +2 -2
  345. package/components/LogoV2/feedConfigs.tsx +7 -7
  346. package/components/LspRecommendation/LspRecommendationMenu.tsx +3 -3
  347. package/components/MCPServerApprovalDialog.tsx +5 -5
  348. package/components/MCPServerDesktopImportDialog.tsx +11 -11
  349. package/components/MCPServerDialogCopy.tsx +1 -1
  350. package/components/MCPServerMultiselectDialog.tsx +9 -9
  351. package/components/ManagedSettingsSecurityDialog/ManagedSettingsSecurityDialog.tsx +7 -7
  352. package/components/ManagedSettingsSecurityDialog/utils.ts +3 -3
  353. package/components/Markdown.tsx +7 -7
  354. package/components/MarkdownTable.tsx +6 -6
  355. package/components/MemoryUsageIndicator.tsx +3 -3
  356. package/components/Message.tsx +29 -29
  357. package/components/MessageModel.tsx +3 -3
  358. package/components/MessageResponse.tsx +2 -2
  359. package/components/MessageRow.tsx +12 -12
  360. package/components/MessageSelector.tsx +20 -20
  361. package/components/MessageTimestamp.tsx +3 -3
  362. package/components/Messages.tsx +39 -39
  363. package/components/ModelPicker.tsx +16 -16
  364. package/components/NativeAutoUpdater.tsx +11 -11
  365. package/components/NotebookEditToolUseRejectedMessage.tsx +4 -4
  366. package/components/OffscreenFreeze.tsx +3 -3
  367. package/components/Onboarding.tsx +19 -19
  368. package/components/OutputStylePicker.tsx +7 -7
  369. package/components/PackageManagerAutoUpdater.tsx +7 -7
  370. package/components/Passes/Passes.tsx +12 -12
  371. package/components/PrBadge.tsx +2 -2
  372. package/components/PressEnterToContinue.tsx +1 -1
  373. package/components/PromptInput/HistorySearchInput.tsx +3 -3
  374. package/components/PromptInput/IssueFlagBanner.tsx +2 -2
  375. package/components/PromptInput/Notifications.tsx +30 -30
  376. package/components/PromptInput/PromptInput.tsx +117 -117
  377. package/components/PromptInput/PromptInputFooter.tsx +22 -22
  378. package/components/PromptInput/PromptInputFooterLeftSide.tsx +33 -33
  379. package/components/PromptInput/PromptInputFooterSuggestions.tsx +5 -5
  380. package/components/PromptInput/PromptInputHelpMenu.tsx +7 -7
  381. package/components/PromptInput/PromptInputModeIndicator.tsx +6 -6
  382. package/components/PromptInput/PromptInputQueuedCommands.tsx +10 -10
  383. package/components/PromptInput/PromptInputStashNotice.tsx +1 -1
  384. package/components/PromptInput/SandboxPromptFooterHint.tsx +3 -3
  385. package/components/PromptInput/ShimmeredInput.tsx +3 -3
  386. package/components/PromptInput/VoiceIndicator.tsx +3 -3
  387. package/components/PromptInput/inputModes.ts +2 -2
  388. package/components/PromptInput/inputPaste.ts +2 -2
  389. package/components/PromptInput/useMaybeTruncateInput.ts +2 -2
  390. package/components/PromptInput/usePromptInputPlaceholder.ts +5 -5
  391. package/components/PromptInput/useSwarmBanner.ts +10 -10
  392. package/components/PromptInput/utils.ts +4 -4
  393. package/components/QuickOpenDialog.tsx +12 -12
  394. package/components/RemoteCallout.tsx +7 -7
  395. package/components/RemoteEnvironmentDialog.tsx +14 -14
  396. package/components/ResumeTask.tsx +14 -14
  397. package/components/SandboxViolationExpandedView.tsx +4 -4
  398. package/components/ScrollKeybindingHandler.tsx +10 -10
  399. package/components/SearchBox.tsx +1 -1
  400. package/components/SessionBackgroundHint.tsx +10 -10
  401. package/components/SessionPreview.tsx +11 -11
  402. package/components/Settings/Config.tsx +43 -43
  403. package/components/Settings/Settings.tsx +10 -10
  404. package/components/Settings/Status.tsx +10 -10
  405. package/components/Settings/Usage.tsx +14 -14
  406. package/components/ShowInIDEPrompt.tsx +6 -6
  407. package/components/SkillImprovementSurvey.tsx +6 -6
  408. package/components/Spinner/FlashingChar.tsx +3 -3
  409. package/components/Spinner/GlimmerMessage.tsx +6 -6
  410. package/components/Spinner/ShimmerChar.tsx +2 -2
  411. package/components/Spinner/SpinnerAnimationRow.tsx +12 -12
  412. package/components/Spinner/SpinnerGlyph.tsx +3 -3
  413. package/components/Spinner/TeammateSpinnerLine.tsx +11 -11
  414. package/components/Spinner/TeammateSpinnerTree.tsx +6 -6
  415. package/components/Spinner/index.ts +8 -8
  416. package/components/Spinner/useShimmerAnimation.ts +3 -3
  417. package/components/Spinner/utils.ts +2 -2
  418. package/components/Spinner.tsx +32 -32
  419. package/components/Stats.tsx +18 -18
  420. package/components/StatusLine.tsx +26 -26
  421. package/components/StatusNotices.tsx +5 -5
  422. package/components/StructuredDiff/Fallback.tsx +3 -3
  423. package/components/StructuredDiff/colorDiff.ts +1 -1
  424. package/components/StructuredDiff.tsx +6 -6
  425. package/components/StructuredDiffList.tsx +3 -3
  426. package/components/TagTabs.tsx +3 -3
  427. package/components/TaskListV2.tsx +13 -13
  428. package/components/TeammateViewHeader.tsx +6 -6
  429. package/components/TeleportError.tsx +7 -7
  430. package/components/TeleportProgress.tsx +4 -4
  431. package/components/TeleportRepoMismatchDialog.tsx +6 -6
  432. package/components/TeleportResumeWrapper.tsx +8 -8
  433. package/components/TeleportStash.tsx +7 -7
  434. package/components/TextInput.tsx +10 -10
  435. package/components/ThemePicker.tsx +16 -16
  436. package/components/ThinkingToggle.tsx +8 -8
  437. package/components/TokenWarning.tsx +7 -7
  438. package/components/ToolUseLoader.tsx +3 -3
  439. package/components/TrustDialog/TrustDialog.tsx +15 -15
  440. package/components/TrustDialog/utils.ts +6 -6
  441. package/components/ValidationErrorsList.tsx +3 -3
  442. package/components/VimTextInput.tsx +6 -6
  443. package/components/VirtualMessageList.tsx +12 -12
  444. package/components/WorkflowMultiselectDialog.tsx +8 -8
  445. package/components/WorktreeExitDialog.tsx +11 -11
  446. package/components/agents/AgentDetail.tsx +11 -11
  447. package/components/agents/AgentEditor.tsx +13 -13
  448. package/components/agents/AgentNavigationFooter.tsx +2 -2
  449. package/components/agents/AgentsList.tsx +10 -10
  450. package/components/agents/AgentsMenu.tsx +20 -20
  451. package/components/agents/ColorPicker.tsx +4 -4
  452. package/components/agents/ModelSelector.tsx +3 -3
  453. package/components/agents/ToolSelector.tsx +27 -27
  454. package/components/agents/agentFileUtils.ts +9 -9
  455. package/components/agents/generateAgent.ts +11 -11
  456. package/components/agents/new-agent-creation/CreateAgentWizard.tsx +17 -17
  457. package/components/agents/new-agent-creation/wizard-steps/ColorStep.tsx +10 -10
  458. package/components/agents/new-agent-creation/wizard-steps/ConfirmStep.tsx +17 -17
  459. package/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.tsx +10 -10
  460. package/components/agents/new-agent-creation/wizard-steps/DescriptionStep.tsx +10 -10
  461. package/components/agents/new-agent-creation/wizard-steps/GenerateStep.tsx +13 -13
  462. package/components/agents/new-agent-creation/wizard-steps/LocationStep.tsx +9 -9
  463. package/components/agents/new-agent-creation/wizard-steps/MemoryStep.tsx +11 -11
  464. package/components/agents/new-agent-creation/wizard-steps/MethodStep.tsx +8 -8
  465. package/components/agents/new-agent-creation/wizard-steps/ModelStep.tsx +7 -7
  466. package/components/agents/new-agent-creation/wizard-steps/PromptStep.tsx +10 -10
  467. package/components/agents/new-agent-creation/wizard-steps/ToolsStep.tsx +8 -8
  468. package/components/agents/new-agent-creation/wizard-steps/TypeStep.tsx +11 -11
  469. package/components/agents/types.ts +2 -2
  470. package/components/agents/utils.ts +2 -2
  471. package/components/agents/validateAgent.ts +4 -4
  472. package/components/design-system/Byline.tsx +1 -1
  473. package/components/design-system/Dialog.tsx +8 -8
  474. package/components/design-system/Divider.tsx +4 -4
  475. package/components/design-system/FuzzyPicker.tsx +10 -10
  476. package/components/design-system/KeyboardShortcutHint.tsx +1 -1
  477. package/components/design-system/ListItem.tsx +2 -2
  478. package/components/design-system/LoadingState.tsx +2 -2
  479. package/components/design-system/Pane.tsx +4 -4
  480. package/components/design-system/ProgressBar.tsx +2 -2
  481. package/components/design-system/Ratchet.tsx +3 -3
  482. package/components/design-system/StatusIcon.tsx +1 -1
  483. package/components/design-system/Tabs.tsx +8 -8
  484. package/components/design-system/ThemeProvider.tsx +4 -4
  485. package/components/design-system/ThemedBox.tsx +8 -8
  486. package/components/design-system/ThemedText.tsx +4 -4
  487. package/components/design-system/color.ts +3 -3
  488. package/components/diff/DiffDetailView.tsx +6 -6
  489. package/components/diff/DiffDialog.tsx +13 -13
  490. package/components/diff/DiffFileList.tsx +5 -5
  491. package/components/grove/Grove.tsx +7 -7
  492. package/components/hooks/HooksConfigMenu.tsx +15 -15
  493. package/components/hooks/PromptDialog.tsx +5 -5
  494. package/components/hooks/SelectEventMode.tsx +6 -6
  495. package/components/hooks/SelectHookMode.tsx +6 -6
  496. package/components/hooks/SelectMatcherMode.tsx +6 -6
  497. package/components/hooks/ViewHookMode.tsx +3 -3
  498. package/components/mcp/CapabilitiesSection.tsx +2 -2
  499. package/components/mcp/ElicitationDialog.tsx +15 -15
  500. package/components/mcp/MCPAgentServerMenu.tsx +12 -12
  501. package/components/mcp/MCPListPanel.tsx +13 -13
  502. package/components/mcp/MCPReconnect.tsx +5 -5
  503. package/components/mcp/MCPRemoteServerMenu.tsx +27 -27
  504. package/components/mcp/MCPSettings.tsx +13 -13
  505. package/components/mcp/MCPStdioServerMenu.tsx +17 -17
  506. package/components/mcp/MCPToolDetailView.tsx +6 -6
  507. package/components/mcp/MCPToolListView.tsx +12 -12
  508. package/components/mcp/McpParsingWarnings.tsx +5 -5
  509. package/components/mcp/index.ts +9 -9
  510. package/components/mcp/utils/reconnectHelpers.tsx +3 -3
  511. package/components/memory/MemoryFileSelector.tsx +19 -19
  512. package/components/memory/MemoryUpdateNotification.tsx +2 -2
  513. package/components/messageActions.tsx +5 -5
  514. package/components/messages/AdvisorMessage.tsx +7 -7
  515. package/components/messages/AssistantRedactedThinkingMessage.tsx +1 -1
  516. package/components/messages/AssistantTextMessage.tsx +15 -15
  517. package/components/messages/AssistantThinkingMessage.tsx +3 -3
  518. package/components/messages/AssistantToolUseMessage.tsx +17 -17
  519. package/components/messages/AttachmentMessage.tsx +24 -24
  520. package/components/messages/CollapsedReadSearchContent.tsx +16 -16
  521. package/components/messages/CompactBoundaryMessage.tsx +2 -2
  522. package/components/messages/GroupedToolUseContent.tsx +3 -3
  523. package/components/messages/HighlightedThinkingText.tsx +5 -5
  524. package/components/messages/HookProgressMessage.tsx +4 -4
  525. package/components/messages/PlanApprovalMessage.tsx +6 -6
  526. package/components/messages/RateLimitMessage.tsx +7 -7
  527. package/components/messages/ShutdownMessage.tsx +2 -2
  528. package/components/messages/SystemAPIErrorMessage.tsx +5 -5
  529. package/components/messages/SystemTextMessage.tsx +18 -18
  530. package/components/messages/TaskAssignmentMessage.tsx +2 -2
  531. package/components/messages/UserAgentNotificationMessage.tsx +3 -3
  532. package/components/messages/UserBashInputMessage.tsx +2 -2
  533. package/components/messages/UserBashOutputMessage.tsx +2 -2
  534. package/components/messages/UserChannelMessage.tsx +4 -4
  535. package/components/messages/UserCommandMessage.tsx +3 -3
  536. package/components/messages/UserImageMessage.tsx +5 -5
  537. package/components/messages/UserLocalCommandOutputMessage.tsx +6 -6
  538. package/components/messages/UserMemoryInputMessage.tsx +3 -3
  539. package/components/messages/UserPlanMessage.tsx +2 -2
  540. package/components/messages/UserPromptMessage.tsx +9 -9
  541. package/components/messages/UserResourceUpdateMessage.tsx +2 -2
  542. package/components/messages/UserTeammateMessage.tsx +9 -9
  543. package/components/messages/UserTextMessage.tsx +20 -20
  544. package/components/messages/UserToolResultMessage/RejectedPlanMessage.tsx +3 -3
  545. package/components/messages/UserToolResultMessage/RejectedToolUseMessage.tsx +2 -2
  546. package/components/messages/UserToolResultMessage/UserToolCanceledMessage.tsx +2 -2
  547. package/components/messages/UserToolResultMessage/UserToolErrorMessage.tsx +10 -10
  548. package/components/messages/UserToolResultMessage/UserToolRejectMessage.tsx +6 -6
  549. package/components/messages/UserToolResultMessage/UserToolResultMessage.tsx +8 -8
  550. package/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx +9 -9
  551. package/components/messages/UserToolResultMessage/utils.tsx +2 -2
  552. package/components/messages/nullRenderingAttachments.ts +2 -2
  553. package/components/messages/teamMemCollapsed.tsx +2 -2
  554. package/components/messages/teamMemSaved.ts +1 -1
  555. package/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.tsx +22 -22
  556. package/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.tsx +7 -7
  557. package/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.tsx +15 -15
  558. package/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.tsx +5 -5
  559. package/components/permissions/AskUserQuestionPermissionRequest/QuestionView.tsx +16 -16
  560. package/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.tsx +8 -8
  561. package/components/permissions/BashPermissionRequest/BashPermissionRequest.tsx +29 -29
  562. package/components/permissions/BashPermissionRequest/bashToolUseOptions.tsx +8 -8
  563. package/components/permissions/ComputerUseApproval/ComputerUseApproval.tsx +6 -6
  564. package/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.tsx +8 -8
  565. package/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.tsx +40 -40
  566. package/components/permissions/FallbackPermissionRequest.tsx +12 -12
  567. package/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +7 -7
  568. package/components/permissions/FilePermissionDialog/FilePermissionDialog.tsx +17 -17
  569. package/components/permissions/FilePermissionDialog/ideDiffConfig.ts +1 -1
  570. package/components/permissions/FilePermissionDialog/permissionOptions.tsx +7 -7
  571. package/components/permissions/FilePermissionDialog/useFilePermissionDialog.ts +9 -9
  572. package/components/permissions/FilePermissionDialog/usePermissionHandler.ts +10 -10
  573. package/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +9 -9
  574. package/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +6 -6
  575. package/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +5 -5
  576. package/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.tsx +6 -6
  577. package/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.tsx +10 -10
  578. package/components/permissions/PermissionDecisionDebugInfo.tsx +11 -11
  579. package/components/permissions/PermissionDialog.tsx +4 -4
  580. package/components/permissions/PermissionExplanation.tsx +7 -7
  581. package/components/permissions/PermissionPrompt.tsx +6 -6
  582. package/components/permissions/PermissionRequest.tsx +32 -32
  583. package/components/permissions/PermissionRequestTitle.tsx +3 -3
  584. package/components/permissions/PermissionRuleExplanation.tsx +6 -6
  585. package/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.tsx +20 -20
  586. package/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.tsx +5 -5
  587. package/components/permissions/SandboxPermissionRequest.tsx +5 -5
  588. package/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.tsx +10 -10
  589. package/components/permissions/SkillPermissionRequest/SkillPermissionRequest.tsx +14 -14
  590. package/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.tsx +9 -9
  591. package/components/permissions/WorkerBadge.tsx +3 -3
  592. package/components/permissions/WorkerPendingPermission.tsx +4 -4
  593. package/components/permissions/hooks.ts +13 -13
  594. package/components/permissions/rules/AddPermissionRules.tsx +14 -14
  595. package/components/permissions/rules/AddWorkspaceDirectory.tsx +13 -13
  596. package/components/permissions/rules/PermissionRuleDescription.tsx +3 -3
  597. package/components/permissions/rules/PermissionRuleInput.tsx +9 -9
  598. package/components/permissions/rules/PermissionRuleList.tsx +27 -27
  599. package/components/permissions/rules/RecentDenialsTab.tsx +5 -5
  600. package/components/permissions/rules/RemoveWorkspaceDirectory.tsx +5 -5
  601. package/components/permissions/rules/WorkspaceTab.tsx +6 -6
  602. package/components/permissions/shellPermissionHelpers.tsx +4 -4
  603. package/components/permissions/useShellPermissionFeedback.ts +5 -5
  604. package/components/permissions/utils.ts +3 -3
  605. package/components/sandbox/SandboxConfigTab.tsx +2 -2
  606. package/components/sandbox/SandboxDependenciesTab.tsx +3 -3
  607. package/components/sandbox/SandboxDoctorSection.tsx +2 -2
  608. package/components/sandbox/SandboxOverridesTab.tsx +5 -5
  609. package/components/sandbox/SandboxSettings.tsx +12 -12
  610. package/components/shell/OutputLine.tsx +8 -8
  611. package/components/shell/ShellProgressMessage.tsx +5 -5
  612. package/components/shell/ShellTimeDisplay.tsx +2 -2
  613. package/components/skills/SkillsMenu.tsx +9 -9
  614. package/components/tasks/AsyncAgentDetailDialog.tsx +16 -16
  615. package/components/tasks/BackgroundTask.tsx +10 -10
  616. package/components/tasks/BackgroundTaskStatus.tsx +13 -13
  617. package/components/tasks/BackgroundTasksDialog.tsx +37 -37
  618. package/components/tasks/DreamDetailDialog.tsx +10 -10
  619. package/components/tasks/InProcessTeammateDetailDialog.tsx +15 -15
  620. package/components/tasks/RemoteSessionDetailDialog.tsx +26 -26
  621. package/components/tasks/RemoteSessionProgress.tsx +7 -7
  622. package/components/tasks/ShellDetailDialog.tsx +13 -13
  623. package/components/tasks/ShellProgress.tsx +4 -4
  624. package/components/tasks/renderToolActivity.tsx +5 -5
  625. package/components/tasks/taskStatusUtils.tsx +6 -6
  626. package/components/teams/TeamStatus.tsx +2 -2
  627. package/components/teams/TeamsDialog.tsx +24 -24
  628. package/components/ui/OrderedList.tsx +2 -2
  629. package/components/ui/OrderedListItem.tsx +1 -1
  630. package/components/ui/TreeSelect.tsx +3 -3
  631. package/components/wizard/WizardDialogLayout.tsx +4 -4
  632. package/components/wizard/WizardNavigationFooter.tsx +5 -5
  633. package/components/wizard/WizardProvider.tsx +2 -2
  634. package/components/wizard/index.ts +5 -5
  635. package/components/wizard/useWizard.ts +2 -2
  636. package/constants/figures.ts +1 -1
  637. package/constants/github-app.ts +1 -1
  638. package/constants/keys.ts +1 -1
  639. package/constants/oauth.ts +1 -1
  640. package/constants/outputStyles.ts +7 -7
  641. package/constants/prompts.ts +42 -42
  642. package/constants/spinnerVerbs.ts +1 -1
  643. package/constants/system.ts +5 -5
  644. package/constants/systemPromptSections.ts +1 -1
  645. package/constants/tools.ts +28 -28
  646. package/context/QueuedMessageContext.tsx +1 -1
  647. package/context/fpsMetrics.tsx +1 -1
  648. package/context/mailbox.tsx +1 -1
  649. package/context/modalContext.tsx +1 -1
  650. package/context/notifications.tsx +2 -2
  651. package/context/overlayContext.tsx +2 -2
  652. package/context/promptOverlayContext.tsx +1 -1
  653. package/context/stats.tsx +1 -1
  654. package/context/voice.tsx +1 -1
  655. package/context.ts +9 -9
  656. package/coordinator/coordinatorMode.ts +369 -0
  657. package/cost-tracker.ts +11 -11
  658. package/costHook.ts +3 -3
  659. package/dialogLaunchers.tsx +10 -10
  660. package/entrypoints/agentSdkTypes.ts +8 -8
  661. package/entrypoints/init.ts +26 -26
  662. package/entrypoints/mcp.ts +18 -18
  663. package/entrypoints/sandboxTypes.ts +1 -1
  664. package/entrypoints/sdk/controlSchemas.ts +2 -2
  665. package/entrypoints/sdk/coreSchemas.ts +1 -1
  666. package/entrypoints/sdk/coreTypes.ts +3 -3
  667. package/entrypoints/sdk/toolTypes.ts +1 -1
  668. package/history.ts +11 -11
  669. package/hooks/fileSuggestions.ts +18 -18
  670. package/hooks/notifs/useAutoModeUnavailableNotification.ts +6 -6
  671. package/hooks/notifs/useCanSwitchToExistingSubscription.tsx +6 -6
  672. package/hooks/notifs/useDeprecationWarningNotification.tsx +3 -3
  673. package/hooks/notifs/useFastModeNotification.tsx +5 -5
  674. package/hooks/notifs/useIDEStatusIndicator.tsx +8 -8
  675. package/hooks/notifs/useInstallMessages.tsx +2 -2
  676. package/hooks/notifs/useLspInitializationNotification.tsx +7 -7
  677. package/hooks/notifs/useMcpConnectivityStatus.tsx +5 -5
  678. package/hooks/notifs/useModelMigrationNotifications.tsx +3 -3
  679. package/hooks/notifs/useNpmDeprecationNotification.tsx +4 -4
  680. package/hooks/notifs/usePluginAutoupdateNotification.tsx +5 -5
  681. package/hooks/notifs/usePluginInstallationStatus.tsx +6 -6
  682. package/hooks/notifs/useRateLimitWarningNotification.tsx +7 -7
  683. package/hooks/notifs/useSettingsErrors.tsx +5 -5
  684. package/hooks/notifs/useStartupNotification.ts +3 -3
  685. package/hooks/notifs/useTeammateShutdownNotification.ts +4 -4
  686. package/hooks/toolPermission/PermissionContext.ts +16 -16
  687. package/hooks/toolPermission/handlers/coordinatorHandler.ts +5 -5
  688. package/hooks/toolPermission/handlers/interactiveHandler.ts +16 -16
  689. package/hooks/toolPermission/handlers/swarmWorkerHandler.ts +10 -10
  690. package/hooks/toolPermission/permissionLogging.ts +8 -8
  691. package/hooks/unifiedSuggestions.ts +9 -9
  692. package/hooks/useAfterFirstRender.ts +1 -1
  693. package/hooks/useApiKeyVerification.ts +3 -3
  694. package/hooks/useArrowKeyHistory.tsx +8 -8
  695. package/hooks/useAssistantHistory.ts +6 -6
  696. package/hooks/useAwaySummary.ts +5 -5
  697. package/hooks/useBackgroundTaskNavigation.ts +7 -7
  698. package/hooks/useBlink.ts +1 -1
  699. package/hooks/useCanUseTool.tsx +21 -21
  700. package/hooks/useCancelRequest.ts +17 -17
  701. package/hooks/useChromeExtensionNotification.tsx +5 -5
  702. package/hooks/useClaudeCodeHintRecommendation.tsx +7 -7
  703. package/hooks/useClipboardImageHint.ts +3 -3
  704. package/hooks/useCommandKeybindings.tsx +4 -4
  705. package/hooks/useCommandQueue.ts +2 -2
  706. package/hooks/useCopyOnSelect.ts +4 -4
  707. package/hooks/useDeferredHookMessages.ts +1 -1
  708. package/hooks/useDiffData.ts +1 -1
  709. package/hooks/useDiffInIDE.ts +15 -15
  710. package/hooks/useDirectConnect.ts +12 -12
  711. package/hooks/useDynamicConfig.ts +1 -1
  712. package/hooks/useElapsedTime.ts +1 -1
  713. package/hooks/useExitOnCtrlCD.ts +3 -3
  714. package/hooks/useExitOnCtrlCDWithKeybindings.ts +2 -2
  715. package/hooks/useFileHistorySnapshotInit.ts +1 -1
  716. package/hooks/useGlobalKeybindings.tsx +8 -8
  717. package/hooks/useHistorySearch.ts +7 -7
  718. package/hooks/useIDEIntegration.tsx +5 -5
  719. package/hooks/useIdeAtMentioned.ts +4 -4
  720. package/hooks/useIdeConnectionStatus.ts +1 -1
  721. package/hooks/useIdeLogging.ts +4 -4
  722. package/hooks/useIdeSelection.ts +4 -4
  723. package/hooks/useInboxPoller.ts +27 -27
  724. package/hooks/useInputBuffer.ts +1 -1
  725. package/hooks/useIssueFlagBanner.ts +3 -3
  726. package/hooks/useLogMessages.ts +4 -4
  727. package/hooks/useLspPluginRecommendation.tsx +10 -10
  728. package/hooks/useMailboxBridge.ts +1 -1
  729. package/hooks/useMainLoopModel.ts +3 -3
  730. package/hooks/useManagePlugins.ts +19 -19
  731. package/hooks/useMergedClients.ts +1 -1
  732. package/hooks/useMergedCommands.ts +1 -1
  733. package/hooks/useMergedTools.ts +4 -4
  734. package/hooks/useNotifyAfterTimeout.ts +3 -3
  735. package/hooks/useOfficialMarketplaceNotification.tsx +5 -5
  736. package/hooks/usePasteHandler.ts +5 -5
  737. package/hooks/usePluginRecommendationBase.tsx +5 -5
  738. package/hooks/usePrStatus.ts +2 -2
  739. package/hooks/usePromptSuggestion.ts +4 -4
  740. package/hooks/usePromptsFromClaudeInChrome.tsx +7 -7
  741. package/hooks/useQueueProcessor.ts +4 -4
  742. package/hooks/useRemoteSession.ts +18 -18
  743. package/hooks/useReplBridge.tsx +24 -24
  744. package/hooks/useSSHSession.ts +12 -12
  745. package/hooks/useScheduledTasks.ts +12 -12
  746. package/hooks/useSearchInput.ts +4 -4
  747. package/hooks/useSessionBackgrounding.ts +2 -2
  748. package/hooks/useSettings.ts +1 -1
  749. package/hooks/useSettingsChange.ts +4 -4
  750. package/hooks/useSkillImprovementSurvey.ts +7 -7
  751. package/hooks/useSkillsChange.ts +5 -5
  752. package/hooks/useSwarmInitialization.ts +8 -8
  753. package/hooks/useSwarmPermissionPoller.ts +5 -5
  754. package/hooks/useTaskListWatcher.ts +2 -2
  755. package/hooks/useTasksV2.ts +5 -5
  756. package/hooks/useTeammateViewAutoExit.ts +3 -3
  757. package/hooks/useTeleportResume.tsx +6 -6
  758. package/hooks/useTerminalSize.ts +1 -1
  759. package/hooks/useTextInput.ts +12 -12
  760. package/hooks/useTurnDiffs.ts +3 -3
  761. package/hooks/useTypeahead.tsx +27 -27
  762. package/hooks/useVimInput.ts +8 -8
  763. package/hooks/useVirtualScroll.ts +2 -2
  764. package/hooks/useVoice.ts +11 -11
  765. package/hooks/useVoiceEnabled.ts +2 -2
  766. package/hooks/useVoiceIntegration.tsx +10 -10
  767. package/ink/Ansi.tsx +4 -4
  768. package/ink/clearTerminal.ts +1 -1
  769. package/ink/colorize.ts +1 -1
  770. package/ink/components/AlternateScreen.tsx +5 -5
  771. package/ink/components/App.tsx +24 -24
  772. package/ink/components/Box.tsx +6 -6
  773. package/ink/components/Button.tsx +6 -6
  774. package/ink/components/ClockContext.tsx +2 -2
  775. package/ink/components/CursorDeclarationContext.ts +1 -1
  776. package/ink/components/ErrorOverview.tsx +2 -2
  777. package/ink/components/Link.tsx +2 -2
  778. package/ink/components/NoSelect.tsx +1 -1
  779. package/ink/components/ScrollBox.tsx +6 -6
  780. package/ink/components/Spacer.tsx +1 -1
  781. package/ink/components/StdinContext.ts +2 -2
  782. package/ink/components/TerminalFocusContext.tsx +1 -1
  783. package/ink/components/Text.tsx +1 -1
  784. package/ink/dom.ts +10 -10
  785. package/ink/events/click-event.ts +1 -1
  786. package/ink/events/dispatcher.ts +3 -3
  787. package/ink/events/emitter.ts +1 -1
  788. package/ink/events/event-handlers.ts +5 -5
  789. package/ink/events/focus-event.ts +1 -1
  790. package/ink/events/input-event.ts +2 -2
  791. package/ink/events/keyboard-event.ts +2 -2
  792. package/ink/events/terminal-event.ts +1 -1
  793. package/ink/events/terminal-focus-event.ts +1 -1
  794. package/ink/focus.ts +2 -2
  795. package/ink/frame.ts +4 -4
  796. package/ink/get-max-width.ts +1 -1
  797. package/ink/hit-test.ts +4 -4
  798. package/ink/hooks/use-animation-frame.ts +3 -3
  799. package/ink/hooks/use-app.ts +1 -1
  800. package/ink/hooks/use-declared-cursor.ts +2 -2
  801. package/ink/hooks/use-input.ts +2 -2
  802. package/ink/hooks/use-interval.ts +1 -1
  803. package/ink/hooks/use-search-highlight.ts +4 -4
  804. package/ink/hooks/use-selection.ts +3 -3
  805. package/ink/hooks/use-stdin.ts +1 -1
  806. package/ink/hooks/use-tab-status.ts +3 -3
  807. package/ink/hooks/use-terminal-focus.ts +1 -1
  808. package/ink/hooks/use-terminal-title.ts +2 -2
  809. package/ink/hooks/use-terminal-viewport.ts +2 -2
  810. package/ink/ink.tsx +32 -32
  811. package/ink/instances.ts +1 -1
  812. package/ink/layout/engine.ts +2 -2
  813. package/ink/layout/yoga.ts +2 -2
  814. package/ink/line-width-cache.ts +1 -1
  815. package/ink/log-update.ts +6 -6
  816. package/ink/measure-element.ts +1 -1
  817. package/ink/measure-text.ts +1 -1
  818. package/ink/node-cache.ts +2 -2
  819. package/ink/optimizer.ts +1 -1
  820. package/ink/output.ts +8 -8
  821. package/ink/parse-keypress.ts +2 -2
  822. package/ink/reconciler.ts +8 -8
  823. package/ink/render-border.ts +5 -5
  824. package/ink/render-node-to-output.ts +14 -14
  825. package/ink/render-to-screen.ts +8 -8
  826. package/ink/renderer.ts +7 -7
  827. package/ink/root.ts +4 -4
  828. package/ink/screen.ts +3 -3
  829. package/ink/searchHighlight.ts +1 -1
  830. package/ink/selection.ts +3 -3
  831. package/ink/squash-text-nodes.ts +2 -2
  832. package/ink/stringWidth.ts +1 -1
  833. package/ink/styles.ts +2 -2
  834. package/ink/tabstops.ts +2 -2
  835. package/ink/terminal-querier.ts +3 -3
  836. package/ink/terminal.ts +7 -7
  837. package/ink/termio/csi.ts +1 -1
  838. package/ink/termio/dec.ts +1 -1
  839. package/ink/termio/esc.ts +1 -1
  840. package/ink/termio/osc.ts +4 -4
  841. package/ink/termio/parser.ts +10 -10
  842. package/ink/termio/sgr.ts +2 -2
  843. package/ink/termio/tokenize.ts +2 -2
  844. package/ink/termio.ts +4 -4
  845. package/ink/useTerminalNotification.ts +3 -3
  846. package/ink/warn.ts +1 -1
  847. package/ink/widest-line.ts +1 -1
  848. package/ink/wrap-text.ts +4 -4
  849. package/ink.ts +47 -47
  850. package/interactiveHelpers.tsx +28 -28
  851. package/main.tsx +155 -155
  852. package/memdir/findRelevantMemories.ts +141 -0
  853. package/memdir/memdir.ts +507 -0
  854. package/memdir/memoryAge.ts +53 -0
  855. package/memdir/memoryScan.ts +94 -0
  856. package/memdir/memoryTypes.ts +271 -0
  857. package/memdir/paths.ts +278 -0
  858. package/memdir/teamMemPaths.ts +292 -0
  859. package/memdir/teamMemPrompts.ts +100 -0
  860. package/migrations/migrateAutoUpdatesToSettings.ts +61 -0
  861. package/migrations/migrateBypassPermissionsAcceptedToSettings.ts +40 -0
  862. package/migrations/migrateEnableAllProjectMcpServersToSettings.ts +118 -0
  863. package/migrations/migrateFennecToOpus.ts +45 -0
  864. package/migrations/migrateLegacyOpusToCurrent.ts +57 -0
  865. package/migrations/migrateOpusToOpus1m.ts +43 -0
  866. package/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.ts +22 -0
  867. package/migrations/migrateSonnet1mToSonnet45.ts +48 -0
  868. package/migrations/migrateSonnet45ToSonnet46.ts +67 -0
  869. package/migrations/resetAutoModeOptInForDefaultOffer.ts +51 -0
  870. package/migrations/resetProToOpusDefault.ts +51 -0
  871. package/native-ts/color-diff/index.ts +999 -0
  872. package/native-ts/file-index/index.ts +370 -0
  873. package/native-ts/yoga-layout/enums.ts +134 -0
  874. package/native-ts/yoga-layout/index.ts +2578 -0
  875. package/outputStyles/loadOutputStylesDir.ts +98 -0
  876. package/package.json +21 -5
  877. package/plugins/builtinPlugins.ts +159 -0
  878. package/plugins/bundled/index.ts +23 -0
  879. package/projectOnboardingState.ts +4 -4
  880. package/query/config.ts +4 -4
  881. package/query/deps.ts +3 -3
  882. package/query/stopHooks.ts +20 -20
  883. package/query/tokenBudget.ts +1 -1
  884. package/query.ts +41 -41
  885. package/replLauncher.tsx +5 -5
  886. package/schemas/hooks.ts +222 -0
  887. package/screens/Doctor.tsx +575 -0
  888. package/screens/REPL.tsx +5006 -0
  889. package/screens/ResumeConversation.tsx +399 -0
  890. package/server/createDirectConnectSession.ts +88 -0
  891. package/server/directConnectManager.ts +213 -0
  892. package/server/types.ts +57 -0
  893. package/services/AgentSummary/agentSummary.ts +9 -9
  894. package/services/MagicDocs/magicDocs.ts +11 -11
  895. package/services/MagicDocs/prompts.ts +2 -2
  896. package/services/PromptSuggestion/promptSuggestion.ts +17 -17
  897. package/services/PromptSuggestion/speculation.ts +25 -25
  898. package/services/SessionMemory/prompts.ts +4 -4
  899. package/services/SessionMemory/sessionMemory.ts +23 -23
  900. package/services/SessionMemory/sessionMemoryUtils.ts +5 -5
  901. package/services/analytics/config.ts +2 -2
  902. package/services/analytics/datadog.ts +7 -7
  903. package/services/analytics/firstPartyEventLogger.ts +13 -13
  904. package/services/analytics/firstPartyEventLoggingExporter.ts +18 -18
  905. package/services/analytics/growthbook.ts +11 -11
  906. package/services/analytics/metadata.ts +16 -16
  907. package/services/analytics/sink.ts +5 -5
  908. package/services/analytics/sinkKillswitch.ts +1 -1
  909. package/services/api/adminRequests.ts +2 -2
  910. package/services/api/bootstrap.ts +10 -10
  911. package/services/api/claude.ts +70 -70
  912. package/services/api/client.ts +9 -9
  913. package/services/api/dumpPrompts.ts +3 -3
  914. package/services/api/emptyUsage.ts +1 -1
  915. package/services/api/errors.ts +18 -18
  916. package/services/api/filesApi.ts +7 -7
  917. package/services/api/firstTokenDate.ts +5 -5
  918. package/services/api/grove.ts +11 -11
  919. package/services/api/logging.ts +19 -19
  920. package/services/api/metricsOptOut.ts +9 -9
  921. package/services/api/overageCreditGrant.ts +6 -6
  922. package/services/api/promptCacheBreakDetection.ts +9 -9
  923. package/services/api/referral.ts +8 -8
  924. package/services/api/sessionIngress.ts +11 -11
  925. package/services/api/ultrareviewQuota.ts +4 -4
  926. package/services/api/usage.ts +5 -5
  927. package/services/api/withRetry.ts +20 -20
  928. package/services/autoDream/autoDream.ts +18 -18
  929. package/services/autoDream/config.ts +2 -2
  930. package/services/autoDream/consolidationLock.ts +6 -6
  931. package/services/autoDream/consolidationPrompt.ts +1 -1
  932. package/services/awaySummary.ts +8 -8
  933. package/services/claudeAiLimits.ts +13 -13
  934. package/services/claudeAiLimitsHook.ts +1 -1
  935. package/services/compact/apiMicrocompact.ts +10 -10
  936. package/services/compact/autoCompact.ts +20 -20
  937. package/services/compact/compact.ts +44 -44
  938. package/services/compact/compactWarningHook.ts +1 -1
  939. package/services/compact/compactWarningState.ts +1 -1
  940. package/services/compact/grouping.ts +1 -1
  941. package/services/compact/microCompact.ts +19 -19
  942. package/services/compact/postCompactCleanup.ts +9 -9
  943. package/services/compact/prompt.ts +1 -1
  944. package/services/compact/sessionMemoryCompact.ts +19 -19
  945. package/services/compact/timeBasedMCConfig.ts +1 -1
  946. package/services/diagnosticTracking.ts +7 -7
  947. package/services/extractMemories/extractMemories.ts +24 -24
  948. package/services/extractMemories/prompts.ts +7 -7
  949. package/services/internalLogging.ts +3 -3
  950. package/services/lsp/LSPClient.ts +5 -5
  951. package/services/lsp/LSPDiagnosticRegistry.ts +5 -5
  952. package/services/lsp/LSPServerInstance.ts +7 -7
  953. package/services/lsp/LSPServerManager.ts +6 -6
  954. package/services/lsp/config.ts +7 -7
  955. package/services/lsp/manager.ts +6 -6
  956. package/services/lsp/passiveFeedback.ts +7 -7
  957. package/services/mcp/InProcessTransport.ts +2 -2
  958. package/services/mcp/MCPConnectionManager.tsx +4 -4
  959. package/services/mcp/SdkControlTransport.ts +2 -2
  960. package/services/mcp/auth.ts +23 -23
  961. package/services/mcp/channelAllowlist.ts +3 -3
  962. package/services/mcp/channelNotification.ts +9 -9
  963. package/services/mcp/channelPermissions.ts +2 -2
  964. package/services/mcp/claudeai.ts +9 -9
  965. package/services/mcp/client.ts +57 -57
  966. package/services/mcp/config.ts +25 -25
  967. package/services/mcp/elicitationHandler.ts +7 -7
  968. package/services/mcp/headersHelper.ts +9 -9
  969. package/services/mcp/mcpStringUtils.ts +1 -1
  970. package/services/mcp/oauthPort.ts +1 -1
  971. package/services/mcp/officialRegistry.ts +2 -2
  972. package/services/mcp/types.ts +3 -3
  973. package/services/mcp/useManageMCPConnections.ts +23 -23
  974. package/services/mcp/utils.ts +14 -14
  975. package/services/mcp/vscodeSdkMcp.ts +5 -5
  976. package/services/mcp/xaa.ts +5 -5
  977. package/services/mcp/xaaIdpLogin.ts +11 -11
  978. package/services/mcpServerApproval.tsx +7 -7
  979. package/services/mockRateLimits.ts +3 -3
  980. package/services/notifier.ts +7 -7
  981. package/services/oauth/auth-code-listener.ts +4 -4
  982. package/services/oauth/client.ts +8 -8
  983. package/services/oauth/getOauthProfile.ts +5 -5
  984. package/services/oauth/index.ts +6 -6
  985. package/services/plugins/PluginInstallationManager.ts +9 -9
  986. package/services/plugins/pluginCliCommands.ts +10 -10
  987. package/services/plugins/pluginOperations.ts +21 -21
  988. package/services/policyLimits/index.ts +14 -14
  989. package/services/policyLimits/types.ts +1 -1
  990. package/services/preventSleep.ts +2 -2
  991. package/services/rateLimitMessages.ts +4 -4
  992. package/services/rateLimitMocking.ts +1 -1
  993. package/services/remoteManagedSettings/index.ts +14 -14
  994. package/services/remoteManagedSettings/securityCheck.tsx +10 -10
  995. package/services/remoteManagedSettings/syncCache.ts +4 -4
  996. package/services/remoteManagedSettings/syncCacheState.ts +6 -6
  997. package/services/remoteManagedSettings/types.ts +2 -2
  998. package/services/settingsSync/index.ts +18 -18
  999. package/services/settingsSync/types.ts +1 -1
  1000. package/services/teamMemorySync/index.ts +16 -16
  1001. package/services/teamMemorySync/secretScanner.ts +1 -1
  1002. package/services/teamMemorySync/types.ts +1 -1
  1003. package/services/teamMemorySync/watcher.ts +8 -8
  1004. package/services/tips/tipHistory.ts +1 -1
  1005. package/services/tips/tipRegistry.ts +28 -28
  1006. package/services/tips/tipScheduler.ts +5 -5
  1007. package/services/tokenEstimation.ts +14 -14
  1008. package/services/toolUseSummary/toolUseSummaryGenerator.ts +6 -6
  1009. package/services/tools/StreamingToolExecutor.ts +7 -7
  1010. package/services/tools/toolExecution.ts +41 -41
  1011. package/services/tools/toolHooks.ts +16 -16
  1012. package/services/tools/toolOrchestration.ts +5 -5
  1013. package/services/vcr.ts +9 -9
  1014. package/services/voice.ts +4 -4
  1015. package/services/voiceKeyterms.ts +2 -2
  1016. package/services/voiceStreamSTT.ts +9 -9
  1017. package/setup.ts +32 -32
  1018. package/skills/bundled/batch.ts +124 -0
  1019. package/skills/bundled/claudeApi.ts +196 -0
  1020. package/skills/bundled/claudeApiContent.ts +48 -0
  1021. package/skills/bundled/claudeInChrome.ts +34 -0
  1022. package/skills/bundled/debug.ts +103 -0
  1023. package/skills/bundled/index.ts +79 -0
  1024. package/skills/bundled/keybindings.ts +339 -0
  1025. package/skills/bundled/loop.ts +92 -0
  1026. package/skills/bundled/loremIpsum.ts +282 -0
  1027. package/skills/bundled/remember.ts +82 -0
  1028. package/skills/bundled/scheduleRemoteAgents.ts +447 -0
  1029. package/skills/bundled/simplify.ts +69 -0
  1030. package/skills/bundled/skillify.ts +197 -0
  1031. package/skills/bundled/stuck.ts +79 -0
  1032. package/skills/bundled/updateConfig.ts +475 -0
  1033. package/skills/bundled/verify/SKILL.md +3 -0
  1034. package/skills/bundled/verify/examples/cli.md +3 -0
  1035. package/skills/bundled/verify/examples/server.md +3 -0
  1036. package/skills/bundled/verify.ts +30 -0
  1037. package/skills/bundled/verifyContent.ts +9 -0
  1038. package/skills/bundledSkills.ts +220 -0
  1039. package/skills/loadSkillsDir.ts +1086 -0
  1040. package/skills/mcpSkillBuilders.ts +44 -0
  1041. package/state/AppState.tsx +9 -9
  1042. package/state/AppStateStore.ts +29 -29
  1043. package/state/onChangeAppState.ts +10 -10
  1044. package/state/selectors.ts +4 -4
  1045. package/state/teammateViewHelpers.ts +4 -4
  1046. package/tasks/DreamTask/DreamTask.ts +157 -0
  1047. package/tasks/InProcessTeammateTask/InProcessTeammateTask.tsx +126 -0
  1048. package/tasks/InProcessTeammateTask/types.ts +121 -0
  1049. package/tasks/LocalAgentTask/LocalAgentTask.tsx +683 -0
  1050. package/tasks/LocalMainSessionTask.ts +479 -0
  1051. package/tasks/LocalShellTask/LocalShellTask.tsx +523 -0
  1052. package/tasks/LocalShellTask/guards.ts +41 -0
  1053. package/tasks/LocalShellTask/killShellTasks.ts +76 -0
  1054. package/tasks/RemoteAgentTask/RemoteAgentTask.tsx +856 -0
  1055. package/tasks/pillLabel.ts +82 -0
  1056. package/tasks/stopTask.ts +100 -0
  1057. package/tasks/types.ts +46 -0
  1058. package/tasks.ts +5 -5
  1059. package/tools/AgentTool/AgentTool.tsx +54 -54
  1060. package/tools/AgentTool/UI.tsx +28 -28
  1061. package/tools/AgentTool/agentColorManager.ts +2 -2
  1062. package/tools/AgentTool/agentDisplay.ts +3 -3
  1063. package/tools/AgentTool/agentMemory.ts +6 -6
  1064. package/tools/AgentTool/agentMemorySnapshot.ts +5 -5
  1065. package/tools/AgentTool/agentToolUtils.ts +27 -27
  1066. package/tools/AgentTool/built-in/claudeCodeGuideAgent.ts +12 -12
  1067. package/tools/AgentTool/built-in/exploreAgent.ts +11 -11
  1068. package/tools/AgentTool/built-in/generalPurposeAgent.ts +1 -1
  1069. package/tools/AgentTool/built-in/planAgent.ts +12 -12
  1070. package/tools/AgentTool/built-in/statuslineSetup.ts +1 -1
  1071. package/tools/AgentTool/built-in/verificationAgent.ts +8 -8
  1072. package/tools/AgentTool/builtInAgents.ts +10 -10
  1073. package/tools/AgentTool/forkSubagent.ts +7 -7
  1074. package/tools/AgentTool/loadAgentsDir.ts +23 -23
  1075. package/tools/AgentTool/prompt.ts +13 -13
  1076. package/tools/AgentTool/resumeAgent.ts +26 -26
  1077. package/tools/AgentTool/runAgent.ts +38 -38
  1078. package/tools/AskUserQuestionTool/AskUserQuestionTool.tsx +9 -9
  1079. package/tools/AskUserQuestionTool/prompt.ts +1 -1
  1080. package/tools/BashTool/BashTool.tsx +48 -48
  1081. package/tools/BashTool/BashToolResultMessage.tsx +7 -7
  1082. package/tools/BashTool/UI.tsx +20 -20
  1083. package/tools/BashTool/bashCommandHelpers.ts +8 -8
  1084. package/tools/BashTool/bashPermissions.ts +33 -33
  1085. package/tools/BashTool/bashSecurity.ts +6 -6
  1086. package/tools/BashTool/commandSemantics.ts +1 -1
  1087. package/tools/BashTool/modeValidation.ts +4 -4
  1088. package/tools/BashTool/pathValidation.ts +13 -13
  1089. package/tools/BashTool/prompt.ts +18 -18
  1090. package/tools/BashTool/readOnlyValidation.ts +14 -14
  1091. package/tools/BashTool/sedEditParser.ts +1 -1
  1092. package/tools/BashTool/sedValidation.ts +4 -4
  1093. package/tools/BashTool/shouldUseSandbox.ts +5 -5
  1094. package/tools/BashTool/utils.ts +10 -10
  1095. package/tools/BriefTool/BriefTool.ts +11 -11
  1096. package/tools/BriefTool/UI.tsx +8 -8
  1097. package/tools/BriefTool/attachments.ts +6 -6
  1098. package/tools/BriefTool/upload.ts +5 -5
  1099. package/tools/ConfigTool/ConfigTool.ts +12 -12
  1100. package/tools/ConfigTool/UI.tsx +4 -4
  1101. package/tools/ConfigTool/prompt.ts +3 -3
  1102. package/tools/ConfigTool/supportedSettings.ts +5 -5
  1103. package/tools/EnterPlanModeTool/EnterPlanModeTool.ts +10 -10
  1104. package/tools/EnterPlanModeTool/UI.tsx +7 -7
  1105. package/tools/EnterPlanModeTool/prompt.ts +2 -2
  1106. package/tools/EnterWorktreeTool/EnterWorktreeTool.ts +16 -16
  1107. package/tools/EnterWorktreeTool/UI.tsx +5 -5
  1108. package/tools/ExitPlanModeTool/ExitPlanModeV2Tool.ts +19 -19
  1109. package/tools/ExitPlanModeTool/UI.tsx +12 -12
  1110. package/tools/ExitWorktreeTool/ExitWorktreeTool.ts +17 -17
  1111. package/tools/ExitWorktreeTool/UI.tsx +5 -5
  1112. package/tools/FileEditTool/FileEditTool.ts +34 -34
  1113. package/tools/FileEditTool/UI.tsx +18 -18
  1114. package/tools/FileEditTool/prompt.ts +2 -2
  1115. package/tools/FileEditTool/types.ts +2 -2
  1116. package/tools/FileEditTool/utils.ts +7 -7
  1117. package/tools/FileReadTool/FileReadTool.ts +37 -37
  1118. package/tools/FileReadTool/UI.tsx +10 -10
  1119. package/tools/FileReadTool/imageProcessor.ts +1 -1
  1120. package/tools/FileReadTool/limits.ts +2 -2
  1121. package/tools/FileReadTool/prompt.ts +2 -2
  1122. package/tools/FileWriteTool/FileWriteTool.ts +31 -31
  1123. package/tools/FileWriteTool/UI.tsx +19 -19
  1124. package/tools/FileWriteTool/prompt.ts +1 -1
  1125. package/tools/GlobTool/GlobTool.ts +14 -14
  1126. package/tools/GlobTool/UI.tsx +8 -8
  1127. package/tools/GlobTool/prompt.ts +1 -1
  1128. package/tools/GrepTool/GrepTool.ts +19 -19
  1129. package/tools/GrepTool/UI.tsx +10 -10
  1130. package/tools/GrepTool/prompt.ts +3 -3
  1131. package/tools/LSPTool/LSPTool.ts +18 -18
  1132. package/tools/LSPTool/UI.tsx +8 -8
  1133. package/tools/LSPTool/formatters.ts +3 -3
  1134. package/tools/LSPTool/schemas.ts +1 -1
  1135. package/tools/LSPTool/symbolContext.ts +4 -4
  1136. package/tools/ListMcpResourcesTool/ListMcpResourcesTool.ts +9 -9
  1137. package/tools/ListMcpResourcesTool/UI.tsx +7 -7
  1138. package/tools/MCPTool/MCPTool.ts +7 -7
  1139. package/tools/MCPTool/UI.tsx +13 -13
  1140. package/tools/McpAuthTool/McpAuthTool.ts +9 -9
  1141. package/tools/NotebookEditTool/NotebookEditTool.ts +16 -16
  1142. package/tools/NotebookEditTool/UI.tsx +12 -12
  1143. package/tools/PowerShellTool/PowerShellTool.tsx +42 -42
  1144. package/tools/PowerShellTool/UI.tsx +12 -12
  1145. package/tools/PowerShellTool/gitSafety.ts +2 -2
  1146. package/tools/PowerShellTool/modeValidation.ts +5 -5
  1147. package/tools/PowerShellTool/pathValidation.ts +15 -15
  1148. package/tools/PowerShellTool/powershellPermissions.ts +16 -16
  1149. package/tools/PowerShellTool/powershellSecurity.ts +4 -4
  1150. package/tools/PowerShellTool/prompt.ts +10 -10
  1151. package/tools/PowerShellTool/readOnlyValidation.ts +6 -6
  1152. package/tools/REPLTool/constants.ts +9 -9
  1153. package/tools/REPLTool/primitiveTools.ts +9 -9
  1154. package/tools/ReadMcpResourceTool/ReadMcpResourceTool.ts +9 -9
  1155. package/tools/ReadMcpResourceTool/UI.tsx +7 -7
  1156. package/tools/RemoteTriggerTool/RemoteTriggerTool.ts +11 -11
  1157. package/tools/RemoteTriggerTool/UI.tsx +4 -4
  1158. package/tools/ScheduleCronTool/CronCreateTool.ts +10 -10
  1159. package/tools/ScheduleCronTool/CronDeleteTool.ts +7 -7
  1160. package/tools/ScheduleCronTool/CronListTool.ts +8 -8
  1161. package/tools/ScheduleCronTool/UI.tsx +6 -6
  1162. package/tools/ScheduleCronTool/prompt.ts +3 -3
  1163. package/tools/SendMessageTool/SendMessageTool.ts +27 -27
  1164. package/tools/SendMessageTool/UI.tsx +4 -4
  1165. package/tools/SkillTool/SkillTool.ts +32 -32
  1166. package/tools/SkillTool/UI.tsx +13 -13
  1167. package/tools/SkillTool/prompt.ts +10 -10
  1168. package/tools/SleepTool/prompt.ts +1 -1
  1169. package/tools/SyntheticOutputTool/SyntheticOutputTool.ts +6 -6
  1170. package/tools/TaskCreateTool/TaskCreateTool.ts +7 -7
  1171. package/tools/TaskCreateTool/prompt.ts +1 -1
  1172. package/tools/TaskGetTool/TaskGetTool.ts +5 -5
  1173. package/tools/TaskListTool/TaskListTool.ts +5 -5
  1174. package/tools/TaskListTool/prompt.ts +1 -1
  1175. package/tools/TaskOutputTool/TaskOutputTool.tsx +27 -27
  1176. package/tools/TaskStopTool/TaskStopTool.ts +7 -7
  1177. package/tools/TaskStopTool/UI.tsx +5 -5
  1178. package/tools/TaskUpdateTool/TaskUpdateTool.ts +11 -11
  1179. package/tools/TeamCreateTool/TeamCreateTool.ts +21 -21
  1180. package/tools/TeamCreateTool/UI.tsx +1 -1
  1181. package/tools/TeamDeleteTool/TeamDeleteTool.ts +14 -14
  1182. package/tools/TeamDeleteTool/UI.tsx +2 -2
  1183. package/tools/TodoWriteTool/TodoWriteTool.ts +9 -9
  1184. package/tools/TodoWriteTool/prompt.ts +1 -1
  1185. package/tools/ToolSearchTool/ToolSearchTool.ts +7 -7
  1186. package/tools/ToolSearchTool/prompt.ts +6 -6
  1187. package/tools/WebFetchTool/UI.tsx +7 -7
  1188. package/tools/WebFetchTool/WebFetchTool.ts +10 -10
  1189. package/tools/WebFetchTool/utils.ts +10 -10
  1190. package/tools/WebSearchTool/UI.tsx +6 -6
  1191. package/tools/WebSearchTool/WebSearchTool.ts +15 -15
  1192. package/tools/WebSearchTool/prompt.ts +1 -1
  1193. package/tools/shared/gitOperationTracking.ts +2 -2
  1194. package/tools/shared/spawnMultiAgent.ts +32 -32
  1195. package/tools/testing/TestingPermissionTool.tsx +3 -3
  1196. package/tools/utils.ts +1 -1
  1197. package/tools.ts +43 -43
  1198. package/types/command.ts +12 -12
  1199. package/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +2 -2
  1200. package/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +2 -2
  1201. package/types/hooks.ts +9 -9
  1202. package/types/logs.ts +5 -5
  1203. package/types/plugin.ts +5 -5
  1204. package/types/textInputTypes.ts +7 -7
  1205. package/upstreamproxy/relay.ts +455 -0
  1206. package/upstreamproxy/upstreamproxy.ts +285 -0
  1207. package/utils/Cursor.ts +3 -3
  1208. package/utils/QueryGuard.ts +1 -1
  1209. package/utils/Shell.ts +24 -24
  1210. package/utils/ShellCommand.ts +4 -4
  1211. package/utils/activityManager.ts +1 -1
  1212. package/utils/advisor.ts +4 -4
  1213. package/utils/agentContext.ts +2 -2
  1214. package/utils/agentSwarmsEnabled.ts +2 -2
  1215. package/utils/agenticSessionSearch.ts +8 -8
  1216. package/utils/analyzeContext.ts +29 -29
  1217. package/utils/ansiToPng.ts +2 -2
  1218. package/utils/ansiToSvg.ts +1 -1
  1219. package/utils/api.ts +37 -37
  1220. package/utils/apiPreconnect.ts +2 -2
  1221. package/utils/appleTerminalBackup.ts +3 -3
  1222. package/utils/argumentSubstitution.ts +1 -1
  1223. package/utils/asciicast.ts +8 -8
  1224. package/utils/attachments.ts +94 -94
  1225. package/utils/attribution.ts +20 -20
  1226. package/utils/auth.ts +29 -29
  1227. package/utils/authFileDescriptor.ts +5 -5
  1228. package/utils/authPortable.ts +1 -1
  1229. package/utils/autoRunIssue.tsx +3 -3
  1230. package/utils/autoUpdater.ts +15 -15
  1231. package/utils/aws.ts +1 -1
  1232. package/utils/awsAuthStatusManager.ts +1 -1
  1233. package/utils/background/remote/preconditions.ts +11 -11
  1234. package/utils/background/remote/remoteSession.ts +7 -7
  1235. package/utils/backgroundHousekeeping.ts +7 -7
  1236. package/utils/bash/ParsedCommand.ts +3 -3
  1237. package/utils/bash/ShellSnapshot.ts +13 -13
  1238. package/utils/bash/ast.ts +3 -3
  1239. package/utils/bash/bashPipeCommand.ts +1 -1
  1240. package/utils/bash/commands.ts +3 -3
  1241. package/utils/bash/parser.ts +3 -3
  1242. package/utils/bash/prefix.ts +4 -4
  1243. package/utils/bash/registry.ts +2 -2
  1244. package/utils/bash/shellCompletion.ts +5 -5
  1245. package/utils/bash/shellPrefix.ts +1 -1
  1246. package/utils/bash/shellQuote.ts +2 -2
  1247. package/utils/bash/shellQuoting.ts +1 -1
  1248. package/utils/bash/specs/alias.ts +1 -1
  1249. package/utils/bash/specs/index.ts +8 -8
  1250. package/utils/bash/specs/nohup.ts +1 -1
  1251. package/utils/bash/specs/pyright.ts +1 -1
  1252. package/utils/bash/specs/sleep.ts +1 -1
  1253. package/utils/bash/specs/srun.ts +1 -1
  1254. package/utils/bash/specs/time.ts +1 -1
  1255. package/utils/bash/specs/timeout.ts +1 -1
  1256. package/utils/betas.ts +11 -11
  1257. package/utils/billing.ts +3 -3
  1258. package/utils/binaryCheck.ts +2 -2
  1259. package/utils/browser.ts +1 -1
  1260. package/utils/caCerts.ts +3 -3
  1261. package/utils/caCertsConfig.ts +3 -3
  1262. package/utils/cachePaths.ts +2 -2
  1263. package/utils/classifierApprovals.ts +1 -1
  1264. package/utils/classifierApprovalsHook.ts +1 -1
  1265. package/utils/claudeCodeHints.ts +2 -2
  1266. package/utils/claudeDesktop.ts +5 -5
  1267. package/utils/claudeInChrome/chromeNativeHost.ts +3 -3
  1268. package/utils/claudeInChrome/common.ts +8 -8
  1269. package/utils/claudeInChrome/mcpServer.ts +12 -12
  1270. package/utils/claudeInChrome/setup.ts +13 -13
  1271. package/utils/claudeInChrome/setupPortable.ts +1 -1
  1272. package/utils/claudeInChrome/toolRendering.tsx +8 -8
  1273. package/utils/claudemd.ts +21 -21
  1274. package/utils/cleanup.ts +15 -15
  1275. package/utils/collapseBackgroundBashNotifications.ts +5 -5
  1276. package/utils/collapseHookSummaries.ts +1 -1
  1277. package/utils/collapseReadSearch.ts +13 -13
  1278. package/utils/collapseTeammateShutdowns.ts +1 -1
  1279. package/utils/combinedAbortSignal.ts +1 -1
  1280. package/utils/commitAttribution.ts +12 -12
  1281. package/utils/completionCache.ts +7 -7
  1282. package/utils/computerUse/cleanup.ts +6 -6
  1283. package/utils/computerUse/common.ts +2 -2
  1284. package/utils/computerUse/computerUseLock.ts +6 -6
  1285. package/utils/computerUse/drainRunLoop.ts +3 -3
  1286. package/utils/computerUse/escHotkey.ts +3 -3
  1287. package/utils/computerUse/executor.ts +9 -9
  1288. package/utils/computerUse/gates.ts +3 -3
  1289. package/utils/computerUse/hostAdapter.ts +5 -5
  1290. package/utils/computerUse/mcpServer.ts +10 -10
  1291. package/utils/computerUse/setup.ts +5 -5
  1292. package/utils/computerUse/toolRendering.tsx +4 -4
  1293. package/utils/computerUse/wrapper.tsx +9 -9
  1294. package/utils/concurrentSessions.ts +9 -9
  1295. package/utils/config.ts +29 -29
  1296. package/utils/context.ts +5 -5
  1297. package/utils/contextAnalysis.ts +4 -4
  1298. package/utils/contextSuggestions.ts +7 -7
  1299. package/utils/conversationRecovery.ts +14 -14
  1300. package/utils/cronJitterConfig.ts +3 -3
  1301. package/utils/cronScheduler.ts +6 -6
  1302. package/utils/cronTasks.ts +8 -8
  1303. package/utils/cronTasksLock.ts +8 -8
  1304. package/utils/crossProjectResume.ts +4 -4
  1305. package/utils/cwd.ts +1 -1
  1306. package/utils/debug.ts +8 -8
  1307. package/utils/deepLink/banner.ts +3 -3
  1308. package/utils/deepLink/parseDeepLink.ts +1 -1
  1309. package/utils/deepLink/protocolHandler.ts +7 -7
  1310. package/utils/deepLink/registerProtocol.ts +10 -10
  1311. package/utils/deepLink/terminalLauncher.ts +4 -4
  1312. package/utils/deepLink/terminalPreference.ts +2 -2
  1313. package/utils/desktopDeepLink.ts +6 -6
  1314. package/utils/detectRepository.ts +3 -3
  1315. package/utils/diagLogs.ts +2 -2
  1316. package/utils/diff.ts +6 -6
  1317. package/utils/directMemberMessage.ts +1 -1
  1318. package/utils/doctorContextWarnings.ts +11 -11
  1319. package/utils/doctorDiagnostic.ts +17 -17
  1320. package/utils/dxt/helpers.ts +2 -2
  1321. package/utils/dxt/zip.ts +4 -4
  1322. package/utils/earlyInput.ts +1 -1
  1323. package/utils/editor.ts +3 -3
  1324. package/utils/effort.ts +8 -8
  1325. package/utils/embeddedTools.ts +1 -1
  1326. package/utils/env.ts +6 -6
  1327. package/utils/envDynamic.ts +4 -4
  1328. package/utils/envValidation.ts +1 -1
  1329. package/utils/errorLogSink.ts +8 -8
  1330. package/utils/exampleCommands.ts +7 -7
  1331. package/utils/execFileNoThrow.ts +3 -3
  1332. package/utils/execFileNoThrowPortable.ts +2 -2
  1333. package/utils/execSyncWrapper.ts +2 -2
  1334. package/utils/exportRenderer.tsx +8 -8
  1335. package/utils/extraUsage.ts +2 -2
  1336. package/utils/fastMode.ts +14 -14
  1337. package/utils/file.ts +11 -11
  1338. package/utils/fileHistory.ts +11 -11
  1339. package/utils/fileOperationAnalytics.ts +2 -2
  1340. package/utils/filePersistence/filePersistence.ts +7 -7
  1341. package/utils/filePersistence/outputsScanner.ts +2 -2
  1342. package/utils/filePersistence/types.ts +1 -1
  1343. package/utils/fileRead.ts +2 -2
  1344. package/utils/fileReadCache.ts +2 -2
  1345. package/utils/findExecutable.ts +1 -1
  1346. package/utils/fingerprint.ts +1 -1
  1347. package/utils/forkedAgent.ts +22 -22
  1348. package/utils/format.ts +2 -2
  1349. package/utils/frontmatterParser.ts +3 -3
  1350. package/utils/fsOperations.ts +2 -2
  1351. package/utils/fullscreen.ts +4 -4
  1352. package/utils/genericProcessUtils.ts +1 -1
  1353. package/utils/getWorktreePaths.ts +3 -3
  1354. package/utils/ghPrStatus.ts +3 -3
  1355. package/utils/git/gitFilesystem.ts +5 -5
  1356. package/utils/git/gitignore.ts +5 -5
  1357. package/utils/git.ts +10 -10
  1358. package/utils/gitDiff.ts +5 -5
  1359. package/utils/gitSettings.ts +2 -2
  1360. package/utils/github/ghAuthStatus.ts +1 -1
  1361. package/utils/githubRepoPathMapping.ts +7 -7
  1362. package/utils/glob.ts +6 -6
  1363. package/utils/gracefulShutdown.ts +17 -17
  1364. package/utils/groupToolUses.ts +2 -2
  1365. package/utils/handlePromptSubmit.ts +28 -28
  1366. package/utils/headlessProfiler.ts +6 -6
  1367. package/utils/heapDumpService.ts +8 -8
  1368. package/utils/heatmap.ts +2 -2
  1369. package/utils/highlightMatch.tsx +1 -1
  1370. package/utils/hooks/AsyncHookRegistry.ts +6 -6
  1371. package/utils/hooks/apiQueryHookHelper.ts +9 -9
  1372. package/utils/hooks/execAgentHook.ts +25 -25
  1373. package/utils/hooks/execHttpHook.ts +8 -8
  1374. package/utils/hooks/execPromptHook.ts +15 -15
  1375. package/utils/hooks/fileChangedWatcher.ts +6 -6
  1376. package/utils/hooks/hookEvents.ts +2 -2
  1377. package/utils/hooks/hookHelpers.ts +7 -7
  1378. package/utils/hooks/hooksConfigManager.ts +4 -4
  1379. package/utils/hooks/hooksConfigSnapshot.ts +5 -5
  1380. package/utils/hooks/hooksSettings.ts +9 -9
  1381. package/utils/hooks/postSamplingHooks.ts +6 -6
  1382. package/utils/hooks/registerFrontmatterHooks.ts +5 -5
  1383. package/utils/hooks/registerSkillHooks.ts +5 -5
  1384. package/utils/hooks/sessionHooks.ts +7 -7
  1385. package/utils/hooks/skillImprovement.ts +17 -17
  1386. package/utils/hooks.ts +56 -56
  1387. package/utils/http.ts +4 -4
  1388. package/utils/hyperlink.ts +1 -1
  1389. package/utils/iTermBackup.ts +2 -2
  1390. package/utils/ide.ts +22 -22
  1391. package/utils/idleTimeout.ts +2 -2
  1392. package/utils/imagePaste.ts +8 -8
  1393. package/utils/imageResizer.ts +7 -7
  1394. package/utils/imageStore.ts +5 -5
  1395. package/utils/imageValidation.ts +3 -3
  1396. package/utils/immediateCommand.ts +1 -1
  1397. package/utils/inProcessTeammateHelpers.ts +4 -4
  1398. package/utils/ink.ts +2 -2
  1399. package/utils/jetbrains.ts +2 -2
  1400. package/utils/json.ts +5 -5
  1401. package/utils/listSessionsImpl.ts +3 -3
  1402. package/utils/localInstaller.ts +7 -7
  1403. package/utils/log.ts +10 -10
  1404. package/utils/logoV2Utils.ts +11 -11
  1405. package/utils/mailbox.ts +1 -1
  1406. package/utils/managedEnv.ts +9 -9
  1407. package/utils/markdown.ts +9 -9
  1408. package/utils/markdownConfigLoader.ts +14 -14
  1409. package/utils/mcp/dateTimeParser.ts +4 -4
  1410. package/utils/mcp/elicitationValidation.ts +4 -4
  1411. package/utils/mcpInstructionsDelta.ts +5 -5
  1412. package/utils/mcpOutputStorage.ts +6 -6
  1413. package/utils/mcpValidation.ts +4 -4
  1414. package/utils/mcpWebSocketTransport.ts +5 -5
  1415. package/utils/memoize.ts +2 -2
  1416. package/utils/memory/versions.ts +1 -1
  1417. package/utils/memoryFileDetection.ts +4 -4
  1418. package/utils/messagePredicates.ts +1 -1
  1419. package/utils/messageQueueManager.ts +10 -10
  1420. package/utils/messages/mappers.ts +9 -9
  1421. package/utils/messages/systemInit.ts +8 -8
  1422. package/utils/messages.ts +59 -59
  1423. package/utils/model/agent.ts +6 -6
  1424. package/utils/model/antModels.ts +2 -2
  1425. package/utils/model/bedrock.ts +4 -4
  1426. package/utils/model/check1mAccess.ts +4 -4
  1427. package/utils/model/configs.ts +2 -2
  1428. package/utils/model/contextWindowUpgradeCheck.ts +2 -2
  1429. package/utils/model/deprecation.ts +1 -1
  1430. package/utils/model/model.ts +13 -13
  1431. package/utils/model/modelAllowlist.ts +4 -4
  1432. package/utils/model/modelCapabilities.ts +10 -10
  1433. package/utils/model/modelOptions.ts +11 -11
  1434. package/utils/model/modelStrings.ts +7 -7
  1435. package/utils/model/modelSupportOverrides.ts +1 -1
  1436. package/utils/model/providers.ts +2 -2
  1437. package/utils/model/validateModel.ts +5 -5
  1438. package/utils/modelCost.ts +6 -6
  1439. package/utils/mtls.ts +3 -3
  1440. package/utils/nativeInstaller/download.ts +10 -10
  1441. package/utils/nativeInstaller/index.ts +1 -1
  1442. package/utils/nativeInstaller/installer.ts +20 -20
  1443. package/utils/nativeInstaller/packageManagers.ts +3 -3
  1444. package/utils/nativeInstaller/pidLock.ts +8 -8
  1445. package/utils/notebook.ts +6 -6
  1446. package/utils/pasteStore.ts +3 -3
  1447. package/utils/path.ts +5 -5
  1448. package/utils/pdf.ts +6 -6
  1449. package/utils/pdfUtils.ts +1 -1
  1450. package/utils/permissions/PermissionMode.ts +3 -3
  1451. package/utils/permissions/PermissionPromptToolResultSchema.ts +6 -6
  1452. package/utils/permissions/PermissionResult.ts +1 -1
  1453. package/utils/permissions/PermissionRule.ts +2 -2
  1454. package/utils/permissions/PermissionUpdate.ts +11 -11
  1455. package/utils/permissions/PermissionUpdateSchema.ts +4 -4
  1456. package/utils/permissions/bypassPermissionsKillswitch.ts +4 -4
  1457. package/utils/permissions/classifierDecision.ts +21 -21
  1458. package/utils/permissions/classifierShared.ts +1 -1
  1459. package/utils/permissions/filesystem.ts +24 -24
  1460. package/utils/permissions/getNextPermissionMode.ts +4 -4
  1461. package/utils/permissions/pathValidation.ts +8 -8
  1462. package/utils/permissions/permissionExplainer.ts +11 -11
  1463. package/utils/permissions/permissionRuleParser.ts +4 -4
  1464. package/utils/permissions/permissionSetup.ts +27 -27
  1465. package/utils/permissions/permissions.ts +35 -35
  1466. package/utils/permissions/permissionsLoader.ts +9 -9
  1467. package/utils/permissions/shadowedRuleDetection.ts +4 -4
  1468. package/utils/permissions/shellRuleMatching.ts +1 -1
  1469. package/utils/permissions/yoloClassifier.ts +25 -25
  1470. package/utils/planModeV2.ts +3 -3
  1471. package/utils/plans.ts +14 -14
  1472. package/utils/platform.ts +2 -2
  1473. package/utils/plugins/addDirPluginSettings.ts +3 -3
  1474. package/utils/plugins/cacheUtils.ts +16 -16
  1475. package/utils/plugins/dependencyResolver.ts +5 -5
  1476. package/utils/plugins/fetchTelemetry.ts +2 -2
  1477. package/utils/plugins/gitAvailability.ts +1 -1
  1478. package/utils/plugins/headlessPluginInstall.ts +12 -12
  1479. package/utils/plugins/hintRecommendation.ts +9 -9
  1480. package/utils/plugins/installCounts.ts +7 -7
  1481. package/utils/plugins/installedPluginsManager.ts +15 -15
  1482. package/utils/plugins/loadPluginAgents.ts +17 -17
  1483. package/utils/plugins/loadPluginCommands.ts +17 -17
  1484. package/utils/plugins/loadPluginHooks.ts +9 -9
  1485. package/utils/plugins/loadPluginOutputStyles.ts +8 -8
  1486. package/utils/plugins/lspPluginIntegration.ts +10 -10
  1487. package/utils/plugins/lspRecommendation.ts +6 -6
  1488. package/utils/plugins/managedPlugins.ts +1 -1
  1489. package/utils/plugins/marketplaceHelpers.ts +7 -7
  1490. package/utils/plugins/marketplaceManager.ts +22 -22
  1491. package/utils/plugins/mcpPluginIntegration.ts +10 -10
  1492. package/utils/plugins/mcpbHandler.ts +12 -12
  1493. package/utils/plugins/officialMarketplace.ts +1 -1
  1494. package/utils/plugins/officialMarketplaceGcs.ts +6 -6
  1495. package/utils/plugins/officialMarketplaceStartupCheck.ts +12 -12
  1496. package/utils/plugins/orphanedPluginFilter.ts +2 -2
  1497. package/utils/plugins/parseMarketplaceInput.ts +3 -3
  1498. package/utils/plugins/performStartupChecks.tsx +6 -6
  1499. package/utils/plugins/pluginAutoupdate.ts +9 -9
  1500. package/utils/plugins/pluginBlocklist.ts +7 -7
  1501. package/utils/plugins/pluginDirectories.ts +6 -6
  1502. package/utils/plugins/pluginFlagging.ts +5 -5
  1503. package/utils/plugins/pluginIdentifier.ts +2 -2
  1504. package/utils/plugins/pluginInstallationHelpers.ts +18 -18
  1505. package/utils/plugins/pluginLoader.ts +31 -31
  1506. package/utils/plugins/pluginOptionsStorage.ts +7 -7
  1507. package/utils/plugins/pluginPolicy.ts +1 -1
  1508. package/utils/plugins/pluginStartupCheck.ts +11 -11
  1509. package/utils/plugins/pluginVersioning.ts +3 -3
  1510. package/utils/plugins/reconciler.ts +8 -8
  1511. package/utils/plugins/refresh.ts +17 -17
  1512. package/utils/plugins/schemas.ts +3 -3
  1513. package/utils/plugins/validatePlugin.ts +5 -5
  1514. package/utils/plugins/walkPluginMarkdown.ts +2 -2
  1515. package/utils/plugins/zipCache.ts +6 -6
  1516. package/utils/plugins/zipCacheAdapters.ts +5 -5
  1517. package/utils/powershell/dangerousCmdlets.ts +2 -2
  1518. package/utils/powershell/parser.ts +4 -4
  1519. package/utils/powershell/staticPrefix.ts +5 -5
  1520. package/utils/preflightChecks.tsx +8 -8
  1521. package/utils/processUserInput/processBashCommand.tsx +13 -13
  1522. package/utils/processUserInput/processSlashCommand.tsx +45 -45
  1523. package/utils/processUserInput/processTextPrompt.ts +8 -8
  1524. package/utils/processUserInput/processUserInput.ts +22 -22
  1525. package/utils/profilerBase.ts +1 -1
  1526. package/utils/promptCategory.ts +3 -3
  1527. package/utils/promptEditor.ts +9 -9
  1528. package/utils/promptShellExecution.ts +9 -9
  1529. package/utils/proxy.ts +4 -4
  1530. package/utils/queryContext.ts +14 -14
  1531. package/utils/queryHelpers.ts +23 -23
  1532. package/utils/queryProfiler.ts +3 -3
  1533. package/utils/queueProcessor.ts +2 -2
  1534. package/utils/readEditContext.ts +1 -1
  1535. package/utils/readFileInRange.ts +1 -1
  1536. package/utils/releaseNotes.ts +7 -7
  1537. package/utils/renderOptions.ts +3 -3
  1538. package/utils/ripgrep.ts +9 -9
  1539. package/utils/sandbox/sandbox-adapter.ts +17 -17
  1540. package/utils/screenshotClipboard.ts +4 -4
  1541. package/utils/sdkEventQueue.ts +2 -2
  1542. package/utils/secureStorage/fallbackStorage.ts +1 -1
  1543. package/utils/secureStorage/index.ts +4 -4
  1544. package/utils/secureStorage/keychainPrefetch.ts +2 -2
  1545. package/utils/secureStorage/macOsKeychainHelpers.ts +3 -3
  1546. package/utils/secureStorage/macOsKeychainStorage.ts +6 -6
  1547. package/utils/secureStorage/plainTextStorage.ts +5 -5
  1548. package/utils/sessionActivity.ts +3 -3
  1549. package/utils/sessionEnvironment.ts +5 -5
  1550. package/utils/sessionFileAccessHooks.ts +16 -16
  1551. package/utils/sessionIngressAuth.ts +5 -5
  1552. package/utils/sessionRestore.ts +28 -28
  1553. package/utils/sessionStart.ts +11 -11
  1554. package/utils/sessionState.ts +3 -3
  1555. package/utils/sessionStorage.ts +35 -35
  1556. package/utils/sessionStoragePortable.ts +3 -3
  1557. package/utils/sessionTitle.ts +9 -9
  1558. package/utils/sessionUrl.ts +1 -1
  1559. package/utils/settings/allErrors.ts +3 -3
  1560. package/utils/settings/applySettingsChange.ts +8 -8
  1561. package/utils/settings/changeDetector.ts +13 -13
  1562. package/utils/settings/constants.ts +1 -1
  1563. package/utils/settings/managedPath.ts +1 -1
  1564. package/utils/settings/mdm/rawRead.ts +1 -1
  1565. package/utils/settings/mdm/settings.ts +11 -11
  1566. package/utils/settings/permissionValidation.ts +5 -5
  1567. package/utils/settings/pluginOnlyPolicy.ts +2 -2
  1568. package/utils/settings/schemaOutput.ts +2 -2
  1569. package/utils/settings/settings.ts +23 -23
  1570. package/utils/settings/settingsCache.ts +3 -3
  1571. package/utils/settings/types.ts +10 -10
  1572. package/utils/settings/validateEditTool.ts +3 -3
  1573. package/utils/settings/validation.ts +8 -8
  1574. package/utils/shell/bashProvider.ts +12 -12
  1575. package/utils/shell/outputLimits.ts +1 -1
  1576. package/utils/shell/powershellDetection.ts +2 -2
  1577. package/utils/shell/powershellProvider.ts +2 -2
  1578. package/utils/shell/prefix.ts +8 -8
  1579. package/utils/shell/readOnlyCommandValidation.ts +1 -1
  1580. package/utils/shell/resolveDefaultShell.ts +1 -1
  1581. package/utils/shell/shellToolUtils.ts +4 -4
  1582. package/utils/shell/specPrefix.ts +1 -1
  1583. package/utils/shellConfig.ts +2 -2
  1584. package/utils/sideQuery.ts +12 -12
  1585. package/utils/sideQuestion.ts +5 -5
  1586. package/utils/sinks.ts +2 -2
  1587. package/utils/skills/skillChangeDetector.ts +10 -10
  1588. package/utils/sliceAnsi.ts +1 -1
  1589. package/utils/slowOperations.ts +6 -6
  1590. package/utils/standaloneAgent.ts +2 -2
  1591. package/utils/startupProfiler.ts +7 -7
  1592. package/utils/staticRender.tsx +1 -1
  1593. package/utils/stats.ts +11 -11
  1594. package/utils/statsCache.ts +8 -8
  1595. package/utils/status.tsx +19 -19
  1596. package/utils/statusNoticeDefinitions.tsx +10 -10
  1597. package/utils/statusNoticeHelpers.ts +2 -2
  1598. package/utils/streamJsonStdoutGuard.ts +2 -2
  1599. package/utils/streamlinedTransform.ts +15 -15
  1600. package/utils/subprocessEnv.ts +1 -1
  1601. package/utils/suggestions/commandSuggestions.ts +4 -4
  1602. package/utils/suggestions/directoryCompletion.ts +5 -5
  1603. package/utils/suggestions/shellHistoryCompletion.ts +2 -2
  1604. package/utils/suggestions/skillUsageTracking.ts +1 -1
  1605. package/utils/suggestions/slackChannelSuggestions.ts +6 -6
  1606. package/utils/swarm/It2SetupPrompt.tsx +7 -7
  1607. package/utils/swarm/backends/ITermBackend.ts +6 -6
  1608. package/utils/swarm/backends/InProcessBackend.ts +9 -9
  1609. package/utils/swarm/backends/PaneBackendExecutor.ts +12 -12
  1610. package/utils/swarm/backends/TmuxBackend.ts +10 -10
  1611. package/utils/swarm/backends/detection.ts +3 -3
  1612. package/utils/swarm/backends/it2Setup.ts +4 -4
  1613. package/utils/swarm/backends/registry.ts +9 -9
  1614. package/utils/swarm/backends/teammateModeSnapshot.ts +3 -3
  1615. package/utils/swarm/backends/types.ts +1 -1
  1616. package/utils/swarm/inProcessRunner.ts +55 -55
  1617. package/utils/swarm/leaderPermissionBridge.ts +2 -2
  1618. package/utils/swarm/permissionSync.ts +10 -10
  1619. package/utils/swarm/reconnection.ts +5 -5
  1620. package/utils/swarm/spawnInProcess.ts +16 -16
  1621. package/utils/swarm/spawnUtils.ts +6 -6
  1622. package/utils/swarm/teamHelpers.ts +13 -13
  1623. package/utils/swarm/teammateInit.ts +8 -8
  1624. package/utils/swarm/teammateLayoutManager.ts +4 -4
  1625. package/utils/swarm/teammateModel.ts +2 -2
  1626. package/utils/systemDirectories.ts +2 -2
  1627. package/utils/systemPrompt.ts +7 -7
  1628. package/utils/systemTheme.ts +1 -1
  1629. package/utils/task/TaskOutput.ts +6 -6
  1630. package/utils/task/diskOutput.ts +5 -5
  1631. package/utils/task/framework.ts +7 -7
  1632. package/utils/task/outputFormatting.ts +2 -2
  1633. package/utils/task/sdkProgress.ts +2 -2
  1634. package/utils/tasks.ts +12 -12
  1635. package/utils/teamDiscovery.ts +3 -3
  1636. package/utils/teamMemoryOps.ts +3 -3
  1637. package/utils/teammate.ts +4 -4
  1638. package/utils/teammateMailbox.ts +17 -17
  1639. package/utils/telemetry/betaSessionTracing.ts +7 -7
  1640. package/utils/telemetry/bigqueryExporter.ts +10 -10
  1641. package/utils/telemetry/events.ts +4 -4
  1642. package/utils/telemetry/instrumentation.ts +19 -19
  1643. package/utils/telemetry/logger.ts +2 -2
  1644. package/utils/telemetry/perfettoTracing.ts +8 -8
  1645. package/utils/telemetry/pluginTelemetry.ts +3 -3
  1646. package/utils/telemetry/sessionTracing.ts +6 -6
  1647. package/utils/telemetry/skillLoadedEvent.ts +3 -3
  1648. package/utils/telemetryAttributes.ts +6 -6
  1649. package/utils/teleport/api.ts +10 -10
  1650. package/utils/teleport/environmentSelection.ts +3 -3
  1651. package/utils/teleport/environments.ts +6 -6
  1652. package/utils/teleport/gitBundle.ts +8 -8
  1653. package/utils/teleport.tsx +37 -37
  1654. package/utils/terminal.ts +3 -3
  1655. package/utils/terminalPanel.ts +5 -5
  1656. package/utils/textHighlighting.ts +1 -1
  1657. package/utils/theme.ts +1 -1
  1658. package/utils/thinking.ts +6 -6
  1659. package/utils/tmuxSocket.ts +6 -6
  1660. package/utils/todo/types.ts +1 -1
  1661. package/utils/tokens.ts +4 -4
  1662. package/utils/toolErrors.ts +2 -2
  1663. package/utils/toolPool.ts +3 -3
  1664. package/utils/toolResultStorage.ts +12 -12
  1665. package/utils/toolSearch.ts +16 -16
  1666. package/utils/transcriptSearch.ts +2 -2
  1667. package/utils/treeify.ts +2 -2
  1668. package/utils/truncate.ts +2 -2
  1669. package/utils/ultraplan/ccrSession.ts +6 -6
  1670. package/utils/unaryLogging.ts +1 -1
  1671. package/utils/undercover.ts +3 -3
  1672. package/utils/user.ts +6 -6
  1673. package/utils/uuid.ts +1 -1
  1674. package/utils/warningHandler.ts +4 -4
  1675. package/utils/which.ts +1 -1
  1676. package/utils/windowsPaths.ts +5 -5
  1677. package/utils/worktree.ts +14 -14
  1678. package/vim/motions.ts +82 -0
  1679. package/vim/operators.ts +556 -0
  1680. package/vim/textObjects.ts +186 -0
  1681. package/vim/transitions.ts +490 -0
  1682. package/vim/types.ts +199 -0
  1683. package/voice/voiceModeEnabled.ts +54 -0
@@ -0,0 +1,1769 @@
1
+ import type { BetaMessageStreamParams } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
2
+ import type { Attributes, Meter, MetricOptions } from '@opentelemetry/api'
3
+ import type { logs } from '@opentelemetry/api-logs'
4
+ import type { LoggerProvider } from '@opentelemetry/sdk-logs'
5
+ import type { MeterProvider } from '@opentelemetry/sdk-metrics'
6
+ import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base'
7
+ import { realpathSync } from 'fs'
8
+ import sumBy from 'lodash-es/sumBy.js'
9
+ import { cwd } from 'process'
10
+ import type { HookEvent, ModelUsage } from '../entrypoints/agentSdkTypes.ts'
11
+ import type { AgentColorName } from '../tools/AgentTool/agentColorManager.ts'
12
+ import type { HookCallbackMatcher } from '../types/hooks.ts'
13
+ // Indirection for browser-sdk build (package.json "browser" field swaps
14
+ // crypto.ts for crypto.browser.ts). Pure leaf re-export of node:crypto —
15
+ // zero circular-dep risk. Path-alias import bypasses bootstrap-isolation
16
+ // (rule only checks ./ and / prefixes); explicit disable documents intent.
17
+ // eslint-disable-next-line custom-rules/bootstrap-isolation
18
+ import { randomUUID } from '../utils/crypto.ts'
19
+ import type { ModelSetting } from '../utils/model/model.ts'
20
+ import type { ModelStrings } from '../utils/model/modelStrings.ts'
21
+ import type { SettingSource } from '../utils/settings/constants.ts'
22
+ import { resetSettingsCache } from '../utils/settings/settingsCache.ts'
23
+ import type { PluginHookMatcher } from '../utils/settings/types.ts'
24
+ import { createSignal } from '../utils/signal.ts'
25
+
26
+ // Union type for registered hooks - can be SDK callbacks or native plugin hooks
27
+ type RegisteredHookMatcher = HookCallbackMatcher | PluginHookMatcher
28
+
29
+ import type { SessionId } from '../types/ids.ts'
30
+
31
+ // DO NOT ADD MORE STATE HERE - BE JUDICIOUS WITH GLOBAL STATE
32
+
33
+ // dev: true on entries that came via --dangerously-load-development-channels.
34
+ // The allowlist gate checks this per-entry (not the session-wide
35
+ // hasDevChannels bit) so passing both flags doesn't let the dev dialog's
36
+ // acceptance leak allowlist-bypass to the --channels entries.
37
+ export type ChannelEntry =
38
+ | { kind: 'plugin'; name: string; marketplace: string; dev?: boolean }
39
+ | { kind: 'server'; name: string; dev?: boolean }
40
+
41
+ export type AttributedCounter = {
42
+ add(value: number, additionalAttributes?: Attributes): void
43
+ }
44
+
45
+ type State = {
46
+ originalCwd: string
47
+ // Stable project root - set once at startup (including by --worktree flag),
48
+ // never updated by mid-session EnterWorktreeTool.
49
+ // Use for project identity (history, skills, sessions) not file operations.
50
+ projectRoot: string
51
+ totalCostUSD: number
52
+ totalAPIDuration: number
53
+ totalAPIDurationWithoutRetries: number
54
+ totalToolDuration: number
55
+ turnHookDurationMs: number
56
+ turnToolDurationMs: number
57
+ turnClassifierDurationMs: number
58
+ turnToolCount: number
59
+ turnHookCount: number
60
+ turnClassifierCount: number
61
+ startTime: number
62
+ lastInteractionTime: number
63
+ totalLinesAdded: number
64
+ totalLinesRemoved: number
65
+ hasUnknownModelCost: boolean
66
+ cwd: string
67
+ modelUsage: { [modelName: string]: ModelUsage }
68
+ mainLoopModelOverride: ModelSetting | undefined
69
+ initialMainLoopModel: ModelSetting
70
+ modelStrings: ModelStrings | null
71
+ isInteractive: boolean
72
+ kairosActive: boolean
73
+ // When true, ensureToolResultPairing throws on mismatch instead of
74
+ // repairing with synthetic placeholders. HFI opts in at startup so
75
+ // trajectories fail fast rather than conditioning the model on fake
76
+ // tool_results.
77
+ strictToolResultPairing: boolean
78
+ sdkAgentProgressSummariesEnabled: boolean
79
+ userMsgOptIn: boolean
80
+ clientType: string
81
+ sessionSource: string | undefined
82
+ questionPreviewFormat: 'markdown' | 'html' | undefined
83
+ flagSettingsPath: string | undefined
84
+ flagSettingsInline: Record<string, unknown> | null
85
+ allowedSettingSources: SettingSource[]
86
+ sessionIngressToken: string | null | undefined
87
+ oauthTokenFromFd: string | null | undefined
88
+ apiKeyFromFd: string | null | undefined
89
+ // Telemetry state
90
+ meter: Meter | null
91
+ sessionCounter: AttributedCounter | null
92
+ locCounter: AttributedCounter | null
93
+ prCounter: AttributedCounter | null
94
+ commitCounter: AttributedCounter | null
95
+ costCounter: AttributedCounter | null
96
+ tokenCounter: AttributedCounter | null
97
+ codeEditToolDecisionCounter: AttributedCounter | null
98
+ activeTimeCounter: AttributedCounter | null
99
+ statsStore: { observe(name: string, value: number): void } | null
100
+ sessionId: SessionId
101
+ // Parent session ID for tracking session lineage (e.g., plan mode -> implementation)
102
+ parentSessionId: SessionId | undefined
103
+ // Logger state
104
+ loggerProvider: LoggerProvider | null
105
+ eventLogger: ReturnType<typeof logs.getLogger> | null
106
+ // Meter provider state
107
+ meterProvider: MeterProvider | null
108
+ // Tracer provider state
109
+ tracerProvider: BasicTracerProvider | null
110
+ // Agent color state
111
+ agentColorMap: Map<string, AgentColorName>
112
+ agentColorIndex: number
113
+ // Last API request for bug reports
114
+ lastAPIRequest: Omit<BetaMessageStreamParams, 'messages'> | null
115
+ // Messages from the last API request (ant-only; reference, not clone).
116
+ // Captures the exact post-compaction, CLAUDE.md-injected message set sent
117
+ // to the API so /share's serialized_conversation.json reflects reality.
118
+ lastAPIRequestMessages: BetaMessageStreamParams['messages'] | null
119
+ // Last auto-mode classifier request(s) for /share transcript
120
+ lastClassifierRequests: unknown[] | null
121
+ // CLAUDE.md content cached by context.ts for the auto-mode classifier.
122
+ // Breaks the yoloClassifier → claudemd → filesystem → permissions cycle.
123
+ cachedClaudeMdContent: string | null
124
+ // In-memory error log for recent errors
125
+ inMemoryErrorLog: Array<{ error: string; timestamp: string }>
126
+ // Session-only plugins from --plugin-dir flag
127
+ inlinePlugins: Array<string>
128
+ // Explicit --chrome / --no-chrome flag value (undefined = not set on CLI)
129
+ chromeFlagOverride: boolean | undefined
130
+ // Use cowork_plugins directory instead of plugins (--cowork flag or env var)
131
+ useCoworkPlugins: boolean
132
+ // Session-only bypass permissions mode flag (not persisted)
133
+ sessionBypassPermissionsMode: boolean
134
+ // Session-only flag gating the .claude/scheduled_tasks.json watcher
135
+ // (useScheduledTasks). Set by cronScheduler.start() when the JSON has
136
+ // entries, or by CronCreateTool. Not persisted.
137
+ scheduledTasksEnabled: boolean
138
+ // Session-only cron tasks created via CronCreate with durable: false.
139
+ // Fire on schedule like file-backed tasks but are never written to
140
+ // .claude/scheduled_tasks.json — they die with the process. Typed via
141
+ // SessionCronTask below (not importing from cronTasks.ts keeps
142
+ // bootstrap a leaf of the import DAG).
143
+ sessionCronTasks: SessionCronTask[]
144
+ // Teams created this session via TeamCreate. cleanupSessionTeams()
145
+ // removes these on gracefulShutdown so subagent-created teams don't
146
+ // persist on disk forever (gh-32730). TeamDelete removes entries to
147
+ // avoid double-cleanup. Lives here (not teamHelpers.ts) so
148
+ // resetStateForTests() clears it between tests.
149
+ sessionCreatedTeams: Set<string>
150
+ // Session-only trust flag for home directory (not persisted to disk)
151
+ // When running from home dir, trust dialog is shown but not saved to disk.
152
+ // This flag allows features requiring trust to work during the session.
153
+ sessionTrustAccepted: boolean
154
+ // Session-only flag to disable session persistence to disk
155
+ sessionPersistenceDisabled: boolean
156
+ // Track if user has exited plan mode in this session (for re-entry guidance)
157
+ hasExitedPlanMode: boolean
158
+ // Track if we need to show the plan mode exit attachment (one-time notification)
159
+ needsPlanModeExitAttachment: boolean
160
+ // Track if we need to show the auto mode exit attachment (one-time notification)
161
+ needsAutoModeExitAttachment: boolean
162
+ // Track if LSP plugin recommendation has been shown this session (only show once)
163
+ lspRecommendationShownThisSession: boolean
164
+ // SDK init event state - jsonSchema for structured output
165
+ initJsonSchema: Record<string, unknown> | null
166
+ // Registered hooks - SDK callbacks and plugin native hooks
167
+ registeredHooks: Partial<Record<HookEvent, RegisteredHookMatcher[]>> | null
168
+ // Cache for plan slugs: sessionId -> wordSlug
169
+ planSlugCache: Map<string, string>
170
+ // Track teleported session for reliability logging
171
+ teleportedSessionInfo: {
172
+ isTeleported: boolean
173
+ hasLoggedFirstMessage: boolean
174
+ sessionId: string | null
175
+ } | null
176
+ // Track invoked skills for preservation across compaction
177
+ // Keys are composite: `${agentId ?? ''}:${skillName}` to prevent cross-agent overwrites
178
+ invokedSkills: Map<
179
+ string,
180
+ {
181
+ skillName: string
182
+ skillPath: string
183
+ content: string
184
+ invokedAt: number
185
+ agentId: string | null
186
+ }
187
+ >
188
+ // Track slow operations for dev bar display (ant-only)
189
+ slowOperations: Array<{
190
+ operation: string
191
+ durationMs: number
192
+ timestamp: number
193
+ }>
194
+ // SDK-provided betas (e.g., context-1m-2025-08-07)
195
+ sdkBetas: string[] | undefined
196
+ // Main thread agent type (from --agent flag or settings)
197
+ mainThreadAgentType: string | undefined
198
+ // Remote mode (--remote flag)
199
+ isRemoteMode: boolean
200
+ // Direct connect server URL (for display in header)
201
+ directConnectServerUrl: string | undefined
202
+ // System prompt section cache state
203
+ systemPromptSectionCache: Map<string, string | null>
204
+ // Last date emitted to the model (for detecting midnight date changes)
205
+ lastEmittedDate: string | null
206
+ // Additional directories from --add-dir flag (for CLAUDE.md loading)
207
+ additionalDirectoriesForClaudeMd: string[]
208
+ // Channel server allowlist from --channels flag (servers whose channel
209
+ // notifications should register this session). Parsed once in main.tsx —
210
+ // the tag decides trust model: 'plugin' → marketplace verification +
211
+ // allowlist, 'server' → allowlist always fails (schema is plugin-only).
212
+ // Either kind needs entry.dev to bypass allowlist.
213
+ allowedChannels: ChannelEntry[]
214
+ // True if any entry in allowedChannels came from
215
+ // --dangerously-load-development-channels (so ChannelsNotice can name the
216
+ // right flag in policy-blocked messages)
217
+ hasDevChannels: boolean
218
+ // Dir containing the session's `.jsonl`; null = derive from originalCwd.
219
+ sessionProjectDir: string | null
220
+ // Cached prompt cache 1h TTL allowlist from GrowthBook (session-stable)
221
+ promptCache1hAllowlist: string[] | null
222
+ // Cached 1h TTL user eligibility (session-stable). Latched on first
223
+ // evaluation so mid-session overage flips don't change the cache_control
224
+ // TTL, which would bust the server-side prompt cache.
225
+ promptCache1hEligible: boolean | null
226
+ // Sticky-on latch for AFK_MODE_BETA_HEADER. Once auto mode is first
227
+ // activated, keep sending the header for the rest of the session so
228
+ // Shift+Tab toggles don't bust the ~50-70K token prompt cache.
229
+ afkModeHeaderLatched: boolean | null
230
+ // Sticky-on latch for FAST_MODE_BETA_HEADER. Once fast mode is first
231
+ // enabled, keep sending the header so cooldown enter/exit doesn't
232
+ // double-bust the prompt cache. The `speed` body param stays dynamic.
233
+ fastModeHeaderLatched: boolean | null
234
+ // Sticky-on latch for the cache-editing beta header. Once cached
235
+ // microcompact is first enabled, keep sending the header so mid-session
236
+ // GrowthBook/settings toggles don't bust the prompt cache.
237
+ cacheEditingHeaderLatched: boolean | null
238
+ // Sticky-on latch for clearing thinking from prior tool loops. Triggered
239
+ // when >1h since last API call (confirmed cache miss — no cache-hit
240
+ // benefit to keeping thinking). Once latched, stays on so the newly-warmed
241
+ // thinking-cleared cache isn't busted by flipping back to keep:'all'.
242
+ thinkingClearLatched: boolean | null
243
+ // Current prompt ID (UUID) correlating a user prompt with subsequent OTel events
244
+ promptId: string | null
245
+ // Last API requestId for the main conversation chain (not subagents).
246
+ // Updated after each successful API response for main-session queries.
247
+ // Read at shutdown to send cache eviction hints to inference.
248
+ lastMainRequestId: string | undefined
249
+ // Timestamp (Date.now()) of the last successful API call completion.
250
+ // Used to compute timeSinceLastApiCallMs in tengu_api_success for
251
+ // correlating cache misses with idle time (cache TTL is ~5min).
252
+ lastApiCompletionTimestamp: number | null
253
+ // Set to true after compaction (auto or manual /compact). Consumed by
254
+ // logAPISuccess to tag the first post-compaction API call so we can
255
+ // distinguish compaction-induced cache misses from TTL expiry.
256
+ pendingPostCompaction: boolean
257
+ }
258
+
259
+ // ALSO HERE - THINK THRICE BEFORE MODIFYING
260
+ function getInitialState(): State {
261
+ // Resolve symlinks in cwd to match behavior of shell.ts setCwd
262
+ // This ensures consistency with how paths are sanitized for session storage
263
+ let resolvedCwd = ''
264
+ if (
265
+ typeof process !== 'undefined' &&
266
+ typeof process.cwd === 'function' &&
267
+ typeof realpathSync === 'function'
268
+ ) {
269
+ const rawCwd = cwd()
270
+ try {
271
+ resolvedCwd = realpathSync(rawCwd).normalize('NFC')
272
+ } catch {
273
+ // File Provider EPERM on CloudStorage mounts (lstat per path component).
274
+ resolvedCwd = rawCwd.normalize('NFC')
275
+ }
276
+ }
277
+ const state: State = {
278
+ originalCwd: resolvedCwd,
279
+ projectRoot: resolvedCwd,
280
+ totalCostUSD: 0,
281
+ totalAPIDuration: 0,
282
+ totalAPIDurationWithoutRetries: 0,
283
+ totalToolDuration: 0,
284
+ turnHookDurationMs: 0,
285
+ turnToolDurationMs: 0,
286
+ turnClassifierDurationMs: 0,
287
+ turnToolCount: 0,
288
+ turnHookCount: 0,
289
+ turnClassifierCount: 0,
290
+ startTime: Date.now(),
291
+ lastInteractionTime: Date.now(),
292
+ totalLinesAdded: 0,
293
+ totalLinesRemoved: 0,
294
+ hasUnknownModelCost: false,
295
+ cwd: resolvedCwd,
296
+ modelUsage: {},
297
+ mainLoopModelOverride: undefined,
298
+ initialMainLoopModel: null,
299
+ modelStrings: null,
300
+ isInteractive: false,
301
+ kairosActive: false,
302
+ strictToolResultPairing: false,
303
+ sdkAgentProgressSummariesEnabled: false,
304
+ userMsgOptIn: false,
305
+ clientType: 'cli',
306
+ sessionSource: undefined,
307
+ questionPreviewFormat: undefined,
308
+ sessionIngressToken: undefined,
309
+ oauthTokenFromFd: undefined,
310
+ apiKeyFromFd: undefined,
311
+ flagSettingsPath: undefined,
312
+ flagSettingsInline: null,
313
+ allowedSettingSources: [
314
+ 'userSettings',
315
+ 'projectSettings',
316
+ 'localSettings',
317
+ 'flagSettings',
318
+ 'policySettings',
319
+ ],
320
+ // Telemetry state
321
+ meter: null,
322
+ sessionCounter: null,
323
+ locCounter: null,
324
+ prCounter: null,
325
+ commitCounter: null,
326
+ costCounter: null,
327
+ tokenCounter: null,
328
+ codeEditToolDecisionCounter: null,
329
+ activeTimeCounter: null,
330
+ statsStore: null,
331
+ sessionId: randomUUID() as SessionId,
332
+ parentSessionId: undefined,
333
+ // Logger state
334
+ loggerProvider: null,
335
+ eventLogger: null,
336
+ // Meter provider state
337
+ meterProvider: null,
338
+ tracerProvider: null,
339
+ // Agent color state
340
+ agentColorMap: new Map(),
341
+ agentColorIndex: 0,
342
+ // Last API request for bug reports
343
+ lastAPIRequest: null,
344
+ lastAPIRequestMessages: null,
345
+ // Last auto-mode classifier request(s) for /share transcript
346
+ lastClassifierRequests: null,
347
+ cachedClaudeMdContent: null,
348
+ // In-memory error log for recent errors
349
+ inMemoryErrorLog: [],
350
+ // Session-only plugins from --plugin-dir flag
351
+ inlinePlugins: [],
352
+ // Explicit --chrome / --no-chrome flag value (undefined = not set on CLI)
353
+ chromeFlagOverride: undefined,
354
+ // Use cowork_plugins directory instead of plugins
355
+ useCoworkPlugins: false,
356
+ // Session-only bypass permissions mode flag (not persisted)
357
+ sessionBypassPermissionsMode: false,
358
+ // Scheduled tasks disabled until flag or dialog enables them
359
+ scheduledTasksEnabled: false,
360
+ sessionCronTasks: [],
361
+ sessionCreatedTeams: new Set(),
362
+ // Session-only trust flag (not persisted to disk)
363
+ sessionTrustAccepted: false,
364
+ // Session-only flag to disable session persistence to disk
365
+ sessionPersistenceDisabled: false,
366
+ // Track if user has exited plan mode in this session
367
+ hasExitedPlanMode: false,
368
+ // Track if we need to show the plan mode exit attachment
369
+ needsPlanModeExitAttachment: false,
370
+ // Track if we need to show the auto mode exit attachment
371
+ needsAutoModeExitAttachment: false,
372
+ // Track if LSP plugin recommendation has been shown this session
373
+ lspRecommendationShownThisSession: false,
374
+ // SDK init event state
375
+ initJsonSchema: null,
376
+ registeredHooks: null,
377
+ // Cache for plan slugs
378
+ planSlugCache: new Map(),
379
+ // Track teleported session for reliability logging
380
+ teleportedSessionInfo: null,
381
+ // Track invoked skills for preservation across compaction
382
+ invokedSkills: new Map(),
383
+ // Track slow operations for dev bar display
384
+ slowOperations: [],
385
+ // SDK-provided betas
386
+ sdkBetas: undefined,
387
+ // Main thread agent type
388
+ mainThreadAgentType: undefined,
389
+ // Remote mode
390
+ isRemoteMode: false,
391
+ ...(process.env.USER_TYPE === 'ant'
392
+ ? {
393
+ replBridgeActive: false,
394
+ }
395
+ : {}),
396
+ // Direct connect server URL
397
+ directConnectServerUrl: undefined,
398
+ // System prompt section cache state
399
+ systemPromptSectionCache: new Map(),
400
+ // Last date emitted to the model
401
+ lastEmittedDate: null,
402
+ // Additional directories from --add-dir flag (for CLAUDE.md loading)
403
+ additionalDirectoriesForClaudeMd: [],
404
+ // Channel server allowlist from --channels flag
405
+ allowedChannels: [],
406
+ hasDevChannels: false,
407
+ // Session project dir (null = derive from originalCwd)
408
+ sessionProjectDir: null,
409
+ // Prompt cache 1h allowlist (null = not yet fetched from GrowthBook)
410
+ promptCache1hAllowlist: null,
411
+ // Prompt cache 1h eligibility (null = not yet evaluated)
412
+ promptCache1hEligible: null,
413
+ // Beta header latches (null = not yet triggered)
414
+ afkModeHeaderLatched: null,
415
+ fastModeHeaderLatched: null,
416
+ cacheEditingHeaderLatched: null,
417
+ thinkingClearLatched: null,
418
+ // Current prompt ID
419
+ promptId: null,
420
+ lastMainRequestId: undefined,
421
+ lastApiCompletionTimestamp: null,
422
+ pendingPostCompaction: false,
423
+ }
424
+
425
+ return state
426
+ }
427
+
428
+ // AND ESPECIALLY HERE
429
+ const STATE: State = getInitialState()
430
+
431
+ export function getSessionId(): SessionId {
432
+ return STATE.sessionId
433
+ }
434
+
435
+ export function regenerateSessionId(
436
+ options: { setCurrentAsParent?: boolean } = {},
437
+ ): SessionId {
438
+ if (options.setCurrentAsParent) {
439
+ STATE.parentSessionId = STATE.sessionId
440
+ }
441
+ // Drop the outgoing session's plan-slug entry so the Map doesn't
442
+ // accumulate stale keys. Callers that need to carry the slug across
443
+ // (REPL.tsx clearContext) read it before calling clearConversation.
444
+ STATE.planSlugCache.delete(STATE.sessionId)
445
+ // Regenerated sessions live in the current project: reset projectDir to
446
+ // null so getTranscriptPath() derives from originalCwd.
447
+ STATE.sessionId = randomUUID() as SessionId
448
+ STATE.sessionProjectDir = null
449
+ return STATE.sessionId
450
+ }
451
+
452
+ export function getParentSessionId(): SessionId | undefined {
453
+ return STATE.parentSessionId
454
+ }
455
+
456
+ /**
457
+ * Atomically switch the active session. `sessionId` and `sessionProjectDir`
458
+ * always change together — there is no separate setter for either, so they
459
+ * cannot drift out of sync (CC-34).
460
+ *
461
+ * @param projectDir — directory containing `<sessionId>.jsonl`. Omit (or
462
+ * pass `null`) for sessions in the current project — the path will derive
463
+ * from originalCwd at read time. Pass `dirname(transcriptPath)` when the
464
+ * session lives in a different project directory (git worktrees,
465
+ * cross-project resume). Every call resets the project dir; it never
466
+ * carries over from the previous session.
467
+ */
468
+ export function switchSession(
469
+ sessionId: SessionId,
470
+ projectDir: string | null = null,
471
+ ): void {
472
+ // Drop the outgoing session's plan-slug entry so the Map stays bounded
473
+ // across repeated /resume. Only the current session's slug is ever read
474
+ // (plans.ts getPlanSlug defaults to getSessionId()).
475
+ STATE.planSlugCache.delete(STATE.sessionId)
476
+ STATE.sessionId = sessionId
477
+ STATE.sessionProjectDir = projectDir
478
+ sessionSwitched.emit(sessionId)
479
+ }
480
+
481
+ const sessionSwitched = createSignal<[id: SessionId]>()
482
+
483
+ /**
484
+ * Register a callback that fires when switchSession changes the active
485
+ * sessionId. bootstrap can't import listeners directly (DAG leaf), so
486
+ * callers register themselves. concurrentSessions.ts uses this to keep the
487
+ * PID file's sessionId in sync with --resume.
488
+ */
489
+ export const onSessionSwitch = sessionSwitched.subscribe
490
+
491
+ /**
492
+ * Project directory the current session's transcript lives in, or `null` if
493
+ * the session was created in the current project (common case — derive from
494
+ * originalCwd). See `switchSession()`.
495
+ */
496
+ export function getSessionProjectDir(): string | null {
497
+ return STATE.sessionProjectDir
498
+ }
499
+
500
+ export function getOriginalCwd(): string {
501
+ return STATE.originalCwd
502
+ }
503
+
504
+ /**
505
+ * Get the stable project root directory.
506
+ * Unlike getOriginalCwd(), this is never updated by mid-session EnterWorktreeTool
507
+ * (so skills/history stay stable when entering a throwaway worktree).
508
+ * It IS set at startup by --worktree, since that worktree is the session's project.
509
+ * Use for project identity (history, skills, sessions) not file operations.
510
+ */
511
+ export function getProjectRoot(): string {
512
+ return STATE.projectRoot
513
+ }
514
+
515
+ export function setOriginalCwd(cwd: string): void {
516
+ STATE.originalCwd = cwd.normalize('NFC')
517
+ }
518
+
519
+ /**
520
+ * Only for --worktree startup flag. Mid-session EnterWorktreeTool must NOT
521
+ * call this — skills/history should stay anchored to where the session started.
522
+ */
523
+ export function setProjectRoot(cwd: string): void {
524
+ STATE.projectRoot = cwd.normalize('NFC')
525
+ }
526
+
527
+ export function getCwdState(): string {
528
+ return STATE.cwd
529
+ }
530
+
531
+ export function setCwdState(cwd: string): void {
532
+ STATE.cwd = cwd.normalize('NFC')
533
+ }
534
+
535
+ export function getDirectConnectServerUrl(): string | undefined {
536
+ return STATE.directConnectServerUrl
537
+ }
538
+
539
+ export function setDirectConnectServerUrl(url: string): void {
540
+ STATE.directConnectServerUrl = url
541
+ }
542
+
543
+ export function addToTotalDurationState(
544
+ duration: number,
545
+ durationWithoutRetries: number,
546
+ ): void {
547
+ STATE.totalAPIDuration += duration
548
+ STATE.totalAPIDurationWithoutRetries += durationWithoutRetries
549
+ }
550
+
551
+ export function resetTotalDurationStateAndCost_FOR_TESTS_ONLY(): void {
552
+ STATE.totalAPIDuration = 0
553
+ STATE.totalAPIDurationWithoutRetries = 0
554
+ STATE.totalCostUSD = 0
555
+ }
556
+
557
+ export function addToTotalCostState(
558
+ cost: number,
559
+ modelUsage: ModelUsage,
560
+ model: string,
561
+ ): void {
562
+ STATE.modelUsage[model] = modelUsage
563
+ STATE.totalCostUSD += cost
564
+ }
565
+
566
+ export function getTotalCostUSD(): number {
567
+ return STATE.totalCostUSD
568
+ }
569
+
570
+ export function getTotalAPIDuration(): number {
571
+ return STATE.totalAPIDuration
572
+ }
573
+
574
+ export function getTotalDuration(): number {
575
+ return Date.now() - STATE.startTime
576
+ }
577
+
578
+ export function getTotalAPIDurationWithoutRetries(): number {
579
+ return STATE.totalAPIDurationWithoutRetries
580
+ }
581
+
582
+ export function getTotalToolDuration(): number {
583
+ return STATE.totalToolDuration
584
+ }
585
+
586
+ export function addToToolDuration(duration: number): void {
587
+ STATE.totalToolDuration += duration
588
+ STATE.turnToolDurationMs += duration
589
+ STATE.turnToolCount++
590
+ }
591
+
592
+ export function getTurnHookDurationMs(): number {
593
+ return STATE.turnHookDurationMs
594
+ }
595
+
596
+ export function addToTurnHookDuration(duration: number): void {
597
+ STATE.turnHookDurationMs += duration
598
+ STATE.turnHookCount++
599
+ }
600
+
601
+ export function resetTurnHookDuration(): void {
602
+ STATE.turnHookDurationMs = 0
603
+ STATE.turnHookCount = 0
604
+ }
605
+
606
+ export function getTurnHookCount(): number {
607
+ return STATE.turnHookCount
608
+ }
609
+
610
+ export function getTurnToolDurationMs(): number {
611
+ return STATE.turnToolDurationMs
612
+ }
613
+
614
+ export function resetTurnToolDuration(): void {
615
+ STATE.turnToolDurationMs = 0
616
+ STATE.turnToolCount = 0
617
+ }
618
+
619
+ export function getTurnToolCount(): number {
620
+ return STATE.turnToolCount
621
+ }
622
+
623
+ export function getTurnClassifierDurationMs(): number {
624
+ return STATE.turnClassifierDurationMs
625
+ }
626
+
627
+ export function addToTurnClassifierDuration(duration: number): void {
628
+ STATE.turnClassifierDurationMs += duration
629
+ STATE.turnClassifierCount++
630
+ }
631
+
632
+ export function resetTurnClassifierDuration(): void {
633
+ STATE.turnClassifierDurationMs = 0
634
+ STATE.turnClassifierCount = 0
635
+ }
636
+
637
+ export function getTurnClassifierCount(): number {
638
+ return STATE.turnClassifierCount
639
+ }
640
+
641
+ export function getStatsStore(): {
642
+ observe(name: string, value: number): void
643
+ } | null {
644
+ return STATE.statsStore
645
+ }
646
+
647
+ export function setStatsStore(
648
+ store: { observe(name: string, value: number): void } | null,
649
+ ): void {
650
+ STATE.statsStore = store
651
+ }
652
+
653
+ /**
654
+ * Marks that an interaction occurred.
655
+ *
656
+ * By default the actual Date.now() call is deferred until the next Ink render
657
+ * frame (via flushInteractionTime()) so we avoid calling Date.now() on every
658
+ * single keypress.
659
+ *
660
+ * Pass `immediate = true` when calling from React useEffect callbacks or
661
+ * other code that runs *after* the Ink render cycle has already flushed.
662
+ * Without it the timestamp stays stale until the next render, which may never
663
+ * come if the user is idle (e.g. permission dialog waiting for input).
664
+ */
665
+ let interactionTimeDirty = false
666
+
667
+ export function updateLastInteractionTime(immediate?: boolean): void {
668
+ if (immediate) {
669
+ flushInteractionTime_inner()
670
+ } else {
671
+ interactionTimeDirty = true
672
+ }
673
+ }
674
+
675
+ /**
676
+ * If an interaction was recorded since the last flush, update the timestamp
677
+ * now. Called by Ink before each render cycle so we batch many keypresses into
678
+ * a single Date.now() call.
679
+ */
680
+ export function flushInteractionTime(): void {
681
+ if (interactionTimeDirty) {
682
+ flushInteractionTime_inner()
683
+ }
684
+ }
685
+
686
+ function flushInteractionTime_inner(): void {
687
+ STATE.lastInteractionTime = Date.now()
688
+ interactionTimeDirty = false
689
+ }
690
+
691
+ export function addToTotalLinesChanged(added: number, removed: number): void {
692
+ STATE.totalLinesAdded += added
693
+ STATE.totalLinesRemoved += removed
694
+ }
695
+
696
+ export function getTotalLinesAdded(): number {
697
+ return STATE.totalLinesAdded
698
+ }
699
+
700
+ export function getTotalLinesRemoved(): number {
701
+ return STATE.totalLinesRemoved
702
+ }
703
+
704
+ export function getTotalInputTokens(): number {
705
+ return sumBy(Object.values(STATE.modelUsage), 'inputTokens')
706
+ }
707
+
708
+ export function getTotalOutputTokens(): number {
709
+ return sumBy(Object.values(STATE.modelUsage), 'outputTokens')
710
+ }
711
+
712
+ export function getTotalCacheReadInputTokens(): number {
713
+ return sumBy(Object.values(STATE.modelUsage), 'cacheReadInputTokens')
714
+ }
715
+
716
+ export function getTotalCacheCreationInputTokens(): number {
717
+ return sumBy(Object.values(STATE.modelUsage), 'cacheCreationInputTokens')
718
+ }
719
+
720
+ export function getTotalWebSearchRequests(): number {
721
+ return sumBy(Object.values(STATE.modelUsage), 'webSearchRequests')
722
+ }
723
+
724
+ let outputTokensAtTurnStart = 0
725
+ let currentTurnTokenBudget: number | null = null
726
+ export function getTurnOutputTokens(): number {
727
+ return getTotalOutputTokens() - outputTokensAtTurnStart
728
+ }
729
+ export function getCurrentTurnTokenBudget(): number | null {
730
+ return currentTurnTokenBudget
731
+ }
732
+ let budgetContinuationCount = 0
733
+ export function snapshotOutputTokensForTurn(budget: number | null): void {
734
+ outputTokensAtTurnStart = getTotalOutputTokens()
735
+ currentTurnTokenBudget = budget
736
+ budgetContinuationCount = 0
737
+ }
738
+ export function getBudgetContinuationCount(): number {
739
+ return budgetContinuationCount
740
+ }
741
+ export function incrementBudgetContinuationCount(): void {
742
+ budgetContinuationCount++
743
+ }
744
+
745
+ export function setHasUnknownModelCost(): void {
746
+ STATE.hasUnknownModelCost = true
747
+ }
748
+
749
+ export function hasUnknownModelCost(): boolean {
750
+ return STATE.hasUnknownModelCost
751
+ }
752
+
753
+ export function getLastMainRequestId(): string | undefined {
754
+ return STATE.lastMainRequestId
755
+ }
756
+
757
+ export function setLastMainRequestId(requestId: string): void {
758
+ STATE.lastMainRequestId = requestId
759
+ }
760
+
761
+ export function getLastApiCompletionTimestamp(): number | null {
762
+ return STATE.lastApiCompletionTimestamp
763
+ }
764
+
765
+ export function setLastApiCompletionTimestamp(timestamp: number): void {
766
+ STATE.lastApiCompletionTimestamp = timestamp
767
+ }
768
+
769
+ /** Mark that a compaction just occurred. The next API success event will
770
+ * include isPostCompaction=true, then the flag auto-resets. */
771
+ export function markPostCompaction(): void {
772
+ STATE.pendingPostCompaction = true
773
+ }
774
+
775
+ /** Consume the post-compaction flag. Returns true once after compaction,
776
+ * then returns false until the next compaction. */
777
+ export function consumePostCompaction(): boolean {
778
+ const was = STATE.pendingPostCompaction
779
+ STATE.pendingPostCompaction = false
780
+ return was
781
+ }
782
+
783
+ export function getLastInteractionTime(): number {
784
+ return STATE.lastInteractionTime
785
+ }
786
+
787
+ // Scroll drain suspension — background intervals check this before doing work
788
+ // so they don't compete with scroll frames for the event loop. Set by
789
+ // ScrollBox scrollBy/scrollTo, cleared SCROLL_DRAIN_IDLE_MS after the last
790
+ // scroll event. Module-scope (not in STATE) — ephemeral hot-path flag, no
791
+ // test-reset needed since the debounce timer self-clears.
792
+ let scrollDraining = false
793
+ let scrollDrainTimer: ReturnType<typeof setTimeout> | undefined
794
+ const SCROLL_DRAIN_IDLE_MS = 150
795
+
796
+ /** Mark that a scroll event just happened. Background intervals gate on
797
+ * getIsScrollDraining() and skip their work until the debounce clears. */
798
+ export function markScrollActivity(): void {
799
+ scrollDraining = true
800
+ if (scrollDrainTimer) clearTimeout(scrollDrainTimer)
801
+ scrollDrainTimer = setTimeout(() => {
802
+ scrollDraining = false
803
+ scrollDrainTimer = undefined
804
+ }, SCROLL_DRAIN_IDLE_MS)
805
+ scrollDrainTimer.unref?.()
806
+ }
807
+
808
+ /** True while scroll is actively draining (within 150ms of last event).
809
+ * Intervals should early-return when this is set — the work picks up next
810
+ * tick after scroll settles. */
811
+ export function getIsScrollDraining(): boolean {
812
+ return scrollDraining
813
+ }
814
+
815
+ /** Await this before expensive one-shot work (network, subprocess) that could
816
+ * coincide with scroll. Resolves immediately if not scrolling; otherwise
817
+ * polls at the idle interval until the flag clears. */
818
+ export async function waitForScrollIdle(): Promise<void> {
819
+ while (scrollDraining) {
820
+ // bootstrap-isolation forbids importing sleep() from src/utils/
821
+ // eslint-disable-next-line no-restricted-syntax
822
+ await new Promise(r => setTimeout(r, SCROLL_DRAIN_IDLE_MS).unref?.())
823
+ }
824
+ }
825
+
826
+ export function getModelUsage(): { [modelName: string]: ModelUsage } {
827
+ return STATE.modelUsage
828
+ }
829
+
830
+ export function getUsageForModel(model: string): ModelUsage | undefined {
831
+ return STATE.modelUsage[model]
832
+ }
833
+
834
+ /**
835
+ * Gets the model override set from the --model CLI flag or after the user
836
+ * updates their configured model.
837
+ */
838
+ export function getMainLoopModelOverride(): ModelSetting | undefined {
839
+ return STATE.mainLoopModelOverride
840
+ }
841
+
842
+ export function getInitialMainLoopModel(): ModelSetting {
843
+ return STATE.initialMainLoopModel
844
+ }
845
+
846
+ export function setMainLoopModelOverride(
847
+ model: ModelSetting | undefined,
848
+ ): void {
849
+ STATE.mainLoopModelOverride = model
850
+ }
851
+
852
+ export function setInitialMainLoopModel(model: ModelSetting): void {
853
+ STATE.initialMainLoopModel = model
854
+ }
855
+
856
+ export function getSdkBetas(): string[] | undefined {
857
+ return STATE.sdkBetas
858
+ }
859
+
860
+ export function setSdkBetas(betas: string[] | undefined): void {
861
+ STATE.sdkBetas = betas
862
+ }
863
+
864
+ export function resetCostState(): void {
865
+ STATE.totalCostUSD = 0
866
+ STATE.totalAPIDuration = 0
867
+ STATE.totalAPIDurationWithoutRetries = 0
868
+ STATE.totalToolDuration = 0
869
+ STATE.startTime = Date.now()
870
+ STATE.totalLinesAdded = 0
871
+ STATE.totalLinesRemoved = 0
872
+ STATE.hasUnknownModelCost = false
873
+ STATE.modelUsage = {}
874
+ STATE.promptId = null
875
+ }
876
+
877
+ /**
878
+ * Sets cost state values for session restore.
879
+ * Called by restoreCostStateForSession in cost-tracker.ts.
880
+ */
881
+ export function setCostStateForRestore({
882
+ totalCostUSD,
883
+ totalAPIDuration,
884
+ totalAPIDurationWithoutRetries,
885
+ totalToolDuration,
886
+ totalLinesAdded,
887
+ totalLinesRemoved,
888
+ lastDuration,
889
+ modelUsage,
890
+ }: {
891
+ totalCostUSD: number
892
+ totalAPIDuration: number
893
+ totalAPIDurationWithoutRetries: number
894
+ totalToolDuration: number
895
+ totalLinesAdded: number
896
+ totalLinesRemoved: number
897
+ lastDuration: number | undefined
898
+ modelUsage: { [modelName: string]: ModelUsage } | undefined
899
+ }): void {
900
+ STATE.totalCostUSD = totalCostUSD
901
+ STATE.totalAPIDuration = totalAPIDuration
902
+ STATE.totalAPIDurationWithoutRetries = totalAPIDurationWithoutRetries
903
+ STATE.totalToolDuration = totalToolDuration
904
+ STATE.totalLinesAdded = totalLinesAdded
905
+ STATE.totalLinesRemoved = totalLinesRemoved
906
+
907
+ // Restore per-model usage breakdown
908
+ if (modelUsage) {
909
+ STATE.modelUsage = modelUsage
910
+ }
911
+
912
+ // Adjust startTime to make wall duration accumulate
913
+ if (lastDuration) {
914
+ STATE.startTime = Date.now() - lastDuration
915
+ }
916
+ }
917
+
918
+ // Only used in tests
919
+ export function resetStateForTests(): void {
920
+ if (process.env.NODE_ENV !== 'test') {
921
+ throw new Error('resetStateForTests can only be called in tests')
922
+ }
923
+ Object.entries(getInitialState()).forEach(([key, value]) => {
924
+ STATE[key as keyof State] = value as never
925
+ })
926
+ outputTokensAtTurnStart = 0
927
+ currentTurnTokenBudget = null
928
+ budgetContinuationCount = 0
929
+ sessionSwitched.clear()
930
+ }
931
+
932
+ // You shouldn't use this directly. See src/utils/model/modelStrings.ts::getModelStrings()
933
+ export function getModelStrings(): ModelStrings | null {
934
+ return STATE.modelStrings
935
+ }
936
+
937
+ // You shouldn't use this directly. See src/utils/model/modelStrings.ts
938
+ export function setModelStrings(modelStrings: ModelStrings): void {
939
+ STATE.modelStrings = modelStrings
940
+ }
941
+
942
+ // Test utility function to reset model strings for re-initialization.
943
+ // Separate from setModelStrings because we only want to accept 'null' in tests.
944
+ export function resetModelStringsForTestingOnly() {
945
+ STATE.modelStrings = null
946
+ }
947
+
948
+ export function setMeter(
949
+ meter: Meter,
950
+ createCounter: (name: string, options: MetricOptions) => AttributedCounter,
951
+ ): void {
952
+ STATE.meter = meter
953
+
954
+ // Initialize all counters using the provided factory
955
+ STATE.sessionCounter = createCounter('claude_code.session.count', {
956
+ description: 'Count of CLI sessions started',
957
+ })
958
+ STATE.locCounter = createCounter('claude_code.lines_of_code.count', {
959
+ description:
960
+ "Count of lines of code modified, with the 'type' attribute indicating whether lines were added or removed",
961
+ })
962
+ STATE.prCounter = createCounter('claude_code.pull_request.count', {
963
+ description: 'Number of pull requests created',
964
+ })
965
+ STATE.commitCounter = createCounter('claude_code.commit.count', {
966
+ description: 'Number of git commits created',
967
+ })
968
+ STATE.costCounter = createCounter('claude_code.cost.usage', {
969
+ description: 'Cost of the Claude Code session',
970
+ unit: 'USD',
971
+ })
972
+ STATE.tokenCounter = createCounter('claude_code.token.usage', {
973
+ description: 'Number of tokens used',
974
+ unit: 'tokens',
975
+ })
976
+ STATE.codeEditToolDecisionCounter = createCounter(
977
+ 'claude_code.code_edit_tool.decision',
978
+ {
979
+ description:
980
+ 'Count of code editing tool permission decisions (accept/reject) for Edit, Write, and NotebookEdit tools',
981
+ },
982
+ )
983
+ STATE.activeTimeCounter = createCounter('claude_code.active_time.total', {
984
+ description: 'Total active time in seconds',
985
+ unit: 's',
986
+ })
987
+ }
988
+
989
+ export function getMeter(): Meter | null {
990
+ return STATE.meter
991
+ }
992
+
993
+ export function getSessionCounter(): AttributedCounter | null {
994
+ return STATE.sessionCounter
995
+ }
996
+
997
+ export function getLocCounter(): AttributedCounter | null {
998
+ return STATE.locCounter
999
+ }
1000
+
1001
+ export function getPrCounter(): AttributedCounter | null {
1002
+ return STATE.prCounter
1003
+ }
1004
+
1005
+ export function getCommitCounter(): AttributedCounter | null {
1006
+ return STATE.commitCounter
1007
+ }
1008
+
1009
+ export function getCostCounter(): AttributedCounter | null {
1010
+ return STATE.costCounter
1011
+ }
1012
+
1013
+ export function getTokenCounter(): AttributedCounter | null {
1014
+ return STATE.tokenCounter
1015
+ }
1016
+
1017
+ export function getCodeEditToolDecisionCounter(): AttributedCounter | null {
1018
+ return STATE.codeEditToolDecisionCounter
1019
+ }
1020
+
1021
+ export function getActiveTimeCounter(): AttributedCounter | null {
1022
+ return STATE.activeTimeCounter
1023
+ }
1024
+
1025
+ export function getLoggerProvider(): LoggerProvider | null {
1026
+ return STATE.loggerProvider
1027
+ }
1028
+
1029
+ export function setLoggerProvider(provider: LoggerProvider | null): void {
1030
+ STATE.loggerProvider = provider
1031
+ }
1032
+
1033
+ export function getEventLogger(): ReturnType<typeof logs.getLogger> | null {
1034
+ return STATE.eventLogger
1035
+ }
1036
+
1037
+ export function setEventLogger(
1038
+ logger: ReturnType<typeof logs.getLogger> | null,
1039
+ ): void {
1040
+ STATE.eventLogger = logger
1041
+ }
1042
+
1043
+ export function getMeterProvider(): MeterProvider | null {
1044
+ return STATE.meterProvider
1045
+ }
1046
+
1047
+ export function setMeterProvider(provider: MeterProvider | null): void {
1048
+ STATE.meterProvider = provider
1049
+ }
1050
+ export function getTracerProvider(): BasicTracerProvider | null {
1051
+ return STATE.tracerProvider
1052
+ }
1053
+ export function setTracerProvider(provider: BasicTracerProvider | null): void {
1054
+ STATE.tracerProvider = provider
1055
+ }
1056
+
1057
+ export function getIsNonInteractiveSession(): boolean {
1058
+ return !STATE.isInteractive
1059
+ }
1060
+
1061
+ export function getIsInteractive(): boolean {
1062
+ return STATE.isInteractive
1063
+ }
1064
+
1065
+ export function setIsInteractive(value: boolean): void {
1066
+ STATE.isInteractive = value
1067
+ }
1068
+
1069
+ export function getClientType(): string {
1070
+ return STATE.clientType
1071
+ }
1072
+
1073
+ export function setClientType(type: string): void {
1074
+ STATE.clientType = type
1075
+ }
1076
+
1077
+ export function getSdkAgentProgressSummariesEnabled(): boolean {
1078
+ return STATE.sdkAgentProgressSummariesEnabled
1079
+ }
1080
+
1081
+ export function setSdkAgentProgressSummariesEnabled(value: boolean): void {
1082
+ STATE.sdkAgentProgressSummariesEnabled = value
1083
+ }
1084
+
1085
+ export function getKairosActive(): boolean {
1086
+ return STATE.kairosActive
1087
+ }
1088
+
1089
+ export function setKairosActive(value: boolean): void {
1090
+ STATE.kairosActive = value
1091
+ }
1092
+
1093
+ export function getStrictToolResultPairing(): boolean {
1094
+ return STATE.strictToolResultPairing
1095
+ }
1096
+
1097
+ export function setStrictToolResultPairing(value: boolean): void {
1098
+ STATE.strictToolResultPairing = value
1099
+ }
1100
+
1101
+ // Field name 'userMsgOptIn' avoids excluded-string substrings ('BriefTool',
1102
+ // 'SendUserMessage' — case-insensitive). All callers are inside feature()
1103
+ // guards so these accessors don't need their own (matches getKairosActive).
1104
+ export function getUserMsgOptIn(): boolean {
1105
+ return STATE.userMsgOptIn
1106
+ }
1107
+
1108
+ export function setUserMsgOptIn(value: boolean): void {
1109
+ STATE.userMsgOptIn = value
1110
+ }
1111
+
1112
+ export function getSessionSource(): string | undefined {
1113
+ return STATE.sessionSource
1114
+ }
1115
+
1116
+ export function setSessionSource(source: string): void {
1117
+ STATE.sessionSource = source
1118
+ }
1119
+
1120
+ export function getQuestionPreviewFormat(): 'markdown' | 'html' | undefined {
1121
+ return STATE.questionPreviewFormat
1122
+ }
1123
+
1124
+ export function setQuestionPreviewFormat(format: 'markdown' | 'html'): void {
1125
+ STATE.questionPreviewFormat = format
1126
+ }
1127
+
1128
+ export function isReplBridgeActive(): boolean {
1129
+ // replBridgeActive only exists when USER_TYPE === 'ant'
1130
+ return 'replBridgeActive' in STATE ? STATE.replBridgeActive : false
1131
+ }
1132
+
1133
+ export function setReplBridgeActive(value: boolean): void {
1134
+ if ('replBridgeActive' in STATE) {
1135
+ STATE.replBridgeActive = value
1136
+ }
1137
+ }
1138
+
1139
+ export function getAgentColorMap(): Map<string, AgentColorName> {
1140
+ return STATE.agentColorMap
1141
+ }
1142
+
1143
+ export function getFlagSettingsPath(): string | undefined {
1144
+ return STATE.flagSettingsPath
1145
+ }
1146
+
1147
+ export function setFlagSettingsPath(path: string | undefined): void {
1148
+ STATE.flagSettingsPath = path
1149
+ }
1150
+
1151
+ export function getFlagSettingsInline(): Record<string, unknown> | null {
1152
+ return STATE.flagSettingsInline
1153
+ }
1154
+
1155
+ export function setFlagSettingsInline(
1156
+ settings: Record<string, unknown> | null,
1157
+ ): void {
1158
+ STATE.flagSettingsInline = settings
1159
+ }
1160
+
1161
+ export function getSessionIngressToken(): string | null | undefined {
1162
+ return STATE.sessionIngressToken
1163
+ }
1164
+
1165
+ export function setSessionIngressToken(token: string | null): void {
1166
+ STATE.sessionIngressToken = token
1167
+ }
1168
+
1169
+ export function getOauthTokenFromFd(): string | null | undefined {
1170
+ return STATE.oauthTokenFromFd
1171
+ }
1172
+
1173
+ export function setOauthTokenFromFd(token: string | null): void {
1174
+ STATE.oauthTokenFromFd = token
1175
+ }
1176
+
1177
+ export function getApiKeyFromFd(): string | null | undefined {
1178
+ return STATE.apiKeyFromFd
1179
+ }
1180
+
1181
+ export function setApiKeyFromFd(key: string | null): void {
1182
+ STATE.apiKeyFromFd = key
1183
+ }
1184
+
1185
+ export function setLastAPIRequest(
1186
+ params: Omit<BetaMessageStreamParams, 'messages'> | null,
1187
+ ): void {
1188
+ STATE.lastAPIRequest = params
1189
+ }
1190
+
1191
+ export function getLastAPIRequest(): Omit<
1192
+ BetaMessageStreamParams,
1193
+ 'messages'
1194
+ > | null {
1195
+ return STATE.lastAPIRequest
1196
+ }
1197
+
1198
+ export function setLastAPIRequestMessages(
1199
+ messages: BetaMessageStreamParams['messages'] | null,
1200
+ ): void {
1201
+ STATE.lastAPIRequestMessages = messages
1202
+ }
1203
+
1204
+ export function getLastAPIRequestMessages():
1205
+ | BetaMessageStreamParams['messages']
1206
+ | null {
1207
+ return STATE.lastAPIRequestMessages
1208
+ }
1209
+
1210
+ export function setLastClassifierRequests(requests: unknown[] | null): void {
1211
+ STATE.lastClassifierRequests = requests
1212
+ }
1213
+
1214
+ export function getLastClassifierRequests(): unknown[] | null {
1215
+ return STATE.lastClassifierRequests
1216
+ }
1217
+
1218
+ export function setCachedClaudeMdContent(content: string | null): void {
1219
+ STATE.cachedClaudeMdContent = content
1220
+ }
1221
+
1222
+ export function getCachedClaudeMdContent(): string | null {
1223
+ return STATE.cachedClaudeMdContent
1224
+ }
1225
+
1226
+ export function addToInMemoryErrorLog(errorInfo: {
1227
+ error: string
1228
+ timestamp: string
1229
+ }): void {
1230
+ const MAX_IN_MEMORY_ERRORS = 100
1231
+ if (STATE.inMemoryErrorLog.length >= MAX_IN_MEMORY_ERRORS) {
1232
+ STATE.inMemoryErrorLog.shift() // Remove oldest error
1233
+ }
1234
+ STATE.inMemoryErrorLog.push(errorInfo)
1235
+ }
1236
+
1237
+ export function getAllowedSettingSources(): SettingSource[] {
1238
+ return STATE.allowedSettingSources
1239
+ }
1240
+
1241
+ export function setAllowedSettingSources(sources: SettingSource[]): void {
1242
+ STATE.allowedSettingSources = sources
1243
+ }
1244
+
1245
+ export function preferThirdPartyAuthentication(): boolean {
1246
+ // IDE extension should behave as 1P for authentication reasons.
1247
+ return getIsNonInteractiveSession() && STATE.clientType !== 'claude-vscode'
1248
+ }
1249
+
1250
+ export function setInlinePlugins(plugins: Array<string>): void {
1251
+ STATE.inlinePlugins = plugins
1252
+ }
1253
+
1254
+ export function getInlinePlugins(): Array<string> {
1255
+ return STATE.inlinePlugins
1256
+ }
1257
+
1258
+ export function setChromeFlagOverride(value: boolean | undefined): void {
1259
+ STATE.chromeFlagOverride = value
1260
+ }
1261
+
1262
+ export function getChromeFlagOverride(): boolean | undefined {
1263
+ return STATE.chromeFlagOverride
1264
+ }
1265
+
1266
+ export function setUseCoworkPlugins(value: boolean): void {
1267
+ STATE.useCoworkPlugins = value
1268
+ resetSettingsCache()
1269
+ }
1270
+
1271
+ export function getUseCoworkPlugins(): boolean {
1272
+ return STATE.useCoworkPlugins
1273
+ }
1274
+
1275
+ export function setSessionBypassPermissionsMode(enabled: boolean): void {
1276
+ STATE.sessionBypassPermissionsMode = enabled
1277
+ }
1278
+
1279
+ export function getSessionBypassPermissionsMode(): boolean {
1280
+ return STATE.sessionBypassPermissionsMode
1281
+ }
1282
+
1283
+ export function setScheduledTasksEnabled(enabled: boolean): void {
1284
+ STATE.scheduledTasksEnabled = enabled
1285
+ }
1286
+
1287
+ export function getScheduledTasksEnabled(): boolean {
1288
+ return STATE.scheduledTasksEnabled
1289
+ }
1290
+
1291
+ export type SessionCronTask = {
1292
+ id: string
1293
+ cron: string
1294
+ prompt: string
1295
+ createdAt: number
1296
+ recurring?: boolean
1297
+ /**
1298
+ * When set, the task was created by an in-process teammate (not the team lead).
1299
+ * The scheduler routes fires to that teammate's pendingUserMessages queue
1300
+ * instead of the main REPL command queue. Session-only — never written to disk.
1301
+ */
1302
+ agentId?: string
1303
+ }
1304
+
1305
+ export function getSessionCronTasks(): SessionCronTask[] {
1306
+ return STATE.sessionCronTasks
1307
+ }
1308
+
1309
+ export function addSessionCronTask(task: SessionCronTask): void {
1310
+ STATE.sessionCronTasks.push(task)
1311
+ }
1312
+
1313
+ /**
1314
+ * Returns the number of tasks actually removed. Callers use this to skip
1315
+ * downstream work (e.g. the disk read in removeCronTasks) when all ids
1316
+ * were accounted for here.
1317
+ */
1318
+ export function removeSessionCronTasks(ids: readonly string[]): number {
1319
+ if (ids.length === 0) return 0
1320
+ const idSet = new Set(ids)
1321
+ const remaining = STATE.sessionCronTasks.filter(t => !idSet.has(t.id))
1322
+ const removed = STATE.sessionCronTasks.length - remaining.length
1323
+ if (removed === 0) return 0
1324
+ STATE.sessionCronTasks = remaining
1325
+ return removed
1326
+ }
1327
+
1328
+ export function setSessionTrustAccepted(accepted: boolean): void {
1329
+ STATE.sessionTrustAccepted = accepted
1330
+ }
1331
+
1332
+ export function getSessionTrustAccepted(): boolean {
1333
+ return STATE.sessionTrustAccepted
1334
+ }
1335
+
1336
+ export function setSessionPersistenceDisabled(disabled: boolean): void {
1337
+ STATE.sessionPersistenceDisabled = disabled
1338
+ }
1339
+
1340
+ export function isSessionPersistenceDisabled(): boolean {
1341
+ return STATE.sessionPersistenceDisabled
1342
+ }
1343
+
1344
+ export function hasExitedPlanModeInSession(): boolean {
1345
+ return STATE.hasExitedPlanMode
1346
+ }
1347
+
1348
+ export function setHasExitedPlanMode(value: boolean): void {
1349
+ STATE.hasExitedPlanMode = value
1350
+ }
1351
+
1352
+ export function needsPlanModeExitAttachment(): boolean {
1353
+ return STATE.needsPlanModeExitAttachment
1354
+ }
1355
+
1356
+ export function setNeedsPlanModeExitAttachment(value: boolean): void {
1357
+ STATE.needsPlanModeExitAttachment = value
1358
+ }
1359
+
1360
+ export function handlePlanModeTransition(
1361
+ fromMode: string,
1362
+ toMode: string,
1363
+ ): void {
1364
+ // If switching TO plan mode, clear any pending exit attachment
1365
+ // This prevents sending both plan_mode and plan_mode_exit when user toggles quickly
1366
+ if (toMode === 'plan' && fromMode !== 'plan') {
1367
+ STATE.needsPlanModeExitAttachment = false
1368
+ }
1369
+
1370
+ // If switching out of plan mode, trigger the plan_mode_exit attachment
1371
+ if (fromMode === 'plan' && toMode !== 'plan') {
1372
+ STATE.needsPlanModeExitAttachment = true
1373
+ }
1374
+ }
1375
+
1376
+ export function needsAutoModeExitAttachment(): boolean {
1377
+ return STATE.needsAutoModeExitAttachment
1378
+ }
1379
+
1380
+ export function setNeedsAutoModeExitAttachment(value: boolean): void {
1381
+ STATE.needsAutoModeExitAttachment = value
1382
+ }
1383
+
1384
+ export function handleAutoModeTransition(
1385
+ fromMode: string,
1386
+ toMode: string,
1387
+ ): void {
1388
+ // Auto↔plan transitions are handled by prepareContextForPlanMode (auto may
1389
+ // stay active through plan if opted in) and ExitPlanMode (restores mode).
1390
+ // Skip both directions so this function only handles direct auto transitions.
1391
+ if (
1392
+ (fromMode === 'auto' && toMode === 'plan') ||
1393
+ (fromMode === 'plan' && toMode === 'auto')
1394
+ ) {
1395
+ return
1396
+ }
1397
+ const fromIsAuto = fromMode === 'auto'
1398
+ const toIsAuto = toMode === 'auto'
1399
+
1400
+ // If switching TO auto mode, clear any pending exit attachment
1401
+ // This prevents sending both auto_mode and auto_mode_exit when user toggles quickly
1402
+ if (toIsAuto && !fromIsAuto) {
1403
+ STATE.needsAutoModeExitAttachment = false
1404
+ }
1405
+
1406
+ // If switching out of auto mode, trigger the auto_mode_exit attachment
1407
+ if (fromIsAuto && !toIsAuto) {
1408
+ STATE.needsAutoModeExitAttachment = true
1409
+ }
1410
+ }
1411
+
1412
+ // LSP plugin recommendation session tracking
1413
+ export function hasShownLspRecommendationThisSession(): boolean {
1414
+ return STATE.lspRecommendationShownThisSession
1415
+ }
1416
+
1417
+ export function setLspRecommendationShownThisSession(value: boolean): void {
1418
+ STATE.lspRecommendationShownThisSession = value
1419
+ }
1420
+
1421
+ // SDK init event state
1422
+ export function setInitJsonSchema(schema: Record<string, unknown>): void {
1423
+ STATE.initJsonSchema = schema
1424
+ }
1425
+
1426
+ export function getInitJsonSchema(): Record<string, unknown> | null {
1427
+ return STATE.initJsonSchema
1428
+ }
1429
+
1430
+ export function registerHookCallbacks(
1431
+ hooks: Partial<Record<HookEvent, RegisteredHookMatcher[]>>,
1432
+ ): void {
1433
+ if (!STATE.registeredHooks) {
1434
+ STATE.registeredHooks = {}
1435
+ }
1436
+
1437
+ // `registerHookCallbacks` may be called multiple times, so we need to merge (not overwrite)
1438
+ for (const [event, matchers] of Object.entries(hooks)) {
1439
+ const eventKey = event as HookEvent
1440
+ if (!STATE.registeredHooks[eventKey]) {
1441
+ STATE.registeredHooks[eventKey] = []
1442
+ }
1443
+ STATE.registeredHooks[eventKey]!.push(...matchers)
1444
+ }
1445
+ }
1446
+
1447
+ export function getRegisteredHooks(): Partial<
1448
+ Record<HookEvent, RegisteredHookMatcher[]>
1449
+ > | null {
1450
+ return STATE.registeredHooks
1451
+ }
1452
+
1453
+ export function clearRegisteredHooks(): void {
1454
+ STATE.registeredHooks = null
1455
+ }
1456
+
1457
+ export function clearRegisteredPluginHooks(): void {
1458
+ if (!STATE.registeredHooks) {
1459
+ return
1460
+ }
1461
+
1462
+ const filtered: Partial<Record<HookEvent, RegisteredHookMatcher[]>> = {}
1463
+ for (const [event, matchers] of Object.entries(STATE.registeredHooks)) {
1464
+ // Keep only callback hooks (those without pluginRoot)
1465
+ const callbackHooks = matchers.filter(m => !('pluginRoot' in m))
1466
+ if (callbackHooks.length > 0) {
1467
+ filtered[event as HookEvent] = callbackHooks
1468
+ }
1469
+ }
1470
+
1471
+ STATE.registeredHooks = Object.keys(filtered).length > 0 ? filtered : null
1472
+ }
1473
+
1474
+ export function resetSdkInitState(): void {
1475
+ STATE.initJsonSchema = null
1476
+ STATE.registeredHooks = null
1477
+ }
1478
+
1479
+ export function getPlanSlugCache(): Map<string, string> {
1480
+ return STATE.planSlugCache
1481
+ }
1482
+
1483
+ export function getSessionCreatedTeams(): Set<string> {
1484
+ return STATE.sessionCreatedTeams
1485
+ }
1486
+
1487
+ // Teleported session tracking for reliability logging
1488
+ export function setTeleportedSessionInfo(info: {
1489
+ sessionId: string | null
1490
+ }): void {
1491
+ STATE.teleportedSessionInfo = {
1492
+ isTeleported: true,
1493
+ hasLoggedFirstMessage: false,
1494
+ sessionId: info.sessionId,
1495
+ }
1496
+ }
1497
+
1498
+ export function getTeleportedSessionInfo(): {
1499
+ isTeleported: boolean
1500
+ hasLoggedFirstMessage: boolean
1501
+ sessionId: string | null
1502
+ } | null {
1503
+ return STATE.teleportedSessionInfo
1504
+ }
1505
+
1506
+ export function markFirstTeleportMessageLogged(): void {
1507
+ if (STATE.teleportedSessionInfo) {
1508
+ STATE.teleportedSessionInfo.hasLoggedFirstMessage = true
1509
+ }
1510
+ }
1511
+
1512
+ // Invoked skills tracking for preservation across compaction
1513
+ export type InvokedSkillInfo = {
1514
+ skillName: string
1515
+ skillPath: string
1516
+ content: string
1517
+ invokedAt: number
1518
+ agentId: string | null
1519
+ }
1520
+
1521
+ export function addInvokedSkill(
1522
+ skillName: string,
1523
+ skillPath: string,
1524
+ content: string,
1525
+ agentId: string | null = null,
1526
+ ): void {
1527
+ const key = `${agentId ?? ''}:${skillName}`
1528
+ STATE.invokedSkills.set(key, {
1529
+ skillName,
1530
+ skillPath,
1531
+ content,
1532
+ invokedAt: Date.now(),
1533
+ agentId,
1534
+ })
1535
+ }
1536
+
1537
+ export function getInvokedSkills(): Map<string, InvokedSkillInfo> {
1538
+ return STATE.invokedSkills
1539
+ }
1540
+
1541
+ export function getInvokedSkillsForAgent(
1542
+ agentId: string | undefined | null,
1543
+ ): Map<string, InvokedSkillInfo> {
1544
+ const normalizedId = agentId ?? null
1545
+ const filtered = new Map<string, InvokedSkillInfo>()
1546
+ for (const [key, skill] of STATE.invokedSkills) {
1547
+ if (skill.agentId === normalizedId) {
1548
+ filtered.set(key, skill)
1549
+ }
1550
+ }
1551
+ return filtered
1552
+ }
1553
+
1554
+ export function clearInvokedSkills(
1555
+ preservedAgentIds?: ReadonlySet<string>,
1556
+ ): void {
1557
+ if (!preservedAgentIds || preservedAgentIds.size === 0) {
1558
+ STATE.invokedSkills.clear()
1559
+ return
1560
+ }
1561
+ for (const [key, skill] of STATE.invokedSkills) {
1562
+ if (skill.agentId === null || !preservedAgentIds.has(skill.agentId)) {
1563
+ STATE.invokedSkills.delete(key)
1564
+ }
1565
+ }
1566
+ }
1567
+
1568
+ export function clearInvokedSkillsForAgent(agentId: string): void {
1569
+ for (const [key, skill] of STATE.invokedSkills) {
1570
+ if (skill.agentId === agentId) {
1571
+ STATE.invokedSkills.delete(key)
1572
+ }
1573
+ }
1574
+ }
1575
+
1576
+ // Slow operations tracking for dev bar
1577
+ const MAX_SLOW_OPERATIONS = 10
1578
+ const SLOW_OPERATION_TTL_MS = 10000
1579
+
1580
+ export function addSlowOperation(operation: string, durationMs: number): void {
1581
+ if (process.env.USER_TYPE !== 'ant') return
1582
+ // Skip tracking for editor sessions (user editing a prompt file in $EDITOR)
1583
+ // These are intentionally slow since the user is drafting text
1584
+ if (operation.includes('exec') && operation.includes('claude-prompt-')) {
1585
+ return
1586
+ }
1587
+ const now = Date.now()
1588
+ // Remove stale operations
1589
+ STATE.slowOperations = STATE.slowOperations.filter(
1590
+ op => now - op.timestamp < SLOW_OPERATION_TTL_MS,
1591
+ )
1592
+ // Add new operation
1593
+ STATE.slowOperations.push({ operation, durationMs, timestamp: now })
1594
+ // Keep only the most recent operations
1595
+ if (STATE.slowOperations.length > MAX_SLOW_OPERATIONS) {
1596
+ STATE.slowOperations = STATE.slowOperations.slice(-MAX_SLOW_OPERATIONS)
1597
+ }
1598
+ }
1599
+
1600
+ const EMPTY_SLOW_OPERATIONS: ReadonlyArray<{
1601
+ operation: string
1602
+ durationMs: number
1603
+ timestamp: number
1604
+ }> = []
1605
+
1606
+ export function getSlowOperations(): ReadonlyArray<{
1607
+ operation: string
1608
+ durationMs: number
1609
+ timestamp: number
1610
+ }> {
1611
+ // Most common case: nothing tracked. Return a stable reference so the
1612
+ // caller's setState() can bail via Object.is instead of re-rendering at 2fps.
1613
+ if (STATE.slowOperations.length === 0) {
1614
+ return EMPTY_SLOW_OPERATIONS
1615
+ }
1616
+ const now = Date.now()
1617
+ // Only allocate a new array when something actually expired; otherwise keep
1618
+ // the reference stable across polls while ops are still fresh.
1619
+ if (
1620
+ STATE.slowOperations.some(op => now - op.timestamp >= SLOW_OPERATION_TTL_MS)
1621
+ ) {
1622
+ STATE.slowOperations = STATE.slowOperations.filter(
1623
+ op => now - op.timestamp < SLOW_OPERATION_TTL_MS,
1624
+ )
1625
+ if (STATE.slowOperations.length === 0) {
1626
+ return EMPTY_SLOW_OPERATIONS
1627
+ }
1628
+ }
1629
+ // Safe to return directly: addSlowOperation() reassigns STATE.slowOperations
1630
+ // before pushing, so the array held in React state is never mutated.
1631
+ return STATE.slowOperations
1632
+ }
1633
+
1634
+ export function getMainThreadAgentType(): string | undefined {
1635
+ return STATE.mainThreadAgentType
1636
+ }
1637
+
1638
+ export function setMainThreadAgentType(agentType: string | undefined): void {
1639
+ STATE.mainThreadAgentType = agentType
1640
+ }
1641
+
1642
+ export function getIsRemoteMode(): boolean {
1643
+ return STATE.isRemoteMode
1644
+ }
1645
+
1646
+ export function setIsRemoteMode(value: boolean): void {
1647
+ STATE.isRemoteMode = value
1648
+ }
1649
+
1650
+ // System prompt section accessors
1651
+
1652
+ export function getSystemPromptSectionCache(): Map<string, string | null> {
1653
+ return STATE.systemPromptSectionCache
1654
+ }
1655
+
1656
+ export function setSystemPromptSectionCacheEntry(
1657
+ name: string,
1658
+ value: string | null,
1659
+ ): void {
1660
+ STATE.systemPromptSectionCache.set(name, value)
1661
+ }
1662
+
1663
+ export function clearSystemPromptSectionState(): void {
1664
+ STATE.systemPromptSectionCache.clear()
1665
+ }
1666
+
1667
+ // Last emitted date accessors (for detecting midnight date changes)
1668
+
1669
+ export function getLastEmittedDate(): string | null {
1670
+ return STATE.lastEmittedDate
1671
+ }
1672
+
1673
+ export function setLastEmittedDate(date: string | null): void {
1674
+ STATE.lastEmittedDate = date
1675
+ }
1676
+
1677
+ export function getAdditionalDirectoriesForClaudeMd(): string[] {
1678
+ return STATE.additionalDirectoriesForClaudeMd
1679
+ }
1680
+
1681
+ export function setAdditionalDirectoriesForClaudeMd(
1682
+ directories: string[],
1683
+ ): void {
1684
+ STATE.additionalDirectoriesForClaudeMd = directories
1685
+ }
1686
+
1687
+ export function getAllowedChannels(): ChannelEntry[] {
1688
+ return STATE.allowedChannels
1689
+ }
1690
+
1691
+ export function setAllowedChannels(entries: ChannelEntry[]): void {
1692
+ STATE.allowedChannels = entries
1693
+ }
1694
+
1695
+ export function getHasDevChannels(): boolean {
1696
+ return STATE.hasDevChannels
1697
+ }
1698
+
1699
+ export function setHasDevChannels(value: boolean): void {
1700
+ STATE.hasDevChannels = value
1701
+ }
1702
+
1703
+ export function getPromptCache1hAllowlist(): string[] | null {
1704
+ return STATE.promptCache1hAllowlist
1705
+ }
1706
+
1707
+ export function setPromptCache1hAllowlist(allowlist: string[] | null): void {
1708
+ STATE.promptCache1hAllowlist = allowlist
1709
+ }
1710
+
1711
+ export function getPromptCache1hEligible(): boolean | null {
1712
+ return STATE.promptCache1hEligible
1713
+ }
1714
+
1715
+ export function setPromptCache1hEligible(eligible: boolean | null): void {
1716
+ STATE.promptCache1hEligible = eligible
1717
+ }
1718
+
1719
+ export function getAfkModeHeaderLatched(): boolean | null {
1720
+ return STATE.afkModeHeaderLatched
1721
+ }
1722
+
1723
+ export function setAfkModeHeaderLatched(v: boolean): void {
1724
+ STATE.afkModeHeaderLatched = v
1725
+ }
1726
+
1727
+ export function getFastModeHeaderLatched(): boolean | null {
1728
+ return STATE.fastModeHeaderLatched
1729
+ }
1730
+
1731
+ export function setFastModeHeaderLatched(v: boolean): void {
1732
+ STATE.fastModeHeaderLatched = v
1733
+ }
1734
+
1735
+ export function getCacheEditingHeaderLatched(): boolean | null {
1736
+ return STATE.cacheEditingHeaderLatched
1737
+ }
1738
+
1739
+ export function setCacheEditingHeaderLatched(v: boolean): void {
1740
+ STATE.cacheEditingHeaderLatched = v
1741
+ }
1742
+
1743
+ export function getThinkingClearLatched(): boolean | null {
1744
+ return STATE.thinkingClearLatched
1745
+ }
1746
+
1747
+ export function setThinkingClearLatched(v: boolean): void {
1748
+ STATE.thinkingClearLatched = v
1749
+ }
1750
+
1751
+ /**
1752
+ * Reset beta header latches to null. Called on /clear and /compact so a
1753
+ * fresh conversation gets fresh header evaluation.
1754
+ */
1755
+ export function clearBetaHeaderLatches(): void {
1756
+ STATE.afkModeHeaderLatched = null
1757
+ STATE.fastModeHeaderLatched = null
1758
+ STATE.cacheEditingHeaderLatched = null
1759
+ STATE.thinkingClearLatched = null
1760
+ }
1761
+
1762
+ export function getPromptId(): string | null {
1763
+ return STATE.promptId
1764
+ }
1765
+
1766
+ export function setPromptId(id: string | null): void {
1767
+ STATE.promptId = id
1768
+ }
1769
+