@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
@@ -9,9 +9,27 @@ import { promises as fs } from 'node:fs';
9
9
  import { ensureDir } from '../utils/paths.js';
10
10
  import { Storage } from '@vybestack/llxprt-code-settings';
11
11
  import { debugLogger } from '../utils/debugLogger.js';
12
+ import { delay } from '../utils/delay.js';
12
13
 
13
14
  const LOG_FILE_NAME = 'logs.json';
14
15
  const BACKUP_RETENTION_DAYS = 30;
16
+ // Guard files are inert the moment a rename race loses, so they only need a
17
+ // cutoff comfortably beyond any conceivable forensic interest.
18
+ const GUARD_RETENTION_MS = 24 * 60 * 60 * 1000;
19
+ // Advisory inter-process locking via an O_EXCL lockfile (fs.open 'wx'). Keep the
20
+ // file-mutating sequences serialized across processes; the lock file is deleted on
21
+ // release and recovered when its mtime proves the holder crashed.
22
+ const LOCK_FILE_SUFFIX = '.lock';
23
+ const LOCK_STALE_MS = 30_000;
24
+ const LOCK_BACKOFF_MS = 25;
25
+ // Lease refresh while holding: the holder re-stamps its own lock mtime so a long
26
+ // critical section (large legacy migration, slow FS) cannot age past the staleness
27
+ // threshold and get broken by a waiter.
28
+ const LOCK_HEARTBEAT_MS = 10_000;
29
+ const DEFAULT_LOCK_TIMEOUT_MS = 5_000;
30
+ // Monotonic per-process counter keeps transition-guard names unique inside one
31
+ // millisecond so two mutations in this process can never target the same guard file.
32
+ let lockMutationCounter = 0;
15
33
 
16
34
  export enum MessageSenderType {
17
35
  USER = 'user',
@@ -45,6 +63,9 @@ export class Logger {
45
63
  private sessionId: string | undefined;
46
64
  private messageId = 0; // Instance-specific counter for the next messageId
47
65
  private initialized = false;
66
+ // Set by close(): a closed logger must stay dead instead of lazily
67
+ // re-initializing on the next logMessage.
68
+ private _closed = false;
48
69
  private logs: LogEntry[] = []; // In-memory cache, ideally reflects the last known state of the file
49
70
  private _formatMigrated = false; // True once legacy format check/migration has run
50
71
  private _diskIsLegacy = false; // True when the on-disk file is still legacy JSON-array at load
@@ -53,6 +74,9 @@ export class Logger {
53
74
  // cannot interleave at an await and reuse the same messageId (the old sync
54
75
  // write path was implicitly serialized because it never yielded).
55
76
  private _writeQueue: Promise<unknown> = Promise.resolve();
77
+ // In-flight initialize() so close() can drain it before clearing state —
78
+ // otherwise a late commit could resurrect a closed logger.
79
+ private _initPromise: Promise<void> | undefined;
56
80
 
57
81
  constructor(
58
82
  sessionId: string,
@@ -61,6 +85,230 @@ export class Logger {
61
85
  this.sessionId = sessionId;
62
86
  }
63
87
 
88
+ /**
89
+ * Acquisition deadline for the advisory log-file lock. The
90
+ * `LLXPRT_LOG_LOCK_TIMEOUT_MS` override is deliberately gated to test runs
91
+ * (bun sets NODE_ENV=test): as an undocumented production knob it could
92
+ * silently degrade every contended append, so production always uses the
93
+ * default.
94
+ */
95
+ private _lockTimeoutMs(): number {
96
+ if (process.env['NODE_ENV'] !== 'test') {
97
+ return DEFAULT_LOCK_TIMEOUT_MS;
98
+ }
99
+ const raw = process.env['LLXPRT_LOG_LOCK_TIMEOUT_MS'];
100
+ if (raw !== undefined && raw.trim().length > 0) {
101
+ const parsed = Number(raw);
102
+ if (Number.isFinite(parsed) && parsed > 0) {
103
+ return parsed;
104
+ }
105
+ }
106
+ return DEFAULT_LOCK_TIMEOUT_MS;
107
+ }
108
+
109
+ private _lockFilePath(): string {
110
+ if (!this.logFilePath) {
111
+ throw new Error('Log file path not set during lock operation.');
112
+ }
113
+ return `${this.logFilePath}${LOCK_FILE_SUFFIX}`;
114
+ }
115
+
116
+ /**
117
+ * Acquire the per-log-file lock via the O_EXCL pattern (`fs.open 'wx'`).
118
+ * Retries with a small fixed backoff until it either wins the race, recovers a
119
+ * stale lock (via an atomic rename-guard claim, so a stale break can never
120
+ * bare-unlink a successor's live lock), or hits the acquisition deadline.
121
+ * The exclusive descriptor stays open for the whole critical section: it pins
122
+ * the lock file's inode so ownership can later be verified by inode identity
123
+ * without reading any file content.
124
+ */
125
+ private async _acquireLogLock(lockPath: string): Promise<fs.FileHandle> {
126
+ const deadline = Date.now() + this._lockTimeoutMs();
127
+ for (;;) {
128
+ // Deadline first, so no branch below can bypass it: a persistently
129
+ // failing stale-break (e.g. a dangling symlink at the lock path, or a
130
+ // non-writable directory) must time out like any other contention,
131
+ // never hot-loop and wedge the caller's write queue and close().
132
+ if (Date.now() >= deadline) {
133
+ throw new Error(`Timed out waiting for log lock ${lockPath}`);
134
+ }
135
+ const handle = await this._tryAcquireLogLock(lockPath);
136
+ if (handle !== null) {
137
+ return handle;
138
+ }
139
+ await this._tryBreakStaleLock(lockPath);
140
+ // Always back off between attempts — including after a confirmed break —
141
+ // so a persistent failure can never spin hot.
142
+ await delay(LOCK_BACKOFF_MS);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Create the lock file, write a diagnostic payload ({pid, timestamp}), and
148
+ * keep the descriptor open as the ownership proof. Returns the handle when
149
+ * this process now owns the lock, null when another process holds it (EEXIST).
150
+ * If the exclusive create won but finalizing failed, the just-created lock
151
+ * file has no owner and must not be left behind for waiters to trip on.
152
+ */
153
+ private async _tryAcquireLogLock(
154
+ lockPath: string,
155
+ ): Promise<fs.FileHandle | null> {
156
+ let handle: fs.FileHandle | undefined;
157
+ try {
158
+ handle = await fs.open(lockPath, 'wx');
159
+ await handle.writeFile(
160
+ JSON.stringify({ pid: process.pid, timestamp: Date.now() }),
161
+ 'utf-8',
162
+ );
163
+ return handle;
164
+ } catch (error) {
165
+ if (handle !== undefined) {
166
+ await handle.close().catch(() => {});
167
+ await fs.unlink(lockPath).catch(() => {});
168
+ }
169
+ const nodeError = error as NodeJS.ErrnoException;
170
+ if (nodeError.code !== 'EEXIST') {
171
+ throw error;
172
+ }
173
+ return null;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Try to break a lock whose mtime is past the staleness threshold without ever
179
+ * bare-unlinking the live lock path (POSIX rename overwrites, so a blind unlink
180
+ * could delete a successor's fresh lock). The live name is atomically moved to a
181
+ * unique guard — only one contender can win the rename — then re-verified as
182
+ * stale. A fresh file that was moved by mistake is restored with a hard link
183
+ * (link fails EEXIST rather than overwriting) rather than deleted.
184
+ */
185
+ private async _tryBreakStaleLock(lockPath: string): Promise<boolean> {
186
+ let lockStat: Awaited<ReturnType<typeof fs.stat>>;
187
+ try {
188
+ lockStat = await fs.stat(lockPath);
189
+ } catch {
190
+ // The lock vanished between our failed open and this stat — retry the open.
191
+ return true;
192
+ }
193
+ if (Date.now() - lockStat.mtimeMs <= LOCK_STALE_MS) {
194
+ return false;
195
+ }
196
+ const guardPath = this._guardPath(lockPath, 'brk');
197
+ try {
198
+ await fs.rename(lockPath, guardPath);
199
+ } catch {
200
+ // Another waiter claimed the stale lock first — retry the open.
201
+ return true;
202
+ }
203
+ try {
204
+ const guardStat = await fs.stat(guardPath);
205
+ if (Date.now() - guardStat.mtimeMs > LOCK_STALE_MS) {
206
+ await fs.unlink(guardPath).catch(() => {});
207
+ return true;
208
+ }
209
+ } catch {
210
+ // The moved guard file vanished — retry the open.
211
+ return true;
212
+ }
213
+ // The renamed file is younger than the threshold: the holder refreshed it or a
214
+ // successor acquired between our stat and rename. Restore it without clobbering
215
+ // a lock that may have been re-created at the live path in the meantime.
216
+ try {
217
+ await fs.link(guardPath, lockPath);
218
+ await fs.unlink(guardPath);
219
+ } catch {
220
+ debugLogger.debug(
221
+ `Lock replaced while breaking stale lock; inert guard left behind: ${guardPath}`,
222
+ );
223
+ }
224
+ return false;
225
+ }
226
+
227
+ /**
228
+ * Run `fn` while this process owns `logFilePath`'s advisory lock and release it
229
+ * in `finally`, so reader/writer sequences cannot interleave with other processes.
230
+ * A heartbeat re-stamps the held descriptor's inode (not the lock path, so a
231
+ * broken holder can never refresh a successor's lock) to keep the lease alive
232
+ * during long critical sections such as a slow legacy migration. Never nested:
233
+ * no code inside the wrapped callbacks acquires again.
234
+ */
235
+ private async _withLogLock<T>(fn: () => Promise<T>): Promise<T> {
236
+ const lockPath = this._lockFilePath();
237
+ const handle = await this._acquireLogLock(lockPath);
238
+ const heartbeat = setInterval(() => {
239
+ const now = new Date();
240
+ // Best-effort lease refresh: futimes on our own descriptor touches only
241
+ // the inode we pinned, even if the lock path has since been taken over.
242
+ void handle.utimes(now, now).catch(() => {});
243
+ }, LOCK_HEARTBEAT_MS);
244
+ heartbeat.unref();
245
+ try {
246
+ return await fn();
247
+ } finally {
248
+ clearInterval(heartbeat);
249
+ await this._releaseLogLock(lockPath, handle);
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Release the lock without a bare unlink and without reading any file
255
+ * content (steady-state appends must stay read-free). The live name is moved
256
+ * to a unique guard; the guard's inode is compared against the descriptor we
257
+ * have pinned since acquisition, which proves ownership race-free. Only our
258
+ * own inode is ever unlinked — a mismatched guard (our lock was broken and a
259
+ * successor owns the path) is restored via a hard link, which fails EEXIST
260
+ * rather than clobbering a newer lock.
261
+ */
262
+ private async _releaseLogLock(
263
+ lockPath: string,
264
+ handle: fs.FileHandle,
265
+ ): Promise<void> {
266
+ const guardPath = this._guardPath(lockPath, 'rel');
267
+ try {
268
+ await fs.rename(lockPath, guardPath);
269
+ } catch (error) {
270
+ // ENOENT: the lock was already broken or removed — nothing to release.
271
+ // Any other errno abandons the path on purpose: a blind unlink could
272
+ // delete a successor's live lock. Waiters recover via staleness.
273
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
274
+ debugLogger.debug(
275
+ `Failed to claim log lock for release (${(error as NodeJS.ErrnoException).code}); leaving it for stale recovery:`,
276
+ error,
277
+ );
278
+ }
279
+ await handle.close().catch(() => {});
280
+ return;
281
+ }
282
+ try {
283
+ const [guardStat, ownStat] = await Promise.all([
284
+ fs.stat(guardPath),
285
+ handle.stat(),
286
+ ]);
287
+ if (guardStat.ino === ownStat.ino && guardStat.dev === ownStat.dev) {
288
+ await fs.unlink(guardPath).catch((error: unknown) => {
289
+ debugLogger.debug('Failed to remove log lock file:', error);
290
+ });
291
+ return;
292
+ }
293
+ // Not our inode: we were broken mid-hold and renamed away a successor's
294
+ // live lock. Restore it without clobbering a lock that may already have
295
+ // been re-created at the live path.
296
+ await fs.link(guardPath, lockPath);
297
+ await fs.unlink(guardPath);
298
+ } catch {
299
+ debugLogger.debug(
300
+ `Lock replaced during release; inert guard left behind: ${guardPath}`,
301
+ );
302
+ } finally {
303
+ await handle.close().catch(() => {});
304
+ }
305
+ }
306
+
307
+ private _guardPath(lockPath: string, kind: 'brk' | 'rel'): string {
308
+ lockMutationCounter++;
309
+ return `${lockPath}.${kind}.${process.pid}.${Date.now()}.${lockMutationCounter}`;
310
+ }
311
+
64
312
  private _parseLegacyJsonArray(trimmed: string): LogEntry[] | null {
65
313
  if (!trimmed.startsWith('[')) {
66
314
  return null;
@@ -214,6 +462,26 @@ export class Logger {
214
462
  return;
215
463
  }
216
464
  if (this._diskIsLegacy) {
465
+ if (this.initialized) {
466
+ // Append-time retry: initialize's eager migration failed and was
467
+ // swallowed, so this.logs may be a stale snapshot — another process
468
+ // may have migrated the file and appended since. Re-read inside this
469
+ // same lock hold so the rewrite below cannot destroy those entries.
470
+ // Never reached in steady state (only while migration is pending) and
471
+ // never during initialize's eager pass (initialized is still false).
472
+ const { entries, legacy } = await this._loadFromDisk();
473
+ this.logs = entries;
474
+ this._diskIsLegacy = legacy;
475
+ // Disk state changed under us, so the counter carried over from
476
+ // initialize may already be taken by a foreign entry: recompute from
477
+ // the freshly loaded entries before the append assigns an id.
478
+ this._recomputeMessageId();
479
+ if (!legacy) {
480
+ // Another process already migrated the file — nothing to rewrite.
481
+ this._formatMigrated = true;
482
+ return;
483
+ }
484
+ }
217
485
  const backedUp = await this._backupCorruptedLogFile('pre_migration');
218
486
  if (!backedUp) {
219
487
  // Fail fast: never append JSONL onto a still-legacy file, which would
@@ -381,28 +649,33 @@ export class Logger {
381
649
  throw new Error('Log file path not set during update attempt.');
382
650
  }
383
651
 
384
- await this._ensureJsonlFormat();
385
-
386
- entryToAppend.messageId = this.messageId;
652
+ // Hold the cross-process lock across the whole mutate sequence (format-ensure,
653
+ // id assignment, duplicate check, newline-fix + append) so it cannot
654
+ // interleave with another process's append or legacy migration rewrite.
655
+ return this._withLogLock(async () => {
656
+ await this._ensureJsonlFormat();
387
657
 
388
- const entryExists = this.logs.some(
389
- (e) =>
390
- e.sessionId === entryToAppend.sessionId &&
391
- e.messageId === entryToAppend.messageId &&
392
- e.timestamp === entryToAppend.timestamp &&
393
- e.message === entryToAppend.message,
394
- );
658
+ entryToAppend.messageId = this.messageId;
395
659
 
396
- if (entryExists) {
397
- debugLogger.debug(
398
- `Duplicate log entry detected and skipped: session ${entryToAppend.sessionId}, messageId ${entryToAppend.messageId}`,
660
+ const entryExists = this.logs.some(
661
+ (e) =>
662
+ e.sessionId === entryToAppend.sessionId &&
663
+ e.messageId === entryToAppend.messageId &&
664
+ e.timestamp === entryToAppend.timestamp &&
665
+ e.message === entryToAppend.message,
399
666
  );
400
- return null;
401
- }
402
667
 
403
- await this._appendJsonl(entryToAppend);
404
- this.logs.push(entryToAppend);
405
- return entryToAppend;
668
+ if (entryExists) {
669
+ debugLogger.debug(
670
+ `Duplicate log entry detected and skipped: session ${entryToAppend.sessionId}, messageId ${entryToAppend.messageId}`,
671
+ );
672
+ return null;
673
+ }
674
+
675
+ await this._appendJsonl(entryToAppend);
676
+ this.logs.push(entryToAppend);
677
+ return entryToAppend;
678
+ });
406
679
  }
407
680
 
408
681
  private async _pruneOldBackups(): Promise<void> {
@@ -430,6 +703,13 @@ export class Logger {
430
703
  const match = entry.match(/\.(\d+)\.tmp$/);
431
704
  return match !== null && Number(match[1]) < cutoffMs;
432
705
  }
706
+ // Inert guard files left by lost rename-guard races: they never sit at
707
+ // the live .lock path, but prune them so they cannot accumulate.
708
+ // logs.json.lock.<brk|rel>.<pid>.<ts>.<counter>
709
+ const guardMatch = entry.match(/\.lock\.(?:brk|rel)\.\d+\.(\d+)\.\d+$/);
710
+ if (guardMatch !== null) {
711
+ return Number(guardMatch[1]) < Date.now() - GUARD_RETENTION_MS;
712
+ }
433
713
  return false;
434
714
  });
435
715
  for (const file of staleFiles) {
@@ -446,7 +726,25 @@ export class Logger {
446
726
  if (this.initialized) {
447
727
  return;
448
728
  }
729
+ // Deduplicate concurrent callers and let close() drain the in-flight
730
+ // initialization before it clears state.
731
+ const inFlight = this._initPromise;
732
+ if (inFlight) {
733
+ await inFlight;
734
+ return;
735
+ }
736
+ const run = this._doInitialize();
737
+ this._initPromise = run;
738
+ try {
739
+ await run;
740
+ } finally {
741
+ if (this._initPromise === run) {
742
+ this._initPromise = undefined;
743
+ }
744
+ }
745
+ }
449
746
 
747
+ private async _doInitialize(): Promise<void> {
450
748
  ensureDir(Storage.getGlobalLogDir());
451
749
  const llxprtDir = this.storage.getProjectTempDir();
452
750
  this.logFilePath = path.join(llxprtDir, LOG_FILE_NAME);
@@ -464,33 +762,45 @@ export class Logger {
464
762
  await this._pruneOldBackups();
465
763
 
466
764
  try {
467
- const { entries, legacy } = await this._loadFromDisk();
468
- this.logs = entries;
469
- this._diskIsLegacy = legacy;
470
- // Eagerly migrate a legacy file to JSONL so the write path stays O(1)
471
- // (no read). Migration failure here is non-fatal: writes will retry.
472
- try {
473
- await this._ensureJsonlFormat();
474
- } catch (err) {
475
- debugLogger.debug(
476
- 'Non-fatal legacy migration failure during init:',
477
- err,
478
- );
479
- }
480
- const sessionLogs = this.logs.filter(
481
- (entry) => entry.sessionId === this.sessionId,
482
- );
483
- this.messageId =
484
- sessionLogs.length > 0
485
- ? Math.max(...sessionLogs.map((entry) => entry.messageId)) + 1
486
- : 0;
487
- this.initialized = true;
765
+ await this._withLogLock(async () => {
766
+ const { entries, legacy } = await this._loadFromDisk();
767
+ this.logs = entries;
768
+ this._diskIsLegacy = legacy;
769
+ // Eagerly migrate a legacy file to JSONL so the write path stays O(1)
770
+ // (no read). Migration failure here is non-fatal: writes will retry.
771
+ try {
772
+ await this._ensureJsonlFormat();
773
+ } catch (err) {
774
+ debugLogger.debug(
775
+ 'Non-fatal legacy migration failure during init:',
776
+ err,
777
+ );
778
+ }
779
+ this._recomputeMessageId();
780
+ this.initialized = true;
781
+ });
488
782
  } catch (err) {
489
783
  debugLogger.error('Failed to initialize logger:', err);
490
784
  this.initialized = false;
491
785
  }
492
786
  }
493
787
 
788
+ /**
789
+ * Reset the instance's next-id counter to one past the highest id already
790
+ * on disk for this session. Called whenever `this.logs` is (re)populated
791
+ * from disk, so a foreign writer that appended while we held a stale
792
+ * snapshot cannot collide with our next append.
793
+ */
794
+ private _recomputeMessageId(): void {
795
+ const sessionLogs = this.logs.filter(
796
+ (entry) => entry.sessionId === this.sessionId,
797
+ );
798
+ this.messageId =
799
+ sessionLogs.length > 0
800
+ ? Math.max(...sessionLogs.map((entry) => entry.messageId)) + 1
801
+ : 0;
802
+ }
803
+
494
804
  async getPreviousUserMessages(): Promise<string[]> {
495
805
  if (!this.initialized) return [];
496
806
  const logsWithPersistedTypes: Array<
@@ -507,6 +817,21 @@ export class Logger {
507
817
  }
508
818
 
509
819
  async logMessage(type: MessageSenderType, message: string): Promise<void> {
820
+ // A lock timeout during initialize() must not wedge logging for the whole
821
+ // session: the blocking lock becomes breakable once it ages past the
822
+ // staleness threshold, so an uninitialized (but not closed) logger lazily
823
+ // retries initialization here.
824
+ if (this._closed) {
825
+ // Closed loggers must stay dead; same message as below keeps the
826
+ // observable contract for post-close callers unchanged.
827
+ debugLogger.debug(
828
+ 'Logger not initialized or session ID missing. Cannot log message.',
829
+ );
830
+ return;
831
+ }
832
+ if (!this.initialized) {
833
+ await this.initialize();
834
+ }
510
835
  if (!this.initialized || this.sessionId === undefined) {
511
836
  debugLogger.debug(
512
837
  'Logger not initialized or session ID missing. Cannot log message.',
@@ -537,6 +862,12 @@ export class Logger {
537
862
  }
538
863
 
539
864
  async close(): Promise<void> {
865
+ // Mark closed first so logMessage calls arriving during the drain do not
866
+ // lazily re-initialize the logger.
867
+ this._closed = true;
868
+ // An in-flight initialize() must commit (or fail) before state is
869
+ // cleared, or its late commit would resurrect the closed logger.
870
+ await this._initPromise?.catch(() => {});
540
871
  // Drain pending writes until the queue reference stops changing. A single
541
872
  // `await this._writeQueue` would miss a write chained onto a newer queue
542
873
  // during the await; that write would resume after state is cleared and
@@ -11,7 +11,6 @@ import { Storage } from '@vybestack/llxprt-code-settings';
11
11
  import { isGitRepository } from '../utils/gitUtils.js';
12
12
  import { PromptService } from '../prompt-config/prompt-service.js';
13
13
  import { getRuntimeSettingsService } from '../runtime/settingsRuntimeAdapter.js';
14
- import { getFolderStructure } from '../utils/getFolderStructure.js';
15
14
  import { DebugLogger } from '../debug/index.js';
16
15
  import {
17
16
  getGlobalCoreMemoryFilePath,
@@ -25,9 +24,6 @@ import type {
25
24
  PromptEnvironment,
26
25
  } from '../prompt-config/types.js';
27
26
 
28
- const MAX_FOLDER_STRUCTURE_LINES = 40;
29
- const MAX_FOLDER_STRUCTURE_CHARS = 6000;
30
- const MAX_FOLDER_STRUCTURE_TOP_LEVEL = 20;
31
27
  const SESSION_STARTED_AT = new Date();
32
28
  const SESSION_STARTED_AT_LABEL = SESSION_STARTED_AT.toLocaleString();
33
29
  const logger = new DebugLogger('llxprt:core:prompts');
@@ -134,81 +130,6 @@ function getToolNameMapping(): Record<string, string> {
134
130
  };
135
131
  }
136
132
 
137
- function extractFolderStructureHeader(lines: string[]): {
138
- header: string[];
139
- body: string[];
140
- } {
141
- if (lines.length === 0) {
142
- return { header: [], body: [] };
143
- }
144
-
145
- const header: string[] = [];
146
- let index = 0;
147
-
148
- header.push(lines[index++] ?? '');
149
-
150
- if (index < lines.length && lines[index].trim() === '') {
151
- header.push(lines[index++]);
152
- }
153
-
154
- if (index < lines.length) {
155
- header.push(lines[index++]);
156
- }
157
-
158
- return { header, body: lines.slice(index) };
159
- }
160
-
161
- export function compactFolderStructureSnapshot(
162
- structure?: string,
163
- ): string | undefined {
164
- if (!structure) {
165
- return structure;
166
- }
167
-
168
- const normalized = structure.replace(/\r\n/g, '\n').trim();
169
- if (!normalized) {
170
- return undefined;
171
- }
172
-
173
- const lines = normalized.split('\n');
174
- if (
175
- lines.length <= MAX_FOLDER_STRUCTURE_LINES &&
176
- normalized.length <= MAX_FOLDER_STRUCTURE_CHARS
177
- ) {
178
- return normalized;
179
- }
180
-
181
- const { header, body } = extractFolderStructureHeader(lines);
182
- if (body.length === 0) {
183
- return normalized.slice(0, MAX_FOLDER_STRUCTURE_CHARS);
184
- }
185
-
186
- const topLevelEntries = body.filter(
187
- (line) => line.startsWith('├───') || line.startsWith('└───'),
188
- );
189
- const candidateLines = topLevelEntries.length > 0 ? topLevelEntries : body;
190
- const limitedLines = candidateLines.slice(0, MAX_FOLDER_STRUCTURE_TOP_LEVEL);
191
- const omittedCount = Math.max(candidateLines.length - limitedLines.length, 0);
192
-
193
- const truncatedLine = `└───... ${omittedCount} more entries omitted (folder structure truncated for provider limits)`;
194
- const snapshotLines = [...header, ...limitedLines, truncatedLine];
195
-
196
- let snapshot = snapshotLines.join('\n');
197
- if (snapshot.length > MAX_FOLDER_STRUCTURE_CHARS) {
198
- const allowance = Math.max(
199
- MAX_FOLDER_STRUCTURE_CHARS - truncatedLine.length - 1,
200
- 0,
201
- );
202
- const preserved = snapshotLines
203
- .slice(0, snapshotLines.length - 1)
204
- .join('\n')
205
- .slice(0, allowance);
206
- snapshot = preserved ? `${preserved}\n${truncatedLine}` : truncatedLine;
207
- }
208
-
209
- return snapshot;
210
- }
211
-
212
133
  /**
213
134
  * Options for getCoreSystemPromptAsync
214
135
  */
@@ -288,20 +209,12 @@ export async function loadCoreMemoryContent(cwd: string): Promise<string> {
288
209
 
289
210
  return parts.join('\n\n');
290
211
  }
291
- function resolveFolderStructureSettings(): {
292
- includeFolderStructure: boolean;
212
+ function resolvePromptSettings(): {
293
213
  enableToolPrompts: boolean;
294
214
  } {
295
- let includeFolderStructure = false;
296
215
  let enableToolPrompts = false;
297
216
  try {
298
217
  const settingsService = getRuntimeSettingsService();
299
- const folderStructureSetting = settingsService.get(
300
- 'include-folder-structure',
301
- ) as boolean | undefined;
302
- if (folderStructureSetting !== undefined) {
303
- includeFolderStructure = folderStructureSetting;
304
- }
305
218
  const toolPromptsSetting = settingsService.get('enable-tool-prompts') as
306
219
  | boolean
307
220
  | undefined;
@@ -311,28 +224,11 @@ function resolveFolderStructureSettings(): {
311
224
  } catch {
312
225
  // Settings unavailable; use defaults.
313
226
  }
314
- return { includeFolderStructure, enableToolPrompts };
315
- }
316
-
317
- async function resolveFolderStructure(
318
- cwd: string,
319
- includeFolderStructure: boolean,
320
- ): Promise<string | undefined> {
321
- if (!includeFolderStructure) return undefined;
322
- try {
323
- const raw = await getFolderStructure(cwd, {
324
- maxItems: 100,
325
- });
326
- return compactFolderStructureSnapshot(raw);
327
- } catch (error) {
328
- logger.debug(() => `Failed to generate folder structure: ${error}`);
329
- return undefined;
330
- }
227
+ return { enableToolPrompts };
331
228
  }
332
229
 
333
230
  function buildEnvironment(
334
231
  cwd: string,
335
- folderStructure: string | undefined,
336
232
  interactionMode: CoreSystemPromptOptions['interactionMode'],
337
233
  ): PromptEnvironment {
338
234
  const environment: PromptEnvironment = {
@@ -344,7 +240,6 @@ function buildEnvironment(
344
240
  workspaceRoot: cwd,
345
241
  workspaceName: path.basename(cwd),
346
242
  workspaceDirectories: [cwd],
347
- folderStructure,
348
243
  interactionMode,
349
244
  };
350
245
 
@@ -450,13 +345,8 @@ async function buildPromptContext(
450
345
  options;
451
346
  const cwd = process.cwd();
452
347
 
453
- const { includeFolderStructure, enableToolPrompts } =
454
- resolveFolderStructureSettings();
455
- const folderStructure = await resolveFolderStructure(
456
- cwd,
457
- includeFolderStructure,
458
- );
459
- const environment = buildEnvironment(cwd, folderStructure, interactionMode);
348
+ const { enableToolPrompts } = resolvePromptSettings();
349
+ const environment = buildEnvironment(cwd, interactionMode);
460
350
  const enabledTools = resolveEnabledTools(tools);
461
351
  const resolvedProvider = resolveProvider(provider);
462
352
  const { asyncSubagentsEnabled, profileAsyncEnabled } =
package/src/core/turn.ts CHANGED
@@ -259,10 +259,10 @@ export type ServerChatCompressedEvent = {
259
259
  export type ServerUsageMetadataEvent = {
260
260
  type: AgentEventType.UsageMetadata;
261
261
  value: {
262
- promptTokenCount?: number;
263
- candidatesTokenCount?: number;
262
+ inputTokenCount?: number;
263
+ outputTokenCount?: number;
264
264
  totalTokenCount?: number;
265
- cachedContentTokenCount?: number;
265
+ cachedTokenCount?: number;
266
266
  };
267
267
  };
268
268