@vybestack/llxprt-code-core 0.11.0 → 0.12.0-nightly.260910.2aac6841e

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 (417) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/prompt-config/defaults/default-prompts.json +3 -3
  5. package/dist/src/config/agentClientLifecycle.d.ts +4 -3
  6. package/dist/src/config/agentClientLifecycle.js +27 -14
  7. package/dist/src/config/agentClientLifecycle.js.map +1 -1
  8. package/dist/src/config/config.d.ts +2 -5
  9. package/dist/src/config/config.js +10 -23
  10. package/dist/src/config/config.js.map +1 -1
  11. package/dist/src/config/configBase.d.ts +5 -1
  12. package/dist/src/config/configBase.js +27 -6
  13. package/dist/src/config/configBase.js.map +1 -1
  14. package/dist/src/config/configBaseCore.d.ts +26 -8
  15. package/dist/src/config/configBaseCore.js +30 -26
  16. package/dist/src/config/configBaseCore.js.map +1 -1
  17. package/dist/src/config/configMcpRuntime.d.ts +16 -0
  18. package/dist/src/config/configMcpRuntime.js +31 -0
  19. package/dist/src/config/configMcpRuntime.js.map +1 -0
  20. package/dist/src/config/configMediaDefaults.d.ts +10 -0
  21. package/dist/src/config/configMediaDefaults.js +17 -0
  22. package/dist/src/config/configMediaDefaults.js.map +1 -0
  23. package/dist/src/config/configTestHarness.d.ts +4 -0
  24. package/dist/src/config/configTypes.d.ts +4 -54
  25. package/dist/src/config/configTypes.js +6 -82
  26. package/dist/src/config/configTypes.js.map +1 -1
  27. package/dist/src/config/index.d.ts +1 -2
  28. package/dist/src/config/index.js +1 -2
  29. package/dist/src/config/index.js.map +1 -1
  30. package/dist/src/config/models.d.ts +0 -4
  31. package/dist/src/config/models.js +0 -4
  32. package/dist/src/config/models.js.map +1 -1
  33. package/dist/src/config/toolRegistryFactory.d.ts +2 -2
  34. package/dist/src/core/clientContract.d.ts +4 -6
  35. package/dist/src/core/compression/transcriptPathNotice.d.ts +22 -0
  36. package/dist/src/core/compression/transcriptPathNotice.js +29 -0
  37. package/dist/src/core/compression/transcriptPathNotice.js.map +1 -0
  38. package/dist/src/core/contentGenerator.d.ts +2 -5
  39. package/dist/src/core/contentGenerator.js +10 -24
  40. package/dist/src/core/contentGenerator.js.map +1 -1
  41. package/dist/src/core/logger.d.ts +66 -0
  42. package/dist/src/core/logger.js +345 -30
  43. package/dist/src/core/logger.js.map +1 -1
  44. package/dist/src/core/prompts.d.ts +0 -1
  45. package/dist/src/core/prompts.js +5 -79
  46. package/dist/src/core/prompts.js.map +1 -1
  47. package/dist/src/core/turn.d.ts +3 -3
  48. package/dist/src/hooks/hookTranslator.js +5 -4
  49. package/dist/src/hooks/hookTranslator.js.map +1 -1
  50. package/dist/src/index.d.ts +8 -6
  51. package/dist/src/index.js +8 -6
  52. package/dist/src/index.js.map +1 -1
  53. package/dist/src/llm-types/index.d.ts +1 -1
  54. package/dist/src/llm-types/modelEnvelope.d.ts +2 -1
  55. package/dist/src/llm-types/modelEnvelope.js +17 -1
  56. package/dist/src/llm-types/modelEnvelope.js.map +1 -1
  57. package/dist/src/models/schema.d.ts +40 -40
  58. package/dist/src/policy/policies/read-only.toml +0 -5
  59. package/dist/src/prompt-config/TemplateEngine.js +0 -3
  60. package/dist/src/prompt-config/TemplateEngine.js.map +1 -1
  61. package/dist/src/prompt-config/defaults/providers/gemini/core.md +0 -2
  62. package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
  63. package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
  64. package/dist/src/prompt-config/prompt-loader.d.ts +1 -1
  65. package/dist/src/prompt-config/prompt-loader.js +4 -4
  66. package/dist/src/prompt-config/prompt-loader.js.map +1 -1
  67. package/dist/src/prompt-config/types.d.ts +0 -1
  68. package/dist/src/recording/CheckpointService.d.ts +4 -0
  69. package/dist/src/recording/CheckpointService.js +67 -46
  70. package/dist/src/recording/CheckpointService.js.map +1 -1
  71. package/dist/src/recording/HistoryMutationService.d.ts +1 -1
  72. package/dist/src/recording/HistoryMutationService.js +27 -4
  73. package/dist/src/recording/HistoryMutationService.js.map +1 -1
  74. package/dist/src/recording/RecordingIntegration.d.ts +36 -2
  75. package/dist/src/recording/RecordingIntegration.js +224 -7
  76. package/dist/src/recording/RecordingIntegration.js.map +1 -1
  77. package/dist/src/recording/ReplayEngine.d.ts +8 -10
  78. package/dist/src/recording/ReplayEngine.js +161 -95
  79. package/dist/src/recording/ReplayEngine.js.map +1 -1
  80. package/dist/src/recording/SessionDiscovery.d.ts +4 -2
  81. package/dist/src/recording/SessionDiscovery.js +13 -5
  82. package/dist/src/recording/SessionDiscovery.js.map +1 -1
  83. package/dist/src/recording/SessionRecordingService.d.ts +23 -3
  84. package/dist/src/recording/SessionRecordingService.js +209 -51
  85. package/dist/src/recording/SessionRecordingService.js.map +1 -1
  86. package/dist/src/recording/SessionTransitionService.d.ts +7 -0
  87. package/dist/src/recording/SessionTransitionService.js +66 -13
  88. package/dist/src/recording/SessionTransitionService.js.map +1 -1
  89. package/dist/src/recording/index.d.ts +1 -0
  90. package/dist/src/recording/index.js +1 -0
  91. package/dist/src/recording/index.js.map +1 -1
  92. package/dist/src/recording/janitor/cleanupTypes.d.ts +3 -0
  93. package/dist/src/recording/janitor/cleanupTypes.js.map +1 -1
  94. package/dist/src/recording/janitor/mediaReclamation.d.ts +23 -0
  95. package/dist/src/recording/janitor/mediaReclamation.js +195 -0
  96. package/dist/src/recording/janitor/mediaReclamation.js.map +1 -0
  97. package/dist/src/recording/janitor/sessionJanitor.js +47 -1
  98. package/dist/src/recording/janitor/sessionJanitor.js.map +1 -1
  99. package/dist/src/recording/janitor/sessionScanner.d.ts +12 -9
  100. package/dist/src/recording/janitor/sessionScanner.js +248 -193
  101. package/dist/src/recording/janitor/sessionScanner.js.map +1 -1
  102. package/dist/src/recording/replay-test-helpers.d.ts +10 -1
  103. package/dist/src/recording/replay-test-helpers.js +24 -2
  104. package/dist/src/recording/replay-test-helpers.js.map +1 -1
  105. package/dist/src/recording/replayCheckpointMetadata.d.ts +28 -0
  106. package/dist/src/recording/replayCheckpointMetadata.js +96 -0
  107. package/dist/src/recording/replayCheckpointMetadata.js.map +1 -0
  108. package/dist/src/recording/replayErrorFormatting.d.ts +6 -0
  109. package/dist/src/recording/replayErrorFormatting.js +38 -0
  110. package/dist/src/recording/replayErrorFormatting.js.map +1 -0
  111. package/dist/src/recording/resumeSession.d.ts +3 -0
  112. package/dist/src/recording/resumeSession.js +7 -1
  113. package/dist/src/recording/resumeSession.js.map +1 -1
  114. package/dist/src/recording/semanticMediaPurgeReplayValidation.d.ts +14 -0
  115. package/dist/src/recording/semanticMediaPurgeReplayValidation.js +24 -0
  116. package/dist/src/recording/semanticMediaPurgeReplayValidation.js.map +1 -0
  117. package/dist/src/recording/session-media-package-blobs.d.ts +8 -0
  118. package/dist/src/recording/session-media-package-blobs.js +72 -0
  119. package/dist/src/recording/session-media-package-blobs.js.map +1 -0
  120. package/dist/src/recording/session-media-package-import.d.ts +26 -0
  121. package/dist/src/recording/session-media-package-import.js +124 -0
  122. package/dist/src/recording/session-media-package-import.js.map +1 -0
  123. package/dist/src/recording/session-media-package-state.d.ts +19 -0
  124. package/dist/src/recording/session-media-package-state.js +56 -0
  125. package/dist/src/recording/session-media-package-state.js.map +1 -0
  126. package/dist/src/recording/session-media-package-validation.d.ts +59 -0
  127. package/dist/src/recording/session-media-package-validation.js +286 -0
  128. package/dist/src/recording/session-media-package-validation.js.map +1 -0
  129. package/dist/src/recording/session-media-package-writer.d.ts +18 -0
  130. package/dist/src/recording/session-media-package-writer.js +70 -0
  131. package/dist/src/recording/session-media-package-writer.js.map +1 -0
  132. package/dist/src/recording/session-media-package.d.ts +27 -0
  133. package/dist/src/recording/session-media-package.js +366 -0
  134. package/dist/src/recording/session-media-package.js.map +1 -0
  135. package/dist/src/recording/types.d.ts +34 -2
  136. package/dist/src/recording/types.js.map +1 -1
  137. package/dist/src/runtime/AgentRuntimeContext.d.ts +22 -5
  138. package/dist/src/runtime/AgentRuntimeLoader.d.ts +6 -0
  139. package/dist/src/runtime/AgentRuntimeLoader.js +25 -6
  140. package/dist/src/runtime/AgentRuntimeLoader.js.map +1 -1
  141. package/dist/src/runtime/contracts/PromptEstimation.d.ts +1 -0
  142. package/dist/src/runtime/contracts/PromptEstimation.js.map +1 -1
  143. package/dist/src/runtime/contracts/RuntimeProvider.d.ts +3 -2
  144. package/dist/src/runtime/contracts/RuntimeProviderManager.d.ts +0 -2
  145. package/dist/src/runtime/createAgentRuntimeContext.js +28 -1
  146. package/dist/src/runtime/createAgentRuntimeContext.js.map +1 -1
  147. package/dist/src/runtime/providerRuntimeContext.d.ts +12 -0
  148. package/dist/src/runtime/providerRuntimeContext.js +3 -0
  149. package/dist/src/runtime/providerRuntimeContext.js.map +1 -1
  150. package/dist/src/runtime/runtimeAdapters.js +2 -2
  151. package/dist/src/runtime/runtimeAdapters.js.map +1 -1
  152. package/dist/src/services/history/ContentConverters.d.ts +11 -7
  153. package/dist/src/services/history/ContentConverters.js +11 -7
  154. package/dist/src/services/history/ContentConverters.js.map +1 -1
  155. package/dist/src/services/history/HistoryService.d.ts +18 -180
  156. package/dist/src/services/history/HistoryService.js +53 -523
  157. package/dist/src/services/history/HistoryService.js.map +1 -1
  158. package/dist/src/services/history/HistoryServiceCore.d.ts +278 -0
  159. package/dist/src/services/history/HistoryServiceCore.js +727 -0
  160. package/dist/src/services/history/HistoryServiceCore.js.map +1 -0
  161. package/dist/src/services/history/IContent.d.ts +118 -16
  162. package/dist/src/services/history/IContent.js +284 -4
  163. package/dist/src/services/history/IContent.js.map +1 -1
  164. package/dist/src/services/history/contentSize.js +22 -2
  165. package/dist/src/services/history/contentSize.js.map +1 -1
  166. package/dist/src/services/history/historyChronology.d.ts +7 -0
  167. package/dist/src/services/history/historyChronology.js +35 -3
  168. package/dist/src/services/history/historyChronology.js.map +1 -1
  169. package/dist/src/services/history/historyCloneUtils.d.ts +5 -4
  170. package/dist/src/services/history/historyCloneUtils.js +23 -16
  171. package/dist/src/services/history/historyCloneUtils.js.map +1 -1
  172. package/dist/src/services/history/historyCompressionQueue.d.ts +33 -0
  173. package/dist/src/services/history/historyCompressionQueue.js +81 -0
  174. package/dist/src/services/history/historyCompressionQueue.js.map +1 -0
  175. package/dist/src/services/history/historyEventTypes.d.ts +3 -0
  176. package/dist/src/services/history/historyMutationFailure.d.ts +15 -0
  177. package/dist/src/services/history/historyMutationFailure.js +22 -0
  178. package/dist/src/services/history/historyMutationFailure.js.map +1 -1
  179. package/dist/src/services/history/historyProviderPipeline.d.ts +1 -1
  180. package/dist/src/services/history/historyProviderPipeline.js +15 -5
  181. package/dist/src/services/history/historyProviderPipeline.js.map +1 -1
  182. package/dist/src/services/history/historyTokenEstimation.js +10 -6
  183. package/dist/src/services/history/historyTokenEstimation.js.map +1 -1
  184. package/dist/src/services/history/historyToolNormalization.d.ts +2 -0
  185. package/dist/src/services/history/historyToolNormalization.js +26 -9
  186. package/dist/src/services/history/historyToolNormalization.js.map +1 -1
  187. package/dist/src/services/history/provider-file-binding.d.ts +11 -0
  188. package/dist/src/services/history/provider-file-binding.js +70 -0
  189. package/dist/src/services/history/provider-file-binding.js.map +1 -0
  190. package/dist/src/services/history/semantic-media-purge.d.ts +66 -0
  191. package/dist/src/services/history/semantic-media-purge.js +404 -0
  192. package/dist/src/services/history/semantic-media-purge.js.map +1 -0
  193. package/dist/src/storage/SessionPersistenceService.d.ts +53 -2
  194. package/dist/src/storage/SessionPersistenceService.js +435 -23
  195. package/dist/src/storage/SessionPersistenceService.js.map +1 -1
  196. package/dist/src/storage/history-media-ownership.d.ts +38 -0
  197. package/dist/src/storage/history-media-ownership.js +136 -0
  198. package/dist/src/storage/history-media-ownership.js.map +1 -0
  199. package/dist/src/storage/local-media-store-child.d.ts +6 -0
  200. package/dist/src/storage/local-media-store-child.js +140 -0
  201. package/dist/src/storage/local-media-store-child.js.map +1 -0
  202. package/dist/src/storage/local-media-store-files.d.ts +44 -0
  203. package/dist/src/storage/local-media-store-files.js +460 -0
  204. package/dist/src/storage/local-media-store-files.js.map +1 -0
  205. package/dist/src/storage/local-media-store-lock-recovery.d.ts +15 -0
  206. package/dist/src/storage/local-media-store-lock-recovery.js +112 -0
  207. package/dist/src/storage/local-media-store-lock-recovery.js.map +1 -0
  208. package/dist/src/storage/local-media-store-persistence.d.ts +48 -0
  209. package/dist/src/storage/local-media-store-persistence.js +443 -0
  210. package/dist/src/storage/local-media-store-persistence.js.map +1 -0
  211. package/dist/src/storage/local-media-store-quota.d.ts +6 -0
  212. package/dist/src/storage/local-media-store-quota.js +66 -0
  213. package/dist/src/storage/local-media-store-quota.js.map +1 -0
  214. package/dist/src/storage/local-media-store-reservations.d.ts +55 -0
  215. package/dist/src/storage/local-media-store-reservations.js +377 -0
  216. package/dist/src/storage/local-media-store-reservations.js.map +1 -0
  217. package/dist/src/storage/local-media-store-types.d.ts +110 -0
  218. package/dist/src/storage/local-media-store-types.js +35 -0
  219. package/dist/src/storage/local-media-store-types.js.map +1 -0
  220. package/dist/src/storage/local-media-store-validation.d.ts +34 -0
  221. package/dist/src/storage/local-media-store-validation.js +449 -0
  222. package/dist/src/storage/local-media-store-validation.js.map +1 -0
  223. package/dist/src/storage/local-media-store.d.ts +47 -0
  224. package/dist/src/storage/local-media-store.js +353 -0
  225. package/dist/src/storage/local-media-store.js.map +1 -0
  226. package/dist/src/storage/media-admission-service.d.ts +49 -0
  227. package/dist/src/storage/media-admission-service.js +333 -0
  228. package/dist/src/storage/media-admission-service.js.map +1 -0
  229. package/dist/src/storage/media-lifecycle-metrics.d.ts +75 -0
  230. package/dist/src/storage/media-lifecycle-metrics.js +105 -0
  231. package/dist/src/storage/media-lifecycle-metrics.js.map +1 -0
  232. package/dist/src/storage/media-reference-lifecycle.d.ts +16 -0
  233. package/dist/src/storage/media-reference-lifecycle.js +84 -0
  234. package/dist/src/storage/media-reference-lifecycle.js.map +1 -0
  235. package/dist/src/storage/request-media-resolver.d.ts +67 -0
  236. package/dist/src/storage/request-media-resolver.js +325 -0
  237. package/dist/src/storage/request-media-resolver.js.map +1 -0
  238. package/dist/src/storage/session-media-service-factories.d.ts +19 -0
  239. package/dist/src/storage/session-media-service-factories.js +34 -0
  240. package/dist/src/storage/session-media-service-factories.js.map +1 -0
  241. package/dist/src/storage/session-persistence-helpers.d.ts +10 -0
  242. package/dist/src/storage/session-persistence-helpers.js +46 -0
  243. package/dist/src/storage/session-persistence-helpers.js.map +1 -0
  244. package/dist/src/test-utils/config.d.ts +2 -0
  245. package/dist/src/test-utils/config.js +5 -5
  246. package/dist/src/test-utils/config.js.map +1 -1
  247. package/dist/src/test-utils/runtime.d.ts +2 -0
  248. package/dist/src/test-utils/runtime.js +1 -2
  249. package/dist/src/test-utils/runtime.js.map +1 -1
  250. package/dist/src/tools-adapters/CoreShellToolHostAdapter.js +1 -9
  251. package/dist/src/tools-adapters/CoreShellToolHostAdapter.js.map +1 -1
  252. package/dist/src/tools-adapters/CoreSkillServiceAdapter.d.ts +0 -2
  253. package/dist/src/tools-adapters/CoreSkillServiceAdapter.js +0 -17
  254. package/dist/src/tools-adapters/CoreSkillServiceAdapter.js.map +1 -1
  255. package/dist/src/tools-adapters/CoreToolHostAdapter.d.ts +0 -21
  256. package/dist/src/tools-adapters/CoreToolHostAdapter.js +0 -8
  257. package/dist/src/tools-adapters/CoreToolHostAdapter.js.map +1 -1
  258. package/dist/src/utils/environmentContext.d.ts +8 -9
  259. package/dist/src/utils/environmentContext.js +11 -22
  260. package/dist/src/utils/environmentContext.js.map +1 -1
  261. package/dist/src/utils/errorParsing.d.ts +1 -2
  262. package/dist/src/utils/errorParsing.js +22 -41
  263. package/dist/src/utils/errorParsing.js.map +1 -1
  264. package/dist/src/utils/generateContentResponseUtilities.js +12 -0
  265. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
  266. package/dist/src/utils/summarizer.d.ts +1 -2
  267. package/dist/src/utils/summarizer.js +6 -5
  268. package/dist/src/utils/summarizer.js.map +1 -1
  269. package/dist/src/utils/tool-utils.js +7 -1
  270. package/dist/src/utils/tool-utils.js.map +1 -1
  271. package/index.ts +0 -4
  272. package/package.json +38 -30
  273. package/src/config/agentClientLifecycle.ts +53 -22
  274. package/src/config/config.ts +11 -26
  275. package/src/config/configBase.ts +46 -7
  276. package/src/config/configBaseCore.ts +38 -36
  277. package/src/config/configMcpRuntime.ts +46 -0
  278. package/src/config/configMediaDefaults.ts +19 -0
  279. package/src/config/configTypes.ts +13 -53
  280. package/src/config/index.ts +1 -4
  281. package/src/config/models.ts +0 -6
  282. package/src/config/toolRegistryFactory.ts +2 -2
  283. package/src/core/clientContract.ts +4 -6
  284. package/src/core/compression/transcriptPathNotice.ts +31 -0
  285. package/src/core/contentGenerator.ts +15 -39
  286. package/src/core/logger.ts +370 -39
  287. package/src/core/prompts.ts +4 -114
  288. package/src/core/turn.ts +3 -3
  289. package/src/hooks/hookTranslator.ts +6 -4
  290. package/src/index.ts +7 -7
  291. package/src/llm-types/index.ts +5 -0
  292. package/src/llm-types/modelEnvelope.ts +26 -2
  293. package/src/policy/policies/read-only.toml +0 -5
  294. package/src/prompt-config/TemplateEngine.ts +0 -3
  295. package/src/prompt-config/defaults/providers/gemini/core.md +0 -2
  296. package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
  297. package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
  298. package/src/prompt-config/prompt-loader.ts +7 -8
  299. package/src/prompt-config/types.ts +0 -1
  300. package/src/recording/CheckpointService.ts +110 -45
  301. package/src/recording/HistoryMutationService.ts +28 -3
  302. package/src/recording/RecordingIntegration.ts +258 -11
  303. package/src/recording/ReplayEngine.ts +220 -110
  304. package/src/recording/SessionDiscovery.ts +30 -4
  305. package/src/recording/SessionRecordingService.ts +253 -55
  306. package/src/recording/SessionTransitionService.ts +75 -12
  307. package/src/recording/index.ts +7 -0
  308. package/src/recording/janitor/cleanupTypes.ts +4 -0
  309. package/src/recording/janitor/mediaReclamation.ts +295 -0
  310. package/src/recording/janitor/sessionJanitor.ts +54 -1
  311. package/src/recording/janitor/sessionScanner.ts +319 -227
  312. package/src/recording/replay-test-helpers.ts +33 -2
  313. package/src/recording/replayCheckpointMetadata.ts +115 -0
  314. package/src/recording/replayErrorFormatting.ts +43 -0
  315. package/src/recording/resumeSession.ts +10 -0
  316. package/src/recording/semanticMediaPurgeReplayValidation.ts +35 -0
  317. package/src/recording/session-media-package-blobs.ts +116 -0
  318. package/src/recording/session-media-package-import.ts +189 -0
  319. package/src/recording/session-media-package-state.ts +120 -0
  320. package/src/recording/session-media-package-validation.ts +400 -0
  321. package/src/recording/session-media-package-writer.ts +117 -0
  322. package/src/recording/session-media-package.ts +692 -0
  323. package/src/recording/types.ts +37 -2
  324. package/src/runtime/AgentRuntimeContext.ts +28 -5
  325. package/src/runtime/AgentRuntimeLoader.ts +32 -7
  326. package/src/runtime/contracts/PromptEstimation.ts +1 -0
  327. package/src/runtime/contracts/RuntimeProvider.ts +3 -8
  328. package/src/runtime/contracts/RuntimeProviderManager.ts +0 -2
  329. package/src/runtime/createAgentRuntimeContext.ts +43 -1
  330. package/src/runtime/providerRuntimeContext.ts +22 -0
  331. package/src/runtime/runtimeAdapters.ts +2 -2
  332. package/src/services/history/ContentConverters.ts +11 -7
  333. package/src/services/history/HistoryService.ts +71 -696
  334. package/src/services/history/HistoryServiceCore.ts +1055 -0
  335. package/src/services/history/IContent.ts +460 -20
  336. package/src/services/history/contentSize.ts +22 -2
  337. package/src/services/history/historyChronology.ts +53 -3
  338. package/src/services/history/historyCloneUtils.ts +26 -22
  339. package/src/services/history/historyCompressionQueue.ts +102 -0
  340. package/src/services/history/historyEventTypes.ts +9 -0
  341. package/src/services/history/historyMutationFailure.ts +33 -0
  342. package/src/services/history/historyProviderPipeline.ts +19 -5
  343. package/src/services/history/historyTokenEstimation.ts +9 -5
  344. package/src/services/history/historyToolNormalization.ts +43 -11
  345. package/src/services/history/provider-file-binding.ts +115 -0
  346. package/src/services/history/semantic-media-purge.ts +593 -0
  347. package/src/storage/SessionPersistenceService.ts +667 -30
  348. package/src/storage/history-media-ownership.ts +185 -0
  349. package/src/storage/local-media-store-child.ts +163 -0
  350. package/src/storage/local-media-store-files.ts +643 -0
  351. package/src/storage/local-media-store-lock-recovery.ts +159 -0
  352. package/src/storage/local-media-store-persistence.ts +737 -0
  353. package/src/storage/local-media-store-quota.ts +111 -0
  354. package/src/storage/local-media-store-reservations.ts +485 -0
  355. package/src/storage/local-media-store-types.ts +161 -0
  356. package/src/storage/local-media-store-validation.ts +643 -0
  357. package/src/storage/local-media-store.ts +696 -0
  358. package/src/storage/media-admission-service.ts +512 -0
  359. package/src/storage/media-lifecycle-metrics.ts +228 -0
  360. package/src/storage/media-reference-lifecycle.ts +164 -0
  361. package/src/storage/request-media-resolver.ts +491 -0
  362. package/src/storage/session-media-service-factories.ts +48 -0
  363. package/src/storage/session-persistence-helpers.ts +85 -0
  364. package/src/test-utils/config.ts +7 -5
  365. package/src/test-utils/runtime.ts +3 -2
  366. package/src/tools-adapters/CoreShellToolHostAdapter.ts +1 -11
  367. package/src/tools-adapters/CoreSkillServiceAdapter.ts +0 -23
  368. package/src/tools-adapters/CoreToolHostAdapter.ts +0 -36
  369. package/src/utils/environmentContext.ts +11 -30
  370. package/src/utils/errorParsing.ts +19 -69
  371. package/src/utils/generateContentResponseUtilities.ts +28 -1
  372. package/src/utils/summarizer.ts +8 -10
  373. package/src/utils/tool-utils.ts +7 -1
  374. package/dist/src/code_assist/codeAssist.d.ts +0 -19
  375. package/dist/src/code_assist/codeAssist.js +0 -41
  376. package/dist/src/code_assist/codeAssist.js.map +0 -1
  377. package/dist/src/code_assist/contentGeneratorAdapters.d.ts +0 -49
  378. package/dist/src/code_assist/contentGeneratorAdapters.js +0 -197
  379. package/dist/src/code_assist/contentGeneratorAdapters.js.map +0 -1
  380. package/dist/src/code_assist/converter.d.ts +0 -74
  381. package/dist/src/code_assist/converter.js +0 -158
  382. package/dist/src/code_assist/converter.js.map +0 -1
  383. package/dist/src/code_assist/googleGenAIWrapper.d.ts +0 -27
  384. package/dist/src/code_assist/googleGenAIWrapper.js +0 -46
  385. package/dist/src/code_assist/googleGenAIWrapper.js.map +0 -1
  386. package/dist/src/code_assist/oauth-credential-storage.d.ts +0 -30
  387. package/dist/src/code_assist/oauth-credential-storage.js +0 -135
  388. package/dist/src/code_assist/oauth-credential-storage.js.map +0 -1
  389. package/dist/src/code_assist/server.d.ts +0 -44
  390. package/dist/src/code_assist/server.js +0 -154
  391. package/dist/src/code_assist/server.js.map +0 -1
  392. package/dist/src/code_assist/setup.d.ts +0 -20
  393. package/dist/src/code_assist/setup.js +0 -126
  394. package/dist/src/code_assist/setup.js.map +0 -1
  395. package/dist/src/code_assist/types.d.ts +0 -161
  396. package/dist/src/code_assist/types.js +0 -46
  397. package/dist/src/code_assist/types.js.map +0 -1
  398. package/dist/src/utils/getFolderStructure.d.ts +0 -31
  399. package/dist/src/utils/getFolderStructure.js +0 -240
  400. package/dist/src/utils/getFolderStructure.js.map +0 -1
  401. package/dist/src/utils/installationManager.d.ts +0 -16
  402. package/dist/src/utils/installationManager.js +0 -51
  403. package/dist/src/utils/installationManager.js.map +0 -1
  404. package/dist/src/utils/llm-edit-fixer.d.ts +0 -25
  405. package/dist/src/utils/llm-edit-fixer.js +0 -120
  406. package/dist/src/utils/llm-edit-fixer.js.map +0 -1
  407. package/src/code_assist/codeAssist.ts +0 -59
  408. package/src/code_assist/contentGeneratorAdapters.ts +0 -275
  409. package/src/code_assist/converter.ts +0 -288
  410. package/src/code_assist/googleGenAIWrapper.ts +0 -90
  411. package/src/code_assist/oauth-credential-storage.ts +0 -171
  412. package/src/code_assist/server.ts +0 -263
  413. package/src/code_assist/setup.ts +0 -189
  414. package/src/code_assist/types.ts +0 -201
  415. package/src/utils/getFolderStructure.ts +0 -382
  416. package/src/utils/installationManager.ts +0 -59
  417. package/src/utils/llm-edit-fixer.ts +0 -157
@@ -88,6 +88,16 @@ export interface ChronologyMarker {
88
88
  /**
89
89
  * Metadata associated with content
90
90
  */
91
+ export interface SemanticMediaPurgeBoundaryTag {
92
+ readonly blockIndex: number;
93
+ readonly boundaryId: object;
94
+ }
95
+
96
+ export interface SemanticMediaPurgeCacheWriteEvidence {
97
+ readonly boundaryId: object;
98
+ readonly preparation: 'added' | 'reused';
99
+ }
100
+
91
101
  export interface ContentMetadata {
92
102
  /** When this content was created */
93
103
  timestamp?: number;
@@ -182,6 +192,20 @@ export interface ContentMetadata {
182
192
  * history replacement drops it automatically. NEVER serialized to a provider.
183
193
  */
184
194
  cacheAnchor?: boolean;
195
+
196
+ /** Session-owned durable cursor for explicit semantic media purge. */
197
+ semanticMediaPurgeFrontier?: {
198
+ readonly contentIndex: number;
199
+ readonly blockIndex: number;
200
+ readonly contentId?: string;
201
+ readonly mediaId?: string;
202
+ };
203
+
204
+ /** Request-local marker for the exact semantic purge pre-image boundary. */
205
+ semanticMediaPurgeBoundary?: SemanticMediaPurgeBoundaryTag;
206
+
207
+ /** Request-local proof that the provider observed a matching cache write. */
208
+ semanticMediaPurgeCacheWriteEvidence?: SemanticMediaPurgeCacheWriteEvidence;
185
209
  }
186
210
 
187
211
  export interface UsageStats {
@@ -295,30 +319,436 @@ export interface ToolResponseBlock {
295
319
  /**
296
320
  * Media content (images, files, etc.)
297
321
  */
298
- export interface MediaBlock {
322
+ interface MediaBlockBase {
299
323
  type: 'media';
300
-
301
- /** MIME type of the media */
302
324
  mimeType: string;
325
+ caption?: string;
326
+ filename?: string;
327
+ providerMetadata?: Record<string, unknown>;
328
+ }
303
329
 
304
- /** Either a URL or base64-encoded data */
305
- data: string;
330
+ /** Intrinsic media dimensions when admission could determine both values. */
331
+ export interface MediaDimensions {
332
+ readonly width: number;
333
+ readonly height: number;
334
+ }
306
335
 
307
- /** Whether data is a URL or base64 */
336
+ /** Deeply immutable, recording-safe semantic metadata values. */
337
+ export type MediaSemanticMetadataValue =
338
+ | string
339
+ | number
340
+ | boolean
341
+ | null
342
+ | MediaSemanticMetadata
343
+ | readonly MediaSemanticMetadataValue[];
344
+
345
+ /** Provider-neutral semantics that remain stable for the referenced bytes. */
346
+ export interface MediaSemanticMetadata {
347
+ readonly [key: string]: MediaSemanticMetadataValue;
348
+ }
349
+
350
+ /** Legacy inline media retained for recording and caller compatibility. */
351
+ export interface ProviderFileReferenceMetadata {
352
+ readonly cacheKey?: string;
353
+ readonly provider: string;
354
+ readonly baseURL: string;
355
+ readonly credentialHash: string;
356
+ readonly fileId: string;
357
+ readonly byteLength: number;
358
+ readonly scope: 'session' | 'workspace';
359
+ readonly scopeId: string;
360
+ readonly createdAt: number;
361
+ readonly expiresAt: number;
362
+ readonly deletion: 'retain' | 'delete';
363
+ readonly zeroDataRetention: 'not-applicable' | 'incompatible-while-retained';
364
+ readonly deletionState: 'active' | 'pending' | 'failed';
365
+ }
366
+
367
+ export interface InlineMediaBlock extends MediaBlockBase {
308
368
  encoding: 'url' | 'base64';
369
+ data: string;
370
+ readonly dimensions?: MediaDimensions;
371
+ readonly semanticMetadata?: MediaSemanticMetadata;
372
+ readonly providerFileIds?: Readonly<Record<string, string>>;
373
+ readonly providerFiles?: readonly ProviderFileReferenceMetadata[];
374
+ readonly sourceContentId?: string;
375
+ readonly originalData?: string;
376
+ readonly originalMimeType?: string;
377
+ readonly originalDimensions?: MediaDimensions;
378
+ readonly transformation?: MediaTransformation;
379
+ }
309
380
 
310
- /** Optional caption or alt text */
311
- caption?: string;
381
+ /** Exact immutable metadata for one content-addressed media object. */
382
+ export interface MediaStoredObject {
383
+ readonly contentId: string;
384
+ readonly mimeType: string;
385
+ readonly byteLength: number;
386
+ readonly normalizedBase64Length: number;
387
+ readonly dimensions?: MediaDimensions;
388
+ }
312
389
 
313
- /** Original filename if applicable */
314
- filename?: string;
390
+ /** Stable identity of the policy that selected or produced a stored variant. */
391
+ export interface MediaTransformation {
392
+ readonly policyId: string;
393
+ readonly policyVersion: number;
394
+ readonly parameters: MediaSemanticMetadata;
395
+ }
315
396
 
316
- /**
317
- * @plan PLAN-20260702-LLMTYPES.P03
318
- * @requirement REQ-009.1
319
- * @pseudocode line 90
320
- */
321
- providerMetadata?: Record<string, unknown>;
397
+ /**
398
+ * Long-lived local media identity. It records replay and accounting metadata
399
+ * without retaining inline bytes or a machine-specific source path.
400
+ */
401
+ export interface MediaReferenceBlock extends MediaBlockBase {
402
+ encoding: 'reference';
403
+ readonly mimeType: string;
404
+ readonly contentId: string;
405
+ readonly originalContentId: string;
406
+ readonly selectedContentId: string;
407
+ readonly originalObject: MediaStoredObject;
408
+ readonly selectedObject: MediaStoredObject;
409
+ readonly transformation: MediaTransformation;
410
+ readonly byteLength: number;
411
+ readonly normalizedBase64Length: number;
412
+ readonly dimensions?: MediaDimensions;
413
+ readonly semanticMetadata: MediaSemanticMetadata;
414
+ readonly providerFileIds?: Readonly<Record<string, string>>;
415
+ readonly providerFiles?: readonly ProviderFileReferenceMetadata[];
416
+ readonly data?: never;
417
+ readonly sourcePath?: never;
418
+ }
419
+
420
+ /** Provider-neutral inline, URL, or local-reference media. */
421
+ export type MediaBlock = InlineMediaBlock | MediaReferenceBlock;
422
+
423
+ function isNonEmptyString(value: unknown): value is string {
424
+ return typeof value === 'string' && value.length > 0;
425
+ }
426
+
427
+ function isPositiveInteger(value: unknown): value is number {
428
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
429
+ }
430
+
431
+ function isRecord(value: unknown): value is Record<string, unknown> {
432
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
433
+ }
434
+
435
+ function isContentId(value: unknown): value is string {
436
+ return typeof value === 'string' && /^sha256:[0-9a-f]{64}$/.test(value);
437
+ }
438
+
439
+ function isMimeType(value: unknown): value is string {
440
+ return (
441
+ typeof value === 'string' &&
442
+ /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+\/[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(value)
443
+ );
444
+ }
445
+
446
+ function isLegacyInlineMimeType(value: unknown): value is string {
447
+ if (typeof value !== 'string') return false;
448
+ const [essence] = value.split(';', 1);
449
+ return isMimeType(essence.trim());
450
+ }
451
+
452
+ function hasValidDimensions(value: unknown): value is MediaDimensions {
453
+ return (
454
+ isRecord(value) &&
455
+ Object.keys(value).length === 2 &&
456
+ isPositiveInteger(value['width']) &&
457
+ isPositiveInteger(value['height'])
458
+ );
459
+ }
460
+
461
+ function hasValidProviderFileIds(value: unknown): boolean {
462
+ if (!isRecord(value)) {
463
+ return false;
464
+ }
465
+ return Object.entries(value).every(
466
+ ([provider, fileId]) => provider.length > 0 && isNonEmptyString(fileId),
467
+ );
468
+ }
469
+
470
+ function isNonNegativeInteger(value: unknown): value is number {
471
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
472
+ }
473
+
474
+ function hasValidProviderFile(value: unknown): boolean {
475
+ if (!isRecord(value)) return false;
476
+ if (value['cacheKey'] !== undefined && !isNonEmptyString(value['cacheKey'])) {
477
+ return false;
478
+ }
479
+ const strings = [
480
+ value['provider'],
481
+ value['baseURL'],
482
+ value['credentialHash'],
483
+ value['fileId'],
484
+ value['scopeId'],
485
+ ];
486
+ if (!strings.every(isNonEmptyString)) return false;
487
+ if (!isPositiveInteger(value['byteLength'])) return false;
488
+ if (value['scope'] !== 'session' && value['scope'] !== 'workspace')
489
+ return false;
490
+ const createdAt = value['createdAt'];
491
+ const expiresAt = value['expiresAt'];
492
+ if (!isNonNegativeInteger(createdAt)) return false;
493
+ if (!isNonNegativeInteger(expiresAt)) return false;
494
+ if (expiresAt <= createdAt) return false;
495
+ if (value['deletion'] !== 'retain' && value['deletion'] !== 'delete')
496
+ return false;
497
+ if (
498
+ value['zeroDataRetention'] !== 'not-applicable' &&
499
+ value['zeroDataRetention'] !== 'incompatible-while-retained'
500
+ ) {
501
+ return false;
502
+ }
503
+ return ['active', 'pending', 'failed'].includes(
504
+ String(value['deletionState']),
505
+ );
506
+ }
507
+
508
+ function hasValidProviderFiles(value: unknown): boolean {
509
+ return Array.isArray(value) && value.every(hasValidProviderFile);
510
+ }
511
+
512
+ const MAX_SEMANTIC_METADATA_DEPTH = 64;
513
+
514
+ function isMediaSemanticMetadataValue(
515
+ value: unknown,
516
+ ancestors: Set<object>,
517
+ depth: number,
518
+ ): value is MediaSemanticMetadataValue {
519
+ if (depth > MAX_SEMANTIC_METADATA_DEPTH) return false;
520
+ if (
521
+ value === null ||
522
+ typeof value === 'string' ||
523
+ typeof value === 'boolean'
524
+ ) {
525
+ return true;
526
+ }
527
+ if (typeof value === 'number') {
528
+ return Number.isFinite(value);
529
+ }
530
+ if (typeof value !== 'object' || ancestors.has(value)) {
531
+ return false;
532
+ }
533
+ if (!Array.isArray(value)) {
534
+ const prototype = Object.getPrototypeOf(value);
535
+ if (prototype !== Object.prototype && prototype !== null) {
536
+ return false;
537
+ }
538
+ }
539
+ ancestors.add(value);
540
+ const entries = Array.isArray(value) ? value : Object.values(value);
541
+ const hasValidKeys =
542
+ Array.isArray(value) || Object.keys(value).every((key) => key.length > 0);
543
+ const isValid =
544
+ hasValidKeys &&
545
+ entries.every((entry) =>
546
+ isMediaSemanticMetadataValue(entry, ancestors, depth + 1),
547
+ );
548
+ ancestors.delete(value);
549
+ return isValid;
550
+ }
551
+
552
+ function isMediaSemanticMetadata(
553
+ value: unknown,
554
+ ): value is MediaSemanticMetadata {
555
+ return (
556
+ isRecord(value) && isMediaSemanticMetadataValue(value, new Set<object>(), 0)
557
+ );
558
+ }
559
+
560
+ function hasValidStoredObject(value: unknown): value is MediaStoredObject {
561
+ if (!isRecord(value) || !isContentId(value['contentId'])) return false;
562
+ if (!isMimeType(value['mimeType'])) return false;
563
+ const byteLength = value['byteLength'];
564
+ if (!isPositiveInteger(byteLength)) return false;
565
+ if (value['normalizedBase64Length'] !== Math.ceil(byteLength / 3) * 4) {
566
+ return false;
567
+ }
568
+ return (
569
+ value['dimensions'] === undefined || hasValidDimensions(value['dimensions'])
570
+ );
571
+ }
572
+
573
+ function hasValidTransformation(value: unknown): value is MediaTransformation {
574
+ return (
575
+ isRecord(value) &&
576
+ isNonEmptyString(value['policyId']) &&
577
+ isPositiveInteger(value['policyVersion']) &&
578
+ isMediaSemanticMetadata(value['parameters'])
579
+ );
580
+ }
581
+
582
+ /** Recognizes valid legacy inline and URL media restored from external data. */
583
+ export function isInlineMediaBlock(value: unknown): value is InlineMediaBlock {
584
+ if (!isRecord(value) || value['type'] !== 'media') {
585
+ return false;
586
+ }
587
+ if (value['encoding'] !== 'url' && value['encoding'] !== 'base64') {
588
+ return false;
589
+ }
590
+ if (!isLegacyInlineMimeType(value['mimeType'])) return false;
591
+ const dimensions = value['dimensions'];
592
+ if (dimensions !== undefined && !hasValidDimensions(dimensions)) return false;
593
+ const semanticMetadata = value['semanticMetadata'];
594
+ if (
595
+ semanticMetadata !== undefined &&
596
+ !isMediaSemanticMetadata(semanticMetadata)
597
+ ) {
598
+ return false;
599
+ }
600
+ const providerFileIds = value['providerFileIds'];
601
+ if (
602
+ providerFileIds !== undefined &&
603
+ !hasValidProviderFileIds(providerFileIds)
604
+ ) {
605
+ return false;
606
+ }
607
+ const providerFiles = value['providerFiles'];
608
+ if (providerFiles !== undefined && !hasValidProviderFiles(providerFiles)) {
609
+ return false;
610
+ }
611
+ const sourceContentId = value['sourceContentId'];
612
+ if (sourceContentId !== undefined && !isContentId(sourceContentId))
613
+ return false;
614
+ const originalData = value['originalData'];
615
+ if (originalData !== undefined && !isNonEmptyString(originalData))
616
+ return false;
617
+ const originalMimeType = value['originalMimeType'];
618
+ if (
619
+ originalMimeType !== undefined &&
620
+ !isLegacyInlineMimeType(originalMimeType)
621
+ ) {
622
+ return false;
623
+ }
624
+ const originalDimensions = value['originalDimensions'];
625
+ if (
626
+ originalDimensions !== undefined &&
627
+ !hasValidDimensions(originalDimensions)
628
+ ) {
629
+ return false;
630
+ }
631
+ const transformation = value['transformation'];
632
+ if (transformation !== undefined && !hasValidTransformation(transformation)) {
633
+ return false;
634
+ }
635
+ return isNonEmptyString(value['data']);
636
+ }
637
+
638
+ function dimensionsMatch(
639
+ left: MediaDimensions | undefined,
640
+ right: MediaDimensions | undefined,
641
+ ): boolean {
642
+ return left?.width === right?.width && left?.height === right?.height;
643
+ }
644
+
645
+ function storedObjectMetadataMatches(
646
+ left: MediaStoredObject,
647
+ right: MediaStoredObject,
648
+ ): boolean {
649
+ return (
650
+ left.mimeType === right.mimeType &&
651
+ left.byteLength === right.byteLength &&
652
+ left.normalizedBase64Length === right.normalizedBase64Length &&
653
+ dimensionsMatch(left.dimensions, right.dimensions)
654
+ );
655
+ }
656
+
657
+ function referenceObjectsMatch(
658
+ value: Readonly<Record<string, unknown>>,
659
+ originalObject: MediaStoredObject,
660
+ selectedObject: MediaStoredObject,
661
+ ): boolean {
662
+ return [
663
+ originalObject.contentId === value['originalContentId'],
664
+ selectedObject.contentId === value['selectedContentId'],
665
+ selectedObject.contentId === value['contentId'],
666
+ selectedObject.mimeType === value['mimeType'],
667
+ selectedObject.byteLength === value['byteLength'],
668
+ selectedObject.normalizedBase64Length === value['normalizedBase64Length'],
669
+ dimensionsMatch(
670
+ selectedObject.dimensions,
671
+ hasValidDimensions(value['dimensions']) ? value['dimensions'] : undefined,
672
+ ),
673
+ originalObject.contentId !== selectedObject.contentId ||
674
+ storedObjectMetadataMatches(originalObject, selectedObject),
675
+ ].every(Boolean);
676
+ }
677
+
678
+ /** Validates the complete persisted local-reference shape and its invariants. */
679
+ export function isMediaReferenceBlock(
680
+ value: unknown,
681
+ ): value is MediaReferenceBlock {
682
+ if (!isRecord(value) || value['type'] !== 'media') {
683
+ return false;
684
+ }
685
+ if (value['encoding'] !== 'reference') {
686
+ return false;
687
+ }
688
+ if ('data' in value || 'sourcePath' in value) {
689
+ return false;
690
+ }
691
+ if (!isMimeType(value['mimeType'])) {
692
+ return false;
693
+ }
694
+ if (!isContentId(value['contentId'])) {
695
+ return false;
696
+ }
697
+ if (!isContentId(value['originalContentId'])) {
698
+ return false;
699
+ }
700
+ if (!isContentId(value['selectedContentId'])) {
701
+ return false;
702
+ }
703
+ if (value['contentId'] !== value['selectedContentId']) {
704
+ return false;
705
+ }
706
+ const byteLength = value['byteLength'];
707
+ if (!isPositiveInteger(byteLength)) {
708
+ return false;
709
+ }
710
+ const normalizedBase64Length = value['normalizedBase64Length'];
711
+ if (!isPositiveInteger(normalizedBase64Length)) {
712
+ return false;
713
+ }
714
+ if (normalizedBase64Length !== Math.ceil(byteLength / 3) * 4) {
715
+ return false;
716
+ }
717
+ const originalObject = value['originalObject'];
718
+ const selectedObject = value['selectedObject'];
719
+ if (!hasValidStoredObject(originalObject)) return false;
720
+ if (!hasValidStoredObject(selectedObject)) return false;
721
+ if (!hasValidTransformation(value['transformation'])) return false;
722
+ if (!referenceObjectsMatch(value, originalObject, selectedObject)) {
723
+ return false;
724
+ }
725
+ if (!isMediaSemanticMetadata(value['semanticMetadata'])) {
726
+ return false;
727
+ }
728
+ const dimensions = value['dimensions'];
729
+ if (dimensions !== undefined && !hasValidDimensions(dimensions)) {
730
+ return false;
731
+ }
732
+ const providerFileIds = value['providerFileIds'];
733
+ if (
734
+ providerFileIds !== undefined &&
735
+ !hasValidProviderFileIds(providerFileIds)
736
+ ) {
737
+ return false;
738
+ }
739
+ const providerFiles = value['providerFiles'];
740
+ return providerFiles === undefined || hasValidProviderFiles(providerFiles);
741
+ }
742
+
743
+ /** Rejects local references before a converter attempts inline transport. */
744
+ export function requireInlineMediaBlock(block: MediaBlock): InlineMediaBlock {
745
+ if (block.encoding !== 'reference') {
746
+ return block;
747
+ }
748
+ if (!isMediaReferenceBlock(block)) {
749
+ throw new Error('Malformed media reference');
750
+ }
751
+ throw new Error(`Unresolved media reference ${block.contentId}`);
322
752
  }
323
753
 
324
754
  /**
@@ -406,7 +836,7 @@ export const ContentValidation = {
406
836
  return Boolean(block.callId) && block.result !== undefined;
407
837
  }
408
838
  if (block.type === 'media') {
409
- return !!block.data && !!block.mimeType;
839
+ return isInlineMediaBlock(block) || isMediaReferenceBlock(block);
410
840
  }
411
841
  if (block.type === 'thinking') {
412
842
  // A thinking block is valid if it has:
@@ -542,11 +972,21 @@ export function stampAiTurnModel(
542
972
  * every entry was considered and rejected: a shallow `{...entry}` would still
543
973
  * share `blocks` and `metadata`, so it would advertise immutability it does not
544
974
  * provide, and a deep clone would be real cost on every compression for a
545
- * hazard no caller exhibits. Both call sites — `applyCompressionWithAnchor` and
546
- * `applyDensityMutations` — use the result as a replacement history and never
547
- * write through it. Sharing entry references is also the established
975
+ * hazard no caller exhibits. Sharing entry references is also the established
548
976
  * convention here: `HistoryService.getCurated()` and the compression
549
977
  * strategies' `history.slice(...)` hand out the same objects.
978
+ *
979
+ * Call sites and why each is safe:
980
+ * - `applyCompressionWithAnchor` and `applyDensityMutations` use the result as
981
+ * a replacement history and never write through it.
982
+ * - `finalizeReplay` returns the result as `ReplayResult.history` (#3160). Its
983
+ * consumers DO install those entries into a `HistoryService`, whose
984
+ * chronology stamper writes `metadata` in place. What is shared is the
985
+ * ENTRIES, not the array: the returned array is new. That is safe here only
986
+ * because the entries belong to the replay accumulator, which is discarded
987
+ * when `finalizeReplay` returns, so no second owner can observe the
988
+ * mutation. Any future caller whose input entries outlive the call must
989
+ * clone the ENTRIES first; copying the array would not help.
550
990
  */
551
991
  export function invalidateResponsesStatefulChain(
552
992
  history: readonly IContent[],
@@ -189,12 +189,32 @@ export function estimateBlockBytesTracked(
189
189
  total += optionalStringBytes(block.streamStatus);
190
190
  break;
191
191
  case 'media':
192
- // `data` is the payload: a base64 body or a URL.
193
- total += requiredStringBytes(block.data);
194
192
  total += requiredStringBytes(block.mimeType);
195
193
  total += requiredStringBytes(block.encoding);
196
194
  total += optionalStringBytes(block.caption);
197
195
  total += optionalStringBytes(block.filename);
196
+ if (block.providerFiles !== undefined) {
197
+ total += estimateValueBytes(block.providerFiles, 1, seen);
198
+ }
199
+ if (block.encoding !== 'reference') {
200
+ total += requiredStringBytes(block.data);
201
+ break;
202
+ }
203
+ total += block.normalizedBase64Length;
204
+ total += requiredStringBytes(block.contentId);
205
+ total += requiredStringBytes(block.originalContentId);
206
+ total += requiredStringBytes(block.selectedContentId);
207
+ total += VALUE_OVERHEAD_BYTES;
208
+ total += estimateValueBytes(block.originalObject, 1, seen);
209
+ total += estimateValueBytes(block.selectedObject, 1, seen);
210
+ total += estimateValueBytes(block.transformation, 1, seen);
211
+ if (block.dimensions !== undefined) {
212
+ total += estimateValueBytes(block.dimensions, 1, seen);
213
+ }
214
+ total += estimateValueBytes(block.semanticMetadata, 1, seen);
215
+ if (block.providerFileIds !== undefined) {
216
+ total += estimateValueBytes(block.providerFileIds, 1, seen);
217
+ }
198
218
  break;
199
219
  case 'tool_call':
200
220
  total += requiredStringBytes(block.name);
@@ -20,6 +20,12 @@ import type {
20
20
  ChronologyReplacedSpan,
21
21
  } from './IContent.js';
22
22
 
23
+ export interface ChronologyState {
24
+ readonly nextSeq: number;
25
+ readonly currentUserTurn: number;
26
+ readonly nextStep: number;
27
+ }
28
+
23
29
  /**
24
30
  * Stamps and reconciles {@link ChronologyMarker}s onto {@link IContent}.
25
31
  *
@@ -46,6 +52,20 @@ export class ChronologyStamper {
46
52
 
47
53
  constructor(private readonly now: () => number = Date.now) {}
48
54
 
55
+ snapshot(): ChronologyState {
56
+ return {
57
+ nextSeq: this.nextSeq,
58
+ currentUserTurn: this.currentUserTurn,
59
+ nextStep: this.nextStep,
60
+ };
61
+ }
62
+
63
+ restore(state: ChronologyState): void {
64
+ this.nextSeq = state.nextSeq;
65
+ this.currentUserTurn = state.currentUserTurn;
66
+ this.nextStep = state.nextStep;
67
+ }
68
+
49
69
  /**
50
70
  * Attach a chronology marker to `content` and return it.
51
71
  *
@@ -145,6 +165,35 @@ function collectSeqs(history: readonly IContent[]): Set<number> {
145
165
  return seqs;
146
166
  }
147
167
 
168
+ function transferSemanticMediaPurgeFrontier(
169
+ previousHistory: readonly IContent[],
170
+ newHistory: readonly IContent[],
171
+ ): IContent[] {
172
+ const frontier = previousHistory.find(
173
+ (content) => content.metadata?.semanticMediaPurgeFrontier !== undefined,
174
+ )?.metadata?.semanticMediaPurgeFrontier;
175
+ if (
176
+ frontier === undefined ||
177
+ newHistory.length === 0 ||
178
+ newHistory.some(
179
+ (content) => content.metadata?.semanticMediaPurgeFrontier !== undefined,
180
+ )
181
+ ) {
182
+ return [...newHistory];
183
+ }
184
+ const first = newHistory[0];
185
+ return [
186
+ {
187
+ ...first,
188
+ metadata: {
189
+ ...first.metadata,
190
+ semanticMediaPurgeFrontier: frontier,
191
+ },
192
+ },
193
+ ...newHistory.slice(1),
194
+ ];
195
+ }
196
+
148
197
  /**
149
198
  * Annotate summary entries in `newHistory` with the span of chronology seqs
150
199
  * destroyed by the compression that produced it.
@@ -180,7 +229,7 @@ export function annotateCompressionSpan(
180
229
  }
181
230
 
182
231
  if (destroyed.size === 0) {
183
- return [...newHistory];
232
+ return transferSemanticMediaPurgeFrontier(previousHistory, newHistory);
184
233
  }
185
234
 
186
235
  // Iterative min/max: spreading a Set into Math.min/Math.max puts every
@@ -205,10 +254,10 @@ export function annotateCompressionSpan(
205
254
  (item) => item.metadata?.isSummary === true,
206
255
  );
207
256
  if (!hasSummary) {
208
- return [...newHistory];
257
+ return transferSemanticMediaPurgeFrontier(previousHistory, newHistory);
209
258
  }
210
259
 
211
- return newHistory.map((item) => {
260
+ const annotated = newHistory.map((item) => {
212
261
  if (
213
262
  item.metadata?.isSummary === true &&
214
263
  item.metadata.chronologyReplaced === undefined
@@ -223,6 +272,7 @@ export function annotateCompressionSpan(
223
272
  }
224
273
  return item;
225
274
  });
275
+ return transferSemanticMediaPurgeFrontier(previousHistory, annotated);
226
276
  }
227
277
 
228
278
  /**