hippo-memory 1.72.0 → 2.1.0

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 (995) hide show
  1. package/README.md +6 -4
  2. package/dist/agent-memories/apply.d.ts +7 -5
  3. package/dist/agent-memories/apply.js +66 -39
  4. package/dist/agent-memories/claude-code.d.ts +8 -2
  5. package/dist/agent-memories/claude-code.js +26 -7
  6. package/dist/agent-memories/copilot.js +2 -1
  7. package/dist/agent-memories/files.js +2 -1
  8. package/dist/agent-memories/legacy.d.ts +6 -3
  9. package/dist/agent-memories/legacy.js +35 -14
  10. package/dist/agent-memories/markdown.d.ts +3 -1
  11. package/dist/agent-memories/markdown.js +3 -1
  12. package/dist/agent-memories/openclaw.js +5 -2
  13. package/dist/agent-memories/plan.js +11 -1
  14. package/dist/agent-memories/project-folds.js +2 -1
  15. package/dist/agent-memories/report.d.ts +4 -1
  16. package/dist/agent-memories/report.js +43 -9
  17. package/dist/agent-memories/source.d.ts +8 -2
  18. package/dist/agent-memories/source.js +11 -3
  19. package/dist/agent-memories/sync.d.ts +7 -2
  20. package/dist/agent-memories/sync.js +141 -101
  21. package/dist/api/assemble.d.ts +6 -4
  22. package/dist/api/assemble.js +11 -5
  23. package/dist/api/{audit.d.ts → auth/audit.d.ts} +18 -16
  24. package/dist/api/auth/audit.js +58 -0
  25. package/dist/api/{auth.d.ts → auth/auth.d.ts} +19 -16
  26. package/dist/api/{auth.js → auth/auth.js} +66 -54
  27. package/dist/api/{quarantine.d.ts → auth/quarantine.d.ts} +8 -7
  28. package/dist/api/{quarantine.js → auth/quarantine.js} +8 -7
  29. package/dist/api/auth/session-owners.d.ts +10 -0
  30. package/dist/api/auth/session-owners.js +35 -0
  31. package/dist/api/availability.d.ts +3 -1
  32. package/dist/api/availability.js +3 -1
  33. package/dist/api/busy.d.ts +2 -0
  34. package/dist/api/busy.js +2 -0
  35. package/dist/api/cli-surface.d.ts +6 -0
  36. package/dist/api/cli-surface.js +6 -0
  37. package/dist/api/config-of.d.ts +5 -0
  38. package/dist/api/config-of.js +6 -0
  39. package/dist/api/context-auto.d.ts +4 -1
  40. package/dist/api/context-auto.js +14 -4
  41. package/dist/api/context-render.js +14 -7
  42. package/dist/api/context-select.d.ts +4 -1
  43. package/dist/api/context-select.js +31 -34
  44. package/dist/api/context-types.d.ts +38 -12
  45. package/dist/api/context.d.ts +8 -5
  46. package/dist/api/context.js +120 -63
  47. package/dist/api/continuity.d.ts +24 -21
  48. package/dist/api/continuity.js +18 -20
  49. package/dist/api/correction-latency.d.ts +3 -1
  50. package/dist/api/correction-latency.js +3 -1
  51. package/dist/api/error-reply.d.ts +4 -1
  52. package/dist/api/error-reply.js +12 -3
  53. package/dist/api/index.d.ts +39 -23
  54. package/dist/api/index.js +21 -23
  55. package/dist/api/instruction-detect.d.ts +4 -1
  56. package/dist/api/instruction-detect.js +75 -20
  57. package/dist/api/ledger-db.d.ts +15 -11
  58. package/dist/api/ledger-db.js +21 -23
  59. package/dist/api/memories/conflicts.d.ts +33 -0
  60. package/dist/api/memories/conflicts.js +67 -0
  61. package/dist/api/{forget.d.ts → memories/forget.d.ts} +11 -9
  62. package/dist/api/{forget.js → memories/forget.js} +23 -17
  63. package/dist/api/memories/memories.d.ts +27 -0
  64. package/dist/api/memories/memories.js +52 -0
  65. package/dist/api/memories/outcome.d.ts +22 -0
  66. package/dist/api/memories/outcome.js +28 -0
  67. package/dist/api/memories/promote.d.ts +40 -0
  68. package/dist/api/memories/promote.js +76 -0
  69. package/dist/api/memories/refine.d.ts +10 -0
  70. package/dist/api/memories/refine.js +12 -0
  71. package/dist/api/{remember-local.d.ts → memories/remember-local.d.ts} +17 -9
  72. package/dist/api/{remember-local.js → memories/remember-local.js} +46 -24
  73. package/dist/api/{remember.d.ts → memories/remember.d.ts} +22 -13
  74. package/dist/api/{remember.js → memories/remember.js} +50 -32
  75. package/dist/api/objects/cards.d.ts +39 -0
  76. package/dist/api/{cards.js → objects/cards.js} +12 -14
  77. package/dist/api/{drill-down.d.ts → objects/drill-down.d.ts} +12 -10
  78. package/dist/api/{drill-down.js → objects/drill-down.js} +7 -7
  79. package/dist/api/objects/goals.d.ts +18 -0
  80. package/dist/api/{goals.js → objects/goals.js} +12 -12
  81. package/dist/api/objects/graph.d.ts +11 -0
  82. package/dist/api/objects/graph.js +16 -0
  83. package/dist/api/objects/objects.d.ts +9 -0
  84. package/dist/api/{objects.js → objects/objects.js} +2 -3
  85. package/dist/api/objects/predictions.d.ts +11 -0
  86. package/dist/api/{predictions.js → objects/predictions.js} +7 -5
  87. package/dist/api/{projects.d.ts → objects/projects.d.ts} +8 -5
  88. package/dist/api/{projects.js → objects/projects.js} +8 -4
  89. package/dist/api/pilot-arm.d.ts +8 -4
  90. package/dist/api/pilot-arm.js +5 -4
  91. package/dist/api/prompt-hook.d.ts +35 -20
  92. package/dist/api/prompt-hook.js +66 -44
  93. package/dist/api/provenance-coverage.d.ts +3 -1
  94. package/dist/api/provenance-coverage.js +3 -1
  95. package/dist/api/recall/finish.d.ts +185 -0
  96. package/dist/api/recall/finish.js +301 -0
  97. package/dist/api/{recall-pipeline.d.ts → recall/pipeline.d.ts} +12 -8
  98. package/dist/api/{recall-pipeline.js → recall/pipeline.js} +185 -101
  99. package/dist/api/recall/recall.d.ts +6 -0
  100. package/dist/api/{recall.js → recall/recall.js} +116 -72
  101. package/dist/api/recall/render.d.ts +39 -0
  102. package/dist/api/recall/render.js +60 -0
  103. package/dist/api/{recall-request.d.ts → recall/request.d.ts} +7 -5
  104. package/dist/api/recall/request.js +261 -0
  105. package/dist/api/{recall-cli.d.ts → recall/rows.d.ts} +18 -12
  106. package/dist/api/{recall-cli.js → recall/rows.js} +28 -27
  107. package/dist/api/{recall-types.d.ts → recall/types.d.ts} +95 -68
  108. package/dist/api/{recall-types.js → recall/types.js} +1 -1
  109. package/dist/api/session-end.d.ts +36 -8
  110. package/dist/api/session-end.js +71 -25
  111. package/dist/api/{auto-sleep.d.ts → sleep/auto-sleep.d.ts} +9 -5
  112. package/dist/api/{auto-sleep.js → sleep/auto-sleep.js} +7 -12
  113. package/dist/api/sleep/dormant.d.ts +25 -0
  114. package/dist/api/sleep/dormant.js +64 -0
  115. package/dist/api/{learn.d.ts → sleep/learn.d.ts} +5 -4
  116. package/dist/api/sleep/learn.js +138 -0
  117. package/dist/api/sleep/sleep-run.d.ts +38 -0
  118. package/dist/api/{sleep-run.js → sleep/sleep-run.js} +54 -45
  119. package/dist/api/{sleep.d.ts → sleep/sleep.d.ts} +17 -11
  120. package/dist/api/sleep/sleep.js +9 -0
  121. package/dist/api/status.d.ts +3 -1
  122. package/dist/api/status.js +3 -1
  123. package/dist/api/store-init.d.ts +4 -1
  124. package/dist/api/store-init.js +4 -1
  125. package/dist/api/tokens.d.ts +10 -9
  126. package/dist/api/tokens.js +9 -10
  127. package/dist/api/types.d.ts +27 -12
  128. package/dist/api/types.js +13 -4
  129. package/dist/capture/caller-session.d.ts +8 -2
  130. package/dist/capture/caller-session.js +16 -6
  131. package/dist/capture/capture-error.d.ts +3 -1
  132. package/dist/capture/capture-error.js +3 -1
  133. package/dist/capture/codex-patch.js +7 -2
  134. package/dist/capture/command.d.ts +4 -2
  135. package/dist/capture/command.js +34 -15
  136. package/dist/capture/compact-resume-caller.js +15 -8
  137. package/dist/capture/compact.d.ts +8 -5
  138. package/dist/capture/compact.js +34 -23
  139. package/dist/capture/compaction-items-caller.js +9 -3
  140. package/dist/capture/compaction-record.d.ts +4 -3
  141. package/dist/capture/compaction-record.js +20 -12
  142. package/dist/capture/compaction-spool.d.ts +18 -9
  143. package/dist/capture/compaction-spool.js +105 -63
  144. package/dist/capture/copilot-transcript.d.ts +11 -3
  145. package/dist/capture/copilot-transcript.js +16 -6
  146. package/dist/capture/extract.js +20 -8
  147. package/dist/capture/failure-caller.js +23 -12
  148. package/dist/capture/failure-reading.d.ts +10 -3
  149. package/dist/capture/failure-reading.js +24 -7
  150. package/dist/capture/pre-compact-caller.js +11 -4
  151. package/dist/capture/session-digest.d.ts +15 -4
  152. package/dist/capture/session-digest.js +39 -13
  153. package/dist/capture/session-end-caller.d.ts +4 -1
  154. package/dist/capture/session-end-caller.js +20 -8
  155. package/dist/capture/session-texts.d.ts +6 -2
  156. package/dist/capture/session-texts.js +22 -7
  157. package/dist/capture/session-worker.d.ts +4 -2
  158. package/dist/capture/session-worker.js +58 -17
  159. package/dist/capture/transcript.d.ts +13 -4
  160. package/dist/capture/transcript.js +32 -10
  161. package/dist/capture/working-state.d.ts +13 -4
  162. package/dist/capture/working-state.js +50 -56
  163. package/dist/cli/api-context.d.ts +14 -2
  164. package/dist/cli/api-context.js +45 -2
  165. package/dist/cli/audit.js +33 -33
  166. package/dist/cli/auth.js +23 -31
  167. package/dist/cli/briefs.d.ts +1 -1
  168. package/dist/cli/briefs.js +20 -15
  169. package/dist/cli/card.d.ts +1 -1
  170. package/dist/cli/card.js +56 -73
  171. package/dist/cli/client.d.ts +12 -5
  172. package/dist/cli/client.js +53 -23
  173. package/dist/cli/compact-resume-payload.d.ts +4 -1
  174. package/dist/cli/compact-resume-payload.js +12 -5
  175. package/dist/cli/context.js +43 -18
  176. package/dist/cli/continuity.d.ts +5 -5
  177. package/dist/cli/continuity.js +90 -107
  178. package/dist/cli/curate.d.ts +5 -4
  179. package/dist/cli/curate.js +55 -77
  180. package/dist/cli/dag.d.ts +1 -1
  181. package/dist/cli/dag.js +14 -17
  182. package/dist/cli/decisions.js +30 -30
  183. package/dist/cli/eval.js +16 -21
  184. package/dist/cli/exit.d.ts +4 -1
  185. package/dist/cli/exit.js +10 -2
  186. package/dist/cli/explain.js +12 -11
  187. package/dist/cli/flag-values.d.ts +1 -1
  188. package/dist/cli/flag-values.js +9 -18
  189. package/dist/cli/github.d.ts +6 -0
  190. package/dist/cli/github.js +25 -13
  191. package/dist/cli/goals.d.ts +1 -1
  192. package/dist/cli/goals.js +39 -56
  193. package/dist/cli/graph.d.ts +1 -1
  194. package/dist/cli/graph.js +15 -11
  195. package/dist/cli/hook-runtime.d.ts +34 -10
  196. package/dist/cli/hook-runtime.js +41 -16
  197. package/dist/cli/incidents.d.ts +1 -1
  198. package/dist/cli/incidents.js +25 -25
  199. package/dist/cli/init.d.ts +1 -1
  200. package/dist/cli/init.js +35 -20
  201. package/dist/cli/install-steps.d.ts +12 -3
  202. package/dist/cli/install-steps.js +42 -18
  203. package/dist/cli/last-sleep.d.ts +4 -1
  204. package/dist/cli/last-sleep.js +9 -4
  205. package/dist/cli/maintenance.d.ts +1 -1
  206. package/dist/cli/maintenance.js +11 -12
  207. package/dist/cli/notes.d.ts +1 -1
  208. package/dist/cli/notes.js +8 -5
  209. package/dist/cli/object-verbs.d.ts +5 -5
  210. package/dist/cli/object-verbs.js +13 -16
  211. package/dist/cli/open-browser.js +11 -2
  212. package/dist/cli/playbooks.d.ts +3 -3
  213. package/dist/cli/playbooks.js +40 -32
  214. package/dist/cli/predictions.js +17 -22
  215. package/dist/cli/print.js +4 -2
  216. package/dist/cli/projects.js +21 -11
  217. package/dist/cli/quality-repair-once.d.ts +1 -1
  218. package/dist/cli/quality-repair-once.js +7 -6
  219. package/dist/cli/recall.js +129 -93
  220. package/dist/cli/refine-llm.d.ts +15 -4
  221. package/dist/cli/refine-llm.js +17 -7
  222. package/dist/cli/remember.js +51 -55
  223. package/dist/cli/scheduler.d.ts +4 -1
  224. package/dist/cli/scheduler.js +9 -5
  225. package/dist/cli/serve.js +28 -18
  226. package/dist/cli/session-hooks.d.ts +2 -6
  227. package/dist/cli/session-hooks.js +140 -112
  228. package/dist/cli/setup.d.ts +1 -1
  229. package/dist/cli/setup.js +56 -34
  230. package/dist/cli/shared.d.ts +4 -2
  231. package/dist/cli/shared.js +26 -11
  232. package/dist/cli/slack.js +15 -24
  233. package/dist/cli/sleep-render.d.ts +3 -1
  234. package/dist/cli/sleep-render.js +8 -5
  235. package/dist/cli/sleep.js +16 -8
  236. package/dist/cli/status.d.ts +4 -4
  237. package/dist/cli/status.js +32 -27
  238. package/dist/cli/stdin.d.ts +10 -3
  239. package/dist/cli/stdin.js +10 -3
  240. package/dist/cli/transfer.d.ts +4 -4
  241. package/dist/cli/transfer.js +97 -82
  242. package/dist/cli/usage.d.ts +1 -1
  243. package/dist/cli/usage.js +1 -1
  244. package/dist/cli/verb-row.d.ts +2 -0
  245. package/dist/cli/verbs/health.js +2 -0
  246. package/dist/cli/verbs/memory.js +47 -53
  247. package/dist/cli/verbs/objects.js +16 -7
  248. package/dist/cli/verbs/sessions.js +4 -2
  249. package/dist/cli/versioned-verbs.d.ts +8 -7
  250. package/dist/cli/versioned-verbs.js +31 -21
  251. package/dist/cli.js +14 -18
  252. package/dist/connectors/dlq.d.ts +6 -6
  253. package/dist/connectors/dlq.js +12 -7
  254. package/dist/connectors/github/backfill.d.ts +4 -4
  255. package/dist/connectors/github/backfill.js +6 -4
  256. package/dist/connectors/github/deletion.d.ts +6 -4
  257. package/dist/connectors/github/deletion.js +5 -4
  258. package/dist/connectors/github/dlq.d.ts +8 -6
  259. package/dist/connectors/github/dlq.js +11 -5
  260. package/dist/connectors/github/ingest.d.ts +2 -2
  261. package/dist/connectors/github/ingest.js +9 -5
  262. package/dist/connectors/github/octokit-client.d.ts +3 -1
  263. package/dist/connectors/github/octokit-client.js +7 -2
  264. package/dist/connectors/github/ratelimit.d.ts +6 -2
  265. package/dist/connectors/github/ratelimit.js +6 -2
  266. package/dist/connectors/github/signature.d.ts +14 -3
  267. package/dist/connectors/github/signature.js +17 -3
  268. package/dist/connectors/github/tenant-routing.d.ts +6 -4
  269. package/dist/connectors/github/tenant-routing.js +6 -5
  270. package/dist/connectors/github/transform.js +50 -67
  271. package/dist/connectors/github/types.d.ts +10 -3
  272. package/dist/connectors/github/types.js +6 -2
  273. package/dist/connectors/github/webhook.d.ts +5 -5
  274. package/dist/connectors/github/webhook.js +36 -23
  275. package/dist/connectors/ingest.d.ts +5 -3
  276. package/dist/connectors/ingest.js +3 -3
  277. package/dist/connectors/slack/backfill.d.ts +5 -5
  278. package/dist/connectors/slack/backfill.js +3 -3
  279. package/dist/connectors/slack/deletion.d.ts +4 -4
  280. package/dist/connectors/slack/deletion.js +6 -5
  281. package/dist/connectors/slack/dlq.d.ts +4 -4
  282. package/dist/connectors/slack/dlq.js +6 -6
  283. package/dist/connectors/slack/ingest.d.ts +6 -4
  284. package/dist/connectors/slack/ingest.js +5 -4
  285. package/dist/connectors/slack/signature.d.ts +4 -1
  286. package/dist/connectors/slack/tenant-routing.d.ts +6 -4
  287. package/dist/connectors/slack/tenant-routing.js +6 -5
  288. package/dist/connectors/slack/transform.d.ts +6 -2
  289. package/dist/connectors/slack/transform.js +6 -2
  290. package/dist/connectors/slack/types.d.ts +3 -1
  291. package/dist/connectors/slack/web-client.js +8 -3
  292. package/dist/connectors/slack/webhook.d.ts +5 -5
  293. package/dist/connectors/slack/webhook.js +19 -11
  294. package/dist/connectors/slack/workspaces.d.ts +7 -3
  295. package/dist/connectors/slack/workspaces.js +7 -3
  296. package/dist/connectors/store.d.ts +8 -0
  297. package/dist/connectors/store.js +2 -0
  298. package/dist/consolidate/conflicts.js +24 -10
  299. package/dist/consolidate/dag-summary.js +2 -1
  300. package/dist/consolidate/dag.d.ts +10 -5
  301. package/dist/consolidate/dag.js +45 -39
  302. package/dist/consolidate/decay.js +19 -6
  303. package/dist/consolidate/dedupe.d.ts +14 -5
  304. package/dist/consolidate/dedupe.js +28 -17
  305. package/dist/consolidate/flush-units.d.ts +4 -1
  306. package/dist/consolidate/flush-units.js +4 -1
  307. package/dist/consolidate/half-life-migration.d.ts +18 -8
  308. package/dist/consolidate/half-life-migration.js +48 -18
  309. package/dist/consolidate/llm-passes.js +27 -11
  310. package/dist/consolidate/memory-value-weights.d.ts +6 -2
  311. package/dist/consolidate/memory-value-weights.js +6 -2
  312. package/dist/consolidate/memory-value.d.ts +30 -10
  313. package/dist/consolidate/memory-value.js +37 -14
  314. package/dist/consolidate/merge.d.ts +4 -1
  315. package/dist/consolidate/merge.js +47 -37
  316. package/dist/consolidate/overlap-index.d.ts +8 -2
  317. package/dist/consolidate/overlap-index.js +11 -4
  318. package/dist/consolidate/physics-pass.d.ts +3 -1
  319. package/dist/consolidate/physics-pass.js +10 -7
  320. package/dist/consolidate/replay.d.ts +11 -4
  321. package/dist/consolidate/replay.js +19 -7
  322. package/dist/consolidate/run.d.ts +13 -5
  323. package/dist/consolidate/run.js +4 -4
  324. package/dist/consolidate/sleep.d.ts +14 -6
  325. package/dist/consolidate/sleep.js +42 -39
  326. package/dist/consolidate/trace.d.ts +7 -2
  327. package/dist/consolidate/trace.js +7 -2
  328. package/dist/consolidate/traces.js +27 -30
  329. package/dist/core/ablation.d.ts +9 -3
  330. package/dist/core/ablation.js +14 -4
  331. package/dist/core/active-scope.d.ts +3 -1
  332. package/dist/core/active-scope.js +3 -1
  333. package/dist/core/agent-memory-tools.d.ts +2 -0
  334. package/dist/core/agent-memory-tools.js +2 -0
  335. package/dist/core/ambient.d.ts +4 -3
  336. package/dist/core/ambient.js +8 -6
  337. package/dist/core/api-errors.d.ts +9 -3
  338. package/dist/core/api-errors.js +9 -3
  339. package/dist/core/capture-contract.d.ts +4 -1
  340. package/dist/core/capture-contract.js +27 -8
  341. package/dist/core/compare.d.ts +24 -8
  342. package/dist/core/compare.js +24 -8
  343. package/dist/core/config.d.ts +18 -9
  344. package/dist/core/config.js +38 -29
  345. package/dist/core/cosine.d.ts +4 -1
  346. package/dist/core/cosine.js +4 -1
  347. package/dist/core/handoff.d.ts +7 -2
  348. package/dist/core/handoff.js +4 -1
  349. package/dist/core/markdown.js +22 -17
  350. package/dist/core/memory-audit.js +14 -3
  351. package/dist/core/memory-quality.d.ts +12 -3
  352. package/dist/core/memory-quality.js +57 -21
  353. package/dist/core/memory.d.ts +87 -30
  354. package/dist/core/memory.js +82 -33
  355. package/dist/core/merged-row.d.ts +8 -2
  356. package/dist/core/merged-row.js +10 -3
  357. package/dist/core/package-root.d.ts +3 -1
  358. package/dist/core/package-root.js +3 -1
  359. package/dist/core/particle-refresh.d.ts +8 -0
  360. package/dist/core/particle-refresh.js +22 -0
  361. package/dist/core/physics-config.d.ts +4 -1
  362. package/dist/core/physics-config.js +6 -2
  363. package/dist/core/physics.d.ts +39 -11
  364. package/dist/core/physics.js +71 -21
  365. package/dist/core/project-identity.d.ts +34 -17
  366. package/dist/core/project-identity.js +35 -18
  367. package/dist/core/project-remote.d.ts +8 -4
  368. package/dist/core/project-remote.js +31 -14
  369. package/dist/core/recall-scope.d.ts +33 -11
  370. package/dist/core/recall-scope.js +42 -15
  371. package/dist/core/rejection-digest.d.ts +7 -0
  372. package/dist/core/rejection-digest.js +13 -0
  373. package/dist/core/salience.d.ts +3 -1
  374. package/dist/core/salience.js +10 -4
  375. package/dist/core/search-types.d.ts +15 -2
  376. package/dist/core/search-types.js +11 -0
  377. package/dist/dashboard/dashboard-actions.d.ts +2 -2
  378. package/dist/dashboard/dashboard-actions.js +18 -7
  379. package/dist/dashboard/dashboard-queries.js +2 -7
  380. package/dist/dashboard/dashboard-snapshot.d.ts +2 -2
  381. package/dist/dashboard/dashboard-snapshot.js +5 -7
  382. package/dist/dashboard/dashboard.js +22 -8
  383. package/dist/db/backup.js +2 -2
  384. package/dist/db/busy.d.ts +10 -3
  385. package/dist/db/busy.js +27 -5
  386. package/dist/db/connect.d.ts +10 -2
  387. package/dist/db/connect.js +8 -2
  388. package/dist/db/continuity.d.ts +1 -1
  389. package/dist/db/continuity.js +27 -11
  390. package/dist/db/meta.d.ts +4 -1
  391. package/dist/db/meta.js +4 -1
  392. package/dist/db/migrate.d.ts +10 -5
  393. package/dist/db/migrate.js +40 -20
  394. package/dist/db/migrations/index.d.ts +1 -1
  395. package/dist/db/migrations/index.js +3 -1
  396. package/dist/db/migrations/types.d.ts +2 -1
  397. package/dist/db/migrations/v11.js +1 -0
  398. package/dist/db/migrations/v12.js +2 -1
  399. package/dist/db/migrations/v14.js +2 -0
  400. package/dist/db/migrations/v15.js +4 -2
  401. package/dist/db/migrations/v16.js +6 -3
  402. package/dist/db/migrations/v17.js +2 -1
  403. package/dist/db/migrations/v19.js +4 -2
  404. package/dist/db/migrations/v20.js +2 -1
  405. package/dist/db/migrations/v22.js +12 -6
  406. package/dist/db/migrations/v23.js +6 -3
  407. package/dist/db/migrations/v24.js +6 -3
  408. package/dist/db/migrations/v25.js +4 -2
  409. package/dist/db/migrations/v26.js +4 -2
  410. package/dist/db/migrations/v27.js +6 -3
  411. package/dist/db/migrations/v28.js +4 -2
  412. package/dist/db/migrations/v29.js +4 -2
  413. package/dist/db/migrations/v30.js +6 -3
  414. package/dist/db/migrations/v31.js +4 -2
  415. package/dist/db/migrations/v32.js +6 -3
  416. package/dist/db/migrations/v33.js +4 -2
  417. package/dist/db/migrations/v34.js +2 -1
  418. package/dist/db/migrations/v35.js +2 -1
  419. package/dist/db/migrations/v36.js +2 -1
  420. package/dist/db/migrations/v37.js +10 -5
  421. package/dist/db/migrations/v38.js +10 -5
  422. package/dist/db/migrations/v39.js +14 -6
  423. package/dist/db/migrations/v40.js +4 -2
  424. package/dist/db/migrations/v41.js +4 -2
  425. package/dist/db/migrations/v42.js +2 -1
  426. package/dist/db/migrations/v44.js +4 -2
  427. package/dist/db/migrations/v45.js +4 -2
  428. package/dist/db/migrations/v49.js +2 -1
  429. package/dist/db/migrations/v50.js +4 -2
  430. package/dist/db/migrations/v51.js +4 -2
  431. package/dist/db/migrations/v52.js +2 -1
  432. package/dist/db/migrations/v53.js +8 -4
  433. package/dist/db/migrations/v54.js +2 -1
  434. package/dist/db/migrations/v55.js +4 -2
  435. package/dist/db/migrations/v56.d.ts +3 -0
  436. package/dist/db/migrations/v56.js +28 -0
  437. package/dist/db/open.d.ts +24 -12
  438. package/dist/db/open.js +25 -13
  439. package/dist/db/physics-state.d.ts +8 -8
  440. package/dist/db/physics-state.js +17 -50
  441. package/dist/db/raw-archive-mirror-cleanup.d.ts +4 -2
  442. package/dist/db/raw-archive-mirror-cleanup.js +6 -4
  443. package/dist/db/request-stores.d.ts +20 -5
  444. package/dist/db/request-stores.js +15 -5
  445. package/dist/db/tables.d.ts +2 -1
  446. package/dist/db/tables.js +12 -4
  447. package/dist/db/vector-store.d.ts +13 -4
  448. package/dist/db/vector-store.js +35 -14
  449. package/dist/db/wal-checkpointer.d.ts +2 -1
  450. package/dist/db/wal-checkpointer.js +19 -7
  451. package/dist/doctor.d.ts +7 -1
  452. package/dist/doctor.js +128 -46
  453. package/dist/embeddings/local.d.ts +8 -4
  454. package/dist/embeddings/local.js +11 -7
  455. package/dist/embeddings/provider.d.ts +19 -10
  456. package/dist/embeddings/provider.js +32 -27
  457. package/dist/embeddings/transformers.d.ts +16 -4
  458. package/dist/embeddings/transformers.js +32 -15
  459. package/dist/entry/json-hooks.d.ts +1 -1
  460. package/dist/entry/json-hooks.js +1 -1
  461. package/dist/entry/project-identity.js +2 -1
  462. package/dist/entry/session-text.d.ts +1 -1
  463. package/dist/entry/session-text.js +1 -1
  464. package/dist/entry/sqlite-handles.d.ts +10 -0
  465. package/dist/entry/sqlite-handles.js +9 -0
  466. package/dist/entry/store-kit.d.ts +50 -0
  467. package/dist/entry/store-kit.js +27 -0
  468. package/dist/entry/testing.d.ts +6 -0
  469. package/dist/entry/testing.js +7 -0
  470. package/dist/eval/eval-stats.d.ts +27 -8
  471. package/dist/eval/eval-stats.js +17 -5
  472. package/dist/eval/eval-suite.d.ts +3 -1
  473. package/dist/eval/eval-suite.js +409 -187
  474. package/dist/eval/eval.d.ts +8 -2
  475. package/dist/eval/eval.js +8 -2
  476. package/dist/eval/judgment.js +17 -7
  477. package/dist/graph/delta.d.ts +9 -42
  478. package/dist/graph/delta.js +17 -11
  479. package/dist/graph/extract.d.ts +10 -7
  480. package/dist/graph/extract.js +57 -25
  481. package/dist/graph/recall.d.ts +12 -4
  482. package/dist/graph/recall.js +30 -13
  483. package/dist/graph/stream.d.ts +18 -6
  484. package/dist/graph/stream.js +32 -10
  485. package/dist/graph/view.d.ts +19 -6
  486. package/dist/graph/view.js +42 -17
  487. package/dist/hooks/codex-session.js +2 -2
  488. package/dist/hooks/codex-wrapper.d.ts +3 -1
  489. package/dist/hooks/codex-wrapper.js +9 -4
  490. package/dist/hooks/copilot.d.ts +19 -5
  491. package/dist/hooks/copilot.js +54 -15
  492. package/dist/hooks/hook-blocks.d.ts +4 -1
  493. package/dist/hooks/hook-blocks.js +8 -3
  494. package/dist/hooks/json-hooks.d.ts +9 -5
  495. package/dist/hooks/json-hooks.js +72 -33
  496. package/dist/hooks/opencode.js +15 -5
  497. package/dist/hooks/shared.d.ts +27 -8
  498. package/dist/hooks/shared.js +57 -16
  499. package/dist/importers/core.d.ts +12 -4
  500. package/dist/importers/core.js +11 -10
  501. package/dist/importers/markdown-parse.d.ts +15 -5
  502. package/dist/importers/markdown-parse.js +16 -7
  503. package/dist/importers/markdown.js +6 -9
  504. package/dist/importers/sources.js +10 -23
  505. package/dist/importers/vault.d.ts +3 -3
  506. package/dist/importers/vault.js +61 -45
  507. package/dist/index.d.ts +33 -7
  508. package/dist/index.js +26 -8
  509. package/dist/learn/autolearn.d.ts +21 -6
  510. package/dist/learn/autolearn.js +57 -26
  511. package/dist/learn/churn-git.d.ts +4 -1
  512. package/dist/learn/churn-git.js +29 -5
  513. package/dist/learn/extract.d.ts +4 -1
  514. package/dist/learn/extract.js +17 -10
  515. package/dist/learn/forward-claim-detector.d.ts +17 -5
  516. package/dist/learn/forward-claim-detector.js +34 -15
  517. package/dist/learn/invalidation.d.ts +12 -6
  518. package/dist/learn/invalidation.js +62 -28
  519. package/dist/learn/roots.d.ts +3 -0
  520. package/dist/learn/roots.js +5 -0
  521. package/dist/mcp/admin-tools.d.ts +5 -5
  522. package/dist/mcp/admin-tools.js +28 -23
  523. package/dist/mcp/format.d.ts +1 -1
  524. package/dist/mcp/format.js +4 -2
  525. package/dist/mcp/framing.d.ts +3 -1
  526. package/dist/mcp/framing.js +20 -8
  527. package/dist/mcp/memory-tools.d.ts +3 -3
  528. package/dist/mcp/memory-tools.js +21 -20
  529. package/dist/mcp/protocol.d.ts +32 -16
  530. package/dist/mcp/protocol.js +12 -9
  531. package/dist/mcp/recall-tools.d.ts +3 -3
  532. package/dist/mcp/recall-tools.js +62 -74
  533. package/dist/mcp/request.d.ts +7 -5
  534. package/dist/mcp/request.js +61 -77
  535. package/dist/mcp/server.d.ts +3 -1
  536. package/dist/mcp/server.js +8 -3
  537. package/dist/mcp/session-state.d.ts +1 -1
  538. package/dist/mcp/session-state.js +4 -3
  539. package/dist/mcp/shared-gate.d.ts +3 -2
  540. package/dist/mcp/shared-gate.js +3 -2
  541. package/dist/mcp/stdio.d.ts +6 -3
  542. package/dist/mcp/stdio.js +59 -23
  543. package/dist/mcp/tool-args.d.ts +4 -1
  544. package/dist/mcp/tool-args.js +8 -3
  545. package/dist/mcp/tools.js +76 -32
  546. package/dist/objects/customer-notes.d.ts +12 -10
  547. package/dist/objects/customer-notes.js +21 -15
  548. package/dist/objects/decisions.d.ts +18 -10
  549. package/dist/objects/decisions.js +23 -17
  550. package/dist/objects/descriptor.js +2 -1
  551. package/dist/objects/fields.d.ts +4 -1
  552. package/dist/objects/fields.js +6 -2
  553. package/dist/objects/incidents.d.ts +14 -16
  554. package/dist/objects/incidents.js +29 -30
  555. package/dist/objects/lifecycle.d.ts +0 -4
  556. package/dist/objects/lifecycle.js +21 -24
  557. package/dist/objects/policies.d.ts +12 -16
  558. package/dist/objects/policies.js +17 -21
  559. package/dist/objects/processes.d.ts +16 -10
  560. package/dist/objects/processes.js +20 -15
  561. package/dist/objects/project-briefs.d.ts +13 -14
  562. package/dist/objects/project-briefs.js +33 -39
  563. package/dist/objects/skills.d.ts +10 -12
  564. package/dist/objects/skills.js +17 -22
  565. package/dist/postinstall.js +15 -7
  566. package/dist/predictions/planning-fallacy.d.ts +19 -6
  567. package/dist/predictions/planning-fallacy.js +4 -2
  568. package/dist/rerankers/clef.d.ts +8 -2
  569. package/dist/rerankers/clef.js +14 -9
  570. package/dist/rerankers/cross-encoder.d.ts +2 -1
  571. package/dist/rerankers/cross-encoder.js +19 -9
  572. package/dist/rerankers/index.js +2 -1
  573. package/dist/rerankers/jev.js +2 -1
  574. package/dist/rerankers/llm.d.ts +6 -2
  575. package/dist/rerankers/llm.js +8 -3
  576. package/dist/rerankers/remote.d.ts +3 -1
  577. package/dist/rerankers/remote.js +5 -2
  578. package/dist/rerankers/types.d.ts +6 -2
  579. package/dist/search/bm25-search.d.ts +3 -1
  580. package/dist/search/bm25-search.js +15 -2
  581. package/dist/search/boosts.js +4 -3
  582. package/dist/search/embed-memories.d.ts +12 -4
  583. package/dist/search/embed-memories.js +96 -58
  584. package/dist/search/engine.d.ts +11 -0
  585. package/dist/search/engine.js +14 -0
  586. package/dist/search/goal-boost.d.ts +10 -3
  587. package/dist/search/goal-boost.js +13 -6
  588. package/dist/search/hybrid-score.d.ts +4 -1
  589. package/dist/search/hybrid-score.js +4 -1
  590. package/dist/search/hybrid.d.ts +23 -8
  591. package/dist/search/hybrid.js +12 -7
  592. package/dist/search/multihop.js +14 -13
  593. package/dist/search/path-context.d.ts +10 -3
  594. package/dist/search/path-context.js +10 -3
  595. package/dist/search/physics-search.d.ts +9 -4
  596. package/dist/search/physics-search.js +38 -14
  597. package/dist/search/rerank.d.ts +2 -1
  598. package/dist/search/rerank.js +2 -1
  599. package/dist/search/rrf.d.ts +14 -5
  600. package/dist/search/rrf.js +11 -4
  601. package/dist/search/vector.d.ts +8 -2
  602. package/dist/search/vector.js +14 -8
  603. package/dist/server/auth.d.ts +19 -15
  604. package/dist/server/auth.js +68 -38
  605. package/dist/server/boot.d.ts +4 -1
  606. package/dist/server/boot.js +115 -67
  607. package/dist/server/client-ip.d.ts +17 -5
  608. package/dist/server/client-ip.js +56 -21
  609. package/dist/server/cursor.d.ts +10 -3
  610. package/dist/server/cursor.js +10 -3
  611. package/dist/server/deadline.d.ts +5 -2
  612. package/dist/server/deadline.js +10 -3
  613. package/dist/server/key-check-bounds.js +12 -4
  614. package/dist/server/lifecycle.d.ts +4 -1
  615. package/dist/server/lifecycle.js +10 -4
  616. package/dist/server/mcp-http.d.ts +2 -1
  617. package/dist/server/mcp-http.js +37 -22
  618. package/dist/server/rate-limit.d.ts +17 -5
  619. package/dist/server/rate-limit.js +55 -26
  620. package/dist/server/ready.js +7 -4
  621. package/dist/server/request.d.ts +15 -4
  622. package/dist/server/request.js +42 -15
  623. package/dist/server/route-checks.d.ts +4 -1
  624. package/dist/server/route-checks.js +8 -3
  625. package/dist/server/route-table.d.ts +8 -6
  626. package/dist/server/route-table.js +550 -97
  627. package/dist/server/routes/admin.d.ts +7 -7
  628. package/dist/server/routes/admin.js +36 -15
  629. package/dist/server/routes/customer-notes.d.ts +5 -5
  630. package/dist/server/routes/customer-notes.js +5 -4
  631. package/dist/server/routes/decisions.d.ts +5 -5
  632. package/dist/server/routes/decisions.js +12 -6
  633. package/dist/server/routes/incidents.d.ts +5 -5
  634. package/dist/server/routes/incidents.js +10 -4
  635. package/dist/server/routes/memories.d.ts +8 -8
  636. package/dist/server/routes/memories.js +12 -17
  637. package/dist/server/routes/object-routes.d.ts +8 -5
  638. package/dist/server/routes/object-routes.js +4 -2
  639. package/dist/server/routes/policies.d.ts +6 -6
  640. package/dist/server/routes/policies.js +11 -4
  641. package/dist/server/routes/predictions.d.ts +5 -5
  642. package/dist/server/routes/predictions.js +9 -4
  643. package/dist/server/routes/processes.d.ts +5 -5
  644. package/dist/server/routes/processes.js +15 -6
  645. package/dist/server/routes/project-briefs.d.ts +6 -6
  646. package/dist/server/routes/project-briefs.js +3 -2
  647. package/dist/server/routes/recall.d.ts +3 -3
  648. package/dist/server/routes/recall.js +21 -10
  649. package/dist/server/routes/skills.d.ts +6 -6
  650. package/dist/server/routes/skills.js +12 -4
  651. package/dist/server/server-detect.d.ts +24 -8
  652. package/dist/server/server-detect.js +57 -22
  653. package/dist/server/sleep-child.js +16 -10
  654. package/dist/server/sleep-offload.d.ts +8 -5
  655. package/dist/server/sleep-offload.js +40 -18
  656. package/dist/server/tls.d.ts +10 -2
  657. package/dist/server/tls.js +25 -5
  658. package/dist/server/types.d.ts +41 -24
  659. package/dist/server/validation.d.ts +4 -1
  660. package/dist/server/validation.js +22 -9
  661. package/dist/server.d.ts +17 -49
  662. package/dist/server.js +33 -40
  663. package/dist/sharing/global-store.d.ts +6 -12
  664. package/dist/sharing/global-store.js +8 -48
  665. package/dist/sharing/global-sync.d.ts +3 -1
  666. package/dist/sharing/global-sync.js +17 -7
  667. package/dist/sharing/project-merge.d.ts +25 -7
  668. package/dist/sharing/project-merge.js +49 -17
  669. package/dist/sharing/search-both.d.ts +8 -4
  670. package/dist/sharing/search-both.js +28 -14
  671. package/dist/sharing/share.d.ts +8 -4
  672. package/dist/sharing/share.js +40 -18
  673. package/dist/store/ambient.js +10 -5
  674. package/dist/store/audit-event.d.ts +2 -2
  675. package/dist/store/audit-event.js +8 -3
  676. package/dist/store/audit.d.ts +6 -3
  677. package/dist/store/audit.js +16 -6
  678. package/dist/store/auth.d.ts +4 -2
  679. package/dist/store/auth.js +63 -20
  680. package/dist/store/busy.d.ts +9 -0
  681. package/dist/store/busy.js +16 -0
  682. package/dist/store/candidates.d.ts +12 -5
  683. package/dist/store/candidates.js +90 -41
  684. package/dist/store/capture-write.d.ts +2 -1
  685. package/dist/store/capture-write.js +2 -1
  686. package/dist/store/card-detail.d.ts +4 -4
  687. package/dist/store/card-detail.js +15 -8
  688. package/dist/store/cards.d.ts +24 -10
  689. package/dist/store/cards.js +97 -63
  690. package/dist/store/compaction-caller.d.ts +2 -1
  691. package/dist/store/compaction-caller.js +2 -1
  692. package/dist/store/compactions-record.d.ts +14 -8
  693. package/dist/store/compactions-record.js +101 -37
  694. package/dist/store/compactions.js +35 -15
  695. package/dist/store/conflicts.d.ts +16 -5
  696. package/dist/store/conflicts.js +104 -48
  697. package/dist/store/connectors/dlq.d.ts +17 -5
  698. package/dist/store/connectors/dlq.js +58 -6
  699. package/dist/store/connectors/event-log.d.ts +122 -0
  700. package/dist/store/connectors/event-log.js +25 -0
  701. package/dist/store/connectors/github.d.ts +6 -3
  702. package/dist/store/connectors/github.js +30 -48
  703. package/dist/store/connectors/slack.d.ts +2 -1
  704. package/dist/store/connectors/slack.js +31 -47
  705. package/dist/store/dashboard-reads.d.ts +7 -3
  706. package/dist/store/dashboard-reads.js +32 -10
  707. package/dist/store/delete-and-batch.d.ts +17 -11
  708. package/dist/store/delete-and-batch.js +70 -28
  709. package/dist/store/delivery-recorder.d.ts +10 -7
  710. package/dist/store/delivery-recorder.js +70 -37
  711. package/dist/store/descendant-page.d.ts +2 -1
  712. package/dist/store/descendant-page.js +26 -10
  713. package/dist/store/diagnostics.d.ts +2 -1
  714. package/dist/store/diagnostics.js +2 -1
  715. package/dist/store/doctor-reads.d.ts +2 -1
  716. package/dist/store/doctor-reads.js +13 -5
  717. package/dist/store/dormant.d.ts +19 -11
  718. package/dist/store/dormant.js +45 -19
  719. package/dist/store/embeddings/index.d.ts +13 -9
  720. package/dist/store/embeddings/index.js +19 -12
  721. package/dist/store/entry-reads.d.ts +72 -21
  722. package/dist/store/entry-reads.js +215 -69
  723. package/dist/store/entry-row.d.ts +10 -6
  724. package/dist/store/entry-row.js +26 -14
  725. package/dist/store/entry-writes.d.ts +28 -13
  726. package/dist/store/entry-writes.js +61 -22
  727. package/dist/store/failure-log-at.js +1 -1
  728. package/dist/store/failure-log.d.ts +4 -2
  729. package/dist/store/failure-log.js +13 -6
  730. package/dist/store/gated-write.d.ts +3 -3
  731. package/dist/store/gated-write.js +3 -3
  732. package/dist/store/goals.d.ts +5 -4
  733. package/dist/store/goals.js +11 -12
  734. package/dist/store/graph-apply.d.ts +21 -0
  735. package/dist/{graph/write.js → store/graph-apply.js} +31 -11
  736. package/dist/store/graph-queue.d.ts +9 -6
  737. package/dist/store/graph-queue.js +15 -10
  738. package/dist/store/graph-reads.d.ts +16 -11
  739. package/dist/store/graph-reads.js +29 -19
  740. package/dist/store/graph-rows.d.ts +41 -3
  741. package/dist/store/graph-rows.js +10 -7
  742. package/dist/store/graph-view-rows.js +15 -7
  743. package/dist/store/graph-writes.d.ts +16 -10
  744. package/dist/store/graph-writes.js +59 -36
  745. package/dist/store/half-life.js +2 -2
  746. package/dist/store/handoffs.d.ts +13 -7
  747. package/dist/store/handoffs.js +44 -22
  748. package/dist/store/index-and-stats.d.ts +2 -2
  749. package/dist/store/index-and-stats.js +6 -5
  750. package/dist/store/index.d.ts +4 -2
  751. package/dist/store/index.js +2 -1
  752. package/dist/store/key-audit.d.ts +2 -1
  753. package/dist/store/key-audit.js +2 -1
  754. package/dist/store/key-writes.d.ts +2 -1
  755. package/dist/store/key-writes.js +9 -2
  756. package/dist/store/ledger-turn.d.ts +4 -1
  757. package/dist/store/ledger-turn.js +7 -2
  758. package/dist/store/mirrors.d.ts +11 -4
  759. package/dist/store/mirrors.js +96 -19
  760. package/dist/store/narrow.d.ts +6 -0
  761. package/dist/store/narrow.js +11 -0
  762. package/dist/store/open.d.ts +6 -3
  763. package/dist/store/open.js +20 -10
  764. package/dist/store/pilot-arm.d.ts +2 -1
  765. package/dist/store/pilot-arm.js +18 -6
  766. package/dist/store/planning-fallacy-evidence.d.ts +2 -2
  767. package/dist/store/planning-fallacy-evidence.js +8 -5
  768. package/dist/store/port/agent-import.d.ts +62 -0
  769. package/dist/store/port/agent-import.js +2 -0
  770. package/dist/store/port/consolidation.d.ts +129 -0
  771. package/dist/store/port/consolidation.js +2 -0
  772. package/dist/store/port/learning.d.ts +19 -0
  773. package/dist/store/port/learning.js +2 -0
  774. package/dist/store/port/local-files.d.ts +18 -0
  775. package/dist/store/port/local-files.js +2 -0
  776. package/dist/store/port/promotion.d.ts +20 -0
  777. package/dist/store/port/promotion.js +3 -0
  778. package/dist/store/port-groups.d.ts +160 -0
  779. package/dist/store/port-groups.js +2 -0
  780. package/dist/store/port.d.ts +261 -219
  781. package/dist/store/port.js +3 -9
  782. package/dist/store/predictions.d.ts +14 -10
  783. package/dist/store/predictions.js +37 -17
  784. package/dist/store/project-tags.d.ts +4 -1
  785. package/dist/store/project-tags.js +16 -5
  786. package/dist/store/quality-repair.d.ts +8 -4
  787. package/dist/store/quality-repair.js +53 -20
  788. package/dist/store/quarantine.d.ts +1 -0
  789. package/dist/store/quarantine.js +23 -9
  790. package/dist/store/raw-archive.d.ts +5 -4
  791. package/dist/store/raw-archive.js +11 -10
  792. package/dist/store/recall-trace.d.ts +22 -17
  793. package/dist/store/recall-trace.js +128 -64
  794. package/dist/store/rejected-values.d.ts +15 -10
  795. package/dist/store/rejected-values.js +46 -20
  796. package/dist/store/rejection.d.ts +12 -11
  797. package/dist/store/rejection.js +18 -19
  798. package/dist/store/report-reads.d.ts +2 -1
  799. package/dist/store/report-reads.js +2 -1
  800. package/dist/store/rows.d.ts +7 -5
  801. package/dist/store/rows.js +20 -13
  802. package/dist/store/rule-sql.d.ts +7 -3
  803. package/dist/store/rule-sql.js +26 -13
  804. package/dist/store/search-rows.d.ts +16 -11
  805. package/dist/store/search-rows.js +54 -32
  806. package/dist/store/sessions.d.ts +12 -10
  807. package/dist/store/sessions.js +40 -21
  808. package/dist/store/set-aside.d.ts +2 -2
  809. package/dist/store/set-aside.js +18 -5
  810. package/dist/store/sqlite/agent-import.d.ts +3 -0
  811. package/dist/store/sqlite/agent-import.js +77 -0
  812. package/dist/store/sqlite/cards-group.d.ts +6 -0
  813. package/dist/store/sqlite/cards-group.js +37 -0
  814. package/dist/store/sqlite/conflicts-group.d.ts +6 -0
  815. package/dist/store/sqlite/conflicts-group.js +18 -0
  816. package/dist/store/sqlite/connector-events-group.d.ts +2 -1
  817. package/dist/store/sqlite/connector-events-group.js +17 -6
  818. package/dist/store/sqlite/connector-writes-group.d.ts +2 -1
  819. package/dist/store/sqlite/connector-writes-group.js +12 -5
  820. package/dist/store/sqlite/consolidation-group.d.ts +4 -0
  821. package/dist/store/sqlite/consolidation-group.js +64 -0
  822. package/dist/store/sqlite/dag-reads-group.js +1 -1
  823. package/dist/store/sqlite/dormant-group.d.ts +6 -0
  824. package/dist/store/sqlite/dormant-group.js +29 -0
  825. package/dist/store/sqlite/entry-writes-group.d.ts +9 -6
  826. package/dist/store/sqlite/entry-writes-group.js +37 -14
  827. package/dist/store/sqlite/error-codec.d.ts +4 -2
  828. package/dist/store/sqlite/error-codec.js +32 -10
  829. package/dist/store/sqlite/executor-counts.js +2 -1
  830. package/dist/store/sqlite/executor.d.ts +8 -3
  831. package/dist/store/sqlite/executor.js +56 -18
  832. package/dist/store/sqlite/global-promote.d.ts +5 -0
  833. package/dist/store/sqlite/global-promote.js +48 -0
  834. package/dist/store/sqlite/goals-group.d.ts +6 -0
  835. package/dist/store/sqlite/goals-group.js +23 -0
  836. package/dist/store/sqlite/graph-reads-group.d.ts +2 -1
  837. package/dist/store/sqlite/graph-reads-group.js +2 -1
  838. package/dist/store/sqlite/held-connection.d.ts +8 -0
  839. package/dist/store/sqlite/held-connection.js +34 -7
  840. package/dist/store/sqlite/last-recall-group.d.ts +15 -0
  841. package/dist/store/sqlite/last-recall-group.js +62 -0
  842. package/dist/store/sqlite/learning-group.d.ts +4 -0
  843. package/dist/store/sqlite/learning-group.js +17 -0
  844. package/dist/store/sqlite/maintenance-groups.d.ts +6 -0
  845. package/dist/store/sqlite/maintenance-groups.js +61 -0
  846. package/dist/store/sqlite/object-rows.d.ts +6 -3
  847. package/dist/store/sqlite/object-rows.js +34 -5
  848. package/dist/store/sqlite/objects-group.d.ts +5 -4
  849. package/dist/store/sqlite/objects-group.js +97 -38
  850. package/dist/store/sqlite/predictions-group.d.ts +2 -1
  851. package/dist/store/sqlite/predictions-group.js +4 -2
  852. package/dist/store/sqlite/promotion-group.d.ts +3 -0
  853. package/dist/store/sqlite/promotion-group.js +10 -0
  854. package/dist/store/sqlite/quarantine-group.d.ts +2 -1
  855. package/dist/store/sqlite/quarantine-group.js +4 -2
  856. package/dist/store/sqlite/reports-group.d.ts +6 -0
  857. package/dist/store/sqlite/reports-group.js +33 -0
  858. package/dist/store/sqlite/request-scope.d.ts +6 -0
  859. package/dist/store/sqlite/request-scope.js +18 -0
  860. package/dist/store/sqlite/sessions-group.d.ts +6 -0
  861. package/dist/store/sqlite/sessions-group.js +46 -0
  862. package/dist/store/sqlite/store.d.ts +22 -18
  863. package/dist/store/sqlite/store.js +95 -33
  864. package/dist/store/sqlite/vector-pack.js +2 -1
  865. package/dist/store/sqlite/vector-reads-group.js +2 -1
  866. package/dist/store/sqlite/worker-jobs.d.ts +2 -1
  867. package/dist/store/sqlite/worker-jobs.js +19 -7
  868. package/dist/store/sqlite/worker-ops.d.ts +10 -5
  869. package/dist/store/sqlite/worker-ops.js +6 -3
  870. package/dist/store/sqlite/worker-store.d.ts +4 -3
  871. package/dist/store/sqlite/worker-store.js +24 -14
  872. package/dist/store/summaries.d.ts +25 -11
  873. package/dist/store/summaries.js +84 -27
  874. package/dist/store/summary-dirty.d.ts +2 -1
  875. package/dist/store/summary-dirty.js +2 -1
  876. package/dist/store/tenant.d.ts +3 -2
  877. package/dist/store/tenant.js +5 -4
  878. package/dist/store/token-ledger-rows.js +8 -4
  879. package/dist/store/token-ledger.d.ts +19 -13
  880. package/dist/store/token-ledger.js +27 -14
  881. package/dist/store/tombstone-checks.d.ts +4 -1
  882. package/dist/store/tombstone-checks.js +10 -1
  883. package/dist/store/usage-reports.js +2 -1
  884. package/dist/store/vector-index.d.ts +8 -5
  885. package/dist/store/vector-index.js +28 -11
  886. package/dist/store/working-memory.d.ts +6 -4
  887. package/dist/store/working-memory.js +14 -9
  888. package/dist/support-bundle.js +10 -5
  889. package/dist/trust/quarantine.d.ts +1 -2
  890. package/dist/trust/quarantine.js +1 -5
  891. package/dist/trust/reject-flow.d.ts +12 -3
  892. package/dist/trust/reject-flow.js +12 -4
  893. package/dist/util/anthropic-messages.d.ts +7 -2
  894. package/dist/util/anthropic-messages.js +18 -7
  895. package/dist/util/atomic-write.d.ts +8 -3
  896. package/dist/util/atomic-write.js +36 -21
  897. package/dist/util/compaction-items.d.ts +4 -1
  898. package/dist/util/compaction-items.js +8 -2
  899. package/dist/util/crash-handlers.d.ts +7 -2
  900. package/dist/util/crash-handlers.js +13 -4
  901. package/dist/util/env.d.ts +26 -5
  902. package/dist/util/env.js +87 -25
  903. package/dist/util/format.d.ts +2 -0
  904. package/dist/util/format.js +4 -0
  905. package/dist/util/home-path.js +12 -6
  906. package/dist/util/hook-payload.d.ts +3 -1
  907. package/dist/util/hook-payload.js +3 -1
  908. package/dist/util/http-retry.d.ts +12 -6
  909. package/dist/util/http-retry.js +16 -6
  910. package/dist/util/http-util.d.ts +20 -5
  911. package/dist/util/http-util.js +28 -9
  912. package/dist/util/json.d.ts +4 -1
  913. package/dist/util/json.js +4 -1
  914. package/dist/util/keyset.js +2 -1
  915. package/dist/util/limits.js +4 -2
  916. package/dist/util/log.d.ts +13 -5
  917. package/dist/util/log.js +29 -6
  918. package/dist/util/net.d.ts +5 -0
  919. package/dist/util/net.js +19 -0
  920. package/dist/util/real-path.d.ts +2 -1
  921. package/dist/util/real-path.js +4 -3
  922. package/dist/util/request-scope.d.ts +16 -4
  923. package/dist/util/request-scope.js +19 -6
  924. package/dist/util/same-text.d.ts +10 -3
  925. package/dist/util/same-text.js +10 -3
  926. package/dist/util/secret-detect.d.ts +24 -7
  927. package/dist/util/secret-detect.js +49 -14
  928. package/dist/util/spawn-argv.d.ts +11 -0
  929. package/dist/util/spawn-argv.js +66 -0
  930. package/dist/util/sql.d.ts +3 -0
  931. package/dist/util/sql.js +6 -0
  932. package/dist/util/sqlite-blocked.d.ts +15 -4
  933. package/dist/util/sqlite-blocked.js +19 -6
  934. package/dist/util/stored-json.d.ts +4 -1
  935. package/dist/util/stored-json.js +6 -2
  936. package/dist/util/stream-tee.d.ts +2 -1
  937. package/dist/util/stream-tee.js +8 -5
  938. package/dist/util/transcript-tail.d.ts +4 -1
  939. package/dist/util/transcript-tail.js +4 -1
  940. package/dist/util/vector-codec.d.ts +4 -0
  941. package/dist/util/vector-codec.js +15 -0
  942. package/dist/util/version.d.ts +8 -3
  943. package/dist/util/version.js +8 -3
  944. package/dist/util/write-budget.d.ts +7 -2
  945. package/dist/util/write-budget.js +5 -2
  946. package/dist/util/yaml.d.ts +4 -1
  947. package/dist/util/yaml.js +4 -1
  948. package/extensions/openclaw-plugin/openclaw.plugin.json +1 -1
  949. package/extensions/openclaw-plugin/package.json +1 -1
  950. package/openclaw.plugin.json +1 -1
  951. package/package.json +4 -1
  952. package/scripts/postinstall.cjs +3 -1
  953. package/dist/api/audit.js +0 -56
  954. package/dist/api/cards.d.ts +0 -42
  955. package/dist/api/conflicts.d.ts +0 -28
  956. package/dist/api/conflicts.js +0 -61
  957. package/dist/api/dormant.d.ts +0 -14
  958. package/dist/api/dormant.js +0 -58
  959. package/dist/api/goals.d.ts +0 -18
  960. package/dist/api/graph.d.ts +0 -8
  961. package/dist/api/graph.js +0 -7
  962. package/dist/api/learn.js +0 -124
  963. package/dist/api/memories.d.ts +0 -23
  964. package/dist/api/memories.js +0 -46
  965. package/dist/api/objects.d.ts +0 -9
  966. package/dist/api/on-store.d.ts +0 -16
  967. package/dist/api/on-store.js +0 -38
  968. package/dist/api/outcome.d.ts +0 -19
  969. package/dist/api/outcome.js +0 -21
  970. package/dist/api/predictions.d.ts +0 -11
  971. package/dist/api/promote.d.ts +0 -36
  972. package/dist/api/promote.js +0 -65
  973. package/dist/api/recall-core.d.ts +0 -4
  974. package/dist/api/recall-core.js +0 -120
  975. package/dist/api/recall-finish.d.ts +0 -53
  976. package/dist/api/recall-finish.js +0 -30
  977. package/dist/api/recall-history.d.ts +0 -64
  978. package/dist/api/recall-history.js +0 -159
  979. package/dist/api/recall-record.d.ts +0 -43
  980. package/dist/api/recall-record.js +0 -78
  981. package/dist/api/recall-request.js +0 -121
  982. package/dist/api/recall.d.ts +0 -6
  983. package/dist/api/refine.d.ts +0 -7
  984. package/dist/api/refine.js +0 -10
  985. package/dist/api/session-owners.d.ts +0 -4
  986. package/dist/api/session-owners.js +0 -17
  987. package/dist/api/sleep-run.d.ts +0 -26
  988. package/dist/api/sleep.js +0 -10
  989. package/dist/cli/lenient-id.d.ts +0 -2
  990. package/dist/cli/lenient-id.js +0 -13
  991. package/dist/graph/write.d.ts +0 -14
  992. package/dist/store/sqlite/busy.d.ts +0 -3
  993. package/dist/store/sqlite/busy.js +0 -8
  994. package/dist/store/sqlite/local.d.ts +0 -21
  995. package/dist/store/sqlite/local.js +0 -39
@@ -1,23 +1,31 @@
1
- // hippo.db as serve() runs it by default: the methods in the op table answer from worker threads, the rest still run on the calling thread.
1
+ // hippo.db as serve() runs it by default: the methods in the op table answer from worker threads, the rest still run on
2
+ // the calling thread.
2
3
  import { existsSync } from 'node:fs';
3
4
  import { getHippoDbPath } from '../../db/index.js';
4
- import { currentDeadline, currentRequestId } from '../../util/request-scope.js';
5
+ import { currentDeadline, currentRequestId, currentSignal } from '../../util/request-scope.js';
5
6
  import { createSqliteExecutor } from './executor.js';
6
7
  import { sqliteStore } from './store.js';
7
8
  import { vectorCopiesOf, vectorViewsOf } from './vector-pack.js';
8
- import { WORKER_OPS } from './worker-ops.js';
9
+ import { WORKER_OPS, } from './worker-ops.js';
9
10
  const offLoopStores = new WeakSet();
10
- /** Whether `store` answers its `loop: 'off'` routes from worker threads, so a hippo.db open on the server thread inside one is a defect. */
11
+ /** Whether `store` answers its `loop: 'off'` routes from worker threads, so a hippo.db open on the server thread inside
12
+ * one is a defect. */
11
13
  export function runsOffLoop(store) {
12
14
  return offLoopStores.has(store);
13
15
  }
14
16
  function send(executor, op, args, mode) {
15
17
  const deadline = currentDeadline();
16
- const call = executor.call(op, args, { mode, requestId: currentRequestId(), deadlineAt: deadline?.at });
18
+ const call = executor.call(op, args, {
19
+ mode,
20
+ requestId: currentRequestId(),
21
+ deadlineAt: deadline?.at,
22
+ signal: currentSignal(),
23
+ });
17
24
  // The request's own timer then waits for this call's answer, which names what became of a write.
18
25
  return deadline ? deadline.track(call) : call;
19
26
  }
20
- /** `inProcess` with each method the op table places on a worker answered from one, so a new method of a group needs its tag and no body here. */
27
+ /** `inProcess` with each method the op table places on a worker answered from one, so a new method of a group needs its
28
+ * tag and no body here. */
21
29
  function onWorkers(executor, group, places, inProcess) {
22
30
  const moved = Object.entries(places).flatMap(([method, place]) => (place === 'server' ? [] : [[
23
31
  method,
@@ -25,23 +33,25 @@ function onWorkers(executor, group, places, inProcess) {
25
33
  ]]));
26
34
  return { ...inProcess, ...Object.fromEntries(moved) };
27
35
  }
28
- // The two reads that return vectors: the worker answers with one moved buffer, and the port's Map is rebuilt here. No ids reads nothing, as in process.
36
+ // The two reads that return vectors: the worker answers with one moved buffer, and the port's Map is rebuilt here. No
37
+ // ids reads nothing, as in process.
29
38
  function vectorGroups(executor, inProcess) {
30
39
  const { vectors, vectorViews } = WORKER_OPS;
31
40
  const pack = (op, ids, mode) => send(executor, op, [ids], mode);
32
41
  return {
33
42
  vectors: {
34
43
  ...onWorkers(executor, 'vectors', vectors, inProcess),
35
- storedVectors: async (ids) => (ids.length === 0 ? new Map() : vectorCopiesOf(await pack('vectors.storedVectors', ids, vectors.storedVectors))),
44
+ storedVectors: async (ids) => ids.length === 0 ? new Map() : vectorCopiesOf(await pack('vectors.storedVectors', ids, vectors.storedVectors)),
36
45
  },
37
46
  vectorViews: {
38
- storedVectorViews: async (ids) => (ids.length === 0
47
+ storedVectorViews: async (ids) => ids.length === 0
39
48
  ? new Map()
40
- : vectorViewsOf(await pack('vectorViews.storedVectorViews', ids, vectorViews.storedVectorViews))),
49
+ : vectorViewsOf(await pack('vectorViews.storedVectorViews', ids, vectorViews.storedVectorViews)),
41
50
  },
42
51
  };
43
52
  }
44
- // A probe must not create the store, and a worker's first job sets it up, so a root with no hippo.db is ready before any thread starts.
53
+ // A probe must not create the store, and a worker's first job sets it up, so a root with no hippo.db is ready before
54
+ // any thread starts.
45
55
  function probing(hippoRoot, served) {
46
56
  return {
47
57
  ping: async () => {
@@ -50,11 +60,11 @@ function probing(hippoRoot, served) {
50
60
  },
51
61
  };
52
62
  }
53
- /** `sqliteStore` with the worker-backed methods in place of its in-process ones; close() closes `executor` and resolves once its threads have exited.
54
- * `executor` defaults to threads of the store's own, with the server's lock wait. */
63
+ /** `sqliteStore` with the worker-backed methods in place of its in-process ones; close() closes `executor` and resolves
64
+ * once its threads have exited. `executor` defaults to threads of the store's own, with the server's lock wait. */
55
65
  export function workerSqliteStore(hippoRoot, executor = createSqliteExecutor(hippoRoot)) {
56
66
  const inProcess = sqliteStore(hippoRoot);
57
- const { keyAudit, keyWrites, vectorWrites, entryWrites, contextReads, predictions, dagReads, auditLog, quarantine, graphReads, objects } = WORKER_OPS;
67
+ const { keyAudit, keyWrites, vectorWrites, entryWrites, contextReads, predictions, dagReads, auditLog, quarantine, graphReads, objects, } = WORKER_OPS;
58
68
  const store = {
59
69
  ...inProcess,
60
70
  ...onWorkers(executor, 'base', WORKER_OPS.base, inProcess),
@@ -1,13 +1,25 @@
1
- import type { MemoryEntry } from '../core/memory.js';
2
- /** Host-wide loader for L2 topic summaries without an L3 parent, for consolidate phase 1.9 (buildEntityProfiles); SQL-level filter, since in-memory
3
- * `survivors` lacks L2s created by phase 1.7. Entries carry tenantId so per-cluster writes stay tenant-scoped. */
1
+ import { type MemoryEntry } from '../core/memory.js';
2
+ /** Host-wide loader for L2 topic summaries without an L3 parent, for consolidate phase 1.9 (buildEntityProfiles);
3
+ * SQL-level filter, since in-memory `survivors` lacks L2s created by phase 1.7. Entries carry tenantId so per-cluster
4
+ * writes stay tenant-scoped. */
4
5
  export declare function loadAllL2Summaries(hippoRoot: string): MemoryEntry[];
5
- /** Dirty summaries across all tenants, newest change first (latest_at DESC NULLS LAST, id ASC), at most `limit` (all when omitted)
6
- * so HIPPO_DAG_REBUILD_CAP reads only the most recently changed. Each entry carries its tenantId so later writes stay tenant-scoped. */
6
+ /** Dirty summaries across all tenants, newest change first (latest_at DESC NULLS LAST, id ASC), at most `limit` (all
7
+ * when omitted) so HIPPO_DAG_REBUILD_CAP reads only the most recently changed. Each entry carries its tenantId so later
8
+ * writes stay tenant-scoped. */
7
9
  export declare function loadAllDirtySummaries(hippoRoot: string, limit?: number): MemoryEntry[];
8
- /** Live (non-archived) children of a DAG summary, so a rebuild regenerates from the CURRENT child set; tenant-scoped as defence in depth. */
10
+ /** Live (non-archived) children of a DAG summary, so a rebuild regenerates from the CURRENT child set; tenant-scoped as
11
+ * defence in depth. */
9
12
  export declare function loadChildrenOfSummary(hippoRoot: string, summaryId: string, tenantId: string): MemoryEntry[];
10
- /** Patch applied by applyRebuildResult; `bumpRebuildCount` is false for the zero-child case, true for a normal rebuild. */
13
+ /** loadChildrenOfSummary for many summaries in one IN query per tenant chunk; the map key is
14
+ * `${tenantId}\u0000${summaryId}`, each list in created order. */
15
+ export declare function loadChildrenOfSummaries(hippoRoot: string, summaries: ReadonlyArray<{
16
+ id: string;
17
+ tenant_id: string;
18
+ }>): Map<string, MemoryEntry[]>;
19
+ /** Key into the map loadChildrenOfSummaries returns. */
20
+ export declare function childrenKey(tenantId: string, summaryId: string): string;
21
+ /** Patch applied by applyRebuildResult; `bumpRebuildCount` is false for the zero-child case, true for a normal
22
+ * rebuild. */
11
23
  export interface RebuildPatch {
12
24
  content: string;
13
25
  descendant_count: number;
@@ -17,13 +29,15 @@ export interface RebuildPatch {
17
29
  zeroChildren: boolean;
18
30
  actor: string;
19
31
  }
20
- /** Apply a rebuild result to a dirty summary in one write scope (UPDATE plus syncFtsRow); `AND summary_dirty = 1` makes a concurrent race-loser a no-op.
21
- * Returns `{ changed, refused }`: `refused` only when a tombstone hit suppressed the content write while the metadata UPDATE still landed. */
32
+ /** Apply a rebuild result to a dirty summary in one write scope (UPDATE plus syncFtsRow); `AND summary_dirty = 1` makes
33
+ * a concurrent race-loser a no-op. Returns `{ changed, refused }`: `refused` only when a tombstone hit suppressed the
34
+ * content write while the metadata UPDATE still landed. */
22
35
  export declare function applyRebuildResult(hippoRoot: string, summary: MemoryEntry, patch: RebuildPatch): {
23
36
  changed: boolean;
24
37
  refused: boolean;
25
38
  };
26
- /** Clear summary_dirty on a new summary after buildDag's child-link loop (each member's writeEntry marks the parent dirty, so the same cycle would rebuild it).
27
- * Idempotent (no-op, no audit if not dirty); audit source='buildDag-clean' distinguishes it from the rebuild's. */
39
+ /** Clear summary_dirty on a new summary after buildDag's child-link loop (each member's writeEntry marks the parent
40
+ * dirty, so the same cycle would rebuild it). Idempotent (no-op, no audit if not dirty); audit source='buildDag-clean'
41
+ * distinguishes it from the rebuild's. */
28
42
  export declare function clearSummaryDirtyAfterBuild(hippoRoot: string, summaryId: string, tenantId: string, actor?: string, source?: string): void;
29
43
  //# sourceMappingURL=summaries.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { DAG_LEVEL } from '../core/memory.js';
1
2
  import { withWriteScope } from '../db/index.js';
2
3
  import { assertTenantId } from './tenant.js';
3
4
  import { findRejectedValue, rejectionDigest } from './rejection.js';
@@ -6,11 +7,15 @@ import { MEMORY_SELECT_COLUMNS, rowToEntry } from './rows.js';
6
7
  import { audit } from './audit-event.js';
7
8
  import { syncFtsRow } from './entry-row.js';
8
9
  import { onHandle, openStore } from './open.js';
10
+ import { chunked } from '../util/chunked.js';
9
11
  import { DIGEST_DISPLAY_CHARS } from '../util/token-text.js';
10
- // Sleep-cycle rebuild surface: lives here, not in src/consolidate/dag.ts, because it needs module-private MEMORY_SELECT_COLUMNS, MemoryRow, rowToEntry,
11
- // audit, syncFtsRow and assertTenantId. dag.ts keeps only the thin orchestrator rebuildDirtySummaries().
12
- /** Host-wide loader for L2 topic summaries without an L3 parent, for consolidate phase 1.9 (buildEntityProfiles); SQL-level filter, since in-memory
13
- * `survivors` lacks L2s created by phase 1.7. Entries carry tenantId so per-cluster writes stay tenant-scoped. */
12
+ import { placeholders } from '../util/sql.js';
13
+ // Sleep-cycle rebuild surface: lives here, not in src/consolidate/dag.ts, because it needs module-private
14
+ // MEMORY_SELECT_COLUMNS, MemoryRow, rowToEntry, audit, syncFtsRow and assertTenantId. dag.ts keeps only the thin
15
+ // orchestrator rebuildDirtySummaries().
16
+ /** Host-wide loader for L2 topic summaries without an L3 parent, for consolidate phase 1.9 (buildEntityProfiles);
17
+ * SQL-level filter, since in-memory `survivors` lacks L2s created by phase 1.7. Entries carry tenantId so per-cluster
18
+ * writes stay tenant-scoped. */
14
19
  export function loadAllL2Summaries(hippoRoot) {
15
20
  return onHandle(hippoRoot, (db) => {
16
21
  // SAFETY: this query selects exactly MEMORY_SELECT_COLUMNS, matching
@@ -18,7 +23,7 @@ export function loadAllL2Summaries(hippoRoot) {
18
23
  const rows = db.prepare(`
19
24
  SELECT ${MEMORY_SELECT_COLUMNS}
20
25
  FROM memories
21
- WHERE dag_level = 2
26
+ WHERE dag_level = ${DAG_LEVEL.topic}
22
27
  AND dag_parent_id IS NULL
23
28
  AND kind != 'archived'
24
29
  AND superseded_by IS NULL
@@ -27,8 +32,9 @@ export function loadAllL2Summaries(hippoRoot) {
27
32
  return rows.map(rowToEntry);
28
33
  }, openStore);
29
34
  }
30
- /** Dirty summaries across all tenants, newest change first (latest_at DESC NULLS LAST, id ASC), at most `limit` (all when omitted)
31
- * so HIPPO_DAG_REBUILD_CAP reads only the most recently changed. Each entry carries its tenantId so later writes stay tenant-scoped. */
35
+ /** Dirty summaries across all tenants, newest change first (latest_at DESC NULLS LAST, id ASC), at most `limit` (all
36
+ * when omitted) so HIPPO_DAG_REBUILD_CAP reads only the most recently changed. Each entry carries its tenantId so later
37
+ * writes stay tenant-scoped. */
32
38
  export function loadAllDirtySummaries(hippoRoot, limit) {
33
39
  return onHandle(hippoRoot, (db) => {
34
40
  // SAFETY: this query selects exactly MEMORY_SELECT_COLUMNS, matching
@@ -44,7 +50,8 @@ export function loadAllDirtySummaries(hippoRoot, limit) {
44
50
  return rows.map(rowToEntry);
45
51
  }, openStore);
46
52
  }
47
- /** Live (non-archived) children of a DAG summary, so a rebuild regenerates from the CURRENT child set; tenant-scoped as defence in depth. */
53
+ /** Live (non-archived) children of a DAG summary, so a rebuild regenerates from the CURRENT child set; tenant-scoped as
54
+ * defence in depth. */
48
55
  export function loadChildrenOfSummary(hippoRoot, summaryId, tenantId) {
49
56
  assertTenantId('loadChildrenOfSummary', tenantId);
50
57
  return onHandle(hippoRoot, (db) => {
@@ -62,10 +69,52 @@ export function loadChildrenOfSummary(hippoRoot, summaryId, tenantId) {
62
69
  return rows.map(rowToEntry);
63
70
  }, openStore);
64
71
  }
65
- /** Apply a rebuild result to a dirty summary in one write scope (UPDATE plus syncFtsRow); `AND summary_dirty = 1` makes a concurrent race-loser a no-op.
66
- * Returns `{ changed, refused }`: `refused` only when a tombstone hit suppressed the content write while the metadata UPDATE still landed. */
72
+ /** loadChildrenOfSummary for many summaries in one IN query per tenant chunk; the map key is
73
+ * `${tenantId}\u0000${summaryId}`, each list in created order. */
74
+ export function loadChildrenOfSummaries(hippoRoot, summaries) {
75
+ const byTenant = new Map();
76
+ for (const s of summaries) {
77
+ assertTenantId('loadChildrenOfSummaries', s.tenant_id);
78
+ const ids = byTenant.get(s.tenant_id) ?? [];
79
+ ids.push(s.id);
80
+ byTenant.set(s.tenant_id, ids);
81
+ }
82
+ const out = new Map();
83
+ onHandle(hippoRoot, (db) => {
84
+ for (const [tenantId, ids] of byTenant) {
85
+ for (const slice of chunked(ids)) {
86
+ // SAFETY: this query selects exactly MEMORY_SELECT_COLUMNS, matching MemoryRow's field set.
87
+ const rows = db.prepare(`
88
+ SELECT ${MEMORY_SELECT_COLUMNS}
89
+ FROM memories
90
+ WHERE dag_parent_id IN (${placeholders(slice.length)})
91
+ AND tenant_id = ?
92
+ AND kind != 'archived'
93
+ AND superseded_by IS NULL
94
+ ORDER BY created ASC
95
+ `).all(...slice, tenantId);
96
+ for (const entry of rows.map(rowToEntry)) {
97
+ const key = childrenKey(tenantId, entry.dag_parent_id ?? '');
98
+ const list = out.get(key);
99
+ if (list)
100
+ list.push(entry);
101
+ else
102
+ out.set(key, [entry]);
103
+ }
104
+ }
105
+ }
106
+ }, openStore);
107
+ return out;
108
+ }
109
+ /** Key into the map loadChildrenOfSummaries returns. */
110
+ export function childrenKey(tenantId, summaryId) {
111
+ return `${tenantId}\u0000${summaryId}`;
112
+ }
113
+ /** Apply a rebuild result to a dirty summary in one write scope (UPDATE plus syncFtsRow); `AND summary_dirty = 1` makes
114
+ * a concurrent race-loser a no-op. Returns `{ changed, refused }`: `refused` only when a tombstone hit suppressed the
115
+ * content write while the metadata UPDATE still landed. */
67
116
  export function applyRebuildResult(hippoRoot, summary, patch) {
68
- assertTenantId('applyRebuildResult', summary.tenantId);
117
+ assertTenantId('applyRebuildResult', summary.tenant_id);
69
118
  return onHandle(hippoRoot, (db) => {
70
119
  return withWriteScope(db, 'rebuild_summary', () => applyRebuildInSavepoint(db, summary, patch));
71
120
  }, openStore);
@@ -81,7 +130,7 @@ const REBUILD_CONTENT_SQL = `UPDATE memories
81
130
  summary_dirty = 0
82
131
  WHERE id = ?
83
132
  AND tenant_id = ?
84
- AND dag_level IN (2, 3)
133
+ AND dag_level IN (${DAG_LEVEL.topic}, ${DAG_LEVEL.entity})
85
134
  AND summary_dirty = 1
86
135
  AND kind != 'archived'`;
87
136
  const REBUILD_METADATA_SQL = `UPDATE memories
@@ -91,7 +140,7 @@ const REBUILD_METADATA_SQL = `UPDATE memories
91
140
  summary_dirty = 0
92
141
  WHERE id = ?
93
142
  AND tenant_id = ?
94
- AND dag_level IN (2, 3)
143
+ AND dag_level IN (${DAG_LEVEL.topic}, ${DAG_LEVEL.entity})
95
144
  AND summary_dirty = 1
96
145
  AND kind != 'archived'`;
97
146
  function applyRebuildInSavepoint(db, summary, patch) {
@@ -99,14 +148,15 @@ function applyRebuildInSavepoint(db, summary, patch) {
99
148
  // Check tombstones before choosing the UPDATE: this direct UPDATE bypasses upsertEntryRow's guard, and
100
149
  // a deterministic rebuild would otherwise re-assert a rejected value every sleep cycle.
101
150
  const tombstone = patch.bumpRebuildCount
102
- ? findRejectedValue(db, summary.tenantId, rejectionDigest(patch.content))
151
+ ? findRejectedValue(db, summary.tenant_id, rejectionDigest(patch.content))
103
152
  : null;
104
- // On a tombstone hit, write no content: take the zero-child metadata-only path (descendant_count/earliest_at/latest_at, summary_dirty cleared, no
105
- // rebuild_count bump). Clearing dirty is deliberate: leaving it set would make every later sleep re-attempt and re-refuse the same rebuild forever.
153
+ // On a tombstone hit, write no content: take the zero-child metadata-only path
154
+ // (descendant_count/earliest_at/latest_at, summary_dirty cleared, no rebuild_count bump). Clearing dirty is
155
+ // deliberate: leaving it set would make every later sleep re-attempt and re-refuse the same rebuild forever.
106
156
  const applyContentWrite = patch.bumpRebuildCount && !tombstone;
107
157
  const result = applyContentWrite
108
- ? db.prepare(REBUILD_CONTENT_SQL).run(patch.content, patch.descendant_count, patch.earliest_at, patch.latest_at, nowIso, summary.id, summary.tenantId)
109
- : db.prepare(REBUILD_METADATA_SQL).run(patch.descendant_count, patch.earliest_at, patch.latest_at, summary.id, summary.tenantId);
158
+ ? db.prepare(REBUILD_CONTENT_SQL).run(patch.content, patch.descendant_count, patch.earliest_at, patch.latest_at, nowIso, summary.id, summary.tenant_id)
159
+ : db.prepare(REBUILD_METADATA_SQL).run(patch.descendant_count, patch.earliest_at, patch.latest_at, summary.id, summary.tenant_id);
110
160
  // `changed` means THIS call's UPDATE hit a row, so a refusal still settles the cycle (false would retry
111
161
  // the doomed rebuild forever); `refused` lets the caller count it as refused rather than rebuilt.
112
162
  const changed = (result.changes ?? 0) > 0;
@@ -119,13 +169,14 @@ function applyRebuildInSavepoint(db, summary, patch) {
119
169
  }
120
170
  /** Audit and log a rebuild whose content matched a rejected value; metadata still landed. */
121
171
  function auditRefusedRebuild(db, summary, patch, tombstone) {
122
- // refused === true here (narrowed for the tombstone.* access). Best-effort refusal audit written INLINE in this still-open SAVEPOINT (the metadata
123
- // UPDATE already committed to it), so a direct audit() call is correct, not the post-rollback auditRejectionRefusal.
172
+ // refused === true here (narrowed for the tombstone.* access). Best-effort refusal audit written INLINE in this
173
+ // still-open SAVEPOINT (the metadata UPDATE already committed to it), so a direct audit() call is correct, not the
174
+ // post-rollback auditRejectionRefusal.
124
175
  audit(db, 'reject_refusal', {
125
176
  targetId: summary.id,
126
177
  metadata: { digest: tombstone.digest, reason: tombstone.reason },
127
178
  actor: patch.actor,
128
- tenantId: summary.tenantId
179
+ tenantId: summary.tenant_id
129
180
  });
130
181
  log.warn(`applyRebuildResult: refused rebuild content for ${summary.id} — matches a rejected value ` +
131
182
  `(digest ${tombstone.digest.slice(0, DIGEST_DISPLAY_CHARS)}...); metadata updated, content unchanged`);
@@ -139,7 +190,7 @@ function syncRebuiltSummary(db, summary, patch, applyContentWrite, nowIso) {
139
190
  descendant_count: patch.descendant_count,
140
191
  earliest_at: patch.earliest_at,
141
192
  latest_at: patch.latest_at,
142
- summary_dirty: 0,
193
+ summary_dirty: false,
143
194
  last_rebuilt_at: applyContentWrite ? nowIso : summary.last_rebuilt_at,
144
195
  rebuild_count: applyContentWrite
145
196
  ? (summary.rebuild_count ?? 0) + 1
@@ -152,10 +203,11 @@ function syncRebuiltSummary(db, summary, patch, applyContentWrite, nowIso) {
152
203
  source: 'E3-rebuild',
153
204
  zero_children: patch.zeroChildren,
154
205
  descendant_count: patch.descendant_count,
155
- }, actor: patch.actor, tenantId: summary.tenantId });
206
+ }, actor: patch.actor, tenantId: summary.tenant_id });
156
207
  }
157
- /** Clear summary_dirty on a new summary after buildDag's child-link loop (each member's writeEntry marks the parent dirty, so the same cycle would rebuild it).
158
- * Idempotent (no-op, no audit if not dirty); audit source='buildDag-clean' distinguishes it from the rebuild's. */
208
+ /** Clear summary_dirty on a new summary after buildDag's child-link loop (each member's writeEntry marks the parent
209
+ * dirty, so the same cycle would rebuild it). Idempotent (no-op, no audit if not dirty); audit source='buildDag-clean'
210
+ * distinguishes it from the rebuild's. */
159
211
  export function clearSummaryDirtyAfterBuild(hippoRoot, summaryId, tenantId, actor = 'cli', source = 'buildDag-clean') {
160
212
  assertTenantId('clearSummaryDirtyAfterBuild', tenantId);
161
213
  onHandle(hippoRoot, (db) => {
@@ -166,14 +218,19 @@ export function clearSummaryDirtyAfterBuild(hippoRoot, summaryId, tenantId, acto
166
218
  SET summary_dirty = 0
167
219
  WHERE id = ?
168
220
  AND tenant_id = ?
169
- AND dag_level IN (2, 3)
221
+ AND dag_level IN (${DAG_LEVEL.topic}, ${DAG_LEVEL.entity})
170
222
  AND summary_dirty = 1
171
223
  AND kind != 'archived'
172
224
  RETURNING dag_level
173
225
  `).get(summaryId, tenantId);
174
226
  if (result) {
175
227
  // source tells buildDag-clean (L2) from buildEntityProfiles-clean (L3) and any future build path.
176
- audit(db, 'summary_marked_clean', { targetId: summaryId, metadata: { dag_level: result.dag_level, source }, actor, tenantId });
228
+ audit(db, 'summary_marked_clean', {
229
+ targetId: summaryId,
230
+ metadata: { dag_level: result.dag_level, source },
231
+ actor,
232
+ tenantId,
233
+ });
177
234
  }
178
235
  }, openStore);
179
236
  }
@@ -1,4 +1,5 @@
1
1
  import type { DatabaseSyncLike } from '../db/index.js';
2
- /** Runs in the caller's transaction so the mark commits or rolls back with the child change; only a 0 to 1 flip is audited. */
2
+ /** Runs in the caller's transaction so the mark commits or rolls back with the child change; only a 0 to 1 flip is
3
+ * audited. */
3
4
  export declare function markSummaryDirtyInTx(db: DatabaseSyncLike, summaryId: string, tenantId: string, actor: string): void;
4
5
  //# sourceMappingURL=summary-dirty.d.ts.map
@@ -1,6 +1,7 @@
1
1
  // Leaf module so entry-writes.ts and raw-archive.ts can both mark a parent summary dirty without importing each other.
2
2
  import { appendAuditEvent, reportAuditWriteFailure } from './audit.js';
3
- /** Runs in the caller's transaction so the mark commits or rolls back with the child change; only a 0 to 1 flip is audited. */
3
+ /** Runs in the caller's transaction so the mark commits or rolls back with the child change; only a 0 to 1 flip is
4
+ * audited. */
4
5
  export function markSummaryDirtyInTx(db, summaryId, tenantId, actor) {
5
6
  // SAFETY: result's shape matches the single `dag_level` column returned below.
6
7
  const result = db.prepare(`
@@ -5,7 +5,8 @@ export interface ResolveOpts {
5
5
  apiKey?: string;
6
6
  }
7
7
  export declare function resolveTenantId(opts: ResolveOpts): string;
8
- /** Runtime guard for tenant id args: an older JS caller can pass a `sessionId` as the tenant (`loadLatestHandoff(root, 'sess-abc')`) and silently get null.
9
- * Rejects values starting `sess-` / `sess_`; a tenant literally named `sess-...` is refused, an accepted tradeoff. */
8
+ /** Runtime guard for tenant id args: an older JS caller can pass a `sessionId` as the tenant (`loadLatestHandoff(root,
9
+ * 'sess-abc')`) and silently get null. Rejects values starting `sess-` / `sess_`; a tenant literally named `sess-...`
10
+ * is refused, an accepted tradeoff. */
10
11
  export declare function assertTenantId(fnName: string, value: JsonValue): asserts value is string;
11
12
  //# sourceMappingURL=tenant.d.ts.map
@@ -9,12 +9,13 @@ export function resolveTenantId(opts) {
9
9
  throw new Error('invalid api key');
10
10
  return ctx.tenantId;
11
11
  }
12
- // Empty/whitespace-only HIPPO_TENANT must fall through to 'default': `??` only catches undefined, so '' leaked through and broke every downstream tenant
13
- // filter.
12
+ // Empty/whitespace-only HIPPO_TENANT must fall through to 'default': `??` only catches undefined, so '' leaked
13
+ // through and broke every downstream tenant filter.
14
14
  return envTenant();
15
15
  }
16
- /** Runtime guard for tenant id args: an older JS caller can pass a `sessionId` as the tenant (`loadLatestHandoff(root, 'sess-abc')`) and silently get null.
17
- * Rejects values starting `sess-` / `sess_`; a tenant literally named `sess-...` is refused, an accepted tradeoff. */
16
+ /** Runtime guard for tenant id args: an older JS caller can pass a `sessionId` as the tenant (`loadLatestHandoff(root,
17
+ * 'sess-abc')`) and silently get null. Rejects values starting `sess-` / `sess_`; a tenant literally named `sess-...`
18
+ * is refused, an accepted tradeoff. */
18
19
  export function assertTenantId(fnName, value) {
19
20
  if (typeof value !== 'string' || value.length === 0) {
20
21
  throw new Error(`${fnName}: tenantId is required (got ${typeof value})`);
@@ -1,3 +1,4 @@
1
+ import { placeholders } from '../util/sql.js';
1
2
  export function insertTokenRow(db, row) {
2
3
  db.prepare(`INSERT INTO token_ledger (ts, tenant_id, session_id, surface, event, items, tokens, block_hash)
3
4
  VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(row.ts, row.tenantId, row.sessionId, row.surface, row.event, row.items, row.tokens, row.blockHash);
@@ -33,12 +34,15 @@ export function surfaceTotals(db, tenantId, sinceIso) {
33
34
  /** Window-wide session counts; `rereadSurfaces` are the hook surfaces whose sessions count as hook sessions. */
34
35
  export function sessionTotals(db, tenantId, sinceIso, rereadSurfaces) {
35
36
  // SAFETY: the SELECT names exactly these four aggregate columns.
36
- return db.prepare(`SELECT COUNT(DISTINCT session_id) AS sessions,
37
- COUNT(DISTINCT CASE WHEN event <> 'reset' AND surface IN (${rereadSurfaces.map(() => '?').join(', ')}) THEN session_id END) AS hook_sessions,
37
+ return db
38
+ .prepare(`SELECT COUNT(DISTINCT session_id) AS sessions,
39
+ COUNT(DISTINCT CASE WHEN event <> 'reset' AND surface IN (${placeholders(rereadSurfaces.length)}) THEN
40
+ session_id END) AS hook_sessions,
38
41
  COUNT(DISTINCT CASE WHEN event = 'reread' THEN session_id END) AS reread_sessions,
39
42
  SUM(CASE WHEN event = 'inject' THEN tokens ELSE 0 END) AS tokens
40
43
  FROM token_ledger
41
- WHERE tenant_id = ? AND ts >= ? AND session_id IS NOT NULL AND event <> 'arm'`).get(...rereadSurfaces, tenantId, sinceIso);
44
+ WHERE tenant_id = ? AND ts >= ? AND session_id IS NOT NULL AND event <> 'arm'`)
45
+ .get(...rereadSurfaces, tenantId, sinceIso);
42
46
  }
43
47
  export function sessionTokenRows(db, tenantId, sinceIso) {
44
48
  // SAFETY: the SELECT names exactly these columns, all aggregates or TEXT.
@@ -53,7 +57,7 @@ export function sessionTokenRows(db, tenantId, sinceIso) {
53
57
  export function injectedBlocks(db, tenantId, sessionId, surfaces) {
54
58
  // SAFETY: the SELECT names exactly these three columns.
55
59
  return db.prepare(`SELECT ts, surface, tokens FROM token_ledger
56
- WHERE tenant_id = ? AND session_id = ? AND event = 'inject' AND surface IN (${surfaces.map(() => '?').join(', ')})`).all(tenantId, sessionId, ...surfaces);
60
+ WHERE tenant_id = ? AND session_id = ? AND event = 'inject' AND surface IN (${placeholders(surfaces.length)})`).all(tenantId, sessionId, ...surfaces);
57
61
  }
58
62
  export function deleteRereadRows(db, tenantId, sessionId) {
59
63
  db.prepare(`DELETE FROM token_ledger WHERE tenant_id = ? AND session_id = ? AND event = 'reread'`).run(tenantId, sessionId);
@@ -1,13 +1,15 @@
1
1
  import { type DatabaseSyncLike } from '../db/index.js';
2
- /** Where a block was sent: `hook`/`hook_recall` (per-prompt hook), `compact_resume`, `context`/`recall` (CLI), `mcp_*`, `http_*`,
3
- * and `pilot` (session pilot arm row, src/api/pilot-arm.ts; not a send, so in no surface list). */
2
+ /** Where a block was sent: `hook`/`hook_recall` (per-prompt hook), `compact_resume`, `context`/`recall` (CLI), `mcp_*`,
3
+ * `http_*`, and `pilot` (session pilot arm row, src/api/pilot-arm.ts; not a send, so in no surface list). */
4
4
  export type TokenSurface = 'hook' | 'hook_recall' | 'compact_resume' | 'context' | 'recall' | 'mcp_recall' | 'mcp_context' | 'http_recall' | 'http_context' | 'http_assemble' | 'pilot';
5
5
  /** All surfaces, in report order. */
6
6
  export declare const TOKEN_SURFACES: readonly TokenSurface[];
7
- /** Surfaces whose re-reads are counted: only a hook payload tells a sub-agent's block from its parent's, as both carry one session id. */
7
+ /** Surfaces whose re-reads are counted: only a hook payload tells a sub-agent's block from its parent's, as both carry
8
+ * one session id. */
8
9
  export declare const REREAD_SURFACES: readonly TokenSurface[];
9
- /** What happened to a block: `inject` (sent), `skip` (identical to the last injected block), `reset` (host compacted, next must send), `reread` (tokens
10
- * later calls read again, booked at session end), `arm` (pilot assignment; `block_hash` is `hippo` or `holdout`, `items` the holdout rate in bp). */
10
+ /** What happened to a block: `inject` (sent), `skip` (identical to the last injected block), `reset` (host compacted,
11
+ * next must send), `reread` (tokens later calls read again, booked at session end), `arm` (pilot assignment;
12
+ * `block_hash` is `hippo` or `holdout`, `items` the holdout rate in bp). */
11
13
  export type TokenEvent = 'inject' | 'skip' | 'reset' | 'reread' | 'arm';
12
14
  /** Rows older than this are pruned on write. */
13
15
  export declare const TOKEN_LEDGER_RETENTION_DAYS = 90;
@@ -36,10 +38,11 @@ export interface LastSent {
36
38
  /** Consecutive `skip` rows since that injection. */
37
39
  skipsSince: number;
38
40
  }
39
- /** The last block this session injected on `surface`, or null if none, a `reset` came after it, or there is no session id (the caller then always injects). */
41
+ /** The last block this session injected on `surface`, or null if none, a `reset` came after it, or there is no session
42
+ * id (the caller then always injects). */
40
43
  export declare function lastSentState(db: DatabaseSyncLike, tenantId: string, sessionId: string | null | undefined, surface: TokenSurface): LastSent | null;
41
- /** Whether a block identical to the session's last injection should be skipped; `refreshTurns` resends it after that many consecutive skips so a long
42
- * session still sees its pinned rules, 0 never resends. */
44
+ /** Whether a block identical to the session's last injection should be skipped; `refreshTurns` resends it after that
45
+ * many consecutive skips so a long session still sees its pinned rules, 0 never resends. */
43
46
  export declare function shouldSkipUnchanged(last: LastSent | null, hash: string, refreshTurns: number): boolean;
44
47
  /** Per-surface totals for {@link summarizeTokenUse}. */
45
48
  export interface TokenSurfaceSummary {
@@ -52,7 +55,8 @@ export interface TokenSurfaceSummary {
52
55
  skipped: number;
53
56
  /** Tokens those skipped blocks would have cost. */
54
57
  tokensAvoided: number;
55
- /** Tokens of these blocks that later model calls read again, from sessions that have ended; 0 off {@link REREAD_SURFACES}. */
58
+ /** Tokens of these blocks that later model calls read again, from sessions that have ended; 0 off {@link
59
+ * REREAD_SURFACES}. */
56
60
  tokensReread: number;
57
61
  /** Distinct session ids seen (rows without one are not counted). */
58
62
  sessions: number;
@@ -80,7 +84,8 @@ export declare function summarizeTokenUse(db: DatabaseSyncLike, tenantId: string
80
84
  interface ModelTagged {
81
85
  model?: unknown;
82
86
  }
83
- /** Claude Code writes its own API errors and limit notices as assistant lines from this model; no model call made them. */
87
+ /** Claude Code writes its own API errors and limit notices as assistant lines from this model; no model call made
88
+ * them. */
84
89
  export declare function isSyntheticMessage(message: ModelTagged): boolean;
85
90
  /** Tokens hippo sent and skipped in one session, for {@link tokensBySession}. */
86
91
  export interface SessionTokens {
@@ -92,8 +97,8 @@ export interface SessionTokens {
92
97
  /** Blocks sent. */
93
98
  injections: number;
94
99
  }
95
- /** Ledger totals per session id since `sinceIso`, across surfaces; hook rows carry the host's session id (the transcript file name), so they join to its
96
- * usage records. */
100
+ /** Ledger totals per session id since `sinceIso`, across surfaces; hook rows carry the host's session id (the
101
+ * transcript file name), so they join to its usage records. */
97
102
  export declare function tokensBySession(db: DatabaseSyncLike, tenantId: string, sinceIso: string): SessionTokens[];
98
103
  /** One model API call in a host transcript, for {@link recordRereads}. */
99
104
  export interface ApiCall {
@@ -112,7 +117,8 @@ export interface TranscriptCalls {
112
117
  export declare function readApiCalls(transcriptPath: string): Promise<TranscriptCalls>;
113
118
  /** Calls that carried a block sent at `at` (epoch ms): every later call in the first later call's context window. */
114
119
  export declare function carryingCalls(calls: readonly ApiCall[], at: number): ApiCall[];
115
- /** Replace a session's `reread` rows in `hippoRoot`'s store, one per {@link REREAD_SURFACES} surface and UTC day; returns the tokens booked. */
120
+ /** Replace a session's `reread` rows in `hippoRoot`'s store, one per {@link REREAD_SURFACES} surface and UTC day;
121
+ * returns the tokens booked. */
116
122
  export declare function recordRereads(hippoRoot: string, tenantId: string, sessionId: string, calls: readonly ApiCall[]): number;
117
123
  export {};
118
124
  //# sourceMappingURL=token-ledger.d.ts.map
@@ -1,6 +1,7 @@
1
- /** Token ledger: one row per block of memory text sent to an agent on any surface, with its token cost; the input for the token-savings evals.
2
- * Backs inject-only-on-change: the hook records a `skip` when the block hash matches the session's last; `reread` rows cover {@link REREAD_SURFACES} blocks.
3
- * Counts use {@link estimateTokens} (chars / 4); rows never hold content or query text. Writes are best-effort: a ledger failure must not break recall. */
1
+ /** Token ledger: one row per block of memory text sent to an agent on any surface, with its token cost; the input for
2
+ * the token-savings evals. Backs inject-only-on-change: the hook records a `skip` when the block hash matches the
3
+ * session's last; `reread` rows cover {@link REREAD_SURFACES} blocks. Counts use {@link estimateTokens} (chars / 4);
4
+ * rows never hold content or query text. Writes are best-effort: a ledger failure must not break recall. */
4
5
  import { open } from 'node:fs/promises';
5
6
  import { withWriteScope } from '../db/index.js';
6
7
  import { onHandle } from './open.js';
@@ -13,7 +14,8 @@ export const TOKEN_SURFACES = [
13
14
  'hook', 'hook_recall', 'compact_resume', 'context', 'recall', 'mcp_recall', 'mcp_context',
14
15
  'http_recall', 'http_context', 'http_assemble',
15
16
  ];
16
- /** Surfaces whose re-reads are counted: only a hook payload tells a sub-agent's block from its parent's, as both carry one session id. */
17
+ /** Surfaces whose re-reads are counted: only a hook payload tells a sub-agent's block from its parent's, as both carry
18
+ * one session id. */
17
19
  export const REREAD_SURFACES = ['hook', 'hook_recall', 'compact_resume'];
18
20
  /** Rows older than this are pruned on write. */
19
21
  export const TOKEN_LEDGER_RETENTION_DAYS = 90;
@@ -33,7 +35,8 @@ export function recordTokenUse(db, use) {
33
35
  const cutoff = new Date(Date.parse(now) - TOKEN_LEDGER_RETENTION_DAYS * DAY_MS).toISOString();
34
36
  pruneTokenRowsBefore(db, cutoff);
35
37
  }
36
- /** The last block this session injected on `surface`, or null if none, a `reset` came after it, or there is no session id (the caller then always injects). */
38
+ /** The last block this session injected on `surface`, or null if none, a `reset` came after it, or there is no session
39
+ * id (the caller then always injects). */
37
40
  export function lastSentState(db, tenantId, sessionId, surface) {
38
41
  if (!sessionId)
39
42
  return null;
@@ -43,8 +46,8 @@ export function lastSentState(db, tenantId, sessionId, surface) {
43
46
  const skips = countSkipsAfter(db, tenantId, sessionId, surface, anchor.id);
44
47
  return { hash: anchor.block_hash, skipsSince: Number(skips?.n ?? 0) };
45
48
  }
46
- /** Whether a block identical to the session's last injection should be skipped; `refreshTurns` resends it after that many consecutive skips so a long
47
- * session still sees its pinned rules, 0 never resends. */
49
+ /** Whether a block identical to the session's last injection should be skipped; `refreshTurns` resends it after that
50
+ * many consecutive skips so a long session still sees its pinned rules, 0 never resends. */
48
51
  export function shouldSkipUnchanged(last, hash, refreshTurns) {
49
52
  if (!last || last.hash !== hash)
50
53
  return false;
@@ -86,12 +89,13 @@ export function summarizeTokenUse(db, tenantId, sinceIso) {
86
89
  rereadSessions: Number(perSession?.reread_sessions ?? 0),
87
90
  };
88
91
  }
89
- /** Claude Code writes its own API errors and limit notices as assistant lines from this model; no model call made them. */
92
+ /** Claude Code writes its own API errors and limit notices as assistant lines from this model; no model call made
93
+ * them. */
90
94
  export function isSyntheticMessage(message) {
91
95
  return message.model === '<synthetic>';
92
96
  }
93
- /** Ledger totals per session id since `sinceIso`, across surfaces; hook rows carry the host's session id (the transcript file name), so they join to its
94
- * usage records. */
97
+ /** Ledger totals per session id since `sinceIso`, across surfaces; hook rows carry the host's session id (the
98
+ * transcript file name), so they join to its usage records. */
95
99
  export function tokensBySession(db, tenantId, sinceIso) {
96
100
  return sessionTokenRows(db, tenantId, sinceIso).map((r) => ({
97
101
  sessionId: r.session_id,
@@ -149,13 +153,15 @@ export async function readApiCalls(transcriptPath) {
149
153
  }
150
154
  /** Calls that carried a block sent at `at` (epoch ms): every later call in the first later call's context window. */
151
155
  export function carryingCalls(calls, at) {
152
- // Windows come from file order, not boundary timestamps: the compact-resume block is booked before its boundary's timestamp.
156
+ // Windows come from file order, not boundary timestamps: the compact-resume block is booked before its boundary's
157
+ // timestamp.
153
158
  const first = calls.find((call) => call.at > at);
154
159
  if (!first)
155
160
  return [];
156
161
  return calls.filter((call) => call.at > at && call.compactions === first.compactions);
157
162
  }
158
- /** Replace a session's `reread` rows in `hippoRoot`'s store, one per {@link REREAD_SURFACES} surface and UTC day; returns the tokens booked. */
163
+ /** Replace a session's `reread` rows in `hippoRoot`'s store, one per {@link REREAD_SURFACES} surface and UTC day;
164
+ * returns the tokens booked. */
159
165
  export function recordRereads(hippoRoot, tenantId, sessionId, calls) {
160
166
  return onHandle(hippoRoot, (db) => {
161
167
  return replaceRereadRows(db, tenantId, sessionId, calls);
@@ -173,7 +179,8 @@ function replaceRereadRows(db, tenantId, sessionId, calls) {
173
179
  };
174
180
  for (const row of rows) {
175
181
  const sentAt = Date.parse(row.ts);
176
- // Dated by when the calls happened, so a --days window counts re-reads in it; the empty send-day row keeps the session in coverage.
182
+ // Dated by when the calls happened, so a --days window counts re-reads in it; the empty send-day row keeps the
183
+ // session in coverage.
177
184
  add(row.surface, sentAt, 0, 0);
178
185
  // The first carrying call is the send itself; every later one is a re-read.
179
186
  for (const call of carryingCalls(calls, sentAt).slice(1))
@@ -182,7 +189,13 @@ function replaceRereadRows(db, tenantId, sessionId, calls) {
182
189
  deleteRereadRows(db, tenantId, sessionId);
183
190
  for (const day of days.values()) {
184
191
  recordTokenUse(db, {
185
- tenantId, sessionId, surface: day.surface, event: 'reread', items: day.rereads, tokens: day.tokens, now: new Date(day.at).toISOString(),
192
+ tenantId,
193
+ sessionId,
194
+ surface: day.surface,
195
+ event: 'reread',
196
+ items: day.rereads,
197
+ tokens: day.tokens,
198
+ now: new Date(day.at).toISOString(),
186
199
  });
187
200
  }
188
201
  return [...days.values()].reduce((sum, day) => sum + day.tokens, 0);
@@ -1,11 +1,14 @@
1
1
  import { type AppendAuditOpts } from './audit.js';
2
2
  import { type RejectedValueRow } from './rejection.js';
3
- /** Tombstone lookups and their refusal audit rows on one handle: opened on first use, never under dryRun, closed once. */
3
+ /** Tombstone lookups and their refusal audit rows on one handle: opened on first use, never under dryRun, closed
4
+ * once. */
4
5
  export interface TombstoneChecks {
5
6
  /** The tenant's tombstone for `digest`; null when there is none, and always under dryRun. */
6
7
  find(tenantId: string, digest: string): RejectedValueRow | null;
7
8
  /** One audit row on the same handle; nothing under dryRun. */
8
9
  audit(event: AppendAuditOpts): void;
10
+ /** `audit`, with a failed write logged and counted instead of thrown, for a refusal that stands without its row. */
11
+ auditOrCount(event: AppendAuditOpts): void;
9
12
  close(): void;
10
13
  }
11
14
  export declare function lazyTombstoneChecks(hippoRoot: string, dryRun: boolean): TombstoneChecks;