@remnic/core 10.0.186 → 10.0.188

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 (292) hide show
  1. package/dist/access-admin-ops-surface.js +105 -104
  2. package/dist/access-audit.js +2 -2
  3. package/dist/access-cli.js +105 -104
  4. package/dist/access-cli.js.map +1 -1
  5. package/dist/access-coding-context-resolution.js +6 -6
  6. package/dist/access-extraction-force-flush-preempt.js +105 -104
  7. package/dist/access-extraction-force-flush.js +105 -104
  8. package/dist/access-http-briefing.js +105 -104
  9. package/dist/access-http-query.js +105 -104
  10. package/dist/access-http.js +105 -104
  11. package/dist/access-identity-continuity-surface.js +105 -104
  12. package/dist/access-lcm-surface.js +105 -104
  13. package/dist/access-mcp.js +105 -104
  14. package/dist/access-observe-write-category.js +6 -6
  15. package/dist/access-observe-write-surface.js +105 -104
  16. package/dist/access-offline-manifest.js +5 -5
  17. package/dist/access-operations-batch.js +105 -104
  18. package/dist/access-operations.js +105 -104
  19. package/dist/access-recall-concurrency.js +105 -104
  20. package/dist/access-recall-response.js +105 -104
  21. package/dist/access-recall-surface.js +105 -104
  22. package/dist/access-schema.js +5 -5
  23. package/dist/access-service.js +105 -104
  24. package/dist/active-recall.js +10 -10
  25. package/dist/adapters/index.js +4 -4
  26. package/dist/adapters/registry.js +2 -2
  27. package/dist/{auto-sync-OOEY2FSA.js → auto-sync-BJUAGKI5.js} +4 -4
  28. package/dist/briefing.js +7 -7
  29. package/dist/buffer-add-turns-bounded.js +2 -2
  30. package/dist/buffer-admission-idempotency.d.ts.map +1 -1
  31. package/dist/buffer-admission-idempotency.js +1 -1
  32. package/dist/buffer-persistence.d.ts +14 -0
  33. package/dist/buffer-persistence.d.ts.map +1 -1
  34. package/dist/buffer-persistence.js +3 -1
  35. package/dist/buffer.js +9 -8
  36. package/dist/calibration.js +4 -4
  37. package/dist/causal-consolidation.js +8 -8
  38. package/dist/{chunk-XYZR3NBU.js → chunk-2I3ETW3G.js} +2 -2
  39. package/dist/{chunk-5RWIZISF.js → chunk-2VNMSEZR.js} +3 -3
  40. package/dist/{chunk-4TPU36X4.js → chunk-4N33L4HY.js} +2 -2
  41. package/dist/{chunk-BFPF5N3H.js → chunk-4RASUAN3.js} +4 -4
  42. package/dist/{chunk-N2PXVLV3.js → chunk-56BNHKZM.js} +7 -7
  43. package/dist/{chunk-R3UQIS3F.js → chunk-5AFBFAFX.js} +4 -4
  44. package/dist/{chunk-3FEQNKMB.js → chunk-5WDUY2ZZ.js} +2 -2
  45. package/dist/{chunk-5ITPOAKW.js → chunk-65DWWJKI.js} +2 -2
  46. package/dist/{chunk-O5ZCDK32.js → chunk-6AMFGXG2.js} +39 -11
  47. package/dist/chunk-6AMFGXG2.js.map +1 -0
  48. package/dist/{chunk-L4TYD52M.js → chunk-6MDHK6NO.js} +2 -2
  49. package/dist/{chunk-FYHFM64A.js → chunk-6OHCNTKU.js} +2 -2
  50. package/dist/{chunk-PY5XP7GR.js → chunk-6TIQLG7I.js} +2 -2
  51. package/dist/{chunk-A3HLZMHD.js → chunk-7KTORRIK.js} +2 -2
  52. package/dist/{chunk-ENKXMLE3.js → chunk-A32EBVCZ.js} +2 -2
  53. package/dist/{chunk-H4HBQRGI.js → chunk-ATPY63F5.js} +2 -2
  54. package/dist/{chunk-2LXROA34.js → chunk-AXSQGJSG.js} +2 -2
  55. package/dist/chunk-B256MMS7.js +205 -0
  56. package/dist/chunk-B256MMS7.js.map +1 -0
  57. package/dist/{chunk-VUC3DLQ5.js → chunk-C6Y2YHJL.js} +2 -2
  58. package/dist/{chunk-FBNR3JI5.js → chunk-CIAQK2OU.js} +7 -2
  59. package/dist/{chunk-FBNR3JI5.js.map → chunk-CIAQK2OU.js.map} +1 -1
  60. package/dist/{chunk-FDXLO6CX.js → chunk-CRS2NY44.js} +2 -2
  61. package/dist/{chunk-AJVCM2E3.js → chunk-CYX7JI4O.js} +2 -2
  62. package/dist/{chunk-JK5YFQQT.js → chunk-D3FP4JQI.js} +2 -2
  63. package/dist/{chunk-ZNHLUYIT.js → chunk-D7HOJFDS.js} +4 -4
  64. package/dist/{chunk-ZX5N5D6M.js → chunk-DAOMWGO2.js} +4 -4
  65. package/dist/{chunk-VN3RYYMS.js → chunk-DR4TYD56.js} +2 -2
  66. package/dist/{chunk-7DFJ4JX2.js → chunk-DTTDMK7Q.js} +7 -7
  67. package/dist/{chunk-YNDLCWXS.js → chunk-EZ25VE3G.js} +4 -4
  68. package/dist/{chunk-QJBULLKG.js → chunk-F2MVWUNF.js} +2 -2
  69. package/dist/{chunk-TQXKUQFX.js → chunk-FZU62GIV.js} +7 -6
  70. package/dist/chunk-FZU62GIV.js.map +1 -0
  71. package/dist/{chunk-BAMF6J4W.js → chunk-GCHM5BYL.js} +4 -4
  72. package/dist/{chunk-6SROXED4.js → chunk-GRX5BE73.js} +2 -2
  73. package/dist/{chunk-TKWIUL3D.js → chunk-H442UKDV.js} +8 -8
  74. package/dist/{chunk-VFJ3PBZI.js → chunk-HL53XYHC.js} +4 -4
  75. package/dist/{chunk-CKTKATXL.js → chunk-IMSLPQJB.js} +20 -16
  76. package/dist/chunk-IMSLPQJB.js.map +1 -0
  77. package/dist/{chunk-63FIQIER.js → chunk-JJ42IDJU.js} +2 -2
  78. package/dist/{chunk-N33M4NWM.js → chunk-K3JGILZC.js} +3 -3
  79. package/dist/{chunk-CJERJ724.js → chunk-K6BS5RB4.js} +2 -2
  80. package/dist/{chunk-VAQIBC2L.js → chunk-KQIOW3TG.js} +2 -2
  81. package/dist/{chunk-UMGO4LEZ.js → chunk-KVTUUU7H.js} +2 -2
  82. package/dist/{chunk-TRFSTCQK.js → chunk-LL6WEMTC.js} +34 -6
  83. package/dist/chunk-LL6WEMTC.js.map +1 -0
  84. package/dist/{chunk-LALPM2DN.js → chunk-MTKSH7HY.js} +143 -139
  85. package/dist/chunk-MTKSH7HY.js.map +1 -0
  86. package/dist/{chunk-IK7NPYYU.js → chunk-NFQKIZK3.js} +2 -2
  87. package/dist/{chunk-2WITFW6F.js → chunk-NKHRIDYP.js} +2 -2
  88. package/dist/{chunk-KYZMCH4I.js → chunk-NN3LMWKA.js} +12 -4
  89. package/dist/chunk-NN3LMWKA.js.map +1 -0
  90. package/dist/{chunk-RXAWE76Y.js → chunk-O6QSBI3U.js} +2 -2
  91. package/dist/{chunk-5RBHL5TF.js → chunk-OA7YDB6A.js} +2 -2
  92. package/dist/{chunk-SSKIXUR5.js → chunk-PCGBESAN.js} +2 -2
  93. package/dist/{chunk-DYZDFOBX.js → chunk-Q6S67LHR.js} +2 -2
  94. package/dist/{chunk-WCXWCAUC.js → chunk-QGT5KNQT.js} +2 -2
  95. package/dist/{chunk-KYPFQO43.js → chunk-QPD7EYGI.js} +2 -2
  96. package/dist/{chunk-4KUK3KGI.js → chunk-QXHWOUS6.js} +3 -3
  97. package/dist/{chunk-FE43YKNJ.js → chunk-RBPC4XGU.js} +31 -8
  98. package/dist/chunk-RBPC4XGU.js.map +1 -0
  99. package/dist/{chunk-CXGD3N2Y.js → chunk-RPOG6HLI.js} +2 -2
  100. package/dist/{chunk-3N7I53KR.js → chunk-RVODERA5.js} +2 -2
  101. package/dist/{chunk-G6V32Q4F.js → chunk-SFWQZBPN.js} +2 -2
  102. package/dist/{chunk-DNXQVCIC.js → chunk-SUI75NTN.js} +8 -8
  103. package/dist/{chunk-3GD5SFDT.js → chunk-T3XOP7TA.js} +5 -5
  104. package/dist/{chunk-FDLPNFKE.js → chunk-T7R42MWB.js} +2 -2
  105. package/dist/{chunk-5BESLEU7.js → chunk-TAPF7T26.js} +2 -2
  106. package/dist/chunk-TK6EBBKG.js +13 -0
  107. package/dist/chunk-TK6EBBKG.js.map +1 -0
  108. package/dist/{chunk-PZ4OA7CP.js → chunk-TQODBIMW.js} +2 -2
  109. package/dist/{chunk-PDXO4LIH.js → chunk-UWKHLWUE.js} +13 -9
  110. package/dist/chunk-UWKHLWUE.js.map +1 -0
  111. package/dist/{chunk-QJG6PEAM.js → chunk-VQQZJ6KJ.js} +3 -3
  112. package/dist/{chunk-CIC3WZVO.js → chunk-X3ERYOLO.js} +2 -2
  113. package/dist/{chunk-T4MKFTJF.js → chunk-XHDS6HIX.js} +5 -5
  114. package/dist/{chunk-J7BAJ6BF.js → chunk-XQF2KLV5.js} +2 -2
  115. package/dist/{chunk-U7VEZ2XS.js → chunk-XWPYK5T4.js} +2 -2
  116. package/dist/{chunk-L7MVHAMS.js → chunk-YVXR7CPS.js} +2 -2
  117. package/dist/{chunk-NU5JRN3A.js → chunk-ZDLVHGIC.js} +2 -2
  118. package/dist/{chunk-OJXK5C6Z.js → chunk-ZG4GNPRE.js} +7 -7
  119. package/dist/{chunk-IJKO5RVJ.js → chunk-ZNYDDZVW.js} +3 -3
  120. package/dist/cli.js +105 -104
  121. package/dist/coding/export-okf-codegraph.js +13 -13
  122. package/dist/compounding/engine.js +8 -8
  123. package/dist/config.js +10 -10
  124. package/dist/connectors/codex-materialize-runner.js +7 -7
  125. package/dist/connectors/index.js +7 -7
  126. package/dist/convergence-refresh.js +9 -9
  127. package/dist/corpus-watermark.js +9 -9
  128. package/dist/dashboard-runtime.js +2 -2
  129. package/dist/deep-recall-http-glue.js +6 -6
  130. package/dist/deep-recall.js +2 -2
  131. package/dist/entity-retrieval.js +7 -7
  132. package/dist/explicit-capture.js +105 -104
  133. package/dist/extraction-entities-source.d.ts +11 -0
  134. package/dist/extraction-entities-source.d.ts.map +1 -0
  135. package/dist/extraction-entities-source.js +8 -0
  136. package/dist/extraction-entities-source.js.map +1 -0
  137. package/dist/extraction-judge.js +2 -2
  138. package/dist/extraction-normalization.js +2 -2
  139. package/dist/extraction-prompt.d.ts +19 -2
  140. package/dist/extraction-prompt.d.ts.map +1 -1
  141. package/dist/extraction-prompt.js +5 -1
  142. package/dist/extraction.d.ts +2 -1
  143. package/dist/extraction.d.ts.map +1 -1
  144. package/dist/extraction.js +18 -17
  145. package/dist/{first-start-migration-TCPK2I7J.js → first-start-migration-CCZ5SM3V.js} +4 -4
  146. package/dist/harmonic-retrieval.js +7 -7
  147. package/dist/index.js +125 -124
  148. package/dist/lcm/engine.js +3 -3
  149. package/dist/lcm/index.js +8 -8
  150. package/dist/local-llm-helpers.d.ts.map +1 -1
  151. package/dist/local-llm-helpers.js +2 -2
  152. package/dist/local-llm-transport.d.ts +82 -9
  153. package/dist/local-llm-transport.d.ts.map +1 -1
  154. package/dist/local-llm-transport.js +11 -3
  155. package/dist/local-llm.d.ts.map +1 -1
  156. package/dist/local-llm.js +3 -3
  157. package/dist/location/index.js +8 -8
  158. package/dist/maintenance/memory-governance.js +7 -7
  159. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +7 -7
  160. package/dist/maintenance/rebuild-memory-projection-runner.js +9 -9
  161. package/dist/maintenance/rebuild-memory-projection.js +8 -8
  162. package/dist/memory-browse.js +5 -5
  163. package/dist/namespaces/migrate.js +8 -8
  164. package/dist/namespaces/search.js +4 -4
  165. package/dist/namespaces/storage.js +7 -7
  166. package/dist/offline-sync-changeset-generations.js +3 -3
  167. package/dist/offline-sync-embedding-generation.js +2 -2
  168. package/dist/offline-sync-snapshot-stream.js +5 -5
  169. package/dist/offline-sync.js +6 -6
  170. package/dist/operator-doctor-corpus.js +10 -10
  171. package/dist/operator-toolkit.js +17 -17
  172. package/dist/orchestration/backlog-scheduler.js +106 -105
  173. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  174. package/dist/orchestration/buffer-drain-runner.js +106 -105
  175. package/dist/orchestration/extraction-queue-coordinator.d.ts.map +1 -1
  176. package/dist/orchestration/extraction-run-helpers.d.ts +2 -1
  177. package/dist/orchestration/extraction-run-helpers.d.ts.map +1 -1
  178. package/dist/orchestration/extraction-run.d.ts.map +1 -1
  179. package/dist/orchestration/maintenance.js +18 -18
  180. package/dist/orchestrator.js +107 -106
  181. package/dist/qmd.js +2 -2
  182. package/dist/recall-navigation.js +105 -104
  183. package/dist/recall-state-view-admission.js +5 -5
  184. package/dist/recall-why-service.js +5 -5
  185. package/dist/resume-bundles.js +13 -13
  186. package/dist/search/factory.js +3 -3
  187. package/dist/search/index.js +3 -3
  188. package/dist/semantic-consolidation.js +8 -8
  189. package/dist/semantic-rule-promotion.js +7 -7
  190. package/dist/semantic-rule-verifier.js +7 -7
  191. package/dist/source-agent-qualifier.js +11 -10
  192. package/dist/standup/build.js +7 -7
  193. package/dist/storage/entity-canonical-id-migration-runner.d.ts.map +1 -1
  194. package/dist/storage.js +6 -6
  195. package/dist/summarizer.js +4 -4
  196. package/dist/support-passport/index.js +4 -4
  197. package/dist/transcript.js +2 -2
  198. package/dist/transfer/export-okf.js +7 -7
  199. package/dist/verified-recall.js +7 -7
  200. package/dist/who-knows-cli.js +8 -8
  201. package/dist/who-knows.js +7 -7
  202. package/package.json +2 -2
  203. package/src/buffer-admission-idempotency.test.ts +115 -0
  204. package/src/buffer-admission-idempotency.ts +67 -11
  205. package/src/buffer-persistence.ts +46 -5
  206. package/src/extraction-carry-forward.test.ts +147 -0
  207. package/src/extraction-entities-source.ts +19 -0
  208. package/src/extraction-prompt.ts +60 -9
  209. package/src/extraction.ts +11 -8
  210. package/src/local-llm-headers-timeout.test.ts +246 -16
  211. package/src/local-llm-helpers.ts +14 -4
  212. package/src/local-llm-transport.ts +253 -16
  213. package/src/local-llm.ts +7 -8
  214. package/src/orchestration/extraction-queue-coordinator.ts +7 -1
  215. package/src/orchestration/extraction-queue-lane-bias.test.ts +35 -0
  216. package/src/orchestration/extraction-run-helpers.ts +11 -4
  217. package/src/orchestration/extraction-run.test.ts +23 -12
  218. package/src/orchestration/extraction-run.ts +6 -5
  219. package/src/storage/entity-canonical-id-migration-runner.test.ts +90 -0
  220. package/src/storage/entity-canonical-id-migration-runner.ts +10 -0
  221. package/dist/chunk-5YQXWVCP.js +0 -74
  222. package/dist/chunk-5YQXWVCP.js.map +0 -1
  223. package/dist/chunk-CKTKATXL.js.map +0 -1
  224. package/dist/chunk-FE43YKNJ.js.map +0 -1
  225. package/dist/chunk-KYZMCH4I.js.map +0 -1
  226. package/dist/chunk-LALPM2DN.js.map +0 -1
  227. package/dist/chunk-O5ZCDK32.js.map +0 -1
  228. package/dist/chunk-PDXO4LIH.js.map +0 -1
  229. package/dist/chunk-TQXKUQFX.js.map +0 -1
  230. package/dist/chunk-TRFSTCQK.js.map +0 -1
  231. /package/dist/{auto-sync-OOEY2FSA.js.map → auto-sync-BJUAGKI5.js.map} +0 -0
  232. /package/dist/{chunk-XYZR3NBU.js.map → chunk-2I3ETW3G.js.map} +0 -0
  233. /package/dist/{chunk-5RWIZISF.js.map → chunk-2VNMSEZR.js.map} +0 -0
  234. /package/dist/{chunk-4TPU36X4.js.map → chunk-4N33L4HY.js.map} +0 -0
  235. /package/dist/{chunk-BFPF5N3H.js.map → chunk-4RASUAN3.js.map} +0 -0
  236. /package/dist/{chunk-N2PXVLV3.js.map → chunk-56BNHKZM.js.map} +0 -0
  237. /package/dist/{chunk-R3UQIS3F.js.map → chunk-5AFBFAFX.js.map} +0 -0
  238. /package/dist/{chunk-3FEQNKMB.js.map → chunk-5WDUY2ZZ.js.map} +0 -0
  239. /package/dist/{chunk-5ITPOAKW.js.map → chunk-65DWWJKI.js.map} +0 -0
  240. /package/dist/{chunk-L4TYD52M.js.map → chunk-6MDHK6NO.js.map} +0 -0
  241. /package/dist/{chunk-FYHFM64A.js.map → chunk-6OHCNTKU.js.map} +0 -0
  242. /package/dist/{chunk-PY5XP7GR.js.map → chunk-6TIQLG7I.js.map} +0 -0
  243. /package/dist/{chunk-A3HLZMHD.js.map → chunk-7KTORRIK.js.map} +0 -0
  244. /package/dist/{chunk-ENKXMLE3.js.map → chunk-A32EBVCZ.js.map} +0 -0
  245. /package/dist/{chunk-H4HBQRGI.js.map → chunk-ATPY63F5.js.map} +0 -0
  246. /package/dist/{chunk-2LXROA34.js.map → chunk-AXSQGJSG.js.map} +0 -0
  247. /package/dist/{chunk-VUC3DLQ5.js.map → chunk-C6Y2YHJL.js.map} +0 -0
  248. /package/dist/{chunk-FDXLO6CX.js.map → chunk-CRS2NY44.js.map} +0 -0
  249. /package/dist/{chunk-AJVCM2E3.js.map → chunk-CYX7JI4O.js.map} +0 -0
  250. /package/dist/{chunk-JK5YFQQT.js.map → chunk-D3FP4JQI.js.map} +0 -0
  251. /package/dist/{chunk-ZNHLUYIT.js.map → chunk-D7HOJFDS.js.map} +0 -0
  252. /package/dist/{chunk-ZX5N5D6M.js.map → chunk-DAOMWGO2.js.map} +0 -0
  253. /package/dist/{chunk-VN3RYYMS.js.map → chunk-DR4TYD56.js.map} +0 -0
  254. /package/dist/{chunk-7DFJ4JX2.js.map → chunk-DTTDMK7Q.js.map} +0 -0
  255. /package/dist/{chunk-YNDLCWXS.js.map → chunk-EZ25VE3G.js.map} +0 -0
  256. /package/dist/{chunk-QJBULLKG.js.map → chunk-F2MVWUNF.js.map} +0 -0
  257. /package/dist/{chunk-BAMF6J4W.js.map → chunk-GCHM5BYL.js.map} +0 -0
  258. /package/dist/{chunk-6SROXED4.js.map → chunk-GRX5BE73.js.map} +0 -0
  259. /package/dist/{chunk-TKWIUL3D.js.map → chunk-H442UKDV.js.map} +0 -0
  260. /package/dist/{chunk-VFJ3PBZI.js.map → chunk-HL53XYHC.js.map} +0 -0
  261. /package/dist/{chunk-63FIQIER.js.map → chunk-JJ42IDJU.js.map} +0 -0
  262. /package/dist/{chunk-N33M4NWM.js.map → chunk-K3JGILZC.js.map} +0 -0
  263. /package/dist/{chunk-CJERJ724.js.map → chunk-K6BS5RB4.js.map} +0 -0
  264. /package/dist/{chunk-VAQIBC2L.js.map → chunk-KQIOW3TG.js.map} +0 -0
  265. /package/dist/{chunk-UMGO4LEZ.js.map → chunk-KVTUUU7H.js.map} +0 -0
  266. /package/dist/{chunk-IK7NPYYU.js.map → chunk-NFQKIZK3.js.map} +0 -0
  267. /package/dist/{chunk-2WITFW6F.js.map → chunk-NKHRIDYP.js.map} +0 -0
  268. /package/dist/{chunk-RXAWE76Y.js.map → chunk-O6QSBI3U.js.map} +0 -0
  269. /package/dist/{chunk-5RBHL5TF.js.map → chunk-OA7YDB6A.js.map} +0 -0
  270. /package/dist/{chunk-SSKIXUR5.js.map → chunk-PCGBESAN.js.map} +0 -0
  271. /package/dist/{chunk-DYZDFOBX.js.map → chunk-Q6S67LHR.js.map} +0 -0
  272. /package/dist/{chunk-WCXWCAUC.js.map → chunk-QGT5KNQT.js.map} +0 -0
  273. /package/dist/{chunk-KYPFQO43.js.map → chunk-QPD7EYGI.js.map} +0 -0
  274. /package/dist/{chunk-4KUK3KGI.js.map → chunk-QXHWOUS6.js.map} +0 -0
  275. /package/dist/{chunk-CXGD3N2Y.js.map → chunk-RPOG6HLI.js.map} +0 -0
  276. /package/dist/{chunk-3N7I53KR.js.map → chunk-RVODERA5.js.map} +0 -0
  277. /package/dist/{chunk-G6V32Q4F.js.map → chunk-SFWQZBPN.js.map} +0 -0
  278. /package/dist/{chunk-DNXQVCIC.js.map → chunk-SUI75NTN.js.map} +0 -0
  279. /package/dist/{chunk-3GD5SFDT.js.map → chunk-T3XOP7TA.js.map} +0 -0
  280. /package/dist/{chunk-FDLPNFKE.js.map → chunk-T7R42MWB.js.map} +0 -0
  281. /package/dist/{chunk-5BESLEU7.js.map → chunk-TAPF7T26.js.map} +0 -0
  282. /package/dist/{chunk-PZ4OA7CP.js.map → chunk-TQODBIMW.js.map} +0 -0
  283. /package/dist/{chunk-QJG6PEAM.js.map → chunk-VQQZJ6KJ.js.map} +0 -0
  284. /package/dist/{chunk-CIC3WZVO.js.map → chunk-X3ERYOLO.js.map} +0 -0
  285. /package/dist/{chunk-T4MKFTJF.js.map → chunk-XHDS6HIX.js.map} +0 -0
  286. /package/dist/{chunk-J7BAJ6BF.js.map → chunk-XQF2KLV5.js.map} +0 -0
  287. /package/dist/{chunk-U7VEZ2XS.js.map → chunk-XWPYK5T4.js.map} +0 -0
  288. /package/dist/{chunk-L7MVHAMS.js.map → chunk-YVXR7CPS.js.map} +0 -0
  289. /package/dist/{chunk-NU5JRN3A.js.map → chunk-ZDLVHGIC.js.map} +0 -0
  290. /package/dist/{chunk-OJXK5C6Z.js.map → chunk-ZG4GNPRE.js.map} +0 -0
  291. /package/dist/{chunk-IJKO5RVJ.js.map → chunk-ZNYDDZVW.js.map} +0 -0
  292. /package/dist/{first-start-migration-TCPK2I7J.js.map → first-start-migration-CCZ5SM3V.js.map} +0 -0
@@ -3,7 +3,6 @@ export interface BufferAdmissionIdempotencyState {
3
3
  admissionIdempotency?: Record<string, number>;
4
4
  admissionIdempotencyOrder?: string[];
5
5
  }
6
-
7
6
  /**
8
7
  * FIFO bound on recorded observe-buffer admission keys per session buffer.
9
8
  * 4096 retains the most recent keys per session — roughly two
@@ -41,18 +40,64 @@ export function ensureAdmissionIdempotencyMap(state: BufferAdmissionIdempotencyS
41
40
  return map;
42
41
  }
43
42
 
44
- export function ensureAdmissionIdempotencyOrder(state: BufferAdmissionIdempotencyState): string[] {
45
- if (!state.admissionIdempotencyOrder) {
46
- state.admissionIdempotencyOrder = [];
47
- }
48
- const order = state.admissionIdempotencyOrder;
49
- const map = state.admissionIdempotency;
43
+ /**
44
+ * Derived membership index for {@link ensureAdmissionIdempotencyOrder}'s array,
45
+ * keyed on the state object (never persisted — the on-disk format stays
46
+ * {keys, order}). Mirrors the order array and the map's key count, so the
47
+ * healthy path is O(1): the old code ran an `order.includes` scan over every
48
+ * map key on EVERY observe — O(n²) once the ring widened to 4096 keys
49
+ * (COS-825 CPU profile: 6.1% self time in this reconcile alone).
50
+ *
51
+ * The map and order can legitimately diverge only on restore (an order array
52
+ * that predates some map keys), so reconciliation runs when the cached map
53
+ * size and the order length disagree — the prescribed heuristic. A
54
+ * same-length but different-membership order (hand corruption) is tolerated
55
+ * until the next membership change, matching the prescription; the map, not
56
+ * the order, stays authoritative for dedup questions.
57
+ */
58
+ const admissionIdempotencyOrderIndex = new WeakMap<
59
+ BufferAdmissionIdempotencyState,
60
+ { set: Set<string>; mapSize: number }
61
+ >();
62
+
63
+ function reconcileAdmissionIdempotencyIndex(
64
+ state: BufferAdmissionIdempotencyState,
65
+ order: string[],
66
+ map: Record<string, number> | undefined,
67
+ ) {
68
+ const set = new Set(order);
69
+ let mapSize = 0;
50
70
  if (map) {
51
71
  for (const key of Object.keys(map)) {
52
- if (Object.hasOwn(map, key) && !order.includes(key)) order.push(key);
72
+ if (!Object.hasOwn(map, key)) continue;
73
+ mapSize++;
74
+ if (!set.has(key)) {
75
+ order.push(key);
76
+ set.add(key);
77
+ }
53
78
  }
54
79
  }
55
- return order;
80
+ const entry = { set, mapSize };
81
+ admissionIdempotencyOrderIndex.set(state, entry);
82
+ return entry;
83
+ }
84
+
85
+ function admissionIdempotencyIndexFor(
86
+ state: BufferAdmissionIdempotencyState,
87
+ order: string[],
88
+ map: Record<string, number> | undefined,
89
+ ) {
90
+ const entry = admissionIdempotencyOrderIndex.get(state);
91
+ if (entry && entry.mapSize === order.length) return entry;
92
+ return reconcileAdmissionIdempotencyIndex(state, order, map);
93
+ }
94
+
95
+ export function ensureAdmissionIdempotencyOrder(state: BufferAdmissionIdempotencyState): string[] {
96
+ if (!state.admissionIdempotencyOrder) {
97
+ state.admissionIdempotencyOrder = [];
98
+ }
99
+ admissionIdempotencyIndexFor(state, state.admissionIdempotencyOrder, state.admissionIdempotency);
100
+ return state.admissionIdempotencyOrder;
56
101
  }
57
102
 
58
103
  export function hasBufferedAdmissionIdempotencyKey(state: BufferAdmissionIdempotencyState, key: string): boolean {
@@ -67,10 +112,21 @@ export function recordBufferedAdmissionIdempotencyKey(state: BufferAdmissionIdem
67
112
  if (!trimmed || turnCount <= 0) return;
68
113
  const map = ensureAdmissionIdempotencyMap(state);
69
114
  const order = ensureAdmissionIdempotencyOrder(state);
115
+ const { set, mapSize } = admissionIdempotencyIndexFor(state, order, map);
116
+ const wasMapKey = Object.hasOwn(map, trimmed);
70
117
  map[trimmed] = turnCount;
71
- if (!order.includes(trimmed)) order.push(trimmed);
118
+ if (!set.has(trimmed)) {
119
+ order.push(trimmed);
120
+ set.add(trimmed);
121
+ }
122
+ const index = admissionIdempotencyOrderIndex.get(state)!;
123
+ index.mapSize = mapSize + (wasMapKey ? 0 : 1);
72
124
  while (order.length > BUFFER_ADMISSION_IDEMPOTENCY_CAP) {
73
125
  const evicted = order.shift();
74
- if (evicted !== undefined) delete map[evicted];
126
+ if (evicted !== undefined) {
127
+ set.delete(evicted);
128
+ delete map[evicted];
129
+ index.mapSize--;
130
+ }
75
131
  }
76
132
  }
@@ -52,6 +52,16 @@ export const BUFFER_SESSION_DEFER_MIN_BYTES = 8 * 1024 * 1024;
52
52
  /** A session past the size floor is rewritten at most once per this interval. */
53
53
  export const BUFFER_SESSION_DEFER_INTERVAL_MS = 60_000;
54
54
 
55
+ /**
56
+ * The admission-idempotency metadata file is rewritten at most once per this
57
+ * interval on steady-state passes (COS-825: it is ~1.16 MB and every observe
58
+ * marks it dirty, so under fleet load it was re-serialized ~4x/s). The keys
59
+ * stay in memory until the coalesced write lands; the pass arms
60
+ * deferredRetryDelayMs so the tail write happens even if observes stop, and
61
+ * durability barriers (allowDeferral omitted/false) always write immediately.
62
+ */
63
+ export const ADMISSION_IDEMPOTENCY_PERSIST_INTERVAL_MS = 1_000;
64
+
55
65
  export interface BufferPersistOptions {
56
66
  /** Injectable clock (monotonic ms) for tests. */
57
67
  now?: () => number;
@@ -92,20 +102,26 @@ export interface BufferSessionPersistenceOptions {
92
102
  now?: () => number;
93
103
  /** Test seam: override BUFFER_SESSION_DEFER_INTERVAL_MS. */
94
104
  deferIntervalMs?: number;
105
+ /** Test seam: override ADMISSION_IDEMPOTENCY_PERSIST_INTERVAL_MS. */
106
+ admissionPersistIntervalMs?: number;
95
107
  }
96
108
 
97
109
  export class BufferSessionPersistence {
98
110
  private readonly dirty = new Set<string>();
99
111
  private readonly deleted = new Set<string>();
100
112
  private admissionIdempotencyDirty = false;
113
+ /** Last successful admission-idempotency write (rate-limit bookkeeping, COS-825). */
114
+ private lastAdmissionPersistAt?: number;
101
115
  /** Last successful session-file write per key (deferral bookkeeping, #3389). */
102
116
  private readonly lastPersistedAt = new Map<string, number>();
103
117
  private readonly clock: () => number;
104
118
  private readonly deferIntervalMs: number;
119
+ private readonly admissionPersistIntervalMs: number;
105
120
 
106
121
  constructor(options: BufferSessionPersistenceOptions = {}) {
107
122
  this.clock = options.now ?? (() => performance.now());
108
123
  this.deferIntervalMs = options.deferIntervalMs ?? BUFFER_SESSION_DEFER_INTERVAL_MS;
124
+ this.admissionPersistIntervalMs = options.admissionPersistIntervalMs ?? ADMISSION_IDEMPOTENCY_PERSIST_INTERVAL_MS;
109
125
  }
110
126
 
111
127
  markDirty(key: string): void {
@@ -156,13 +172,22 @@ export class BufferSessionPersistence {
156
172
  const deleteSession = storage.deleteBufferSession?.bind(storage);
157
173
  if (!saveSession || !deleteSession) {
158
174
  await storage.saveBuffer(state);
175
+ let admissionDeferredMs: number | undefined;
159
176
  if (this.admissionIdempotencyDirty && storage.saveBufferAdmissionIdempotency) {
160
- await storage.saveBufferAdmissionIdempotency(state);
177
+ const nowMs = (opts?.now ?? this.clock)();
178
+ const since = this.lastAdmissionPersistAt === undefined ? Infinity : nowMs - this.lastAdmissionPersistAt;
179
+ if (opts?.allowDeferral === true && since < this.admissionPersistIntervalMs) {
180
+ admissionDeferredMs = this.admissionPersistIntervalMs - since;
181
+ } else {
182
+ await storage.saveBufferAdmissionIdempotency(state);
183
+ this.admissionIdempotencyDirty = false;
184
+ this.lastAdmissionPersistAt = nowMs;
185
+ }
161
186
  }
162
187
  this.dirty.clear();
163
188
  this.deleted.clear();
164
- this.admissionIdempotencyDirty = false;
165
- return { handedOver: [], drainedTurns, deferred: [] };
189
+ if (admissionDeferredMs === undefined) this.admissionIdempotencyDirty = false;
190
+ return { handedOver: [], drainedTurns, deferred: [], deferredRetryDelayMs: admissionDeferredMs };
166
191
  }
167
192
  const now = opts?.now ?? this.clock;
168
193
  const handedOver: string[] = [];
@@ -218,14 +243,30 @@ export class BufferSessionPersistence {
218
243
  // #3368: never persist admission keys while session bodies are still deferred —
219
244
  // a crash after the key lands but before the deferred rewrite would make a
220
245
  // same-key retry swallow the unwritten turns.
246
+ let admissionDeferredMs: number | undefined;
221
247
  if (this.admissionIdempotencyDirty && deferred.length === 0 && storage.saveBufferAdmissionIdempotency) {
222
- await storage.saveBufferAdmissionIdempotency(state);
223
- this.admissionIdempotencyDirty = false;
248
+ // COS-825: steady-state passes coalesce this ~1.16 MB rewrite to at most
249
+ // one per interval; the tail write arms deferredRetryDelayMs so it lands
250
+ // even if observes stop. Barriers (allowDeferral omitted) always write.
251
+ const since = this.lastAdmissionPersistAt === undefined ? Infinity : now() - this.lastAdmissionPersistAt;
252
+ if (opts?.allowDeferral === true && since < this.admissionPersistIntervalMs) {
253
+ admissionDeferredMs = this.admissionPersistIntervalMs - since;
254
+ } else {
255
+ await storage.saveBufferAdmissionIdempotency(state);
256
+ this.admissionIdempotencyDirty = false;
257
+ this.lastAdmissionPersistAt = now();
258
+ }
224
259
  }
225
260
  const outcome: BufferPersistOutcome = { handedOver, drainedTurns, deferred };
226
261
  if (deferred.length > 0 && nextEligibleAt !== undefined) {
227
262
  outcome.deferredRetryDelayMs = Math.max(0, nextEligibleAt - now());
228
263
  }
264
+ if (admissionDeferredMs !== undefined) {
265
+ const retry = Math.max(0, admissionDeferredMs);
266
+ if (outcome.deferredRetryDelayMs === undefined || retry < outcome.deferredRetryDelayMs) {
267
+ outcome.deferredRetryDelayMs = retry;
268
+ }
269
+ }
229
270
  return outcome;
230
271
  }
231
272
  }
@@ -0,0 +1,147 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import {
5
+ buildExtractionInstructions,
6
+ KNOWN_ENTITIES_PROMPT_BUDGET_CHARS,
7
+ selectKnownEntitiesForPrompt,
8
+ } from "./extraction-prompt.js";
9
+ import { memoizeExistingEntities } from "./extraction-entities-source.js";
10
+ import { extractChunkedExtraction } from "./orchestration/extraction-run-helpers.js";
11
+ import { parseConfig } from "./config.js";
12
+ import type { BufferTurn, ExtractionResult } from "./types.js";
13
+
14
+ const emptyResult = (): ExtractionResult => ({
15
+ facts: [],
16
+ profileUpdates: [],
17
+ entities: [],
18
+ questions: [],
19
+ });
20
+
21
+ const defaultConfig = parseConfig({});
22
+ const chunkConfig = parseConfig({ extractionPromptMaxChars: 50 });
23
+
24
+ const turn = (content: string): BufferTurn => ({
25
+ content,
26
+ role: "user",
27
+ timestamp: "2026-12-01T00:00:00Z",
28
+ });
29
+
30
+ test("selectKnownEntitiesForPrompt returns short lists unchanged", () => {
31
+ const entities = ["acme-corp", "person-jane-doe"];
32
+ assert.deepEqual(selectKnownEntitiesForPrompt(entities, "nothing relevant"), entities);
33
+ });
34
+
35
+ test("selectKnownEntitiesForPrompt returns empty for no entities", () => {
36
+ assert.deepEqual(selectKnownEntitiesForPrompt([], "conversation"), []);
37
+ });
38
+
39
+ test("selectKnownEntitiesForPrompt caps oversized lists with mentioned names first", () => {
40
+ const entities = Array.from({ length: 300 }, (_, i) => `entity-${String(i).padStart(4, "0")}`);
41
+ entities[250] = "acme-corp";
42
+ const conversation = "we shipped the acme corp integration today";
43
+ const selected = selectKnownEntitiesForPrompt(entities, conversation);
44
+ assert.ok(selected.join(", ").length <= KNOWN_ENTITIES_PROMPT_BUDGET_CHARS);
45
+ assert.equal(selected[0], "acme-corp");
46
+ assert.ok(selected.length < entities.length);
47
+ });
48
+
49
+ test("rendered KNOWN ENTITIES block stays bounded on huge stores", () => {
50
+ const entities = Array.from({ length: 7000 }, (_, i) => `entity-name-${i}`);
51
+ const prompt = buildExtractionInstructions(defaultConfig, entities, false, "unrelated conversation");
52
+ assert.ok(prompt.length < 20000);
53
+ assert.match(prompt, /KNOWN ENTITIES/);
54
+ });
55
+
56
+ test("a single oversized name never empties the selection", () => {
57
+ const oversized = `x`.repeat(KNOWN_ENTITIES_PROMPT_BUDGET_CHARS * 2);
58
+ const entities = [oversized, "acme-corp", "person-jane-doe"];
59
+ const selected = selectKnownEntitiesForPrompt(entities, "we talk about acme corp a lot");
60
+ assert.ok(selected.includes("acme-corp"));
61
+ assert.ok(selected.includes("person-jane-doe"));
62
+ assert.ok(!selected.includes(oversized));
63
+ });
64
+
65
+ test("memoizeExistingEntities resolves array sources without wrapping", async () => {
66
+ const resolve = memoizeExistingEntities(["a", "b"]);
67
+ assert.deepEqual(await resolve(), ["a", "b"]);
68
+ assert.deepEqual(await resolve(), ["a", "b"]);
69
+ });
70
+
71
+ test("memoizeExistingEntities resolves thunk sources exactly once", async () => {
72
+ let calls = 0;
73
+ const source = async () => {
74
+ calls += 1;
75
+ return ["only"];
76
+ };
77
+ const resolve = memoizeExistingEntities(source);
78
+ await Promise.all([resolve(), resolve(), resolve()]);
79
+ assert.equal(calls, 1);
80
+ });
81
+
82
+ test("memoizeExistingEntities resolves undefined to an empty list", async () => {
83
+ assert.deepEqual(await memoizeExistingEntities(undefined)(), []);
84
+ });
85
+
86
+ test("chunked extraction never resolves the carry-forward on an all-local run", async () => {
87
+ let sourceCalls = 0;
88
+ const source = async () => {
89
+ sourceCalls += 1;
90
+ return ["store-entity"];
91
+ };
92
+ const seen: Array<string[] | (() => Promise<string[]>) | undefined> = [];
93
+ const engine = {
94
+ extract: async (
95
+ _turns: BufferTurn[],
96
+ entities?: string[] | (() => Promise<string[]>),
97
+ ) => {
98
+ seen.push(entities);
99
+ return emptyResult();
100
+ },
101
+ };
102
+ const turns = [turn("a".repeat(60)), turn("b".repeat(60))];
103
+ await extractChunkedExtraction(engine, chunkConfig, turns, source);
104
+ assert.equal(seen.length, 2);
105
+ for (const entities of seen) assert.ok(!Array.isArray(entities), "engine must receive the thunk, not a ready list");
106
+ assert.equal(sourceCalls, 0);
107
+ });
108
+
109
+ test("fallback chunks see names found before and after earlier fallbacks", async () => {
110
+ let sourceCalls = 0;
111
+ const source = async () => {
112
+ sourceCalls += 1;
113
+ return ["store-entity"];
114
+ };
115
+ const fallbackResolutions: string[][] = [];
116
+ let chunkIndex = 0;
117
+ const engine = {
118
+ extract: async (
119
+ _turns: BufferTurn[],
120
+ entities?: string[] | (() => Promise<string[]>),
121
+ ) => {
122
+ chunkIndex += 1;
123
+ if (chunkIndex === 1) {
124
+ const found = emptyResult();
125
+ found.entities = [{ name: "found-in-chunk-1", type: "project", facts: [] }];
126
+ return found;
127
+ }
128
+ fallbackResolutions.push([
129
+ // SAFETY: the chunked path hands every chunk the carry-forward the
130
+ // same way the engine's gateway/direct prompt paths consume it.
131
+ ...(await (entities as () => Promise<string[]>)()),
132
+ ]);
133
+ const found = emptyResult();
134
+ if (chunkIndex === 2) {
135
+ found.entities = [{ name: "found-in-chunk-2", type: "project", facts: [] }];
136
+ }
137
+ return found;
138
+ },
139
+ };
140
+ const turns = [turn("a".repeat(60)), turn("b".repeat(60)), turn("c".repeat(60))];
141
+ await extractChunkedExtraction(engine, chunkConfig, turns, source);
142
+ assert.deepEqual(fallbackResolutions, [
143
+ ["store-entity", "found-in-chunk-1"],
144
+ ["store-entity", "found-in-chunk-1", "found-in-chunk-2"],
145
+ ]);
146
+ assert.equal(sourceCalls, 1);
147
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The entity carry-forward handed to `ExtractionEngine.extract`: either a
3
+ * ready list or a thunk that lists it on demand. Only the gateway/direct
4
+ * prompt paths read it, so local-first callers pass a thunk and never pay
5
+ * the entity-store listing on the hot path. Extracted to a sibling module
6
+ * per the size-ratchet rule (issue #1995).
7
+ */
8
+ export type ExistingEntitiesSource = string[] | (() => Promise<string[]>);
9
+
10
+ /** Thunk resolving at most once; array sources resolve to themselves. */
11
+ export function memoizeExistingEntities(
12
+ source: ExistingEntitiesSource | undefined,
13
+ ): () => Promise<string[]> {
14
+ if (Array.isArray(source)) {
15
+ return () => Promise.resolve(source);
16
+ }
17
+ let resolved: Promise<string[]> | undefined;
18
+ return () => (resolved ??= source?.() ?? Promise.resolve([]));
19
+ }
@@ -110,18 +110,74 @@ Span mode (numbered-message offsets):
110
110
  - Invalid spans fall back to the frame, so keep the frame informative.`;
111
111
  }
112
112
 
113
+ /**
114
+ * Char budget for the KNOWN ENTITIES block on gateway/direct extraction
115
+ * prompts. Mature stores hold thousands of entities; the unbounded list ran
116
+ * to ~200k chars on one production store — wider than the model's context —
117
+ * so the carry-forward is capped, keeping conversation-mentioned names first.
118
+ */
119
+ export const KNOWN_ENTITIES_PROMPT_BUDGET_CHARS = 2000;
120
+
121
+ /** The rendered KNOWN ENTITIES block's fixed framing, kept in one place so
122
+ * the selector's budget reserve matches the render exactly. */
123
+ const KNOWN_ENTITIES_HEADING =
124
+ "\nKNOWN ENTITIES (use these exact names when referencing existing things):\n";
125
+ const KNOWN_ENTITIES_TRAILER =
126
+ "\n\nWhen you see something that matches a known entity, use THAT name exactly. Only create a NEW entity if nothing in this list represents it.\n";
127
+ const KNOWN_ENTITIES_FRAMING_CHARS =
128
+ KNOWN_ENTITIES_HEADING.length + KNOWN_ENTITIES_TRAILER.length;
129
+
130
+ /**
131
+ * Select the entity names worth carrying into an extraction prompt: every
132
+ * name the conversation mentions (hyphen/space/case-folded match), then the
133
+ * remaining names in store order until the char budget is spent. Names the
134
+ * conversation does not touch cannot be referenced by this extraction, so
135
+ * dropping them past the budget never loses a canonical-name hint.
136
+ */
137
+ export function selectKnownEntitiesForPrompt(
138
+ entities: readonly string[],
139
+ conversation: string,
140
+ budgetChars = KNOWN_ENTITIES_PROMPT_BUDGET_CHARS,
141
+ ): string[] {
142
+ if (entities.length === 0) return [];
143
+ if (entities.join(", ").length + KNOWN_ENTITIES_FRAMING_CHARS <= budgetChars) return [...entities];
144
+ const fold = (value: string): string => value.toLowerCase().replace(/[-_]+/g, " ");
145
+ const foldedConversation = fold(conversation);
146
+ const mentioned: string[] = [];
147
+ const rest: string[] = [];
148
+ for (const name of entities) {
149
+ (foldedConversation.includes(fold(name)) ? mentioned : rest).push(name);
150
+ }
151
+ const selected: string[] = [];
152
+ let used = 0;
153
+ for (const name of [...mentioned, ...rest]) {
154
+ const cost = (selected.length > 0 ? 2 : 0) + name.length;
155
+ // Skip a single oversized name instead of aborting the fill — smaller
156
+ // names behind it still deserve the budget.
157
+ if (cost > budgetChars - KNOWN_ENTITIES_FRAMING_CHARS) continue;
158
+ if (used + cost > budgetChars - KNOWN_ENTITIES_FRAMING_CHARS) break;
159
+ selected.push(name);
160
+ used += cost;
161
+ }
162
+ return selected;
163
+ }
164
+
113
165
  /**
114
166
  * Build extraction instructions shared between local and cloud LLM.
115
167
  *
116
168
  * `ambientCapture` marks input from an always-on recorder, which may carry
117
- * speech the user never authored (issue #2294).
169
+ * speech the user never authored (issue #2294). `conversation` ranks the
170
+ * KNOWN ENTITIES carry-forward mention-first under the char budget; callers
171
+ * that omit it keep store order under the same budget.
118
172
  */
119
173
  export function buildExtractionInstructions(
120
174
  config: PluginConfig,
121
175
  existingEntities?: string[],
122
- ambientCapture = false
176
+ ambientCapture = false,
177
+ conversation = ""
123
178
  ): string {
124
179
  const lifecycleCaps = resolveMemoryLifecycleCapabilities(config);
180
+ const knownEntities = selectKnownEntitiesForPrompt(existingEntities ?? [], conversation);
125
181
  return `You are a memory extraction system. Analyze the following conversation and extract durable, reusable memories.
126
182
 
127
183
  Memory categories:
@@ -195,13 +251,8 @@ Entity creation rules (STRICT):
195
251
  - The entity list should be SHORT — think "things that would have their own Wikipedia page" not "things mentioned in passing"
196
252
 
197
253
  ${
198
- existingEntities && existingEntities.length > 0
199
- ? `
200
- KNOWN ENTITIES (use these exact names when referencing existing things):
201
- ${existingEntities.join(", ")}
202
-
203
- When you see something that matches a known entity, use THAT name exactly. Only create a NEW entity if nothing in this list represents it.
204
- `
254
+ knownEntities.length > 0
255
+ ? KNOWN_ENTITIES_HEADING + knownEntities.join(", ") + KNOWN_ENTITIES_TRAILER
205
256
  : ""
206
257
  }
207
258
  ${eventTimePromptInstruction(config)}${spanModePromptSection(config.extraction?.spanMode ?? "off")}
package/src/extraction.ts CHANGED
@@ -56,6 +56,7 @@ import {
56
56
  import { containsExtractionPlaceholder, extractionAttributes, extractionCueAnchors, extractionText, isPlainRecord } from "./extraction-normalization.js";
57
57
  import { applyExtractionSpanMaterialization, bindLocalExtractionPrompt, buildSpanMaterializeTurns, stripUntrustedFactSpans, truncateLocalExtractionConversation, type SpanMaterializeTurn } from "./extraction-span-materialize.js";
58
58
  import { extractionProviderJsonSchema, extractionProviderResponseFormat } from "./extraction-span-wire.js";
59
+ import { memoizeExistingEntities, type ExistingEntitiesSource } from "./extraction-entities-source.js";
59
60
  import { resolveLocalLlmCapabilities, resolveMemoryLifecycleCapabilities, resolvePipelineProcessingCapabilities, resolveRecallAuxiliaryCapabilities } from "./capabilities.js";
60
61
  type ExtractionQuestion = ExtractionResult["questions"][number];
61
62
  type ExtractedFactResult = ExtractionResult["facts"][number];
@@ -1067,10 +1068,13 @@ export class ExtractionEngine {
1067
1068
 
1068
1069
  async extract(
1069
1070
  turns: BufferTurn[],
1070
- existingEntities?: string[],
1071
+ existingEntities?: ExistingEntitiesSource,
1071
1072
  signal?: AbortSignal,
1072
1073
  ): Promise<ExtractionResult> {
1073
1074
  const lifecycleCaps = resolveMemoryLifecycleCapabilities(this.config);
1075
+ // Resolved only when a gateway/direct prompt needs it; the local path
1076
+ // (every call on local-first deployments) never reads the list.
1077
+ const resolveEntities = memoizeExistingEntities(existingEntities);
1074
1078
 
1075
1079
  // Guard: skip if buffer is empty or all turns are whitespace-only
1076
1080
  const substantiveTurns = turns.filter((t) => t.content.trim().length > 0);
@@ -1188,7 +1192,7 @@ export class ExtractionEngine {
1188
1192
  this.profiler.startSpan("local-llm", extractionTraceId);
1189
1193
  primaryExtractorAttempted = true;
1190
1194
  try {
1191
- const localResult = await this.extractWithLocalLlm(conversation, existingEntities, signal, ambientCapture);
1195
+ const localResult = await this.extractWithLocalLlm(conversation, signal, ambientCapture);
1192
1196
  throwIfExtractionAborted(signal);
1193
1197
  if (localResult) {
1194
1198
  const durationMs = Date.now() - startTime;
@@ -1247,7 +1251,7 @@ export class ExtractionEngine {
1247
1251
  this.profiler.startSpan("direct-client", extractionTraceId);
1248
1252
  primaryExtractorAttempted = true;
1249
1253
  try {
1250
- const directResult = await this.extractWithDirectClient(conversation, existingEntities, signal, ambientCapture);
1254
+ const directResult = await this.extractWithDirectClient(conversation, resolveEntities, signal, ambientCapture);
1251
1255
  if (directResult) {
1252
1256
  const durationMs = Date.now() - startTime;
1253
1257
  this.profiler.endSpan("direct-client", extractionTraceId);
@@ -1317,7 +1321,7 @@ export class ExtractionEngine {
1317
1321
  {
1318
1322
  role: "system" as const,
1319
1323
  content:
1320
- buildExtractionInstructions(this.config, existingEntities, ambientCapture) +
1324
+ buildExtractionInstructions(this.config, await resolveEntities(), ambientCapture, conversation) +
1321
1325
  `\n\nReturn only valid JSON matching this shape. Placeholder text describes field shape only and is never source evidence:\n${extractionResponseShape(this.config.extraction?.spanMode ?? "off")}`,
1322
1326
  },
1323
1327
  { role: "user" as const, content: conversation },
@@ -1429,7 +1433,6 @@ export class ExtractionEngine {
1429
1433
  */
1430
1434
  private async extractWithLocalLlm(
1431
1435
  conversation: string,
1432
- existingEntities?: string[],
1433
1436
  signal?: AbortSignal,
1434
1437
  ambientCapture = false,
1435
1438
  ): Promise<ExtractionResult | null> {
@@ -1557,7 +1560,7 @@ ${truncatedConversation}`;
1557
1560
  */
1558
1561
  private async extractWithDirectClient(
1559
1562
  conversation: string,
1560
- existingEntities?: string[],
1563
+ resolveEntities: () => Promise<string[]>,
1561
1564
  signal?: AbortSignal,
1562
1565
  ambientCapture = false,
1563
1566
  ): Promise<ExtractionResult | null> {
@@ -1575,10 +1578,10 @@ ${truncatedConversation}`;
1575
1578
  {
1576
1579
  role: "system",
1577
1580
  content:
1578
- buildExtractionInstructions(this.config, existingEntities, ambientCapture) +
1581
+ buildExtractionInstructions(this.config, await resolveEntities(), ambientCapture, conversation) +
1579
1582
  `\n\nReturn only valid JSON matching this shape. Placeholder text describes field shape only and is never source evidence:\n${extractionResponseShape(this.config.extraction?.spanMode ?? "off")}`,
1580
1583
  },
1581
- { role: "user", content: conversation },
1584
+ { role: "user" as const, content: conversation },
1582
1585
  ],
1583
1586
  ...tokenParams,
1584
1587
  },