ummaya 0.2.13 → 0.2.15

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 (566) hide show
  1. package/npm-shrinkwrap.json +2 -2
  2. package/package.json +7 -4
  3. package/pyproject.toml +2 -2
  4. package/tui/package.json +1 -1
  5. package/tui/src/buddy/CompanionSprite.tsx +1 -2
  6. package/tui/src/buddy/useBuddyNotification.tsx +1 -2
  7. package/tui/src/cli/controlAuth.ts +20 -0
  8. package/tui/src/cli/handlers/auth.ts +7 -7
  9. package/tui/src/cli/handlers/mcp.tsx +0 -1
  10. package/tui/src/cli/handlers/util.tsx +2 -3
  11. package/tui/src/cli/print.ts +7 -4
  12. package/tui/src/commands/add-dir/add-dir.tsx +1 -2
  13. package/tui/src/commands/agents/agents.tsx +1 -2
  14. package/tui/src/commands/bridge/bridge.tsx +1 -2
  15. package/tui/src/commands/btw/btw.tsx +1 -2
  16. package/tui/src/commands/config/config.tsx +1 -2
  17. package/tui/src/commands/context/context.tsx +1 -2
  18. package/tui/src/commands/copy/copy.tsx +1 -2
  19. package/tui/src/commands/desktop/desktop.tsx +1 -2
  20. package/tui/src/commands/diff/diff.tsx +1 -2
  21. package/tui/src/commands/doctor/doctor.tsx +1 -2
  22. package/tui/src/commands/effort/effort.tsx +1 -2
  23. package/tui/src/commands/exit/exit.tsx +1 -2
  24. package/tui/src/commands/export/export.tsx +1 -2
  25. package/tui/src/commands/extra-usage/extra-usage.tsx +1 -2
  26. package/tui/src/commands/fast/fast.tsx +0 -1
  27. package/tui/src/commands/feedback/feedback.tsx +1 -2
  28. package/tui/src/commands/help/help.tsx +1 -2
  29. package/tui/src/commands/hooks/hooks.tsx +1 -2
  30. package/tui/src/commands/ide/ide.tsx +0 -1
  31. package/tui/src/commands/install-github-app/OAuthFlowStep.tsx +1 -2
  32. package/tui/src/commands/install-github-app/install-github-app.tsx +4 -4
  33. package/tui/src/commands/install.tsx +0 -1
  34. package/tui/src/commands/login/login.tsx +1 -2
  35. package/tui/src/commands/logout/logout.tsx +0 -1
  36. package/tui/src/commands/mcp/mcp.tsx +1 -2
  37. package/tui/src/commands/memory/memory.tsx +0 -1
  38. package/tui/src/commands/mobile/mobile.tsx +0 -1
  39. package/tui/src/commands/model/model.tsx +0 -1
  40. package/tui/src/commands/output-style/output-style.tsx +1 -2
  41. package/tui/src/commands/passes/passes.tsx +1 -2
  42. package/tui/src/commands/permissions/permissions.tsx +1 -2
  43. package/tui/src/commands/plan/plan.tsx +1 -2
  44. package/tui/src/commands/plugin/AddMarketplace.tsx +1 -2
  45. package/tui/src/commands/plugin/BrowseMarketplace.tsx +1 -2
  46. package/tui/src/commands/plugin/DiscoverPlugins.tsx +0 -1
  47. package/tui/src/commands/plugin/ManageMarketplaces.tsx +0 -1
  48. package/tui/src/commands/plugin/ManagePlugins.tsx +1 -2
  49. package/tui/src/commands/plugin/PluginErrors.tsx +1 -2
  50. package/tui/src/commands/plugin/PluginOptionsDialog.tsx +1 -2
  51. package/tui/src/commands/plugin/PluginOptionsFlow.tsx +1 -2
  52. package/tui/src/commands/plugin/PluginSettings.tsx +1 -2
  53. package/tui/src/commands/plugin/PluginTrustWarning.tsx +0 -1
  54. package/tui/src/commands/plugin/UnifiedInstalledCell.tsx +1 -2
  55. package/tui/src/commands/plugin/ValidatePlugin.tsx +1 -2
  56. package/tui/src/commands/plugin/index.tsx +0 -1
  57. package/tui/src/commands/plugin/plugin.tsx +1 -2
  58. package/tui/src/commands/plugin/pluginDetailsHelpers.tsx +1 -2
  59. package/tui/src/commands/privacy-settings/privacy-settings.tsx +0 -1
  60. package/tui/src/commands/rate-limit-options/rate-limit-options.tsx +1 -2
  61. package/tui/src/commands/remote-env/remote-env.tsx +1 -2
  62. package/tui/src/commands/remote-setup/remote-setup.tsx +0 -1
  63. package/tui/src/commands/resume/resume.tsx +1 -2
  64. package/tui/src/commands/review/UltrareviewOverageDialog.tsx +1 -2
  65. package/tui/src/commands/review/ultrareviewCommand.tsx +0 -1
  66. package/tui/src/commands/sandbox-toggle/sandbox-toggle.tsx +1 -2
  67. package/tui/src/commands/session/session.tsx +0 -1
  68. package/tui/src/commands/skills/skills.tsx +1 -2
  69. package/tui/src/commands/stats/stats.tsx +1 -2
  70. package/tui/src/commands/status/status.tsx +1 -2
  71. package/tui/src/commands/statusline.tsx +0 -1
  72. package/tui/src/commands/tag/tag.tsx +1 -2
  73. package/tui/src/commands/tasks/tasks.tsx +1 -2
  74. package/tui/src/commands/terminalSetup/terminalSetup.tsx +1 -2
  75. package/tui/src/commands/theme/theme.tsx +1 -2
  76. package/tui/src/commands/thinkback/thinkback.tsx +0 -1
  77. package/tui/src/commands/ultraplan.tsx +0 -1
  78. package/tui/src/commands/usage/usage.tsx +1 -2
  79. package/tui/src/commands/voice/voice.ts +2 -2
  80. package/tui/src/components/AgentProgressLine.tsx +1 -2
  81. package/tui/src/components/App.tsx +1 -2
  82. package/tui/src/components/ApproveApiKey.tsx +1 -2
  83. package/tui/src/components/AutoModeOptInDialog.tsx +0 -1
  84. package/tui/src/components/AutoUpdater.tsx +1 -2
  85. package/tui/src/components/AutoUpdaterWrapper.tsx +1 -2
  86. package/tui/src/components/AwsAuthStatusBox.tsx +1 -2
  87. package/tui/src/components/BaseTextInput.tsx +0 -1
  88. package/tui/src/components/BashModeProgress.tsx +1 -2
  89. package/tui/src/components/BridgeDialog.tsx +1 -2
  90. package/tui/src/components/BypassPermissionsModeDialog.tsx +0 -1
  91. package/tui/src/components/ChannelDowngradeDialog.tsx +1 -2
  92. package/tui/src/components/ClaudeCodeHint/PluginHintMenu.tsx +1 -2
  93. package/tui/src/components/ClaudeMdExternalIncludesDialog.tsx +0 -1
  94. package/tui/src/components/ClickableImageRef.tsx +1 -2
  95. package/tui/src/components/CompactSummary.tsx +1 -2
  96. package/tui/src/components/ConfigurableShortcutHint.tsx +1 -2
  97. package/tui/src/components/ContextSuggestions.tsx +1 -2
  98. package/tui/src/components/ContextVisualization.tsx +1 -2
  99. package/tui/src/components/CoordinatorAgentStatus.tsx +1 -2
  100. package/tui/src/components/CostThresholdDialog.tsx +0 -1
  101. package/tui/src/components/CtrlOToExpand.tsx +1 -2
  102. package/tui/src/components/CustomSelect/SelectMulti.tsx +1 -2
  103. package/tui/src/components/CustomSelect/select-input-option.tsx +1 -2
  104. package/tui/src/components/CustomSelect/select-option.tsx +1 -2
  105. package/tui/src/components/CustomSelect/select.tsx +1 -2
  106. package/tui/src/components/DesktopHandoff.tsx +0 -1
  107. package/tui/src/components/DesktopUpsell/DesktopUpsellStartup.tsx +0 -1
  108. package/tui/src/components/DevBar.tsx +1 -2
  109. package/tui/src/components/DevChannelsDialog.tsx +1 -2
  110. package/tui/src/components/DiagnosticsDisplay.tsx +1 -2
  111. package/tui/src/components/EffortCallout.tsx +1 -2
  112. package/tui/src/components/ExitFlow.tsx +1 -2
  113. package/tui/src/components/ExportDialog.tsx +1 -2
  114. package/tui/src/components/FallbackToolUseErrorMessage.tsx +0 -1
  115. package/tui/src/components/FallbackToolUseRejectedMessage.tsx +1 -2
  116. package/tui/src/components/FastIcon.tsx +1 -2
  117. package/tui/src/components/Feedback.tsx +0 -1
  118. package/tui/src/components/FeedbackSurvey/FeedbackSurvey.tsx +1 -2
  119. package/tui/src/components/FeedbackSurvey/FeedbackSurveyView.tsx +0 -1
  120. package/tui/src/components/FeedbackSurvey/TranscriptSharePrompt.tsx +0 -1
  121. package/tui/src/components/FeedbackSurvey/useFeedbackSurvey.tsx +0 -1
  122. package/tui/src/components/FeedbackSurvey/useMemorySurvey.tsx +0 -1
  123. package/tui/src/components/FeedbackSurvey/usePostCompactSurvey.tsx +0 -1
  124. package/tui/src/components/FeedbackSurvey/useSurveyState.tsx +1 -2
  125. package/tui/src/components/FileEditToolDiff.tsx +1 -2
  126. package/tui/src/components/FileEditToolUpdatedMessage.tsx +1 -2
  127. package/tui/src/components/FileEditToolUseRejectedMessage.tsx +1 -2
  128. package/tui/src/components/FilePathLink.tsx +1 -2
  129. package/tui/src/components/FullscreenLayout.tsx +1 -2
  130. package/tui/src/components/GlobalSearchDialog.tsx +1 -2
  131. package/tui/src/components/HelpV2/Commands.tsx +1 -2
  132. package/tui/src/components/HelpV2/General.tsx +0 -1
  133. package/tui/src/components/HelpV2/HelpV2.tsx +0 -1
  134. package/tui/src/components/HighlightedCode/Fallback.tsx +1 -2
  135. package/tui/src/components/HighlightedCode.tsx +1 -2
  136. package/tui/src/components/HistorySearchDialog.tsx +1 -2
  137. package/tui/src/components/IdeAutoConnectDialog.tsx +1 -2
  138. package/tui/src/components/IdeOnboardingDialog.tsx +0 -1
  139. package/tui/src/components/IdeStatusIndicator.tsx +1 -2
  140. package/tui/src/components/IdleReturnDialog.tsx +1 -2
  141. package/tui/src/components/InterruptedByUser.tsx +0 -1
  142. package/tui/src/components/InvalidConfigDialog.tsx +1 -2
  143. package/tui/src/components/InvalidSettingsDialog.tsx +1 -2
  144. package/tui/src/components/KeybindingWarnings.tsx +1 -2
  145. package/tui/src/components/LanguagePicker.tsx +1 -2
  146. package/tui/src/components/LogSelector.tsx +0 -1
  147. package/tui/src/components/LogoV2/AnimatedAsterisk.tsx +1 -2
  148. package/tui/src/components/LogoV2/AnimatedClawd.tsx +1 -2
  149. package/tui/src/components/LogoV2/ChannelsNotice.tsx +0 -1
  150. package/tui/src/components/LogoV2/Clawd.tsx +1 -2
  151. package/tui/src/components/LogoV2/CondensedLogo.tsx +0 -1
  152. package/tui/src/components/LogoV2/EmergencyTip.tsx +0 -1
  153. package/tui/src/components/LogoV2/Feed.tsx +1 -2
  154. package/tui/src/components/LogoV2/FeedColumn.tsx +1 -2
  155. package/tui/src/components/LogoV2/GuestPassesUpsell.tsx +0 -1
  156. package/tui/src/components/LogoV2/LogoV2.tsx +0 -1
  157. package/tui/src/components/LogoV2/Opus1mMergeNotice.tsx +1 -2
  158. package/tui/src/components/LogoV2/OverageCreditUpsell.tsx +1 -2
  159. package/tui/src/components/LogoV2/VoiceModeNotice.tsx +1 -2
  160. package/tui/src/components/LogoV2/feedConfigs.tsx +0 -1
  161. package/tui/src/components/LspRecommendation/LspRecommendationMenu.tsx +1 -2
  162. package/tui/src/components/MCPServerApprovalDialog.tsx +1 -2
  163. package/tui/src/components/MCPServerDesktopImportDialog.tsx +0 -1
  164. package/tui/src/components/MCPServerDialogCopy.tsx +0 -1
  165. package/tui/src/components/MCPServerMultiselectDialog.tsx +1 -2
  166. package/tui/src/components/ManagedSettingsSecurityDialog/ManagedSettingsSecurityDialog.tsx +0 -1
  167. package/tui/src/components/Markdown.tsx +1 -2
  168. package/tui/src/components/MarkdownTable.tsx +1 -2
  169. package/tui/src/components/MemoryUsageIndicator.tsx +1 -2
  170. package/tui/src/components/Message.tsx +1 -2
  171. package/tui/src/components/MessageModel.tsx +1 -2
  172. package/tui/src/components/MessageResponse.tsx +1 -2
  173. package/tui/src/components/MessageRow.tsx +1 -2
  174. package/tui/src/components/MessageSelector.tsx +1 -2
  175. package/tui/src/components/MessageTimestamp.tsx +1 -2
  176. package/tui/src/components/Messages.tsx +0 -1
  177. package/tui/src/components/ModelPicker.tsx +0 -1
  178. package/tui/src/components/NativeAutoUpdater.tsx +1 -2
  179. package/tui/src/components/NotebookEditToolUseRejectedMessage.tsx +1 -2
  180. package/tui/src/components/OffscreenFreeze.tsx +1 -2
  181. package/tui/src/components/Onboarding.tsx +2 -3
  182. package/tui/src/components/OutputStylePicker.tsx +0 -1
  183. package/tui/src/components/PackageManagerAutoUpdater.tsx +0 -1
  184. package/tui/src/components/Passes/Passes.tsx +0 -1
  185. package/tui/src/components/PrBadge.tsx +1 -2
  186. package/tui/src/components/PressEnterToContinue.tsx +1 -2
  187. package/tui/src/components/PromptInput/HistorySearchInput.tsx +1 -2
  188. package/tui/src/components/PromptInput/IssueFlagBanner.tsx +1 -2
  189. package/tui/src/components/PromptInput/Notifications.tsx +1 -2
  190. package/tui/src/components/PromptInput/PromptInput.tsx +0 -1
  191. package/tui/src/components/PromptInput/PromptInputFooter.tsx +1 -2
  192. package/tui/src/components/PromptInput/PromptInputFooterLeftSide.tsx +1 -2
  193. package/tui/src/components/PromptInput/PromptInputFooterSuggestions.tsx +1 -2
  194. package/tui/src/components/PromptInput/PromptInputHelpMenu.tsx +1 -2
  195. package/tui/src/components/PromptInput/PromptInputModeIndicator.tsx +1 -2
  196. package/tui/src/components/PromptInput/PromptInputQueuedCommands.tsx +1 -2
  197. package/tui/src/components/PromptInput/PromptInputStashNotice.tsx +1 -2
  198. package/tui/src/components/PromptInput/SandboxPromptFooterHint.tsx +1 -2
  199. package/tui/src/components/PromptInput/ShimmeredInput.tsx +1 -2
  200. package/tui/src/components/PromptInput/VoiceIndicator.tsx +1 -2
  201. package/tui/src/components/QuickOpenDialog.tsx +1 -2
  202. package/tui/src/components/RemoteCallout.tsx +0 -1
  203. package/tui/src/components/RemoteEnvironmentDialog.tsx +0 -1
  204. package/tui/src/components/ResumeTask.tsx +0 -1
  205. package/tui/src/components/SandboxViolationExpandedView.tsx +1 -2
  206. package/tui/src/components/ScrollKeybindingHandler.tsx +0 -1
  207. package/tui/src/components/SearchBox.tsx +1 -2
  208. package/tui/src/components/SessionBackgroundHint.tsx +1 -2
  209. package/tui/src/components/SessionPreview.tsx +1 -2
  210. package/tui/src/components/Settings/Config.tsx +0 -1
  211. package/tui/src/components/Settings/Settings.tsx +1 -2
  212. package/tui/src/components/Settings/Status.tsx +1 -2
  213. package/tui/src/components/Settings/Usage.tsx +1 -2
  214. package/tui/src/components/ShowInIDEPrompt.tsx +1 -2
  215. package/tui/src/components/SkillImprovementSurvey.tsx +1 -2
  216. package/tui/src/components/Spinner/FlashingChar.tsx +1 -2
  217. package/tui/src/components/Spinner/GlimmerMessage.tsx +1 -2
  218. package/tui/src/components/Spinner/ShimmerChar.tsx +1 -2
  219. package/tui/src/components/Spinner/SpinnerAnimationRow.tsx +1 -2
  220. package/tui/src/components/Spinner/SpinnerGlyph.tsx +1 -2
  221. package/tui/src/components/Spinner/TeammateSpinnerLine.tsx +1 -2
  222. package/tui/src/components/Spinner/TeammateSpinnerTree.tsx +1 -2
  223. package/tui/src/components/Spinner.tsx +0 -1
  224. package/tui/src/components/Stats.tsx +0 -1
  225. package/tui/src/components/StatusLine.tsx +1 -2
  226. package/tui/src/components/StatusNotices.tsx +1 -2
  227. package/tui/src/components/StructuredDiff/Fallback.tsx +1 -2
  228. package/tui/src/components/StructuredDiff.tsx +1 -2
  229. package/tui/src/components/StructuredDiffList.tsx +1 -2
  230. package/tui/src/components/TagTabs.tsx +1 -2
  231. package/tui/src/components/TaskListV2.tsx +1 -2
  232. package/tui/src/components/TeammateViewHeader.tsx +1 -2
  233. package/tui/src/components/TeleportError.tsx +0 -1
  234. package/tui/src/components/TeleportProgress.tsx +1 -2
  235. package/tui/src/components/TeleportRepoMismatchDialog.tsx +0 -1
  236. package/tui/src/components/TeleportStash.tsx +1 -2
  237. package/tui/src/components/TextInput.tsx +1 -2
  238. package/tui/src/components/ThemePicker.tsx +0 -1
  239. package/tui/src/components/ThinkingToggle.tsx +0 -1
  240. package/tui/src/components/TokenWarning.tsx +1 -2
  241. package/tui/src/components/ToolUseLoader.tsx +1 -2
  242. package/tui/src/components/TrustDialog/TrustDialog.tsx +0 -1
  243. package/tui/src/components/ValidationErrorsList.tsx +1 -2
  244. package/tui/src/components/VimTextInput.tsx +1 -2
  245. package/tui/src/components/VirtualMessageList.tsx +1 -2
  246. package/tui/src/components/WorktreeExitDialog.tsx +1 -2
  247. package/tui/src/components/agents/AgentDetail.tsx +0 -1
  248. package/tui/src/components/agents/AgentEditor.tsx +1 -2
  249. package/tui/src/components/agents/AgentNavigationFooter.tsx +1 -2
  250. package/tui/src/components/agents/AgentsList.tsx +0 -1
  251. package/tui/src/components/agents/AgentsMenu.tsx +1 -2
  252. package/tui/src/components/agents/ColorPicker.tsx +1 -2
  253. package/tui/src/components/agents/ModelSelector.tsx +1 -2
  254. package/tui/src/components/agents/ToolSelector.tsx +1 -2
  255. package/tui/src/components/agents/new-agent-creation/CreateAgentWizard.tsx +1 -2
  256. package/tui/src/components/agents/new-agent-creation/wizard-steps/ColorStep.tsx +1 -2
  257. package/tui/src/components/agents/new-agent-creation/wizard-steps/ConfirmStep.tsx +0 -1
  258. package/tui/src/components/agents/new-agent-creation/wizard-steps/ConfirmStepWrapper.tsx +1 -2
  259. package/tui/src/components/agents/new-agent-creation/wizard-steps/DescriptionStep.tsx +0 -1
  260. package/tui/src/components/agents/new-agent-creation/wizard-steps/GenerateStep.tsx +1 -2
  261. package/tui/src/components/agents/new-agent-creation/wizard-steps/LocationStep.tsx +1 -2
  262. package/tui/src/components/agents/new-agent-creation/wizard-steps/MemoryStep.tsx +1 -2
  263. package/tui/src/components/agents/new-agent-creation/wizard-steps/MethodStep.tsx +0 -1
  264. package/tui/src/components/agents/new-agent-creation/wizard-steps/ModelStep.tsx +1 -2
  265. package/tui/src/components/agents/new-agent-creation/wizard-steps/PromptStep.tsx +1 -2
  266. package/tui/src/components/agents/new-agent-creation/wizard-steps/ToolsStep.tsx +1 -2
  267. package/tui/src/components/agents/new-agent-creation/wizard-steps/TypeStep.tsx +1 -2
  268. package/tui/src/components/design-system/Byline.tsx +1 -2
  269. package/tui/src/components/design-system/Dialog.tsx +1 -2
  270. package/tui/src/components/design-system/Divider.tsx +1 -2
  271. package/tui/src/components/design-system/FuzzyPicker.tsx +1 -2
  272. package/tui/src/components/design-system/KeyboardShortcutHint.tsx +1 -2
  273. package/tui/src/components/design-system/ListItem.tsx +1 -2
  274. package/tui/src/components/design-system/LoadingState.tsx +0 -1
  275. package/tui/src/components/design-system/Pane.tsx +1 -2
  276. package/tui/src/components/design-system/ProgressBar.tsx +1 -2
  277. package/tui/src/components/design-system/Ratchet.tsx +1 -2
  278. package/tui/src/components/design-system/StatusIcon.tsx +1 -2
  279. package/tui/src/components/design-system/Tabs.tsx +1 -2
  280. package/tui/src/components/design-system/ThemeProvider.tsx +1 -2
  281. package/tui/src/components/design-system/ThemedBox.tsx +1 -2
  282. package/tui/src/components/design-system/ThemedText.tsx +1 -2
  283. package/tui/src/components/diff/DiffDetailView.tsx +1 -2
  284. package/tui/src/components/diff/DiffDialog.tsx +1 -2
  285. package/tui/src/components/diff/DiffFileList.tsx +1 -2
  286. package/tui/src/components/grove/Grove.tsx +0 -1
  287. package/tui/src/components/hooks/HooksConfigMenu.tsx +0 -1
  288. package/tui/src/components/hooks/PromptDialog.tsx +1 -2
  289. package/tui/src/components/hooks/SelectEventMode.tsx +0 -1
  290. package/tui/src/components/hooks/SelectHookMode.tsx +0 -1
  291. package/tui/src/components/hooks/SelectMatcherMode.tsx +0 -1
  292. package/tui/src/components/hooks/ViewHookMode.tsx +0 -1
  293. package/tui/src/components/mcp/CapabilitiesSection.tsx +1 -2
  294. package/tui/src/components/mcp/ElicitationDialog.tsx +0 -1
  295. package/tui/src/components/mcp/MCPAgentServerMenu.tsx +1 -2
  296. package/tui/src/components/mcp/MCPListPanel.tsx +0 -1
  297. package/tui/src/components/mcp/MCPReconnect.tsx +1 -2
  298. package/tui/src/components/mcp/MCPRemoteServerMenu.tsx +2 -3
  299. package/tui/src/components/mcp/MCPSettings.tsx +0 -1
  300. package/tui/src/components/mcp/MCPStdioServerMenu.tsx +1 -2
  301. package/tui/src/components/mcp/MCPToolDetailView.tsx +1 -2
  302. package/tui/src/components/mcp/MCPToolListView.tsx +1 -2
  303. package/tui/src/components/mcp/McpParsingWarnings.tsx +0 -1
  304. package/tui/src/components/mcp/utils/reconnectHelpers.tsx +1 -2
  305. package/tui/src/components/memory/MemoryFileSelector.tsx +1 -2
  306. package/tui/src/components/memory/MemoryUpdateNotification.tsx +1 -2
  307. package/tui/src/components/messageActions.tsx +1 -2
  308. package/tui/src/components/messages/AdvisorMessage.tsx +1 -2
  309. package/tui/src/components/messages/AssistantRedactedThinkingMessage.tsx +1 -2
  310. package/tui/src/components/messages/AssistantThinkingMessage.tsx +1 -2
  311. package/tui/src/components/messages/AssistantToolUseMessage.tsx +0 -1
  312. package/tui/src/components/messages/AttachmentMessage.tsx +1 -2
  313. package/tui/src/components/messages/CollapsedReadSearchContent.tsx +1 -2
  314. package/tui/src/components/messages/CompactBoundaryMessage.tsx +1 -2
  315. package/tui/src/components/messages/GroupedToolUseContent.tsx +1 -2
  316. package/tui/src/components/messages/HighlightedThinkingText.tsx +1 -2
  317. package/tui/src/components/messages/HookProgressMessage.tsx +1 -2
  318. package/tui/src/components/messages/PlanApprovalMessage.tsx +1 -2
  319. package/tui/src/components/messages/RateLimitMessage.tsx +1 -2
  320. package/tui/src/components/messages/ShutdownMessage.tsx +1 -2
  321. package/tui/src/components/messages/SystemAPIErrorMessage.tsx +1 -2
  322. package/tui/src/components/messages/SystemTextMessage.tsx +1 -2
  323. package/tui/src/components/messages/TaskAssignmentMessage.tsx +1 -2
  324. package/tui/src/components/messages/UserAgentNotificationMessage.tsx +1 -2
  325. package/tui/src/components/messages/UserBashInputMessage.tsx +1 -2
  326. package/tui/src/components/messages/UserBashOutputMessage.tsx +1 -2
  327. package/tui/src/components/messages/UserChannelMessage.tsx +1 -2
  328. package/tui/src/components/messages/UserCommandMessage.tsx +1 -2
  329. package/tui/src/components/messages/UserImageMessage.tsx +1 -2
  330. package/tui/src/components/messages/UserLocalCommandOutputMessage.tsx +1 -2
  331. package/tui/src/components/messages/UserMemoryInputMessage.tsx +1 -2
  332. package/tui/src/components/messages/UserPlanMessage.tsx +1 -2
  333. package/tui/src/components/messages/UserPromptMessage.tsx +1 -2
  334. package/tui/src/components/messages/UserResourceUpdateMessage.tsx +1 -2
  335. package/tui/src/components/messages/UserTeammateMessage.tsx +1 -2
  336. package/tui/src/components/messages/UserTextMessage.tsx +1 -2
  337. package/tui/src/components/messages/UserToolResultMessage/RejectedPlanMessage.tsx +0 -1
  338. package/tui/src/components/messages/UserToolResultMessage/RejectedToolUseMessage.tsx +1 -2
  339. package/tui/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.tsx +1 -2
  340. package/tui/src/components/messages/UserToolResultMessage/UserToolErrorMessage.tsx +1 -2
  341. package/tui/src/components/messages/UserToolResultMessage/UserToolRejectMessage.tsx +1 -2
  342. package/tui/src/components/messages/UserToolResultMessage/UserToolResultMessage.tsx +1 -2
  343. package/tui/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx +1 -2
  344. package/tui/src/components/messages/UserToolResultMessage/utils.tsx +0 -1
  345. package/tui/src/components/messages/teamMemCollapsed.tsx +1 -2
  346. package/tui/src/components/permissions/AskUserQuestionPermissionRequest/AskUserQuestionPermissionRequest.tsx +1 -2
  347. package/tui/src/components/permissions/AskUserQuestionPermissionRequest/PreviewBox.tsx +1 -2
  348. package/tui/src/components/permissions/AskUserQuestionPermissionRequest/PreviewQuestionView.tsx +1 -2
  349. package/tui/src/components/permissions/AskUserQuestionPermissionRequest/QuestionNavigationBar.tsx +1 -2
  350. package/tui/src/components/permissions/AskUserQuestionPermissionRequest/QuestionView.tsx +1 -2
  351. package/tui/src/components/permissions/AskUserQuestionPermissionRequest/SubmitQuestionsView.tsx +1 -2
  352. package/tui/src/components/permissions/BashPermissionRequest/BashPermissionRequest.tsx +1 -2
  353. package/tui/src/components/permissions/BashPermissionRequest/bashToolUseOptions.tsx +0 -1
  354. package/tui/src/components/permissions/ComputerUseApproval/ComputerUseApproval.tsx +0 -1
  355. package/tui/src/components/permissions/EnterPlanModePermissionRequest/EnterPlanModePermissionRequest.tsx +0 -1
  356. package/tui/src/components/permissions/ExitPlanModePermissionRequest/ExitPlanModePermissionRequest.tsx +0 -1
  357. package/tui/src/components/permissions/FallbackPermissionRequest.tsx +1 -2
  358. package/tui/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +1 -2
  359. package/tui/src/components/permissions/FilePermissionDialog/FilePermissionDialog.tsx +1 -2
  360. package/tui/src/components/permissions/FilePermissionDialog/permissionOptions.tsx +0 -1
  361. package/tui/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +1 -2
  362. package/tui/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +1 -2
  363. package/tui/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +1 -2
  364. package/tui/src/components/permissions/NotebookEditPermissionRequest/NotebookEditPermissionRequest.tsx +1 -2
  365. package/tui/src/components/permissions/NotebookEditPermissionRequest/NotebookEditToolDiff.tsx +1 -2
  366. package/tui/src/components/permissions/PermissionDecisionDebugInfo.tsx +1 -2
  367. package/tui/src/components/permissions/PermissionDialog.tsx +1 -2
  368. package/tui/src/components/permissions/PermissionExplanation.tsx +1 -2
  369. package/tui/src/components/permissions/PermissionPrompt.tsx +0 -1
  370. package/tui/src/components/permissions/PermissionRequest.tsx +0 -1
  371. package/tui/src/components/permissions/PermissionRequestTitle.tsx +1 -2
  372. package/tui/src/components/permissions/PermissionRuleExplanation.tsx +1 -2
  373. package/tui/src/components/permissions/PowerShellPermissionRequest/PowerShellPermissionRequest.tsx +1 -2
  374. package/tui/src/components/permissions/PowerShellPermissionRequest/powershellToolUseOptions.tsx +0 -1
  375. package/tui/src/components/permissions/SandboxPermissionRequest.tsx +0 -1
  376. package/tui/src/components/permissions/SedEditPermissionRequest/SedEditPermissionRequest.tsx +1 -2
  377. package/tui/src/components/permissions/SkillPermissionRequest/SkillPermissionRequest.tsx +0 -1
  378. package/tui/src/components/permissions/WebFetchPermissionRequest/WebFetchPermissionRequest.tsx +0 -1
  379. package/tui/src/components/permissions/WorkerBadge.tsx +1 -2
  380. package/tui/src/components/permissions/WorkerPendingPermission.tsx +1 -2
  381. package/tui/src/components/permissions/rules/AddPermissionRules.tsx +0 -1
  382. package/tui/src/components/permissions/rules/AddWorkspaceDirectory.tsx +0 -1
  383. package/tui/src/components/permissions/rules/PermissionRuleDescription.tsx +1 -2
  384. package/tui/src/components/permissions/rules/PermissionRuleInput.tsx +1 -2
  385. package/tui/src/components/permissions/rules/PermissionRuleList.tsx +0 -1
  386. package/tui/src/components/permissions/rules/RecentDenialsTab.tsx +1 -2
  387. package/tui/src/components/permissions/rules/RemoveWorkspaceDirectory.tsx +0 -1
  388. package/tui/src/components/permissions/rules/WorkspaceTab.tsx +1 -2
  389. package/tui/src/components/permissions/shellPermissionHelpers.tsx +1 -2
  390. package/tui/src/components/sandbox/SandboxConfigTab.tsx +1 -2
  391. package/tui/src/components/sandbox/SandboxDependenciesTab.tsx +1 -2
  392. package/tui/src/components/sandbox/SandboxDoctorSection.tsx +1 -2
  393. package/tui/src/components/sandbox/SandboxOverridesTab.tsx +0 -1
  394. package/tui/src/components/sandbox/SandboxSettings.tsx +0 -1
  395. package/tui/src/components/shell/ExpandShellOutputContext.tsx +1 -2
  396. package/tui/src/components/shell/OutputLine.tsx +1 -2
  397. package/tui/src/components/shell/ShellProgressMessage.tsx +1 -2
  398. package/tui/src/components/shell/ShellTimeDisplay.tsx +1 -2
  399. package/tui/src/components/skills/SkillsMenu.tsx +0 -1
  400. package/tui/src/components/tasks/AsyncAgentDetailDialog.tsx +1 -2
  401. package/tui/src/components/tasks/BackgroundTask.tsx +1 -2
  402. package/tui/src/components/tasks/BackgroundTaskStatus.tsx +1 -2
  403. package/tui/src/components/tasks/BackgroundTasksDialog.tsx +1 -2
  404. package/tui/src/components/tasks/DreamDetailDialog.tsx +1 -2
  405. package/tui/src/components/tasks/InProcessTeammateDetailDialog.tsx +1 -2
  406. package/tui/src/components/tasks/RemoteSessionDetailDialog.tsx +0 -1
  407. package/tui/src/components/tasks/RemoteSessionProgress.tsx +1 -2
  408. package/tui/src/components/tasks/ShellDetailDialog.tsx +1 -2
  409. package/tui/src/components/tasks/ShellProgress.tsx +1 -2
  410. package/tui/src/components/tasks/renderToolActivity.tsx +1 -2
  411. package/tui/src/components/tasks/taskStatusUtils.tsx +1 -2
  412. package/tui/src/components/teams/TeamStatus.tsx +1 -2
  413. package/tui/src/components/teams/TeamsDialog.tsx +1 -2
  414. package/tui/src/components/ui/OrderedList.tsx +1 -2
  415. package/tui/src/components/ui/OrderedListItem.tsx +1 -2
  416. package/tui/src/components/ui/TreeSelect.tsx +1 -2
  417. package/tui/src/components/wizard/WizardDialogLayout.tsx +1 -2
  418. package/tui/src/components/wizard/WizardNavigationFooter.tsx +1 -2
  419. package/tui/src/components/wizard/WizardProvider.tsx +1 -2
  420. package/tui/src/context/QueuedMessageContext.tsx +1 -2
  421. package/tui/src/context/fpsMetrics.tsx +1 -2
  422. package/tui/src/context/mailbox.tsx +1 -2
  423. package/tui/src/context/modalContext.tsx +1 -2
  424. package/tui/src/context/notifications.tsx +1 -2
  425. package/tui/src/context/overlayContext.tsx +1 -2
  426. package/tui/src/context/promptOverlayContext.tsx +1 -2
  427. package/tui/src/context/stats.tsx +1 -2
  428. package/tui/src/context/voice.tsx +1 -2
  429. package/tui/src/dialogLaunchers.tsx +0 -1
  430. package/tui/src/entrypoints/cli.tsx +0 -1
  431. package/tui/src/hooks/notifs/useCanSwitchToExistingSubscription.tsx +0 -1
  432. package/tui/src/hooks/notifs/useDeprecationWarningNotification.tsx +1 -2
  433. package/tui/src/hooks/notifs/useFastModeNotification.tsx +1 -2
  434. package/tui/src/hooks/notifs/useIDEStatusIndicator.tsx +1 -2
  435. package/tui/src/hooks/notifs/useInstallMessages.tsx +1 -2
  436. package/tui/src/hooks/notifs/useLspInitializationNotification.tsx +1 -2
  437. package/tui/src/hooks/notifs/useMcpConnectivityStatus.tsx +0 -1
  438. package/tui/src/hooks/notifs/useModelMigrationNotifications.tsx +1 -2
  439. package/tui/src/hooks/notifs/useNpmDeprecationNotification.tsx +1 -2
  440. package/tui/src/hooks/notifs/usePluginAutoupdateNotification.tsx +1 -2
  441. package/tui/src/hooks/notifs/usePluginInstallationStatus.tsx +1 -2
  442. package/tui/src/hooks/notifs/useRateLimitWarningNotification.tsx +1 -2
  443. package/tui/src/hooks/notifs/useSettingsErrors.tsx +1 -2
  444. package/tui/src/hooks/useApiKeyVerification.ts +7 -7
  445. package/tui/src/hooks/useArrowKeyHistory.tsx +1 -2
  446. package/tui/src/hooks/useCanUseTool.tsx +0 -1
  447. package/tui/src/hooks/useChromeExtensionNotification.tsx +0 -1
  448. package/tui/src/hooks/useClaudeCodeHintRecommendation.tsx +1 -2
  449. package/tui/src/hooks/useCommandKeybindings.tsx +1 -2
  450. package/tui/src/hooks/useGlobalKeybindings.tsx +1 -2
  451. package/tui/src/hooks/useIDEIntegration.tsx +1 -2
  452. package/tui/src/hooks/useLspPluginRecommendation.tsx +1 -2
  453. package/tui/src/hooks/useOfficialMarketplaceNotification.tsx +0 -1
  454. package/tui/src/hooks/usePluginRecommendationBase.tsx +1 -2
  455. package/tui/src/hooks/usePromptsFromClaudeInChrome.tsx +1 -2
  456. package/tui/src/hooks/useReplBridge.tsx +1 -2
  457. package/tui/src/hooks/useTypeahead.tsx +0 -1
  458. package/tui/src/hooks/useVoiceIntegration.tsx +1 -2
  459. package/tui/src/ink/Ansi.tsx +1 -2
  460. package/tui/src/ink/components/AlternateScreen.tsx +1 -2
  461. package/tui/src/ink/components/App.tsx +0 -1
  462. package/tui/src/ink/components/Box.tsx +1 -2
  463. package/tui/src/ink/components/Button.tsx +1 -2
  464. package/tui/src/ink/components/ClockContext.tsx +1 -2
  465. package/tui/src/ink/components/ErrorOverview.tsx +1 -2
  466. package/tui/src/ink/components/Link.tsx +1 -2
  467. package/tui/src/ink/components/Newline.tsx +1 -2
  468. package/tui/src/ink/components/NoSelect.tsx +1 -2
  469. package/tui/src/ink/components/RawAnsi.tsx +1 -2
  470. package/tui/src/ink/components/ScrollBox.tsx +1 -2
  471. package/tui/src/ink/components/Spacer.tsx +1 -2
  472. package/tui/src/ink/components/TerminalFocusContext.tsx +1 -2
  473. package/tui/src/ink/components/TerminalSizeContext.tsx +1 -2
  474. package/tui/src/ink/components/Text.tsx +1 -2
  475. package/tui/src/ink/ink.tsx +0 -1
  476. package/tui/src/interactiveHelpers.tsx +0 -1
  477. package/tui/src/keybindings/KeybindingContext.tsx +1 -2
  478. package/tui/src/keybindings/KeybindingProviderSetup.tsx +1 -2
  479. package/tui/src/main.tsx +0 -1
  480. package/tui/src/moreright/useMoreRight.tsx +1 -2
  481. package/tui/src/replLauncher.tsx +1 -2
  482. package/tui/src/screens/Doctor.tsx +0 -1
  483. package/tui/src/screens/REPL.tsx +0 -1
  484. package/tui/src/screens/ResumeConversation.tsx +0 -1
  485. package/tui/src/services/mcp/MCPConnectionManager.tsx +1 -2
  486. package/tui/src/services/mcp/claudeai.ts +1 -1
  487. package/tui/src/services/mcpServerApproval.tsx +1 -2
  488. package/tui/src/services/oauth/client.ts +16 -14
  489. package/tui/src/services/oauth/getOauthProfile.ts +2 -2
  490. package/tui/src/services/oauth/index.ts +12 -16
  491. package/tui/src/services/policyLimits/index.ts +3 -3
  492. package/tui/src/services/remoteManagedSettings/index.ts +3 -3
  493. package/tui/src/services/remoteManagedSettings/securityCheck.tsx +1 -2
  494. package/tui/src/services/remoteManagedSettings/syncCache.ts +3 -3
  495. package/tui/src/services/voiceStreamSTT.ts +2 -2
  496. package/tui/src/state/AppState.tsx +1 -2
  497. package/tui/src/tasks/InProcessTeammateTask/InProcessTeammateTask.tsx +1 -2
  498. package/tui/src/tasks/LocalAgentTask/LocalAgentTask.tsx +1 -2
  499. package/tui/src/tasks/LocalShellTask/LocalShellTask.tsx +1 -2
  500. package/tui/src/tasks/RemoteAgentTask/RemoteAgentTask.tsx +0 -1
  501. package/tui/src/tools/AgentTool/UI.tsx +1 -2
  502. package/tui/src/tools/BashTool/BashToolResultMessage.tsx +0 -1
  503. package/tui/src/tools/BashTool/UI.tsx +1 -2
  504. package/tui/src/tools/BriefTool/UI.tsx +0 -1
  505. package/tui/src/tools/ConfigTool/ConfigTool.ts +2 -2
  506. package/tui/src/tools/ConfigTool/UI.tsx +1 -2
  507. package/tui/src/tools/EnterPlanModeTool/UI.tsx +0 -1
  508. package/tui/src/tools/EnterWorktreeTool/UI.tsx +1 -2
  509. package/tui/src/tools/ExitPlanModeTool/UI.tsx +0 -1
  510. package/tui/src/tools/ExitWorktreeTool/UI.tsx +1 -2
  511. package/tui/src/tools/FileEditTool/UI.tsx +1 -2
  512. package/tui/src/tools/FileReadTool/UI.tsx +1 -2
  513. package/tui/src/tools/FileWriteTool/UI.tsx +1 -2
  514. package/tui/src/tools/GlobTool/UI.tsx +1 -2
  515. package/tui/src/tools/GrepTool/UI.tsx +1 -2
  516. package/tui/src/tools/LSPTool/UI.tsx +1 -2
  517. package/tui/src/tools/ListMcpResourcesTool/UI.tsx +1 -2
  518. package/tui/src/tools/MCPTool/UI.tsx +1 -2
  519. package/tui/src/tools/NotebookEditTool/UI.tsx +1 -2
  520. package/tui/src/tools/PowerShellTool/UI.tsx +0 -1
  521. package/tui/src/tools/ReadMcpResourceTool/UI.tsx +1 -2
  522. package/tui/src/tools/RemoteTriggerTool/UI.tsx +1 -2
  523. package/tui/src/tools/ScheduleCronTool/UI.tsx +1 -2
  524. package/tui/src/tools/SendMessageTool/UI.tsx +1 -2
  525. package/tui/src/tools/SkillTool/UI.tsx +1 -2
  526. package/tui/src/tools/TaskStopTool/UI.tsx +1 -2
  527. package/tui/src/tools/TeamCreateTool/UI.tsx +1 -2
  528. package/tui/src/tools/TeamDeleteTool/UI.tsx +1 -2
  529. package/tui/src/tools/WebFetchTool/UI.tsx +1 -2
  530. package/tui/src/tools/testing/TestingPermissionTool.tsx +1 -2
  531. package/tui/src/utils/auth.ts +8 -8
  532. package/tui/src/utils/autoRunIssue.tsx +1 -2
  533. package/tui/src/utils/billing.ts +2 -2
  534. package/tui/src/utils/computerUse/toolRendering.tsx +1 -2
  535. package/tui/src/utils/computerUse/wrapper.tsx +0 -1
  536. package/tui/src/utils/exportRenderer.tsx +1 -2
  537. package/tui/src/utils/fastMode.ts +2 -2
  538. package/tui/src/utils/highlightMatch.tsx +1 -2
  539. package/tui/src/utils/http.ts +2 -2
  540. package/tui/src/utils/managedEnv.ts +1 -1
  541. package/tui/src/utils/messages/systemInit.ts +2 -2
  542. package/tui/src/utils/plugins/performStartupChecks.tsx +1 -2
  543. package/tui/src/utils/preflightChecks.tsx +0 -1
  544. package/tui/src/utils/processUserInput/processBashCommand.tsx +1 -2
  545. package/tui/src/utils/processUserInput/processSlashCommand.tsx +0 -1
  546. package/tui/src/utils/staticRender.tsx +1 -2
  547. package/tui/src/utils/status.tsx +1 -2
  548. package/tui/src/utils/statusNoticeDefinitions.tsx +5 -6
  549. package/tui/src/utils/swarm/It2SetupPrompt.tsx +1 -2
  550. package/tui/src/utils/teleport.tsx +0 -1
  551. package/tui/src/voice/voiceModeEnabled.ts +3 -3
  552. package/uv.lock +1 -1
  553. package/src/ummaya/llm/_cc_reference/README.md +0 -104
  554. package/src/ummaya/llm/_cc_reference/api.ts +0 -721
  555. package/src/ummaya/llm/_cc_reference/claude.ts +0 -3422
  556. package/src/ummaya/llm/_cc_reference/client.ts +0 -392
  557. package/src/ummaya/llm/_cc_reference/emptyUsage.ts +0 -25
  558. package/src/ummaya/llm/_cc_reference/errors.ts +0 -1210
  559. package/src/ummaya/llm/_cc_reference/messages.ts +0 -5515
  560. package/src/ummaya/llm/_cc_reference/permissions.ts +0 -1489
  561. package/src/ummaya/llm/_cc_reference/prompts.ts +0 -917
  562. package/src/ummaya/llm/_cc_reference/query.ts +0 -1732
  563. package/src/ummaya/llm/_cc_reference/toolExecution.ts +0 -1748
  564. package/src/ummaya/llm/_cc_reference/toolOrchestration.ts +0 -191
  565. package/src/ummaya/llm/_cc_reference/toolResultStorage.ts +0 -1043
  566. package/src/ummaya/llm/_cc_reference/tools.ts +0 -392
@@ -1,1043 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0 (Anthropic upstream) — research-use mirror
2
- // Source: .references/claude-code-sourcemap/restored-src/src/utils/toolResultStorage.ts (CC 2.1.88)
3
-
4
- /**
5
- * Utility for persisting large tool results to disk instead of truncating them.
6
- */
7
-
8
- import type { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
9
- import { mkdir, writeFile } from 'fs/promises'
10
- import { join } from 'path'
11
- import { getOriginalCwd, getSessionId } from '../bootstrap/state.js'
12
- import {
13
- BYTES_PER_TOKEN,
14
- DEFAULT_MAX_RESULT_SIZE_CHARS,
15
- MAX_TOOL_RESULT_BYTES,
16
- MAX_TOOL_RESULTS_PER_MESSAGE_CHARS,
17
- } from '../constants/toolLimits.js'
18
- import { getFeatureValue_CACHED_MAY_BE_STALE } from '../services/analytics/growthbook.js'
19
- import { logEvent } from '../services/analytics/index.js'
20
- import { sanitizeToolNameForAnalytics } from '../services/analytics/metadata.js'
21
- import type { Message } from '../types/message.js'
22
- import { logForDebugging } from './debug.js'
23
- import { getErrnoCode, toError } from './errors.js'
24
- import { formatFileSize } from './format.js'
25
- import { logError } from './log.js'
26
- import { getProjectDir } from './sessionStorage.js'
27
- import { jsonStringify } from './slowOperations.js'
28
-
29
- // Subdirectory name for tool results within a session
30
- export const TOOL_RESULTS_SUBDIR = 'tool-results'
31
-
32
- // XML tag used to wrap persisted output messages
33
- export const PERSISTED_OUTPUT_TAG = '<persisted-output>'
34
- export const PERSISTED_OUTPUT_CLOSING_TAG = '</persisted-output>'
35
-
36
- // Message used when tool result content was cleared without persisting to file
37
- export const TOOL_RESULT_CLEARED_MESSAGE = '[Old tool result content cleared]'
38
-
39
- /**
40
- * GrowthBook override map: tool name -> persistence threshold (chars).
41
- * When a tool name is present in this map, that value is used directly as the
42
- * effective threshold, bypassing the Math.min() clamp against the 50k default.
43
- * Tools absent from the map use the hardcoded fallback.
44
- * Flag default is {} (no overrides == behavior unchanged).
45
- */
46
- const PERSIST_THRESHOLD_OVERRIDE_FLAG = 'tengu_satin_quoll'
47
-
48
- /**
49
- * Resolve the effective persistence threshold for a tool.
50
- * GrowthBook override wins when present; otherwise falls back to the declared
51
- * per-tool cap clamped by the global default.
52
- *
53
- * Defensive: GrowthBook's cache returns `cached !== undefined ? cached : default`,
54
- * so a flag served as `null` leaks through. We guard with optional chaining and a
55
- * typeof check so any non-object flag value (null, string, number) falls through
56
- * to the hardcoded default instead of throwing on index or returning 0.
57
- */
58
- export function getPersistenceThreshold(
59
- toolName: string,
60
- declaredMaxResultSizeChars: number,
61
- ): number {
62
- // Infinity = hard opt-out. Read self-bounds via maxTokens; persisting its
63
- // output to a file the model reads back with Read is circular. Checked
64
- // before the GB override so tengu_satin_quoll can't force it back on.
65
- if (!Number.isFinite(declaredMaxResultSizeChars)) {
66
- return declaredMaxResultSizeChars
67
- }
68
- const overrides = getFeatureValue_CACHED_MAY_BE_STALE<Record<
69
- string,
70
- number
71
- > | null>(PERSIST_THRESHOLD_OVERRIDE_FLAG, {})
72
- const override = overrides?.[toolName]
73
- if (
74
- typeof override === 'number' &&
75
- Number.isFinite(override) &&
76
- override > 0
77
- ) {
78
- return override
79
- }
80
- return Math.min(declaredMaxResultSizeChars, DEFAULT_MAX_RESULT_SIZE_CHARS)
81
- }
82
-
83
- // Result of persisting a tool result to disk
84
- export type PersistedToolResult = {
85
- filepath: string
86
- originalSize: number
87
- isJson: boolean
88
- preview: string
89
- hasMore: boolean
90
- }
91
-
92
- // Error result when persistence fails
93
- export type PersistToolResultError = {
94
- error: string
95
- }
96
-
97
- /**
98
- * Get the session directory (projectDir/sessionId)
99
- */
100
- function getSessionDir(): string {
101
- return join(getProjectDir(getOriginalCwd()), getSessionId())
102
- }
103
-
104
- /**
105
- * Get the tool results directory for this session (projectDir/sessionId/tool-results)
106
- */
107
- export function getToolResultsDir(): string {
108
- return join(getSessionDir(), TOOL_RESULTS_SUBDIR)
109
- }
110
-
111
- // Preview size in bytes for the reference message
112
- export const PREVIEW_SIZE_BYTES = 2000
113
-
114
- /**
115
- * Get the filepath where a tool result would be persisted.
116
- */
117
- export function getToolResultPath(id: string, isJson: boolean): string {
118
- const ext = isJson ? 'json' : 'txt'
119
- return join(getToolResultsDir(), `${id}.${ext}`)
120
- }
121
-
122
- /**
123
- * Ensure the session-specific tool results directory exists
124
- */
125
- export async function ensureToolResultsDir(): Promise<void> {
126
- try {
127
- await mkdir(getToolResultsDir(), { recursive: true })
128
- } catch {
129
- // Directory may already exist
130
- }
131
- }
132
-
133
- /**
134
- * Persist a tool result to disk and return information about the persisted file
135
- *
136
- * @param content - The tool result content to persist (string or array of content blocks)
137
- * @param toolUseId - The ID of the tool use that produced the result
138
- * @returns Information about the persisted file including filepath and preview
139
- */
140
- export async function persistToolResult(
141
- content: NonNullable<ToolResultBlockParam['content']>,
142
- toolUseId: string,
143
- ): Promise<PersistedToolResult | PersistToolResultError> {
144
- const isJson = Array.isArray(content)
145
-
146
- // Check for non-text content - we can only persist text blocks
147
- if (isJson) {
148
- const hasNonTextContent = content.some(block => block.type !== 'text')
149
- if (hasNonTextContent) {
150
- return {
151
- error: 'Cannot persist tool results containing non-text content',
152
- }
153
- }
154
- }
155
-
156
- await ensureToolResultsDir()
157
- const filepath = getToolResultPath(toolUseId, isJson)
158
- const contentStr = isJson ? jsonStringify(content, null, 2) : content
159
-
160
- // tool_use_id is unique per invocation and content is deterministic for a
161
- // given id, so skip if the file already exists. This prevents re-writing
162
- // the same content on every API turn when microcompact replays the
163
- // original messages. Use 'wx' instead of a stat-then-write race.
164
- try {
165
- await writeFile(filepath, contentStr, { encoding: 'utf-8', flag: 'wx' })
166
- logForDebugging(
167
- `Persisted tool result to ${filepath} (${formatFileSize(contentStr.length)})`,
168
- )
169
- } catch (error) {
170
- if (getErrnoCode(error) !== 'EEXIST') {
171
- logError(toError(error))
172
- return { error: getFileSystemErrorMessage(toError(error)) }
173
- }
174
- // EEXIST: already persisted on a prior turn, fall through to preview
175
- }
176
-
177
- // Generate a preview
178
- const { preview, hasMore } = generatePreview(contentStr, PREVIEW_SIZE_BYTES)
179
-
180
- return {
181
- filepath,
182
- originalSize: contentStr.length,
183
- isJson,
184
- preview,
185
- hasMore,
186
- }
187
- }
188
-
189
- /**
190
- * Build a message for large tool results with preview
191
- */
192
- export function buildLargeToolResultMessage(
193
- result: PersistedToolResult,
194
- ): string {
195
- let message = `${PERSISTED_OUTPUT_TAG}\n`
196
- message += `Output too large (${formatFileSize(result.originalSize)}). Full output saved to: ${result.filepath}\n\n`
197
- message += `Preview (first ${formatFileSize(PREVIEW_SIZE_BYTES)}):\n`
198
- message += result.preview
199
- message += result.hasMore ? '\n...\n' : '\n'
200
- message += PERSISTED_OUTPUT_CLOSING_TAG
201
- return message
202
- }
203
-
204
- /**
205
- * Process a tool result for inclusion in a message.
206
- * Maps the result to the API format and persists large results to disk.
207
- */
208
- export async function processToolResultBlock<T>(
209
- tool: {
210
- name: string
211
- maxResultSizeChars: number
212
- mapToolResultToToolResultBlockParam: (
213
- result: T,
214
- toolUseID: string,
215
- ) => ToolResultBlockParam
216
- },
217
- toolUseResult: T,
218
- toolUseID: string,
219
- ): Promise<ToolResultBlockParam> {
220
- const toolResultBlock = tool.mapToolResultToToolResultBlockParam(
221
- toolUseResult,
222
- toolUseID,
223
- )
224
- return maybePersistLargeToolResult(
225
- toolResultBlock,
226
- tool.name,
227
- getPersistenceThreshold(tool.name, tool.maxResultSizeChars),
228
- )
229
- }
230
-
231
- /**
232
- * Process a pre-mapped tool result block. Applies persistence for large results
233
- * without re-calling mapToolResultToToolResultBlockParam.
234
- */
235
- export async function processPreMappedToolResultBlock(
236
- toolResultBlock: ToolResultBlockParam,
237
- toolName: string,
238
- maxResultSizeChars: number,
239
- ): Promise<ToolResultBlockParam> {
240
- return maybePersistLargeToolResult(
241
- toolResultBlock,
242
- toolName,
243
- getPersistenceThreshold(toolName, maxResultSizeChars),
244
- )
245
- }
246
-
247
- /**
248
- * True when a tool_result's content is empty or effectively empty. Covers:
249
- * undefined/null/'', whitespace-only strings, empty arrays, and arrays whose
250
- * only blocks are text blocks with empty/whitespace text. Non-text blocks
251
- * (images, tool_reference) are treated as non-empty.
252
- */
253
- export function isToolResultContentEmpty(
254
- content: ToolResultBlockParam['content'],
255
- ): boolean {
256
- if (!content) return true
257
- if (typeof content === 'string') return content.trim() === ''
258
- if (!Array.isArray(content)) return false
259
- if (content.length === 0) return true
260
- return content.every(
261
- block =>
262
- typeof block === 'object' &&
263
- 'type' in block &&
264
- block.type === 'text' &&
265
- 'text' in block &&
266
- (typeof block.text !== 'string' || block.text.trim() === ''),
267
- )
268
- }
269
-
270
- /**
271
- * Handle large tool results by persisting to disk instead of truncating.
272
- * Returns the original block if no persistence needed, or a modified block
273
- * with the content replaced by a reference to the persisted file.
274
- */
275
- async function maybePersistLargeToolResult(
276
- toolResultBlock: ToolResultBlockParam,
277
- toolName: string,
278
- persistenceThreshold?: number,
279
- ): Promise<ToolResultBlockParam> {
280
- // Check size first before doing any async work - most tool results are small
281
- const content = toolResultBlock.content
282
-
283
- // inc-4586: Empty tool_result content at the prompt tail causes some models
284
- // (notably capybara) to emit the \n\nHuman: stop sequence and end their turn
285
- // with zero output. The server renderer inserts no \n\nAssistant: marker after
286
- // tool results, so a bare </function_results>\n\n pattern-matches to a turn
287
- // boundary. Several tools can legitimately produce empty output (silent-success
288
- // shell commands, MCP servers returning content:[], REPL statements, etc.).
289
- // Inject a short marker so the model always has something to react to.
290
- if (isToolResultContentEmpty(content)) {
291
- logEvent('tengu_tool_empty_result', {
292
- toolName: sanitizeToolNameForAnalytics(toolName),
293
- })
294
- return {
295
- ...toolResultBlock,
296
- content: `(${toolName} completed with no output)`,
297
- }
298
- }
299
- // Narrow after the emptiness guard — content is non-nullish past this point.
300
- if (!content) {
301
- return toolResultBlock
302
- }
303
-
304
- // Skip persistence for image content blocks - they need to be sent as-is to Claude
305
- if (hasImageBlock(content)) {
306
- return toolResultBlock
307
- }
308
-
309
- const size = contentSize(content)
310
-
311
- // Use tool-specific threshold if provided, otherwise fall back to global limit
312
- const threshold = persistenceThreshold ?? MAX_TOOL_RESULT_BYTES
313
- if (size <= threshold) {
314
- return toolResultBlock
315
- }
316
-
317
- // Persist the entire content as a unit
318
- const result = await persistToolResult(content, toolResultBlock.tool_use_id)
319
- if (isPersistError(result)) {
320
- // If persistence failed, return the original block unchanged
321
- return toolResultBlock
322
- }
323
-
324
- const message = buildLargeToolResultMessage(result)
325
-
326
- // Log analytics
327
- logEvent('tengu_tool_result_persisted', {
328
- toolName: sanitizeToolNameForAnalytics(toolName),
329
- originalSizeBytes: result.originalSize,
330
- persistedSizeBytes: message.length,
331
- estimatedOriginalTokens: Math.ceil(result.originalSize / BYTES_PER_TOKEN),
332
- estimatedPersistedTokens: Math.ceil(message.length / BYTES_PER_TOKEN),
333
- thresholdUsed: threshold,
334
- })
335
-
336
- return { ...toolResultBlock, content: message }
337
- }
338
-
339
- /**
340
- * Generate a preview of content, truncating at a newline boundary when possible.
341
- */
342
- export function generatePreview(
343
- content: string,
344
- maxBytes: number,
345
- ): { preview: string; hasMore: boolean } {
346
- if (content.length <= maxBytes) {
347
- return { preview: content, hasMore: false }
348
- }
349
-
350
- // Find the last newline within the limit to avoid cutting mid-line
351
- const truncated = content.slice(0, maxBytes)
352
- const lastNewline = truncated.lastIndexOf('\n')
353
-
354
- // If we found a newline reasonably close to the limit, use it
355
- // Otherwise fall back to the exact limit
356
- const cutPoint = lastNewline > maxBytes * 0.5 ? lastNewline : maxBytes
357
-
358
- return { preview: content.slice(0, cutPoint), hasMore: true }
359
- }
360
-
361
- /**
362
- * Type guard to check if persist result is an error
363
- */
364
- export function isPersistError(
365
- result: PersistedToolResult | PersistToolResultError,
366
- ): result is PersistToolResultError {
367
- return 'error' in result
368
- }
369
-
370
- // --- Message-level aggregate tool result budget ---
371
- //
372
- // Tracks replacement state across turns so enforceToolResultBudget makes the
373
- // same choices every time (preserves prompt cache prefix).
374
-
375
- /**
376
- * Per-conversation-thread state for the aggregate tool result budget.
377
- * State must be stable to preserve prompt cache:
378
- * - seenIds: results that have passed through the budget check (replaced
379
- * or not). Once seen, a result's fate is frozen for the conversation.
380
- * - replacements: subset of seenIds that were persisted to disk and
381
- * replaced with previews, mapped to the exact preview string shown to
382
- * the model. Re-application is a Map lookup — no file I/O, guaranteed
383
- * byte-identical, cannot fail.
384
- *
385
- * Lifecycle: one instance per conversation thread, carried on ToolUseContext.
386
- * Main thread: REPL provisions once, never resets — stale entries after
387
- * /clear, rewind, resume, or compact are never looked up (tool_use_ids are
388
- * UUIDs) so they're harmless. Subagents: createSubagentContext clones the
389
- * parent's state by default (cache-sharing forks like agentSummary need
390
- * identical decisions), or resumeAgentBackground threads one reconstructed
391
- * from sidechain records.
392
- */
393
- export type ContentReplacementState = {
394
- seenIds: Set<string>
395
- replacements: Map<string, string>
396
- }
397
-
398
- export function createContentReplacementState(): ContentReplacementState {
399
- return { seenIds: new Set(), replacements: new Map() }
400
- }
401
-
402
- /**
403
- * Clone replacement state for a cache-sharing fork (e.g. agentSummary).
404
- * The fork needs state identical to the source at fork time so
405
- * enforceToolResultBudget makes the same choices → same wire prefix →
406
- * prompt cache hit. Mutating the clone does not affect the source.
407
- */
408
- export function cloneContentReplacementState(
409
- source: ContentReplacementState,
410
- ): ContentReplacementState {
411
- return {
412
- seenIds: new Set(source.seenIds),
413
- replacements: new Map(source.replacements),
414
- }
415
- }
416
-
417
- /**
418
- * Resolve the per-message aggregate budget limit. GrowthBook override
419
- * (tengu_hawthorn_window) wins when present and a finite positive number;
420
- * otherwise falls back to the hardcoded constant. Defensive typeof/finite
421
- * check: GrowthBook's cache returns `cached !== undefined ? cached : default`,
422
- * so a flag served as null/string/NaN leaks through.
423
- */
424
- export function getPerMessageBudgetLimit(): number {
425
- const override = getFeatureValue_CACHED_MAY_BE_STALE<number | null>(
426
- 'tengu_hawthorn_window',
427
- null,
428
- )
429
- if (
430
- typeof override === 'number' &&
431
- Number.isFinite(override) &&
432
- override > 0
433
- ) {
434
- return override
435
- }
436
- return MAX_TOOL_RESULTS_PER_MESSAGE_CHARS
437
- }
438
-
439
- /**
440
- * Provision replacement state for a new conversation thread.
441
- *
442
- * Encapsulates the feature-flag gate + reconstruct-vs-fresh choice:
443
- * - Flag off → undefined (query.ts skips enforcement entirely)
444
- * - No initialMessages (cold start) → fresh
445
- * - initialMessages present → reconstruct (freeze all candidate IDs so the
446
- * budget never replaces content the model already saw unreplaced). Empty
447
- * or absent records freeze everything; non-empty records additionally
448
- * populate the replacements Map for byte-identical re-apply.
449
- */
450
- export function provisionContentReplacementState(
451
- initialMessages?: Message[],
452
- initialContentReplacements?: ContentReplacementRecord[],
453
- ): ContentReplacementState | undefined {
454
- const enabled = getFeatureValue_CACHED_MAY_BE_STALE(
455
- 'tengu_hawthorn_steeple',
456
- false,
457
- )
458
- if (!enabled) return undefined
459
- if (initialMessages) {
460
- return reconstructContentReplacementState(
461
- initialMessages,
462
- initialContentReplacements ?? [],
463
- )
464
- }
465
- return createContentReplacementState()
466
- }
467
-
468
- /**
469
- * Serializable record of one content-replacement decision. Written to the
470
- * transcript as a ContentReplacementEntry so decisions survive resume.
471
- * Discriminated by `kind` so future replacement mechanisms (user text,
472
- * offloaded images) can share the same transcript entry type.
473
- *
474
- * `replacement` is the exact string the model saw — stored rather than
475
- * derived on resume so code changes to the preview template, size formatting,
476
- * or path layout can't silently break prompt cache.
477
- */
478
- export type ContentReplacementRecord = {
479
- kind: 'tool-result'
480
- toolUseId: string
481
- replacement: string
482
- }
483
-
484
- export type ToolResultReplacementRecord = Extract<
485
- ContentReplacementRecord,
486
- { kind: 'tool-result' }
487
- >
488
-
489
- type ToolResultCandidate = {
490
- toolUseId: string
491
- content: NonNullable<ToolResultBlockParam['content']>
492
- size: number
493
- }
494
-
495
- type CandidatePartition = {
496
- mustReapply: Array<ToolResultCandidate & { replacement: string }>
497
- frozen: ToolResultCandidate[]
498
- fresh: ToolResultCandidate[]
499
- }
500
-
501
- function isContentAlreadyCompacted(
502
- content: ToolResultBlockParam['content'],
503
- ): boolean {
504
- // All budget-produced content starts with the tag (buildLargeToolResultMessage).
505
- // `.startsWith()` avoids false-positives when the tag appears anywhere else
506
- // in the content (e.g., reading this source file).
507
- return typeof content === 'string' && content.startsWith(PERSISTED_OUTPUT_TAG)
508
- }
509
-
510
- function hasImageBlock(
511
- content: NonNullable<ToolResultBlockParam['content']>,
512
- ): boolean {
513
- return (
514
- Array.isArray(content) &&
515
- content.some(
516
- b => typeof b === 'object' && 'type' in b && b.type === 'image',
517
- )
518
- )
519
- }
520
-
521
- function contentSize(
522
- content: NonNullable<ToolResultBlockParam['content']>,
523
- ): number {
524
- if (typeof content === 'string') return content.length
525
- // Sum text-block lengths directly. Slightly under-counts vs serialized
526
- // (no JSON framing), but the budget is a rough token heuristic anyway.
527
- // Avoids allocating a content-sized string every enforcement pass.
528
- return content.reduce(
529
- (sum, b) => sum + (b.type === 'text' ? b.text.length : 0),
530
- 0,
531
- )
532
- }
533
-
534
- /**
535
- * Walk messages and build tool_use_id → tool_name from assistant tool_use
536
- * blocks. tool_use always precedes its tool_result (model calls, then result
537
- * arrives), so by the time budget enforcement sees a result, its name is known.
538
- */
539
- function buildToolNameMap(messages: Message[]): Map<string, string> {
540
- const map = new Map<string, string>()
541
- for (const message of messages) {
542
- if (message.type !== 'assistant') continue
543
- const content = message.message.content
544
- if (!Array.isArray(content)) continue
545
- for (const block of content) {
546
- if (block.type === 'tool_use') {
547
- map.set(block.id, block.name)
548
- }
549
- }
550
- }
551
- return map
552
- }
553
-
554
- /**
555
- * Extract candidate tool_result blocks from a single user message: blocks
556
- * that are non-empty, non-image, and not already compacted by tag (i.e. by
557
- * the per-tool limit, or an earlier iteration of this same query call).
558
- * Returns [] for messages with no eligible blocks.
559
- */
560
- function collectCandidatesFromMessage(message: Message): ToolResultCandidate[] {
561
- if (message.type !== 'user' || !Array.isArray(message.message.content)) {
562
- return []
563
- }
564
- return message.message.content.flatMap(block => {
565
- if (block.type !== 'tool_result' || !block.content) return []
566
- if (isContentAlreadyCompacted(block.content)) return []
567
- if (hasImageBlock(block.content)) return []
568
- return [
569
- {
570
- toolUseId: block.tool_use_id,
571
- content: block.content,
572
- size: contentSize(block.content),
573
- },
574
- ]
575
- })
576
- }
577
-
578
- /**
579
- * Extract candidate tool_result blocks grouped by API-level user message.
580
- *
581
- * normalizeMessagesForAPI merges consecutive user messages into one
582
- * (Bedrock compat; 1P does the same server-side), so parallel tool
583
- * results that arrive as N separate user messages in our state become
584
- * ONE user message on the wire. The budget must group the same way or
585
- * it would see N under-budget messages instead of one over-budget
586
- * message and fail to enforce exactly when it matters most.
587
- *
588
- * A "group" is a maximal run of user messages NOT separated by an
589
- * assistant message. Only assistant messages create wire-level
590
- * boundaries — normalizeMessagesForAPI filters out progress entirely
591
- * and merges attachment / system(local_command) INTO adjacent user
592
- * blocks, so those types do NOT break groups here either.
593
- *
594
- * This matters for abort-during-parallel-tools paths: agent_progress
595
- * messages (non-ephemeral, persisted in REPL state) can interleave
596
- * between fresh tool_result messages. If we flushed on progress, those
597
- * tool_results would split into under-budget groups, slip through
598
- * unreplaced, get frozen, then be merged by normalizeMessagesForAPI
599
- * into one over-budget wire message — defeating the feature.
600
- *
601
- * Only groups with at least one eligible candidate are returned.
602
- */
603
- function collectCandidatesByMessage(
604
- messages: Message[],
605
- ): ToolResultCandidate[][] {
606
- const groups: ToolResultCandidate[][] = []
607
- let current: ToolResultCandidate[] = []
608
-
609
- const flush = () => {
610
- if (current.length > 0) groups.push(current)
611
- current = []
612
- }
613
-
614
- // Track all assistant message.ids seen so far — same-ID fragments are
615
- // merged by normalizeMessagesForAPI (messages.ts ~2126 walks back PAST
616
- // different-ID assistants via `continue`), so any re-appearance of a
617
- // previously-seen ID must NOT create a group boundary. Two scenarios:
618
- // • Consecutive: streamingToolExecution yields one AssistantMessage per
619
- // content_block_stop (same id); a fast tool drains between blocks;
620
- // abort/hook-stop leaves [asst(X), user(trA), asst(X), user(trB)].
621
- // • Interleaved: coordinator/teammate streams mix different responses
622
- // so [asst(X), user(trA), asst(Y), user(trB), asst(X), user(trC)].
623
- // In both, normalizeMessagesForAPI merges the X fragments into one wire
624
- // assistant, and their following tool_results merge into one wire user
625
- // message — so the budget must see them as one group too.
626
- const seenAsstIds = new Set<string>()
627
- for (const message of messages) {
628
- if (message.type === 'user') {
629
- current.push(...collectCandidatesFromMessage(message))
630
- } else if (message.type === 'assistant') {
631
- if (!seenAsstIds.has(message.message.id)) {
632
- flush()
633
- seenAsstIds.add(message.message.id)
634
- }
635
- }
636
- // progress / attachment / system are filtered or merged by
637
- // normalizeMessagesForAPI — they don't create wire boundaries.
638
- }
639
- flush()
640
-
641
- return groups
642
- }
643
-
644
- /**
645
- * Partition candidates by their prior decision state:
646
- * - mustReapply: previously replaced → re-apply the cached replacement for
647
- * prefix stability
648
- * - frozen: previously seen and left unreplaced → off-limits (replacing
649
- * now would change a prefix that was already cached)
650
- * - fresh: never seen → eligible for new replacement decisions
651
- */
652
- function partitionByPriorDecision(
653
- candidates: ToolResultCandidate[],
654
- state: ContentReplacementState,
655
- ): CandidatePartition {
656
- return candidates.reduce<CandidatePartition>(
657
- (acc, c) => {
658
- const replacement = state.replacements.get(c.toolUseId)
659
- if (replacement !== undefined) {
660
- acc.mustReapply.push({ ...c, replacement })
661
- } else if (state.seenIds.has(c.toolUseId)) {
662
- acc.frozen.push(c)
663
- } else {
664
- acc.fresh.push(c)
665
- }
666
- return acc
667
- },
668
- { mustReapply: [], frozen: [], fresh: [] },
669
- )
670
- }
671
-
672
- /**
673
- * Pick the largest fresh results to replace until the model-visible total
674
- * (frozen + remaining fresh) is at or under budget, or fresh is exhausted.
675
- * If frozen results alone exceed budget we accept the overage — microcompact
676
- * will eventually clear them.
677
- */
678
- function selectFreshToReplace(
679
- fresh: ToolResultCandidate[],
680
- frozenSize: number,
681
- limit: number,
682
- ): ToolResultCandidate[] {
683
- const sorted = [...fresh].sort((a, b) => b.size - a.size)
684
- const selected: ToolResultCandidate[] = []
685
- let remaining = frozenSize + fresh.reduce((sum, c) => sum + c.size, 0)
686
- for (const c of sorted) {
687
- if (remaining <= limit) break
688
- selected.push(c)
689
- // We don't know the replacement size until after persist, but previews
690
- // are ~2K and results hitting this path are much larger, so subtracting
691
- // the full size is a close approximation for selection purposes.
692
- remaining -= c.size
693
- }
694
- return selected
695
- }
696
-
697
- /**
698
- * Return a new Message[] where each tool_result block whose id appears in
699
- * replacementMap has its content replaced. Messages and blocks with no
700
- * replacements are passed through by reference.
701
- */
702
- function replaceToolResultContents(
703
- messages: Message[],
704
- replacementMap: Map<string, string>,
705
- ): Message[] {
706
- return messages.map(message => {
707
- if (message.type !== 'user' || !Array.isArray(message.message.content)) {
708
- return message
709
- }
710
- const content = message.message.content
711
- const needsReplace = content.some(
712
- b => b.type === 'tool_result' && replacementMap.has(b.tool_use_id),
713
- )
714
- if (!needsReplace) return message
715
- return {
716
- ...message,
717
- message: {
718
- ...message.message,
719
- content: content.map(block => {
720
- if (block.type !== 'tool_result') return block
721
- const replacement = replacementMap.get(block.tool_use_id)
722
- return replacement === undefined
723
- ? block
724
- : { ...block, content: replacement }
725
- }),
726
- },
727
- }
728
- })
729
- }
730
-
731
- async function buildReplacement(
732
- candidate: ToolResultCandidate,
733
- ): Promise<{ content: string; originalSize: number } | null> {
734
- const result = await persistToolResult(candidate.content, candidate.toolUseId)
735
- if (isPersistError(result)) return null
736
- return {
737
- content: buildLargeToolResultMessage(result),
738
- originalSize: result.originalSize,
739
- }
740
- }
741
-
742
- /**
743
- * Enforce the per-message budget on aggregate tool result size.
744
- *
745
- * For each user message whose tool_result blocks together exceed the
746
- * per-message limit (see getPerMessageBudgetLimit), the largest FRESH
747
- * (never-before-seen) results in THAT message are persisted to disk and
748
- * replaced with previews.
749
- * Messages are evaluated independently — a 150K result in one message and
750
- * a 150K result in another are both under budget and untouched.
751
- *
752
- * State is tracked by tool_use_id in `state`. Once a result is seen its
753
- * fate is frozen: previously-replaced results get the same replacement
754
- * re-applied every turn from the cached preview string (zero I/O,
755
- * byte-identical), and previously-unreplaced results are never replaced
756
- * later (would break prompt cache).
757
- *
758
- * Each turn adds at most one new user message with tool_result blocks,
759
- * so the per-message loop typically does the budget check at most once;
760
- * all prior messages just re-apply cached replacements.
761
- *
762
- * @param state — MUTATED: seenIds and replacements are updated in place
763
- * to record choices made this call. The caller holds a stable reference
764
- * across turns; returning a new object would require error-prone ref
765
- * updates after every query.
766
- *
767
- * Returns `{ messages, newlyReplaced }`:
768
- * - messages: same array instance when no replacement is needed
769
- * - newlyReplaced: replacements made THIS call (not re-applies).
770
- * Caller persists these to the transcript for resume reconstruction.
771
- */
772
- export async function enforceToolResultBudget(
773
- messages: Message[],
774
- state: ContentReplacementState,
775
- skipToolNames: ReadonlySet<string> = new Set(),
776
- ): Promise<{
777
- messages: Message[]
778
- newlyReplaced: ToolResultReplacementRecord[]
779
- }> {
780
- const candidatesByMessage = collectCandidatesByMessage(messages)
781
- const nameByToolUseId =
782
- skipToolNames.size > 0 ? buildToolNameMap(messages) : undefined
783
- const shouldSkip = (id: string): boolean =>
784
- nameByToolUseId !== undefined &&
785
- skipToolNames.has(nameByToolUseId.get(id) ?? '')
786
- // Resolve once per call. A mid-session flag change only affects FRESH
787
- // messages (prior decisions are frozen via seenIds/replacements), so
788
- // prompt cache for already-seen content is preserved regardless.
789
- const limit = getPerMessageBudgetLimit()
790
-
791
- // Walk each API-level message group independently. For previously-processed messages
792
- // (all IDs in seenIds) this just re-applies cached replacements. For the
793
- // single new message this turn added, it runs the budget check.
794
- const replacementMap = new Map<string, string>()
795
- const toPersist: ToolResultCandidate[] = []
796
- let reappliedCount = 0
797
- let messagesOverBudget = 0
798
-
799
- for (const candidates of candidatesByMessage) {
800
- const { mustReapply, frozen, fresh } = partitionByPriorDecision(
801
- candidates,
802
- state,
803
- )
804
-
805
- // Re-apply: pure Map lookups. No file I/O, byte-identical, cannot fail.
806
- mustReapply.forEach(c => replacementMap.set(c.toolUseId, c.replacement))
807
- reappliedCount += mustReapply.length
808
-
809
- // Fresh means this is a new message. Check its per-message budget.
810
- // (A previously-processed message has fresh.length === 0 because all
811
- // its IDs were added to seenIds when first seen.)
812
- if (fresh.length === 0) {
813
- // mustReapply/frozen are already in seenIds from their first pass —
814
- // re-adding is a no-op but keeps the invariant explicit.
815
- candidates.forEach(c => state.seenIds.add(c.toolUseId))
816
- continue
817
- }
818
-
819
- // Tools with maxResultSizeChars: Infinity (Read) — never persist.
820
- // Mark as seen (frozen) so the decision sticks across turns. They don't
821
- // count toward freshSize; if that lets the group slip under budget and
822
- // the wire message is still large, that's the contract — Read's own
823
- // maxTokens is the bound, not this wrapper.
824
- const skipped = fresh.filter(c => shouldSkip(c.toolUseId))
825
- skipped.forEach(c => state.seenIds.add(c.toolUseId))
826
- const eligible = fresh.filter(c => !shouldSkip(c.toolUseId))
827
-
828
- const frozenSize = frozen.reduce((sum, c) => sum + c.size, 0)
829
- const freshSize = eligible.reduce((sum, c) => sum + c.size, 0)
830
-
831
- const selected =
832
- frozenSize + freshSize > limit
833
- ? selectFreshToReplace(eligible, frozenSize, limit)
834
- : []
835
-
836
- // Mark non-persisting candidates as seen NOW (synchronously). IDs
837
- // selected for persist are marked seen AFTER the await, alongside
838
- // replacements.set — keeps the pair atomic under observation so no
839
- // concurrent reader (once subagents share state) ever sees X∈seenIds
840
- // but X∉replacements, which would misclassify X as frozen and send
841
- // full content while the main thread sends the preview → cache miss.
842
- const selectedIds = new Set(selected.map(c => c.toolUseId))
843
- candidates
844
- .filter(c => !selectedIds.has(c.toolUseId))
845
- .forEach(c => state.seenIds.add(c.toolUseId))
846
-
847
- if (selected.length === 0) continue
848
- messagesOverBudget++
849
- toPersist.push(...selected)
850
- }
851
-
852
- if (replacementMap.size === 0 && toPersist.length === 0) {
853
- return { messages, newlyReplaced: [] }
854
- }
855
-
856
- // Fresh: concurrent persist for all selected candidates across all
857
- // messages. In practice toPersist comes from a single message per turn.
858
- const freshReplacements = await Promise.all(
859
- toPersist.map(async c => [c, await buildReplacement(c)] as const),
860
- )
861
- const newlyReplaced: ToolResultReplacementRecord[] = []
862
- let replacedSize = 0
863
- for (const [candidate, replacement] of freshReplacements) {
864
- // Mark seen HERE, post-await, atomically with replacements.set for
865
- // success cases. For persist failures (replacement === null) the ID
866
- // is seen-but-unreplaced — the original content was sent to the
867
- // model, so treating it as frozen going forward is correct.
868
- state.seenIds.add(candidate.toolUseId)
869
- if (replacement === null) continue
870
- replacedSize += candidate.size
871
- replacementMap.set(candidate.toolUseId, replacement.content)
872
- state.replacements.set(candidate.toolUseId, replacement.content)
873
- newlyReplaced.push({
874
- kind: 'tool-result',
875
- toolUseId: candidate.toolUseId,
876
- replacement: replacement.content,
877
- })
878
- logEvent('tengu_tool_result_persisted_message_budget', {
879
- originalSizeBytes: replacement.originalSize,
880
- persistedSizeBytes: replacement.content.length,
881
- estimatedOriginalTokens: Math.ceil(
882
- replacement.originalSize / BYTES_PER_TOKEN,
883
- ),
884
- estimatedPersistedTokens: Math.ceil(
885
- replacement.content.length / BYTES_PER_TOKEN,
886
- ),
887
- })
888
- }
889
-
890
- if (replacementMap.size === 0) {
891
- return { messages, newlyReplaced: [] }
892
- }
893
-
894
- if (newlyReplaced.length > 0) {
895
- logForDebugging(
896
- `Per-message budget: persisted ${newlyReplaced.length} tool results ` +
897
- `across ${messagesOverBudget} over-budget message(s), ` +
898
- `shed ~${formatFileSize(replacedSize)}, ${reappliedCount} re-applied`,
899
- )
900
- logEvent('tengu_message_level_tool_result_budget_enforced', {
901
- resultsPersisted: newlyReplaced.length,
902
- messagesOverBudget,
903
- replacedSizeBytes: replacedSize,
904
- reapplied: reappliedCount,
905
- })
906
- }
907
-
908
- return {
909
- messages: replaceToolResultContents(messages, replacementMap),
910
- newlyReplaced,
911
- }
912
- }
913
-
914
- /**
915
- * Query-loop integration point for the aggregate budget.
916
- *
917
- * Gates on `state` (undefined means feature disabled → no-op return),
918
- * applies enforcement, and fires an optional transcript-write callback
919
- * for new replacements. The caller (query.ts) owns the persistence gate
920
- * — it passes a callback only for querySources that read records back on
921
- * resume (repl_main_thread*, agent:*); ephemeral runForkedAgent callers
922
- * (agentSummary, sessionMemory, /btw, compact) pass undefined.
923
- *
924
- * @returns messages with replacements applied, or the input array unchanged
925
- * when the feature is off or no replacement occurred.
926
- */
927
- export async function applyToolResultBudget(
928
- messages: Message[],
929
- state: ContentReplacementState | undefined,
930
- writeToTranscript?: (records: ToolResultReplacementRecord[]) => void,
931
- skipToolNames?: ReadonlySet<string>,
932
- ): Promise<Message[]> {
933
- if (!state) return messages
934
- const result = await enforceToolResultBudget(messages, state, skipToolNames)
935
- if (result.newlyReplaced.length > 0) {
936
- writeToTranscript?.(result.newlyReplaced)
937
- }
938
- return result.messages
939
- }
940
-
941
- /**
942
- * Reconstruct replacement state from content-replacement records loaded from
943
- * the transcript. Used on resume so the budget makes the same choices it
944
- * made in the original session (prompt cache stability).
945
- *
946
- * Accepts the full ContentReplacementRecord[] from LogOption (may include
947
- * future non-tool-result kinds); only tool-result records are applied here.
948
- *
949
- * - replacements: populated directly from the stored replacement strings.
950
- * Records for IDs not in messages (e.g. after compact) are skipped —
951
- * they're inert anyway.
952
- * - seenIds: every candidate tool_use_id in the loaded messages. A result
953
- * being in the transcript means it was sent to the model, so it was seen.
954
- * This freezes unreplaced results against future replacement.
955
- * - inheritedReplacements: gap-fill for fork-subagent resume. A fork's
956
- * original run applies parent-inherited replacements via mustReapply
957
- * (never persisted — not newlyReplaced). On resume the sidechain has
958
- * the original content but no record, so records alone would classify
959
- * it as frozen. The parent's live state still has the mapping; copy
960
- * it for IDs in messages that records don't cover. No-op for non-fork
961
- * resumes (parent IDs aren't in the subagent's messages).
962
- */
963
- export function reconstructContentReplacementState(
964
- messages: Message[],
965
- records: ContentReplacementRecord[],
966
- inheritedReplacements?: ReadonlyMap<string, string>,
967
- ): ContentReplacementState {
968
- const state = createContentReplacementState()
969
- const candidateIds = new Set(
970
- collectCandidatesByMessage(messages)
971
- .flat()
972
- .map(c => c.toolUseId),
973
- )
974
-
975
- for (const id of candidateIds) {
976
- state.seenIds.add(id)
977
- }
978
- for (const r of records) {
979
- if (r.kind === 'tool-result' && candidateIds.has(r.toolUseId)) {
980
- state.replacements.set(r.toolUseId, r.replacement)
981
- }
982
- }
983
- if (inheritedReplacements) {
984
- for (const [id, replacement] of inheritedReplacements) {
985
- if (candidateIds.has(id) && !state.replacements.has(id)) {
986
- state.replacements.set(id, replacement)
987
- }
988
- }
989
- }
990
- return state
991
- }
992
-
993
- /**
994
- * AgentTool-resume variant: encapsulates the feature-flag gate + parent
995
- * gap-fill so both AgentTool.call and resumeAgentBackground share one
996
- * implementation. Returns undefined when parentState is undefined (feature
997
- * off); otherwise reconstructs from sidechain records with parent's live
998
- * replacements filling gaps for fork-inherited mustReapply entries.
999
- *
1000
- * Kept out of AgentTool.tsx — that file is at the feature() DCE complexity
1001
- * cliff and cannot tolerate even +1 net source line without silently
1002
- * breaking feature('TRANSCRIPT_CLASSIFIER') eval in tests.
1003
- */
1004
- export function reconstructForSubagentResume(
1005
- parentState: ContentReplacementState | undefined,
1006
- resumedMessages: Message[],
1007
- sidechainRecords: ContentReplacementRecord[],
1008
- ): ContentReplacementState | undefined {
1009
- if (!parentState) return undefined
1010
- return reconstructContentReplacementState(
1011
- resumedMessages,
1012
- sidechainRecords,
1013
- parentState.replacements,
1014
- )
1015
- }
1016
-
1017
- /**
1018
- * Get a human-readable error message from a filesystem error
1019
- */
1020
- function getFileSystemErrorMessage(error: Error): string {
1021
- // Node.js filesystem errors have a 'code' property
1022
- // eslint-disable-next-line no-restricted-syntax -- uses .path, not just .code
1023
- const nodeError = error as NodeJS.ErrnoException
1024
- if (nodeError.code) {
1025
- switch (nodeError.code) {
1026
- case 'ENOENT':
1027
- return `Directory not found: ${nodeError.path ?? 'unknown path'}`
1028
- case 'EACCES':
1029
- return `Permission denied: ${nodeError.path ?? 'unknown path'}`
1030
- case 'ENOSPC':
1031
- return 'No space left on device'
1032
- case 'EROFS':
1033
- return 'Read-only file system'
1034
- case 'EMFILE':
1035
- return 'Too many open files'
1036
- case 'EEXIST':
1037
- return `File already exists: ${nodeError.path ?? 'unknown path'}`
1038
- default:
1039
- return `${nodeError.code}: ${nodeError.message}`
1040
- }
1041
- }
1042
- return error.message
1043
- }