@cchistory/lite 0.4.2

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 (533) hide show
  1. package/INSTALL.md +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +16 -0
  4. package/apps/lite-cli/dist/bin.d.ts +3 -0
  5. package/apps/lite-cli/dist/bin.d.ts.map +1 -0
  6. package/apps/lite-cli/dist/bin.js +7 -0
  7. package/apps/lite-cli/dist/bin.js.map +1 -0
  8. package/apps/lite-cli/dist/index.d.ts +21 -0
  9. package/apps/lite-cli/dist/index.d.ts.map +1 -0
  10. package/apps/lite-cli/dist/index.js +1812 -0
  11. package/apps/lite-cli/dist/index.js.map +1 -0
  12. package/apps/lite-cli/dist/index.test.d.ts +2 -0
  13. package/apps/lite-cli/dist/index.test.d.ts.map +1 -0
  14. package/apps/lite-cli/dist/index.test.js +1290 -0
  15. package/apps/lite-cli/dist/index.test.js.map +1 -0
  16. package/apps/lite-cli/dist/json-v2.d.ts +17 -0
  17. package/apps/lite-cli/dist/json-v2.d.ts.map +1 -0
  18. package/apps/lite-cli/dist/json-v2.js +352 -0
  19. package/apps/lite-cli/dist/json-v2.js.map +1 -0
  20. package/apps/lite-cli/dist/query.d.ts +50 -0
  21. package/apps/lite-cli/dist/query.d.ts.map +1 -0
  22. package/apps/lite-cli/dist/query.js +297 -0
  23. package/apps/lite-cli/dist/query.js.map +1 -0
  24. package/apps/lite-cli/dist/shell.d.ts +18 -0
  25. package/apps/lite-cli/dist/shell.d.ts.map +1 -0
  26. package/apps/lite-cli/dist/shell.js +276 -0
  27. package/apps/lite-cli/dist/shell.js.map +1 -0
  28. package/apps/lite-tui/dist/bin.d.ts +3 -0
  29. package/apps/lite-tui/dist/bin.d.ts.map +1 -0
  30. package/apps/lite-tui/dist/bin.js +7 -0
  31. package/apps/lite-tui/dist/bin.js.map +1 -0
  32. package/apps/lite-tui/dist/colors.d.ts +49 -0
  33. package/apps/lite-tui/dist/colors.d.ts.map +1 -0
  34. package/apps/lite-tui/dist/colors.js +70 -0
  35. package/apps/lite-tui/dist/colors.js.map +1 -0
  36. package/apps/lite-tui/dist/index.d.ts +23 -0
  37. package/apps/lite-tui/dist/index.d.ts.map +1 -0
  38. package/apps/lite-tui/dist/index.js +519 -0
  39. package/apps/lite-tui/dist/index.js.map +1 -0
  40. package/apps/lite-tui/dist/index.test.d.ts +2 -0
  41. package/apps/lite-tui/dist/index.test.d.ts.map +1 -0
  42. package/apps/lite-tui/dist/index.test.js +487 -0
  43. package/apps/lite-tui/dist/index.test.js.map +1 -0
  44. package/apps/lite-tui/dist/input.d.ts +23 -0
  45. package/apps/lite-tui/dist/input.d.ts.map +1 -0
  46. package/apps/lite-tui/dist/input.js +98 -0
  47. package/apps/lite-tui/dist/input.js.map +1 -0
  48. package/apps/lite-tui/dist/keys.d.ts +32 -0
  49. package/apps/lite-tui/dist/keys.d.ts.map +1 -0
  50. package/apps/lite-tui/dist/keys.js +136 -0
  51. package/apps/lite-tui/dist/keys.js.map +1 -0
  52. package/apps/lite-tui/dist/keys.test.d.ts +2 -0
  53. package/apps/lite-tui/dist/keys.test.d.ts.map +1 -0
  54. package/apps/lite-tui/dist/keys.test.js +67 -0
  55. package/apps/lite-tui/dist/keys.test.js.map +1 -0
  56. package/apps/lite-tui/dist/model.d.ts +88 -0
  57. package/apps/lite-tui/dist/model.d.ts.map +1 -0
  58. package/apps/lite-tui/dist/model.js +146 -0
  59. package/apps/lite-tui/dist/model.js.map +1 -0
  60. package/apps/lite-tui/dist/render.d.ts +46 -0
  61. package/apps/lite-tui/dist/render.d.ts.map +1 -0
  62. package/apps/lite-tui/dist/render.js +706 -0
  63. package/apps/lite-tui/dist/render.js.map +1 -0
  64. package/apps/lite-tui/dist/render.test.d.ts +2 -0
  65. package/apps/lite-tui/dist/render.test.d.ts.map +1 -0
  66. package/apps/lite-tui/dist/render.test.js +594 -0
  67. package/apps/lite-tui/dist/render.test.js.map +1 -0
  68. package/apps/lite-tui/dist/state.d.ts +127 -0
  69. package/apps/lite-tui/dist/state.d.ts.map +1 -0
  70. package/apps/lite-tui/dist/state.js +391 -0
  71. package/apps/lite-tui/dist/state.js.map +1 -0
  72. package/apps/lite-tui/dist/state.test.d.ts +2 -0
  73. package/apps/lite-tui/dist/state.test.d.ts.map +1 -0
  74. package/apps/lite-tui/dist/state.test.js +331 -0
  75. package/apps/lite-tui/dist/state.test.js.map +1 -0
  76. package/apps/lite-tui/dist/text.d.ts +38 -0
  77. package/apps/lite-tui/dist/text.d.ts.map +1 -0
  78. package/apps/lite-tui/dist/text.js +246 -0
  79. package/apps/lite-tui/dist/text.js.map +1 -0
  80. package/apps/lite-tui/dist/version.d.ts +10 -0
  81. package/apps/lite-tui/dist/version.d.ts.map +1 -0
  82. package/apps/lite-tui/dist/version.js +10 -0
  83. package/apps/lite-tui/dist/version.js.map +1 -0
  84. package/apps/lite-tui/dist/view-model.d.ts +26 -0
  85. package/apps/lite-tui/dist/view-model.d.ts.map +1 -0
  86. package/apps/lite-tui/dist/view-model.js +87 -0
  87. package/apps/lite-tui/dist/view-model.js.map +1 -0
  88. package/bin/cchistory-lite +3 -0
  89. package/bin/cchistory-lite-tui +3 -0
  90. package/bin/cchistory-lite-tui.cmd +3 -0
  91. package/bin/cchistory-lite-tui.mjs +7 -0
  92. package/bin/cchistory-lite.cmd +3 -0
  93. package/bin/cchistory-lite.mjs +11 -0
  94. package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts +33 -0
  95. package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts.map +1 -0
  96. package/node_modules/@cchistory/canonical/dist/directory-scope.js +95 -0
  97. package/node_modules/@cchistory/canonical/dist/directory-scope.js.map +1 -0
  98. package/node_modules/@cchistory/canonical/dist/fallback-projects.d.ts +14 -0
  99. package/node_modules/@cchistory/canonical/dist/fallback-projects.d.ts.map +1 -0
  100. package/node_modules/@cchistory/canonical/dist/fallback-projects.js +120 -0
  101. package/node_modules/@cchistory/canonical/dist/fallback-projects.js.map +1 -0
  102. package/node_modules/@cchistory/canonical/dist/index.d.ts +12 -0
  103. package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -0
  104. package/node_modules/@cchistory/canonical/dist/index.js +12 -0
  105. package/node_modules/@cchistory/canonical/dist/index.js.map +1 -0
  106. package/node_modules/@cchistory/canonical/dist/index.test.d.ts +2 -0
  107. package/node_modules/@cchistory/canonical/dist/index.test.d.ts.map +1 -0
  108. package/node_modules/@cchistory/canonical/dist/index.test.js +901 -0
  109. package/node_modules/@cchistory/canonical/dist/index.test.js.map +1 -0
  110. package/node_modules/@cchistory/canonical/dist/project-linker.d.ts +30 -0
  111. package/node_modules/@cchistory/canonical/dist/project-linker.d.ts.map +1 -0
  112. package/node_modules/@cchistory/canonical/dist/project-linker.js +720 -0
  113. package/node_modules/@cchistory/canonical/dist/project-linker.js.map +1 -0
  114. package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts +23 -0
  115. package/node_modules/@cchistory/canonical/dist/projection-audit.d.ts.map +1 -0
  116. package/node_modules/@cchistory/canonical/dist/projection-audit.js +192 -0
  117. package/node_modules/@cchistory/canonical/dist/projection-audit.js.map +1 -0
  118. package/node_modules/@cchistory/canonical/dist/read-order.d.ts +19 -0
  119. package/node_modules/@cchistory/canonical/dist/read-order.d.ts.map +1 -0
  120. package/node_modules/@cchistory/canonical/dist/read-order.js +73 -0
  121. package/node_modules/@cchistory/canonical/dist/read-order.js.map +1 -0
  122. package/node_modules/@cchistory/canonical/dist/related-work.d.ts +4 -0
  123. package/node_modules/@cchistory/canonical/dist/related-work.d.ts.map +1 -0
  124. package/node_modules/@cchistory/canonical/dist/related-work.js +232 -0
  125. package/node_modules/@cchistory/canonical/dist/related-work.js.map +1 -0
  126. package/node_modules/@cchistory/canonical/dist/runtime-warning-filter.d.ts +10 -0
  127. package/node_modules/@cchistory/canonical/dist/runtime-warning-filter.d.ts.map +1 -0
  128. package/node_modules/@cchistory/canonical/dist/runtime-warning-filter.js +34 -0
  129. package/node_modules/@cchistory/canonical/dist/runtime-warning-filter.js.map +1 -0
  130. package/node_modules/@cchistory/canonical/dist/search.d.ts +69 -0
  131. package/node_modules/@cchistory/canonical/dist/search.d.ts.map +1 -0
  132. package/node_modules/@cchistory/canonical/dist/search.js +337 -0
  133. package/node_modules/@cchistory/canonical/dist/search.js.map +1 -0
  134. package/node_modules/@cchistory/canonical/dist/session-collections.d.ts +8 -0
  135. package/node_modules/@cchistory/canonical/dist/session-collections.d.ts.map +1 -0
  136. package/node_modules/@cchistory/canonical/dist/session-collections.js +21 -0
  137. package/node_modules/@cchistory/canonical/dist/session-collections.js.map +1 -0
  138. package/node_modules/@cchistory/canonical/dist/session-family.d.ts +23 -0
  139. package/node_modules/@cchistory/canonical/dist/session-family.d.ts.map +1 -0
  140. package/node_modules/@cchistory/canonical/dist/session-family.js +808 -0
  141. package/node_modules/@cchistory/canonical/dist/session-family.js.map +1 -0
  142. package/node_modules/@cchistory/canonical/dist/session-family.test.d.ts +2 -0
  143. package/node_modules/@cchistory/canonical/dist/session-family.test.d.ts.map +1 -0
  144. package/node_modules/@cchistory/canonical/dist/session-family.test.js +650 -0
  145. package/node_modules/@cchistory/canonical/dist/session-family.test.js.map +1 -0
  146. package/node_modules/@cchistory/canonical/dist/usage.d.ts +79 -0
  147. package/node_modules/@cchistory/canonical/dist/usage.d.ts.map +1 -0
  148. package/node_modules/@cchistory/canonical/dist/usage.js +232 -0
  149. package/node_modules/@cchistory/canonical/dist/usage.js.map +1 -0
  150. package/node_modules/@cchistory/canonical/dist/utils.d.ts +5 -0
  151. package/node_modules/@cchistory/canonical/dist/utils.d.ts.map +1 -0
  152. package/node_modules/@cchistory/canonical/dist/utils.js +18 -0
  153. package/node_modules/@cchistory/canonical/dist/utils.js.map +1 -0
  154. package/node_modules/@cchistory/canonical/package.json +14 -0
  155. package/node_modules/@cchistory/domain/dist/index.d.ts +943 -0
  156. package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -0
  157. package/node_modules/@cchistory/domain/dist/index.js +238 -0
  158. package/node_modules/@cchistory/domain/dist/index.js.map +1 -0
  159. package/node_modules/@cchistory/domain/dist/index.test.d.ts +2 -0
  160. package/node_modules/@cchistory/domain/dist/index.test.d.ts.map +1 -0
  161. package/node_modules/@cchistory/domain/dist/index.test.js +423 -0
  162. package/node_modules/@cchistory/domain/dist/index.test.js.map +1 -0
  163. package/node_modules/@cchistory/domain/package.json +14 -0
  164. package/node_modules/@cchistory/live-runtime/dist/async-pool.d.ts +3 -0
  165. package/node_modules/@cchistory/live-runtime/dist/async-pool.d.ts.map +1 -0
  166. package/node_modules/@cchistory/live-runtime/dist/async-pool.js +19 -0
  167. package/node_modules/@cchistory/live-runtime/dist/async-pool.js.map +1 -0
  168. package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts +3 -0
  169. package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts.map +1 -0
  170. package/node_modules/@cchistory/live-runtime/dist/bootstrap.js +22 -0
  171. package/node_modules/@cchistory/live-runtime/dist/bootstrap.js.map +1 -0
  172. package/node_modules/@cchistory/live-runtime/dist/index.d.ts +149 -0
  173. package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -0
  174. package/node_modules/@cchistory/live-runtime/dist/index.js +1180 -0
  175. package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -0
  176. package/node_modules/@cchistory/live-runtime/dist/index.test.d.ts +2 -0
  177. package/node_modules/@cchistory/live-runtime/dist/index.test.d.ts.map +1 -0
  178. package/node_modules/@cchistory/live-runtime/dist/index.test.js +1819 -0
  179. package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -0
  180. package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts +5 -0
  181. package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts.map +1 -0
  182. package/node_modules/@cchistory/live-runtime/dist/node-memory.js +83 -0
  183. package/node_modules/@cchistory/live-runtime/dist/node-memory.js.map +1 -0
  184. package/node_modules/@cchistory/live-runtime/package.json +18 -0
  185. package/node_modules/@cchistory/source-adapters/dist/core/antigravity-logic.d.ts +8 -0
  186. package/node_modules/@cchistory/source-adapters/dist/core/antigravity-logic.d.ts.map +1 -0
  187. package/node_modules/@cchistory/source-adapters/dist/core/antigravity-logic.js +115 -0
  188. package/node_modules/@cchistory/source-adapters/dist/core/antigravity-logic.js.map +1 -0
  189. package/node_modules/@cchistory/source-adapters/dist/core/ask-user-registry.d.ts +9 -0
  190. package/node_modules/@cchistory/source-adapters/dist/core/ask-user-registry.d.ts.map +1 -0
  191. package/node_modules/@cchistory/source-adapters/dist/core/ask-user-registry.js +223 -0
  192. package/node_modules/@cchistory/source-adapters/dist/core/ask-user-registry.js.map +1 -0
  193. package/node_modules/@cchistory/source-adapters/dist/core/ask-user.test.d.ts +2 -0
  194. package/node_modules/@cchistory/source-adapters/dist/core/ask-user.test.d.ts.map +1 -0
  195. package/node_modules/@cchistory/source-adapters/dist/core/ask-user.test.js +318 -0
  196. package/node_modules/@cchistory/source-adapters/dist/core/ask-user.test.js.map +1 -0
  197. package/node_modules/@cchistory/source-adapters/dist/core/atomizer.d.ts +11 -0
  198. package/node_modules/@cchistory/source-adapters/dist/core/atomizer.d.ts.map +1 -0
  199. package/node_modules/@cchistory/source-adapters/dist/core/atomizer.js +206 -0
  200. package/node_modules/@cchistory/source-adapters/dist/core/atomizer.js.map +1 -0
  201. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts +62 -0
  202. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts.map +1 -0
  203. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.js +224 -0
  204. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.js.map +1 -0
  205. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.d.ts +15 -0
  206. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.d.ts.map +1 -0
  207. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.js +96 -0
  208. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.js.map +1 -0
  209. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.test.d.ts +2 -0
  210. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.test.d.ts.map +1 -0
  211. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.test.js +97 -0
  212. package/node_modules/@cchistory/source-adapters/dist/core/directory-preview.test.js.map +1 -0
  213. package/node_modules/@cchistory/source-adapters/dist/core/discovery.d.ts +11 -0
  214. package/node_modules/@cchistory/source-adapters/dist/core/discovery.d.ts.map +1 -0
  215. package/node_modules/@cchistory/source-adapters/dist/core/discovery.js +412 -0
  216. package/node_modules/@cchistory/source-adapters/dist/core/discovery.js.map +1 -0
  217. package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.d.ts +2 -0
  218. package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.d.ts.map +1 -0
  219. package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js +552 -0
  220. package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js.map +1 -0
  221. package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts +10 -0
  222. package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts.map +1 -0
  223. package/node_modules/@cchistory/source-adapters/dist/core/factories.js +83 -0
  224. package/node_modules/@cchistory/source-adapters/dist/core/factories.js.map +1 -0
  225. package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts +5 -0
  226. package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts.map +1 -0
  227. package/node_modules/@cchistory/source-adapters/dist/core/git-project.js +86 -0
  228. package/node_modules/@cchistory/source-adapters/dist/core/git-project.js.map +1 -0
  229. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.d.ts +31 -0
  230. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.d.ts.map +1 -0
  231. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.js +216 -0
  232. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.js.map +1 -0
  233. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.d.ts +2 -0
  234. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.d.ts.map +1 -0
  235. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js +367 -0
  236. package/node_modules/@cchistory/source-adapters/dist/core/jsonl-records.test.js.map +1 -0
  237. package/node_modules/@cchistory/source-adapters/dist/core/legacy.d.ts +10 -0
  238. package/node_modules/@cchistory/source-adapters/dist/core/legacy.d.ts.map +1 -0
  239. package/node_modules/@cchistory/source-adapters/dist/core/legacy.js +10 -0
  240. package/node_modules/@cchistory/source-adapters/dist/core/legacy.js.map +1 -0
  241. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +70 -0
  242. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -0
  243. package/node_modules/@cchistory/source-adapters/dist/core/parser.js +1389 -0
  244. package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -0
  245. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.d.ts +15 -0
  246. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.d.ts.map +1 -0
  247. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.js +76 -0
  248. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.js.map +1 -0
  249. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.test.d.ts +2 -0
  250. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.test.d.ts.map +1 -0
  251. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.test.js +33 -0
  252. package/node_modules/@cchistory/source-adapters/dist/core/path-utils.test.js.map +1 -0
  253. package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts +24 -0
  254. package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -0
  255. package/node_modules/@cchistory/source-adapters/dist/core/probe.js +1829 -0
  256. package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -0
  257. package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts +39 -0
  258. package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts.map +1 -0
  259. package/node_modules/@cchistory/source-adapters/dist/core/projections.js +873 -0
  260. package/node_modules/@cchistory/source-adapters/dist/core/projections.js.map +1 -0
  261. package/node_modules/@cchistory/source-adapters/dist/core/projections.test.d.ts +2 -0
  262. package/node_modules/@cchistory/source-adapters/dist/core/projections.test.d.ts.map +1 -0
  263. package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js +165 -0
  264. package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js.map +1 -0
  265. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.d.ts +2 -0
  266. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.d.ts.map +1 -0
  267. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js +87 -0
  268. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js.map +1 -0
  269. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping-worker.d.ts +2 -0
  270. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping-worker.d.ts.map +1 -0
  271. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping-worker.js +10 -0
  272. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping-worker.js.map +1 -0
  273. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts +29 -0
  274. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts.map +1 -0
  275. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js +455 -0
  276. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js.map +1 -0
  277. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.d.ts +2 -0
  278. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.d.ts.map +1 -0
  279. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js +357 -0
  280. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js.map +1 -0
  281. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts +25 -0
  282. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -0
  283. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +144 -0
  284. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -0
  285. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts +14 -0
  286. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts.map +1 -0
  287. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js +247 -0
  288. package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js.map +1 -0
  289. package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.d.ts +2 -0
  290. package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.d.ts.map +1 -0
  291. package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js +323 -0
  292. package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js.map +1 -0
  293. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts +26 -0
  294. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts.map +1 -0
  295. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js +80 -0
  296. package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js.map +1 -0
  297. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts +226 -0
  298. package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts.map +1 -0
  299. package/node_modules/@cchistory/source-adapters/dist/core/types.js +2 -0
  300. package/node_modules/@cchistory/source-adapters/dist/core/types.js.map +1 -0
  301. package/node_modules/@cchistory/source-adapters/dist/core/user-text.d.ts +29 -0
  302. package/node_modules/@cchistory/source-adapters/dist/core/user-text.d.ts.map +1 -0
  303. package/node_modules/@cchistory/source-adapters/dist/core/user-text.js +327 -0
  304. package/node_modules/@cchistory/source-adapters/dist/core/user-text.js.map +1 -0
  305. package/node_modules/@cchistory/source-adapters/dist/core/utils.d.ts +11 -0
  306. package/node_modules/@cchistory/source-adapters/dist/core/utils.d.ts.map +1 -0
  307. package/node_modules/@cchistory/source-adapters/dist/core/utils.js +19 -0
  308. package/node_modules/@cchistory/source-adapters/dist/core/utils.js.map +1 -0
  309. package/node_modules/@cchistory/source-adapters/dist/core/utils.test.d.ts +2 -0
  310. package/node_modules/@cchistory/source-adapters/dist/core/utils.test.d.ts.map +1 -0
  311. package/node_modules/@cchistory/source-adapters/dist/core/utils.test.js +289 -0
  312. package/node_modules/@cchistory/source-adapters/dist/core/utils.test.js.map +1 -0
  313. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts +43 -0
  314. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts.map +1 -0
  315. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js +520 -0
  316. package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js.map +1 -0
  317. package/node_modules/@cchistory/source-adapters/dist/index.d.ts +13 -0
  318. package/node_modules/@cchistory/source-adapters/dist/index.d.ts.map +1 -0
  319. package/node_modules/@cchistory/source-adapters/dist/index.js +8 -0
  320. package/node_modules/@cchistory/source-adapters/dist/index.js.map +1 -0
  321. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +31 -0
  322. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -0
  323. package/node_modules/@cchistory/source-adapters/dist/index.test.js +31 -0
  324. package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -0
  325. package/node_modules/@cchistory/source-adapters/dist/masks.d.ts +31 -0
  326. package/node_modules/@cchistory/source-adapters/dist/masks.d.ts.map +1 -0
  327. package/node_modules/@cchistory/source-adapters/dist/masks.js +342 -0
  328. package/node_modules/@cchistory/source-adapters/dist/masks.js.map +1 -0
  329. package/node_modules/@cchistory/source-adapters/dist/platforms/accio/runtime.d.ts +31 -0
  330. package/node_modules/@cchistory/source-adapters/dist/platforms/accio/runtime.d.ts.map +1 -0
  331. package/node_modules/@cchistory/source-adapters/dist/platforms/accio/runtime.js +161 -0
  332. package/node_modules/@cchistory/source-adapters/dist/platforms/accio/runtime.js.map +1 -0
  333. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.d.ts +3 -0
  334. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.d.ts.map +1 -0
  335. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.js +107 -0
  336. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.js.map +1 -0
  337. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.d.ts +2 -0
  338. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.d.ts.map +1 -0
  339. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js +202 -0
  340. package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js.map +1 -0
  341. package/node_modules/@cchistory/source-adapters/dist/platforms/amp/runtime.d.ts +4 -0
  342. package/node_modules/@cchistory/source-adapters/dist/platforms/amp/runtime.d.ts.map +1 -0
  343. package/node_modules/@cchistory/source-adapters/dist/platforms/amp/runtime.js +85 -0
  344. package/node_modules/@cchistory/source-adapters/dist/platforms/amp/runtime.js.map +1 -0
  345. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.d.ts +3 -0
  346. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.d.ts.map +1 -0
  347. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.js +10 -0
  348. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.js.map +1 -0
  349. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.d.ts +2 -0
  350. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.d.ts.map +1 -0
  351. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js +105 -0
  352. package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js.map +1 -0
  353. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.d.ts +45 -0
  354. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.d.ts.map +1 -0
  355. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.js +609 -0
  356. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/live.js.map +1 -0
  357. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/runtime.d.ts +16 -0
  358. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/runtime.d.ts.map +1 -0
  359. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/runtime.js +534 -0
  360. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity/runtime.js.map +1 -0
  361. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.d.ts +12 -0
  362. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.d.ts.map +1 -0
  363. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.js +105 -0
  364. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.js.map +1 -0
  365. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.d.ts +2 -0
  366. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.d.ts.map +1 -0
  367. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js +820 -0
  368. package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js.map +1 -0
  369. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code/runtime.d.ts +4 -0
  370. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code/runtime.d.ts.map +1 -0
  371. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code/runtime.js +130 -0
  372. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code/runtime.js.map +1 -0
  373. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code.d.ts +3 -0
  374. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code.d.ts.map +1 -0
  375. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code.js +10 -0
  376. package/node_modules/@cchistory/source-adapters/dist/platforms/claude-code.js.map +1 -0
  377. package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.d.ts +2 -0
  378. package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.d.ts.map +1 -0
  379. package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js +357 -0
  380. package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js.map +1 -0
  381. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.d.ts +4 -0
  382. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.d.ts.map +1 -0
  383. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.js +27 -0
  384. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.js.map +1 -0
  385. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.d.ts +2 -0
  386. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.d.ts.map +1 -0
  387. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js +49 -0
  388. package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js.map +1 -0
  389. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/runtime.d.ts +4 -0
  390. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/runtime.d.ts.map +1 -0
  391. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/runtime.js +555 -0
  392. package/node_modules/@cchistory/source-adapters/dist/platforms/codex/runtime.js.map +1 -0
  393. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.d.ts +3 -0
  394. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.d.ts.map +1 -0
  395. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.js +15 -0
  396. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.js.map +1 -0
  397. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.d.ts +2 -0
  398. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.d.ts.map +1 -0
  399. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js +893 -0
  400. package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js.map +1 -0
  401. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts +70 -0
  402. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts.map +1 -0
  403. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js +786 -0
  404. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js.map +1 -0
  405. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.d.ts +4 -0
  406. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.d.ts.map +1 -0
  407. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.js +14 -0
  408. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.js.map +1 -0
  409. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.d.ts +2 -0
  410. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.d.ts.map +1 -0
  411. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js +154 -0
  412. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js.map +1 -0
  413. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.d.ts +4 -0
  414. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.d.ts.map +1 -0
  415. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.js +151 -0
  416. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.js.map +1 -0
  417. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.d.ts +2 -0
  418. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.d.ts.map +1 -0
  419. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js +1486 -0
  420. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js.map +1 -0
  421. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid/runtime.d.ts +4 -0
  422. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid/runtime.d.ts.map +1 -0
  423. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid/runtime.js +229 -0
  424. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid/runtime.js.map +1 -0
  425. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.d.ts +3 -0
  426. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.d.ts.map +1 -0
  427. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.js +10 -0
  428. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.js.map +1 -0
  429. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.d.ts +2 -0
  430. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.d.ts.map +1 -0
  431. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js +222 -0
  432. package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js.map +1 -0
  433. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.d.ts +7 -0
  434. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.d.ts.map +1 -0
  435. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.js +65 -0
  436. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.js.map +1 -0
  437. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.d.ts +2 -0
  438. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.d.ts.map +1 -0
  439. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js +220 -0
  440. package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js.map +1 -0
  441. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.d.ts +20 -0
  442. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.d.ts.map +1 -0
  443. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js +365 -0
  444. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js.map +1 -0
  445. package/node_modules/@cchistory/source-adapters/dist/platforms/grok/runtime.d.ts +17 -0
  446. package/node_modules/@cchistory/source-adapters/dist/platforms/grok/runtime.d.ts.map +1 -0
  447. package/node_modules/@cchistory/source-adapters/dist/platforms/grok/runtime.js +498 -0
  448. package/node_modules/@cchistory/source-adapters/dist/platforms/grok/runtime.js.map +1 -0
  449. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.d.ts +36 -0
  450. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.d.ts.map +1 -0
  451. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js +261 -0
  452. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js.map +1 -0
  453. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.d.ts +2 -0
  454. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.d.ts.map +1 -0
  455. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js +565 -0
  456. package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js.map +1 -0
  457. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi/runtime.d.ts +4 -0
  458. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi/runtime.d.ts.map +1 -0
  459. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi/runtime.js +193 -0
  460. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi/runtime.js.map +1 -0
  461. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.d.ts +7 -0
  462. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.d.ts.map +1 -0
  463. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.js +55 -0
  464. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.js.map +1 -0
  465. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.d.ts +2 -0
  466. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.d.ts.map +1 -0
  467. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js +163 -0
  468. package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js.map +1 -0
  469. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.d.ts +3 -0
  470. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.d.ts.map +1 -0
  471. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.js +10 -0
  472. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.js.map +1 -0
  473. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.d.ts +2 -0
  474. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.d.ts.map +1 -0
  475. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js +179 -0
  476. package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js.map +1 -0
  477. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw/runtime.d.ts +4 -0
  478. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw/runtime.d.ts.map +1 -0
  479. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw/runtime.js +44 -0
  480. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw/runtime.js.map +1 -0
  481. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.d.ts +3 -0
  482. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.d.ts.map +1 -0
  483. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.js +60 -0
  484. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.js.map +1 -0
  485. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.d.ts +2 -0
  486. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.d.ts.map +1 -0
  487. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js +39 -0
  488. package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js.map +1 -0
  489. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.d.ts +3 -0
  490. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.d.ts.map +1 -0
  491. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.js +45 -0
  492. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.js.map +1 -0
  493. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.d.ts +2 -0
  494. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.d.ts.map +1 -0
  495. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js +170 -0
  496. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js.map +1 -0
  497. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.d.ts +7 -0
  498. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.d.ts.map +1 -0
  499. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js +52 -0
  500. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js.map +1 -0
  501. package/node_modules/@cchistory/source-adapters/dist/platforms/runtime-types.d.ts +104 -0
  502. package/node_modules/@cchistory/source-adapters/dist/platforms/runtime-types.d.ts.map +1 -0
  503. package/node_modules/@cchistory/source-adapters/dist/platforms/runtime-types.js +2 -0
  504. package/node_modules/@cchistory/source-adapters/dist/platforms/runtime-types.js.map +1 -0
  505. package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts +38 -0
  506. package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts.map +1 -0
  507. package/node_modules/@cchistory/source-adapters/dist/platforms/types.js +19 -0
  508. package/node_modules/@cchistory/source-adapters/dist/platforms/types.js.map +1 -0
  509. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts +14 -0
  510. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts.map +1 -0
  511. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js +283 -0
  512. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js.map +1 -0
  513. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.d.ts +3 -0
  514. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.d.ts.map +1 -0
  515. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.js +26 -0
  516. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.js.map +1 -0
  517. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.d.ts +2 -0
  518. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.d.ts.map +1 -0
  519. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js +411 -0
  520. package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js.map +1 -0
  521. package/node_modules/@cchistory/source-adapters/dist/test-helpers.d.ts +85 -0
  522. package/node_modules/@cchistory/source-adapters/dist/test-helpers.d.ts.map +1 -0
  523. package/node_modules/@cchistory/source-adapters/dist/test-helpers.js +2106 -0
  524. package/node_modules/@cchistory/source-adapters/dist/test-helpers.js.map +1 -0
  525. package/node_modules/@cchistory/source-adapters/package.json +14 -0
  526. package/package.json +38 -0
  527. package/schemas/cchistory-lite-canonical-v1.schema.json +13 -0
  528. package/schemas/cchistory-lite-error-v1.schema.json +30 -0
  529. package/schemas/cchistory-lite-query-result-v1.schema.json +29 -0
  530. package/schemas/cchistory-lite-query-result-v2.schema.json +29 -0
  531. package/schemas/cchistory-lite-query-v1.schema.json +62 -0
  532. package/schemas/cchistory-lite-query-v2.schema.json +82 -0
  533. package/schemas/cchistory-lite-v2.schema.json +176 -0
@@ -0,0 +1,1829 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import { readFile, stat } from "node:fs/promises";
4
+ import { deriveHostId, selectTailBlob } from "@cchistory/domain";
5
+ import { nowIso, stableId, pathExists, formatErrorMessage, createLossAudit, dedupeById, listSourceFiles, readGitProjectEvidence, deriveSessionId, extractSourceSessionIdFromCanonicalSessionId, buildSourceResumeCommand, minIso, maxIso, sha1, compareTimeThenSeq, collapseAntigravityUserTurnAtoms, } from "./utils.js";
6
+ import { getDefaultSources, resolveSourceFormatProfile } from "./discovery.js";
7
+ import { extractAntigravityLiveSeeds } from "../platforms/antigravity/live.js";
8
+ import { isAntigravityBrainSourceFile, isAntigravityHistoryIndexFile } from "../platforms/antigravity.js";
9
+ import { extractCursorChatStoreSeed, clearCursorWorkspaceIndexCache } from "../platforms/cursor/runtime.js";
10
+ import { getPlatformAdapter } from "../platforms/registry.js";
11
+ import { deriveSourceFileLogicalSessionKey, inspectSourceFileLogicalSessionMetadata, SESSION_METADATA_MAX_LINE_BYTES, } from "./session-grouping.js";
12
+ import { extractRecords, extractMultiSessionSeeds, buildAdapterBlobResult, captureBlob, captureBlobStreaming, fileIdentityFromStats, parseRecord, isOrdinaryResumeEligibleSourceFile, extractGenericSessionMetadata, extractGenericRole, extractGenericContentItems, extractRichTextText, collectConversationSeedsFromValue, dedupeClaudeCodeTokenUsageFragments, } from "./parser.js";
13
+ import { collectJsonlRecordsStreaming, isIncrementalJsonlPlatform } from "./jsonl-records.js";
14
+ import { atomizeFragments, hydrateDraftFromAtoms } from "./atomizer.js";
15
+ import { splitUserText } from "./user-text.js";
16
+ import { buildProjectObservationCandidates, buildSubmissionGroups, buildTurnsAndContext, buildAskUserQuestionTurns, buildStageRuns, } from "./projections.js";
17
+ import { asArray, asNumber, asString, buildTokenUsageCheckpointBaselineKey, coerceIso, epochMillisToIso, extractTokenUsage, firstDefinedNumber, isObject, mergeMaxTokenUsageMetrics, normalizeStopReason, normalizeWorkspacePath, safeJsonParse, truncate, } from "./utils.js";
18
+ const DEFAULT_MAX_FILE_BYTES = 64 * 1024 * 1024;
19
+ function buildHost() {
20
+ const now = nowIso();
21
+ return {
22
+ id: deriveHostId(os.hostname()),
23
+ hostname: os.hostname(),
24
+ os: `${os.platform()} ${os.release()}`,
25
+ first_seen: now,
26
+ last_seen: now,
27
+ };
28
+ }
29
+ export async function runSourceProbe(options = {}, sources = getDefaultSources()) {
30
+ const host = buildHost();
31
+ const sourceList = sources.map((source) => ({ ...source }));
32
+ const selectedSourceIds = new Set(options.source_ids ?? sourceList.map((source) => source.id));
33
+ const payloads = [];
34
+ const collectorState = new Map();
35
+ for (const source of sourceList) {
36
+ if (!selectedSourceIds.has(source.id) && !selectedSourceIds.has(source.slot_id)) {
37
+ continue;
38
+ }
39
+ collectorState.set(source.id, {
40
+ source,
41
+ sourceFormatProfile: resolveSourceFormatProfile(source),
42
+ startedAt: nowIso(),
43
+ monotonicStartedAt: Date.now(),
44
+ sessionsById: new Map(),
45
+ orphanBlobs: [],
46
+ lossAudits: [],
47
+ fileProcessingErrors: [],
48
+ filesObserved: 0,
49
+ missingSource: undefined,
50
+ });
51
+ }
52
+ for await (const event of streamSourceProbe(options, sourceList, host)) {
53
+ const sourceId = event.kind === "file_chunk" ? event.chunk.source_id : event.source_id;
54
+ const state = collectorState.get(sourceId);
55
+ if (!state) {
56
+ continue;
57
+ }
58
+ if (event.kind === "source_missing") {
59
+ state.missingSource = event.source;
60
+ }
61
+ else if (event.kind === "file_chunk") {
62
+ absorbChunk(state, event.chunk);
63
+ state.filesObserved += 1;
64
+ }
65
+ else if (event.kind === "file_skip") {
66
+ if (event.chunk) {
67
+ absorbChunk(state, event.chunk);
68
+ }
69
+ state.filesObserved += 1;
70
+ }
71
+ else if (event.kind === "file_error") {
72
+ state.fileProcessingErrors.push(event.detail);
73
+ if (event.chunk) {
74
+ absorbChunk(state, event.chunk);
75
+ }
76
+ state.filesObserved += 1;
77
+ }
78
+ else if (event.kind === "source_done") {
79
+ payloads.push(await finalizeSourcePayload(state, host, options));
80
+ }
81
+ }
82
+ const targetRefs = options.target_session_refs?.filter((ref) => ref.trim().length > 0) ?? [];
83
+ for (const targetRef of targetRefs) {
84
+ if (!payloads.some((payload) => payload.sessions.some((session) => targetRefMatchesSession(targetRef, session.id, session.source_session_id)))) {
85
+ throw new Error(`Source probe did not find requested session ${targetRef}.`);
86
+ }
87
+ }
88
+ return { host, sources: payloads };
89
+ }
90
+ function absorbChunk(state, chunk) {
91
+ for (const sessionInput of chunk.session_inputs) {
92
+ mergeSessionBuildInput(state.sessionsById, sessionInput);
93
+ }
94
+ state.orphanBlobs.push(...chunk.orphan_blobs);
95
+ state.lossAudits.push(...chunk.loss_audits);
96
+ }
97
+ async function finalizeSourcePayload(state, host, options) {
98
+ if (state.missingSource) {
99
+ const stageRuns = buildStageRuns(state.source.id, state.source.platform, state.startedAt, nowIso(), {
100
+ blobs: 0, records: 0, fragments: 0, atoms: 0, sessions: 0, turns: 0,
101
+ }, []);
102
+ return {
103
+ source: { ...state.missingSource, host_id: host.id },
104
+ stage_runs: stageRuns,
105
+ loss_audits: [],
106
+ blobs: [],
107
+ records: [],
108
+ fragments: [],
109
+ atoms: [],
110
+ edges: [],
111
+ candidates: [],
112
+ sessions: [],
113
+ turns: [],
114
+ contexts: [],
115
+ ask_user_question_turns: [],
116
+ };
117
+ }
118
+ emitProbeProgress(options, state.source, {
119
+ stage: "derive_start",
120
+ message: `Deriving projections from ${state.sessionsById.size} session candidate(s)`,
121
+ });
122
+ const deriveStartedAt = Date.now();
123
+ const processingCore = await processCollectedSessions(state.sessionsById, state.orphanBlobs, state.lossAudits, { safeMode: options.safe_mode ?? false });
124
+ emitProbeProgress(options, state.source, {
125
+ stage: "derive_done",
126
+ message: `Derived ${processingCore.sessions.length} session(s), ${processingCore.turns.length} turn(s)`,
127
+ count: processingCore.turns.length,
128
+ elapsed_ms: Date.now() - deriveStartedAt,
129
+ });
130
+ const uniqueBlobs = dedupeById(processingCore.blobs);
131
+ const finishedAt = nowIso();
132
+ const stageRuns = buildStageRuns(state.source.id, state.source.platform, state.startedAt, finishedAt, {
133
+ blobs: uniqueBlobs.length,
134
+ records: processingCore.records.length,
135
+ fragments: processingCore.fragments.length,
136
+ atoms: processingCore.atoms.length,
137
+ sessions: processingCore.sessions.length,
138
+ turns: processingCore.turns.length,
139
+ }, processingCore.lossAudits);
140
+ const payload = {
141
+ source: {
142
+ id: state.source.id,
143
+ slot_id: state.source.slot_id,
144
+ family: state.source.family,
145
+ platform: state.source.platform,
146
+ display_name: state.source.display_name,
147
+ base_dir: state.source.base_dir,
148
+ host_id: host.id,
149
+ last_sync: finishedAt,
150
+ sync_status: state.filesObserved === 0
151
+ ? "stale"
152
+ : processingCore.sessions.length > 0 || processingCore.turns.length > 0
153
+ ? "healthy"
154
+ : state.fileProcessingErrors.length > 0
155
+ ? "error"
156
+ : "stale",
157
+ error_message: state.fileProcessingErrors.length > 0
158
+ ? `${state.fileProcessingErrors[0]}${state.fileProcessingErrors.length > 1 ? ` (+${state.fileProcessingErrors.length - 1} more)` : ""}`
159
+ : undefined,
160
+ total_blobs: uniqueBlobs.length,
161
+ total_records: processingCore.records.length,
162
+ total_fragments: processingCore.fragments.length,
163
+ total_atoms: processingCore.atoms.length,
164
+ total_sessions: processingCore.sessions.length,
165
+ total_turns: processingCore.turns.length,
166
+ },
167
+ stage_runs: stageRuns,
168
+ loss_audits: processingCore.lossAudits,
169
+ blobs: uniqueBlobs,
170
+ records: processingCore.records,
171
+ fragments: processingCore.fragments,
172
+ atoms: processingCore.atoms,
173
+ edges: processingCore.edges,
174
+ candidates: processingCore.candidates,
175
+ sessions: processingCore.sessions,
176
+ turns: processingCore.turns,
177
+ contexts: processingCore.contexts,
178
+ ask_user_question_turns: processingCore.askUserQuestionTurns,
179
+ };
180
+ emitProbeProgress(options, state.source, {
181
+ stage: "source_done",
182
+ message: `Finished ${state.source.display_name}`,
183
+ count: processingCore.turns.length,
184
+ elapsed_ms: Date.now() - state.monotonicStartedAt,
185
+ });
186
+ return payload;
187
+ }
188
+ /**
189
+ * Streaming variant of runSourceProbe. Yields one event per file/per source,
190
+ * letting consumers (CLI sync) bound memory by processing each chunk and
191
+ * releasing it before the next. Host is constructed internally and passed
192
+ * back via the runSourceProbe collector; for direct consumers the host is
193
+ * also returned via the generator's final value.
194
+ */
195
+ export async function* streamSourceProbe(options = {}, sources = getDefaultSources(), host) {
196
+ clearCursorWorkspaceIndexCache();
197
+ const resolvedHost = host ?? buildHost();
198
+ const sourceList = sources.map((source) => ({ ...source }));
199
+ const selectedSourceIds = new Set(options.source_ids ?? sourceList.map((source) => source.id));
200
+ for (const source of sourceList) {
201
+ if (!selectedSourceIds.has(source.id) && !selectedSourceIds.has(source.slot_id)) {
202
+ continue;
203
+ }
204
+ yield* streamSingleSource(options, source, resolvedHost);
205
+ }
206
+ return resolvedHost;
207
+ }
208
+ async function* streamSingleSource(options, source, host) {
209
+ const startedAt = nowIso();
210
+ const monotonicStartedAt = Date.now();
211
+ const sourceFormatProfile = resolveSourceFormatProfile(source);
212
+ emitProbeProgress(options, source, {
213
+ stage: "source_start",
214
+ message: `Scanning ${source.display_name} (${source.slot_id})`,
215
+ });
216
+ const baseDirExists = await pathExists(source.base_dir);
217
+ if (!baseDirExists) {
218
+ emitProbeProgress(options, source, {
219
+ stage: "source_missing",
220
+ message: `Source path not found: ${source.base_dir}`,
221
+ elapsed_ms: Date.now() - monotonicStartedAt,
222
+ });
223
+ const missingSource = {
224
+ id: source.id,
225
+ slot_id: source.slot_id,
226
+ family: source.family,
227
+ platform: source.platform,
228
+ display_name: source.display_name,
229
+ base_dir: source.base_dir,
230
+ host_id: host.id,
231
+ last_sync: nowIso(),
232
+ sync_status: "error",
233
+ error_message: `Source path not found: ${source.base_dir}`,
234
+ total_blobs: 0,
235
+ total_records: 0,
236
+ total_fragments: 0,
237
+ total_atoms: 0,
238
+ total_sessions: 0,
239
+ total_turns: 0,
240
+ };
241
+ yield { kind: "source_missing", source_id: source.id, source: missingSource };
242
+ yield { kind: "source_done", source_id: source.id, file_processing_errors: [] };
243
+ return;
244
+ }
245
+ const fileProcessingErrors = [];
246
+ for await (const collected of streamCollectedFileInputs(source, host, sourceFormatProfile, options, startedAt)) {
247
+ const chunk = {
248
+ source_id: source.id,
249
+ origin_path: collected.originPath,
250
+ session_inputs: collected.sessionInputs,
251
+ orphan_blobs: collected.orphanBlobs,
252
+ loss_audits: collected.lossAudits,
253
+ trusted_bytes_by_blob_id: collected.trustedBytesByBlobId,
254
+ };
255
+ if (collected.errorDetail) {
256
+ fileProcessingErrors.push(collected.errorDetail);
257
+ yield {
258
+ kind: "file_error",
259
+ source_id: source.id,
260
+ origin_path: collected.originPath,
261
+ detail: collected.errorDetail,
262
+ chunk,
263
+ };
264
+ }
265
+ else if (collected.skipReason) {
266
+ yield {
267
+ kind: "file_skip",
268
+ source_id: source.id,
269
+ origin_path: collected.originPath,
270
+ reason: collected.skipReason,
271
+ size_bytes: collected.sizeBytes,
272
+ chunk,
273
+ };
274
+ }
275
+ else {
276
+ yield { kind: "file_chunk", chunk };
277
+ }
278
+ }
279
+ yield { kind: "source_done", source_id: source.id, file_processing_errors: fileProcessingErrors };
280
+ }
281
+ /**
282
+ * Project one file's worth of SessionBuildInputs into the flat arrays that
283
+ * the storage layer consumes. Used by streaming merge consumers that don't
284
+ * re-merge across files (CLI sync). operatePerFile: each session is projected
285
+ * independently; cross-file session merging is the caller's responsibility.
286
+ */
287
+ export async function projectFileSessionInputs(source, sessionInputs, orphanBlobs, lossAudits, options) {
288
+ const sessionsById = new Map();
289
+ for (const sessionInput of sessionInputs) {
290
+ mergeSessionBuildInput(sessionsById, sessionInput);
291
+ }
292
+ return processCollectedSessions(sessionsById, [...orphanBlobs], [...lossAudits], options);
293
+ }
294
+ async function* streamCollectedFileInputs(source, host, sourceFormatProfile, options, startedAt) {
295
+ const captureRunId = stableId("capture-run", source.id, startedAt);
296
+ const adapter = getPlatformAdapter(source.platform);
297
+ const previousIndex = buildPreviousSourceIndex(options.previous_payloads?.[source.id], sourceFormatProfile);
298
+ const changedSinceMs = parseChangedSinceMs(options.changed_since);
299
+ const capturedCompanionPaths = new Set();
300
+ let remainingFileLimit = options.limit_files_per_source;
301
+ if (source.platform === "antigravity" && !options.safe_mode) {
302
+ emitProbeProgress(options, source, {
303
+ stage: "live_probe_start",
304
+ message: "Reading Antigravity live trajectory API",
305
+ });
306
+ const liveCollection = await extractAntigravityLiveSeeds(source.base_dir, {
307
+ limit: remainingFileLimit,
308
+ sessionRefs: options.target_session_refs,
309
+ });
310
+ if (liveCollection) {
311
+ for (const [index, seed] of liveCollection.seeds.entries()) {
312
+ const virtualPath = liveCollection.virtualPaths[index] ?? `antigravity-live://${seed.sessionId}`;
313
+ const adapterResult = buildSyntheticSeedAdapterResult(source, sourceFormatProfile, host.id, captureRunId, virtualPath, seed);
314
+ const sessionsById = new Map();
315
+ mergeAdapterBlobResult(sessionsById, adapterResult);
316
+ yield {
317
+ originPath: virtualPath,
318
+ sessionInputs: [...sessionsById.values()],
319
+ orphanBlobs: [],
320
+ lossAudits: [],
321
+ trustedBytesByBlobId: new Map(),
322
+ };
323
+ }
324
+ if (typeof remainingFileLimit === "number") {
325
+ remainingFileLimit = Math.max(remainingFileLimit - liveCollection.virtualPaths.length, 0);
326
+ }
327
+ }
328
+ emitProbeProgress(options, source, {
329
+ stage: "live_probe_done",
330
+ message: `Collected ${liveCollection?.virtualPaths.length ?? 0} live item(s)`,
331
+ count: liveCollection?.virtualPaths.length ?? 0,
332
+ });
333
+ }
334
+ emitProbeProgress(options, source, {
335
+ stage: "list_files_start",
336
+ message: `Listing source files under ${source.base_dir}`,
337
+ });
338
+ const listFilesStartedAt = Date.now();
339
+ const selectedFiles = options.source_file_paths?.[source.id] ?? options.source_file_paths?.[source.slot_id];
340
+ const listedFiles = selectedFiles
341
+ ? [...selectedFiles].slice(0, remainingFileLimit)
342
+ : await listSourceFiles(source.platform, source.base_dir, remainingFileLimit);
343
+ const files = options.target_session_refs?.length && !selectedFiles
344
+ ? await selectTargetSourceFiles(source, adapter, listedFiles, options.target_session_refs)
345
+ : listedFiles;
346
+ emitProbeProgress(options, source, {
347
+ stage: "list_files_done",
348
+ message: `Found ${files.length} source file(s)`,
349
+ count: files.length,
350
+ file_count: files.length,
351
+ elapsed_ms: Date.now() - listFilesStartedAt,
352
+ });
353
+ for (const [fileIndex, filePath] of files.entries()) {
354
+ yield* streamSingleFileInputs(source, host, sourceFormatProfile, options, captureRunId, adapter, previousIndex, changedSinceMs, capturedCompanionPaths, filePath, fileIndex, files.length);
355
+ }
356
+ }
357
+ async function* streamSingleFileInputs(source, host, sourceFormatProfile, options, captureRunId, adapter, previousIndex, changedSinceMs, capturedCompanionPaths, filePath, fileIndex, fileCount) {
358
+ let capturedBlob;
359
+ const fileStartedAt = Date.now();
360
+ emitProbeProgress(options, source, {
361
+ stage: "file_start",
362
+ message: `Processing ${filePath}`,
363
+ file_path: filePath,
364
+ file_index: fileIndex + 1,
365
+ file_count: fileCount,
366
+ });
367
+ const fileLossAudits = [];
368
+ const fileOrphanBlobs = [];
369
+ const fileTrustedBytesByBlobId = new Map();
370
+ const fileSessionInputs = [];
371
+ let fileSkipReason;
372
+ let fileSizeBytes;
373
+ let fileErrorDetail;
374
+ let earlyYield = false;
375
+ try {
376
+ const fileStats = await stat(filePath);
377
+ const sizeBytes = fileStats.size;
378
+ const maxFileBytes = options.max_file_bytes ?? DEFAULT_MAX_FILE_BYTES;
379
+ const isOversized = sizeBytes > maxFileBytes;
380
+ // Oversized files are skipped only when parsing needs the whole file in
381
+ // memory. Incremental JSONL streams; path-backed SQLite is opened by path.
382
+ const canProcessOversizedWithoutMaterializing = isOversized &&
383
+ (isIncrementalJsonlPlatform(source.platform) || isPathBackedSqliteSourceFile(source.platform, filePath));
384
+ if (isOversized && !canProcessOversizedWithoutMaterializing) {
385
+ const detail = `Skipped oversized source file ${filePath}: ${sizeBytes} bytes exceeds ${maxFileBytes} byte limit`;
386
+ const blobRef = stableId("blob", source.id, filePath, "oversized");
387
+ fileLossAudits.push(createLossAudit(source.id, blobRef, "unknown_fragment", detail, {
388
+ stageKind: "capture",
389
+ diagnosticCode: "blob_too_large",
390
+ severity: "warning",
391
+ blobRef,
392
+ sourceFormatProfileId: sourceFormatProfile.id,
393
+ }));
394
+ fileErrorDetail = detail;
395
+ fileSkipReason = "oversized";
396
+ fileSizeBytes = sizeBytes;
397
+ emitProbeProgress(options, source, {
398
+ stage: "file_error",
399
+ message: detail,
400
+ file_path: filePath,
401
+ file_index: fileIndex + 1,
402
+ file_count: fileCount,
403
+ elapsed_ms: Date.now() - fileStartedAt,
404
+ });
405
+ earlyYield = true;
406
+ }
407
+ else {
408
+ const previousEntry = previousIndex?.byOriginPath.get(path.normalize(filePath));
409
+ const isOlderThanSince = changedSinceMs !== undefined && fileStats.mtime.getTime() < changedSinceMs;
410
+ if (previousEntry && canReuseBlobFromStats(previousEntry, fileStats)) {
411
+ if (!previousIndex?.metadataOnly) {
412
+ const sessionsById = new Map();
413
+ mergePreviousFileEntry(sessionsById, fileOrphanBlobs, fileLossAudits, previousEntry);
414
+ fileSessionInputs.push(...sessionsById.values());
415
+ }
416
+ fileSkipReason = "metadata_only";
417
+ fileSizeBytes = fileStats.size;
418
+ emitProbeProgress(options, source, {
419
+ stage: "file_skip",
420
+ message: `Reused unchanged file without reading content: ${filePath}`,
421
+ file_path: filePath,
422
+ file_index: fileIndex + 1,
423
+ file_count: fileCount,
424
+ size_bytes: fileStats.size,
425
+ elapsed_ms: Date.now() - fileStartedAt,
426
+ });
427
+ emitProbeProgress(options, source, {
428
+ stage: "file_done",
429
+ message: `Processed ${filePath}`,
430
+ file_path: filePath,
431
+ file_index: fileIndex + 1,
432
+ file_count: fileCount,
433
+ size_bytes: fileStats.size,
434
+ elapsed_ms: Date.now() - fileStartedAt,
435
+ });
436
+ earlyYield = true;
437
+ }
438
+ else {
439
+ const captureStartedAt = Date.now();
440
+ capturedBlob = canProcessOversizedWithoutMaterializing
441
+ ? isPathBackedSqliteSourceFile(source.platform, filePath)
442
+ ? await capturePathBackedBlob(source, host.id, filePath, captureRunId)
443
+ : await captureBlobStreaming(source, host.id, filePath, captureRunId)
444
+ : await captureBlob(source, host.id, filePath, captureRunId);
445
+ emitProbeProgress(options, source, {
446
+ stage: "file_capture_done",
447
+ message: `Captured ${filePath}`,
448
+ file_path: filePath,
449
+ file_index: fileIndex + 1,
450
+ file_count: fileCount,
451
+ size_bytes: capturedBlob.blob.size_bytes,
452
+ elapsed_ms: Date.now() - captureStartedAt,
453
+ });
454
+ if (previousEntry && canReuseCapturedBlob(previousEntry, capturedBlob.blob)) {
455
+ if (previousIndex?.metadataOnly) {
456
+ fileOrphanBlobs.push(capturedBlob.blob);
457
+ // Stage 3: streaming variant has no fileBuffer — storage will
458
+ // stream-read the bytes from captured_path if needed.
459
+ if (capturedBlobHasFileBuffer(capturedBlob)) {
460
+ fileTrustedBytesByBlobId.set(capturedBlob.blob.id, capturedBlob.fileBuffer);
461
+ }
462
+ fileSkipReason = "metadata_only";
463
+ fileSizeBytes = capturedBlob.blob.size_bytes;
464
+ emitProbeProgress(options, source, {
465
+ stage: "file_skip",
466
+ message: `Reused unchanged file: ${filePath}`,
467
+ file_path: filePath,
468
+ file_index: fileIndex + 1,
469
+ file_count: fileCount,
470
+ size_bytes: capturedBlob.blob.size_bytes,
471
+ elapsed_ms: Date.now() - fileStartedAt,
472
+ });
473
+ emitProbeProgress(options, source, {
474
+ stage: "file_done",
475
+ message: `Processed ${filePath}`,
476
+ file_path: filePath,
477
+ file_index: fileIndex + 1,
478
+ file_count: fileCount,
479
+ size_bytes: capturedBlob.blob.size_bytes,
480
+ elapsed_ms: Date.now() - fileStartedAt,
481
+ });
482
+ earlyYield = true;
483
+ }
484
+ else {
485
+ const sessionsById = new Map();
486
+ mergePreviousFileEntry(sessionsById, fileOrphanBlobs, fileLossAudits, previousEntry, capturedBlob.blob);
487
+ fileSessionInputs.push(...sessionsById.values());
488
+ if (capturedBlobHasFileBuffer(capturedBlob)) {
489
+ fileTrustedBytesByBlobId.set(capturedBlob.blob.id, capturedBlob.fileBuffer);
490
+ }
491
+ fileSkipReason = "unchanged";
492
+ fileSizeBytes = capturedBlob.blob.size_bytes;
493
+ emitProbeProgress(options, source, {
494
+ stage: isOlderThanSince ? "file_skip" : "file_reuse",
495
+ message: isOlderThanSince
496
+ ? `Reused unchanged file: ${filePath}`
497
+ : `Reused unchanged projection for ${filePath}`,
498
+ file_path: filePath,
499
+ file_index: fileIndex + 1,
500
+ file_count: fileCount,
501
+ size_bytes: capturedBlob.blob.size_bytes,
502
+ elapsed_ms: Date.now() - fileStartedAt,
503
+ });
504
+ emitProbeProgress(options, source, {
505
+ stage: "file_done",
506
+ message: `Processed ${filePath}`,
507
+ file_path: filePath,
508
+ file_index: fileIndex + 1,
509
+ file_count: fileCount,
510
+ size_bytes: capturedBlob.blob.size_bytes,
511
+ elapsed_ms: Date.now() - fileStartedAt,
512
+ });
513
+ earlyYield = true;
514
+ }
515
+ }
516
+ }
517
+ }
518
+ }
519
+ catch (error) {
520
+ const detail = `Failed to capture source file ${filePath}: ${formatErrorMessage(error)}`;
521
+ const blobRef = stableId("blob", source.id, filePath, "capture-failed");
522
+ fileLossAudits.push(createLossAudit(source.id, blobRef, "unknown_fragment", detail, {
523
+ stageKind: "capture",
524
+ diagnosticCode: "blob_capture_failed",
525
+ severity: "error",
526
+ blobRef,
527
+ sourceFormatProfileId: sourceFormatProfile.id,
528
+ }));
529
+ fileErrorDetail = detail;
530
+ fileSkipReason = "capture_failed";
531
+ emitProbeProgress(options, source, {
532
+ stage: "file_error",
533
+ message: detail,
534
+ file_path: filePath,
535
+ file_index: fileIndex + 1,
536
+ file_count: fileCount,
537
+ elapsed_ms: Date.now() - fileStartedAt,
538
+ });
539
+ earlyYield = true;
540
+ }
541
+ if (earlyYield) {
542
+ yield {
543
+ originPath: filePath,
544
+ sessionInputs: fileSessionInputs,
545
+ orphanBlobs: fileOrphanBlobs,
546
+ lossAudits: fileLossAudits,
547
+ trustedBytesByBlobId: fileTrustedBytesByBlobId,
548
+ skipReason: fileSkipReason,
549
+ sizeBytes: fileSizeBytes,
550
+ errorDetail: fileErrorDetail,
551
+ };
552
+ return;
553
+ }
554
+ try {
555
+ const parseStartedAt = Date.now();
556
+ const previousEntry = previousIndex?.byOriginPath.get(path.normalize(filePath));
557
+ const appendedResults = previousEntry && capturedBlob
558
+ ? await processAppendedJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob, previousEntry)
559
+ : undefined;
560
+ if (appendedResults) {
561
+ emitProbeProgress(options, source, {
562
+ stage: "file_append_start",
563
+ message: `Parsing appended records for ${filePath}`,
564
+ file_path: filePath,
565
+ file_index: fileIndex + 1,
566
+ file_count: fileCount,
567
+ });
568
+ }
569
+ const adapterResults = appendedResults ?? (capturedBlob
570
+ ? (capturedBlobHasFileBuffer(capturedBlob)
571
+ ? await processBlob(source, sourceFormatProfile, filePath, capturedBlob, options.target_session_refs)
572
+ : capturedBlobIsStreaming(capturedBlob)
573
+ ? await processStreamingJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob)
574
+ : await processPathBackedSqliteBlob(source, sourceFormatProfile, filePath, capturedBlob.blob, options.target_session_refs))
575
+ : []);
576
+ const sessionsById = new Map();
577
+ const targetedResults = options.target_session_refs?.length
578
+ ? adapterResults.filter((result) => options.target_session_refs.some((ref) => targetRefMatchesSession(ref, result.draft.id, result.draft.source_session_id)) || resultReferencesTargetSession(source, result, options.target_session_refs))
579
+ : adapterResults;
580
+ for (const adapterResult of targetedResults) {
581
+ mergeAdapterBlobResult(sessionsById, adapterResult);
582
+ }
583
+ if (capturedBlob && capturedBlobHasFileBuffer(capturedBlob)) {
584
+ fileTrustedBytesByBlobId.set(capturedBlob.blob.id, capturedBlob.fileBuffer);
585
+ }
586
+ emitProbeProgress(options, source, {
587
+ stage: appendedResults ? "file_append_done" : "file_parse_done",
588
+ message: appendedResults ? `Parsed appended records for ${filePath}` : `Parsed ${filePath}`,
589
+ file_path: filePath,
590
+ file_index: fileIndex + 1,
591
+ file_count: fileCount,
592
+ size_bytes: capturedBlob?.blob.size_bytes,
593
+ elapsed_ms: Date.now() - parseStartedAt,
594
+ });
595
+ if (adapter?.getCompanionEvidencePaths && !options.safe_mode) {
596
+ for (const companionPath of await adapter.getCompanionEvidencePaths(source.base_dir, filePath)) {
597
+ const normalizedCompanionPath = path.normalize(companionPath);
598
+ if (capturedCompanionPaths.has(normalizedCompanionPath) || !(await pathExists(normalizedCompanionPath))) {
599
+ continue;
600
+ }
601
+ capturedCompanionPaths.add(normalizedCompanionPath);
602
+ try {
603
+ const companionCaptured = await captureBlob(source, host.id, normalizedCompanionPath, captureRunId);
604
+ fileOrphanBlobs.push(companionCaptured.blob);
605
+ fileTrustedBytesByBlobId.set(companionCaptured.blob.id, companionCaptured.fileBuffer);
606
+ }
607
+ catch (error) {
608
+ const blobRef = stableId("blob", source.id, normalizedCompanionPath, "capture-failed");
609
+ fileLossAudits.push(createLossAudit(source.id, blobRef, "unknown_fragment", `Failed to capture companion evidence file ${normalizedCompanionPath}: ${formatErrorMessage(error)}`, {
610
+ stageKind: "capture",
611
+ diagnosticCode: "blob_capture_failed",
612
+ severity: "warning",
613
+ blobRef,
614
+ sourceFormatProfileId: sourceFormatProfile.id,
615
+ }));
616
+ }
617
+ }
618
+ }
619
+ emitProbeProgress(options, source, {
620
+ stage: "file_done",
621
+ message: `Processed ${filePath}`,
622
+ file_path: filePath,
623
+ file_index: fileIndex + 1,
624
+ file_count: fileCount,
625
+ size_bytes: capturedBlob?.blob.size_bytes,
626
+ elapsed_ms: Date.now() - fileStartedAt,
627
+ });
628
+ yield {
629
+ originPath: filePath,
630
+ sessionInputs: [...sessionsById.values()],
631
+ orphanBlobs: fileOrphanBlobs,
632
+ lossAudits: fileLossAudits,
633
+ trustedBytesByBlobId: fileTrustedBytesByBlobId,
634
+ };
635
+ }
636
+ catch (error) {
637
+ const orphanBlob = capturedBlob?.blob;
638
+ if (orphanBlob) {
639
+ fileOrphanBlobs.push(orphanBlob);
640
+ }
641
+ const detail = `Failed to process captured source file ${filePath}: ${formatErrorMessage(error)}`;
642
+ if (orphanBlob) {
643
+ fileLossAudits.push(createLossAudit(source.id, orphanBlob.id, "unknown_fragment", detail, {
644
+ stageKind: "extract_records",
645
+ diagnosticCode: "blob_processing_failed",
646
+ severity: "error",
647
+ blobRef: orphanBlob.id,
648
+ sessionRef: capturedBlob && capturedBlobHasFileBuffer(capturedBlob)
649
+ ? deriveSessionId(source.platform, filePath, capturedBlob.fileBuffer)
650
+ : undefined,
651
+ sourceFormatProfileId: sourceFormatProfile.id,
652
+ }));
653
+ }
654
+ fileErrorDetail = detail;
655
+ emitProbeProgress(options, source, {
656
+ stage: "file_error",
657
+ message: detail,
658
+ file_path: filePath,
659
+ file_index: fileIndex + 1,
660
+ file_count: fileCount,
661
+ elapsed_ms: Date.now() - fileStartedAt,
662
+ });
663
+ yield {
664
+ originPath: filePath,
665
+ sessionInputs: [],
666
+ orphanBlobs: fileOrphanBlobs,
667
+ lossAudits: fileLossAudits,
668
+ trustedBytesByBlobId: fileTrustedBytesByBlobId,
669
+ errorDetail: fileErrorDetail,
670
+ };
671
+ }
672
+ }
673
+ async function selectTargetSourceFiles(source, adapter, files, sessionRefs) {
674
+ if (adapter?.sessionTargeting === "container")
675
+ return [...files];
676
+ const selected = [];
677
+ for (const filePath of files) {
678
+ if ((adapter?.sessionTargeting === "hybrid" || source.platform === "openclaw") &&
679
+ isMultiSessionContainer(source.platform, filePath)) {
680
+ selected.push(filePath);
681
+ continue;
682
+ }
683
+ const normalizedPath = filePath.replace(/\\/gu, "/").toLowerCase();
684
+ const pathMatch = sessionRefs.some((ref) => {
685
+ const nativeRef = stripCanonicalSessionPrefix(ref, source.platform).toLowerCase();
686
+ return nativeRef.length > 0 && normalizedPath.includes(nativeRef);
687
+ });
688
+ if (pathMatch) {
689
+ selected.push(filePath);
690
+ continue;
691
+ }
692
+ const metadata = source.platform === "codex" || source.platform === "claude_code"
693
+ ? await inspectSourceFileLogicalSessionMetadata(source.platform, filePath, { includeWorkspaceMetadata: false })
694
+ : undefined;
695
+ if (metadata?.sessionKeyState === "uncertain") {
696
+ selected.push(filePath);
697
+ continue;
698
+ }
699
+ const sessionKey = metadata?.sessionKey ?? await deriveSourceFileLogicalSessionKey(source.platform, filePath);
700
+ if (sessionRefs.some((ref) => targetRefMatchesSession(ref, sessionKey)) ||
701
+ metadata?.relatedSessionRefs?.some((relatedRef) => sessionRefs.some((ref) => targetRefMatchesSession(ref, relatedRef)))) {
702
+ selected.push(filePath);
703
+ }
704
+ }
705
+ return selected;
706
+ }
707
+ function isMultiSessionContainer(platform, filePath) {
708
+ const basename = path.basename(filePath);
709
+ if (platform === "antigravity" &&
710
+ (isAntigravityHistoryIndexFile(filePath) || isAntigravityBrainSourceFile(filePath))) {
711
+ return true;
712
+ }
713
+ return ((platform === "openclaw" && isOpenClawCronRunFile(filePath)) ||
714
+ platform === "zcode" ||
715
+ platform === "lobechat" ||
716
+ ((platform === "cursor" || platform === "antigravity") &&
717
+ (basename === "state.vscdb" || basename === "store.db")));
718
+ }
719
+ function isPathBackedSqliteSourceFile(platform, filePath) {
720
+ const basename = path.basename(filePath);
721
+ if (platform === "zcode") {
722
+ return basename === "db.sqlite";
723
+ }
724
+ return ((platform === "cursor" || platform === "antigravity") &&
725
+ (basename === "state.vscdb" || basename === "store.db"));
726
+ }
727
+ function capturedBlobHasFileBuffer(captured) {
728
+ return Buffer.isBuffer(captured.fileBuffer);
729
+ }
730
+ function capturedBlobIsStreaming(captured) {
731
+ return typeof captured.streamingLineReader === "function";
732
+ }
733
+ async function capturePathBackedBlob(source, hostId, filePath, captureRunId) {
734
+ const beforeStats = await stat(filePath);
735
+ const afterStats = await stat(filePath);
736
+ const fileIdentityStable = fileIdentityFromStats(beforeStats, afterStats);
737
+ const checksum = sha1(`path-backed:${afterStats.size}:${afterStats.mtimeMs}:${afterStats.ctimeMs}`);
738
+ return {
739
+ blob: {
740
+ id: stableId("blob", source.id, filePath, checksum),
741
+ source_id: source.id,
742
+ host_id: hostId,
743
+ origin_path: filePath,
744
+ checksum,
745
+ size_bytes: afterStats.size,
746
+ captured_at: nowIso(),
747
+ capture_run_id: captureRunId,
748
+ file_modified_at: afterStats.mtime.toISOString(),
749
+ file_changed_at: fileIdentityStable ? afterStats.ctime.toISOString() : undefined,
750
+ file_identity_stable: fileIdentityStable,
751
+ },
752
+ };
753
+ }
754
+ function isOpenClawCronRunFile(filePath) {
755
+ return filePath.replace(/\\/gu, "/").includes("/cron/runs/");
756
+ }
757
+ function resultReferencesTargetSession(source, result, sessionRefs) {
758
+ if (source.platform !== "openclaw" && source.platform !== "codex")
759
+ return false;
760
+ return result.fragments.some((fragment) => {
761
+ if (fragment.fragment_kind !== "session_relation")
762
+ return false;
763
+ const parentRef = fragment.payload.parent_uuid;
764
+ if (typeof parentRef !== "string" || parentRef.length === 0)
765
+ return false;
766
+ const canonicalParentRef = `sess:${source.platform}:${parentRef}`;
767
+ return sessionRefs.some((ref) => targetRefMatchesSession(ref, canonicalParentRef, parentRef));
768
+ });
769
+ }
770
+ function stripCanonicalSessionPrefix(ref, platform) {
771
+ const prefix = `sess:${platform}:`;
772
+ return ref.startsWith(prefix) ? ref.slice(prefix.length) : ref;
773
+ }
774
+ function isCanonicalSessionPrefix(ref) {
775
+ return /^sess:[^:]+:./u.test(ref);
776
+ }
777
+ function targetRefMatchesSession(ref, sessionId, sourceSessionId) {
778
+ if (!ref)
779
+ return false;
780
+ if (ref === sessionId || ref === sourceSessionId)
781
+ return true;
782
+ const sessionNative = sessionId.match(/^sess:[^:]+:(.+)$/u)?.[1];
783
+ if (sessionNative && ref === sessionNative)
784
+ return true;
785
+ if (isCanonicalSessionPrefix(ref) && sessionId.startsWith(ref))
786
+ return true;
787
+ if (!ref.startsWith("sess:") && (sessionNative?.startsWith(ref) || sourceSessionId?.startsWith(ref))) {
788
+ return true;
789
+ }
790
+ if (!isCanonicalSessionPrefix(ref) || !sessionNative)
791
+ return false;
792
+ const refPlatform = ref.match(/^sess:([^:]+):/u)?.[1];
793
+ const sessionPlatform = sessionId.match(/^sess:([^:]+):/u)?.[1];
794
+ const refNative = ref.match(/^sess:[^:]+:(.+)$/u)?.[1];
795
+ return Boolean(refNative &&
796
+ refPlatform === sessionPlatform &&
797
+ (sessionNative.startsWith(refNative) || sourceSessionId?.startsWith(refNative)));
798
+ }
799
+ function mergeAdapterBlobResult(sessionsById, adapterResult) {
800
+ mergeSessionBuildInput(sessionsById, {
801
+ draft: adapterResult.draft,
802
+ blobs: [...adapterResult.blobs],
803
+ records: [...adapterResult.records],
804
+ fragments: [...adapterResult.fragments],
805
+ atoms: [...adapterResult.atoms],
806
+ edges: [...adapterResult.edges],
807
+ loss_audits: [...adapterResult.loss_audits],
808
+ });
809
+ }
810
+ function mergeSessionBuildInput(sessionsById, sessionInput) {
811
+ const current = sessionsById.get(sessionInput.draft.id);
812
+ if (current) {
813
+ const currentHasTranscript = sessionInputHasCursorTranscript(current);
814
+ const currentHasComposer = sessionInputHasCursorComposer(current);
815
+ const incomingHasComposer = sessionInputHasCursorComposer(sessionInput);
816
+ current.blobs.push(...sessionInput.blobs);
817
+ current.records.push(...sessionInput.records);
818
+ current.fragments.push(...sessionInput.fragments);
819
+ current.atoms.push(...sessionInput.atoms);
820
+ current.edges.push(...sessionInput.edges);
821
+ current.loss_audits.push(...sessionInput.loss_audits);
822
+ const preferIncomingComposerMeta = current.draft.source_platform === "cursor" &&
823
+ incomingHasComposer &&
824
+ currentHasTranscript &&
825
+ !currentHasComposer;
826
+ if (preferIncomingComposerMeta) {
827
+ current.draft.title = sessionInput.draft.title ?? current.draft.title;
828
+ current.draft.canonical_title = sessionInput.draft.canonical_title ?? current.draft.canonical_title;
829
+ current.draft.working_directory = sessionInput.draft.working_directory ?? current.draft.working_directory;
830
+ current.draft.model = sessionInput.draft.model ?? current.draft.model;
831
+ }
832
+ else if (!current.draft.title && sessionInput.draft.title) {
833
+ current.draft.title = sessionInput.draft.title;
834
+ current.draft.canonical_title = sessionInput.draft.canonical_title;
835
+ }
836
+ else if (current.draft.title === sessionInput.draft.title) {
837
+ current.draft.canonical_title = current.draft.canonical_title ?? sessionInput.draft.canonical_title;
838
+ }
839
+ if (!preferIncomingComposerMeta) {
840
+ current.draft.working_directory = current.draft.working_directory ?? sessionInput.draft.working_directory;
841
+ current.draft.model = current.draft.model ?? sessionInput.draft.model;
842
+ }
843
+ current.draft.source_session_id = current.draft.source_session_id ?? sessionInput.draft.source_session_id;
844
+ current.draft.resume_command = current.draft.resume_command ?? sessionInput.draft.resume_command;
845
+ current.draft.resume_working_directory =
846
+ current.draft.resume_working_directory ?? sessionInput.draft.resume_working_directory;
847
+ current.draft.resume_command_confidence =
848
+ current.draft.resume_command_confidence ?? sessionInput.draft.resume_command_confidence;
849
+ current.draft.created_at = minIso(current.draft.created_at, sessionInput.draft.created_at);
850
+ current.draft.updated_at = maxIso(current.draft.updated_at, sessionInput.draft.updated_at);
851
+ suppressOverlappingCursorConversation(current);
852
+ return;
853
+ }
854
+ sessionsById.set(sessionInput.draft.id, {
855
+ draft: { ...sessionInput.draft },
856
+ blobs: [...sessionInput.blobs],
857
+ records: [...sessionInput.records],
858
+ fragments: [...sessionInput.fragments],
859
+ atoms: [...sessionInput.atoms],
860
+ edges: [...sessionInput.edges],
861
+ loss_audits: [...sessionInput.loss_audits],
862
+ });
863
+ }
864
+ function sessionInputHasCursorTranscript(sessionInput) {
865
+ return sessionInput.blobs.some((blob) => isCursorAgentTranscriptPath(blob.origin_path));
866
+ }
867
+ function sessionInputHasCursorComposer(sessionInput) {
868
+ return sessionInput.blobs.some((blob) => path.basename(blob.origin_path) === "state.vscdb");
869
+ }
870
+ function isCursorAgentTranscriptPath(originPath) {
871
+ const normalized = originPath.replace(/\\/g, "/");
872
+ return normalized.includes("/agent-transcripts/") && normalized.endsWith(".jsonl");
873
+ }
874
+ function suppressOverlappingCursorConversation(session) {
875
+ if (session.draft.source_platform !== "cursor") {
876
+ return;
877
+ }
878
+ collapseOverlappingCursorComposerConversations(session);
879
+ const transcriptBlobIds = new Set(session.blobs.filter((blob) => isCursorAgentTranscriptPath(blob.origin_path)).map((blob) => blob.id));
880
+ const composerBlobIds = new Set(session.blobs.filter((blob) => path.basename(blob.origin_path) === "state.vscdb").map((blob) => blob.id));
881
+ const storeBlobIds = new Set(session.blobs
882
+ .filter((blob) => {
883
+ const normalized = blob.origin_path.replace(/\\/g, "/");
884
+ return path.basename(blob.origin_path) === "store.db" && normalized.includes("/chats/");
885
+ })
886
+ .map((blob) => blob.id));
887
+ if (transcriptBlobIds.size > 0 && composerBlobIds.size > 0) {
888
+ const transcriptCount = cursorUserRecordCount(session, transcriptBlobIds);
889
+ const composerCount = cursorUserRecordCount(session, composerBlobIds);
890
+ const dropBlobIds = composerCount >= transcriptCount ? transcriptBlobIds : composerBlobIds;
891
+ dropCursorConversationRecords(session, dropBlobIds, { keepMeta: dropBlobIds === composerBlobIds });
892
+ applyCursorComposerClockToTranscript(session);
893
+ }
894
+ if (storeBlobIds.size > 0) {
895
+ const nonStoreBlobIds = new Set(session.blobs.filter((blob) => !storeBlobIds.has(blob.id)).map((blob) => blob.id));
896
+ const storeCount = cursorAuthoredUserRecordCount(session, storeBlobIds);
897
+ const otherCount = cursorAuthoredUserRecordCount(session, nonStoreBlobIds);
898
+ if (otherCount > 0 && otherCount >= storeCount) {
899
+ dropCursorConversationRecords(session, storeBlobIds, { keepMeta: true });
900
+ }
901
+ else if (storeCount > otherCount && otherCount > 0) {
902
+ dropCursorConversationRecords(session, nonStoreBlobIds, { keepMeta: true });
903
+ }
904
+ }
905
+ }
906
+ function collapseOverlappingCursorComposerConversations(session) {
907
+ const composerBlobs = session.blobs.filter((blob) => path.basename(blob.origin_path) === "state.vscdb");
908
+ if (composerBlobs.length < 2) {
909
+ return;
910
+ }
911
+ const winner = composerBlobs.reduce((currentWinner, blob) => {
912
+ const count = cursorUserRecordCount(session, new Set([blob.id]));
913
+ const winnerCount = cursorUserRecordCount(session, new Set([currentWinner.id]));
914
+ return count > winnerCount ? blob : currentWinner;
915
+ });
916
+ const dropBlobIds = new Set(composerBlobs.filter((blob) => blob.id !== winner.id).map((blob) => blob.id));
917
+ if (dropBlobIds.size === 0) {
918
+ return;
919
+ }
920
+ dropCursorConversationRecords(session, dropBlobIds, { keepMeta: true });
921
+ }
922
+ function dropCursorConversationRecords(session, dropBlobIds, options) {
923
+ session.records = session.records.filter((record) => {
924
+ if (!dropBlobIds.has(record.blob_id)) {
925
+ return true;
926
+ }
927
+ return options.keepMeta && record.record_path_or_offset === "meta";
928
+ });
929
+ const keptRecordIds = new Set(session.records.map((record) => record.id));
930
+ session.fragments = session.fragments.filter((fragment) => keptRecordIds.has(fragment.record_id));
931
+ const keptFragmentIds = new Set(session.fragments.map((fragment) => fragment.id));
932
+ session.atoms = session.atoms.filter((atom) => atom.fragment_refs.every((fragmentId) => keptFragmentIds.has(fragmentId)));
933
+ const keptAtomIds = new Set(session.atoms.map((atom) => atom.id));
934
+ session.edges = session.edges.filter((edge) => keptAtomIds.has(edge.from_atom_id) && keptAtomIds.has(edge.to_atom_id));
935
+ recomputeSessionDraftTimesFromRecords(session);
936
+ }
937
+ function applyCursorComposerClockToTranscript(session) {
938
+ const composerClock = readCursorComposerClock(session);
939
+ if (!composerClock?.updatedAt && !composerClock?.createdAt) {
940
+ return;
941
+ }
942
+ const transcriptRecords = session.records.filter((record) => {
943
+ if (record.record_path_or_offset === "meta") {
944
+ return false;
945
+ }
946
+ const blob = session.blobs.find((candidate) => candidate.id === record.blob_id);
947
+ return Boolean(blob && isCursorAgentTranscriptPath(blob.origin_path));
948
+ });
949
+ if (transcriptRecords.length === 0) {
950
+ return;
951
+ }
952
+ if (transcriptRecords.some((record) => rawRecordHasExplicitTimestamp(record))) {
953
+ return;
954
+ }
955
+ const createdAt = composerClock.createdAt ?? composerClock.updatedAt;
956
+ const updatedAt = composerClock.updatedAt ?? composerClock.createdAt;
957
+ if (!createdAt || !updatedAt) {
958
+ return;
959
+ }
960
+ assignObservedTimes(transcriptRecords, createdAt, updatedAt);
961
+ const restampedByRecordId = new Map(transcriptRecords.map((record) => [record.id, record.observed_at]));
962
+ for (const fragment of session.fragments) {
963
+ const observedAt = restampedByRecordId.get(fragment.record_id);
964
+ if (observedAt) {
965
+ fragment.time_key = observedAt;
966
+ }
967
+ }
968
+ for (const atom of session.atoms) {
969
+ const fragment = session.fragments.find((candidate) => atom.fragment_refs.includes(candidate.id));
970
+ const observedAt = fragment ? restampedByRecordId.get(fragment.record_id) : undefined;
971
+ if (observedAt) {
972
+ atom.time_key = observedAt;
973
+ }
974
+ }
975
+ recomputeSessionDraftTimesFromRecords(session);
976
+ }
977
+ function readCursorComposerClock(session) {
978
+ for (const record of session.records) {
979
+ if (record.record_path_or_offset !== "meta") {
980
+ continue;
981
+ }
982
+ const blob = session.blobs.find((candidate) => candidate.id === record.blob_id);
983
+ if (!blob || path.basename(blob.origin_path) !== "state.vscdb") {
984
+ continue;
985
+ }
986
+ const parsed = safeJsonParse(record.raw_json);
987
+ if (!isObject(parsed)) {
988
+ continue;
989
+ }
990
+ const createdAt = coerceIso(parsed.createdAt) ??
991
+ epochMillisToIso(asNumber(parsed.createdAt));
992
+ const updatedAt = coerceIso(parsed.updatedAt) ??
993
+ coerceIso(parsed.lastUpdatedAt) ??
994
+ epochMillisToIso(asNumber(parsed.lastUpdatedAt)) ??
995
+ epochMillisToIso(asNumber(parsed.updatedAt));
996
+ if (createdAt || updatedAt) {
997
+ return { createdAt, updatedAt };
998
+ }
999
+ }
1000
+ return undefined;
1001
+ }
1002
+ function rawRecordHasExplicitTimestamp(record) {
1003
+ const parsed = safeJsonParse(record.raw_json);
1004
+ if (!isObject(parsed)) {
1005
+ return false;
1006
+ }
1007
+ return Boolean(coerceIso(parsed.timestamp) ??
1008
+ coerceIso(parsed.createdAt) ??
1009
+ coerceIso(parsed.updatedAt) ??
1010
+ epochMillisToIso(asNumber(parsed.timestamp)) ??
1011
+ epochMillisToIso(asNumber(parsed.createdAt)));
1012
+ }
1013
+ function assignObservedTimes(records, createdAt, updatedAt) {
1014
+ if (records.length === 1) {
1015
+ records[0].observed_at = updatedAt;
1016
+ return;
1017
+ }
1018
+ const start = Date.parse(createdAt);
1019
+ const end = Date.parse(updatedAt);
1020
+ if (!Number.isFinite(start) || !Number.isFinite(end) || records.length === 0) {
1021
+ for (const record of records) {
1022
+ record.observed_at = updatedAt;
1023
+ }
1024
+ return;
1025
+ }
1026
+ const span = Math.max(end - start, records.length - 1);
1027
+ records.forEach((record, index) => {
1028
+ const ratio = index / (records.length - 1);
1029
+ record.observed_at = new Date(start + Math.round(span * ratio)).toISOString();
1030
+ });
1031
+ }
1032
+ function recomputeSessionDraftTimesFromRecords(session) {
1033
+ const observedAt = session.records
1034
+ .map((record) => record.observed_at)
1035
+ .filter((value) => Boolean(value));
1036
+ session.draft.created_at = observedAt.reduce((current, value) => minIso(current, value), undefined);
1037
+ session.draft.updated_at = observedAt.reduce((current, value) => maxIso(current, value), undefined);
1038
+ }
1039
+ function cursorUserRecordCount(session, blobIds) {
1040
+ return session.records.filter((record) => {
1041
+ if (!blobIds.has(record.blob_id) || record.record_path_or_offset === "meta") {
1042
+ return false;
1043
+ }
1044
+ const parsed = safeJsonParse(record.raw_json);
1045
+ return isObject(parsed) && extractGenericRole(parsed) === "user";
1046
+ }).length;
1047
+ }
1048
+ function cursorAuthoredUserRecordCount(session, blobIds) {
1049
+ return session.records.filter((record) => {
1050
+ if (!blobIds.has(record.blob_id) || record.record_path_or_offset === "meta") {
1051
+ return false;
1052
+ }
1053
+ const parsed = safeJsonParse(record.raw_json);
1054
+ if (!isObject(parsed) || extractGenericRole(parsed) !== "user") {
1055
+ return false;
1056
+ }
1057
+ const message = isObject(parsed.message) ? parsed.message : parsed;
1058
+ const text = extractGenericContentItems(message)
1059
+ .map((item) => asString(item.text) ?? asString(item.input_text) ?? asString(item.output_text) ?? "")
1060
+ .filter(Boolean)
1061
+ .join("\n");
1062
+ return splitUserText(text, { platform: "cursor" }).some((chunk) => chunk.originKind === "user_authored");
1063
+ }).length;
1064
+ }
1065
+ function mergePreviousFileEntry(sessionsById, orphanBlobs, sourceLossAudits, previousEntry, replacementTailBlob) {
1066
+ const blobReplacements = replacementTailBlob ? new Map([[replacementTailBlob.id, replacementTailBlob]]) : undefined;
1067
+ for (const sessionInput of previousEntry.sessionInputs) {
1068
+ mergeSessionBuildInput(sessionsById, blobReplacements ? replaceSessionInputBlobs(sessionInput, blobReplacements) : sessionInput);
1069
+ }
1070
+ orphanBlobs.push(...previousEntry.orphanBlobs.map((blob) => replaceBlob(blob, blobReplacements)));
1071
+ sourceLossAudits.push(...previousEntry.lossAudits);
1072
+ }
1073
+ function replaceSessionInputBlobs(sessionInput, replacements) {
1074
+ return {
1075
+ ...sessionInput,
1076
+ blobs: sessionInput.blobs.map((blob) => replaceBlob(blob, replacements)),
1077
+ };
1078
+ }
1079
+ function replaceBlob(blob, replacements) {
1080
+ const replacement = replacements?.get(blob.id);
1081
+ if (!replacement) {
1082
+ return blob;
1083
+ }
1084
+ return {
1085
+ ...blob,
1086
+ size_bytes: replacement.size_bytes,
1087
+ captured_at: replacement.captured_at,
1088
+ capture_run_id: replacement.capture_run_id,
1089
+ file_modified_at: replacement.file_modified_at,
1090
+ file_changed_at: replacement.file_changed_at,
1091
+ file_identity_stable: replacement.file_identity_stable,
1092
+ };
1093
+ }
1094
+ function backfillReusableSessionResumeFields(platform, filePath, draft) {
1095
+ const sourceSessionId = draft.source_session_id ??
1096
+ extractSourceSessionIdFromCanonicalSessionId(platform, draft.id);
1097
+ const resume = isOrdinaryResumeEligibleSourceFile(platform, filePath, draft)
1098
+ ? buildSourceResumeCommand({
1099
+ platform,
1100
+ sourceSessionId,
1101
+ workingDirectory: draft.working_directory,
1102
+ })
1103
+ : undefined;
1104
+ return {
1105
+ ...draft,
1106
+ source_session_id: sourceSessionId,
1107
+ resume_command: draft.resume_command ?? resume?.command,
1108
+ resume_working_directory: draft.resume_working_directory ?? resume?.working_directory,
1109
+ resume_command_confidence: draft.resume_command_confidence ?? resume?.confidence,
1110
+ };
1111
+ }
1112
+ function hydrateDelegatedDraftFromFragments(platform, draft, fragments) {
1113
+ if (platform !== "codex")
1114
+ return draft;
1115
+ const sourceSessionId = draft.source_session_id ?? extractSourceSessionIdFromCanonicalSessionId(platform, draft.id);
1116
+ const childMeta = fragments.find((fragment) => fragment.fragment_kind === "session_meta" &&
1117
+ fragment.payload.id === sourceSessionId);
1118
+ const source = isObject(childMeta?.payload.source) ? childMeta.payload.source : undefined;
1119
+ const subagent = isObject(source?.subagent) ? source.subagent : undefined;
1120
+ const threadSpawn = isObject(subagent?.thread_spawn) ? subagent.thread_spawn : undefined;
1121
+ const isSubagent = Boolean(threadSpawn) ||
1122
+ Boolean(subagent) ||
1123
+ asString(childMeta?.payload.thread_source) === "subagent";
1124
+ if (!isSubagent)
1125
+ return draft;
1126
+ const explicitParentSessionId = asString(threadSpawn?.parent_thread_id) ??
1127
+ asString(childMeta?.payload.parent_thread_id);
1128
+ const agentNickname = asString(threadSpawn?.agent_nickname) ??
1129
+ asString(childMeta?.payload.agent_nickname) ??
1130
+ asString(subagent?.other);
1131
+ const agentPath = asString(threadSpawn?.agent_path) ?? asString(childMeta?.payload.agent_path);
1132
+ const agentKey = agentPath ?? agentNickname;
1133
+ const relation = explicitParentSessionId
1134
+ ? fragments.find((fragment) => fragment.fragment_kind === "session_relation" &&
1135
+ fragment.payload.parent_uuid === explicitParentSessionId &&
1136
+ fragment.payload.child_session_id === sourceSessionId)
1137
+ : undefined;
1138
+ if (!explicitParentSessionId && !agentKey)
1139
+ return draft;
1140
+ return {
1141
+ ...draft,
1142
+ delegated_parent_session_id: explicitParentSessionId ?? draft.delegated_parent_session_id,
1143
+ delegated_history_start_ordinal: typeof childMeta?.payload.subagent_history_start_ordinal === "number"
1144
+ ? childMeta.payload.subagent_history_start_ordinal
1145
+ : draft.delegated_history_start_ordinal,
1146
+ delegated_agent_key: (typeof relation?.payload.agent_id === "string" ? relation.payload.agent_id : undefined) ??
1147
+ agentKey ??
1148
+ draft.delegated_agent_key,
1149
+ title: draft.title ?? agentNickname,
1150
+ resume_command: undefined,
1151
+ resume_working_directory: undefined,
1152
+ resume_command_confidence: undefined,
1153
+ };
1154
+ }
1155
+ function buildPreviousSourceIndex(previousPayload, sourceFormatProfile) {
1156
+ if (!previousPayload || !isIncrementalJsonlPlatform(previousPayload.source.platform)) {
1157
+ return undefined;
1158
+ }
1159
+ if (!previousPayloadMatchesProfile(previousPayload, sourceFormatProfile)) {
1160
+ return undefined;
1161
+ }
1162
+ const sessionsById = new Map(previousPayload.sessions.map((session) => [session.id, session]));
1163
+ const recordsByBlobId = groupBy(previousPayload.records, (record) => record.blob_id);
1164
+ const fragmentsByRecordId = groupBy(previousPayload.fragments, (fragment) => fragment.record_id);
1165
+ const atomsByFragmentId = new Map();
1166
+ for (const atom of previousPayload.atoms) {
1167
+ for (const fragmentRef of atom.fragment_refs) {
1168
+ pushGrouped(atomsByFragmentId, fragmentRef, atom);
1169
+ }
1170
+ }
1171
+ const edgesByAtomId = new Map();
1172
+ for (const edge of previousPayload.edges) {
1173
+ pushGrouped(edgesByAtomId, edge.from_atom_id, edge);
1174
+ pushGrouped(edgesByAtomId, edge.to_atom_id, edge);
1175
+ }
1176
+ const lossAuditsByBlobRef = groupPresent(previousPayload.loss_audits, (audit) => audit.blob_ref);
1177
+ const lossAuditsByRecordRef = groupPresent(previousPayload.loss_audits, (audit) => audit.record_ref);
1178
+ const lossAuditsByFragmentRef = groupPresent(previousPayload.loss_audits, (audit) => audit.fragment_ref);
1179
+ const lossAuditsByAtomRef = groupPresent(previousPayload.loss_audits, (audit) => audit.atom_ref);
1180
+ const blobsByOriginPath = groupBy(previousPayload.blobs, (blob) => path.normalize(blob.origin_path));
1181
+ const byOriginPath = new Map();
1182
+ for (const [originPath, blobs] of blobsByOriginPath) {
1183
+ const fileRecords = blobs.flatMap((blob) => recordsByBlobId.get(blob.id) ?? []);
1184
+ const fileRecordIds = new Set(fileRecords.map((record) => record.id));
1185
+ const fileFragments = fileRecords.flatMap((record) => fragmentsByRecordId.get(record.id) ?? []);
1186
+ const fileFragmentIds = new Set(fileFragments.map((fragment) => fragment.id));
1187
+ const fileAtoms = dedupeById(fileFragments.flatMap((fragment) => atomsByFragmentId.get(fragment.id) ?? []));
1188
+ const fileAtomIds = new Set(fileAtoms.map((atom) => atom.id));
1189
+ const fileEdges = dedupeById(fileAtoms.flatMap((atom) => edgesByAtomId.get(atom.id) ?? []))
1190
+ .filter((edge) => fileAtomIds.has(edge.from_atom_id) && fileAtomIds.has(edge.to_atom_id));
1191
+ const fileLossAudits = dedupeById([
1192
+ ...blobs.flatMap((blob) => lossAuditsByBlobRef.get(blob.id) ?? []),
1193
+ ...fileRecords.flatMap((record) => lossAuditsByRecordRef.get(record.id) ?? []),
1194
+ ...fileFragments.flatMap((fragment) => lossAuditsByFragmentRef.get(fragment.id) ?? []),
1195
+ ...fileAtoms.flatMap((atom) => lossAuditsByAtomRef.get(atom.id) ?? []),
1196
+ ]);
1197
+ const sessionRefs = new Set(fileRecords.map((record) => record.session_ref));
1198
+ const sessionInputs = [];
1199
+ const sessionLossAuditIds = new Set();
1200
+ for (const sessionRef of sessionRefs) {
1201
+ const session = sessionsById.get(sessionRef);
1202
+ const records = fileRecords.filter((record) => record.session_ref === sessionRef);
1203
+ const recordIds = new Set(records.map((record) => record.id));
1204
+ const fragments = fileFragments.filter((fragment) => recordIds.has(fragment.record_id));
1205
+ const fragmentIds = new Set(fragments.map((fragment) => fragment.id));
1206
+ const atoms = fileAtoms.filter((atom) => atom.fragment_refs.some((fragmentRef) => fragmentIds.has(fragmentRef)));
1207
+ const atomIds = new Set(atoms.map((atom) => atom.id));
1208
+ const edges = fileEdges.filter((edge) => atomIds.has(edge.from_atom_id) || atomIds.has(edge.to_atom_id));
1209
+ const usedBlobIds = new Set(records.map((record) => record.blob_id));
1210
+ const sessionBlobs = blobs.filter((blob) => usedBlobIds.has(blob.id));
1211
+ const sessionLossAudits = dedupeById(fileLossAudits.filter((audit) => audit.session_ref === sessionRef ||
1212
+ (audit.record_ref !== undefined && recordIds.has(audit.record_ref)) ||
1213
+ (audit.fragment_ref !== undefined && fragmentIds.has(audit.fragment_ref)) ||
1214
+ (audit.atom_ref !== undefined && atomIds.has(audit.atom_ref)) ||
1215
+ (audit.blob_ref !== undefined && usedBlobIds.has(audit.blob_ref))));
1216
+ for (const audit of sessionLossAudits) {
1217
+ sessionLossAuditIds.add(audit.id);
1218
+ }
1219
+ const draft = backfillReusableSessionResumeFields(previousPayload.source.platform, originPath, hydrateDelegatedDraftFromFragments(previousPayload.source.platform, {
1220
+ id: sessionRef,
1221
+ source_id: previousPayload.source.id,
1222
+ source_platform: previousPayload.source.platform,
1223
+ host_id: session?.host_id ?? previousPayload.source.host_id,
1224
+ title: session?.title,
1225
+ canonical_title: session?.canonical_title,
1226
+ created_at: minAtomTime(atoms) ?? session?.created_at,
1227
+ updated_at: maxAtomTime(atoms) ?? session?.updated_at,
1228
+ model: session?.model,
1229
+ working_directory: session?.working_directory,
1230
+ source_native_project_ref: session?.source_native_project_ref,
1231
+ source_session_id: session?.source_session_id,
1232
+ resume_command: session?.resume_command,
1233
+ resume_working_directory: session?.resume_working_directory,
1234
+ resume_command_confidence: session?.resume_command_confidence,
1235
+ last_cumulative_token_usage: findLastCumulativeTokenUsage(fragments),
1236
+ cumulative_token_usage_by_baseline: findCumulativeTokenUsageByBaseline(fragments),
1237
+ }, fragments));
1238
+ sessionInputs.push({
1239
+ draft,
1240
+ blobs: sessionBlobs,
1241
+ records,
1242
+ fragments,
1243
+ atoms,
1244
+ edges,
1245
+ loss_audits: sessionLossAudits,
1246
+ });
1247
+ }
1248
+ const recordBlobIds = new Set(fileRecords.map((record) => record.blob_id));
1249
+ byOriginPath.set(originPath, {
1250
+ originPath,
1251
+ blobs,
1252
+ tailBlob: selectTailBlob(blobs),
1253
+ sessionInputs,
1254
+ orphanBlobs: blobs.filter((blob) => !recordBlobIds.has(blob.id)),
1255
+ lossAudits: dedupeById(fileLossAudits.filter((audit) => !sessionLossAuditIds.has(audit.id))),
1256
+ });
1257
+ }
1258
+ return {
1259
+ byOriginPath,
1260
+ metadataOnly: previousPayload.records.length === 0 &&
1261
+ previousPayload.fragments.length === 0 &&
1262
+ previousPayload.atoms.length === 0 &&
1263
+ previousPayload.edges.length === 0 &&
1264
+ previousPayload.sessions.length === 0,
1265
+ };
1266
+ }
1267
+ function previousPayloadMatchesProfile(payload, sourceFormatProfile) {
1268
+ return payload.stage_runs.some((stageRun) => stageRun.parser_version === sourceFormatProfile.parser_version &&
1269
+ stageRun.source_format_profile_ids?.includes(sourceFormatProfile.id));
1270
+ }
1271
+ function canReuseCapturedBlob(previousEntry, capturedBlob) {
1272
+ return previousEntry.tailBlob?.size_bytes === capturedBlob.size_bytes &&
1273
+ previousEntry.tailBlob.checksum === capturedBlob.checksum &&
1274
+ (previousEntry.tailBlob?.content_max_timestamp === undefined ||
1275
+ previousEntry.tailBlob.content_max_timestamp === capturedBlob.content_max_timestamp);
1276
+ }
1277
+ function canReuseBlobFromStats(previousEntry, stats) {
1278
+ return previousEntry.tailBlob?.size_bytes === stats.size &&
1279
+ previousEntry.tailBlob.file_modified_at === stats.mtime.toISOString() &&
1280
+ previousEntry.tailBlob.file_identity_stable === true &&
1281
+ previousEntry.tailBlob.file_changed_at !== undefined &&
1282
+ previousEntry.tailBlob.file_changed_at === stats.ctime.toISOString();
1283
+ }
1284
+ async function processAppendedJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob, previousEntry) {
1285
+ if (!isIncrementalJsonlPlatform(source.platform) || previousEntry.sessionInputs.length !== 1 || !previousEntry.tailBlob) {
1286
+ return undefined;
1287
+ }
1288
+ const previousTail = previousEntry.tailBlob;
1289
+ if (capturedBlob.blob.size_bytes <= previousTail.size_bytes ||
1290
+ capturedBlob.blob.file_modified_at === previousTail.file_modified_at ||
1291
+ (capturedBlob.blob.content_max_timestamp !== undefined &&
1292
+ capturedBlob.blob.content_max_timestamp === previousTail.content_max_timestamp)) {
1293
+ return undefined;
1294
+ }
1295
+ // Stage 3: streaming variant uses hashPrefix (incremental, no allocation)
1296
+ // + readSuffix instead of materializing the whole file. The CapturedBlobInput
1297
+ // path keeps the existing fileBuffer.subarray behavior.
1298
+ const isStreaming = capturedBlobIsStreaming(capturedBlob);
1299
+ let prefixSha1;
1300
+ let prefixLastByte;
1301
+ let appendedBuffer;
1302
+ if (isStreaming) {
1303
+ const { sha1: hashed, lastByte } = await capturedBlob.hashPrefix(previousTail.size_bytes);
1304
+ prefixSha1 = hashed;
1305
+ prefixLastByte = lastByte;
1306
+ appendedBuffer = await capturedBlob.readSuffix(previousTail.size_bytes);
1307
+ }
1308
+ else if (capturedBlobHasFileBuffer(capturedBlob)) {
1309
+ const previousPrefix = capturedBlob.fileBuffer.subarray(0, previousTail.size_bytes);
1310
+ prefixSha1 = sha1(previousPrefix);
1311
+ prefixLastByte = previousPrefix.length > 0 ? previousPrefix[previousPrefix.length - 1] : null;
1312
+ appendedBuffer = capturedBlob.fileBuffer.subarray(previousTail.size_bytes);
1313
+ }
1314
+ else {
1315
+ return undefined;
1316
+ }
1317
+ if (prefixSha1 !== previousTail.checksum) {
1318
+ return undefined;
1319
+ }
1320
+ if (!isJsonlAppendBoundaryStreaming(prefixLastByte, appendedBuffer)) {
1321
+ return undefined;
1322
+ }
1323
+ const previousInput = previousEntry.sessionInputs[0];
1324
+ if (hasPreviousJsonParseFailure(previousInput)) {
1325
+ return undefined;
1326
+ }
1327
+ const sessionId = previousInput.draft.id;
1328
+ const baseOrdinal = previousInput.records.reduce((max, record) => Math.max(max, record.ordinal), -1) + 1;
1329
+ const appendedRecords = collectJsonlRecordsFromText({
1330
+ text: appendedBuffer.toString("utf8"),
1331
+ sourceId: source.id,
1332
+ sessionId,
1333
+ blobId: capturedBlob.blob.id,
1334
+ baseOrdinal,
1335
+ });
1336
+ if (appendedRecords.length === 0) {
1337
+ return undefined;
1338
+ }
1339
+ const context = {
1340
+ source,
1341
+ hostId: capturedBlob.blob.host_id,
1342
+ filePath,
1343
+ profileId: sourceFormatProfile.id,
1344
+ sessionId,
1345
+ captureRunId: capturedBlob.blob.capture_run_id,
1346
+ };
1347
+ const draft = {
1348
+ ...previousInput.draft,
1349
+ updated_at: undefined,
1350
+ last_cumulative_token_usage: findLastCumulativeTokenUsage(previousInput.fragments),
1351
+ cumulative_token_usage_by_baseline: findCumulativeTokenUsageByBaseline(previousInput.fragments),
1352
+ source_session_id: previousInput.draft.source_session_id ??
1353
+ extractSourceSessionIdFromCanonicalSessionId(source.platform, sessionId),
1354
+ };
1355
+ Object.assign(draft, hydrateDelegatedDraftFromFragments(source.platform, draft, previousInput.fragments));
1356
+ const appendedFragments = [];
1357
+ const appendedLossAudits = [];
1358
+ for (const record of appendedRecords) {
1359
+ const parsed = parseRecord(context, record, draft);
1360
+ appendedFragments.push(...parsed.fragments);
1361
+ appendedLossAudits.push(...parsed.lossAudits);
1362
+ }
1363
+ const fragments = [...previousInput.fragments, ...appendedFragments];
1364
+ const atomized = atomizeFragments(source.id, sessionId, sourceFormatProfile.id, fragments);
1365
+ hydrateDraftFromAtoms(draft, atomized.atoms, capturedBlob.blob.file_modified_at);
1366
+ const backfilledDraft = backfillReusableSessionResumeFields(source.platform, filePath, draft);
1367
+ return [{
1368
+ draft: backfilledDraft,
1369
+ blobs: [...previousInput.blobs, capturedBlob.blob],
1370
+ records: [...previousInput.records, ...appendedRecords],
1371
+ fragments,
1372
+ atoms: atomized.atoms,
1373
+ edges: atomized.edges,
1374
+ loss_audits: [...previousInput.loss_audits, ...appendedLossAudits],
1375
+ }];
1376
+ }
1377
+ function isJsonlAppendBoundary(previousPrefix, appendedBuffer) {
1378
+ if (previousPrefix.length === 0 || appendedBuffer.length === 0) {
1379
+ return true;
1380
+ }
1381
+ const previousLast = previousPrefix[previousPrefix.length - 1];
1382
+ const appendedFirst = appendedBuffer[0];
1383
+ return previousLast === 10 || previousLast === 13 || appendedFirst === 10 || appendedFirst === 13;
1384
+ }
1385
+ // Stage 3: streaming variant of isJsonlAppendBoundary. Takes the last byte of
1386
+ // the prefix (returned by hashPrefix) plus the appended buffer; same newline
1387
+ // semantics. null prefixLastByte covers the (theoretical) empty-prefix case.
1388
+ function isJsonlAppendBoundaryStreaming(prefixLastByte, appendedBuffer) {
1389
+ if (prefixLastByte === null || appendedBuffer.length === 0) {
1390
+ return true;
1391
+ }
1392
+ const appendedFirst = appendedBuffer[0];
1393
+ return prefixLastByte === 10 || prefixLastByte === 13 || appendedFirst === 10 || appendedFirst === 13;
1394
+ }
1395
+ function collectJsonlRecordsFromText(input) {
1396
+ const records = [];
1397
+ let start = 0;
1398
+ let ordinal = input.baseOrdinal;
1399
+ for (let index = 0; index <= input.text.length; index += 1) {
1400
+ const isEnd = index === input.text.length;
1401
+ const charCode = isEnd ? -1 : input.text.charCodeAt(index);
1402
+ if (!isEnd && charCode !== 10 && charCode !== 13) {
1403
+ continue;
1404
+ }
1405
+ const line = input.text.slice(start, index).trim();
1406
+ if (line) {
1407
+ records.push({
1408
+ id: stableId("record", input.sourceId, input.sessionId, input.blobId, String(ordinal), `${ordinal}`),
1409
+ source_id: input.sourceId,
1410
+ blob_id: input.blobId,
1411
+ session_ref: input.sessionId,
1412
+ ordinal,
1413
+ record_path_or_offset: `${ordinal}`,
1414
+ observed_at: nowIso(),
1415
+ parseable: true,
1416
+ raw_json: line,
1417
+ });
1418
+ ordinal += 1;
1419
+ }
1420
+ if (charCode === 13 && index + 1 < input.text.length && input.text.charCodeAt(index + 1) === 10) {
1421
+ index += 1;
1422
+ }
1423
+ start = index + 1;
1424
+ }
1425
+ return records;
1426
+ }
1427
+ function hasPreviousJsonParseFailure(previousInput) {
1428
+ return previousInput.loss_audits.some((audit) => audit.diagnostic_code === "record_json_parse_failed");
1429
+ }
1430
+ function minAtomTime(atoms) {
1431
+ return atoms.reduce((current, atom) => minIso(current, atom.time_key), undefined);
1432
+ }
1433
+ function maxAtomTime(atoms) {
1434
+ return atoms.reduce((current, atom) => maxIso(current, atom.time_key), undefined);
1435
+ }
1436
+ function findLastCumulativeTokenUsage(fragments) {
1437
+ for (let index = fragments.length - 1; index >= 0; index -= 1) {
1438
+ const usage = fragments[index]?.payload.cumulative_token_usage;
1439
+ if (isObject(usage)) {
1440
+ return extractTokenUsage(usage);
1441
+ }
1442
+ }
1443
+ return undefined;
1444
+ }
1445
+ function findCumulativeTokenUsageByBaseline(fragments) {
1446
+ let checkpoints;
1447
+ for (const fragment of fragments) {
1448
+ const cumulativeValue = fragment.payload.cumulative_token_usage;
1449
+ if (!isObject(cumulativeValue))
1450
+ continue;
1451
+ const cumulative = extractTokenUsage(cumulativeValue);
1452
+ const checkpoint = extractTokenUsage(fragment.payload.token_usage);
1453
+ const baselineKey = asString(fragment.payload.cumulative_token_usage_baseline_key) ??
1454
+ buildTokenUsageCheckpointBaselineKey(cumulative, checkpoint);
1455
+ if (!baselineKey || !checkpoint)
1456
+ continue;
1457
+ checkpoints ??= Object.create(null);
1458
+ checkpoints[baselineKey] = mergeMaxTokenUsageMetrics(checkpoints[baselineKey], checkpoint);
1459
+ }
1460
+ return checkpoints;
1461
+ }
1462
+ function groupBy(items, keyFor) {
1463
+ const grouped = new Map();
1464
+ for (const item of items) {
1465
+ pushGrouped(grouped, keyFor(item), item);
1466
+ }
1467
+ return grouped;
1468
+ }
1469
+ function groupPresent(items, keyFor) {
1470
+ const grouped = new Map();
1471
+ for (const item of items) {
1472
+ const key = keyFor(item);
1473
+ if (key !== undefined) {
1474
+ pushGrouped(grouped, key, item);
1475
+ }
1476
+ }
1477
+ return grouped;
1478
+ }
1479
+ function pushGrouped(grouped, key, item) {
1480
+ const group = grouped.get(key) ?? [];
1481
+ group.push(item);
1482
+ grouped.set(key, group);
1483
+ }
1484
+ function parseChangedSinceMs(value) {
1485
+ if (!value) {
1486
+ return undefined;
1487
+ }
1488
+ const relative = value.trim().match(/^(\d+)(m|h|d|w)$/iu);
1489
+ if (relative) {
1490
+ const amount = Number(relative[1]);
1491
+ const unit = relative[2].toLowerCase();
1492
+ const multiplier = unit === "m" ? 60 * 1000 :
1493
+ unit === "h" ? 60 * 60 * 1000 :
1494
+ unit === "d" ? 24 * 60 * 60 * 1000 :
1495
+ 7 * 24 * 60 * 60 * 1000;
1496
+ return Date.now() - amount * multiplier;
1497
+ }
1498
+ const parsed = Date.parse(value);
1499
+ return Number.isNaN(parsed) ? undefined : parsed;
1500
+ }
1501
+ async function processCollectedSessions(sessionsById, orphanBlobs, sourceLossAudits, options) {
1502
+ const blobs = [];
1503
+ const records = [];
1504
+ const fragments = [];
1505
+ const atoms = [];
1506
+ const edges = [];
1507
+ const candidates = [];
1508
+ const sessions = [];
1509
+ const turns = [];
1510
+ const contexts = [];
1511
+ const askUserQuestionTurns = [];
1512
+ const lossAudits = [];
1513
+ const claudeInputs = [...sessionsById.values()].filter((sessionInput) => sessionInput.draft.source_platform === "claude_code");
1514
+ if (claudeInputs.length > 0) {
1515
+ const removedFragmentIds = dedupeClaudeCodeTokenUsageFragments(claudeInputs.flatMap((sessionInput) => sessionInput.fragments));
1516
+ if (removedFragmentIds.size > 0) {
1517
+ for (const sessionInput of claudeInputs) {
1518
+ sessionInput.fragments = sessionInput.fragments.filter((fragment) => !removedFragmentIds.has(fragment.id));
1519
+ const removedAtomIds = new Set(sessionInput.atoms
1520
+ .filter((atom) => atom.fragment_refs.some((fragmentId) => removedFragmentIds.has(fragmentId)))
1521
+ .map((atom) => atom.id));
1522
+ sessionInput.atoms = sessionInput.atoms.filter((atom) => !removedAtomIds.has(atom.id));
1523
+ sessionInput.edges = sessionInput.edges.filter((edge) => !removedAtomIds.has(edge.from_atom_id) && !removedAtomIds.has(edge.to_atom_id));
1524
+ }
1525
+ }
1526
+ }
1527
+ for (const sessionInput of sessionsById.values()) {
1528
+ sessionInput.atoms.sort(compareTimeThenSeq);
1529
+ if (sessionInput.draft.source_platform === "antigravity") {
1530
+ sessionInput.atoms = collapseAntigravityUserTurnAtoms(sessionInput.atoms);
1531
+ }
1532
+ const gitProjectEvidence = options.safeMode
1533
+ ? undefined
1534
+ : await readGitProjectEvidence(sessionInput.draft.working_directory);
1535
+ const sessionProjectCandidates = buildProjectObservationCandidates(sessionInput.draft, sessionInput.atoms, gitProjectEvidence);
1536
+ const submissionResult = buildSubmissionGroups(sessionInput.draft, sessionInput.atoms, sessionInput.edges);
1537
+ const turnResult = buildTurnsAndContext(sessionInput.draft, sessionInput.fragments, sessionInput.records, sessionInput.blobs, sessionInput.atoms, submissionResult.groups, submissionResult.edges);
1538
+ const suppressEmptySession = sessionInput.draft.source_platform === "codebuddy" &&
1539
+ turnResult.turns.length === 0 &&
1540
+ sessionInput.atoms.length === 0;
1541
+ blobs.push(...sessionInput.blobs);
1542
+ records.push(...sessionInput.records);
1543
+ fragments.push(...sessionInput.fragments);
1544
+ atoms.push(...sessionInput.atoms);
1545
+ edges.push(...sessionInput.edges, ...submissionResult.edges);
1546
+ if (!suppressEmptySession) {
1547
+ candidates.push(...sessionProjectCandidates, ...submissionResult.groups, ...turnResult.turnCandidates, ...turnResult.contextCandidates);
1548
+ sessions.push(turnResult.session);
1549
+ turns.push(...turnResult.turns);
1550
+ contexts.push(...turnResult.contexts);
1551
+ askUserQuestionTurns.push(...buildAskUserQuestionTurns(sessionInput.draft, sessionInput.atoms, [...sessionInput.edges, ...submissionResult.edges]));
1552
+ }
1553
+ lossAudits.push(...sessionInput.loss_audits);
1554
+ }
1555
+ blobs.push(...orphanBlobs);
1556
+ lossAudits.push(...sourceLossAudits);
1557
+ return {
1558
+ blobs,
1559
+ records,
1560
+ fragments,
1561
+ atoms,
1562
+ edges,
1563
+ candidates,
1564
+ sessions,
1565
+ turns,
1566
+ contexts,
1567
+ askUserQuestionTurns,
1568
+ lossAudits,
1569
+ };
1570
+ }
1571
+ function emitProbeProgress(options, source, event) {
1572
+ options.on_progress?.({
1573
+ source_id: source.id,
1574
+ slot_id: source.slot_id,
1575
+ platform: source.platform,
1576
+ display_name: source.display_name,
1577
+ ...event,
1578
+ });
1579
+ }
1580
+ async function getFileSize(filePath) {
1581
+ return (await stat(filePath)).size;
1582
+ }
1583
+ async function processPathBackedSqliteBlob(source, sourceFormatProfile, filePath, blob, targetSessionRefs) {
1584
+ return (await tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, Buffer.alloc(0), targetSessionRefs)) ?? [];
1585
+ }
1586
+ async function tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, fileBuffer, targetSessionRefs) {
1587
+ const blobId = blob.id;
1588
+ if (source.platform === "cursor" && path.basename(filePath) === "store.db") {
1589
+ const chatStoreSeed = await extractCursorChatStoreSeed(source.platform, filePath, blob.file_modified_at ?? nowIso(), {
1590
+ asString,
1591
+ asNumber,
1592
+ asArray,
1593
+ isObject,
1594
+ safeJsonParse,
1595
+ coerceIso,
1596
+ epochMillisToIso,
1597
+ nowIso,
1598
+ truncate,
1599
+ sha1,
1600
+ normalizeWorkspacePath,
1601
+ extractGenericSessionMetadata,
1602
+ extractGenericRole,
1603
+ extractGenericContentItems,
1604
+ extractTokenUsage,
1605
+ normalizeStopReason,
1606
+ extractRichTextText,
1607
+ collectConversationSeedsFromValue,
1608
+ firstDefinedNumber,
1609
+ });
1610
+ if (chatStoreSeed && (!targetSessionRefs?.length || targetSessionRefs.some((ref) => targetRefMatchesSession(ref, chatStoreSeed.seed.sessionId)))) {
1611
+ const records = chatStoreSeed.seed.records.map((record, ordinal) => ({
1612
+ id: stableId("record", source.id, chatStoreSeed.seed.sessionId, blobId, String(ordinal), record.pointer),
1613
+ source_id: source.id,
1614
+ blob_id: blobId,
1615
+ session_ref: chatStoreSeed.seed.sessionId,
1616
+ ordinal,
1617
+ record_path_or_offset: record.pointer,
1618
+ observed_at: record.observedAt ?? nowIso(),
1619
+ parseable: true,
1620
+ raw_json: record.rawJson,
1621
+ }));
1622
+ const initialLossAudits = chatStoreSeed.diagnostics.map((diagnostic) => createLossAudit(source.id, blobId, "dropped_for_projection", diagnostic.detail, {
1623
+ stageKind: "extract_records",
1624
+ diagnosticCode: diagnostic.code,
1625
+ severity: diagnostic.severity,
1626
+ sessionRef: chatStoreSeed.seed.sessionId,
1627
+ blobRef: blobId,
1628
+ sourceFormatProfileId: sourceFormatProfile.id,
1629
+ }));
1630
+ return [
1631
+ buildAdapterBlobResult(source, sourceFormatProfile, blob.host_id, filePath, blob.capture_run_id, blob, chatStoreSeed.seed.sessionId, records, {
1632
+ title: chatStoreSeed.seed.title,
1633
+ created_at: chatStoreSeed.seed.createdAt,
1634
+ updated_at: chatStoreSeed.seed.updatedAt,
1635
+ model: chatStoreSeed.seed.model,
1636
+ working_directory: chatStoreSeed.seed.workingDirectory,
1637
+ }, initialLossAudits),
1638
+ ];
1639
+ }
1640
+ return [];
1641
+ }
1642
+ const multiSessionSeeds = await extractMultiSessionSeeds(source, filePath, fileBuffer, blobId, targetSessionRefs);
1643
+ if (!multiSessionSeeds) {
1644
+ return undefined;
1645
+ }
1646
+ const results = [];
1647
+ for (const seed of multiSessionSeeds.filter((entry) => !targetSessionRefs?.length || targetSessionRefs.some((ref) => targetRefMatchesSession(ref, entry.sessionId)))) {
1648
+ results.push(buildAdapterBlobResult(source, sourceFormatProfile, blob.host_id, filePath, blob.capture_run_id, blob, seed.sessionId, seed.records.map((record, ordinal) => ({
1649
+ id: stableId("record", source.id, seed.sessionId, blobId, String(ordinal), record.pointer),
1650
+ source_id: source.id,
1651
+ blob_id: blobId,
1652
+ session_ref: seed.sessionId,
1653
+ ordinal,
1654
+ record_path_or_offset: record.pointer,
1655
+ observed_at: record.observedAt ?? nowIso(),
1656
+ parseable: true,
1657
+ raw_json: record.rawJson,
1658
+ })), {
1659
+ title: seed.title,
1660
+ created_at: seed.createdAt,
1661
+ updated_at: seed.updatedAt,
1662
+ model: seed.model,
1663
+ working_directory: seed.workingDirectory,
1664
+ }));
1665
+ }
1666
+ return results;
1667
+ }
1668
+ async function processBlob(source, sourceFormatProfile, filePath, capturedBlob, targetSessionRefs) {
1669
+ const { blob, fileBuffer } = capturedBlob;
1670
+ const pathOpened = await tryProcessPathOpenedContainer(source, sourceFormatProfile, filePath, blob, fileBuffer, targetSessionRefs);
1671
+ if (pathOpened) {
1672
+ return pathOpened;
1673
+ }
1674
+ const blobId = blob.id;
1675
+ const profileId = sourceFormatProfile.id;
1676
+ const sessionId = deriveSessionId(source.platform, filePath, fileBuffer);
1677
+ if (targetSessionRefs?.length &&
1678
+ source.platform !== "codex" &&
1679
+ !targetSessionRefs.some((ref) => targetRefMatchesSession(ref, sessionId)) &&
1680
+ !(source.platform === "openclaw" && isOpenClawCronRunFile(filePath))) {
1681
+ return [];
1682
+ }
1683
+ const context = {
1684
+ source,
1685
+ hostId: blob.host_id,
1686
+ filePath,
1687
+ profileId,
1688
+ sessionId,
1689
+ captureRunId: blob.capture_run_id,
1690
+ };
1691
+ const records = await extractRecords(context, blobId, fileBuffer);
1692
+ const extractionLossAudits = [];
1693
+ if (records.length === 0) {
1694
+ extractionLossAudits.push(createLossAudit(source.id, blobId, "dropped_for_projection", "Blob was captured but produced no raw records", {
1695
+ stageKind: "extract_records",
1696
+ diagnosticCode: "records_missing",
1697
+ severity: "error",
1698
+ sessionRef: sessionId,
1699
+ blobRef: blobId,
1700
+ sourceFormatProfileId: profileId,
1701
+ }));
1702
+ }
1703
+ for (const record of records) {
1704
+ if (record.parseable) {
1705
+ continue;
1706
+ }
1707
+ extractionLossAudits.push(createLossAudit(source.id, record.id, "unknown_fragment", "Raw record could not be extracted into a parseable object", {
1708
+ stageKind: "extract_records",
1709
+ diagnosticCode: "record_unparseable",
1710
+ severity: "warning",
1711
+ sessionRef: sessionId,
1712
+ blobRef: blobId,
1713
+ recordRef: record.id,
1714
+ sourceFormatProfileId: profileId,
1715
+ }));
1716
+ }
1717
+ return [
1718
+ buildAdapterBlobResult(source, sourceFormatProfile, blob.host_id, filePath, blob.capture_run_id, blob, sessionId, records, {}, extractionLossAudits),
1719
+ ];
1720
+ }
1721
+ // Stage 3: streaming counterpart of processBlob for oversized incremental-JSONL
1722
+ // files (codex/claude_code/factory_droid). Uses prefixReader to derive the
1723
+ // session id from the head of the file, and streamingLineReader to parse
1724
+ // records without materializing the whole file in memory.
1725
+ //
1726
+ // Only supports the incremental-JSONL branch of processBlob. Path-backed
1727
+ // SQLite (zcode db.sqlite, cursor/antigravity state.vscdb and store.db) is
1728
+ // captured from file identity (metadata-only) and opened by path via
1729
+ // processPathBackedSqliteBlob instead of being hashed into memory.
1730
+ // AMP root-JSON, Gemini, and other non-JSONL shapes still take the oversized skip.
1731
+ async function processStreamingJsonlBlob(source, sourceFormatProfile, filePath, capturedBlob) {
1732
+ const { blob } = capturedBlob;
1733
+ const blobId = blob.id;
1734
+ const profileId = sourceFormatProfile.id;
1735
+ const head = await capturedBlob.prefixReader(SESSION_METADATA_MAX_LINE_BYTES);
1736
+ const sessionId = deriveSessionId(source.platform, filePath, head);
1737
+ const context = {
1738
+ source,
1739
+ hostId: blob.host_id,
1740
+ filePath,
1741
+ profileId,
1742
+ sessionId,
1743
+ captureRunId: blob.capture_run_id,
1744
+ };
1745
+ const records = await collectJsonlRecordsStreaming(capturedBlob.streamingLineReader(), {
1746
+ sourceId: source.id,
1747
+ blobId,
1748
+ sessionId,
1749
+ }, {
1750
+ observedAt: nowIso(),
1751
+ sidecars: source.platform === "factory_droid"
1752
+ ? [
1753
+ {
1754
+ filePath: filePath.replace(/\.jsonl?$/u, ".settings.json"),
1755
+ pointer: "settings",
1756
+ },
1757
+ ]
1758
+ : undefined,
1759
+ }, {
1760
+ createRecordId: (ordinal, pointer) => stableId("record", source.id, sessionId, blobId, String(ordinal), pointer),
1761
+ pathExists,
1762
+ readTextFile: (targetPath) => readFile(targetPath, "utf8"),
1763
+ nowIso,
1764
+ });
1765
+ const extractionLossAudits = [];
1766
+ if (records.length === 0) {
1767
+ extractionLossAudits.push(createLossAudit(source.id, blobId, "dropped_for_projection", "Blob was captured but produced no raw records", {
1768
+ stageKind: "extract_records",
1769
+ diagnosticCode: "records_missing",
1770
+ severity: "error",
1771
+ sessionRef: sessionId,
1772
+ blobRef: blobId,
1773
+ sourceFormatProfileId: profileId,
1774
+ }));
1775
+ }
1776
+ for (const record of records) {
1777
+ if (record.parseable) {
1778
+ continue;
1779
+ }
1780
+ extractionLossAudits.push(createLossAudit(source.id, record.id, "unknown_fragment", "Raw record could not be extracted into a parseable object", {
1781
+ stageKind: "extract_records",
1782
+ diagnosticCode: "record_unparseable",
1783
+ severity: "warning",
1784
+ sessionRef: sessionId,
1785
+ blobRef: blobId,
1786
+ recordRef: record.id,
1787
+ sourceFormatProfileId: profileId,
1788
+ }));
1789
+ }
1790
+ return [
1791
+ buildAdapterBlobResult(source, sourceFormatProfile, blob.host_id, filePath, blob.capture_run_id, blob, sessionId, records, {}, extractionLossAudits),
1792
+ ];
1793
+ }
1794
+ function buildSyntheticSeedAdapterResult(source, sourceFormatProfile, hostId, captureRunId, originPath, seed) {
1795
+ const serializedSeed = JSON.stringify(seed.records);
1796
+ const fileBuffer = Buffer.from(serializedSeed, "utf8");
1797
+ const checksum = sha1(fileBuffer);
1798
+ const capturedAt = nowIso();
1799
+ const blob = {
1800
+ id: stableId("blob", source.id, originPath, checksum),
1801
+ source_id: source.id,
1802
+ host_id: hostId,
1803
+ origin_path: originPath,
1804
+ checksum,
1805
+ size_bytes: fileBuffer.length,
1806
+ captured_at: capturedAt,
1807
+ capture_run_id: captureRunId,
1808
+ file_modified_at: seed.updatedAt ?? seed.createdAt ?? capturedAt,
1809
+ };
1810
+ const records = seed.records.map((record, ordinal) => ({
1811
+ id: stableId("record", source.id, seed.sessionId, blob.id, String(ordinal), record.pointer),
1812
+ source_id: source.id,
1813
+ blob_id: blob.id,
1814
+ session_ref: seed.sessionId,
1815
+ ordinal,
1816
+ record_path_or_offset: record.pointer,
1817
+ observed_at: record.observedAt ?? nowIso(),
1818
+ parseable: true,
1819
+ raw_json: record.rawJson,
1820
+ }));
1821
+ return buildAdapterBlobResult(source, sourceFormatProfile, hostId, originPath, captureRunId, blob, seed.sessionId, records, {
1822
+ title: seed.title,
1823
+ created_at: seed.createdAt,
1824
+ updated_at: seed.updatedAt,
1825
+ model: seed.model,
1826
+ working_directory: seed.workingDirectory,
1827
+ });
1828
+ }
1829
+ //# sourceMappingURL=probe.js.map