@cchistory/lite 0.8.3 → 0.9.1

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 (297) hide show
  1. package/INSTALL.md +1 -1
  2. package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
  3. package/apps/lite-cli/dist/agent-contract.js +41 -2
  4. package/apps/lite-cli/dist/agent-contract.js.map +1 -1
  5. package/apps/lite-cli/dist/help.js +5 -5
  6. package/apps/lite-cli/dist/index.d.ts.map +1 -1
  7. package/apps/lite-cli/dist/index.js +148 -17
  8. package/apps/lite-cli/dist/index.js.map +1 -1
  9. package/apps/lite-cli/dist/index.test.js +114 -95
  10. package/apps/lite-cli/dist/index.test.js.map +1 -1
  11. package/apps/lite-cli/dist/inventory-and-git.test.d.ts +7 -0
  12. package/apps/lite-cli/dist/inventory-and-git.test.d.ts.map +1 -0
  13. package/apps/lite-cli/dist/inventory-and-git.test.js +776 -0
  14. package/apps/lite-cli/dist/inventory-and-git.test.js.map +1 -0
  15. package/apps/lite-cli/dist/inventory-command.d.ts +30 -0
  16. package/apps/lite-cli/dist/inventory-command.d.ts.map +1 -0
  17. package/apps/lite-cli/dist/inventory-command.js +265 -0
  18. package/apps/lite-cli/dist/inventory-command.js.map +1 -0
  19. package/apps/lite-cli/dist/json-v2.d.ts +2 -2
  20. package/apps/lite-cli/dist/json-v2.d.ts.map +1 -1
  21. package/apps/lite-cli/dist/json-v2.js +9 -3
  22. package/apps/lite-cli/dist/json-v2.js.map +1 -1
  23. package/apps/lite-cli/dist/project-git-command.d.ts +28 -0
  24. package/apps/lite-cli/dist/project-git-command.d.ts.map +1 -0
  25. package/apps/lite-cli/dist/project-git-command.js +288 -0
  26. package/apps/lite-cli/dist/project-git-command.js.map +1 -0
  27. package/apps/lite-cli/dist/startup-render.d.ts +10 -0
  28. package/apps/lite-cli/dist/startup-render.d.ts.map +1 -0
  29. package/apps/lite-cli/dist/startup-render.js +335 -0
  30. package/apps/lite-cli/dist/startup-render.js.map +1 -0
  31. package/apps/lite-cli/dist/version.d.ts +1 -1
  32. package/apps/lite-cli/dist/version.js +1 -1
  33. package/apps/lite-tui/dist/render.d.ts +1 -1
  34. package/apps/lite-tui/dist/version.d.ts +1 -1
  35. package/apps/lite-tui/dist/version.js +1 -1
  36. package/docs/guide/for-agents.md +14 -0
  37. package/docs/guide/lite.md +53 -2
  38. package/node_modules/@cchistory/canonical/dist/agent-inventory.d.ts +25 -0
  39. package/node_modules/@cchistory/canonical/dist/agent-inventory.d.ts.map +1 -0
  40. package/node_modules/@cchistory/canonical/dist/agent-inventory.js +345 -0
  41. package/node_modules/@cchistory/canonical/dist/agent-inventory.js.map +1 -0
  42. package/node_modules/@cchistory/canonical/dist/agent-inventory.test.d.ts +7 -0
  43. package/node_modules/@cchistory/canonical/dist/agent-inventory.test.d.ts.map +1 -0
  44. package/node_modules/@cchistory/canonical/dist/agent-inventory.test.js +231 -0
  45. package/node_modules/@cchistory/canonical/dist/agent-inventory.test.js.map +1 -0
  46. package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts.map +1 -1
  47. package/node_modules/@cchistory/canonical/dist/directory-scope.js +4 -1
  48. package/node_modules/@cchistory/canonical/dist/directory-scope.js.map +1 -1
  49. package/node_modules/@cchistory/canonical/dist/index.d.ts +2 -0
  50. package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
  51. package/node_modules/@cchistory/canonical/dist/index.js +2 -0
  52. package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
  53. package/node_modules/@cchistory/canonical/dist/project-merge.d.ts +42 -0
  54. package/node_modules/@cchistory/canonical/dist/project-merge.d.ts.map +1 -0
  55. package/node_modules/@cchistory/canonical/dist/project-merge.js +396 -0
  56. package/node_modules/@cchistory/canonical/dist/project-merge.js.map +1 -0
  57. package/node_modules/@cchistory/canonical/dist/project-merge.test.d.ts +7 -0
  58. package/node_modules/@cchistory/canonical/dist/project-merge.test.d.ts.map +1 -0
  59. package/node_modules/@cchistory/canonical/dist/project-merge.test.js +319 -0
  60. package/node_modules/@cchistory/canonical/dist/project-merge.test.js.map +1 -0
  61. package/node_modules/@cchistory/canonical/dist/query.js +1 -1
  62. package/node_modules/@cchistory/canonical/dist/query.js.map +1 -1
  63. package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -1
  64. package/node_modules/@cchistory/canonical/dist/session-interpreter.js +38 -0
  65. package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -1
  66. package/node_modules/@cchistory/canonical/dist/tool-call-summary.d.ts.map +1 -1
  67. package/node_modules/@cchistory/canonical/dist/tool-call-summary.js +18 -2
  68. package/node_modules/@cchistory/canonical/dist/tool-call-summary.js.map +1 -1
  69. package/node_modules/@cchistory/canonical/dist/usage-anomalies.d.ts.map +1 -1
  70. package/node_modules/@cchistory/canonical/dist/usage-anomalies.js +2 -0
  71. package/node_modules/@cchistory/canonical/dist/usage-anomalies.js.map +1 -1
  72. package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.d.ts.map +1 -1
  73. package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.js +4 -1
  74. package/node_modules/@cchistory/canonical/dist/usage-call-evaluation.js.map +1 -1
  75. package/node_modules/@cchistory/canonical/dist/usage-trace.d.ts.map +1 -1
  76. package/node_modules/@cchistory/canonical/dist/usage-trace.js +3 -1
  77. package/node_modules/@cchistory/canonical/dist/usage-trace.js.map +1 -1
  78. package/node_modules/@cchistory/canonical/dist/usage-trace.test.js +73 -0
  79. package/node_modules/@cchistory/canonical/dist/usage-trace.test.js.map +1 -1
  80. package/node_modules/@cchistory/canonical/dist/usage.d.ts +1 -0
  81. package/node_modules/@cchistory/canonical/dist/usage.d.ts.map +1 -1
  82. package/node_modules/@cchistory/canonical/dist/usage.js +23 -17
  83. package/node_modules/@cchistory/canonical/dist/usage.js.map +1 -1
  84. package/node_modules/@cchistory/canonical/package.json +1 -1
  85. package/node_modules/@cchistory/domain/dist/agent-inventory.d.ts +146 -0
  86. package/node_modules/@cchistory/domain/dist/agent-inventory.d.ts.map +1 -0
  87. package/node_modules/@cchistory/domain/dist/agent-inventory.js +9 -0
  88. package/node_modules/@cchistory/domain/dist/agent-inventory.js.map +1 -0
  89. package/node_modules/@cchistory/domain/dist/agent-startup.d.ts +362 -0
  90. package/node_modules/@cchistory/domain/dist/agent-startup.d.ts.map +1 -0
  91. package/node_modules/@cchistory/domain/dist/agent-startup.js +8 -0
  92. package/node_modules/@cchistory/domain/dist/agent-startup.js.map +1 -0
  93. package/node_modules/@cchistory/domain/dist/index.d.ts +8 -1
  94. package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
  95. package/node_modules/@cchistory/domain/dist/index.js +3 -0
  96. package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
  97. package/node_modules/@cchistory/domain/dist/index.test.js +27 -1
  98. package/node_modules/@cchistory/domain/dist/index.test.js.map +1 -1
  99. package/node_modules/@cchistory/domain/dist/project-git.d.ts +121 -0
  100. package/node_modules/@cchistory/domain/dist/project-git.d.ts.map +1 -0
  101. package/node_modules/@cchistory/domain/dist/project-git.js +93 -0
  102. package/node_modules/@cchistory/domain/dist/project-git.js.map +1 -0
  103. package/node_modules/@cchistory/domain/dist/token-evidence.d.ts.map +1 -1
  104. package/node_modules/@cchistory/domain/dist/token-evidence.js +3 -1
  105. package/node_modules/@cchistory/domain/dist/token-evidence.js.map +1 -1
  106. package/node_modules/@cchistory/domain/package.json +1 -1
  107. package/node_modules/@cchistory/live-runtime/dist/index.d.ts +4 -1
  108. package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
  109. package/node_modules/@cchistory/live-runtime/dist/index.js +3 -1
  110. package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
  111. package/node_modules/@cchistory/live-runtime/dist/index.test.js +266 -38
  112. package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
  113. package/node_modules/@cchistory/live-runtime/dist/inventory-and-git.d.ts +35 -0
  114. package/node_modules/@cchistory/live-runtime/dist/inventory-and-git.d.ts.map +1 -0
  115. package/node_modules/@cchistory/live-runtime/dist/inventory-and-git.js +68 -0
  116. package/node_modules/@cchistory/live-runtime/dist/inventory-and-git.js.map +1 -0
  117. package/node_modules/@cchistory/live-runtime/package.json +1 -1
  118. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts +3 -0
  119. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.d.ts.map +1 -1
  120. package/node_modules/@cchistory/source-adapters/dist/core/conversation-seeds.js.map +1 -1
  121. package/node_modules/@cchistory/source-adapters/dist/core/discovery.d.ts.map +1 -1
  122. package/node_modules/@cchistory/source-adapters/dist/core/discovery.js +60 -4
  123. package/node_modules/@cchistory/source-adapters/dist/core/discovery.js.map +1 -1
  124. package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts +9 -0
  125. package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts.map +1 -1
  126. package/node_modules/@cchistory/source-adapters/dist/core/git-project.js +130 -7
  127. package/node_modules/@cchistory/source-adapters/dist/core/git-project.js.map +1 -1
  128. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +1 -1
  129. package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
  130. package/node_modules/@cchistory/source-adapters/dist/core/parser.js +198 -1
  131. package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
  132. package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
  133. package/node_modules/@cchistory/source-adapters/dist/core/probe.js +85 -5
  134. package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
  135. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js +17 -1
  136. package/node_modules/@cchistory/source-adapters/dist/core/registry.test.js.map +1 -1
  137. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts.map +1 -1
  138. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js +44 -0
  139. package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js.map +1 -1
  140. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
  141. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +12 -0
  142. package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
  143. package/node_modules/@cchistory/source-adapters/dist/index.d.ts +5 -0
  144. package/node_modules/@cchistory/source-adapters/dist/index.d.ts.map +1 -1
  145. package/node_modules/@cchistory/source-adapters/dist/index.js +5 -0
  146. package/node_modules/@cchistory/source-adapters/dist/index.js.map +1 -1
  147. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +6 -0
  148. package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
  149. package/node_modules/@cchistory/source-adapters/dist/index.test.js +6 -0
  150. package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
  151. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.d.ts +14 -0
  152. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.d.ts.map +1 -0
  153. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.js +397 -0
  154. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.js.map +1 -0
  155. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.test.d.ts +6 -0
  156. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.test.d.ts.map +1 -0
  157. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.test.js +106 -0
  158. package/node_modules/@cchistory/source-adapters/dist/inventory/agent-config-reader.test.js.map +1 -0
  159. package/node_modules/@cchistory/source-adapters/dist/inventory/config-io.d.ts +42 -0
  160. package/node_modules/@cchistory/source-adapters/dist/inventory/config-io.d.ts.map +1 -0
  161. package/node_modules/@cchistory/source-adapters/dist/inventory/config-io.js +368 -0
  162. package/node_modules/@cchistory/source-adapters/dist/inventory/config-io.js.map +1 -0
  163. package/node_modules/@cchistory/source-adapters/dist/inventory/redaction.d.ts +22 -0
  164. package/node_modules/@cchistory/source-adapters/dist/inventory/redaction.d.ts.map +1 -0
  165. package/node_modules/@cchistory/source-adapters/dist/inventory/redaction.js +195 -0
  166. package/node_modules/@cchistory/source-adapters/dist/inventory/redaction.js.map +1 -0
  167. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity-helpers.d.ts +23 -0
  168. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity-helpers.d.ts.map +1 -0
  169. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity-helpers.js +147 -0
  170. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity-helpers.js.map +1 -0
  171. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity.d.ts +11 -0
  172. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity.d.ts.map +1 -0
  173. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity.js +339 -0
  174. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/antigravity.js.map +1 -0
  175. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code-helpers.d.ts +70 -0
  176. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code-helpers.d.ts.map +1 -0
  177. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code-helpers.js +257 -0
  178. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code-helpers.js.map +1 -0
  179. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code.d.ts +11 -0
  180. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code.d.ts.map +1 -0
  181. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code.js +321 -0
  182. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/claude-code.js.map +1 -0
  183. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/codex.d.ts +12 -0
  184. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/codex.d.ts.map +1 -0
  185. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/codex.js +363 -0
  186. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/codex.js.map +1 -0
  187. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/deepseek-harness.d.ts +20 -0
  188. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/deepseek-harness.d.ts.map +1 -0
  189. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/deepseek-harness.js +408 -0
  190. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/deepseek-harness.js.map +1 -0
  191. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/index.d.ts +24 -0
  192. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/index.d.ts.map +1 -0
  193. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/index.js +225 -0
  194. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/index.js.map +1 -0
  195. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/opencode.d.ts +12 -0
  196. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/opencode.d.ts.map +1 -0
  197. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/opencode.js +372 -0
  198. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/opencode.js.map +1 -0
  199. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/shared.d.ts +62 -0
  200. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/shared.d.ts.map +1 -0
  201. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/shared.js +428 -0
  202. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/shared.js.map +1 -0
  203. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/startup.test.d.ts +7 -0
  204. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/startup.test.d.ts.map +1 -0
  205. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/startup.test.js +399 -0
  206. package/node_modules/@cchistory/source-adapters/dist/inventory/startup/startup.test.js.map +1 -0
  207. package/node_modules/@cchistory/source-adapters/dist/inventory/toml.d.ts +16 -0
  208. package/node_modules/@cchistory/source-adapters/dist/inventory/toml.d.ts.map +1 -0
  209. package/node_modules/@cchistory/source-adapters/dist/inventory/toml.js +478 -0
  210. package/node_modules/@cchistory/source-adapters/dist/inventory/toml.js.map +1 -0
  211. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js +2 -0
  212. package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js.map +1 -1
  213. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.d.ts +28 -0
  214. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.d.ts.map +1 -0
  215. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.js +443 -0
  216. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/reader.js.map +1 -0
  217. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.d.ts +4 -0
  218. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.d.ts.map +1 -0
  219. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.js +370 -0
  220. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness/runtime.js.map +1 -0
  221. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.d.ts +3 -0
  222. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.d.ts.map +1 -0
  223. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.js +78 -0
  224. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.js.map +1 -0
  225. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.d.ts +2 -0
  226. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.d.ts.map +1 -0
  227. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.js +313 -0
  228. package/node_modules/@cchistory/source-adapters/dist/platforms/deepseek-harness.test.js.map +1 -0
  229. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.d.ts.map +1 -1
  230. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js +14 -0
  231. package/node_modules/@cchistory/source-adapters/dist/platforms/generic/runtime.js.map +1 -1
  232. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.d.ts +4 -0
  233. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.d.ts.map +1 -0
  234. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.js +306 -0
  235. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/runtime.js.map +1 -0
  236. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.d.ts +8 -0
  237. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.d.ts.map +1 -0
  238. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.js +499 -0
  239. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes/sqlite.js.map +1 -0
  240. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.d.ts +9 -0
  241. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.d.ts.map +1 -0
  242. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.js +53 -0
  243. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.js.map +1 -0
  244. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.d.ts +2 -0
  245. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.d.ts.map +1 -0
  246. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.js +314 -0
  247. package/node_modules/@cchistory/source-adapters/dist/platforms/hermes.test.js.map +1 -0
  248. package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.d.ts +9 -0
  249. package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.d.ts.map +1 -0
  250. package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.js +84 -0
  251. package/node_modules/@cchistory/source-adapters/dist/platforms/oh-my-pi.js.map +1 -0
  252. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.d.ts +50 -0
  253. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.d.ts.map +1 -0
  254. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.js +291 -0
  255. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite-records.js.map +1 -0
  256. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.d.ts +8 -0
  257. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.d.ts.map +1 -0
  258. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.js +321 -0
  259. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode/sqlite.js.map +1 -0
  260. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.d.ts +2 -0
  261. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.d.ts.map +1 -0
  262. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.js +245 -0
  263. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode-sqlite.test.js.map +1 -0
  264. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.d.ts.map +1 -1
  265. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.js +30 -7
  266. package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.js.map +1 -1
  267. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.d.ts +44 -0
  268. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.d.ts.map +1 -0
  269. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.js +533 -0
  270. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/reader.js.map +1 -0
  271. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.d.ts +4 -0
  272. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.d.ts.map +1 -0
  273. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.js +375 -0
  274. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family/runtime.js.map +1 -0
  275. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.d.ts +2 -0
  276. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.d.ts.map +1 -0
  277. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.js +346 -0
  278. package/node_modules/@cchistory/source-adapters/dist/platforms/pi-family.test.js.map +1 -0
  279. package/node_modules/@cchistory/source-adapters/dist/platforms/pi.d.ts +8 -0
  280. package/node_modules/@cchistory/source-adapters/dist/platforms/pi.d.ts.map +1 -0
  281. package/node_modules/@cchistory/source-adapters/dist/platforms/pi.js +60 -0
  282. package/node_modules/@cchistory/source-adapters/dist/platforms/pi.js.map +1 -0
  283. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.d.ts.map +1 -1
  284. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js +8 -0
  285. package/node_modules/@cchistory/source-adapters/dist/platforms/registry.js.map +1 -1
  286. package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts +3 -1
  287. package/node_modules/@cchistory/source-adapters/dist/platforms/types.d.ts.map +1 -1
  288. package/node_modules/@cchistory/source-adapters/dist/platforms/types.js +5 -1
  289. package/node_modules/@cchistory/source-adapters/dist/platforms/types.js.map +1 -1
  290. package/node_modules/@cchistory/source-adapters/package.json +1 -1
  291. package/package.json +5 -5
  292. package/schemas/cchistory-lite-agent-v1.schema.json +3 -1
  293. package/schemas/cchistory-lite-envelope-v1.schema.json +33 -0
  294. package/schemas/cchistory-lite-inventory-v1.schema.json +94 -0
  295. package/schemas/cchistory-lite-merged-projects-v1.schema.json +44 -0
  296. package/schemas/cchistory-lite-v2.schema.json +22 -1
  297. package/skills/using-cchistory-lite/SKILL.md +17 -0
@@ -0,0 +1,291 @@
1
+ import { asNumber, asString, isObject, safeJsonParse } from "../../core/type-guards.js";
2
+ export function buildMessageRecord(schema, message, parsed, parts, context) {
3
+ const v2Type = schema.version === 2 ? asString(message.type) : undefined;
4
+ const role = v2Type ?? asString(parsed.role);
5
+ if (!role) {
6
+ return undefined;
7
+ }
8
+ const content = [];
9
+ const pushLoss = (code, detail, severity = "info") => {
10
+ context.diagnostics.push({ code, detail, severity });
11
+ };
12
+ if (role === "user") {
13
+ appendTextBlock(content, asString(parsed.text));
14
+ for (const part of parts) {
15
+ const parsedPart = parseJsonObject(asString(part.data), context.messageId, context.diagnostics, "part");
16
+ if (parsedPart) {
17
+ appendMessagePart(content, parsedPart, role, pushLoss);
18
+ }
19
+ }
20
+ appendUserFiles(content, parsed.files);
21
+ }
22
+ else if (role === "assistant") {
23
+ const inlineContent = Array.isArray(parsed.content) ? parsed.content : [];
24
+ // Current builds store assistant parts in `session_part`; the inline copy is
25
+ // only authoritative when no part rows exist (part rows disabled).
26
+ if (parts.length === 0) {
27
+ for (const item of inlineContent) {
28
+ if (isObject(item)) {
29
+ appendMessagePart(content, item, role, pushLoss);
30
+ }
31
+ }
32
+ }
33
+ for (const part of parts) {
34
+ const parsedPart = parseJsonObject(asString(part.data), context.messageId, context.diagnostics, "part");
35
+ if (parsedPart) {
36
+ appendMessagePart(content, parsedPart, role, pushLoss);
37
+ }
38
+ }
39
+ if (parsed.error !== undefined) {
40
+ pushLoss("opencode_assistant_error_evidence", `Assistant message ${context.messageId ?? "?"} recorded an error payload: ${describeValue(parsed.error)}`);
41
+ }
42
+ }
43
+ else if (role === "compaction") {
44
+ // Compaction usage is emitted separately as an independent usage_only call
45
+ // record so reply accounting stays untouched while the summary stays collapsed.
46
+ const summary = extractContentText(parsed.summary);
47
+ if (summary) {
48
+ content.push({ type: "text", text: summary, synthetic: true });
49
+ }
50
+ }
51
+ else if (role === "system" || role === "synthetic" || role === "skill") {
52
+ appendTextBlock(content, asString(parsed.text), true);
53
+ }
54
+ else if (role === "shell") {
55
+ appendShellEvidence(content, parsed);
56
+ }
57
+ else {
58
+ pushLoss("opencode_unhandled_message_type", `Unhandled OpenCode message type ${role}; kept only as a diagnostic.`);
59
+ return undefined;
60
+ }
61
+ const usage = role === "compaction" ? undefined : normalizeOpenCodeUsage(parsed.tokens);
62
+ const model = asString(parsed.modelID) ??
63
+ (isObject(parsed.model) ? asString(parsed.model.id) : undefined);
64
+ const stopReason = asString(parsed.finish);
65
+ if (content.length === 0 && !usage && !model && role !== "user" && role !== "compaction") {
66
+ return undefined;
67
+ }
68
+ const observedAt = epochMillisIso(message.time_created) ??
69
+ epochMillisIso(isObject(parsed.time) ? parsed.time.created : undefined);
70
+ return {
71
+ observedAt,
72
+ model,
73
+ record: {
74
+ id: context.messageId,
75
+ role: role === "compaction" || role === "shell" || role === "synthetic" || role === "skill" ? "system" : role,
76
+ timestamp: observedAt,
77
+ content,
78
+ ...(usage ? { usage } : {}),
79
+ ...(stopReason ? { stopReason } : {}),
80
+ ...(model ? { model } : {}),
81
+ ...(context.workingDirectory ? { cwd: context.workingDirectory } : {}),
82
+ opencode: {
83
+ storage: schema.messagesTable,
84
+ message_type: role,
85
+ provider_id: asString(parsed.providerID) ??
86
+ (isObject(parsed.model) ? asString(parsed.model.providerID) : undefined),
87
+ agent: asString(parsed.agent) ?? asString(parsed.mode),
88
+ },
89
+ },
90
+ };
91
+ }
92
+ export function normalizeOpenCodeUsage(tokens) {
93
+ if (!isObject(tokens)) {
94
+ return undefined;
95
+ }
96
+ const cache = isObject(tokens.cache) ? tokens.cache : undefined;
97
+ const inputTokens = asNumber(tokens.input);
98
+ const outputTokens = asNumber(tokens.output);
99
+ const reasoningTokens = asNumber(tokens.reasoning);
100
+ const cacheReadTokens = asNumber(cache?.read);
101
+ const cacheCreationTokens = asNumber(cache?.write);
102
+ const values = [inputTokens, outputTokens, reasoningTokens, cacheReadTokens, cacheCreationTokens];
103
+ if (values.every((value) => value === undefined)) {
104
+ return undefined;
105
+ }
106
+ const totalTokens = values.reduce((total, value) => total + (value ?? 0), 0);
107
+ return {
108
+ ...(inputTokens !== undefined ? { inputTokens } : {}),
109
+ ...(outputTokens !== undefined ? { outputTokens } : {}),
110
+ ...(reasoningTokens !== undefined ? { reasoningTokens } : {}),
111
+ ...(cacheReadTokens !== undefined ? { cacheReadTokens } : {}),
112
+ ...(cacheCreationTokens !== undefined ? { cacheCreationTokens } : {}),
113
+ totalTokens,
114
+ };
115
+ }
116
+ export function parseJsonObject(raw, messageId, diagnostics, kind) {
117
+ if (!raw) {
118
+ diagnostics.push({
119
+ code: "opencode_empty_payload",
120
+ detail: `OpenCode ${kind} record${messageId ? ` ${messageId}` : ""} has no JSON payload.`,
121
+ });
122
+ return undefined;
123
+ }
124
+ const parsed = safeJsonParse(raw);
125
+ if (!isObject(parsed)) {
126
+ diagnostics.push({
127
+ code: "opencode_malformed_payload",
128
+ detail: `OpenCode ${kind} record${messageId ? ` ${messageId}` : ""} is not a JSON object.`,
129
+ });
130
+ return undefined;
131
+ }
132
+ return parsed;
133
+ }
134
+ export function normalizeDirectory(value) {
135
+ const trimmed = value?.trim();
136
+ if (!trimmed) {
137
+ return undefined;
138
+ }
139
+ return trimmed.replace(/\\/gu, "/").replace(/\/+$/u, "") || "/";
140
+ }
141
+ export function epochMillisIso(value) {
142
+ const millis = asNumber(value);
143
+ if (millis === undefined || !Number.isFinite(millis)) {
144
+ return undefined;
145
+ }
146
+ const date = new Date(millis);
147
+ return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
148
+ }
149
+ function appendMessagePart(content, part, role, loss) {
150
+ const partType = asString(part.type);
151
+ if (partType === "text" || partType === "reasoning") {
152
+ appendTextBlock(content, asString(part.text), part.synthetic === true);
153
+ return;
154
+ }
155
+ if (partType === "file" || partType === "file_part") {
156
+ appendFilePart(content, part);
157
+ return;
158
+ }
159
+ if (partType === "tool") {
160
+ appendToolPart(content, part);
161
+ return;
162
+ }
163
+ if (partType === "step-start" || partType === "step-finish" || partType === "snapshot" || partType === "patch") {
164
+ return;
165
+ }
166
+ if (partType === "compaction") {
167
+ loss("opencode_compaction_part_evidence", `Compaction part ${asString(part.id) ?? "?"} is retained only as a diagnostic; its summary/usage is not projected as assistant usage.`);
168
+ return;
169
+ }
170
+ if (partType === "agent" || partType === "subtask") {
171
+ const label = asString(part.name) ??
172
+ asString(part.agent) ??
173
+ asString(part.description) ??
174
+ asString(part.prompt) ??
175
+ partType;
176
+ appendTextBlock(content, `[${partType}] ${label}`, true);
177
+ return;
178
+ }
179
+ if (partType === "retry") {
180
+ loss("opencode_retry_part_evidence", `Retry part ${asString(part.id) ?? "?"} was recorded for ${role}; kept as a diagnostic.`);
181
+ return;
182
+ }
183
+ loss("opencode_unknown_part_type", `Unknown OpenCode ${role} part type ${String(partType)}; raw payload retained in the source row only.`);
184
+ }
185
+ function appendTextBlock(content, text, synthetic = false) {
186
+ if (!text?.trim()) {
187
+ return;
188
+ }
189
+ content.push(synthetic ? { type: "text", text, synthetic: true } : { type: "text", text });
190
+ }
191
+ function appendUserFiles(content, files) {
192
+ if (!Array.isArray(files)) {
193
+ return;
194
+ }
195
+ for (const file of files) {
196
+ if (isObject(file)) {
197
+ appendFilePart(content, file);
198
+ }
199
+ }
200
+ }
201
+ function appendFilePart(content, part) {
202
+ // v1 FilePart: { filename, mime, url }; v2 FileAttachment: { name, ... }.
203
+ // A data: URL is never projected as text; it can be megabytes of base64.
204
+ const filename = asString(part.filename) ?? asString(part.name) ?? asString(part.path);
205
+ if (filename) {
206
+ content.push({ type: "text", text: `[file] ${truncateLabel(filename)}` });
207
+ return;
208
+ }
209
+ const mime = asString(part.mime) ?? asString(part.mediaType);
210
+ if (mime) {
211
+ content.push({ type: "text", text: `[file ${truncateLabel(mime)}]` });
212
+ return;
213
+ }
214
+ content.push({ type: "text", text: "[file attachment]" });
215
+ }
216
+ function appendToolPart(content, item) {
217
+ const state = isObject(item.state) ? item.state : undefined;
218
+ const callId = asString(item.callID) ?? asString(item.callId) ?? asString(item.id);
219
+ const toolName = asString(item.tool) ?? asString(item.name) ?? "tool";
220
+ content.push({
221
+ type: "tool_call",
222
+ id: callId,
223
+ name: toolName,
224
+ input: state?.input ?? item.input ?? {},
225
+ });
226
+ const status = asString(state?.status);
227
+ const error = state?.error ?? item.error;
228
+ const output = state?.output ?? state?.content ?? item.output;
229
+ const isError = status === "error" || error !== undefined;
230
+ if (isError || output !== undefined) {
231
+ // Keep both halves when a failed call carries partial content and an error.
232
+ const detail = isError && output !== undefined && error !== undefined
233
+ ? `${stringifyValue(output)}\n${stringifyValue(error)}`
234
+ : (output ?? error ?? { status });
235
+ content.push({
236
+ type: "tool_result",
237
+ tool_use_id: callId,
238
+ content: detail,
239
+ ...(isError ? { is_error: true } : {}),
240
+ });
241
+ }
242
+ }
243
+ function appendShellEvidence(content, parsed) {
244
+ const command = asString(parsed.command);
245
+ const output = parsed.output;
246
+ const status = asString(parsed.status);
247
+ const exit = asNumber(parsed.exit);
248
+ const text = [
249
+ command ? `$ ${command}` : "shell",
250
+ status ? `status: ${status}${exit !== undefined ? ` (exit ${exit})` : ""}` : undefined,
251
+ output !== undefined ? stringifyValue(output) : undefined,
252
+ ].filter((value) => Boolean(value)).join("\n");
253
+ appendTextBlock(content, text || "shell command evidence", true);
254
+ }
255
+ function extractContentText(value) {
256
+ if (typeof value === "string") {
257
+ return value.trim() || undefined;
258
+ }
259
+ if (!Array.isArray(value)) {
260
+ return undefined;
261
+ }
262
+ const parts = [];
263
+ for (const item of value) {
264
+ if (isObject(item)) {
265
+ const text = asString(item.text);
266
+ if (text) {
267
+ parts.push(text);
268
+ }
269
+ }
270
+ }
271
+ return parts.join("\n").trim() || undefined;
272
+ }
273
+ function describeValue(value) {
274
+ const text = typeof value === "string" ? value : stringifyValue(value);
275
+ return truncateLabel(text);
276
+ }
277
+ function stringifyValue(value) {
278
+ if (typeof value === "string") {
279
+ return value;
280
+ }
281
+ try {
282
+ return JSON.stringify(value) ?? String(value);
283
+ }
284
+ catch {
285
+ return String(value);
286
+ }
287
+ }
288
+ function truncateLabel(value, limit = 160) {
289
+ return value.length <= limit ? value : `${value.slice(0, limit - 1)}…`;
290
+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,CAAC;AACzE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type SourceReadBudget } from "../../core/read-budget.js";
2
+ import type { ExtractedSessionSeed } from "../../core/conversation-seeds.js";
3
+ export interface OpenCodeSqliteReadOptions {
4
+ targetSessionRefs?: readonly string[];
5
+ budget?: SourceReadBudget;
6
+ }
7
+ export declare function extractOpenCodeSqliteSeeds(dbPath: string, options?: OpenCodeSqliteReadOptions): ExtractedSessionSeed[];
8
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../../src/platforms/opencode/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAyD,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACzH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAmC7E,MAAM,WAAW,yBAAyB;IACxC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,yBAA8B,GACtC,oBAAoB,EAAE,CA+BxB"}
@@ -0,0 +1,321 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import { readBudgetedSqliteRows, SourceReadBudgetExceededError } from "../../core/read-budget.js";
3
+ import { asString, isObject, safeJsonParse } from "../../core/type-guards.js";
4
+ import { buildMessageRecord, epochMillisIso, normalizeDirectory, normalizeOpenCodeUsage, parseJsonObject, } from "./sqlite-records.js";
5
+ export function extractOpenCodeSqliteSeeds(dbPath, options = {}) {
6
+ const db = new DatabaseSync(dbPath, { readOnly: true });
7
+ let transactionOpen = false;
8
+ try {
9
+ const schema = detectSchema(db, dbPath);
10
+ db.exec("BEGIN");
11
+ transactionOpen = true;
12
+ const seeds = [];
13
+ for (const sessionRow of listSessions(db, schema, options)) {
14
+ const rawSessionId = asString(sessionRow.id);
15
+ if (!rawSessionId) {
16
+ continue;
17
+ }
18
+ const seed = buildSessionSeed(db, schema, sessionRow, rawSessionId, options);
19
+ if (seed) {
20
+ seeds.push(seed);
21
+ }
22
+ }
23
+ db.exec("COMMIT");
24
+ transactionOpen = false;
25
+ return seeds;
26
+ }
27
+ finally {
28
+ if (transactionOpen) {
29
+ try {
30
+ db.exec("ROLLBACK");
31
+ }
32
+ catch {
33
+ /* the connection is already unusable; close below still runs */
34
+ }
35
+ }
36
+ db.close();
37
+ }
38
+ }
39
+ function detectSchema(db, dbPath) {
40
+ const names = new Set(db
41
+ .prepare("SELECT name FROM sqlite_master WHERE type = 'table'")
42
+ .all()
43
+ .map((row) => asString(row.name))
44
+ .filter((name) => name !== undefined));
45
+ if (names.has("session_message")) {
46
+ const sessionsTable = names.has("session_v2")
47
+ ? "session_v2"
48
+ : names.has("session")
49
+ ? "session"
50
+ : undefined;
51
+ if (!sessionsTable) {
52
+ throw new Error(`Unrecognized OpenCode SQLite schema in ${dbPath}: session_message exists without session/session_v2.`);
53
+ }
54
+ const partsTable = names.has("session_part") ? "session_part" : undefined;
55
+ const schema = {
56
+ version: 2,
57
+ sessionsTable,
58
+ messagesTable: "session_message",
59
+ ...(partsTable ? { partsTable } : {}),
60
+ sessionColumns: tableColumns(db, sessionsTable),
61
+ messageColumns: tableColumns(db, "session_message"),
62
+ partColumns: partsTable ? tableColumns(db, partsTable) : new Set(),
63
+ };
64
+ requireColumns(schema.messageColumns, ["data"], "session_message", dbPath);
65
+ return schema;
66
+ }
67
+ if (names.has("session") && names.has("message")) {
68
+ const partsTable = names.has("part") ? "part" : undefined;
69
+ const schema = {
70
+ version: 1,
71
+ sessionsTable: "session",
72
+ messagesTable: "message",
73
+ ...(partsTable ? { partsTable } : {}),
74
+ sessionColumns: tableColumns(db, "session"),
75
+ messageColumns: tableColumns(db, "message"),
76
+ partColumns: partsTable ? tableColumns(db, partsTable) : new Set(),
77
+ };
78
+ requireColumns(schema.messageColumns, ["data"], "message", dbPath);
79
+ return schema;
80
+ }
81
+ throw new Error(`Unrecognized OpenCode SQLite schema in ${dbPath}: expected session_message/session_v2 or message/session tables.`);
82
+ }
83
+ function requireColumns(columns, required, table, dbPath) {
84
+ const missing = required.filter((column) => !columns.has(column));
85
+ if (missing.length > 0) {
86
+ throw new Error(`Unrecognized OpenCode SQLite schema in ${dbPath}: ${table} is missing ${missing.join(", ")}.`);
87
+ }
88
+ }
89
+ function tableColumns(db, table) {
90
+ return new Set(db
91
+ .prepare(`PRAGMA table_info(${table})`)
92
+ .all()
93
+ .map((row) => asString(row.name))
94
+ .filter((name) => name !== undefined));
95
+ }
96
+ function pickColumns(columns, wanted) {
97
+ return wanted.filter((column) => columns.has(column));
98
+ }
99
+ function matchesSessionRef(ref, rawSessionId) {
100
+ const canonical = `sess:opencode:${rawSessionId}`;
101
+ return ref === canonical || ref === rawSessionId || canonical.startsWith(ref) || rawSessionId.startsWith(ref);
102
+ }
103
+ function listSessions(db, schema, options) {
104
+ const selected = pickColumns(schema.sessionColumns, [
105
+ "id",
106
+ "title",
107
+ "directory",
108
+ "parent_id",
109
+ "model",
110
+ "time_created",
111
+ "time_updated",
112
+ ]);
113
+ if (!selected.includes("id")) {
114
+ throw new Error(`Unrecognized OpenCode SQLite schema: ${schema.sessionsTable} has no id column.`);
115
+ }
116
+ const rows = readBudgetedSqliteRows(db, `SELECT ${selected.join(", ")} FROM ${schema.sessionsTable} ORDER BY id`, selected, [], options.budget, `${schema.sessionsTable} rows`);
117
+ const targetRefs = options.targetSessionRefs?.filter((ref) => ref.trim().length > 0) ?? [];
118
+ if (targetRefs.length === 0) {
119
+ return rows;
120
+ }
121
+ const matchedIds = new Set();
122
+ for (const row of rows) {
123
+ const id = asString(row.id);
124
+ if (id && targetRefs.some((ref) => matchesSessionRef(ref, id))) {
125
+ matchedIds.add(id);
126
+ }
127
+ }
128
+ let added = true;
129
+ while (added) {
130
+ added = false;
131
+ for (const row of rows) {
132
+ const id = asString(row.id);
133
+ if (!id || matchedIds.has(id)) {
134
+ continue;
135
+ }
136
+ const parentId = asString(row.parent_id);
137
+ if (parentId && matchedIds.has(parentId)) {
138
+ matchedIds.add(id);
139
+ added = true;
140
+ }
141
+ }
142
+ }
143
+ return rows.filter((row) => {
144
+ const id = asString(row.id);
145
+ return id !== undefined && matchedIds.has(id);
146
+ });
147
+ }
148
+ function buildSessionSeed(db, schema, session, rawSessionId, options) {
149
+ const diagnostics = [];
150
+ const workingDirectory = normalizeDirectory(asString(session.directory));
151
+ const title = asString(session.title)?.trim() || undefined;
152
+ const parentId = asString(session.parent_id);
153
+ const createdAt = epochMillisIso(session.time_created);
154
+ const updatedAt = epochMillisIso(session.time_updated);
155
+ const sessionModel = readSessionModel(session.model);
156
+ const messages = readMessages(db, schema, rawSessionId, options.budget, diagnostics);
157
+ const partsByMessage = readParts(db, schema, rawSessionId, options.budget, diagnostics);
158
+ const records = [];
159
+ let firstAssistantModel;
160
+ for (const [index, message] of messages.entries()) {
161
+ const messageId = asString(message.id);
162
+ const parsed = parseJsonObject(asString(message.data), messageId, diagnostics, "message");
163
+ if (!parsed) {
164
+ continue;
165
+ }
166
+ const parts = (messageId ? partsByMessage.get(messageId) : undefined) ?? [];
167
+ const role = schema.version === 2 ? asString(message.type) : asString(parsed.role);
168
+ const messageModel = asString(parsed.modelID) ??
169
+ (isObject(parsed.model) ? asString(parsed.model.id) : undefined);
170
+ const effectiveModel = messageModel ?? sessionModel ?? firstAssistantModel;
171
+ const effectiveParsed = { ...parsed };
172
+ if (role === "assistant") {
173
+ const assistantUsage = normalizeOpenCodeUsage(parsed.tokens);
174
+ if (assistantUsage) {
175
+ records.push({
176
+ pointer: `sqlite:assistant-usage[${index}]`,
177
+ observedAt: epochMillisIso(message.time_created) ?? createdAt,
178
+ rawJson: JSON.stringify({
179
+ usage_only: true,
180
+ usage: assistantUsage,
181
+ ...(effectiveModel ? { model: effectiveModel } : {}),
182
+ ...(asString(parsed.finish) ? { stop_reason: asString(parsed.finish) } : {}),
183
+ source_event_type: "opencode_assistant_message",
184
+ call_kind: "assistant",
185
+ }),
186
+ });
187
+ // Usage is projected once as an independent call record so compaction
188
+ // and assistant calls share one attribution path.
189
+ delete effectiveParsed.tokens;
190
+ }
191
+ }
192
+ if (role === "compaction") {
193
+ const compactionUsage = normalizeOpenCodeUsage(parsed.tokens);
194
+ if (compactionUsage) {
195
+ records.push({
196
+ pointer: `sqlite:compaction-usage[${index}]`,
197
+ observedAt: epochMillisIso(message.time_created) ?? createdAt,
198
+ rawJson: JSON.stringify({
199
+ usage_only: true,
200
+ usage: compactionUsage,
201
+ ...(effectiveModel ? { model: effectiveModel } : {}),
202
+ source_event_type: "opencode_compaction",
203
+ call_kind: "compaction",
204
+ }),
205
+ });
206
+ }
207
+ }
208
+ const record = buildMessageRecord(schema, message, effectiveParsed, parts, {
209
+ messageId,
210
+ workingDirectory,
211
+ diagnostics,
212
+ });
213
+ if (!record) {
214
+ continue;
215
+ }
216
+ records.push({
217
+ pointer: `sqlite:${schema.messagesTable}[${index}]`,
218
+ observedAt: record.observedAt ?? epochMillisIso(message.time_created) ?? createdAt,
219
+ rawJson: JSON.stringify(record.record),
220
+ });
221
+ firstAssistantModel = firstAssistantModel ?? record.model;
222
+ }
223
+ const model = sessionModel ?? firstAssistantModel;
224
+ if (parentId || title || model || workingDirectory) {
225
+ records.unshift({
226
+ pointer: "sqlite:session",
227
+ observedAt: createdAt ?? updatedAt,
228
+ rawJson: JSON.stringify({
229
+ id: `sess:opencode:${rawSessionId}`,
230
+ title,
231
+ model,
232
+ cwd: workingDirectory,
233
+ ...(parentId ? { parentUuid: parentId, isSidechain: true } : {}),
234
+ }),
235
+ });
236
+ }
237
+ return {
238
+ sessionId: `sess:opencode:${rawSessionId}`,
239
+ ...(title ? { title } : {}),
240
+ ...(createdAt ? { createdAt } : {}),
241
+ ...(updatedAt ? { updatedAt } : {}),
242
+ ...(model ? { model } : {}),
243
+ ...(workingDirectory ? { workingDirectory } : {}),
244
+ ...(diagnostics.length > 0 ? { diagnostics } : {}),
245
+ records,
246
+ };
247
+ }
248
+ function readSessionModel(value) {
249
+ const parsed = typeof value === "string" ? safeJsonParse(value) : value;
250
+ return isObject(parsed) ? asString(parsed.id) : undefined;
251
+ }
252
+ function readMessages(db, schema, sessionId, budget, diagnostics) {
253
+ const selected = pickColumns(schema.messageColumns, [
254
+ "id",
255
+ "type",
256
+ "seq",
257
+ "data",
258
+ "time_created",
259
+ "time_updated",
260
+ ]);
261
+ const order = schema.messagesTable === "session_message" && schema.messageColumns.has("seq")
262
+ ? "seq ASC"
263
+ : "time_created ASC, id ASC";
264
+ try {
265
+ return readBudgetedSqliteRows(db, `SELECT ${selected.join(", ")} FROM ${schema.messagesTable} WHERE session_id = ? ORDER BY ${order}`, selected, [sessionId], budget, `${schema.messagesTable} rows`);
266
+ }
267
+ catch (error) {
268
+ if (error instanceof SourceReadBudgetExceededError) {
269
+ throw error;
270
+ }
271
+ diagnostics.push({
272
+ code: "opencode_message_read_failed",
273
+ detail: `Could not read ${schema.messagesTable} rows for session ${sessionId}: ${error.message}`,
274
+ });
275
+ return [];
276
+ }
277
+ }
278
+ function readParts(db, schema, sessionId, budget, diagnostics) {
279
+ if (!schema.partsTable) {
280
+ return new Map();
281
+ }
282
+ const selected = pickColumns(schema.partColumns, [
283
+ "message_id",
284
+ "ordinal",
285
+ "type",
286
+ "data",
287
+ "time_created",
288
+ "time_updated",
289
+ ]);
290
+ const order = schema.partsTable === "session_part" && schema.partColumns.has("ordinal")
291
+ ? "message_id ASC, ordinal ASC"
292
+ : schema.partColumns.has("time_created")
293
+ ? "message_id ASC, time_created ASC, rowid ASC"
294
+ : "message_id ASC, rowid ASC";
295
+ let rows;
296
+ try {
297
+ rows = readBudgetedSqliteRows(db, `SELECT ${selected.join(", ")} FROM ${schema.partsTable} WHERE session_id = ? ORDER BY ${order}`, selected, [sessionId], budget, `${schema.partsTable} rows`);
298
+ }
299
+ catch (error) {
300
+ if (error instanceof SourceReadBudgetExceededError) {
301
+ throw error;
302
+ }
303
+ diagnostics.push({
304
+ code: "opencode_part_read_failed",
305
+ detail: `Could not read ${schema.partsTable} rows for session ${sessionId}: ${error.message}`,
306
+ });
307
+ return new Map();
308
+ }
309
+ const byMessage = new Map();
310
+ for (const row of rows) {
311
+ const messageId = asString(row.message_id);
312
+ if (!messageId) {
313
+ continue;
314
+ }
315
+ const existing = byMessage.get(messageId) ?? [];
316
+ existing.push(row);
317
+ byMessage.set(messageId, existing);
318
+ }
319
+ return byMessage;
320
+ }
321
+ //# sourceMappingURL=sqlite.js.map