@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,1389 @@
1
+ import { promises as fs } from "node:fs";
2
+ import { createHash } from "node:crypto";
3
+ import path from "node:path";
4
+ import { parseAccioRecord as parseAccioRuntimeRecord } from "../platforms/accio/runtime.js";
5
+ import { parseAmpRecord as parseAmpRuntimeRecord } from "../platforms/amp/runtime.js";
6
+ import { isAntigravityBrainSourceFile, isAntigravityHistoryIndexFile } from "../platforms/antigravity.js";
7
+ import { extractAntigravityBrainSeed, extractAntigravityHistorySeed, } from "../platforms/antigravity/runtime.js";
8
+ import { parseClaudeRecord as parseClaudeRuntimeRecord } from "../platforms/claude-code/runtime.js";
9
+ import { parseCodexRecord as parseCodexRuntimeRecord } from "../platforms/codex/runtime.js";
10
+ import { resolveCursorTranscriptWorkspacePath } from "../platforms/cursor/runtime.js";
11
+ import { applyGrokWorkspaceFromPath, listGrokRecordSidecarPaths } from "../platforms/grok.js";
12
+ import { collectGrokTurnCompletedUpdateRecords, interleaveGrokTurnCompletedRecords, parseGrokRecord as parseGrokRuntimeRecord, } from "../platforms/grok/runtime.js";
13
+ import { parseFactoryRecord as parseFactoryRuntimeRecord } from "../platforms/factory-droid/runtime.js";
14
+ import { extractGenericContentItems as extractGenericContentItemsRuntime, extractGenericRole as extractGenericRoleRuntime, extractGenericSessionMetadata as extractGenericSessionMetadataRuntime, normalizeToolInput as normalizeToolInputRuntime, parseGenericConversationRecord as parseGenericConversationRuntimeRecord, } from "../platforms/generic/runtime.js";
15
+ import { parseOpenClawCronRunRecord as parseOpenClawCronRunRuntimeRecord } from "../platforms/openclaw/runtime.js";
16
+ import { extractGeminiProjectKey, resolveGeminiRoot } from "../platforms/gemini.js";
17
+ import { resolveKimiSessionDir } from "../platforms/kimi.js";
18
+ import { parseKimiRecord as parseKimiRuntimeRecord } from "../platforms/kimi/runtime.js";
19
+ import { extractZcodeSqliteSeeds } from "../platforms/zcode/runtime.js";
20
+ import { collectJsonlRecords, extractContentMaxTimestamp, isIncrementalJsonlPlatform } from "./jsonl-records.js";
21
+ import { collectConversationSeedsFromValue as collectConversationSeedsFromValueRuntime, normalizeMessageCandidate as normalizeMessageCandidateRuntime, } from "./conversation-seeds.js";
22
+ import { asArray, asBoolean, asNumber, asString, coerceIso, createFragment, createLossAudit, extractSourceSessionIdFromCanonicalSessionId, buildSourceResumeCommand, epochMillisToIso, isObject, mapRoleToActor, nowIso, pathExists, safeJsonParse, stableId, truncate, normalizeWorkspacePath, sha1, extractTextFromContentItem, stringifyToolContent, extractTokenUsage, normalizeStopReason, extractCumulativeTokenUsage, buildTokenUsageCheckpointBaselineKey, mergeMaxTokenUsageMetrics, diffTokenUsageMetrics, isClaudeInterruptionMarker, normalizeFileUri, buildTextChunks, inferDisplayPolicy, firstDefinedNumber, sumDefinedNumbers, minIso, maxIso, } from "./utils.js";
23
+ import { atomizeFragments, hydrateDraftFromAtoms, deriveSourceNativeProjectRef } from "./atomizer.js";
24
+ let vscodeStateExtractorPromise;
25
+ /**
26
+ * Derive the conversation metadata file path from an Accio session file path.
27
+ *
28
+ * Session file: .../agents/DID-xxx/sessions/DID-xxx_CID-yyy.messages.jsonl
29
+ * Conversation: .../conversations/dm/CID-yyy.jsonc
30
+ */
31
+ function deriveAccioConversationMetaPath(sessionFilePath) {
32
+ const basename = path.basename(sessionFilePath, ".messages.jsonl");
33
+ const cidIdx = basename.indexOf("_CID-");
34
+ if (cidIdx < 0)
35
+ return "";
36
+ const cid = basename.slice(cidIdx + 1);
37
+ // Walk up: sessions/ → <agentId>/ → agents/ → <accountRoot>/
38
+ const accountRoot = path.resolve(path.dirname(sessionFilePath), "..", "..", "..");
39
+ return path.join(accountRoot, "conversations", "dm", `${cid}.jsonc`);
40
+ }
41
+ export async function extractRecords(context, blobId, fileBuffer) {
42
+ const text = fileBuffer.toString("utf8");
43
+ const records = [];
44
+ const baseRecordId = (ordinal, pointer) => stableId("record", context.source.id, context.sessionId, blobId, String(ordinal), pointer);
45
+ if (context.source.platform === "amp") {
46
+ let parsedValue;
47
+ try {
48
+ parsedValue = JSON.parse(text);
49
+ }
50
+ catch {
51
+ records.push({
52
+ id: baseRecordId(0, "root"),
53
+ source_id: context.source.id,
54
+ blob_id: blobId,
55
+ session_ref: context.sessionId,
56
+ ordinal: 0,
57
+ record_path_or_offset: "root",
58
+ observed_at: nowIso(),
59
+ parseable: false,
60
+ raw_json: text,
61
+ });
62
+ return records;
63
+ }
64
+ if (!isObject(parsedValue)) {
65
+ records.push({
66
+ id: baseRecordId(0, "root"),
67
+ source_id: context.source.id,
68
+ blob_id: blobId,
69
+ session_ref: context.sessionId,
70
+ ordinal: 0,
71
+ record_path_or_offset: "root",
72
+ observed_at: nowIso(),
73
+ parseable: false,
74
+ raw_json: text,
75
+ });
76
+ return records;
77
+ }
78
+ const parsed = parsedValue;
79
+ const rootObserved = coerceIso(parsed.created_at) ?? epochMillisToIso(asNumber(parsed.created)) ?? nowIso();
80
+ records.push({
81
+ id: baseRecordId(0, "root"),
82
+ source_id: context.source.id,
83
+ blob_id: blobId,
84
+ session_ref: context.sessionId,
85
+ ordinal: 0,
86
+ record_path_or_offset: "root",
87
+ observed_at: rootObserved,
88
+ parseable: true,
89
+ raw_json: JSON.stringify(parsed),
90
+ });
91
+ const messages = asArray(parsed.messages);
92
+ for (const [index, message] of messages.entries()) {
93
+ if (!isObject(message)) {
94
+ continue;
95
+ }
96
+ const messageTimes = [
97
+ epochMillisToIso(asNumber(message.meta?.sentAt)),
98
+ coerceIso(message.timestamp),
99
+ ...asArray(message.content).flatMap((item) => {
100
+ if (!isObject(item))
101
+ return [];
102
+ return [
103
+ epochMillisToIso(asNumber(item.startTime)),
104
+ epochMillisToIso(asNumber(item.finalTime)),
105
+ ];
106
+ }),
107
+ ].filter((value) => value !== undefined);
108
+ const observedAt = messageTimes.sort().at(-1) ?? rootObserved;
109
+ records.push({
110
+ id: baseRecordId(index + 1, `messages[${index}]`),
111
+ source_id: context.source.id,
112
+ blob_id: blobId,
113
+ session_ref: context.sessionId,
114
+ ordinal: index + 1,
115
+ record_path_or_offset: `messages[${index}]`,
116
+ observed_at: observedAt,
117
+ parseable: true,
118
+ raw_json: JSON.stringify(message),
119
+ });
120
+ }
121
+ return records;
122
+ }
123
+ const fallbackObservedAt = context.source.platform === "factory_droid" ||
124
+ context.source.platform === "grok" ||
125
+ context.source.platform === "cursor" ||
126
+ context.source.platform === "cursor_agent"
127
+ ? await fs.stat(context.filePath).then((stats) => stats.mtime.toISOString()).catch(() => nowIso())
128
+ : nowIso();
129
+ const grokSidecars = context.source.platform === "grok"
130
+ ? await listGrokRecordSidecarPaths(context.filePath)
131
+ : undefined;
132
+ const collected = await collectJsonlRecords(text, {
133
+ sourceId: context.source.id,
134
+ blobId,
135
+ sessionId: context.sessionId,
136
+ }, {
137
+ observedAt: fallbackObservedAt,
138
+ sidecars: context.source.platform === "factory_droid"
139
+ ? [
140
+ {
141
+ filePath: context.filePath.replace(/\.jsonl?$/u, ".settings.json"),
142
+ pointer: "settings",
143
+ },
144
+ ]
145
+ : context.source.platform === "kimi"
146
+ ? [
147
+ {
148
+ filePath: path.join(resolveKimiSessionDir(context.filePath) ?? path.dirname(context.filePath), "state.json"),
149
+ pointer: "state",
150
+ },
151
+ ]
152
+ : context.source.platform === "grok"
153
+ ? grokSidecars?.filter((sidecar) => sidecar.pointer !== "updates")
154
+ : context.source.platform === "accio"
155
+ ? [
156
+ {
157
+ filePath: context.filePath.replace(/\.messages\.jsonl$/u, ".meta.jsonc"),
158
+ pointer: "meta",
159
+ },
160
+ {
161
+ filePath: deriveAccioConversationMetaPath(context.filePath),
162
+ pointer: "conversation_meta",
163
+ },
164
+ ]
165
+ : undefined,
166
+ }, {
167
+ createRecordId: baseRecordId,
168
+ pathExists,
169
+ readTextFile: (targetPath) => fs.readFile(targetPath, "utf8"),
170
+ nowIso,
171
+ });
172
+ if (context.source.platform === "factory_droid") {
173
+ return normalizeFactoryRecordObservedTimes(collected, fallbackObservedAt);
174
+ }
175
+ if (context.source.platform === "grok") {
176
+ const updatesSidecar = grokSidecars?.find((sidecar) => sidecar.pointer === "updates");
177
+ if (updatesSidecar) {
178
+ collected.push(...await collectGrokTurnCompletedUpdateRecords({
179
+ filePath: updatesSidecar.filePath,
180
+ identity: {
181
+ sourceId: context.source.id,
182
+ blobId,
183
+ sessionId: context.sessionId,
184
+ },
185
+ startOrdinal: collected.length,
186
+ createRecordId: baseRecordId,
187
+ nowIso,
188
+ }));
189
+ }
190
+ const ordered = applyJsonlOrdinalObservedTimes(collected, fallbackObservedAt, collected
191
+ .map((record) => record.record_path_or_offset)
192
+ .filter((pointer) => pointer === "summary" ||
193
+ pointer.startsWith("subagent_meta") ||
194
+ pointer.startsWith("updates:")));
195
+ return interleaveGrokTurnCompletedRecords(ordered);
196
+ }
197
+ if (context.source.platform === "cursor" || context.source.platform === "cursor_agent") {
198
+ return applyJsonlOrdinalObservedTimes(collected, fallbackObservedAt);
199
+ }
200
+ return collected;
201
+ }
202
+ function applyJsonlOrdinalObservedTimes(records, fallbackObservedAt, skipPointers = []) {
203
+ const baseMs = Date.parse(fallbackObservedAt);
204
+ return records.map((record, index) => {
205
+ if (skipPointers.includes(record.record_path_or_offset)) {
206
+ return record;
207
+ }
208
+ try {
209
+ const parsed = JSON.parse(record.raw_json);
210
+ if (isObject(parsed)) {
211
+ const explicit = coerceIso(parsed.timestamp) ??
212
+ coerceIso(parsed.createdAt) ??
213
+ coerceIso(parsed.updatedAt) ??
214
+ epochMillisToIso(asNumber(parsed.timestamp)) ??
215
+ epochMillisToIso(asNumber(parsed.createdAt));
216
+ if (explicit) {
217
+ return { ...record, observed_at: explicit };
218
+ }
219
+ }
220
+ }
221
+ catch {
222
+ /* keep ordinal fallback */
223
+ }
224
+ if (!Number.isFinite(baseMs)) {
225
+ return record;
226
+ }
227
+ return { ...record, observed_at: new Date(baseMs + index).toISOString() };
228
+ });
229
+ }
230
+ function normalizeFactoryRecordObservedTimes(records, fallbackObservedAt) {
231
+ const explicitTimes = records.map((record) => {
232
+ try {
233
+ const parsed = JSON.parse(record.raw_json);
234
+ return isObject(parsed) ? coerceIso(parsed.timestamp) : undefined;
235
+ }
236
+ catch {
237
+ return undefined;
238
+ }
239
+ });
240
+ const firstExplicit = explicitTimes.find((value) => value !== undefined) ?? fallbackObservedAt;
241
+ let previousExplicit;
242
+ return records.map((record, index) => {
243
+ const explicit = explicitTimes[index];
244
+ if (explicit)
245
+ previousExplicit = explicit;
246
+ const nextExplicit = explicitTimes.slice(index + 1).find((value) => value !== undefined);
247
+ return {
248
+ ...record,
249
+ observed_at: explicit ?? previousExplicit ?? nextExplicit ?? firstExplicit,
250
+ };
251
+ });
252
+ }
253
+ export function parseRecord(context, record, draft) {
254
+ let parsed;
255
+ try {
256
+ parsed = JSON.parse(record.raw_json);
257
+ }
258
+ catch {
259
+ return {
260
+ fragments: [
261
+ createFragment(context, record, 0, "unknown", record.observed_at, {
262
+ reason: "invalid_json",
263
+ raw_preview: record.raw_json.slice(0, 200),
264
+ }),
265
+ ],
266
+ lossAudits: [
267
+ createRecordLossAudit(context, record, "unknown_fragment", "Record could not be parsed as JSON", {
268
+ diagnosticCode: "record_json_parse_failed",
269
+ severity: "warning",
270
+ }),
271
+ ],
272
+ };
273
+ }
274
+ if (!isObject(parsed)) {
275
+ return {
276
+ fragments: [
277
+ createFragment(context, record, 0, "unknown", record.observed_at, {
278
+ reason: "non_object_record",
279
+ }),
280
+ ],
281
+ lossAudits: [
282
+ createRecordLossAudit(context, record, "unknown_fragment", "Record parsed but is not an object", {
283
+ diagnosticCode: "record_not_object",
284
+ severity: "warning",
285
+ }),
286
+ ],
287
+ };
288
+ }
289
+ if (context.source.platform === "codex") {
290
+ return parseCodexRuntimeRecord(context, record, parsed, draft, {
291
+ ...buildCommonParseRuntimeHelpers(),
292
+ safeJsonParse,
293
+ extractCumulativeTokenUsage,
294
+ buildTokenUsageCheckpointBaselineKey,
295
+ mergeMaxTokenUsageMetrics,
296
+ diffTokenUsageMetrics,
297
+ });
298
+ }
299
+ if (context.source.platform === "claude_code") {
300
+ return parseClaudeRuntimeRecord(context, record, parsed, draft, {
301
+ ...buildCommonParseRuntimeHelpers(),
302
+ isClaudeInterruptionMarker,
303
+ });
304
+ }
305
+ if (context.source.platform === "factory_droid") {
306
+ return parseFactoryRuntimeRecord(context, record, parsed, draft, buildCommonParseRuntimeHelpers());
307
+ }
308
+ if (context.source.platform === "kimi") {
309
+ return parseKimiRuntimeRecord(context, record, parsed, draft, buildCommonParseRuntimeHelpers());
310
+ }
311
+ if (context.source.platform === "grok") {
312
+ applyGrokWorkspaceFromPath(context.filePath, draft, normalizeWorkspacePath);
313
+ return parseGrokRuntimeRecord(context, record, parsed, draft, buildCommonParseRuntimeHelpers());
314
+ }
315
+ if (context.source.platform === "codebuddy") {
316
+ const providerData = isObject(parsed.providerData) ? parsed.providerData : undefined;
317
+ if (asBoolean(providerData?.skipRun) || asString(parsed.type) === "skip_run") {
318
+ return {
319
+ fragments: [],
320
+ lossAudits: [
321
+ createRecordLossAudit(context, record, "dropped_for_projection", "CodeBuddy skipRun command echo kept as raw evidence only", {
322
+ diagnosticCode: "codebuddy_skiprun_command_echo",
323
+ severity: "info",
324
+ }),
325
+ ],
326
+ };
327
+ }
328
+ const normalizedParsed = providerData && providerData.usage !== undefined && parsed.usage === undefined
329
+ ? { ...parsed, usage: providerData.usage }
330
+ : parsed;
331
+ return parseGenericConversationRuntimeRecord(context, record, normalizedParsed, draft, {
332
+ ...buildCommonParseRuntimeHelpers(),
333
+ safeJsonParse,
334
+ });
335
+ }
336
+ if (context.source.platform === "openclaw") {
337
+ const normalizedFilePath = context.filePath.replace(/\\/g, "/");
338
+ if (normalizedFilePath.includes("/cron/runs/")) {
339
+ return parseOpenClawCronRunRuntimeRecord(context, record, parsed, draft, {
340
+ ...buildCommonParseRuntimeHelpers(),
341
+ safeJsonParse,
342
+ });
343
+ }
344
+ return parseGenericConversationRuntimeRecord(context, record, parsed, draft, {
345
+ ...buildCommonParseRuntimeHelpers(),
346
+ safeJsonParse,
347
+ });
348
+ }
349
+ if (context.source.platform === "accio") {
350
+ return parseAccioRuntimeRecord(context, record, parsed, draft, {
351
+ ...buildCommonParseRuntimeHelpers(),
352
+ safeJsonParse,
353
+ });
354
+ }
355
+ if (context.source.platform === "cursor" ||
356
+ context.source.platform === "cursor_agent" ||
357
+ context.source.platform === "antigravity" ||
358
+ context.source.platform === "gemini" ||
359
+ context.source.platform === "opencode" ||
360
+ context.source.platform === "lobechat" ||
361
+ context.source.platform === "zcode") {
362
+ if ((context.source.platform === "cursor" || context.source.platform === "cursor_agent") && asString(parsed.type) === "turn_ended") {
363
+ return { fragments: [], lossAudits: [] };
364
+ }
365
+ const cursorParsed = context.source.platform === "cursor" || context.source.platform === "cursor_agent"
366
+ ? applyCursorTranscriptWorkspace(context.filePath, parsed, draft)
367
+ : parsed;
368
+ return parseGenericConversationRuntimeRecord(context, record, cursorParsed, draft, {
369
+ ...buildCommonParseRuntimeHelpers(),
370
+ safeJsonParse,
371
+ });
372
+ }
373
+ return parseAmpRuntimeRecord(context, record, parsed, draft, {
374
+ ...buildCommonParseRuntimeHelpers(),
375
+ normalizeFileUri,
376
+ });
377
+ }
378
+ export async function extractMultiSessionSeeds(source, filePath, fileBuffer, blobId, targetSessionRefs) {
379
+ if (source.platform === "cursor" && path.basename(filePath) === "state.vscdb") {
380
+ const extractVscodeStateSeeds = await loadExtractVscodeStateSeeds();
381
+ return (await extractVscodeStateSeeds(source, filePath, {
382
+ safeJsonParse,
383
+ isObject,
384
+ asArray,
385
+ asString,
386
+ asNumber,
387
+ coerceIso,
388
+ epochMillisToIso,
389
+ nowIso,
390
+ truncate,
391
+ sha1,
392
+ normalizeWorkspacePath,
393
+ extractGenericSessionMetadata,
394
+ extractGenericRole,
395
+ extractGenericContentItems,
396
+ extractTokenUsage,
397
+ normalizeStopReason,
398
+ extractRichTextText,
399
+ collectConversationSeedsFromValue,
400
+ firstDefinedNumber,
401
+ })) ?? [];
402
+ }
403
+ if (source.platform === "antigravity" && path.basename(filePath) === "state.vscdb") {
404
+ const extractVscodeStateSeeds = await loadExtractVscodeStateSeeds();
405
+ return (await extractVscodeStateSeeds(source, filePath, {
406
+ safeJsonParse,
407
+ isObject,
408
+ asArray,
409
+ asString,
410
+ asNumber,
411
+ coerceIso,
412
+ epochMillisToIso,
413
+ nowIso,
414
+ truncate,
415
+ sha1,
416
+ normalizeWorkspacePath,
417
+ extractGenericSessionMetadata,
418
+ extractGenericRole,
419
+ extractGenericContentItems,
420
+ extractTokenUsage,
421
+ normalizeStopReason,
422
+ extractRichTextText,
423
+ collectConversationSeedsFromValue,
424
+ firstDefinedNumber,
425
+ })) ?? [];
426
+ }
427
+ if (source.platform === "antigravity" && isAntigravityHistoryIndexFile(filePath)) {
428
+ const historySeed = await extractAntigravityHistorySeed(filePath, fileBuffer, {
429
+ readOptionalJsonFile,
430
+ extractMarkdownHeading,
431
+ pathExists,
432
+ coerceIso,
433
+ asString,
434
+ nowIso,
435
+ normalizeWorkspacePath,
436
+ });
437
+ return historySeed ? [historySeed] : [];
438
+ }
439
+ if (source.platform === "antigravity" && isAntigravityBrainSourceFile(filePath)) {
440
+ const brainSeed = await extractAntigravityBrainSeed(filePath, fileBuffer, {
441
+ readOptionalJsonFile,
442
+ extractMarkdownHeading,
443
+ pathExists,
444
+ coerceIso,
445
+ asString,
446
+ nowIso,
447
+ normalizeWorkspacePath,
448
+ });
449
+ return brainSeed ? [brainSeed] : [];
450
+ }
451
+ if (source.platform === "lobechat") {
452
+ return extractConversationExportSeeds(source, filePath, fileBuffer, blobId);
453
+ }
454
+ if (source.platform === "zcode" && path.basename(filePath) === "db.sqlite") {
455
+ return extractZcodeSqliteSeeds(source.platform, filePath, {
456
+ asString,
457
+ asNumber,
458
+ isObject,
459
+ safeJsonParse,
460
+ epochMillisToIso,
461
+ nowIso,
462
+ normalizeWorkspacePath,
463
+ }, targetSessionRefs);
464
+ }
465
+ if (source.platform === "opencode" || source.platform === "gemini") {
466
+ const exportSeeds = await extractConversationExportSeeds(source, filePath, fileBuffer, blobId);
467
+ if (exportSeeds && exportSeeds.length > 0) {
468
+ return exportSeeds;
469
+ }
470
+ }
471
+ return undefined;
472
+ }
473
+ export function buildAdapterBlobResult(source, sourceFormatProfile, hostId, filePath, captureRunId, blob, sessionId, records, draftPatch = {}, initialLossAudits = []) {
474
+ const context = {
475
+ source,
476
+ hostId,
477
+ filePath,
478
+ profileId: sourceFormatProfile.id,
479
+ sessionId,
480
+ captureRunId,
481
+ };
482
+ const fragments = [];
483
+ const atoms = [];
484
+ const edges = [];
485
+ const lossAudits = [...initialLossAudits];
486
+ const draft = {
487
+ id: sessionId,
488
+ source_session_id: draftPatch.source_session_id ??
489
+ extractSourceSessionIdFromCanonicalSessionId(source.platform, sessionId),
490
+ source_id: source.id,
491
+ source_platform: source.platform,
492
+ host_id: hostId,
493
+ title: draftPatch.title,
494
+ canonical_title: draftPatch.canonical_title,
495
+ created_at: draftPatch.created_at,
496
+ updated_at: draftPatch.updated_at,
497
+ model: draftPatch.model,
498
+ working_directory: draftPatch.working_directory,
499
+ source_native_project_ref: deriveSourceNativeProjectRef(source, filePath),
500
+ resume_command: draftPatch.resume_command,
501
+ resume_working_directory: draftPatch.resume_working_directory,
502
+ resume_command_confidence: draftPatch.resume_command_confidence,
503
+ last_cumulative_token_usage: draftPatch.last_cumulative_token_usage,
504
+ cumulative_token_usage_by_baseline: draftPatch.cumulative_token_usage_by_baseline,
505
+ delegated_parent_session_id: draftPatch.delegated_parent_session_id,
506
+ delegated_history_start_ordinal: draftPatch.delegated_history_start_ordinal,
507
+ delegated_agent_key: draftPatch.delegated_agent_key,
508
+ };
509
+ for (const record of records) {
510
+ const parsed = parseRecord(context, record, draft);
511
+ fragments.push(...parsed.fragments);
512
+ lossAudits.push(...parsed.lossAudits);
513
+ }
514
+ if (source.platform === "claude_code") {
515
+ dedupeClaudeCodeTokenUsageFragments(fragments);
516
+ }
517
+ const atomized = atomizeFragments(source.id, sessionId, sourceFormatProfile.id, fragments);
518
+ atoms.push(...atomized.atoms);
519
+ edges.push(...atomized.edges);
520
+ hydrateDraftFromAtoms(draft, atoms, blob.file_modified_at);
521
+ // Note: the resume command is built from the *post-hydration* working_directory.
522
+ // R40 deliberately reuses the latest cwd as the resume cwd signal, so the
523
+ // synthesized `cd <cwd> && resume <uuid>` may diverge from the original
524
+ // session's first cwd if a mid-session `cd` is reflected in workspace_signal
525
+ // atoms. Validate that native `codex resume` / `claude --resume` reattach
526
+ // correctly using the latest cwd on each supported upstream version before
527
+ // assuming the projected command is interchangeable with the session's first
528
+ // cwd.
529
+ const resume = isOrdinaryResumeEligibleSourceFile(source.platform, filePath, draft)
530
+ ? buildSourceResumeCommand({
531
+ platform: draft.source_platform,
532
+ sourceSessionId: draft.source_session_id,
533
+ workingDirectory: draft.working_directory,
534
+ })
535
+ : undefined;
536
+ if (resume) {
537
+ draft.resume_command = draft.resume_command ?? resume.command;
538
+ draft.resume_working_directory = draft.resume_working_directory ?? resume.working_directory;
539
+ draft.resume_command_confidence = draft.resume_command_confidence ?? resume.confidence;
540
+ }
541
+ return {
542
+ draft,
543
+ blobs: [blob],
544
+ records,
545
+ fragments,
546
+ atoms,
547
+ edges,
548
+ loss_audits: lossAudits,
549
+ };
550
+ }
551
+ export function isOrdinaryResumeEligibleSourceFile(platform, filePath, draft) {
552
+ if (draft?.delegated_parent_session_id || draft?.delegated_agent_key) {
553
+ return false;
554
+ }
555
+ if (platform === "claude_code" && /(^|[\\/])subagents([\\/]|$)/u.test(filePath)) {
556
+ return false;
557
+ }
558
+ return true;
559
+ }
560
+ export function fileIdentityFromStats(before, after, capturedByteLength) {
561
+ return (before.size === after.size &&
562
+ before.mtimeMs === after.mtimeMs &&
563
+ before.ctimeMs === after.ctimeMs &&
564
+ (capturedByteLength === undefined || capturedByteLength === after.size));
565
+ }
566
+ export async function captureBlob(source, hostId, filePath, captureRunId) {
567
+ const beforeStats = await fs.stat(filePath);
568
+ const fileBuffer = await fs.readFile(filePath);
569
+ const afterStats = await fs.stat(filePath);
570
+ const fileIdentityStable = fileIdentityFromStats(beforeStats, afterStats, fileBuffer.byteLength);
571
+ const checksum = sha1(fileBuffer);
572
+ const content_max_timestamp = isIncrementalJsonlPlatform(source.platform)
573
+ ? extractContentMaxTimestamp(fileBuffer)
574
+ : undefined;
575
+ return {
576
+ blob: {
577
+ id: stableId("blob", source.id, filePath, checksum),
578
+ source_id: source.id,
579
+ host_id: hostId,
580
+ origin_path: filePath,
581
+ checksum,
582
+ size_bytes: fileBuffer.byteLength,
583
+ captured_at: nowIso(),
584
+ capture_run_id: captureRunId,
585
+ file_modified_at: afterStats.mtime.toISOString(),
586
+ file_changed_at: fileIdentityStable ? afterStats.ctime.toISOString() : undefined,
587
+ file_identity_stable: fileIdentityStable,
588
+ content_max_timestamp,
589
+ },
590
+ fileBuffer,
591
+ };
592
+ }
593
+ // Stage 3: backing block size for streaming reads. 4 MiB balances syscall
594
+ // overhead against heap pressure — at this size a 100 MiB file costs ~25
595
+ // read syscalls and the in-flight chunk is bounded.
596
+ const STREAMING_BACKING_BLOCK_BYTES = 4 * 1024 * 1024;
597
+ // Stage 3: tail window retained during streaming capture so we can compute
598
+ // content_max_timestamp without re-reading the file. Matches the tailBytes
599
+ // default in extractContentMaxTimestamp.
600
+ const STREAMING_TAIL_RETENTION_BYTES = 64 * 1024;
601
+ // Stage 3: streaming variant of captureBlob for oversized JSONL files.
602
+ // Reads the file in STREAMING_BACKING_BLOCK_BYTES chunks, hashes incrementally,
603
+ // and retains only the last STREAMING_TAIL_RETENTION_BYTES for the watermark
604
+ // extraction. Returns a CapturedBlobInput without fileBuffer — downstream
605
+ // consumers must use streamingLineReader (for parsing) and prefixReader (for
606
+ // append detection) instead. The two helpers re-open the file on demand so
607
+ // the captured blob's memory cost stays bounded by the chunk size, not the
608
+ // file size.
609
+ export async function captureBlobStreaming(source, hostId, filePath, captureRunId) {
610
+ const beforeStats = await fs.stat(filePath);
611
+ const fileIdentityStableBefore = {
612
+ size: beforeStats.size,
613
+ mtimeMs: beforeStats.mtimeMs,
614
+ ctimeMs: beforeStats.ctimeMs,
615
+ };
616
+ const handle = await fs.open(filePath, "r");
617
+ let totalBytes = 0;
618
+ let tail = Buffer.alloc(0);
619
+ const hasher = createHash("sha1");
620
+ try {
621
+ while (true) {
622
+ const block = Buffer.alloc(STREAMING_BACKING_BLOCK_BYTES);
623
+ const { bytesRead } = await handle.read(block, 0, STREAMING_BACKING_BLOCK_BYTES, null);
624
+ if (bytesRead === 0) {
625
+ break;
626
+ }
627
+ const slice = bytesRead === STREAMING_BACKING_BLOCK_BYTES ? block : block.subarray(0, bytesRead);
628
+ hasher.update(slice);
629
+ totalBytes += bytesRead;
630
+ const retained = Buffer.concat([tail, slice]);
631
+ tail = retained.length > STREAMING_TAIL_RETENTION_BYTES
632
+ ? retained.subarray(retained.length - STREAMING_TAIL_RETENTION_BYTES)
633
+ : retained;
634
+ }
635
+ }
636
+ finally {
637
+ await handle.close();
638
+ }
639
+ const afterStats = await fs.stat(filePath);
640
+ const fileIdentityStable = fileIdentityFromStats(fileIdentityStableBefore, afterStats, totalBytes);
641
+ const checksum = hasher.digest("hex");
642
+ const content_max_timestamp = isIncrementalJsonlPlatform(source.platform)
643
+ ? extractContentMaxTimestamp(tail)
644
+ : undefined;
645
+ return {
646
+ blob: {
647
+ id: stableId("blob", source.id, filePath, checksum),
648
+ source_id: source.id,
649
+ host_id: hostId,
650
+ origin_path: filePath,
651
+ checksum,
652
+ size_bytes: totalBytes,
653
+ captured_at: nowIso(),
654
+ capture_run_id: captureRunId,
655
+ file_modified_at: afterStats.mtime.toISOString(),
656
+ file_changed_at: fileIdentityStable ? afterStats.ctime.toISOString() : undefined,
657
+ file_identity_stable: fileIdentityStable,
658
+ content_max_timestamp,
659
+ },
660
+ streamingLineReader: async function* streamChunks() {
661
+ const fh = await fs.open(filePath, "r");
662
+ try {
663
+ while (true) {
664
+ const block = Buffer.alloc(STREAMING_BACKING_BLOCK_BYTES);
665
+ const { bytesRead } = await fh.read(block, 0, STREAMING_BACKING_BLOCK_BYTES, null);
666
+ if (bytesRead === 0) {
667
+ break;
668
+ }
669
+ yield bytesRead === STREAMING_BACKING_BLOCK_BYTES ? block : block.subarray(0, bytesRead);
670
+ }
671
+ }
672
+ finally {
673
+ await fh.close();
674
+ }
675
+ },
676
+ prefixReader: async function readPrefix(bytes) {
677
+ if (bytes <= 0) {
678
+ return Buffer.alloc(0);
679
+ }
680
+ const fh = await fs.open(filePath, "r");
681
+ try {
682
+ const block = Buffer.alloc(bytes);
683
+ const { bytesRead } = await fh.read(block, 0, bytes, 0);
684
+ return bytesRead === bytes ? block : block.subarray(0, bytesRead);
685
+ }
686
+ finally {
687
+ await fh.close();
688
+ }
689
+ },
690
+ hashPrefix: async function hashPrefix(bytes) {
691
+ if (bytes <= 0) {
692
+ return { sha1: createHash("sha1").digest("hex"), lastByte: null };
693
+ }
694
+ const fh = await fs.open(filePath, "r");
695
+ try {
696
+ const hasher = createHash("sha1");
697
+ let remaining = bytes;
698
+ let lastByte = null;
699
+ const block = Buffer.alloc(STREAMING_BACKING_BLOCK_BYTES);
700
+ while (remaining > 0) {
701
+ const toRead = Math.min(remaining, STREAMING_BACKING_BLOCK_BYTES);
702
+ const { bytesRead } = await fh.read(block, 0, toRead, null);
703
+ if (bytesRead === 0) {
704
+ break;
705
+ }
706
+ hasher.update(block.subarray(0, bytesRead));
707
+ lastByte = block[bytesRead - 1];
708
+ remaining -= bytesRead;
709
+ }
710
+ return { sha1: hasher.digest("hex"), lastByte };
711
+ }
712
+ finally {
713
+ await fh.close();
714
+ }
715
+ },
716
+ readSuffix: async function readSuffix(offset) {
717
+ const fh = await fs.open(filePath, "r");
718
+ try {
719
+ const stats = await fh.stat();
720
+ const length = Math.max(0, stats.size - offset);
721
+ if (length === 0) {
722
+ return Buffer.alloc(0);
723
+ }
724
+ const buf = Buffer.alloc(length);
725
+ const { bytesRead } = await fh.read(buf, 0, length, offset);
726
+ return bytesRead === length ? buf : buf.subarray(0, bytesRead);
727
+ }
728
+ finally {
729
+ await fh.close();
730
+ }
731
+ },
732
+ };
733
+ }
734
+ function createRecordLossAudit(context, record, lossKind, detail, options = {}) {
735
+ return createLossAudit(context.source.id, options.scopeRef ?? record.id, lossKind, detail, {
736
+ stageKind: "parse_source_fragments",
737
+ diagnosticCode: options.diagnosticCode,
738
+ severity: options.severity,
739
+ sessionRef: options.sessionRef ?? record.session_ref,
740
+ blobRef: options.blobRef ?? record.blob_id,
741
+ recordRef: options.recordRef ?? record.id,
742
+ fragmentRef: options.fragmentRef,
743
+ atomRef: options.atomRef,
744
+ candidateRef: options.candidateRef,
745
+ sourceFormatProfileId: options.sourceFormatProfileId ?? context.profileId,
746
+ });
747
+ }
748
+ function buildCommonParseRuntimeHelpers() {
749
+ return {
750
+ asString,
751
+ asNumber,
752
+ asBoolean,
753
+ asArray,
754
+ isObject,
755
+ coerceIso,
756
+ epochMillisToIso,
757
+ nowIso,
758
+ normalizeWorkspacePath,
759
+ mapRoleToActor,
760
+ extractTextFromContentItem,
761
+ stringifyToolContent,
762
+ extractTokenUsage,
763
+ normalizeStopReason,
764
+ createFragment,
765
+ createTokenUsageFragment,
766
+ appendChunkedTextFragments,
767
+ appendUnsupportedContentItem,
768
+ createRecordLossAudit,
769
+ createLossAudit,
770
+ };
771
+ }
772
+ export function extractGenericSessionMetadata(parsed) {
773
+ return extractGenericSessionMetadataRuntime(parsed, {
774
+ isObject,
775
+ asString,
776
+ asBoolean,
777
+ normalizeWorkspacePath,
778
+ });
779
+ }
780
+ export function extractGenericRole(message) {
781
+ return extractGenericRoleRuntime(message, {
782
+ isObject,
783
+ asString,
784
+ });
785
+ }
786
+ export function extractGenericContentItems(message) {
787
+ return extractGenericContentItemsRuntime(message, {
788
+ isObject,
789
+ asString,
790
+ asArray,
791
+ });
792
+ }
793
+ export function normalizeToolInput(value) {
794
+ return normalizeToolInputRuntime(value, {
795
+ isObject,
796
+ safeJsonParse,
797
+ });
798
+ }
799
+ export function buildTextFragmentPayload(actorKind, chunk, options = {}) {
800
+ const payload = {
801
+ actor_kind: actorKind,
802
+ origin_kind: chunk.originKind,
803
+ text: chunk.text,
804
+ display_policy: chunk.displayPolicy ?? inferDisplayPolicy(chunk.originKind, chunk.text),
805
+ };
806
+ if (options.usage) {
807
+ payload.token_usage = options.usage;
808
+ if (typeof options.usage.total_tokens === "number") {
809
+ payload.token_count = options.usage.total_tokens;
810
+ }
811
+ if (options.usage.model) {
812
+ payload.model = options.usage.model;
813
+ }
814
+ }
815
+ if (options.stopReason) {
816
+ payload.stop_reason = options.stopReason;
817
+ }
818
+ if (options.messageId) {
819
+ payload.message_id = options.messageId;
820
+ }
821
+ if (options.model) {
822
+ payload.model = options.model;
823
+ }
824
+ return payload;
825
+ }
826
+ // Claude Code writes multi-block assistant messages (thinking + text + N tool_use)
827
+ // as one JSONL line per block, each carrying the same Anthropic `message.id` and
828
+ // the same final aggregated usage. Without dedup, every non-text block re-emits a
829
+ // token_usage fragment and the same API call is counted many times.
830
+ // We collapse exact (message.id, request_id) calls, keeping the non-sidechain,
831
+ // largest, most complete checkpoint. Distinct request ids remain billable.
832
+ export function dedupeClaudeCodeTokenUsageFragments(fragments) {
833
+ const indexOfKept = new Map();
834
+ const removed = new Set();
835
+ for (let i = 0; i < fragments.length; i++) {
836
+ const frag = fragments[i];
837
+ if (!frag || frag.fragment_kind !== "token_usage_signal")
838
+ continue;
839
+ const messageId = typeof frag.payload.message_id === "string" ? frag.payload.message_id : undefined;
840
+ if (!messageId)
841
+ continue;
842
+ const requestId = typeof frag.payload.request_id === "string" ? frag.payload.request_id : null;
843
+ const key = JSON.stringify([messageId, requestId]);
844
+ const existingIdx = indexOfKept.get(key);
845
+ if (existingIdx === undefined) {
846
+ indexOfKept.set(key, i);
847
+ continue;
848
+ }
849
+ const existing = fragments[existingIdx];
850
+ if (existing && compareClaudeTokenUsageFragments(frag, existing) > 0) {
851
+ removed.add(existingIdx);
852
+ indexOfKept.set(key, i);
853
+ }
854
+ else {
855
+ removed.add(i);
856
+ }
857
+ }
858
+ // Sidechain replay records can carry a different request id. Collapse only
859
+ // an identical usage replay with a matching non-sidechain message.
860
+ const kept = [...indexOfKept.values()].filter((index) => !removed.has(index));
861
+ for (const sidechainIndex of kept) {
862
+ const sidechain = fragments[sidechainIndex];
863
+ if (!sidechain || sidechain.payload.is_sidechain !== true)
864
+ continue;
865
+ const messageId = sidechain.payload.message_id;
866
+ const fingerprint = tokenUsageFingerprint(sidechain.payload);
867
+ const hasMainReplay = kept.some((mainIndex) => {
868
+ if (mainIndex === sidechainIndex || removed.has(mainIndex))
869
+ return false;
870
+ const main = fragments[mainIndex];
871
+ return Boolean(main &&
872
+ main.payload.is_sidechain !== true &&
873
+ main.payload.message_id === messageId &&
874
+ tokenUsageFingerprint(main.payload) === fingerprint);
875
+ });
876
+ if (hasMainReplay)
877
+ removed.add(sidechainIndex);
878
+ }
879
+ const removedIds = new Set();
880
+ if (removed.size > 0) {
881
+ for (let i = fragments.length - 1; i >= 0; i--) {
882
+ if (!removed.has(i))
883
+ continue;
884
+ const fragment = fragments[i];
885
+ if (fragment)
886
+ removedIds.add(fragment.id);
887
+ fragments.splice(i, 1);
888
+ }
889
+ }
890
+ return removedIds;
891
+ }
892
+ function compareClaudeTokenUsageFragments(left, right) {
893
+ const leftMain = left.payload.is_sidechain === true ? 0 : 1;
894
+ const rightMain = right.payload.is_sidechain === true ? 0 : 1;
895
+ if (leftMain !== rightMain)
896
+ return leftMain - rightMain;
897
+ const totalDifference = tokenUsageTotal(left.payload) - tokenUsageTotal(right.payload);
898
+ if (totalDifference !== 0)
899
+ return totalDifference;
900
+ return tokenUsageCompleteness(left.payload) - tokenUsageCompleteness(right.payload);
901
+ }
902
+ function tokenUsageCompleteness(payload) {
903
+ const usage = payload.token_usage;
904
+ const usageFields = usage && typeof usage === "object"
905
+ ? Object.values(usage).filter((value) => value !== undefined).length
906
+ : 0;
907
+ return usageFields + [payload.request_id, payload.model, payload.stop_reason]
908
+ .filter((value) => value !== undefined).length;
909
+ }
910
+ function tokenUsageFingerprint(payload) {
911
+ const usage = payload.token_usage && typeof payload.token_usage === "object"
912
+ ? payload.token_usage
913
+ : {};
914
+ return JSON.stringify([
915
+ usage.input_tokens ?? null,
916
+ usage.cache_read_input_tokens ?? null,
917
+ usage.cache_creation_input_tokens ?? null,
918
+ usage.output_tokens ?? null,
919
+ usage.total_tokens ?? null,
920
+ ]);
921
+ }
922
+ function tokenUsageTotal(payload) {
923
+ const usage = payload.token_usage;
924
+ if (!usage || typeof usage !== "object")
925
+ return 0;
926
+ const u = usage;
927
+ const sum = (key) => (typeof u[key] === "number" ? u[key] : 0);
928
+ return sum("input_tokens") + sum("cache_read_input_tokens")
929
+ + sum("cache_creation_input_tokens") + sum("output_tokens");
930
+ }
931
+ export function createTokenUsageFragment(context, record, seqNo, timeKey, usage, stopReason, extraPayload = {}) {
932
+ const payload = {
933
+ token_usage: usage,
934
+ scope: "turn",
935
+ ...extraPayload,
936
+ };
937
+ if (typeof usage.total_tokens === "number") {
938
+ payload.token_count = usage.total_tokens;
939
+ }
940
+ if (usage.model) {
941
+ payload.model = usage.model;
942
+ }
943
+ if (stopReason) {
944
+ payload.stop_reason = stopReason;
945
+ }
946
+ return createFragment(context, record, seqNo, "token_usage_signal", timeKey, payload);
947
+ }
948
+ export function appendChunkedTextFragments(context, record, fragments, timeKey, actorKind, text, nextSeq, options = {}) {
949
+ let usageApplied = options.usageApplied ?? false;
950
+ const chunks = buildTextChunks(context.source.platform, actorKind, text, { filePath: context.filePath });
951
+ for (const chunk of chunks) {
952
+ const firstAssistantChunk = actorKind === "assistant" && !usageApplied;
953
+ fragments.push(createFragment(context, record, nextSeq++, "text", timeKey, {
954
+ ...buildTextFragmentPayload(actorKind, chunk, {
955
+ usage: firstAssistantChunk ? options.usage : undefined,
956
+ stopReason: firstAssistantChunk ? options.stopReason : undefined,
957
+ messageId: firstAssistantChunk ? options.messageId : undefined,
958
+ model: firstAssistantChunk ? options.model : undefined,
959
+ }),
960
+ }));
961
+ if (firstAssistantChunk) {
962
+ usageApplied = true;
963
+ }
964
+ }
965
+ return { nextSeq, usageApplied };
966
+ }
967
+ export function appendUnsupportedContentItem(context, record, fragments, lossAudits, timeKey, nextSeq, item, detail, diagnosticCode) {
968
+ lossAudits.push(createRecordLossAudit(context, record, "unknown_fragment", detail, {
969
+ diagnosticCode,
970
+ }));
971
+ fragments.push(createFragment(context, record, nextSeq, "unknown", timeKey, item));
972
+ return nextSeq + 1;
973
+ }
974
+ export async function extractConversationExportSeeds(source, filePath, fileBuffer, _blobId) {
975
+ if (source.platform === "opencode") {
976
+ const opencodeSeed = await extractOpenCodeSessionSeed(filePath, fileBuffer);
977
+ if (opencodeSeed) {
978
+ return [opencodeSeed];
979
+ }
980
+ }
981
+ if (source.platform === "gemini") {
982
+ const geminiSeed = await extractGeminiSessionSeed(source.base_dir, filePath, fileBuffer);
983
+ if (geminiSeed) {
984
+ return [geminiSeed];
985
+ }
986
+ }
987
+ const parsed = safeJsonParse(fileBuffer.toString("utf8"));
988
+ const seeds = collectConversationSeedsFromValue(source.platform, parsed, path.basename(filePath, path.extname(filePath)));
989
+ return seeds.length > 0 ? seeds : undefined;
990
+ }
991
+ export async function readOptionalJsonFile(targetPath) {
992
+ try {
993
+ const raw = await fs.readFile(targetPath, "utf8");
994
+ const parsed = safeJsonParse(raw);
995
+ return isObject(parsed) ? parsed : undefined;
996
+ }
997
+ catch {
998
+ return undefined;
999
+ }
1000
+ }
1001
+ export function extractMarkdownHeading(text) {
1002
+ const firstHeading = text
1003
+ .split(/\r?\n/u)
1004
+ .map((line) => line.trim())
1005
+ .find((line) => line.startsWith("#"));
1006
+ return firstHeading?.replace(/^#+\s*/u, "").trim() || undefined;
1007
+ }
1008
+ export function collectConversationSeedsFromValue(platform, value, originHint, options = {}) {
1009
+ return collectConversationSeedsFromValueRuntime(platform, value, originHint, {
1010
+ asString,
1011
+ asNumber,
1012
+ asArray,
1013
+ isObject,
1014
+ coerceIso,
1015
+ epochMillisToIso,
1016
+ nowIso,
1017
+ truncate,
1018
+ sha1,
1019
+ normalizeWorkspacePath,
1020
+ extractGenericSessionMetadata,
1021
+ extractGenericRole,
1022
+ extractGenericContentItems,
1023
+ extractTokenUsage,
1024
+ normalizeStopReason,
1025
+ extractRichTextText,
1026
+ stringifyToolContent,
1027
+ }, options);
1028
+ }
1029
+ export function normalizeMessageCandidate(value, defaultWorkingDirectory) {
1030
+ return normalizeMessageCandidateRuntime(value, {
1031
+ asString,
1032
+ asNumber,
1033
+ asArray,
1034
+ isObject,
1035
+ coerceIso,
1036
+ epochMillisToIso,
1037
+ nowIso,
1038
+ truncate,
1039
+ sha1,
1040
+ normalizeWorkspacePath,
1041
+ extractGenericSessionMetadata,
1042
+ extractGenericRole,
1043
+ extractGenericContentItems,
1044
+ extractTokenUsage,
1045
+ normalizeStopReason,
1046
+ extractRichTextText,
1047
+ stringifyToolContent,
1048
+ }, defaultWorkingDirectory);
1049
+ }
1050
+ export async function extractGeminiSessionSeed(baseDir, filePath, fileBuffer) {
1051
+ const parsed = safeJsonParse(fileBuffer.toString("utf8"));
1052
+ if (!isObject(parsed)) {
1053
+ return undefined;
1054
+ }
1055
+ const rawSessionId = asString(parsed.sessionId) ??
1056
+ asString(parsed.id) ??
1057
+ path.basename(filePath, path.extname(filePath));
1058
+ const sessionId = `sess:gemini:${rawSessionId}`;
1059
+ const projectKey = extractGeminiProjectKey(filePath);
1060
+ const geminiRoot = resolveGeminiRoot(baseDir, filePath);
1061
+ const projectMetadata = geminiRoot && projectKey ? await resolveGeminiProjectMetadata(geminiRoot, projectKey) : {};
1062
+ const title = projectMetadata.title ?? projectKey;
1063
+ const workingDirectory = projectMetadata.workingDirectory;
1064
+ const createdAt = coerceIso(parsed.startTime) ??
1065
+ coerceIso(parsed.createdAt) ??
1066
+ coerceIso(parsed.created_at);
1067
+ const updatedAt = coerceIso(parsed.lastUpdated) ??
1068
+ coerceIso(parsed.updatedAt) ??
1069
+ coerceIso(parsed.updated_at) ??
1070
+ createdAt;
1071
+ const model = asString(parsed.model);
1072
+ const seeds = collectConversationSeedsFromValue("gemini", parsed, rawSessionId, {
1073
+ defaultSessionId: sessionId,
1074
+ defaultTitle: title,
1075
+ defaultWorkingDirectory: workingDirectory,
1076
+ });
1077
+ const seed = seeds[0];
1078
+ if (!seed) {
1079
+ return undefined;
1080
+ }
1081
+ return {
1082
+ sessionId: seed.sessionId,
1083
+ title: seed.title ?? title,
1084
+ createdAt: minIso(seed.createdAt, createdAt),
1085
+ updatedAt: maxIso(seed.updatedAt, updatedAt),
1086
+ model: seed.model ?? model,
1087
+ workingDirectory: seed.workingDirectory ?? workingDirectory,
1088
+ records: seed.records,
1089
+ };
1090
+ }
1091
+ export async function resolveGeminiProjectMetadata(geminiRoot, projectKey) {
1092
+ const tmpProjectRoot = await readOptionalTextFile(path.join(geminiRoot, "tmp", projectKey, ".project_root"));
1093
+ const historyProjectRoot = await readOptionalTextFile(path.join(geminiRoot, "history", projectKey, ".project_root"));
1094
+ const projectRootPath = tmpProjectRoot ?? historyProjectRoot;
1095
+ let workingDirectory = projectRootPath ? normalizeWorkspacePath(projectRootPath) : undefined;
1096
+ const projectsFile = await readOptionalJsonFile(path.join(geminiRoot, "projects.json"));
1097
+ const projects = isObject(projectsFile?.projects) ? projectsFile.projects : undefined;
1098
+ let title;
1099
+ if (workingDirectory && projects) {
1100
+ title = asString(projects[workingDirectory]);
1101
+ }
1102
+ if (!workingDirectory && projects) {
1103
+ for (const [workspacePath, label] of Object.entries(projects)) {
1104
+ if (asString(label) === projectKey) {
1105
+ workingDirectory = normalizeWorkspacePath(workspacePath);
1106
+ title = projectKey;
1107
+ break;
1108
+ }
1109
+ }
1110
+ }
1111
+ return {
1112
+ workingDirectory,
1113
+ title: title ?? projectKey,
1114
+ };
1115
+ }
1116
+ export async function readOptionalTextFile(targetPath) {
1117
+ try {
1118
+ const raw = await fs.readFile(targetPath, "utf8");
1119
+ const trimmed = raw.trim();
1120
+ return trimmed || undefined;
1121
+ }
1122
+ catch {
1123
+ return undefined;
1124
+ }
1125
+ }
1126
+ export async function extractOpenCodeSessionSeed(filePath, fileBuffer) {
1127
+ const parsed = safeJsonParse(fileBuffer.toString("utf8"));
1128
+ if (!isObject(parsed)) {
1129
+ return undefined;
1130
+ }
1131
+ const rawSessionId = asString(parsed.id) ??
1132
+ asString(parsed.sessionId) ??
1133
+ asString(parsed.session_id) ??
1134
+ path.basename(filePath, path.extname(filePath));
1135
+ const sessionId = `sess:opencode:${rawSessionId}`;
1136
+ const storageRoot = resolveOpenCodeStorageRoot(filePath);
1137
+ const messageDir = storageRoot ? path.join(storageRoot, "message", rawSessionId) : undefined;
1138
+ const records = [];
1139
+ const meta = extractGenericSessionMetadata(parsed);
1140
+ const time = isObject(parsed.time) ? parsed.time : undefined;
1141
+ const title = meta.title ?? asString(parsed.title) ?? asString(parsed.name);
1142
+ const model = meta.model ?? asString(parsed.model);
1143
+ const workingDirectory = meta.workspacePath ??
1144
+ (typeof parsed.directory === "string" ? normalizeWorkspacePath(parsed.directory) : undefined);
1145
+ const createdAt = coerceIso(parsed.createdAt) ??
1146
+ coerceIso(parsed.created_at) ??
1147
+ epochMillisToIso(asNumber(parsed.createdAt)) ??
1148
+ epochMillisToIso(asNumber(parsed.created)) ??
1149
+ epochMillisToIso(asNumber(time?.created));
1150
+ const updatedAt = coerceIso(parsed.updatedAt) ??
1151
+ coerceIso(parsed.updated_at) ??
1152
+ epochMillisToIso(asNumber(parsed.updatedAt)) ??
1153
+ epochMillisToIso(asNumber(parsed.updated)) ??
1154
+ epochMillisToIso(asNumber(time?.updated));
1155
+ let childAgentKey;
1156
+ if (messageDir && (await pathExists(messageDir))) {
1157
+ const messageFiles = (await fs.readdir(messageDir))
1158
+ .filter((name) => name.endsWith(".json"))
1159
+ .sort();
1160
+ for (const [index, name] of messageFiles.entries()) {
1161
+ const content = await fs.readFile(path.join(messageDir, name), "utf8");
1162
+ const parsedMessage = safeJsonParse(content);
1163
+ const enrichedMessage = await normalizeOpenCodeMessageEnvelope(parsedMessage, storageRoot, rawSessionId, workingDirectory);
1164
+ childAgentKey = childAgentKey ?? (isObject(enrichedMessage) ? asString(enrichedMessage.agentId) : undefined);
1165
+ const normalized = normalizeMessageCandidate(enrichedMessage ?? parsedMessage, workingDirectory);
1166
+ if (!normalized) {
1167
+ continue;
1168
+ }
1169
+ records.push({
1170
+ pointer: `messages[${index}]`,
1171
+ observedAt: normalized.observedAt ?? nowIso(),
1172
+ rawJson: JSON.stringify(normalized.record),
1173
+ });
1174
+ }
1175
+ }
1176
+ if (title || model || workingDirectory || meta.parentUuid || meta.isSidechain || childAgentKey) {
1177
+ records.unshift({
1178
+ pointer: "meta",
1179
+ observedAt: createdAt ?? updatedAt ?? nowIso(),
1180
+ rawJson: JSON.stringify({
1181
+ id: sessionId,
1182
+ title,
1183
+ model,
1184
+ cwd: workingDirectory,
1185
+ parentUuid: meta.parentUuid,
1186
+ isSidechain: meta.isSidechain,
1187
+ agentId: childAgentKey,
1188
+ }),
1189
+ });
1190
+ }
1191
+ if (records.length === 0) {
1192
+ const fallback = collectConversationSeedsFromValue("opencode", parsed, rawSessionId, {
1193
+ defaultSessionId: sessionId,
1194
+ defaultTitle: title,
1195
+ defaultWorkingDirectory: workingDirectory,
1196
+ });
1197
+ return fallback[0];
1198
+ }
1199
+ return {
1200
+ sessionId,
1201
+ title,
1202
+ createdAt,
1203
+ updatedAt,
1204
+ model,
1205
+ workingDirectory,
1206
+ records,
1207
+ };
1208
+ }
1209
+ export function resolveOpenCodeStorageRoot(filePath) {
1210
+ const normalizedPath = filePath.replace(/\\/g, "/");
1211
+ const parts = normalizedPath.split("/").filter(Boolean);
1212
+ const storageIndex = parts.lastIndexOf("storage");
1213
+ if (storageIndex === -1) {
1214
+ return undefined;
1215
+ }
1216
+ return `${normalizedPath.startsWith("/") ? "/" : ""}${parts.slice(0, storageIndex + 1).join("/")}`;
1217
+ }
1218
+ export async function normalizeOpenCodeMessageEnvelope(value, storageRoot, fallbackSessionId, defaultWorkingDirectory) {
1219
+ if (!isObject(value)) {
1220
+ return undefined;
1221
+ }
1222
+ const info = isObject(value.info) ? value.info : undefined;
1223
+ const time = isObject(value.time) ? value.time : undefined;
1224
+ const messagePath = isObject(value.path) ? value.path : undefined;
1225
+ const messageId = asString(value.id) ?? asString(info?.id);
1226
+ const workingDirectoryCandidate = asString(messagePath?.cwd) ?? defaultWorkingDirectory;
1227
+ const workingDirectory = workingDirectoryCandidate
1228
+ ? normalizeWorkspacePath(workingDirectoryCandidate)
1229
+ : undefined;
1230
+ const partPayload = storageRoot && messageId ? await readOpenCodePartPayload(storageRoot, messageId) : undefined;
1231
+ const inlineParts = Array.isArray(value.parts)
1232
+ ? value.parts.filter((entry) => isObject(entry))
1233
+ : [];
1234
+ const timestamp = coerceIso(value.timestamp) ??
1235
+ coerceIso(info?.timestamp) ??
1236
+ coerceIso(value.createdAt) ??
1237
+ coerceIso(info?.createdAt) ??
1238
+ epochMillisToIso(asNumber(time?.created));
1239
+ return {
1240
+ id: messageId,
1241
+ sessionId: asString(value.sessionID) ?? asString(value.sessionId) ?? fallbackSessionId,
1242
+ parentId: asString(value.parentID) ??
1243
+ asString(value.parentId) ??
1244
+ asString(info?.parentID) ??
1245
+ asString(info?.parentId),
1246
+ agentId: asString(value.agentId) ??
1247
+ asString(value.agent) ??
1248
+ asString(info?.agentId) ??
1249
+ asString(info?.agent),
1250
+ role: asString(value.role) ?? asString(info?.role),
1251
+ model: asString(value.modelID) ?? asString(value.model) ?? asString(info?.model),
1252
+ cwd: workingDirectory,
1253
+ timestamp,
1254
+ stopReason: asString(value.finish) ??
1255
+ asString(value.stopReason) ??
1256
+ asString(info?.stopReason) ??
1257
+ partPayload?.stopReason,
1258
+ usage: normalizeOpenCodeUsagePayload(value.tokens) ??
1259
+ normalizeOpenCodeUsagePayload(value.usage) ??
1260
+ partPayload?.usage,
1261
+ parts: [...inlineParts, ...(partPayload?.items ?? [])],
1262
+ };
1263
+ }
1264
+ export async function readOpenCodePartPayload(storageRoot, messageId) {
1265
+ const partDir = path.join(storageRoot, "part", messageId);
1266
+ if (!(await pathExists(partDir))) {
1267
+ return { items: [] };
1268
+ }
1269
+ const items = [];
1270
+ let usage;
1271
+ let stopReason;
1272
+ const partFiles = (await fs.readdir(partDir)).filter((name) => name.endsWith(".json")).sort();
1273
+ for (const name of partFiles) {
1274
+ const parsedPart = safeJsonParse(await fs.readFile(path.join(partDir, name), "utf8"));
1275
+ if (!isObject(parsedPart)) {
1276
+ continue;
1277
+ }
1278
+ const partType = asString(parsedPart.type);
1279
+ if ((partType === "text" || partType === "reasoning") && typeof parsedPart.text === "string" && parsedPart.text.trim()) {
1280
+ items.push({ type: "text", text: parsedPart.text });
1281
+ continue;
1282
+ }
1283
+ if (partType === "tool") {
1284
+ const state = isObject(parsedPart.state) ? parsedPart.state : undefined;
1285
+ const callId = asString(parsedPart.callID) ?? asString(parsedPart.callId);
1286
+ const toolName = asString(parsedPart.tool) ?? asString(parsedPart.name);
1287
+ items.push({
1288
+ type: "tool_call",
1289
+ id: callId,
1290
+ name: toolName,
1291
+ input: state?.input,
1292
+ });
1293
+ if (state?.output !== undefined || state?.result !== undefined || state?.metadata !== undefined) {
1294
+ items.push({
1295
+ type: "tool_result",
1296
+ tool_use_id: callId,
1297
+ content: state?.output ?? state?.result ?? state?.metadata ?? state,
1298
+ });
1299
+ }
1300
+ continue;
1301
+ }
1302
+ if (partType === "step-finish") {
1303
+ usage = normalizeOpenCodeUsagePayload(parsedPart.tokens) ?? usage;
1304
+ stopReason = asString(parsedPart.reason) ?? stopReason;
1305
+ }
1306
+ }
1307
+ return { items, usage, stopReason };
1308
+ }
1309
+ export function normalizeOpenCodeUsagePayload(value) {
1310
+ if (!isObject(value)) {
1311
+ return undefined;
1312
+ }
1313
+ const cache = isObject(value.cache) ? value.cache : undefined;
1314
+ const inputTokens = asNumber(value.input);
1315
+ const outputTokens = asNumber(value.output);
1316
+ const reasoningTokens = asNumber(value.reasoning);
1317
+ const cacheReadTokens = asNumber(cache?.read);
1318
+ const cacheCreationTokens = asNumber(cache?.write);
1319
+ const totalTokens = sumDefinedNumbers(inputTokens, outputTokens, reasoningTokens, cacheReadTokens, cacheCreationTokens);
1320
+ if (inputTokens === undefined &&
1321
+ outputTokens === undefined &&
1322
+ reasoningTokens === undefined &&
1323
+ cacheReadTokens === undefined &&
1324
+ cacheCreationTokens === undefined) {
1325
+ return undefined;
1326
+ }
1327
+ return {
1328
+ inputTokens,
1329
+ outputTokens,
1330
+ reasoningTokens,
1331
+ cacheReadTokens,
1332
+ cacheCreationTokens,
1333
+ totalTokens,
1334
+ };
1335
+ }
1336
+ export function extractRichTextText(value) {
1337
+ const parsed = safeJsonParse(value);
1338
+ const parts = [];
1339
+ const visit = (candidate) => {
1340
+ if (typeof candidate === "string") {
1341
+ return;
1342
+ }
1343
+ if (Array.isArray(candidate)) {
1344
+ for (const entry of candidate) {
1345
+ visit(entry);
1346
+ }
1347
+ return;
1348
+ }
1349
+ if (!isObject(candidate)) {
1350
+ return;
1351
+ }
1352
+ if (typeof candidate.text === "string") {
1353
+ parts.push(candidate.text);
1354
+ }
1355
+ for (const entry of Object.values(candidate)) {
1356
+ if (entry && typeof entry === "object") {
1357
+ visit(entry);
1358
+ }
1359
+ }
1360
+ };
1361
+ visit(parsed);
1362
+ const text = parts.join("").trim();
1363
+ return text || undefined;
1364
+ }
1365
+ function applyCursorTranscriptWorkspace(filePath, parsed, draft) {
1366
+ if (draft.working_directory ||
1367
+ parsed.cwd ||
1368
+ parsed.workingDirectory ||
1369
+ parsed.working_directory ||
1370
+ parsed.workspacePath) {
1371
+ return parsed;
1372
+ }
1373
+ const workspacePath = resolveCursorTranscriptWorkspacePath(filePath, {
1374
+ safeJsonParse,
1375
+ isObject,
1376
+ asString,
1377
+ normalizeWorkspacePath,
1378
+ });
1379
+ if (!workspacePath) {
1380
+ return parsed;
1381
+ }
1382
+ draft.working_directory = workspacePath;
1383
+ return { ...parsed, cwd: workspacePath };
1384
+ }
1385
+ async function loadExtractVscodeStateSeeds() {
1386
+ vscodeStateExtractorPromise ??= import("./vscode-state.js").then((module) => module.extractVscodeStateSeeds);
1387
+ return vscodeStateExtractorPromise;
1388
+ }
1389
+ //# sourceMappingURL=parser.js.map