@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,1180 @@
1
+ import { access, realpath, stat } from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { deriveHostId, deriveSourceInstanceId, normalizeLocalPathIdentity, } from "@cchistory/domain";
5
+ import { auditProjectionConsistency, buildSessionLastMessageIndex, buildDirectoryScopedProjectTreeProjection, buildFallbackProjectObservationCandidates, buildProjectDisplayList, buildSessionRelatedWorkIndex, compareTurnsByChronology, compareTurnsByRecency, computeUsageOverview, computeUsageRollup, deriveProjectLinkSnapshot, filterProjectsByDirectoryScope, filterSessionsByDirectoryScope, filterTopLevelSessions, filterTurnsByDirectoryScope, buildSessionFamilyInventory, FAMILY_IO_PREVIEW_CHARS, listDelegatedRelationsForFamilyChildren, listSessionFamilies, mergeSessionFamilyInventories, installRuntimeWarningFilter, orderSessionsByLastMessage, pathMatchesDirectoryScope, searchSessionsInMemory, searchTurnsInMemory, resolveTurnUsage, summarizeSessionUsage, } from "@cchistory/canonical";
6
+ import { applyMaskTemplates } from "@cchistory/source-adapters";
7
+ import { SAMPLE_RANK_CONCURRENCY, mapPool } from "./async-pool.js";
8
+ export { buildAdaptiveNodeExecArgv, calculateAdaptiveOldSpaceMiB, isAdaptiveNodeMemoryApplied, runWithAdaptiveNodeMemory, } from "./node-memory.js";
9
+ installRuntimeWarningFilter();
10
+ export function maskCompactPreview(value, kind) {
11
+ if (!value?.trim())
12
+ return undefined;
13
+ const masked = applyMaskTemplates(value, kind).canonical_text.replace(/\s+/gu, " ").trim();
14
+ if (!masked)
15
+ return undefined;
16
+ if (kind === "user_message" || masked.length <= FAMILY_IO_PREVIEW_CHARS)
17
+ return masked;
18
+ return `${masked.slice(0, FAMILY_IO_PREVIEW_CHARS - 1)}…`;
19
+ }
20
+ export class AmbiguousReferenceError extends Error {
21
+ ref;
22
+ candidateIds;
23
+ constructor(ref, candidateIds, prefix) {
24
+ super(`${prefix ? "Ambiguous ID prefix" : "Ambiguous reference"} ${JSON.stringify(ref)} matched ${candidateIds.length} objects.`);
25
+ this.name = "AmbiguousReferenceError";
26
+ this.ref = ref;
27
+ this.candidateIds = [...candidateIds];
28
+ }
29
+ }
30
+ export class LiveHistorySnapshot {
31
+ data;
32
+ /** Non-fatal projection diagnostics kept visible to read-only surfaces. */
33
+ projectionIssues;
34
+ sourcesById;
35
+ projectsById;
36
+ sessionsById;
37
+ relatedWorkBySessionId;
38
+ turnsById;
39
+ contextsByTurnId;
40
+ lastMessageAtBySessionId;
41
+ searchCandidates;
42
+ contributionsBySessionId;
43
+ childrenByParentId;
44
+ familiesByParentId;
45
+ families;
46
+ // Snapshot data is immutable, so derived indexes and ranked searches are
47
+ // memoized for the lifetime of the instance (a refresh builds a new one).
48
+ turnsBySessionId;
49
+ turnsByProjectId;
50
+ searchRankCache;
51
+ sessionSearchRankCache;
52
+ constructor(data, searchCandidates = []) {
53
+ this.data = {
54
+ ...data,
55
+ related_work: data.related_work ?? [],
56
+ session_contributions: data.session_contributions ?? [],
57
+ delegated_children: data.delegated_children ?? [],
58
+ };
59
+ this.projectionIssues = auditProjectionConsistency(this.data);
60
+ this.sourcesById = new Map(data.sources.map((source) => [source.id, source]));
61
+ this.projectsById = new Map(data.projects.map((project) => [project.project_id, project]));
62
+ this.sessionsById = new Map(this.data.sessions.map((session) => [session.id, session]));
63
+ this.relatedWorkBySessionId = new Map();
64
+ for (const entry of this.data.related_work) {
65
+ const related = this.relatedWorkBySessionId.get(entry.query_session_ref);
66
+ if (related)
67
+ related.push(entry);
68
+ else
69
+ this.relatedWorkBySessionId.set(entry.query_session_ref, [entry]);
70
+ }
71
+ this.turnsById = new Map(data.turns.map((turn) => [turn.id, turn]));
72
+ this.lastMessageAtBySessionId = buildSessionLastMessageIndex(data.turns);
73
+ this.contextsByTurnId = new Map(data.contexts.map((context) => [context.turn_id, context]));
74
+ this.searchCandidates = searchCandidates;
75
+ this.contributionsBySessionId = new Map(this.data.session_contributions.map((entry) => [entry.session_ref, entry]));
76
+ this.families = listSessionFamilies(this.data.sessions, {
77
+ contributions: this.data.session_contributions,
78
+ children: this.data.delegated_children,
79
+ });
80
+ this.familiesByParentId = new Map(this.families.map((family) => [family.parent_session_ref, family]));
81
+ this.data.delegated_children = this.families.flatMap((family) => family.children);
82
+ this.childrenByParentId = new Map();
83
+ for (const child of this.data.delegated_children) {
84
+ const siblings = this.childrenByParentId.get(child.parent_session_ref) ?? [];
85
+ siblings.push(child);
86
+ this.childrenByParentId.set(child.parent_session_ref, siblings);
87
+ }
88
+ }
89
+ listSources() {
90
+ return [...this.data.sources];
91
+ }
92
+ listProjects(options = {}) {
93
+ return buildProjectDisplayList(filterProjectsByDirectoryScope({
94
+ projects: this.data.projects,
95
+ sessions: this.data.sessions,
96
+ turns: this.data.turns,
97
+ directoryScope: options.directoryScope,
98
+ }));
99
+ }
100
+ listResolvedSessions(options = {}) {
101
+ return filterSessionsByDirectoryScope(this.data.sessions, options.directoryScope);
102
+ }
103
+ listTopLevelSessions(options = {}) {
104
+ return filterSessionsByDirectoryScope(filterTopLevelSessions(this.data.sessions, this.data.related_work), options.directoryScope);
105
+ }
106
+ listResolvedTurns(options = {}) {
107
+ return filterTurnsByDirectoryScope(this.data.turns, this.data.sessions, options.directoryScope);
108
+ }
109
+ getSessionActivityAt(sessionRef) {
110
+ const session = this.getSession(sessionRef);
111
+ return session ? this.lastMessageAtBySessionId.get(session.id) ?? session.updated_at : undefined;
112
+ }
113
+ getProjectsTreeProjection(options = {}) {
114
+ return buildDirectoryScopedProjectTreeProjection({
115
+ projects: this.listProjects(),
116
+ sessions: this.data.sessions,
117
+ turns: this.data.turns,
118
+ relatedWork: this.data.related_work,
119
+ directoryScope: options.directoryScope,
120
+ });
121
+ }
122
+ listSessionRelatedWork(sessionRef) {
123
+ const session = this.getSession(sessionRef);
124
+ return session ? [...(this.relatedWorkBySessionId.get(session.id) ?? [])] : [];
125
+ }
126
+ getSessionContribution(sessionRef) {
127
+ const session = this.getSession(sessionRef);
128
+ if (!session)
129
+ return undefined;
130
+ return this.contributionsBySessionId.get(session.id);
131
+ }
132
+ listDelegatedChildren(sessionRef) {
133
+ const session = this.getSession(sessionRef);
134
+ if (!session)
135
+ return [];
136
+ return [...(this.childrenByParentId.get(session.id) ?? [])];
137
+ }
138
+ getSessionFamily(sessionRef) {
139
+ const session = this.getSession(sessionRef);
140
+ if (!session)
141
+ return undefined;
142
+ return this.familiesByParentId.get(session.id);
143
+ }
144
+ listSessionFamilies(options = {}) {
145
+ if (!options.directoryScope)
146
+ return [...this.families];
147
+ const allowed = new Set(this.listResolvedSessions(options).map((session) => session.id));
148
+ return this.families.filter((family) => allowed.has(family.parent_session_ref));
149
+ }
150
+ listAskUserQuestionTurns(filter = {}) {
151
+ return this.data.ask_user_question_turns.filter((turn) => {
152
+ if (filter.sourceId && turn.source_id !== filter.sourceId)
153
+ return false;
154
+ if (filter.sessionId && turn.session_id !== filter.sessionId)
155
+ return false;
156
+ return true;
157
+ });
158
+ }
159
+ listLossAudits() {
160
+ return [...this.data.loss_audits];
161
+ }
162
+ getSource(ref) {
163
+ const exact = this.sourcesById.get(ref);
164
+ if (exact)
165
+ return exact;
166
+ return resolveUnique(this.data.sources, ref, (source) => source.id, (source) => [source.slot_id, source.platform, source.display_name, source.base_dir]);
167
+ }
168
+ getProject(ref) {
169
+ const exact = this.projectsById.get(ref);
170
+ if (exact)
171
+ return exact;
172
+ return resolveUnique(this.data.projects, ref, (project) => project.project_id, (project) => [
173
+ project.slug,
174
+ project.display_name,
175
+ project.primary_workspace_path,
176
+ path.basename(project.primary_workspace_path ?? ""),
177
+ ]);
178
+ }
179
+ getSession(ref) {
180
+ const exact = this.sessionsById.get(ref);
181
+ if (exact)
182
+ return exact;
183
+ return resolveUnique(this.data.sessions, ref, (session) => session.id, (session) => [
184
+ session.source_session_id,
185
+ session.title,
186
+ session.working_directory,
187
+ path.basename(session.working_directory ?? ""),
188
+ ], (session) => [session.source_session_id]);
189
+ }
190
+ getSessionDisplayRef(sessionRef, minimumLength = 8) {
191
+ const session = this.getSession(sessionRef);
192
+ if (!session)
193
+ return undefined;
194
+ const nativeRef = session.source_session_id;
195
+ if (nativeRef) {
196
+ const minimum = Math.min(Math.max(1, minimumLength), nativeRef.length);
197
+ for (let length = minimum; length <= nativeRef.length; length += 1) {
198
+ const candidate = nativeRef.slice(0, length);
199
+ try {
200
+ if (this.getSession(candidate)?.id === session.id)
201
+ return candidate;
202
+ }
203
+ catch {
204
+ // Keep extending until the reference resolves uniquely.
205
+ }
206
+ }
207
+ }
208
+ return session.id;
209
+ }
210
+ getTurn(ref) {
211
+ const exact = this.turnsById.get(ref);
212
+ if (exact)
213
+ return exact;
214
+ return resolveUnique(this.data.turns, ref, (turn) => turn.id, () => []);
215
+ }
216
+ getTurnDisplayRef(turnRef, minimumLength = 8) {
217
+ const turn = this.getTurn(turnRef);
218
+ if (!turn)
219
+ return undefined;
220
+ const minimum = Math.min(Math.max(1, minimumLength), turn.id.length);
221
+ for (let length = minimum; length <= turn.id.length; length += 1) {
222
+ const candidate = turn.id.slice(0, length);
223
+ try {
224
+ if (this.getTurn(candidate)?.id === turn.id)
225
+ return candidate;
226
+ }
227
+ catch {
228
+ // Keep extending until the reference resolves uniquely.
229
+ }
230
+ }
231
+ return turn.id;
232
+ }
233
+ getTurnContext(turnRef) {
234
+ const turn = this.getTurn(turnRef);
235
+ return turn ? this.contextsByTurnId.get(turn.id) : undefined;
236
+ }
237
+ getTurnUsage(turnRef) {
238
+ const turn = this.getTurn(turnRef);
239
+ return turn ? resolveTurnUsage(turn) : undefined;
240
+ }
241
+ getSessionUsage(sessionRef) {
242
+ const session = this.getSession(sessionRef);
243
+ return session ? summarizeSessionUsage(this.sessionTurnBuckets().get(session.id) ?? []) : undefined;
244
+ }
245
+ listProjectTurns(projectRef, options = {}) {
246
+ const project = this.getProject(projectRef);
247
+ if (!project)
248
+ return [];
249
+ return filterTurnsByDirectoryScope(this.projectTurnBuckets().get(project.project_id) ?? [], this.data.sessions, options.directoryScope);
250
+ }
251
+ listSessionTurns(sessionRef) {
252
+ const session = this.getSession(sessionRef);
253
+ if (!session)
254
+ return [];
255
+ return [...(this.sessionTurnBuckets().get(session.id) ?? [])];
256
+ }
257
+ search(options = {}) {
258
+ const limit = Math.max(0, options.limit ?? 50);
259
+ const offset = Math.max(0, options.offset ?? 0);
260
+ const cacheKey = JSON.stringify([
261
+ options.query ?? "",
262
+ options.projectId ?? null,
263
+ options.sourceIds ?? null,
264
+ options.directoryScope ?? null,
265
+ ]);
266
+ this.searchRankCache ??= new Map();
267
+ let ranked = this.searchRankCache.get(cacheKey);
268
+ if (!ranked) {
269
+ ranked = searchTurnsInMemory({
270
+ turns: filterTurnsByDirectoryScope(this.data.turns, this.data.sessions, options.directoryScope),
271
+ sessions: this.data.sessions,
272
+ projects: this.data.projects,
273
+ candidates: this.searchCandidates,
274
+ query: options.query,
275
+ project_id: options.projectId,
276
+ source_ids: options.sourceIds,
277
+ limit: Infinity,
278
+ offset: 0,
279
+ }).results;
280
+ this.searchRankCache.set(cacheKey, ranked);
281
+ }
282
+ return { results: ranked.slice(offset, offset + limit), total: ranked.length };
283
+ }
284
+ searchSessions(options = {}) {
285
+ const limit = Math.max(0, options.limit ?? 50);
286
+ const offset = Math.max(0, options.offset ?? 0);
287
+ const cacheKey = JSON.stringify([
288
+ options.query ?? "",
289
+ options.projectId ?? null,
290
+ options.sourceIds ?? null,
291
+ options.directoryScope ?? null,
292
+ ]);
293
+ this.sessionSearchRankCache ??= new Map();
294
+ let ranked = this.sessionSearchRankCache.get(cacheKey);
295
+ if (!ranked) {
296
+ ranked = searchSessionsInMemory({
297
+ turns: filterTurnsByDirectoryScope(this.data.turns, this.data.sessions, options.directoryScope),
298
+ sessions: filterSessionsByDirectoryScope(this.data.sessions, options.directoryScope),
299
+ projects: this.data.projects,
300
+ candidates: this.searchCandidates,
301
+ related_work: this.data.related_work,
302
+ query: options.query,
303
+ project_id: options.projectId,
304
+ source_ids: options.sourceIds,
305
+ limit: Infinity,
306
+ offset: 0,
307
+ }).results;
308
+ this.sessionSearchRankCache.set(cacheKey, ranked);
309
+ }
310
+ return { results: ranked.slice(offset, offset + limit), total: ranked.length };
311
+ }
312
+ sessionTurnBuckets() {
313
+ if (!this.turnsBySessionId) {
314
+ const buckets = new Map();
315
+ for (const turn of this.data.turns) {
316
+ const bucket = buckets.get(turn.session_id);
317
+ if (bucket)
318
+ bucket.push(turn);
319
+ else
320
+ buckets.set(turn.session_id, [turn]);
321
+ }
322
+ for (const bucket of buckets.values())
323
+ bucket.sort(compareTurnsByChronology);
324
+ this.turnsBySessionId = buckets;
325
+ }
326
+ return this.turnsBySessionId;
327
+ }
328
+ projectTurnBuckets() {
329
+ if (!this.turnsByProjectId) {
330
+ const buckets = new Map();
331
+ for (const turn of this.data.turns) {
332
+ if (!turn.project_id)
333
+ continue;
334
+ const bucket = buckets.get(turn.project_id);
335
+ if (bucket)
336
+ bucket.push(turn);
337
+ else
338
+ buckets.set(turn.project_id, [turn]);
339
+ }
340
+ this.turnsByProjectId = buckets;
341
+ }
342
+ return this.turnsByProjectId;
343
+ }
344
+ getUsageOverview(filters = {}) {
345
+ return computeUsageOverview({
346
+ filters,
347
+ listResolvedTurns: () => this.data.turns,
348
+ listResolvedSessions: () => this.data.sessions,
349
+ listSources: () => this.data.sources,
350
+ listProjects: () => this.data.projects,
351
+ });
352
+ }
353
+ getUsageRollup(dimension, filters = {}) {
354
+ return computeUsageRollup({
355
+ dimension,
356
+ filters,
357
+ listResolvedTurns: () => this.data.turns,
358
+ listResolvedSessions: () => this.data.sessions,
359
+ listSources: () => this.data.sources,
360
+ listProjects: () => this.data.projects,
361
+ });
362
+ }
363
+ }
364
+ export async function scanLiteHistory(options = {}) {
365
+ if (options.contextMode === "matching" && resolveContextTargets(options).length === 0) {
366
+ throw new Error("matching context mode requires at least one context target.");
367
+ }
368
+ let sources = await resolveLiteSources(options);
369
+ const exactPlatforms = exactCanonicalSessionPlatforms(options.sessionRefs ?? []);
370
+ if (exactPlatforms.size > 0) {
371
+ sources = sources.filter((source) => exactPlatforms.has(source.platform));
372
+ if (sources.length === 0) {
373
+ throw new Error(`No selected Lite source can resolve requested session ${options.sessionRefs?.join(", ")}.`);
374
+ }
375
+ }
376
+ const sourceAdapters = await import("@cchistory/source-adapters");
377
+ const contextMode = options.contextMode ?? "full";
378
+ const scanSources = async (scanOptions) => {
379
+ const nextPayloads = [];
380
+ let nextHost;
381
+ // Rebuild the native file inventory on every invocation, then scan one
382
+ // source at a time so raw adapter payloads can be released promptly. Each
383
+ // adapter explicitly declares its minimum safe projection boundary; the
384
+ // runtime never infers independence from a file-oriented source shape.
385
+ for (const source of sources) {
386
+ const adapter = sourceAdapters.listPlatformAdapters().find((entry) => entry.platform === source.platform);
387
+ const result = adapter?.projectionBoundary === "logical_session"
388
+ ? await scanLogicalSessionGroups(source, scanOptions, contextMode, sourceAdapters, (filePaths, includeWorkspaceMetadata) => sourceAdapters.inspectSourceFilesLogicalSessionMetadata(source.platform, filePaths, {
389
+ includeWorkspaceMetadata,
390
+ workspaceScan: source.platform === "codex" && scanOptions.directoryScope ? "first" : "full",
391
+ }))
392
+ : await scanSourceWithCollector(source, scanOptions, contextMode, sourceAdapters);
393
+ nextHost ??= result.host;
394
+ nextPayloads.push(result.payload);
395
+ }
396
+ if (!nextHost) {
397
+ const emptyProbe = await sourceAdapters.runSourceProbe({}, []);
398
+ nextHost = emptyProbe.host;
399
+ }
400
+ return { host: nextHost, payloads: nextPayloads };
401
+ };
402
+ let { host, payloads } = await scanSources(options);
403
+ const requestedSessionRefs = options.sessionRefs?.filter((ref) => ref.trim().length > 0) ?? [];
404
+ if (requestedSessionRefs.length === 0)
405
+ return buildLiveSnapshot({ host, sources: payloads });
406
+ const missingChildRefs = missingDelegatedChildSessionRefs(payloads, requestedSessionRefs);
407
+ if (missingChildRefs.length > 0) {
408
+ ({ host, payloads } = await scanSources({
409
+ ...options,
410
+ sessionRefs: [...requestedSessionRefs, ...missingChildRefs],
411
+ }));
412
+ }
413
+ const combined = buildLiveSnapshot({ host, sources: payloads });
414
+ const resolvedSessionRefs = requestedSessionRefs.map((ref) => {
415
+ const session = combined.getSession(ref);
416
+ if (!session)
417
+ throw new Error(`Lite scan did not find requested session ${ref}.`);
418
+ return session.id;
419
+ });
420
+ return buildLiveSnapshot({
421
+ host,
422
+ sources: payloads.map((payload) => filterLiveSourcePayloadBySessions(payload, resolvedSessionRefs)),
423
+ });
424
+ }
425
+ export function buildLiveSnapshot(probe) {
426
+ const sources = probe.sources.map((payload) => payload.source);
427
+ const turns = probe.sources
428
+ .flatMap((payload) => payload.turns)
429
+ .sort(compareTurnsByRecency);
430
+ const sessions = orderSessionsByLastMessage(probe.sources.flatMap((payload) => payload.sessions), turns);
431
+ const candidates = probe.sources.flatMap((payload) => payload.candidates);
432
+ const blobs = probe.sources.flatMap((payload) => payload.blobs);
433
+ const blobsById = new Map(blobs.map((blob) => [blob.id, blob]));
434
+ const fallbackCandidates = buildFallbackProjectObservationCandidates({
435
+ sessions,
436
+ turns,
437
+ candidates,
438
+ sources,
439
+ selectBlobsByIds: (ids) => ids.flatMap((id) => {
440
+ const blob = blobsById.get(id);
441
+ return blob ? [blob] : [];
442
+ }),
443
+ });
444
+ const linked = deriveProjectLinkSnapshot({
445
+ sessions,
446
+ turns,
447
+ candidates: [...candidates, ...fallbackCandidates],
448
+ });
449
+ const relatedWork = probe.sources.flatMap((payload) => materializeRelatedWork(payload));
450
+ const family = mergeSessionFamilyInventories(probe.sources.map((payload) => familyInventoryForLivePayload(payload)));
451
+ const familyRelatedWork = [
452
+ ...relatedWork,
453
+ ...listDelegatedRelationsForFamilyChildren(linked.sessions, family.children, relatedWork),
454
+ ];
455
+ return new LiveHistorySnapshot(normalizeJsonShapeForJsonOutputMutating({
456
+ host: probe.host,
457
+ sources,
458
+ projects: linked.projects,
459
+ sessions: linked.sessions,
460
+ related_work: familyRelatedWork,
461
+ session_contributions: family.contributions,
462
+ delegated_children: family.children,
463
+ turns: linked.turns,
464
+ contexts: probe.sources.flatMap((payload) => payload.contexts),
465
+ ask_user_question_turns: probe.sources.flatMap((payload) => payload.ask_user_question_turns),
466
+ loss_audits: probe.sources.flatMap((payload) => payload.loss_audits),
467
+ }), candidates);
468
+ }
469
+ async function scanSourceWithCollector(source, options, contextMode, sourceAdapters, sourceFiles) {
470
+ let scopedFiles = sourceFiles;
471
+ const directoryScope = options.directoryScope;
472
+ if (scopedFiles === undefined && (directoryScope || options.sample)) {
473
+ const listed = await sourceAdapters.listSourceFiles(source.platform, source.base_dir, options.limitFiles);
474
+ scopedFiles = directoryScope
475
+ ? listed.filter((filePath) => sourceFileMayBeInDirectoryScope(sourceAdapters, source, filePath, directoryScope))
476
+ : listed;
477
+ }
478
+ if (options.sample && scopedFiles) {
479
+ scopedFiles = await selectSampleSourceFiles(source, scopedFiles, options.sample.perSource, sourceAdapters);
480
+ }
481
+ const probe = await sourceAdapters.runSourceProbe({
482
+ ...buildProbeOptions(source, options),
483
+ ...(scopedFiles ? { source_file_paths: { [source.id]: scopedFiles } } : {}),
484
+ }, [source]);
485
+ const payload = probe.sources[0];
486
+ if (!payload) {
487
+ throw new Error(`Lite source probe produced no payload for ${source.display_name}.`);
488
+ }
489
+ const compacted = compactSourcePayload(payload, contextMode, resolveContextTargets(options));
490
+ return {
491
+ host: probe.host,
492
+ payload: options.sessionRefs?.length
493
+ ? filterLiveSourcePayloadBySessions(compacted, options.sessionRefs)
494
+ : compacted,
495
+ };
496
+ }
497
+ async function scanLogicalSessionGroups(source, options, contextMode, sourceAdapters, inspectGroupFiles) {
498
+ const listedFiles = await sourceAdapters.listSourceFiles(source.platform, source.base_dir, options.limitFiles);
499
+ let files = options.directoryScope
500
+ ? listedFiles.filter((filePath) => sourceFileMayBeInDirectoryScope(sourceAdapters, source, filePath, options.directoryScope))
501
+ : listedFiles;
502
+ if (options.sample) {
503
+ if (options.directoryScope && files.length > 0) {
504
+ const inspected = await inspectGroupFiles(files, true);
505
+ files = files.filter((_filePath, index) => {
506
+ const metadata = inspected[index];
507
+ if (metadata.workingDirectoryState !== "known" || !metadata.workingDirectory)
508
+ return true;
509
+ return pathMatchesDirectoryScope(metadata.workingDirectory, options.directoryScope);
510
+ });
511
+ }
512
+ files = await selectSampleSourceFiles(source, files, options.sample.perSource, sourceAdapters);
513
+ }
514
+ if (files.length === 0) {
515
+ return scanSourceWithCollector(source, options, contextMode, sourceAdapters, []);
516
+ }
517
+ const filesByGroup = new Map();
518
+ const requestedSessionRefs = options.sessionRefs?.filter((ref) => ref.trim().length > 0) ?? [];
519
+ const inspectedFiles = await inspectGroupFiles(files, Boolean(options.directoryScope || requestedSessionRefs.length > 0));
520
+ if (inspectedFiles.some((metadata) => metadata.sessionKeyState === "uncertain")) {
521
+ return scanSourceWithCollector(source, options, contextMode, sourceAdapters, files);
522
+ }
523
+ for (const [fileIndex, filePath] of files.entries()) {
524
+ const metadata = inspectedFiles[fileIndex];
525
+ const key = metadata.sessionKey;
526
+ const group = filesByGroup.get(key);
527
+ if (group) {
528
+ group.files.push(filePath);
529
+ for (const ref of metadata.relatedSessionRefs ?? [])
530
+ group.relatedSessionRefs.add(ref);
531
+ if (group.workingDirectoryState === "uncertain" ||
532
+ metadata.workingDirectoryState === "uncertain" ||
533
+ (group.workingDirectoryState === "known" &&
534
+ metadata.workingDirectoryState === "known" &&
535
+ group.workingDirectory !== metadata.workingDirectory)) {
536
+ group.workingDirectoryState = "uncertain";
537
+ group.workingDirectory = undefined;
538
+ }
539
+ else if (group.workingDirectoryState === "absent" && metadata.workingDirectoryState === "known") {
540
+ group.workingDirectoryState = metadata.workingDirectoryState;
541
+ group.workingDirectory = metadata.workingDirectory;
542
+ }
543
+ }
544
+ else {
545
+ filesByGroup.set(key, {
546
+ files: [filePath],
547
+ workingDirectoryState: metadata.workingDirectoryState,
548
+ workingDirectory: metadata.workingDirectory,
549
+ relatedSessionRefs: new Set(metadata.relatedSessionRefs ?? []),
550
+ });
551
+ }
552
+ }
553
+ const directMatchingGroupEntries = [...filesByGroup.entries()]
554
+ .filter(([groupKey]) => requestedSessionRefs.some((ref) => sessionRefMatchesGroup(ref, groupKey, source)));
555
+ const relatedMatchingGroupEntries = [...filesByGroup.entries()]
556
+ .filter(([, group]) => requestedSessionRefs.some((ref) => [...group.relatedSessionRefs].some((relatedRef) => sessionRefMatchesGroup(ref, relatedRef, source))));
557
+ const companionRefs = new Set(directMatchingGroupEntries.flatMap(([, group]) => [...group.relatedSessionRefs]));
558
+ const matchingGroupEntries = [...filesByGroup.entries()].filter(([groupKey, group]) => directMatchingGroupEntries.some(([directKey]) => directKey === groupKey) ||
559
+ relatedMatchingGroupEntries.some(([relatedKey]) => relatedKey === groupKey) ||
560
+ [...companionRefs].some((ref) => sessionRefMatchesGroup(ref, groupKey, source)) ||
561
+ [...group.relatedSessionRefs].some((relatedRef) => directMatchingGroupEntries.some(([directKey]) => sessionRefMatchesGroup(relatedRef, directKey, source))));
562
+ const targetGroups = requestedSessionRefs.length === 0 || matchingGroupEntries.length === 0
563
+ ? [...filesByGroup.entries()]
564
+ : matchingGroupEntries;
565
+ const selectedGroupFiles = targetGroups
566
+ .filter(([, group]) => !options.directoryScope ||
567
+ group.workingDirectoryState !== "known" ||
568
+ !group.workingDirectory ||
569
+ pathMatchesDirectoryScope(group.workingDirectory, options.directoryScope))
570
+ .map(([, group]) => ({
571
+ files: group.files,
572
+ targetSessionRefs: matchingGroupEntries.length > 0
573
+ ? []
574
+ : requestedSessionRefs.length > 0
575
+ ? []
576
+ : undefined,
577
+ }));
578
+ if (selectedGroupFiles.length === 0) {
579
+ return scanSourceWithCollector(source, options, contextMode, sourceAdapters, []);
580
+ }
581
+ const blobsById = new Map();
582
+ const candidatesById = new Map();
583
+ const sessionsById = new Map();
584
+ const turnsById = new Map();
585
+ const contextsByTurnId = new Map();
586
+ const askTurnsById = new Map();
587
+ const sessionRelationFragments = [];
588
+ const familyInventories = [];
589
+ const lossAudits = [];
590
+ const fileProcessingErrors = [];
591
+ let totalRecords = 0;
592
+ let totalFragments = 0;
593
+ let totalAtoms = 0;
594
+ let requiresSourceCollector = false;
595
+ let forwardedSourceStart = false;
596
+ let host;
597
+ for (const group of selectedGroupFiles) {
598
+ const probe = await sourceAdapters.runSourceProbe({
599
+ ...buildProbeOptions(source, options, group.targetSessionRefs),
600
+ source_file_paths: { [source.id]: group.files },
601
+ on_progress: (event) => {
602
+ if (event.stage === "source_start") {
603
+ if (forwardedSourceStart)
604
+ return;
605
+ forwardedSourceStart = true;
606
+ }
607
+ if (event.stage === "source_done")
608
+ return;
609
+ if (event.stage === "file_error" && event.message) {
610
+ fileProcessingErrors.push(event.message);
611
+ }
612
+ options.onProgress?.(event);
613
+ },
614
+ }, [source]);
615
+ host ??= probe.host;
616
+ const groupPayload = probe.sources[0];
617
+ if (!groupPayload) {
618
+ throw new Error(`Lite source probe produced no payload for ${source.display_name}.`);
619
+ }
620
+ totalRecords += groupPayload.source.total_records;
621
+ totalFragments += groupPayload.source.total_fragments;
622
+ totalAtoms += groupPayload.source.total_atoms;
623
+ for (const blob of groupPayload.blobs)
624
+ blobsById.set(blob.id, blob);
625
+ for (const candidate of groupPayload.candidates) {
626
+ if (candidate.candidate_kind === "project_observation") {
627
+ candidatesById.set(candidate.id, candidate);
628
+ }
629
+ }
630
+ for (const session of groupPayload.sessions) {
631
+ if (sessionsById.has(session.id))
632
+ requiresSourceCollector = true;
633
+ sessionsById.set(session.id, session);
634
+ }
635
+ for (const turn of groupPayload.turns)
636
+ turnsById.set(turn.id, turn);
637
+ for (const context of selectPayloadContexts(groupPayload, contextMode, resolveContextTargets(options))) {
638
+ contextsByTurnId.set(context.turn_id, context);
639
+ }
640
+ for (const askTurn of groupPayload.ask_user_question_turns)
641
+ askTurnsById.set(askTurn.id, askTurn);
642
+ sessionRelationFragments.push(...groupPayload.fragments.filter((fragment) => fragment.fragment_kind === "session_relation"));
643
+ familyInventories.push(familyInventoryFromPayload(groupPayload, flattenRelatedWorkIndex(buildSessionRelatedWorkIndex(groupPayload.sessions, groupPayload.fragments))));
644
+ lossAudits.push(...groupPayload.loss_audits);
645
+ }
646
+ if (requiresSourceCollector) {
647
+ return scanSourceWithCollector(source, options, contextMode, sourceAdapters, files);
648
+ }
649
+ if (!host) {
650
+ throw new Error(`Lite logical-session scan produced no host for ${source.display_name}.`);
651
+ }
652
+ const sessions = [...sessionsById.values()];
653
+ const turns = [...turnsById.values()];
654
+ const firstError = fileProcessingErrors[0];
655
+ const family = mergeSessionFamilyInventories(familyInventories);
656
+ return {
657
+ host,
658
+ payload: {
659
+ source: {
660
+ id: source.id,
661
+ slot_id: source.slot_id,
662
+ family: source.family,
663
+ platform: source.platform,
664
+ display_name: source.display_name,
665
+ base_dir: source.base_dir,
666
+ host_id: host.id,
667
+ last_sync: new Date().toISOString(),
668
+ sync_status: sessions.length > 0 || turns.length > 0
669
+ ? "healthy"
670
+ : fileProcessingErrors.length > 0
671
+ ? "error"
672
+ : "stale",
673
+ error_message: firstError
674
+ ? `${firstError}${fileProcessingErrors.length > 1 ? ` (+${fileProcessingErrors.length - 1} more)` : ""}`
675
+ : undefined,
676
+ total_blobs: blobsById.size,
677
+ total_records: totalRecords,
678
+ total_fragments: totalFragments,
679
+ total_atoms: totalAtoms,
680
+ total_sessions: sessions.length,
681
+ total_turns: turns.length,
682
+ },
683
+ blobs: [...blobsById.values()],
684
+ candidates: [...candidatesById.values()],
685
+ sessions,
686
+ related_work: flattenRelatedWorkIndex(buildSessionRelatedWorkIndex(sessions, sessionRelationFragments)),
687
+ session_contributions: family.contributions,
688
+ delegated_children: family.children,
689
+ turns,
690
+ contexts: [...contextsByTurnId.values()],
691
+ ask_user_question_turns: [...askTurnsById.values()],
692
+ loss_audits: lossAudits,
693
+ },
694
+ };
695
+ }
696
+ async function selectSampleSourceFiles(source, files, perSource, sourceAdapters) {
697
+ if (!Number.isInteger(perSource) || perSource < 1)
698
+ return [];
699
+ const ranked = await mapPool(files, SAMPLE_RANK_CONCURRENCY, async (filePath) => {
700
+ if (source.platform === "grok") {
701
+ const catalog = await sourceAdapters.inspectGrokChatHistoryCatalog(filePath);
702
+ return {
703
+ filePath,
704
+ rank: catalog.lastActiveAt ?? await fileModifiedAt(filePath),
705
+ parentPath: grokSampleParentPath(filePath, files, catalog, sourceAdapters),
706
+ };
707
+ }
708
+ return {
709
+ filePath,
710
+ rank: await fileModifiedAt(filePath),
711
+ parentPath: await cheapSampleParentPath(source.platform, filePath, files, sourceAdapters),
712
+ };
713
+ });
714
+ ranked.sort((left, right) => right.rank.localeCompare(left.rank) || left.filePath.localeCompare(right.filePath));
715
+ const selected = [];
716
+ const seen = new Set();
717
+ for (const entry of ranked) {
718
+ const target = entry.parentPath ?? entry.filePath;
719
+ if (seen.has(target))
720
+ continue;
721
+ seen.add(target);
722
+ selected.push(target);
723
+ if (selected.length >= perSource)
724
+ break;
725
+ }
726
+ return selected;
727
+ }
728
+ async function fileModifiedAt(filePath) {
729
+ try {
730
+ return (await stat(filePath)).mtime.toISOString();
731
+ }
732
+ catch {
733
+ return "1970-01-01T00:00:00.000Z";
734
+ }
735
+ }
736
+ function grokSampleParentPath(filePath, files, catalog, sourceAdapters) {
737
+ if (!catalog.isDelegatedChild || !catalog.parentSessionId)
738
+ return undefined;
739
+ const parentPath = sourceAdapters.resolveGrokSiblingSessionChatHistory(filePath, catalog.parentSessionId);
740
+ return parentPath && files.includes(parentPath) ? parentPath : undefined;
741
+ }
742
+ async function cheapSampleParentPath(platform, filePath, files, sourceAdapters) {
743
+ const normalized = filePath.replace(/\\/gu, "/");
744
+ const subagentMatch = normalized.match(/^(.*)\/([^/]+)\/subagents\/[^/]+\.jsonl$/u);
745
+ if (platform === "claude_code" && subagentMatch) {
746
+ const parentPath = `${subagentMatch[1]}/${subagentMatch[2]}.jsonl`;
747
+ return files.includes(parentPath) ? parentPath : undefined;
748
+ }
749
+ if (platform === "codex") {
750
+ const metadata = await sourceAdapters.inspectSourceFileLogicalSessionMetadata(platform, filePath, {
751
+ includeWorkspaceMetadata: false,
752
+ });
753
+ const parentRef = metadata.relatedSessionRefs?.[0];
754
+ if (!parentRef)
755
+ return undefined;
756
+ const native = parentRef.replace(/^sess:codex:/u, "").toLowerCase();
757
+ return files.find((candidate) => candidate.replace(/\\/gu, "/").toLowerCase().includes(native));
758
+ }
759
+ return undefined;
760
+ }
761
+ function sourceFileMayBeInDirectoryScope(sourceAdapters, source, filePath, directoryScope) {
762
+ const layout = sourceAdapters.sourceFileMayMatchDirectoryScope({
763
+ platform: source.platform,
764
+ baseDir: source.base_dir,
765
+ filePath,
766
+ directoryScope,
767
+ });
768
+ if (layout === "no")
769
+ return false;
770
+ if (layout === "yes")
771
+ return true;
772
+ const preview = sourceAdapters.previewSourceFileWorkingDirectory(source.platform, filePath);
773
+ if (preview.state !== "known" || !preview.workingDirectory)
774
+ return true;
775
+ return pathMatchesDirectoryScope(preview.workingDirectory, directoryScope);
776
+ }
777
+ function buildProbeOptions(source, options, targetSessionRefs = options.sessionRefs) {
778
+ return {
779
+ source_ids: [source.id],
780
+ target_session_refs: targetSessionRefs,
781
+ limit_files_per_source: options.limitFiles,
782
+ safe_mode: options.safeMode,
783
+ on_progress: options.onProgress,
784
+ };
785
+ }
786
+ function compactSourcePayload(payload, contextMode, contextTargets = []) {
787
+ const relatedWork = flattenRelatedWorkIndex(buildSessionRelatedWorkIndex(payload.sessions, payload.fragments));
788
+ const family = familyInventoryFromPayload(payload, relatedWork);
789
+ return {
790
+ source: payload.source,
791
+ blobs: payload.blobs,
792
+ candidates: payload.candidates.filter((candidate) => candidate.candidate_kind === "project_observation"),
793
+ sessions: payload.sessions,
794
+ related_work: relatedWork,
795
+ session_contributions: family.contributions,
796
+ delegated_children: family.children,
797
+ turns: payload.turns,
798
+ contexts: selectPayloadContexts(payload, contextMode, contextTargets),
799
+ ask_user_question_turns: payload.ask_user_question_turns,
800
+ loss_audits: payload.loss_audits,
801
+ };
802
+ }
803
+ function familyInventoryFromPayload(payload, relatedWork) {
804
+ return buildSessionFamilyInventory({
805
+ sessions: payload.sessions,
806
+ turns: payload.turns,
807
+ contexts: payload.contexts,
808
+ related_work: relatedWork,
809
+ fragments: payload.fragments,
810
+ blobs: payload.blobs,
811
+ records: payload.records,
812
+ atoms: payload.atoms,
813
+ });
814
+ }
815
+ function familyInventoryForLivePayload(payload) {
816
+ if (payload.session_contributions !== undefined && payload.delegated_children !== undefined) {
817
+ return {
818
+ contributions: [...payload.session_contributions],
819
+ children: [...payload.delegated_children],
820
+ };
821
+ }
822
+ return familyInventoryFromPayload({
823
+ sessions: payload.sessions,
824
+ turns: payload.turns,
825
+ contexts: payload.contexts,
826
+ blobs: payload.blobs,
827
+ records: payload.records ?? [],
828
+ atoms: payload.atoms ?? [],
829
+ fragments: payload.fragments ?? [],
830
+ }, materializeRelatedWork(payload));
831
+ }
832
+ function selectPayloadContexts(payload, contextMode, contextTargets = []) {
833
+ if (contextMode === "full")
834
+ return [...payload.contexts];
835
+ if (contextMode === "none")
836
+ return [];
837
+ if (contextTargets.length === 0)
838
+ throw new Error("matching context mode requires at least one context target.");
839
+ const turnIds = new Set();
840
+ for (const contextTarget of contextTargets) {
841
+ if (contextTarget.kind === "turn") {
842
+ for (const turn of payload.turns) {
843
+ if (turn.id === contextTarget.ref || turn.id.startsWith(contextTarget.ref))
844
+ turnIds.add(turn.id);
845
+ }
846
+ continue;
847
+ }
848
+ const sessionIds = new Set(payload.sessions
849
+ .filter((session) => sessionPotentiallyMatchesRef(session, contextTarget.ref))
850
+ .map((session) => session.id));
851
+ for (const turn of payload.turns)
852
+ if (sessionIds.has(turn.session_id))
853
+ turnIds.add(turn.id);
854
+ }
855
+ return payload.contexts.filter((context) => turnIds.has(context.turn_id));
856
+ }
857
+ function resolveContextTargets(options) {
858
+ const targets = [...(options.contextTargets ?? []), ...(options.contextTarget ? [options.contextTarget] : [])];
859
+ const seen = new Set();
860
+ return targets.filter((target) => {
861
+ const key = `${target.kind}:${target.ref}`;
862
+ if (seen.has(key))
863
+ return false;
864
+ seen.add(key);
865
+ return true;
866
+ });
867
+ }
868
+ function sessionPotentiallyMatchesRef(session, ref) {
869
+ const normalizedRef = normalizeLookup(ref);
870
+ if (!normalizedRef)
871
+ return false;
872
+ const exactAliases = [
873
+ session.source_session_id,
874
+ session.title,
875
+ session.working_directory,
876
+ path.basename(session.working_directory ?? ""),
877
+ ];
878
+ return (session.id === ref ||
879
+ session.id.startsWith(ref) ||
880
+ exactAliases.some((alias) => normalizeLookup(alias) === normalizedRef) ||
881
+ normalizeLookup(session.source_session_id).startsWith(normalizedRef));
882
+ }
883
+ function exactCanonicalSessionPlatforms(refs) {
884
+ if (refs.length === 0)
885
+ return new Set();
886
+ const platforms = new Set();
887
+ for (const ref of refs) {
888
+ const match = ref.match(/^sess:([^:]+):.+$/u);
889
+ if (!match?.[1])
890
+ return new Set();
891
+ platforms.add(match[1]);
892
+ }
893
+ return platforms;
894
+ }
895
+ function filterLiveSourcePayloadBySessions(payload, sessionRefs) {
896
+ const selectedIds = new Set(payload.sessions
897
+ .filter((session) => sessionRefs.some((ref) => sessionMatchesRequestedRef(session, ref)))
898
+ .map((session) => session.id));
899
+ const familySessionIds = expandDelegatedFamilySessionIds(payload, selectedIds);
900
+ const sessions = payload.sessions.filter((session) => familySessionIds.has(session.id));
901
+ const sessionIds = new Set(sessions.map((session) => session.id));
902
+ const turns = payload.turns.filter((turn) => sessionIds.has(turn.session_id));
903
+ const turnIds = new Set(turns.map((turn) => turn.id));
904
+ const relatedWork = payload.related_work?.filter((entry) => sessionIds.has(entry.query_session_ref));
905
+ return {
906
+ ...payload,
907
+ sessions,
908
+ turns,
909
+ candidates: payload.candidates.filter((candidate) => sessionIds.has(candidate.session_ref)),
910
+ contexts: payload.contexts.filter((context) => turnIds.has(context.turn_id)),
911
+ ask_user_question_turns: payload.ask_user_question_turns.filter((turn) => sessionIds.has(turn.session_id)),
912
+ related_work: relatedWork,
913
+ session_contributions: payload.session_contributions?.filter((entry) => familySessionIds.has(entry.session_ref)),
914
+ delegated_children: payload.delegated_children?.filter((entry) => familySessionIds.has(entry.parent_session_ref) ||
915
+ (entry.child_session_ref !== undefined && familySessionIds.has(entry.child_session_ref))),
916
+ };
917
+ }
918
+ function missingDelegatedChildSessionRefs(payloads, sessionRefs) {
919
+ const missing = new Set();
920
+ for (const payload of payloads) {
921
+ const selectedIds = new Set(payload.sessions
922
+ .filter((session) => sessionRefs.some((ref) => sessionMatchesRequestedRef(session, ref)))
923
+ .map((session) => session.id));
924
+ for (const ref of expandDelegatedFamilySessionIds(payload, selectedIds)) {
925
+ if (payload.sessions.some((session) => session.id === ref || session.source_session_id === ref)) {
926
+ continue;
927
+ }
928
+ missing.add(ref);
929
+ }
930
+ }
931
+ return [...missing];
932
+ }
933
+ function expandDelegatedFamilySessionIds(payload, selectedIds) {
934
+ const familySessionIds = new Set(selectedIds);
935
+ const add = (ref) => {
936
+ if (!ref)
937
+ return;
938
+ familySessionIds.add(ref);
939
+ for (const session of payload.sessions) {
940
+ if (session.id === ref || session.source_session_id === ref)
941
+ familySessionIds.add(session.id);
942
+ }
943
+ };
944
+ const family = familyInventoryForLivePayload(payload);
945
+ let grew = true;
946
+ while (grew) {
947
+ const before = familySessionIds.size;
948
+ for (const child of family.children) {
949
+ if (familySessionIds.has(child.parent_session_ref))
950
+ add(child.child_session_ref);
951
+ }
952
+ for (const entry of payload.related_work ?? []) {
953
+ if (entry.relation_kind !== "delegated_session")
954
+ continue;
955
+ if (entry.parent_session_ref && familySessionIds.has(entry.parent_session_ref)) {
956
+ add(entry.child_session_ref);
957
+ }
958
+ }
959
+ grew = familySessionIds.size > before;
960
+ }
961
+ return familySessionIds;
962
+ }
963
+ function sessionMatchesRequestedRef(session, ref) {
964
+ if (!ref)
965
+ return false;
966
+ if (ref === session.id || ref === session.source_session_id)
967
+ return true;
968
+ if (/^sess:[^:]+:./u.test(ref) && session.id.startsWith(ref))
969
+ return true;
970
+ if (ref.startsWith("sess:"))
971
+ return false;
972
+ return Boolean(session.source_session_id?.startsWith(ref) ||
973
+ session.id.startsWith(ref) ||
974
+ session.id.endsWith(`:${ref}`));
975
+ }
976
+ function sessionRefMatchesGroup(ref, groupKey, source) {
977
+ const expected = `sess:${source.platform}:`;
978
+ const canonicalGroup = groupKey.startsWith(expected) ? groupKey : `${expected}${groupKey}`;
979
+ const nativeGroup = canonicalGroup.startsWith(expected) ? canonicalGroup.slice(expected.length) : groupKey;
980
+ if (ref === groupKey ||
981
+ ref === canonicalGroup ||
982
+ ref === nativeGroup ||
983
+ ref.endsWith(`:${groupKey}`) ||
984
+ ref.endsWith(`:${nativeGroup}`) ||
985
+ groupKey.endsWith(`:${ref}`)) {
986
+ return true;
987
+ }
988
+ if (ref.startsWith("sess:")) {
989
+ if (!ref.startsWith(expected) || ref.length <= expected.length)
990
+ return false;
991
+ const nativeRef = ref.slice(expected.length);
992
+ return canonicalGroup.startsWith(ref) || nativeGroup.startsWith(nativeRef);
993
+ }
994
+ return ref.length > 0 && (nativeGroup.startsWith(ref) || groupKey.startsWith(ref));
995
+ }
996
+ function materializeRelatedWork(payload) {
997
+ if (payload.related_work)
998
+ return [...payload.related_work];
999
+ return flattenRelatedWorkIndex(buildSessionRelatedWorkIndex(payload.sessions, payload.fragments ?? []));
1000
+ }
1001
+ function flattenRelatedWorkIndex(index) {
1002
+ return [...index.values()].flatMap((entries) => [...entries]);
1003
+ }
1004
+ export async function resolveLiteSources(options = {}) {
1005
+ const { getDefaultSourcesForHost } = await import("@cchistory/source-adapters");
1006
+ const sourceRoots = options.sourceRoots ?? [];
1007
+ const sourceRefs = options.sourceRefs ?? [];
1008
+ const discoveryOptions = {
1009
+ homeDir: options.homeDir,
1010
+ hostname: options.hostname,
1011
+ platform: options.platform,
1012
+ appDataDir: options.appDataDir,
1013
+ };
1014
+ const discoveredRoster = getDefaultSourcesForHost(discoveryOptions);
1015
+ const completeRoster = getDefaultSourcesForHost({
1016
+ ...discoveryOptions,
1017
+ includeMissing: true,
1018
+ });
1019
+ const hostId = deriveHostId(options.hostname ?? os.hostname());
1020
+ const overrideRefs = new Set();
1021
+ const overridesBySlotId = new Map();
1022
+ for (const override of sourceRoots) {
1023
+ if (overrideRefs.has(override.sourceRef)) {
1024
+ throw new Error(`Duplicate --source-root for ${override.sourceRef}.`);
1025
+ }
1026
+ overrideRefs.add(override.sourceRef);
1027
+ await assertLiteSourceRoot(override.baseDir, { homeDir: options.homeDir });
1028
+ const source = findSource(completeRoster, override.sourceRef);
1029
+ if (!source) {
1030
+ throw new Error(`Unknown Lite source adapter: ${override.sourceRef}.`);
1031
+ }
1032
+ if (overridesBySlotId.has(source.slot_id)) {
1033
+ throw new Error(`Duplicate --source-root for ${source.platform}.`);
1034
+ }
1035
+ const baseDir = path.resolve(override.baseDir);
1036
+ overridesBySlotId.set(source.slot_id, {
1037
+ ...source,
1038
+ base_dir: baseDir,
1039
+ id: deriveSourceInstanceId({
1040
+ host_id: hostId,
1041
+ slot_id: source.slot_id,
1042
+ base_dir: baseDir,
1043
+ }),
1044
+ });
1045
+ }
1046
+ const resolvedRoster = completeRoster.map((source) => overridesBySlotId.get(source.slot_id) ?? source);
1047
+ let result;
1048
+ if (sourceRefs.length === 0) {
1049
+ const discoveredSlots = new Set(discoveredRoster.map((source) => source.slot_id));
1050
+ result = resolvedRoster.filter((source) => discoveredSlots.has(source.slot_id) || overridesBySlotId.has(source.slot_id));
1051
+ }
1052
+ else {
1053
+ const selected = [];
1054
+ for (const ref of sourceRefs) {
1055
+ const source = findSource(resolvedRoster, ref);
1056
+ if (!source) {
1057
+ throw new Error(`Unknown Lite source adapter: ${ref}.`);
1058
+ }
1059
+ if (!selected.some((entry) => entry.id === source.id)) {
1060
+ selected.push(source);
1061
+ }
1062
+ }
1063
+ result = selected;
1064
+ }
1065
+ for (const source of result) {
1066
+ await assertLiteSourceRoot(source.base_dir, { homeDir: options.homeDir });
1067
+ }
1068
+ return result;
1069
+ }
1070
+ export async function assertLiteSourceRoot(inputPath, options = {}) {
1071
+ const requestedPath = path.resolve(inputPath);
1072
+ const resolved = await resolveExistingRealPath(requestedPath);
1073
+ const normalized = normalizeLocalPathIdentity(resolved) ?? resolved.replace(/\\/g, "/");
1074
+ // Case-insensitive on purpose: macOS/Windows filesystems resolve `.CCHISTORY`
1075
+ // and `CCHistory.sqlite` to the Full store too.
1076
+ const lowerNormalized = normalized.toLowerCase();
1077
+ const segments = lowerNormalized.split("/").filter(Boolean);
1078
+ if (segments.includes(".cchistory") || path.basename(lowerNormalized) === "cchistory.sqlite") {
1079
+ throw new Error(`Full store paths are not Lite sources: ${resolved}`);
1080
+ }
1081
+ const canonicalFullStoreRoot = path.resolve(options.homeDir ?? os.homedir(), ".cchistory");
1082
+ const resolvedFullStoreRoot = await resolveExistingRealPath(canonicalFullStoreRoot);
1083
+ if (await pathExists(canonicalFullStoreRoot) &&
1084
+ [requestedPath, resolved].some((sourceRoot) => [canonicalFullStoreRoot, resolvedFullStoreRoot].some((fullStoreRoot) => pathsOverlap(sourceRoot, fullStoreRoot)))) {
1085
+ throw new Error(`Source roots overlapping the Full store are not allowed in Lite: ${resolved}`);
1086
+ }
1087
+ if (await pathExists(path.join(resolved, "cchistory.sqlite"))) {
1088
+ throw new Error(`Full store paths are not Lite sources: ${resolved}`);
1089
+ }
1090
+ if (await pathExists(path.join(resolved, "manifest.json")) &&
1091
+ await pathExists(path.join(resolved, "payloads"))) {
1092
+ throw new Error(`Full bundle paths are not Lite sources: ${resolved}`);
1093
+ }
1094
+ }
1095
+ function findSource(sources, ref) {
1096
+ return sources.find((source) => source.id === ref ||
1097
+ source.slot_id === ref ||
1098
+ source.platform === ref);
1099
+ }
1100
+ function resolveUnique(values, ref, getId, getAliases, getPrefixAliases = () => []) {
1101
+ const normalizedRef = normalizeLookup(ref);
1102
+ // A blank ref would otherwise match every alias-less object (and every id
1103
+ // prefix), returning an arbitrary object or a confusing "Ambiguous" error.
1104
+ if (normalizedRef === "")
1105
+ return undefined;
1106
+ const exact = values.filter((value) => {
1107
+ if (getId(value) === ref)
1108
+ return true;
1109
+ return getAliases(value).some((alias) => normalizeLookup(alias) === normalizedRef);
1110
+ });
1111
+ if (exact.length === 1)
1112
+ return exact[0];
1113
+ if (exact.length > 1) {
1114
+ throw new AmbiguousReferenceError(ref, exact.map(getId), false);
1115
+ }
1116
+ const prefix = values.filter((value) => getId(value).startsWith(ref) ||
1117
+ getPrefixAliases(value).some((alias) => normalizeLookup(alias).startsWith(normalizedRef)));
1118
+ if (prefix.length === 1)
1119
+ return prefix[0];
1120
+ if (prefix.length > 1) {
1121
+ throw new AmbiguousReferenceError(ref, prefix.map(getId), true);
1122
+ }
1123
+ return undefined;
1124
+ }
1125
+ function normalizeLookup(value) {
1126
+ return (normalizeLocalPathIdentity(value) ?? value ?? "").trim().toLowerCase();
1127
+ }
1128
+ async function pathExists(targetPath) {
1129
+ try {
1130
+ await access(targetPath);
1131
+ return true;
1132
+ }
1133
+ catch {
1134
+ return false;
1135
+ }
1136
+ }
1137
+ async function resolveExistingRealPath(targetPath) {
1138
+ try {
1139
+ return await realpath(targetPath);
1140
+ }
1141
+ catch {
1142
+ return targetPath;
1143
+ }
1144
+ }
1145
+ function isPathWithin(parentPath, childPath) {
1146
+ const relative = path.relative(parentPath, childPath);
1147
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
1148
+ }
1149
+ function pathsOverlap(leftPath, rightPath) {
1150
+ return isPathWithin(leftPath, rightPath) || isPathWithin(rightPath, leftPath);
1151
+ }
1152
+ // Mutates the input so it matches what JSON.stringify would produce: arrays
1153
+ // have undefined slots replaced with null and object keys with undefined
1154
+ // values are deleted. This keeps Lite's in-memory snapshot byte-identical to
1155
+ // what Full persists and reads back from SQLite payload_json.
1156
+ function normalizeJsonShapeForJsonOutputMutating(value) {
1157
+ if (Array.isArray(value)) {
1158
+ for (let index = 0; index < value.length; index += 1) {
1159
+ if (value[index] === undefined) {
1160
+ value[index] = null;
1161
+ }
1162
+ else {
1163
+ normalizeJsonShapeForJsonOutputMutating(value[index]);
1164
+ }
1165
+ }
1166
+ return value;
1167
+ }
1168
+ if (value && typeof value === "object") {
1169
+ for (const [key, child] of Object.entries(value)) {
1170
+ if (child === undefined) {
1171
+ delete value[key];
1172
+ }
1173
+ else {
1174
+ normalizeJsonShapeForJsonOutputMutating(child);
1175
+ }
1176
+ }
1177
+ }
1178
+ return value;
1179
+ }
1180
+ //# sourceMappingURL=index.js.map