@remnic/core 9.23.3 → 9.24.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 (377) hide show
  1. package/dist/access-admin-ops-surface.d.ts +13 -10
  2. package/dist/access-admin-ops-surface.js +50 -46
  3. package/dist/access-boundary.d.ts +13 -10
  4. package/dist/access-boundary.js +50 -46
  5. package/dist/access-cli.js +125 -122
  6. package/dist/access-cli.js.map +1 -1
  7. package/dist/access-health-types.d.ts +54 -0
  8. package/dist/access-health-types.js +1 -0
  9. package/dist/access-health-types.js.map +1 -0
  10. package/dist/access-http.d.ts +14 -11
  11. package/dist/access-http.js +59 -55
  12. package/dist/access-identity-continuity-surface.d.ts +9 -8
  13. package/dist/access-identity-continuity-surface.js +50 -46
  14. package/dist/access-lcm-surface.d.ts +13 -10
  15. package/dist/access-lcm-surface.js +50 -46
  16. package/dist/access-mcp.d.ts +13 -10
  17. package/dist/access-mcp.js +55 -51
  18. package/dist/access-memory-search-fanout.d.ts +3 -2
  19. package/dist/{access-namespace-preflight-CmErR03h.d.ts → access-namespace-preflight-wRSZEO5V.d.ts} +1 -1
  20. package/dist/access-namespace-preflight.d.ts +4 -3
  21. package/dist/access-namespace-preflight.js +50 -46
  22. package/dist/access-observe-write-surface.d.ts +13 -10
  23. package/dist/access-observe-write-surface.js +50 -46
  24. package/dist/access-operations-batch.js +52 -48
  25. package/dist/access-operations.d.ts +17 -14
  26. package/dist/access-operations.js +54 -50
  27. package/dist/access-recall-concurrency.d.ts +13 -10
  28. package/dist/access-recall-concurrency.js +50 -46
  29. package/dist/access-recall-response.d.ts +13 -10
  30. package/dist/access-recall-response.js +50 -46
  31. package/dist/access-recall-surface.d.ts +13 -10
  32. package/dist/access-recall-surface.js +50 -46
  33. package/dist/access-schema.d.ts +86 -86
  34. package/dist/access-schema.js +8 -8
  35. package/dist/{access-service-CKEROeFP.d.ts → access-service-BlNKWBC9.d.ts} +11 -38
  36. package/dist/access-service.d.ts +15 -12
  37. package/dist/access-service.js +50 -46
  38. package/dist/access-surface-catalog.d.ts +13 -10
  39. package/dist/access-wearables-meetings-surface.d.ts +4 -3
  40. package/dist/action-confidence.d.ts +2 -1
  41. package/dist/active-memory-bridge.d.ts +2 -1
  42. package/dist/active-recall.d.ts +2 -1
  43. package/dist/active-recall.js +3 -2
  44. package/dist/active-recall.js.map +1 -1
  45. package/dist/adapters/index.js +4 -4
  46. package/dist/adapters/registry.js +2 -2
  47. package/dist/behavior-learner.d.ts +2 -1
  48. package/dist/behavior-signals.d.ts +2 -1
  49. package/dist/bootstrap.d.ts +9 -8
  50. package/dist/briefing.d.ts +3 -2
  51. package/dist/briefing.js +14 -14
  52. package/dist/buffer-surprise-report.d.ts +2 -1
  53. package/dist/buffer.d.ts +6 -2
  54. package/dist/buffer.js +1 -1
  55. package/dist/bulk-import/index.d.ts +4 -3
  56. package/dist/calibration.d.ts +2 -1
  57. package/dist/capabilities.d.ts +2 -1
  58. package/dist/{catalog-BFTVo2Ez.d.ts → catalog-BLLxZ5L5.d.ts} +1 -1
  59. package/dist/causal-behavior.d.ts +2 -1
  60. package/dist/causal-consolidation.d.ts +2 -1
  61. package/dist/causal-consolidation.js +15 -15
  62. package/dist/causal-trajectory-graph.d.ts +2 -1
  63. package/dist/{chunk-P2BLHUL2.js → chunk-2NAFR36N.js} +5 -5
  64. package/dist/{chunk-WMLHJ5UW.js → chunk-2WSX7U2N.js} +2 -2
  65. package/dist/{chunk-E3ZMFFQZ.js → chunk-3FLPLDIL.js} +2 -2
  66. package/dist/chunk-443XCR34.js +213 -0
  67. package/dist/chunk-443XCR34.js.map +1 -0
  68. package/dist/{chunk-JNIJBXVK.js → chunk-4KAIGQVU.js} +2 -2
  69. package/dist/{chunk-354T54RR.js → chunk-4TFIRMTE.js} +28 -1
  70. package/dist/chunk-4TFIRMTE.js.map +1 -0
  71. package/dist/{chunk-XWPFZX6S.js → chunk-7CP7SO32.js} +108 -37
  72. package/dist/chunk-7CP7SO32.js.map +1 -0
  73. package/dist/{chunk-XGEFGNL5.js → chunk-7IECFM4E.js} +18 -10
  74. package/dist/chunk-7IECFM4E.js.map +1 -0
  75. package/dist/{chunk-ZN4UZWMT.js → chunk-A5N6ISRK.js} +2 -2
  76. package/dist/{chunk-XKGPIWGI.js → chunk-AVPXXV6J.js} +4 -4
  77. package/dist/{chunk-4PQ4KLLK.js → chunk-BHKDCWGH.js} +9 -9
  78. package/dist/{chunk-5CPI2QWG.js → chunk-CSXHRAJJ.js} +3 -3
  79. package/dist/{chunk-QCKQEBIY.js → chunk-DFTCJVXI.js} +6 -6
  80. package/dist/{chunk-QE63OHLB.js → chunk-ECG64R7B.js} +5 -5
  81. package/dist/{chunk-ATEAL5EI.js → chunk-EFYACT2X.js} +2 -2
  82. package/dist/{chunk-YNDLCWXS.js → chunk-EZ25VE3G.js} +4 -4
  83. package/dist/{chunk-UGH6VPPO.js → chunk-FHH6R3QI.js} +2 -2
  84. package/dist/{chunk-WZVIB5BK.js → chunk-GCKIDUHE.js} +69 -53
  85. package/dist/chunk-GCKIDUHE.js.map +1 -0
  86. package/dist/{chunk-MAXVH44E.js → chunk-GF22HWS2.js} +10 -10
  87. package/dist/{chunk-ZYU7ZFLT.js → chunk-GJJBPI6I.js} +5 -1
  88. package/dist/chunk-GJJBPI6I.js.map +1 -0
  89. package/dist/{chunk-AU7Q3LSC.js → chunk-JBPKEARU.js} +4 -4
  90. package/dist/{chunk-IPLYGWQF.js → chunk-KQAFEZQX.js} +5 -5
  91. package/dist/{chunk-CUUY5CC4.js → chunk-L7DTBRTI.js} +2 -2
  92. package/dist/{chunk-AYAROCWD.js → chunk-LLISELSY.js} +2 -2
  93. package/dist/{chunk-MMTG3SCJ.js → chunk-M5EPMNS4.js} +2 -2
  94. package/dist/{chunk-HSSIWAZP.js → chunk-M6ZJR6HU.js} +140 -124
  95. package/dist/{chunk-HSSIWAZP.js.map → chunk-M6ZJR6HU.js.map} +1 -1
  96. package/dist/{chunk-WWZ35GWW.js → chunk-MX4TUDMB.js} +2 -2
  97. package/dist/{chunk-SVZGA2MK.js → chunk-NHPROHJD.js} +2 -2
  98. package/dist/{chunk-6TWXQ4E2.js → chunk-NM7SKDZM.js} +2 -2
  99. package/dist/chunk-NQ7E27HN.js +261 -0
  100. package/dist/chunk-NQ7E27HN.js.map +1 -0
  101. package/dist/{chunk-QJAQNXWI.js → chunk-ONHRRJZM.js} +6 -6
  102. package/dist/{chunk-V2XVMCP6.js → chunk-P25IPRXP.js} +7 -7
  103. package/dist/{chunk-KXGE7L62.js → chunk-RENY3AIW.js} +67 -67
  104. package/dist/chunk-RENY3AIW.js.map +1 -0
  105. package/dist/{chunk-3L5O7SMT.js → chunk-SGMORUEU.js} +3 -3
  106. package/dist/{chunk-3ZW6ZQO6.js → chunk-TBJV4BZE.js} +13 -13
  107. package/dist/{chunk-7I7AYIUQ.js → chunk-TGHUJC64.js} +5 -5
  108. package/dist/{chunk-SCOT5DTA.js → chunk-V25OWXAC.js} +1 -1
  109. package/dist/chunk-V25OWXAC.js.map +1 -0
  110. package/dist/{chunk-DLKRXYRL.js → chunk-V4MAO2Y4.js} +15 -15
  111. package/dist/{chunk-5FZQ74K5.js → chunk-WMR5WPZU.js} +2 -2
  112. package/dist/{chunk-M6LJXJ3J.js → chunk-WNSQOXWS.js} +6 -6
  113. package/dist/{chunk-KNB7IBBU.js → chunk-WO7KBATL.js} +4 -4
  114. package/dist/{chunk-3NAHZQU3.js → chunk-X3SQYAPP.js} +2 -2
  115. package/dist/{chunk-3UOSVTFR.js → chunk-XBRPEGXF.js} +5 -5
  116. package/dist/{chunk-GD3QOBMB.js → chunk-XHYCPA5C.js} +2 -2
  117. package/dist/{chunk-ES5IHQ6M.js → chunk-Z3B4V4YI.js} +5 -5
  118. package/dist/chunk-ZLNOX7B2.js +60 -0
  119. package/dist/chunk-ZLNOX7B2.js.map +1 -0
  120. package/dist/{cli-BrwT9YMD.d.ts → cli-Zc6UclD1.d.ts} +5 -5
  121. package/dist/cli.d.ts +15 -12
  122. package/dist/cli.js +85 -82
  123. package/dist/compounding/engine.d.ts +3 -2
  124. package/dist/compounding/engine.js +14 -14
  125. package/dist/compounding/preference-consolidator.d.ts +2 -1
  126. package/dist/compression-optimizer.d.ts +2 -1
  127. package/dist/config.d.ts +2 -1
  128. package/dist/config.js +3 -2
  129. package/dist/connectors/codex-materialize-runner.d.ts +2 -1
  130. package/dist/connectors/codex-materialize-runner.js +14 -14
  131. package/dist/connectors/codex-materialize.d.ts +2 -1
  132. package/dist/connectors/index.d.ts +2 -1
  133. package/dist/connectors/index.js +17 -17
  134. package/dist/consolidation-provenance-check.d.ts +3 -2
  135. package/dist/consolidation-undo.d.ts +3 -2
  136. package/dist/contradiction/index.d.ts +3 -2
  137. package/dist/conversation-index/backend.d.ts +2 -1
  138. package/dist/conversation-index/chunker.d.ts +2 -1
  139. package/dist/conversation-index/faiss-adapter.d.ts +2 -1
  140. package/dist/conversation-index/indexer.d.ts +2 -1
  141. package/dist/conversation-index/search.d.ts +2 -1
  142. package/dist/corpus-watermark.d.ts +228 -0
  143. package/dist/corpus-watermark.js +106 -0
  144. package/dist/corpus-watermark.js.map +1 -0
  145. package/dist/dashboard-runtime.js +2 -2
  146. package/dist/day-summary.d.ts +2 -1
  147. package/dist/delinearize.d.ts +2 -1
  148. package/dist/direct-answer-wiring.d.ts +2 -1
  149. package/dist/direct-answer.d.ts +2 -1
  150. package/dist/embedding-fallback.d.ts +2 -1
  151. package/dist/enrichment/index.d.ts +2 -1
  152. package/dist/entity-retrieval.d.ts +3 -2
  153. package/dist/entity-retrieval.js +14 -14
  154. package/dist/entity-schema.d.ts +2 -1
  155. package/dist/explicit-capture.d.ts +9 -8
  156. package/dist/extraction-error-classification.d.ts +2 -1
  157. package/dist/extraction-faithfulness.d.ts +2 -1
  158. package/dist/extraction-judge-telemetry.d.ts +2 -1
  159. package/dist/extraction-judge-training.d.ts +2 -1
  160. package/dist/extraction-judge.d.ts +2 -1
  161. package/dist/extraction-liveness.d.ts +5 -0
  162. package/dist/extraction-liveness.js +26 -0
  163. package/dist/extraction-liveness.js.map +1 -0
  164. package/dist/extraction.d.ts +2 -1
  165. package/dist/extraction.js +1 -1
  166. package/dist/fallback-llm.d.ts +2 -1
  167. package/dist/graph-dashboard-diff.d.ts +2 -1
  168. package/dist/graph-dashboard-key.d.ts +2 -1
  169. package/dist/graph-dashboard-parser.d.ts +2 -1
  170. package/dist/graph-edge-reinforcement.d.ts +2 -1
  171. package/dist/graph-snapshot.d.ts +2 -1
  172. package/dist/graph.d.ts +2 -1
  173. package/dist/importance.d.ts +2 -1
  174. package/dist/importers/index.d.ts +2 -1
  175. package/dist/in-flight-reads.d.ts +2 -1
  176. package/dist/index.d.ts +427 -424
  177. package/dist/index.js +212 -209
  178. package/dist/intent.d.ts +2 -1
  179. package/dist/lcm/engine.d.ts +2 -1
  180. package/dist/lcm/engine.js +4 -4
  181. package/dist/lcm/index.d.ts +2 -1
  182. package/dist/lcm/index.js +12 -12
  183. package/dist/lcm/tools.d.ts +2 -1
  184. package/dist/lifecycle.d.ts +2 -1
  185. package/dist/live-connectors-runner.d.ts +2 -1
  186. package/dist/local-llm.d.ts +2 -1
  187. package/dist/local-model-endpoint.d.ts +2 -1
  188. package/dist/maintenance/memory-governance.d.ts +2 -1
  189. package/dist/maintenance/memory-governance.js +14 -14
  190. package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +3 -2
  191. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +14 -14
  192. package/dist/maintenance/rebuild-memory-projection.d.ts +3 -2
  193. package/dist/maintenance/rebuild-memory-projection.js +15 -15
  194. package/dist/{maintenance-C98njYb8.d.ts → maintenance-DD22oIx9.d.ts} +3 -3
  195. package/dist/mcp-memory-inspector-app.d.ts +13 -10
  196. package/dist/memory-action-policy.d.ts +2 -1
  197. package/dist/memory-cache.d.ts +2 -1
  198. package/dist/memory-lifecycle-ledger-utils.d.ts +2 -1
  199. package/dist/memory-projection-store.d.ts +2 -1
  200. package/dist/memory-provenance.d.ts +2 -1
  201. package/dist/memory-worth-outcomes.d.ts +3 -2
  202. package/dist/models-json.d.ts +2 -1
  203. package/dist/namespaces/migrate.d.ts +4 -3
  204. package/dist/namespaces/migrate.js +21 -21
  205. package/dist/namespaces/principal.d.ts +2 -1
  206. package/dist/namespaces/search.d.ts +2 -1
  207. package/dist/namespaces/search.js +6 -6
  208. package/dist/namespaces/storage.d.ts +4 -3
  209. package/dist/namespaces/storage.js +14 -14
  210. package/dist/native-knowledge.d.ts +2 -1
  211. package/dist/offline-sync-impression-drain.d.ts +2 -1
  212. package/dist/offline-sync-impression-drain.js +4 -4
  213. package/dist/operator-doctor-corpus.d.ts +31 -0
  214. package/dist/operator-doctor-corpus.js +91 -0
  215. package/dist/operator-doctor-corpus.js.map +1 -0
  216. package/dist/operator-doctor-types.d.ts +22 -0
  217. package/dist/operator-doctor-types.js +1 -0
  218. package/dist/operator-doctor-types.js.map +1 -0
  219. package/dist/operator-toolkit.d.ts +10 -13
  220. package/dist/operator-toolkit.js +35 -29
  221. package/dist/orchestration/compression-guideline-coordinator.d.ts +3 -2
  222. package/dist/orchestration/maintenance.d.ts +5 -4
  223. package/dist/orchestration/maintenance.js +20 -20
  224. package/dist/{orchestrator-C9ZVppNh.d.ts → orchestrator-BTGgoKli.d.ts} +7 -7
  225. package/dist/orchestrator.d.ts +9 -8
  226. package/dist/orchestrator.js +123 -120
  227. package/dist/patterns-cli.d.ts +2 -1
  228. package/dist/{pipeline-id_-sqYm.d.ts → pipeline-Bq5zU6Bp.d.ts} +1 -1
  229. package/dist/policy-runtime.d.ts +2 -1
  230. package/dist/proactive-contention.d.ts +2 -1
  231. package/dist/provenance.d.ts +2 -1
  232. package/dist/{qmd-R6XaQOZK.d.ts → qmd-3ILJkC70.d.ts} +1 -1
  233. package/dist/qmd-preflight.d.ts +3 -2
  234. package/dist/qmd-recall-cache.d.ts +2 -1
  235. package/dist/qmd.d.ts +3 -2
  236. package/dist/qmd.js +4 -4
  237. package/dist/recall-concurrency-config.d.ts +2 -1
  238. package/dist/recall-disclosure-escalation.d.ts +2 -1
  239. package/dist/recall-explain-renderer.d.ts +2 -1
  240. package/dist/recall-explain-renderer.js +3 -3
  241. package/dist/recall-memory-map.d.ts +2 -1
  242. package/dist/recall-planner-llm.d.ts +2 -1
  243. package/dist/recall-state.d.ts +2 -1
  244. package/dist/recall-tag-filter.d.ts +2 -1
  245. package/dist/recall-timings.d.ts +2 -1
  246. package/dist/recall-xray-cli.d.ts +2 -1
  247. package/dist/recall-xray-cli.js +4 -4
  248. package/dist/recall-xray-renderer.d.ts +2 -1
  249. package/dist/recall-xray-renderer.js +3 -3
  250. package/dist/recall-xray.d.ts +2 -1
  251. package/dist/recall-xray.js +2 -2
  252. package/dist/replay/normalizers/chatgpt.d.ts +2 -1
  253. package/dist/replay/normalizers/claude.d.ts +2 -1
  254. package/dist/replay/normalizers/openclaw.d.ts +2 -1
  255. package/dist/replay/normalizers/shared.d.ts +2 -1
  256. package/dist/replay/runner.d.ts +2 -1
  257. package/dist/replay/types.d.ts +2 -1
  258. package/dist/resolve-auth-token.d.ts +2 -1
  259. package/dist/resume-bundles.js +5 -4
  260. package/dist/retrieval-agents.d.ts +3 -2
  261. package/dist/retrieval-tiers.d.ts +2 -1
  262. package/dist/routing/engine.d.ts +2 -1
  263. package/dist/routing/store.d.ts +2 -1
  264. package/dist/salvage-envelope.d.ts +2 -1
  265. package/dist/schemas.d.ts +76 -76
  266. package/dist/{scope-profiles-EhyuAKkd.d.ts → scope-profiles-D0-ff4xT.d.ts} +1 -1
  267. package/dist/search/embed-helper.d.ts +2 -1
  268. package/dist/search/factory.d.ts +2 -1
  269. package/dist/search/factory.js +5 -5
  270. package/dist/search/index.d.ts +2 -1
  271. package/dist/search/index.js +9 -9
  272. package/dist/search/lancedb-backend.d.ts +2 -1
  273. package/dist/search/meilisearch-backend.d.ts +2 -1
  274. package/dist/search/noop-backend.d.ts +2 -1
  275. package/dist/search/orama-backend.d.ts +2 -1
  276. package/dist/search/port.d.ts +2 -1
  277. package/dist/search/remote-backend.d.ts +2 -1
  278. package/dist/{semantic-consolidation-B2xo26UQ.d.ts → semantic-consolidation-4Tfh7c1g.d.ts} +1 -1
  279. package/dist/semantic-consolidation.d.ts +3 -2
  280. package/dist/semantic-consolidation.js +15 -15
  281. package/dist/semantic-rule-promotion.js +14 -14
  282. package/dist/semantic-rule-verifier.d.ts +2 -1
  283. package/dist/semantic-rule-verifier.js +14 -14
  284. package/dist/{service-DgFWlZ-r.d.ts → service-Z8uzoAST.d.ts} +2 -2
  285. package/dist/session-observer-bands.d.ts +2 -1
  286. package/dist/session-observer-state.d.ts +2 -1
  287. package/dist/shared-context/manager.d.ts +10 -9
  288. package/dist/signal.d.ts +2 -1
  289. package/dist/{storage-XGawwqXE.d.ts → storage-BZVMn8yJ.d.ts} +25 -2
  290. package/dist/storage.d.ts +3 -2
  291. package/dist/storage.js +13 -13
  292. package/dist/summarizer.d.ts +2 -1
  293. package/dist/summary-snapshot.d.ts +2 -1
  294. package/dist/temporal-supersession.d.ts +3 -2
  295. package/dist/temporal-timeline-recall.d.ts +2 -1
  296. package/dist/temporal-validity.d.ts +2 -1
  297. package/dist/threading.d.ts +2 -1
  298. package/dist/tier-migration.d.ts +3 -2
  299. package/dist/tier-routing.d.ts +2 -1
  300. package/dist/tokens.js +2 -2
  301. package/dist/topics.d.ts +2 -1
  302. package/dist/transcript.d.ts +2 -1
  303. package/dist/transfer/autodetect.js +1 -1
  304. package/dist/transfer/backup.js +3 -3
  305. package/dist/transfer/capsule-export.js +4 -4
  306. package/dist/transfer/capsule-import.js +1 -1
  307. package/dist/transfer/types.d.ts +66 -66
  308. package/dist/trust-score-stage.d.ts +2 -1
  309. package/dist/trust-score.d.ts +2 -1
  310. package/dist/{types-Bbs0qz6b.d.ts → types-DHBxIF0s.d.ts} +181 -5
  311. package/dist/types.d.ts +2 -1
  312. package/dist/types.js +1 -1
  313. package/dist/utility-runtime.d.ts +2 -1
  314. package/dist/verified-recall.js +14 -14
  315. package/dist/write-envelope.d.ts +2 -1
  316. package/package.json +12 -2
  317. package/src/access-health-types.ts +51 -0
  318. package/src/access-http.test.ts +22 -2
  319. package/src/access-service-health.test.ts +212 -0
  320. package/src/access-service.ts +14 -37
  321. package/src/buffer.ts +30 -0
  322. package/src/cli.ts +2 -4
  323. package/src/config.ts +4 -4
  324. package/src/corpus-watermark.test.ts +840 -0
  325. package/src/corpus-watermark.ts +531 -0
  326. package/src/extraction-liveness.test.ts +461 -0
  327. package/src/extraction-liveness.ts +462 -0
  328. package/src/operator-doctor-corpus.test.ts +171 -0
  329. package/src/operator-doctor-corpus.ts +95 -0
  330. package/src/operator-doctor-types.ts +20 -0
  331. package/src/operator-toolkit.ts +12 -13
  332. package/src/recall/archive-scoring.ts +18 -0
  333. package/src/storage/memory-read-store.ts +91 -22
  334. package/src/storage.ts +27 -2
  335. package/src/types.ts +4 -4
  336. package/dist/chunk-354T54RR.js.map +0 -1
  337. package/dist/chunk-KXGE7L62.js.map +0 -1
  338. package/dist/chunk-SCOT5DTA.js.map +0 -1
  339. package/dist/chunk-WZVIB5BK.js.map +0 -1
  340. package/dist/chunk-XGEFGNL5.js.map +0 -1
  341. package/dist/chunk-XWPFZX6S.js.map +0 -1
  342. package/dist/chunk-ZYU7ZFLT.js.map +0 -1
  343. /package/dist/{chunk-P2BLHUL2.js.map → chunk-2NAFR36N.js.map} +0 -0
  344. /package/dist/{chunk-WMLHJ5UW.js.map → chunk-2WSX7U2N.js.map} +0 -0
  345. /package/dist/{chunk-E3ZMFFQZ.js.map → chunk-3FLPLDIL.js.map} +0 -0
  346. /package/dist/{chunk-JNIJBXVK.js.map → chunk-4KAIGQVU.js.map} +0 -0
  347. /package/dist/{chunk-ZN4UZWMT.js.map → chunk-A5N6ISRK.js.map} +0 -0
  348. /package/dist/{chunk-XKGPIWGI.js.map → chunk-AVPXXV6J.js.map} +0 -0
  349. /package/dist/{chunk-4PQ4KLLK.js.map → chunk-BHKDCWGH.js.map} +0 -0
  350. /package/dist/{chunk-5CPI2QWG.js.map → chunk-CSXHRAJJ.js.map} +0 -0
  351. /package/dist/{chunk-QCKQEBIY.js.map → chunk-DFTCJVXI.js.map} +0 -0
  352. /package/dist/{chunk-QE63OHLB.js.map → chunk-ECG64R7B.js.map} +0 -0
  353. /package/dist/{chunk-ATEAL5EI.js.map → chunk-EFYACT2X.js.map} +0 -0
  354. /package/dist/{chunk-YNDLCWXS.js.map → chunk-EZ25VE3G.js.map} +0 -0
  355. /package/dist/{chunk-UGH6VPPO.js.map → chunk-FHH6R3QI.js.map} +0 -0
  356. /package/dist/{chunk-MAXVH44E.js.map → chunk-GF22HWS2.js.map} +0 -0
  357. /package/dist/{chunk-AU7Q3LSC.js.map → chunk-JBPKEARU.js.map} +0 -0
  358. /package/dist/{chunk-IPLYGWQF.js.map → chunk-KQAFEZQX.js.map} +0 -0
  359. /package/dist/{chunk-CUUY5CC4.js.map → chunk-L7DTBRTI.js.map} +0 -0
  360. /package/dist/{chunk-AYAROCWD.js.map → chunk-LLISELSY.js.map} +0 -0
  361. /package/dist/{chunk-MMTG3SCJ.js.map → chunk-M5EPMNS4.js.map} +0 -0
  362. /package/dist/{chunk-WWZ35GWW.js.map → chunk-MX4TUDMB.js.map} +0 -0
  363. /package/dist/{chunk-SVZGA2MK.js.map → chunk-NHPROHJD.js.map} +0 -0
  364. /package/dist/{chunk-6TWXQ4E2.js.map → chunk-NM7SKDZM.js.map} +0 -0
  365. /package/dist/{chunk-QJAQNXWI.js.map → chunk-ONHRRJZM.js.map} +0 -0
  366. /package/dist/{chunk-V2XVMCP6.js.map → chunk-P25IPRXP.js.map} +0 -0
  367. /package/dist/{chunk-3L5O7SMT.js.map → chunk-SGMORUEU.js.map} +0 -0
  368. /package/dist/{chunk-3ZW6ZQO6.js.map → chunk-TBJV4BZE.js.map} +0 -0
  369. /package/dist/{chunk-7I7AYIUQ.js.map → chunk-TGHUJC64.js.map} +0 -0
  370. /package/dist/{chunk-DLKRXYRL.js.map → chunk-V4MAO2Y4.js.map} +0 -0
  371. /package/dist/{chunk-5FZQ74K5.js.map → chunk-WMR5WPZU.js.map} +0 -0
  372. /package/dist/{chunk-M6LJXJ3J.js.map → chunk-WNSQOXWS.js.map} +0 -0
  373. /package/dist/{chunk-KNB7IBBU.js.map → chunk-WO7KBATL.js.map} +0 -0
  374. /package/dist/{chunk-3NAHZQU3.js.map → chunk-X3SQYAPP.js.map} +0 -0
  375. /package/dist/{chunk-3UOSVTFR.js.map → chunk-XBRPEGXF.js.map} +0 -0
  376. /package/dist/{chunk-GD3QOBMB.js.map → chunk-XHYCPA5C.js.map} +0 -0
  377. /package/dist/{chunk-ES5IHQ6M.js.map → chunk-Z3B4V4YI.js.map} +0 -0
@@ -0,0 +1,462 @@
1
+ /**
2
+ * Extraction-pipeline liveness (issue #2151).
3
+ *
4
+ * A daemon's implicit extraction can fail continuously for months while
5
+ * `/health` stays green and recall keeps serving: every individual failure is
6
+ * logged (timeouts, fallback-no-parsed-output), but nothing aggregates them
7
+ * into a checkable status. This module surfaces a liveness *watermark* — the
8
+ * last successful extraction plus the current buffer backlog — and decides when
9
+ * that watermark is stale enough to call the pipeline degraded.
10
+ *
11
+ * The §22 error-vs-empty principle applies at the pipeline level: "no
12
+ * extraction succeeded for 90 days" (a non-empty buffer with a stale/absent
13
+ * watermark) must be distinguishable from "nothing to extract" (an empty
14
+ * buffer). Degradation therefore requires a NON-EMPTY buffer — an idle daemon
15
+ * with nothing buffered is healthy, not degraded.
16
+ *
17
+ * The core decision (`evaluateExtractionLiveness`) is a pure function shared by
18
+ * every surface (authenticated `/health`, `remnic doctor`, `remnic stats`) so
19
+ * the verdict never diverges across code paths.
20
+ */
21
+ import { coerceBool, coerceNumber } from "./connectors/coerce.js";
22
+ import { log } from "./logger.js";
23
+ import type { OperatorDoctorCheck } from "./operator-doctor-types.js";
24
+ import type { MetaState, PluginConfig } from "./types.js";
25
+
26
+ /** Default staleness window: 24h. A watermark older than this with a non-empty buffer is degraded. */
27
+ const DEFAULT_STALE_WINDOW_MS = 86_400_000;
28
+
29
+ export interface ExtractionLivenessConfig {
30
+ /** Master gate. When false, liveness is never reported degraded. Default true. */
31
+ enabled: boolean;
32
+ /**
33
+ * How stale the last-successful-extraction watermark may get (ms) before a
34
+ * non-empty buffer flags the pipeline degraded. Default 24h.
35
+ */
36
+ staleWindowMs: number;
37
+ }
38
+
39
+ /**
40
+ * A read-only snapshot of buffered, not-yet-extracted work. Structurally
41
+ * satisfied by `SmartBuffer.getBufferSnapshot()` so callers can pass the live
42
+ * buffer without this module depending on the buffer implementation.
43
+ */
44
+ export interface ExtractionBufferSnapshot {
45
+ bufferedSessionCount: number;
46
+ pendingTurnCount: number;
47
+ oldestTurnTimestamp: string | null;
48
+ /**
49
+ * Set by the liveness reader (never by `SmartBuffer`) when the buffer exists
50
+ * but its snapshot read threw. An unreadable buffer is a pipeline fault, not
51
+ * an empty queue (§22): it degrades the pipeline with a distinct reason
52
+ * instead of masquerading as a zero-backlog (healthy) snapshot.
53
+ */
54
+ readFailed?: boolean;
55
+ /** Read-failure detail, surfaced in the degraded reason when `readFailed`. */
56
+ readError?: string;
57
+ }
58
+
59
+ export interface ExtractionBufferSource {
60
+ getBufferSnapshot(): Promise<ExtractionBufferSnapshot>;
61
+ }
62
+
63
+ /**
64
+ * The liveness payload surfaced on `/health.extraction` and in the doctor/stats
65
+ * details.
66
+ *
67
+ * DAEMON-SCOPED SIGNAL: a daemon exposes a single extraction verdict; the
68
+ * last-extraction watermark is read from the daemon's default/root store, so
69
+ * `/health` returns the same `extraction` block for every namespace argument.
70
+ *
71
+ * KNOWN LIMITATION (issue #2159): extraction stamps `lastExtractionAt` on the
72
+ * PER-NAMESPACE store (`storageFor(selfNamespace)`), so this watermark reflects
73
+ * only extraction that stamped the root store (default-namespace work). On a
74
+ * single-namespace deployment (the common case) the watermark and buffer share
75
+ * one scope and the verdict is exact. On a multi-namespace deployment the verdict
76
+ * is NOT guaranteed correct for work isolated to a non-default namespace: it can
77
+ * over-report `degraded` (the default namespace idle while another is extracting)
78
+ * or miss a stall confined to a non-default namespace. Aggregating the watermark
79
+ * across namespace stores is tracked in #2159.
80
+ */
81
+ export interface ExtractionLivenessStatus {
82
+ lastExtractionAt: string | null;
83
+ bufferedSessionCount: number;
84
+ pendingTurnCount: number;
85
+ oldestBufferedTurnAgeMs: number | null;
86
+ degraded: boolean;
87
+ degradedReason: string | null;
88
+ /**
89
+ * Scope of the last-extraction watermark: `root-store` today (read from the
90
+ * daemon's default/root store only), `aggregate` once it is resolved across
91
+ * every namespace store (#2159). A monitor can alert on
92
+ * `watermarkScope !== "aggregate"` while namespaces are enabled instead of
93
+ * trusting a number that may be wrong in either direction.
94
+ */
95
+ watermarkScope: "root-store" | "aggregate";
96
+ }
97
+
98
+ interface ExtractionLivenessStorageLike {
99
+ loadMeta(): Promise<Pick<MetaState, "lastExtractionAt">>;
100
+ }
101
+
102
+ interface ExtractionLivenessOrchestratorLike {
103
+ config: Pick<PluginConfig, "extractionLiveness">;
104
+ buffer?: ExtractionBufferSource;
105
+ }
106
+
107
+ /**
108
+ * Parse the `extractionLiveness` config block. Follows the nested-block shape
109
+ * validation used elsewhere in `config.ts` and coerces string booleans (§24:
110
+ * CLI/JSON deliver `"false"`/`"0"` as strings, which must read as falsy).
111
+ */
112
+ export function parseExtractionLivenessConfig(
113
+ cfg: Record<string, unknown>,
114
+ ): ExtractionLivenessConfig {
115
+ const raw = cfg.extractionLiveness;
116
+ if (raw !== undefined && (raw === null || typeof raw !== "object" || Array.isArray(raw))) {
117
+ throw new Error(`extractionLiveness must be a plain object (got ${JSON.stringify(raw)})`);
118
+ }
119
+ const block = (raw ?? {}) as Record<string, unknown>;
120
+ return {
121
+ // `?? true` keeps the default on when the key is absent while honoring
122
+ // explicit "false"/"0"/false opt-outs (coerceBool handles the string forms).
123
+ enabled: coerceBool(block.enabled) ?? true,
124
+ staleWindowMs: parseStaleWindowMs(block.staleWindowMs),
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Parse `extractionLiveness.staleWindowMs`. Absent (`undefined`) → the 24h
130
+ * default; any PRESENT value (including an explicit `null`) must coerce to a
131
+ * positive INTEGER of milliseconds, else THROW. A fractional or non-positive
132
+ * value ("0.5" would floor to 0, making every backlog instantly stale; 1.9 would
133
+ * floor to 1) is rejected, never floored/reinterpreted (§1/§17/§39). Mirrors
134
+ * config.ts's `parseIntegerInClosedRange` (round 9 finding 1): only an absent key
135
+ * falls back; an explicit `null` is invalid input, not "use the default".
136
+ * Inlined rather than imported because config.ts already imports this module
137
+ * (importing back would be circular), the same reason `recall-concurrency-config.ts`
138
+ * inlines its numeric validation.
139
+ */
140
+ function parseStaleWindowMs(value: unknown): number {
141
+ // Only an absent key (undefined) falls back to the default; an explicit `null`
142
+ // is invalid input and proceeds to validation → throw (mirrors
143
+ // parseIntegerInClosedRange, round 9 finding 1).
144
+ if (value === undefined) return DEFAULT_STALE_WINDOW_MS;
145
+ const coerced = coerceNumber(value);
146
+ if (coerced === undefined || !Number.isFinite(coerced) || !Number.isInteger(coerced) || coerced < 1) {
147
+ throw new Error(
148
+ `extractionLiveness.staleWindowMs must be an integer greater than or equal to 1; got ${JSON.stringify(value)}`,
149
+ );
150
+ }
151
+ return coerced;
152
+ }
153
+
154
+ /** Milliseconds between `timestamp` and `nowMs`, clamped at 0; null when unparsable/absent. */
155
+ function ageMsFrom(timestamp: string | null, nowMs: number): number | null {
156
+ if (typeof timestamp !== "string") return null;
157
+ const parsed = Date.parse(timestamp);
158
+ if (!Number.isFinite(parsed)) return null;
159
+ return Math.max(0, nowMs - parsed);
160
+ }
161
+
162
+ /** Compact human-readable duration ("3d", "5h", "12m", "45s") for logs and CLI output. */
163
+ export function formatAgeMs(ms: number): string {
164
+ const s = Math.max(0, Math.floor(ms / 1000));
165
+ if (s >= 86_400) return `${Math.floor(s / 86_400)}d`;
166
+ if (s >= 3_600) return `${Math.floor(s / 3_600)}h`;
167
+ if (s >= 60) return `${Math.floor(s / 60)}m`;
168
+ return `${s}s`;
169
+ }
170
+
171
+ /**
172
+ * Pure liveness verdict. Degraded when the feature is enabled AND any of: the
173
+ * last-extraction watermark could not be READ (a storage fault, §22), the buffer
174
+ * read failed (a pipeline fault, §22), or the buffer is non-empty and the
175
+ * watermark is absent or stale. Each cause yields a DISTINCT reason so an
176
+ * operator can tell a meta-read failure from a buffer-read failure from a
177
+ * pipeline that has genuinely never extracted.
178
+ *
179
+ * Staleness uses a half-open freshness window (§23): an extraction is fresh
180
+ * while its age is in `[0, staleWindowMs)`, so an age of EXACTLY `staleWindowMs`
181
+ * is stale (the upper bound on "fresh" is exclusive). A null/unparsable watermark
182
+ * means "never succeeded" and is treated as stale — as is a FUTURE watermark (a
183
+ * clock-skewed or corrupt timestamp ahead of now must not read as a fresh
184
+ * extraction and hide a real backlog stall).
185
+ */
186
+ export function evaluateExtractionLiveness(input: {
187
+ config: ExtractionLivenessConfig;
188
+ lastExtractionAt: string | null;
189
+ snapshot: ExtractionBufferSnapshot;
190
+ nowMs: number;
191
+ metaReadFailed?: boolean;
192
+ metaReadError?: string;
193
+ watermarkScope?: "root-store" | "aggregate";
194
+ }): ExtractionLivenessStatus {
195
+ const { config, lastExtractionAt, snapshot, nowMs } = input;
196
+ const lastMs = lastExtractionAt !== null ? Date.parse(lastExtractionAt) : Number.NaN;
197
+ const hasWatermark = Number.isFinite(lastMs);
198
+ const ageMs = nowMs - lastMs;
199
+ // A future watermark (negative age) is clock-skewed or corrupt data, not a
200
+ // fresh extraction: treat it as stale so a real backlog stall is not hidden.
201
+ const stale = !hasWatermark || ageMs < 0 || ageMs >= config.staleWindowMs;
202
+ const hasBacklog = snapshot.bufferedSessionCount > 0;
203
+ // A watermark or buffer that cannot be READ is a fault, not an empty queue
204
+ // (§22): a storage/pipeline outage must not read as healthy, and must stay
205
+ // distinct from a pipeline that has genuinely never extracted.
206
+ const metaReadFailed = input.metaReadFailed === true;
207
+ const readFailed = snapshot.readFailed === true;
208
+ const degraded = config.enabled && (metaReadFailed || readFailed || (hasBacklog && stale));
209
+
210
+ let degradedReason: string | null = null;
211
+ if (degraded) {
212
+ if (metaReadFailed) {
213
+ degradedReason = `extraction watermark unreadable: ${input.metaReadError ?? "meta read failed"}`;
214
+ } else if (readFailed) {
215
+ degradedReason = `extraction buffer unreadable: ${snapshot.readError ?? "buffer snapshot read failed"}`;
216
+ } else {
217
+ const watermark = hasWatermark
218
+ ? `last succeeded ${formatAgeMs(nowMs - lastMs)} ago`
219
+ : "no successful extraction on record";
220
+ degradedReason =
221
+ `${watermark}; ${snapshot.bufferedSessionCount} buffered session(s), ` +
222
+ `${snapshot.pendingTurnCount} turn(s) pending extraction`;
223
+ }
224
+ }
225
+
226
+ return {
227
+ lastExtractionAt,
228
+ bufferedSessionCount: snapshot.bufferedSessionCount,
229
+ pendingTurnCount: snapshot.pendingTurnCount,
230
+ oldestBufferedTurnAgeMs: ageMsFrom(snapshot.oldestTurnTimestamp, nowMs),
231
+ degraded,
232
+ degradedReason,
233
+ watermarkScope: input.watermarkScope ?? "root-store",
234
+ };
235
+ }
236
+
237
+ const EMPTY_SNAPSHOT: ExtractionBufferSnapshot = {
238
+ bufferedSessionCount: 0,
239
+ pendingTurnCount: 0,
240
+ oldestTurnTimestamp: null,
241
+ };
242
+
243
+ /**
244
+ * Read a buffer snapshot without throwing. An ABSENT buffer degrades to an empty
245
+ * (healthy) snapshot — some service constructions have no orchestrator buffer. A
246
+ * buffer that EXISTS but whose read throws yields a `readFailed` snapshot so the
247
+ * verdict can distinguish a pipeline fault from an empty queue (§22).
248
+ */
249
+ async function readBufferSnapshot(
250
+ buffer: ExtractionBufferSource | undefined,
251
+ ): Promise<ExtractionBufferSnapshot> {
252
+ if (!buffer || typeof buffer.getBufferSnapshot !== "function") return EMPTY_SNAPSHOT;
253
+ try {
254
+ return await buffer.getBufferSnapshot();
255
+ } catch (err) {
256
+ return {
257
+ ...EMPTY_SNAPSHOT,
258
+ readFailed: true,
259
+ readError: err instanceof Error ? err.message : String(err),
260
+ };
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Gather the liveness status from a meta store (last-extraction watermark) and
266
+ * an optional buffer (backlog). A read failure on EITHER side is captured and
267
+ * surfaced as a DEGRADED status with a distinct reason (§22) rather than being
268
+ * swallowed into a healthy-looking verdict; no failure path throws.
269
+ */
270
+ export async function gatherExtractionLivenessStatus(input: {
271
+ config: ExtractionLivenessConfig;
272
+ storage: ExtractionLivenessStorageLike;
273
+ buffer: ExtractionBufferSource | undefined;
274
+ nowMs: number;
275
+ }): Promise<ExtractionLivenessStatus> {
276
+ const { config, storage, buffer, nowMs } = input;
277
+ let lastExtractionAt: string | null = null;
278
+ let metaReadFailed = false;
279
+ let metaReadError: string | undefined;
280
+ try {
281
+ lastExtractionAt = (await storage.loadMeta()).lastExtractionAt ?? null;
282
+ } catch (err) {
283
+ // A swallowed loadMeta() failure that reads as "never extracted" is the
284
+ // exact §22 conflation this feature exists to kill — surface it explicitly.
285
+ metaReadFailed = true;
286
+ metaReadError = err instanceof Error ? err.message : String(err);
287
+ }
288
+ const snapshot = await readBufferSnapshot(buffer);
289
+ return evaluateExtractionLiveness({
290
+ config,
291
+ lastExtractionAt,
292
+ snapshot,
293
+ nowMs,
294
+ metaReadFailed,
295
+ metaReadError,
296
+ // Today the watermark comes from the root store only; #2159 flips this to
297
+ // "aggregate" when the resolver reads across every namespace store.
298
+ watermarkScope: "root-store",
299
+ });
300
+ }
301
+
302
+ /**
303
+ * Aggregated-WARN throttle (issue #2151): emit at most ONE warning per
304
+ * staleness window while degraded — not one line per failed extraction attempt.
305
+ * State is instance-scoped (held by the owning service), never a module global
306
+ * (§5), so multiple service instances throttle independently.
307
+ */
308
+ export class ExtractionLivenessWarnThrottle {
309
+ private lastWarnAtMs: number | null = null;
310
+
311
+ /** Warn if degraded and outside the throttle window; returns whether a WARN was emitted. */
312
+ maybeWarn(status: ExtractionLivenessStatus, staleWindowMs: number, nowMs: number): boolean {
313
+ if (!status.degraded) {
314
+ // Recovered (or never degraded): reset so a fresh episode warns at once.
315
+ this.lastWarnAtMs = null;
316
+ return false;
317
+ }
318
+ if (this.lastWarnAtMs !== null && nowMs - this.lastWarnAtMs < staleWindowMs) return false;
319
+ this.lastWarnAtMs = nowMs;
320
+ log.warn(
321
+ `extraction pipeline liveness degraded: ${status.degradedReason ?? "buffered turns are not being extracted"}`,
322
+ );
323
+ return true;
324
+ }
325
+ }
326
+
327
+ /**
328
+ * Normalize the `extractionLiveness` block at the read boundary. `parseConfig`
329
+ * always populates it, but a host adapter, an older persisted config, or a
330
+ * hand-built `PluginConfig` can hand us an absent, partial, or loosely-typed
331
+ * block - and every liveness surface (/health, doctor, stats) must degrade to
332
+ * the documented default (enabled, 24h window) rather than throw. Both fields
333
+ * are coerced with the same rules as `parseExtractionLivenessConfig` (§24:
334
+ * `"false"`/`"0"` read as falsy; a numeric string like `"5000"` parses), except a
335
+ * present but non-integer or non-positive `staleWindowMs` falls back to the
336
+ * default here rather than throwing.
337
+ */
338
+ export function resolveExtractionLivenessConfig(
339
+ block: { enabled?: unknown; staleWindowMs?: unknown } | undefined,
340
+ ): ExtractionLivenessConfig {
341
+ const staleWindowMs = coerceNumber(block?.staleWindowMs);
342
+ return {
343
+ enabled: coerceBool(block?.enabled) ?? true,
344
+ staleWindowMs:
345
+ staleWindowMs !== undefined && Number.isInteger(staleWindowMs) && staleWindowMs >= 1
346
+ ? staleWindowMs
347
+ : DEFAULT_STALE_WINDOW_MS,
348
+ };
349
+ }
350
+
351
+ /**
352
+ * Compute the liveness status for the authenticated `/health` payload and emit
353
+ * the throttled aggregated WARN.
354
+ *
355
+ * The watermark is read from the daemon's default/root store (`orchestrator.storage`),
356
+ * which is why `/health` returns the same `extraction` block for any namespace
357
+ * argument. KNOWN LIMITATION (issue #2159): extraction writes `lastExtractionAt`
358
+ * per-namespace, so this watermark reflects only default-namespace extraction and
359
+ * the verdict is exact only for a single-namespace daemon (see
360
+ * `ExtractionLivenessStatus`).
361
+ */
362
+ export async function computeExtractionLivenessStatus(
363
+ orchestrator: ExtractionLivenessOrchestratorLike & { storage: ExtractionLivenessStorageLike },
364
+ throttle?: ExtractionLivenessWarnThrottle,
365
+ nowMs: number = Date.now(),
366
+ ): Promise<ExtractionLivenessStatus> {
367
+ const config = resolveExtractionLivenessConfig(orchestrator.config.extractionLiveness);
368
+ const status = await gatherExtractionLivenessStatus({
369
+ config,
370
+ storage: orchestrator.storage,
371
+ buffer: orchestrator.buffer,
372
+ nowMs,
373
+ });
374
+ throttle?.maybeWarn(status, config.staleWindowMs, nowMs);
375
+ return status;
376
+ }
377
+
378
+ /**
379
+ * `remnic doctor` check for extraction-pipeline liveness. Status `warn` when
380
+ * degraded (with a remediation hint), `ok` otherwise.
381
+ */
382
+ export async function summarizeExtractionLiveness(
383
+ config: Pick<PluginConfig, "extractionLiveness">,
384
+ storage: ExtractionLivenessStorageLike,
385
+ buffer?: ExtractionBufferSource,
386
+ nowMs: number = Date.now(),
387
+ ): Promise<OperatorDoctorCheck> {
388
+ const livenessConfig = resolveExtractionLivenessConfig(config.extractionLiveness);
389
+ const status = await gatherExtractionLivenessStatus({
390
+ config: livenessConfig,
391
+ storage,
392
+ buffer,
393
+ nowMs,
394
+ });
395
+ const scopeNote =
396
+ ` Watermark scope: ${status.watermarkScope}` +
397
+ (status.watermarkScope === "root-store"
398
+ ? " (default-namespace only; multi-namespace aggregation tracked in #2159)."
399
+ : ".");
400
+ const summary =
401
+ (status.degraded
402
+ ? `Extraction pipeline degraded: ${status.degradedReason}.`
403
+ : `Extraction pipeline healthy: last extraction ${status.lastExtractionAt ?? "never"}, ` +
404
+ `${status.bufferedSessionCount} buffered session(s), ${status.pendingTurnCount} turn(s) pending` +
405
+ `${livenessConfig.enabled ? "" : " (liveness check disabled)"}.`) + scopeNote;
406
+ return {
407
+ key: "extraction_liveness",
408
+ status: status.degraded ? "warn" : "ok",
409
+ summary,
410
+ remediation: status.degraded
411
+ ? "Extraction has stalled while turns are buffered. Inspect daemon logs for extraction " +
412
+ "timeouts or fallback-no-parsed-output errors, verify the extraction model/provider is " +
413
+ "reachable, then force a flush (e.g. `remnic flush`)."
414
+ : undefined,
415
+ details: { ...status, staleWindowMs: livenessConfig.staleWindowMs, enabled: livenessConfig.enabled },
416
+ };
417
+ }
418
+
419
+ /** Meta fields the `remnic stats` view renders directly, beyond the liveness watermark. */
420
+ type ExtractionStatsMeta = Pick<MetaState, "extractionCount" | "lastExtractionAt" | "lastConsolidationAt">;
421
+
422
+ /**
423
+ * Lines for `remnic stats`: extraction watermark, buffer backlog, and the
424
+ * liveness verdict so dashboards can alert on a stalled pipeline. The meta
425
+ * watermark is loaded HERE (not by the caller) so a meta-read failure surfaces
426
+ * as an explicit DEGRADED verdict plus "unavailable" counts (§22) instead of
427
+ * crashing the whole `stats` command.
428
+ */
429
+ export async function renderExtractionLivenessStats(
430
+ orchestrator: ExtractionLivenessOrchestratorLike & { storage: { loadMeta(): Promise<ExtractionStatsMeta> } },
431
+ nowMs: number = Date.now(),
432
+ ): Promise<string[]> {
433
+ let meta: ExtractionStatsMeta | null = null;
434
+ let metaReadFailed = false;
435
+ let metaReadError: string | undefined;
436
+ try {
437
+ meta = await orchestrator.storage.loadMeta();
438
+ } catch (err) {
439
+ metaReadFailed = true;
440
+ metaReadError = err instanceof Error ? err.message : String(err);
441
+ }
442
+ const status = evaluateExtractionLiveness({
443
+ config: resolveExtractionLivenessConfig(orchestrator.config.extractionLiveness),
444
+ lastExtractionAt: meta?.lastExtractionAt ?? null,
445
+ snapshot: await readBufferSnapshot(orchestrator.buffer),
446
+ nowMs,
447
+ metaReadFailed,
448
+ metaReadError,
449
+ });
450
+ const oldestAge =
451
+ status.oldestBufferedTurnAgeMs !== null ? formatAgeMs(status.oldestBufferedTurnAgeMs) : "n/a";
452
+ const unavailable = metaReadFailed ? "unavailable" : "never";
453
+ return [
454
+ `Extractions: ${meta?.extractionCount ?? unavailable}`,
455
+ `Last extraction: ${meta?.lastExtractionAt ?? unavailable}`,
456
+ `Last consolidation: ${meta?.lastConsolidationAt ?? unavailable}`,
457
+ `Buffered sessions: ${status.bufferedSessionCount} (${status.pendingTurnCount} turns pending)`,
458
+ `Oldest buffered turn age: ${oldestAge}`,
459
+ `Extraction watermark scope: ${status.watermarkScope}`,
460
+ `Extraction liveness: ${status.degraded ? `DEGRADED — ${status.degradedReason}` : "ok"}`,
461
+ ];
462
+ }
@@ -0,0 +1,171 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ /**
6
+ * Corpus-watermark doctor check (issue #2149).
7
+ *
8
+ * Verifies `summarizeCorpusWatermark` reports per-namespace counts + a short
9
+ * digest prefix and always resolves `ok` (this PR has no peer to compare
10
+ * against, so it never warns), and that `runOperatorDoctor` wires it in.
11
+ */
12
+ import test from "node:test";
13
+ import { parseConfig } from "./config.js";
14
+ import type { CorpusWatermark } from "./corpus-watermark.js";
15
+ import { summarizeCorpusWatermark } from "./operator-doctor-corpus.js";
16
+ import { type OperatorToolkitOrchestrator, runOperatorDoctor } from "./operator-toolkit.js";
17
+ import type { OperatorDoctorCheck } from "./operator-toolkit.js";
18
+ import { StorageManager } from "./storage.js";
19
+ import type { PluginConfig } from "./types.js";
20
+
21
+ const storageFactory = (dir: string) => new StorageManager(dir);
22
+
23
+ // The doctor stores the watermark array under `details.corpus`; `details` is
24
+ // typed `unknown`, so narrow it once here rather than at each read.
25
+ function corpusOf(check: OperatorDoctorCheck | undefined): CorpusWatermark[] {
26
+ const details = check?.details;
27
+ if (!details || typeof details !== "object" || !("corpus" in details)) return [];
28
+ // `details.corpus` is `unknown` after the `in` guard; the doctor always
29
+ // stores the watermark array here.
30
+ const corpus = details.corpus as CorpusWatermark[];
31
+ return corpus;
32
+ }
33
+
34
+ async function writeMemory(memoryDir: string, rel: string): Promise<void> {
35
+ const full = path.join(memoryDir, rel);
36
+ await mkdir(path.dirname(full), { recursive: true });
37
+ await writeFile(full, `---\nid: ${path.basename(rel, ".md")}\n---\n\nbody\n`, "utf-8");
38
+ }
39
+
40
+ async function makeFixture(): Promise<{
41
+ root: string;
42
+ memoryDir: string;
43
+ config: PluginConfig;
44
+ configPath: string;
45
+ orchestrator: OperatorToolkitOrchestrator;
46
+ }> {
47
+ const root = await mkdtemp(path.join(os.tmpdir(), "engram-corpus-doctor-"));
48
+ const memoryDir = path.join(root, "memory");
49
+ const workspaceDir = path.join(root, "workspace");
50
+ await mkdir(memoryDir, { recursive: true });
51
+ await mkdir(workspaceDir, { recursive: true });
52
+ const rawConfig = {
53
+ openaiApiKey: "sk-test",
54
+ memoryDir,
55
+ workspaceDir,
56
+ qmdEnabled: false,
57
+ transcriptEnabled: false,
58
+ hourlySummariesEnabled: false,
59
+ identityEnabled: false,
60
+ identityContinuityEnabled: false,
61
+ sharedContextEnabled: false,
62
+ captureMode: "implicit",
63
+ namespacesEnabled: false,
64
+ defaultNamespace: "global",
65
+ };
66
+ const config = parseConfig(rawConfig);
67
+ const configPath = path.join(root, "openclaw.json");
68
+ await writeFile(
69
+ configPath,
70
+ JSON.stringify({ plugins: { entries: { "openclaw-remnic": { config: rawConfig } } } }, null, 2),
71
+ "utf-8"
72
+ );
73
+ const orchestrator: OperatorToolkitOrchestrator = {
74
+ config,
75
+ storage: new StorageManager(memoryDir),
76
+ qmd: {
77
+ async probe() {
78
+ return false;
79
+ },
80
+ isAvailable() {
81
+ return false;
82
+ },
83
+ async ensureCollection() {
84
+ return "skipped";
85
+ },
86
+ debugStatus() {
87
+ return "disabled";
88
+ },
89
+ },
90
+ conversationIndexCoordinator: {
91
+ async getHealth() {
92
+ return {
93
+ enabled: false,
94
+ backend: "qmd" as const,
95
+ status: "disabled" as const,
96
+ chunkDocCount: 0,
97
+ lastUpdateAt: null,
98
+ };
99
+ },
100
+ async rebuild() {
101
+ return { chunks: 0, skipped: true, reason: "disabled", embedded: false, rebuilt: false };
102
+ },
103
+ },
104
+ };
105
+ return { root, memoryDir, config, configPath, orchestrator };
106
+ }
107
+
108
+ test("summarizeCorpusWatermark: reports an ok check with per-namespace count and a short digest prefix", async () => {
109
+ const { root, memoryDir, config } = await makeFixture();
110
+ try {
111
+ await writeMemory(memoryDir, "facts/2026-03-08/a.md");
112
+ await writeMemory(memoryDir, "facts/2026-03-08/b.md");
113
+ await writeMemory(memoryDir, "procedures/2026-03-09/c.md");
114
+
115
+ const check = await summarizeCorpusWatermark(config, storageFactory);
116
+ assert.equal(check.key, "corpus_watermark");
117
+ assert.equal(check.status, "ok");
118
+ const corpus = corpusOf(check);
119
+ assert.equal(corpus.length, 1);
120
+ assert.equal(corpus[0]?.namespace, "global");
121
+ assert.equal(corpus[0]?.memoryFileCount, 3);
122
+ assert.match(check.summary, /global: 3 files/);
123
+ assert.match(check.summary, /digest=[0-9a-f]{12}/);
124
+ } finally {
125
+ await rm(root, { recursive: true, force: true });
126
+ }
127
+ });
128
+
129
+ test("summarizeCorpusWatermark: an empty corpus still resolves ok with a zero count", async () => {
130
+ const { root, config } = await makeFixture();
131
+ try {
132
+ const check = await summarizeCorpusWatermark(config, storageFactory);
133
+ assert.equal(check.status, "ok");
134
+ const corpus = corpusOf(check);
135
+ assert.equal(corpus.length, 1);
136
+ assert.equal(corpus[0]?.memoryFileCount, 0);
137
+ } finally {
138
+ await rm(root, { recursive: true, force: true });
139
+ }
140
+ });
141
+
142
+ test("runOperatorDoctor: includes the corpus_watermark check", async () => {
143
+ const { root, memoryDir, configPath, orchestrator } = await makeFixture();
144
+ try {
145
+ await writeMemory(memoryDir, "facts/2026-03-08/a.md");
146
+ const report = await runOperatorDoctor({ configPath, orchestrator });
147
+ const check = report.checks.find((c) => c.key === "corpus_watermark");
148
+ assert.ok(check, "expected a corpus_watermark check");
149
+ assert.equal(check?.status, "ok");
150
+ assert.equal(corpusOf(check)[0]?.memoryFileCount, 1);
151
+ } finally {
152
+ await rm(root, { recursive: true, force: true });
153
+ }
154
+ });
155
+
156
+ test("summarizeCorpusWatermark: warns (not ok) when a namespace scan fails", async () => {
157
+ const { root, config } = await makeFixture();
158
+ try {
159
+ // A storage factory that fails every scan (e.g. an EACCES permission
160
+ // regression). The namespace is omitted, so the check must WARN — not
161
+ // certify ok, and not conflate the failure with an empty deployment.
162
+ const throwingFactory = (_dir: string): never => {
163
+ throw new Error("simulated backend read failure");
164
+ };
165
+ const check = await summarizeCorpusWatermark(config, throwingFactory);
166
+ assert.equal(check.status, "warn", "a scan failure must not be reported as ok");
167
+ assert.match(check.summary, /unavailable|unreadable|churning/i);
168
+ } finally {
169
+ await rm(root, { recursive: true, force: true });
170
+ }
171
+ });