@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
@@ -45,6 +45,7 @@ import {
45
45
  } from './types.js';
46
46
  import { SessionLockManager, type LockHandle } from './SessionLockManager.js';
47
47
  import { replaySession } from './ReplayEngine.js';
48
+ import type { LocalMediaStore } from '../storage/local-media-store.js';
48
49
 
49
50
  export const SESSION_FILE_ID_PREFIX_LENGTH = 12;
50
51
 
@@ -54,6 +55,18 @@ export const SESSION_FILE_ID_PREFIX_LENGTH = 12;
54
55
  * never dropped, because the session file is the durable transcript.
55
56
  */
56
57
  const QUEUE_HIGH_WATER_RECORDS = 4096;
58
+ const MATERIALIZING_EVENT_TYPES: ReadonlySet<SessionEventType> = new Set([
59
+ 'content',
60
+ 'session_metadata',
61
+ 'session_named',
62
+ 'semantic_media_purge',
63
+ ]);
64
+
65
+ type RecordingLifecycle =
66
+ | { readonly status: 'active' }
67
+ | { readonly status: 'failed'; readonly error: unknown }
68
+ | { readonly status: 'failure-reported' }
69
+ | { readonly status: 'disposed' };
57
70
 
58
71
  /**
59
72
  * A record that has already been serialised. Serialising at enqueue time keeps
@@ -67,11 +80,46 @@ interface PendingRecord {
67
80
  readonly bytes: number;
68
81
  }
69
82
 
83
+ export interface PreparedContentBatch {
84
+ publish(): void;
85
+ rollback(): void;
86
+ finalize(): void;
87
+ }
88
+
70
89
  function toPendingRecord(line: SessionRecordLine): PendingRecord {
71
90
  const json = JSON.stringify(line);
72
91
  return { line, json, bytes: Buffer.byteLength(json, 'utf8') + 1 };
73
92
  }
74
93
 
94
+ function totalRecordBytes(records: readonly PendingRecord[]): number {
95
+ return records.reduce((total, record) => total + record.bytes, 0);
96
+ }
97
+
98
+ function containsMediaReference(
99
+ value: unknown,
100
+ seen = new WeakSet<object>(),
101
+ ): boolean {
102
+ if (typeof value !== 'object' || value === null) return false;
103
+ if (seen.has(value)) return false;
104
+ seen.add(value);
105
+ if (
106
+ Reflect.get(value, 'type') === 'media' &&
107
+ Reflect.get(value, 'encoding') === 'reference'
108
+ ) {
109
+ return true;
110
+ }
111
+ if (Array.isArray(value)) {
112
+ return value.some((entry) => containsMediaReference(entry, seen));
113
+ }
114
+ return Reflect.ownKeys(value).some((key) =>
115
+ containsMediaReference(Reflect.get(value, key), seen),
116
+ );
117
+ }
118
+
119
+ function recordingVersion(payload: unknown): number {
120
+ return containsMediaReference(payload) ? 2 : 1;
121
+ }
122
+
75
123
  /**
76
124
  * Core service for recording session events to a JSONL file.
77
125
  *
@@ -87,12 +135,14 @@ export class SessionRecordingService {
87
135
  private seq: number = 0;
88
136
  private filePath: string | null = null;
89
137
  private materialized: boolean = false;
90
- private active: boolean = true;
138
+ private lifecycle: RecordingLifecycle = { status: 'active' };
91
139
  private draining: boolean = false;
92
140
  private drainPromise: Promise<void> | null = null;
93
141
  private readonly sessionId: string;
94
142
  private readonly projectHash: string;
95
143
  private readonly chatsDir: string;
144
+ private readonly maxQueueBytes: number;
145
+ private readonly mediaStore: LocalMediaStore | undefined;
96
146
  private preContentBuffer: PendingRecord[] = [];
97
147
  private preContentBytes: number = 0;
98
148
  private chatsDirWatcher: { close(): void } | null = null;
@@ -129,9 +179,17 @@ export class SessionRecordingService {
129
179
  * @pseudocode session-recording-service.md lines 53-67
130
180
  */
131
181
  constructor(config: SessionRecordingServiceConfig) {
182
+ const maxQueueBytes = config.maxQueueBytes ?? Number.MAX_SAFE_INTEGER;
183
+ if (!Number.isSafeInteger(maxQueueBytes) || maxQueueBytes < 0) {
184
+ throw new Error(
185
+ 'Session recording queue byte limit must be a non-negative safe integer',
186
+ );
187
+ }
132
188
  this.sessionId = config.sessionId;
133
189
  this.projectHash = config.projectHash;
134
190
  this.chatsDir = config.chatsDir;
191
+ this.maxQueueBytes = maxQueueBytes;
192
+ this.mediaStore = config.mediaStore;
135
193
 
136
194
  const startPayload = {
137
195
  sessionId: config.sessionId,
@@ -153,15 +211,16 @@ export class SessionRecordingService {
153
211
  * @pseudocode session-recording-service.md lines 69-79
154
212
  */
155
213
  private bufferPreContent(type: SessionEventType, payload: unknown): void {
156
- this.seq++;
157
214
  const line: SessionRecordLine = {
158
- v: 1,
159
- seq: this.seq,
215
+ v: type === 'semantic_media_purge' ? 2 : recordingVersion(payload),
216
+ seq: this.seq + 1,
160
217
  ts: new Date().toISOString(),
161
218
  type,
162
219
  payload,
163
220
  };
164
221
  const record = toPendingRecord(line);
222
+ this.reserveQueueBytes(record.bytes);
223
+ this.seq = line.seq;
165
224
  this.preContentBuffer.push(record);
166
225
  this.preContentBytes += record.bytes;
167
226
  this.reportHighWater();
@@ -176,40 +235,32 @@ export class SessionRecordingService {
176
235
  * @pseudocode session-recording-service.md lines 81-110
177
236
  */
178
237
  enqueue(type: SessionEventType, payload: unknown): SessionRecordLine | null {
179
- if (!this.active) return null;
180
-
181
- if (
182
- (type === 'content' ||
183
- type === 'session_metadata' ||
184
- type === 'session_named') &&
185
- !this.materialized
186
- ) {
187
- this.materialize();
188
- for (const buffered of this.preContentBuffer) {
189
- this.queue.push(buffered);
190
- }
191
- this.queueBytes += this.preContentBytes;
192
- this.preContentBuffer = [];
193
- this.preContentBytes = 0;
194
- this.materialized = true;
195
- }
196
-
197
- if (!this.materialized && type !== 'content') {
238
+ if (this.lifecycle.status !== 'active') return null;
239
+ if (!this.materialized && !MATERIALIZING_EVENT_TYPES.has(type)) {
198
240
  this.bufferPreContent(type, payload);
199
241
  return (
200
242
  this.preContentBuffer[this.preContentBuffer.length - 1]?.line ?? null
201
243
  );
202
244
  }
203
245
 
204
- this.seq++;
205
246
  const line: SessionRecordLine = {
206
- v: 1,
207
- seq: this.seq,
247
+ v: type === 'semantic_media_purge' ? 2 : recordingVersion(payload),
248
+ seq: this.seq + 1,
208
249
  ts: new Date().toISOString(),
209
250
  type,
210
251
  payload,
211
252
  };
212
253
  const record = toPendingRecord(line);
254
+ this.reserveQueueBytes(record.bytes);
255
+ if (!this.materialized) {
256
+ this.materialize();
257
+ this.queue.push(...this.preContentBuffer);
258
+ this.queueBytes += this.preContentBytes;
259
+ this.preContentBuffer = [];
260
+ this.preContentBytes = 0;
261
+ this.materialized = true;
262
+ }
263
+ this.seq = line.seq;
213
264
  this.queue.push(record);
214
265
  this.queueBytes += record.bytes;
215
266
  this.reportHighWater();
@@ -217,6 +268,46 @@ export class SessionRecordingService {
217
268
  return line;
218
269
  }
219
270
 
271
+ private reserveQueueBytes(bytes: number): void {
272
+ const pendingBytes = this.queueBytes + this.preContentBytes;
273
+ if (bytes > this.maxQueueBytes - pendingBytes) {
274
+ throw new Error(
275
+ `Session recording queue byte limit exceeded: ${pendingBytes} + ${bytes} > ${this.maxQueueBytes}`,
276
+ );
277
+ }
278
+ }
279
+
280
+ private takeRecordingFailure(): unknown | undefined {
281
+ if (this.lifecycle.status !== 'failed') return undefined;
282
+ const error = this.lifecycle.error;
283
+ this.lifecycle = { status: 'failure-reported' };
284
+ return error;
285
+ }
286
+
287
+ private transitionToFailure(error: unknown): void {
288
+ const failures: unknown[] = [error];
289
+ this.queue = [];
290
+ this.queueBytes = 0;
291
+ this.preContentBuffer = [];
292
+ this.preContentBytes = 0;
293
+ try {
294
+ this.chatsDirWatcher?.close();
295
+ } catch (cleanupError: unknown) {
296
+ failures.push(cleanupError);
297
+ }
298
+ this.chatsDirWatcher = null;
299
+ this.lifecycle = {
300
+ status: 'failed',
301
+ error:
302
+ failures.length === 1
303
+ ? error
304
+ : new AggregateError(
305
+ failures,
306
+ 'Session recording write and watcher cleanup failed',
307
+ ),
308
+ };
309
+ }
310
+
220
311
  /**
221
312
  * Reports, once, that the writer has fallen far behind. Deliberately does not
222
313
  * drop records: the JSONL file is the durable transcript, and the queue is
@@ -302,11 +393,7 @@ export class SessionRecordingService {
302
393
  ` error: ${error}`,
303
394
  );
304
395
  }
305
- this.queue = [];
306
- this.queueBytes = 0;
307
- this.chatsDirWatcher?.close();
308
- this.chatsDirWatcher = null;
309
- this.active = false;
396
+ this.transitionToFailure(error);
310
397
  });
311
398
  }
312
399
 
@@ -321,13 +408,16 @@ export class SessionRecordingService {
321
408
  try {
322
409
  while (this.queue.length > 0) {
323
410
  const batch = [...this.queue];
324
- this.queue = [];
325
- this.queueBytes = 0;
326
411
  const lines = batch.map((record) => record.json).join('\n') + '\n';
327
412
  const shouldContinue = await this.writeBatchToFile(lines);
328
413
  if (!shouldContinue) {
329
414
  return;
330
415
  }
416
+ this.queue = this.queue.slice(batch.length);
417
+ this.queueBytes -= batch.reduce(
418
+ (total, record) => total + record.bytes,
419
+ 0,
420
+ );
331
421
  }
332
422
  } finally {
333
423
  this.draining = false;
@@ -344,11 +434,7 @@ export class SessionRecordingService {
344
434
  return true;
345
435
  } catch (error: unknown) {
346
436
  if (this.isDiskSpaceError(error)) {
347
- this.queue = [];
348
- this.queueBytes = 0;
349
- this.chatsDirWatcher?.close();
350
- this.chatsDirWatcher = null;
351
- this.active = false;
437
+ this.transitionToFailure(error);
352
438
  return false;
353
439
  }
354
440
  throw error;
@@ -372,16 +458,25 @@ export class SessionRecordingService {
372
458
  * @pseudocode session-recording-service.md lines 148-160
373
459
  */
374
460
  async flush(): Promise<void> {
375
- if (!this.active) return;
461
+ const existingFailure = this.takeRecordingFailure();
462
+ if (existingFailure !== undefined) throw existingFailure;
463
+ if (this.lifecycle.status !== 'active') return;
376
464
  if (this.queue.length === 0 && !this.draining) return;
377
465
 
378
466
  if (this.drainPromise) {
379
467
  await this.drainPromise;
468
+ const drainFailure = this.takeRecordingFailure();
469
+ if (drainFailure !== undefined) throw drainFailure;
380
470
  }
381
471
 
382
472
  if (this.queue.length > 0) {
383
- this.drainPromise = this.drain();
473
+ this.draining = true;
474
+ this.drainPromise = this.drain().catch((error: unknown) => {
475
+ this.transitionToFailure(error);
476
+ });
384
477
  await this.drainPromise;
478
+ const drainFailure = this.takeRecordingFailure();
479
+ if (drainFailure !== undefined) throw drainFailure;
385
480
  }
386
481
  }
387
482
 
@@ -393,7 +488,7 @@ export class SessionRecordingService {
393
488
  * @pseudocode session-recording-service.md line 162-164
394
489
  */
395
490
  isActive(): boolean {
396
- return this.active;
491
+ return this.lifecycle.status === 'active';
397
492
  }
398
493
 
399
494
  /**
@@ -420,7 +515,9 @@ export class SessionRecordingService {
420
515
 
421
516
  ownsLockFor(sessionId: string): boolean {
422
517
  return (
423
- this.active && this.sessionId === sessionId && this.lockHandle !== null
518
+ this.lifecycle.status === 'active' &&
519
+ this.sessionId === sessionId &&
520
+ this.lockHandle !== null
424
521
  );
425
522
  }
426
523
 
@@ -433,7 +530,7 @@ export class SessionRecordingService {
433
530
  }
434
531
 
435
532
  getOwnedLockHandle(): LockHandle | null {
436
- return this.active ? this.lockHandle : null;
533
+ return this.lifecycle.status === 'active' ? this.lockHandle : null;
437
534
  }
438
535
 
439
536
  /**
@@ -467,14 +564,14 @@ export class SessionRecordingService {
467
564
  */
468
565
  async dispose(): Promise<void> {
469
566
  const failures: unknown[] = [];
470
- if (this.active) {
567
+ if (this.lifecycle.status !== 'disposed') {
471
568
  try {
472
569
  await this.flush();
473
570
  } catch (error: unknown) {
474
571
  failures.push(error);
475
572
  }
476
573
  }
477
- this.active = false;
574
+ this.lifecycle = { status: 'disposed' };
478
575
  this.queue = [];
479
576
  this.queueBytes = 0;
480
577
  this.preContentBuffer = [];
@@ -601,6 +698,97 @@ export class SessionRecordingService {
601
698
  this.enqueue('content', { content });
602
699
  }
603
700
 
701
+ prepareContentBatch(contents: readonly IContent[]): PreparedContentBatch {
702
+ if (this.lifecycle.status !== 'active') {
703
+ throw new Error('Cannot record content batch: recording is not active');
704
+ }
705
+ if (this.draining) {
706
+ throw new Error(
707
+ 'Cannot record content batch while recording is draining',
708
+ );
709
+ }
710
+
711
+ const expectedSeq = this.seq;
712
+ const records = contents.map((content, index) =>
713
+ toPendingRecord({
714
+ v: recordingVersion({ content }),
715
+ seq: expectedSeq + index + 1,
716
+ ts: new Date().toISOString(),
717
+ type: 'content',
718
+ payload: { content },
719
+ }),
720
+ );
721
+ const batchBytes = totalRecordBytes(records);
722
+ const pendingBytes = this.queueBytes + this.preContentBytes;
723
+ if (batchBytes > this.maxQueueBytes - pendingBytes) {
724
+ throw new Error(
725
+ `Session recording queue byte limit exceeded: ${pendingBytes} + ${batchBytes} > ${this.maxQueueBytes}`,
726
+ );
727
+ }
728
+
729
+ const queueBefore = this.queue;
730
+ const queueBytesBefore = this.queueBytes;
731
+ const preContentBefore = this.preContentBuffer;
732
+ const preContentBytesBefore = this.preContentBytes;
733
+ const materializedBefore = this.materialized;
734
+ const filePathBefore = this.filePath;
735
+ const watcherBefore = this.chatsDirWatcher;
736
+ let published = false;
737
+ let finalized = false;
738
+
739
+ return {
740
+ publish: () => {
741
+ if (published) throw new Error('Content batch was already published');
742
+ if (this.seq !== expectedSeq) {
743
+ throw new Error('Recording changed after content batch preflight');
744
+ }
745
+ published = true;
746
+ if (!this.materialized) {
747
+ this.materialize();
748
+ this.queue = [...this.preContentBuffer, ...records];
749
+ this.queueBytes = this.preContentBytes + batchBytes;
750
+ this.preContentBuffer = [];
751
+ this.preContentBytes = 0;
752
+ this.materialized = true;
753
+ } else {
754
+ this.queue = [...this.queue, ...records];
755
+ this.queueBytes += batchBytes;
756
+ }
757
+ this.seq = expectedSeq + records.length;
758
+ this.reportHighWater();
759
+ },
760
+ rollback: () => {
761
+ if (!published || finalized) return;
762
+ if (this.chatsDirWatcher !== watcherBefore) {
763
+ this.chatsDirWatcher?.close();
764
+ }
765
+ this.queue = queueBefore;
766
+ this.queueBytes = queueBytesBefore;
767
+ this.preContentBuffer = preContentBefore;
768
+ this.preContentBytes = preContentBytesBefore;
769
+ this.materialized = materializedBefore;
770
+ this.filePath = filePathBefore;
771
+ this.chatsDirWatcher = watcherBefore;
772
+ this.seq = expectedSeq;
773
+ published = false;
774
+ },
775
+ finalize: () => {
776
+ if (!published) {
777
+ throw new Error('Cannot finalize an unpublished content batch');
778
+ }
779
+ finalized = true;
780
+ this.scheduleDrain();
781
+ },
782
+ };
783
+ }
784
+
785
+ recordSemanticMediaPurge(
786
+ history: readonly IContent[],
787
+ frontier: { readonly contentIndex: number; readonly blockIndex: number },
788
+ ): void {
789
+ this.enqueue('semantic_media_purge', { history, frontier });
790
+ }
791
+
604
792
  /**
605
793
  * Record a compression event — history was compressed into a summary.
606
794
  *
@@ -613,14 +801,22 @@ export class SessionRecordingService {
613
801
  }
614
802
 
615
803
  /**
616
- * Record a rewind event — last N items removed from history.
804
+ * Record a rewind event — history cut from `cutSeq` onwards, which removed
805
+ * `itemsRemoved` items from live history.
806
+ *
807
+ * `cutSeq` is the chronology `seq` of the first removed item and is omitted
808
+ * entirely when the caller could not resolve one, keeping the event
809
+ * byte-identical to a legacy count-only rewind (#2934).
617
810
  *
618
811
  * @plan PLAN-20260211-SESSIONRECORDING.P05
619
812
  * @requirement REQ-REC-002
620
813
  * @pseudocode session-recording-service.md lines 198-200
621
814
  */
622
- recordRewind(itemsRemoved: number): void {
623
- this.enqueue('rewind', { itemsRemoved });
815
+ recordRewind(itemsRemoved: number, cutSeq?: number): void {
816
+ this.enqueue(
817
+ 'rewind',
818
+ cutSeq === undefined ? { itemsRemoved } : { itemsRemoved, cutSeq },
819
+ );
624
820
  }
625
821
 
626
822
  /**
@@ -669,7 +865,7 @@ export class SessionRecordingService {
669
865
  * @requirement REQ-REC-002
670
866
  */
671
867
  recordSessionMetadata(title: string | null): void {
672
- if (!this.active) {
868
+ if (this.lifecycle.status !== 'active') {
673
869
  return;
674
870
  }
675
871
  this.enqueue('session_metadata', { title });
@@ -693,7 +889,7 @@ export class SessionRecordingService {
693
889
  * Rejects if the conversation is empty/unmaterialized or the recorder is inactive.
694
890
  */
695
891
  async createCheckpoint(name: string): Promise<RecordingCheckpointInfo> {
696
- if (!this.active) {
892
+ if (this.lifecycle.status !== 'active') {
697
893
  throw new Error('Cannot create checkpoint: recording is not active');
698
894
  }
699
895
  if (!this.materialized) {
@@ -713,7 +909,9 @@ export class SessionRecordingService {
713
909
  'Cannot create checkpoint: conversation has no content yet',
714
910
  );
715
911
  }
716
- const replay = await replaySession(filePath, this.projectHash);
912
+ const replay = await replaySession(filePath, this.projectHash, {
913
+ mediaStore: this.mediaStore,
914
+ });
717
915
  if (!replay.ok) {
718
916
  throw new Error(`Cannot create checkpoint: ${replay.error}`);
719
917
  }
@@ -746,7 +944,7 @@ export class SessionRecordingService {
746
944
  * The lifecycle event is flushed before the promise resolves.
747
945
  */
748
946
  async deleteCheckpoint(checkpointId: string): Promise<void> {
749
- if (!this.active) {
947
+ if (this.lifecycle.status !== 'active') {
750
948
  throw new Error('Cannot delete checkpoint: recording is not active');
751
949
  }
752
950
  if (!this.materialized) {
@@ -763,7 +961,7 @@ export class SessionRecordingService {
763
961
  * Only display metadata changes; the watermark and ID are unaffected.
764
962
  */
765
963
  async renameCheckpoint(checkpointId: string, name: string): Promise<void> {
766
- if (!this.active) {
964
+ if (this.lifecycle.status !== 'active') {
767
965
  throw new Error('Cannot rename checkpoint: recording is not active');
768
966
  }
769
967
  if (!this.materialized) {
@@ -784,7 +982,7 @@ export class SessionRecordingService {
784
982
  * Pass `null` to clear the name.
785
983
  */
786
984
  async setSessionName(name: string | null): Promise<void> {
787
- if (!this.active) {
985
+ if (this.lifecycle.status !== 'active') {
788
986
  throw new Error('Cannot set session name: recording is not active');
789
987
  }
790
988
  const resolved = name === null ? null : name.trim();
@@ -807,7 +1005,7 @@ export class SessionRecordingService {
807
1005
  * The child recording is self-contained after this.
808
1006
  */
809
1007
  recordSessionFork(payload: SessionForkedPayload): void {
810
- if (!this.active) {
1008
+ if (this.lifecycle.status !== 'active') {
811
1009
  throw new Error('Cannot record session fork: recording is inactive');
812
1010
  }
813
1011
  this.enqueue('session_forked', payload);
@@ -19,6 +19,7 @@ import { type IContent } from '../services/history/IContent.js';
19
19
  import { replaySession, replaySessionThroughSequence } from './ReplayEngine.js';
20
20
  import { SessionLockManager, type LockHandle } from './SessionLockManager.js';
21
21
  import { SessionRecordingService } from './SessionRecordingService.js';
22
+ import type { LocalMediaStore } from '../storage/local-media-store.js';
22
23
  import {
23
24
  type CheckpointMetadataView,
24
25
  type ContinueTarget,
@@ -46,6 +47,8 @@ interface ForkRuntime {
46
47
  provider: string;
47
48
  model: string;
48
49
  workspaceDirs: string[];
50
+ mediaStore?: LocalMediaStore;
51
+ maxQueueBytes?: number;
49
52
  }
50
53
 
51
54
  type CheckpointTarget = Extract<ContinueTarget, { kind: 'checkpoint' }>;
@@ -60,8 +63,11 @@ type HistoryResult =
60
63
  async function loadCheckpointHistory(
61
64
  target: CheckpointTarget,
62
65
  projectHash: string,
66
+ mediaStore: LocalMediaStore | undefined,
63
67
  ): Promise<HistoryResult> {
64
- const fullReplay = await replaySession(target.source.filePath, projectHash);
68
+ const fullReplay = await replaySession(target.source.filePath, projectHash, {
69
+ mediaStore,
70
+ });
65
71
  if (!fullReplay.ok) {
66
72
  return {
67
73
  ok: false,
@@ -88,6 +94,7 @@ async function loadCheckpointHistory(
88
94
  target.source.filePath,
89
95
  projectHash,
90
96
  liveCheckpoint.sequence,
97
+ { mediaStore },
91
98
  );
92
99
  if (!boundedReplay.ok) {
93
100
  return {
@@ -115,14 +122,37 @@ async function loadCheckpointHistory(
115
122
  async function cleanupFailedChild(
116
123
  recording: SessionRecordingService | null,
117
124
  lockHandle: LockHandle | null,
118
- ): Promise<void> {
125
+ ): Promise<unknown[]> {
126
+ const failures: unknown[] = [];
119
127
  const filePath = recording?.getFilePath() ?? null;
120
- const ownedLock = recording?.getOwnedLockHandle() ?? lockHandle;
121
- await recording?.dispose().catch(() => undefined);
122
- await ownedLock?.release().catch(() => undefined);
128
+ if (recording !== null) {
129
+ try {
130
+ await recording.dispose();
131
+ } catch (error: unknown) {
132
+ failures.push(error);
133
+ }
134
+ } else if (lockHandle !== null) {
135
+ try {
136
+ await lockHandle.release();
137
+ } catch (error: unknown) {
138
+ failures.push(error);
139
+ }
140
+ }
123
141
  if (filePath !== null) {
124
- await fs.unlink(filePath).catch(() => undefined);
142
+ try {
143
+ await fs.rm(filePath, { recursive: true, force: true });
144
+ } catch (error: unknown) {
145
+ failures.push(error);
146
+ }
125
147
  }
148
+ return failures;
149
+ }
150
+
151
+ function failureDetail(error: unknown): string {
152
+ if (error instanceof AggregateError) {
153
+ return error.errors.map(failureDetail).join('; ');
154
+ }
155
+ return error instanceof Error ? error.message : String(error);
126
156
  }
127
157
 
128
158
  async function materializeChild(
@@ -141,6 +171,12 @@ async function materializeChild(
141
171
  workspaceDirs: runtime.workspaceDirs,
142
172
  provider: runtime.provider,
143
173
  model: runtime.model,
174
+ ...(runtime.mediaStore === undefined
175
+ ? {}
176
+ : { mediaStore: runtime.mediaStore }),
177
+ ...(runtime.maxQueueBytes === undefined
178
+ ? {}
179
+ : { maxQueueBytes: runtime.maxQueueBytes }),
144
180
  });
145
181
  recording.recordSessionFork({
146
182
  parentSessionId: target.source.sessionId,
@@ -159,15 +195,25 @@ async function materializeChild(
159
195
  }
160
196
  await fs.access(childFilePath);
161
197
  } catch (error: unknown) {
162
- await cleanupFailedChild(recording, null);
163
- const detail = error instanceof Error ? error.message : String(error);
164
- return { ok: false, error: `Failed to create child session: ${detail}` };
198
+ const cleanupFailures = await cleanupFailedChild(recording, null);
199
+ const failures = [error, ...cleanupFailures];
200
+ return {
201
+ ok: false,
202
+ error: `Failed to create child session: ${failures.map(failureDetail).join('; ')}`,
203
+ };
165
204
  }
166
205
 
167
206
  const lockHandle = recording.getOwnedLockHandle();
168
207
  if (lockHandle === null) {
169
- await cleanupFailedChild(recording, null);
170
- return { ok: false, error: 'Failed to retain child session lock' };
208
+ const cleanupFailures = await cleanupFailedChild(recording, null);
209
+ const detail = cleanupFailures.map(failureDetail).join('; ');
210
+ return {
211
+ ok: false,
212
+ error:
213
+ detail.length === 0
214
+ ? 'Failed to retain child session lock'
215
+ : `Failed to retain child session lock; cleanup failed: ${detail}`,
216
+ };
171
217
  }
172
218
  return {
173
219
  ok: true,
@@ -185,7 +231,14 @@ async function materializeChild(
185
231
  };
186
232
  }
187
233
 
234
+ export interface SessionTransitionServiceOptions {
235
+ readonly mediaStore?: LocalMediaStore;
236
+ readonly maxQueueBytes?: number;
237
+ }
238
+
188
239
  export class SessionTransitionService {
240
+ constructor(private readonly options: SessionTransitionServiceOptions = {}) {}
241
+
189
242
  async forkFromCheckpoint(
190
243
  target: CheckpointTarget,
191
244
  chatsDir: string,
@@ -211,7 +264,11 @@ export class SessionTransitionService {
211
264
  }
212
265
  }
213
266
  try {
214
- const history = await loadCheckpointHistory(target, projectHash);
267
+ const history = await loadCheckpointHistory(
268
+ target,
269
+ projectHash,
270
+ this.options.mediaStore,
271
+ );
215
272
  if (!history.ok) return history;
216
273
  return await materializeChild(
217
274
  target,
@@ -223,6 +280,12 @@ export class SessionTransitionService {
223
280
  provider: currentProvider,
224
281
  model: currentModel,
225
282
  workspaceDirs,
283
+ ...(this.options.mediaStore === undefined
284
+ ? {}
285
+ : { mediaStore: this.options.mediaStore }),
286
+ ...(this.options.maxQueueBytes === undefined
287
+ ? {}
288
+ : { maxQueueBytes: this.options.maxQueueBytes }),
226
289
  },
227
290
  );
228
291
  } finally {
@@ -92,3 +92,10 @@ export {
92
92
  type SessionCleanupResult,
93
93
  type UserRetentionSettings,
94
94
  } from './SessionJanitor.js';
95
+ export {
96
+ exportSessionMediaPackage,
97
+ importSessionMediaPackage,
98
+ validateSessionMediaPackage,
99
+ type ImportedSessionMediaPackage,
100
+ type ValidatedSessionMediaPackage,
101
+ } from './session-media-package.js';