@remnic/core 10.0.186 → 10.0.187

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 (245) hide show
  1. package/dist/access-admin-ops-surface.js +97 -96
  2. package/dist/access-audit.js +2 -2
  3. package/dist/access-cli.js +97 -96
  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 +97 -96
  7. package/dist/access-extraction-force-flush.js +97 -96
  8. package/dist/access-http-briefing.js +97 -96
  9. package/dist/access-http-query.js +97 -96
  10. package/dist/access-http.js +97 -96
  11. package/dist/access-identity-continuity-surface.js +97 -96
  12. package/dist/access-lcm-surface.js +97 -96
  13. package/dist/access-mcp.js +97 -96
  14. package/dist/access-observe-write-category.js +6 -6
  15. package/dist/access-observe-write-surface.js +97 -96
  16. package/dist/access-offline-manifest.js +5 -5
  17. package/dist/access-operations-batch.js +97 -96
  18. package/dist/access-operations.js +97 -96
  19. package/dist/access-recall-concurrency.js +97 -96
  20. package/dist/access-recall-response.js +97 -96
  21. package/dist/access-recall-surface.js +97 -96
  22. package/dist/access-schema.js +5 -5
  23. package/dist/access-service.js +97 -96
  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.js +6 -5
  30. package/dist/calibration.js +1 -1
  31. package/dist/causal-consolidation.js +8 -8
  32. package/dist/{chunk-3N7I53KR.js → chunk-2QQCCUXF.js} +2 -2
  33. package/dist/{chunk-FYHFM64A.js → chunk-2RAVHJCD.js} +2 -2
  34. package/dist/{chunk-XYZR3NBU.js → chunk-2ZS7CB5H.js} +2 -2
  35. package/dist/{chunk-4TPU36X4.js → chunk-4N33L4HY.js} +2 -2
  36. package/dist/{chunk-BFPF5N3H.js → chunk-4RASUAN3.js} +4 -4
  37. package/dist/{chunk-CKTKATXL.js → chunk-4VFEN3WT.js} +19 -15
  38. package/dist/chunk-4VFEN3WT.js.map +1 -0
  39. package/dist/{chunk-R3UQIS3F.js → chunk-5AFBFAFX.js} +4 -4
  40. package/dist/{chunk-PY5XP7GR.js → chunk-6TIQLG7I.js} +2 -2
  41. package/dist/{chunk-JK5YFQQT.js → chunk-76KL37ON.js} +2 -2
  42. package/dist/{chunk-L7MVHAMS.js → chunk-7EPEZYX3.js} +2 -2
  43. package/dist/{chunk-A3HLZMHD.js → chunk-7KTORRIK.js} +2 -2
  44. package/dist/{chunk-PZ4OA7CP.js → chunk-7UTCETGK.js} +2 -2
  45. package/dist/{chunk-2LXROA34.js → chunk-AXSQGJSG.js} +2 -2
  46. package/dist/{chunk-5ITPOAKW.js → chunk-BANMPRSC.js} +2 -2
  47. package/dist/{chunk-FDXLO6CX.js → chunk-CRS2NY44.js} +2 -2
  48. package/dist/{chunk-SSKIXUR5.js → chunk-CTWWMEGR.js} +2 -2
  49. package/dist/{chunk-ZNHLUYIT.js → chunk-D7HOJFDS.js} +4 -4
  50. package/dist/{chunk-ZX5N5D6M.js → chunk-DAOMWGO2.js} +4 -4
  51. package/dist/{chunk-VN3RYYMS.js → chunk-DR4TYD56.js} +2 -2
  52. package/dist/{chunk-7DFJ4JX2.js → chunk-DTTDMK7Q.js} +7 -7
  53. package/dist/{chunk-YNDLCWXS.js → chunk-EZ25VE3G.js} +4 -4
  54. package/dist/{chunk-QJBULLKG.js → chunk-F2MVWUNF.js} +2 -2
  55. package/dist/{chunk-N33M4NWM.js → chunk-FKLSIQBF.js} +3 -3
  56. package/dist/{chunk-5BESLEU7.js → chunk-FQE5QN5Q.js} +2 -2
  57. package/dist/{chunk-VFJ3PBZI.js → chunk-FXDQO7VX.js} +2 -2
  58. package/dist/{chunk-BAMF6J4W.js → chunk-GCHM5BYL.js} +4 -4
  59. package/dist/{chunk-6SROXED4.js → chunk-GRX5BE73.js} +2 -2
  60. package/dist/{chunk-UMGO4LEZ.js → chunk-HHCLV572.js} +2 -2
  61. package/dist/{chunk-CIC3WZVO.js → chunk-I233SAGS.js} +2 -2
  62. package/dist/{chunk-FBNR3JI5.js → chunk-IMT7NTFV.js} +2 -2
  63. package/dist/{chunk-63FIQIER.js → chunk-JJ42IDJU.js} +2 -2
  64. package/dist/{chunk-CJERJ724.js → chunk-JRHOL6B5.js} +2 -2
  65. package/dist/{chunk-ENKXMLE3.js → chunk-K5RGHUX7.js} +2 -2
  66. package/dist/{chunk-VAQIBC2L.js → chunk-KQIOW3TG.js} +2 -2
  67. package/dist/{chunk-H4HBQRGI.js → chunk-KVM3BS5K.js} +2 -2
  68. package/dist/{chunk-QJG6PEAM.js → chunk-KZJEKKK6.js} +3 -3
  69. package/dist/{chunk-LALPM2DN.js → chunk-L2DYRQQH.js} +139 -135
  70. package/dist/chunk-L2DYRQQH.js.map +1 -0
  71. package/dist/{chunk-N2PXVLV3.js → chunk-LANV6I63.js} +7 -7
  72. package/dist/{chunk-U7VEZ2XS.js → chunk-LPYGM6RE.js} +2 -2
  73. package/dist/{chunk-WCXWCAUC.js → chunk-MDXZIU5X.js} +2 -2
  74. package/dist/{chunk-VUC3DLQ5.js → chunk-MOWLANEJ.js} +2 -2
  75. package/dist/{chunk-IK7NPYYU.js → chunk-NFQKIZK3.js} +2 -2
  76. package/dist/{chunk-RXAWE76Y.js → chunk-O6QSBI3U.js} +2 -2
  77. package/dist/{chunk-5RBHL5TF.js → chunk-OA7YDB6A.js} +2 -2
  78. package/dist/{chunk-CXGD3N2Y.js → chunk-OVJAQWHO.js} +2 -2
  79. package/dist/{chunk-3GD5SFDT.js → chunk-P5FF44G3.js} +5 -5
  80. package/dist/{chunk-5RWIZISF.js → chunk-PSUSA5SM.js} +3 -3
  81. package/dist/{chunk-DYZDFOBX.js → chunk-Q6S67LHR.js} +2 -2
  82. package/dist/{chunk-KYPFQO43.js → chunk-QPD7EYGI.js} +2 -2
  83. package/dist/{chunk-FE43YKNJ.js → chunk-RBPC4XGU.js} +31 -8
  84. package/dist/chunk-RBPC4XGU.js.map +1 -0
  85. package/dist/{chunk-G6V32Q4F.js → chunk-SFWQZBPN.js} +2 -2
  86. package/dist/{chunk-DNXQVCIC.js → chunk-SUI75NTN.js} +8 -8
  87. package/dist/{chunk-FDLPNFKE.js → chunk-T7R42MWB.js} +2 -2
  88. package/dist/chunk-TK6EBBKG.js +13 -0
  89. package/dist/chunk-TK6EBBKG.js.map +1 -0
  90. package/dist/{chunk-J7BAJ6BF.js → chunk-UCCXPMTP.js} +2 -2
  91. package/dist/{chunk-PDXO4LIH.js → chunk-UWKHLWUE.js} +13 -9
  92. package/dist/chunk-UWKHLWUE.js.map +1 -0
  93. package/dist/{chunk-L4TYD52M.js → chunk-VZBKCRU7.js} +2 -2
  94. package/dist/{chunk-T4MKFTJF.js → chunk-XHDS6HIX.js} +5 -5
  95. package/dist/{chunk-TKWIUL3D.js → chunk-YDGQYG4L.js} +7 -7
  96. package/dist/{chunk-4KUK3KGI.js → chunk-YJZDRM33.js} +3 -3
  97. package/dist/{chunk-NU5JRN3A.js → chunk-ZDLVHGIC.js} +2 -2
  98. package/dist/{chunk-OJXK5C6Z.js → chunk-ZG4GNPRE.js} +7 -7
  99. package/dist/{chunk-IJKO5RVJ.js → chunk-ZNYDDZVW.js} +3 -3
  100. package/dist/cli.js +97 -96
  101. package/dist/coding/export-okf-codegraph.js +13 -13
  102. package/dist/compounding/engine.js +8 -8
  103. package/dist/config.js +10 -10
  104. package/dist/connectors/codex-materialize-runner.js +7 -7
  105. package/dist/connectors/index.js +7 -7
  106. package/dist/convergence-refresh.js +9 -9
  107. package/dist/corpus-watermark.js +9 -9
  108. package/dist/dashboard-runtime.js +2 -2
  109. package/dist/deep-recall-http-glue.js +6 -6
  110. package/dist/deep-recall.js +2 -2
  111. package/dist/entity-retrieval.js +7 -7
  112. package/dist/explicit-capture.js +97 -96
  113. package/dist/extraction-entities-source.d.ts +11 -0
  114. package/dist/extraction-entities-source.d.ts.map +1 -0
  115. package/dist/extraction-entities-source.js +8 -0
  116. package/dist/extraction-entities-source.js.map +1 -0
  117. package/dist/extraction-judge.js +2 -2
  118. package/dist/extraction-normalization.js +2 -2
  119. package/dist/extraction-prompt.d.ts +19 -2
  120. package/dist/extraction-prompt.d.ts.map +1 -1
  121. package/dist/extraction-prompt.js +5 -1
  122. package/dist/extraction.d.ts +2 -1
  123. package/dist/extraction.d.ts.map +1 -1
  124. package/dist/extraction.js +15 -14
  125. package/dist/{first-start-migration-TCPK2I7J.js → first-start-migration-CCZ5SM3V.js} +4 -4
  126. package/dist/harmonic-retrieval.js +7 -7
  127. package/dist/index.js +117 -116
  128. package/dist/lcm/engine.js +3 -3
  129. package/dist/lcm/index.js +8 -8
  130. package/dist/location/index.js +8 -8
  131. package/dist/maintenance/memory-governance.js +7 -7
  132. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +7 -7
  133. package/dist/maintenance/rebuild-memory-projection-runner.js +9 -9
  134. package/dist/maintenance/rebuild-memory-projection.js +8 -8
  135. package/dist/memory-browse.js +5 -5
  136. package/dist/namespaces/migrate.js +8 -8
  137. package/dist/namespaces/search.js +4 -4
  138. package/dist/namespaces/storage.js +7 -7
  139. package/dist/offline-sync-changeset-generations.js +3 -3
  140. package/dist/offline-sync-embedding-generation.js +2 -2
  141. package/dist/offline-sync-snapshot-stream.js +5 -5
  142. package/dist/offline-sync.js +6 -6
  143. package/dist/operator-doctor-corpus.js +10 -10
  144. package/dist/operator-toolkit.js +17 -17
  145. package/dist/orchestration/backlog-scheduler.js +98 -97
  146. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  147. package/dist/orchestration/buffer-drain-runner.js +98 -97
  148. package/dist/orchestration/extraction-queue-coordinator.d.ts.map +1 -1
  149. package/dist/orchestration/extraction-run-helpers.d.ts +2 -1
  150. package/dist/orchestration/extraction-run-helpers.d.ts.map +1 -1
  151. package/dist/orchestration/extraction-run.d.ts.map +1 -1
  152. package/dist/orchestration/maintenance.js +15 -15
  153. package/dist/orchestrator.js +99 -98
  154. package/dist/qmd.js +2 -2
  155. package/dist/recall-navigation.js +97 -96
  156. package/dist/recall-state-view-admission.js +5 -5
  157. package/dist/recall-why-service.js +5 -5
  158. package/dist/resume-bundles.js +13 -13
  159. package/dist/search/factory.js +3 -3
  160. package/dist/search/index.js +3 -3
  161. package/dist/semantic-consolidation.js +8 -8
  162. package/dist/semantic-rule-promotion.js +7 -7
  163. package/dist/semantic-rule-verifier.js +7 -7
  164. package/dist/source-agent-qualifier.js +11 -10
  165. package/dist/standup/build.js +7 -7
  166. package/dist/storage.js +6 -6
  167. package/dist/transcript.js +2 -2
  168. package/dist/transfer/export-okf.js +7 -7
  169. package/dist/verified-recall.js +7 -7
  170. package/dist/who-knows-cli.js +8 -8
  171. package/dist/who-knows.js +7 -7
  172. package/package.json +2 -2
  173. package/src/extraction-carry-forward.test.ts +147 -0
  174. package/src/extraction-entities-source.ts +19 -0
  175. package/src/extraction-prompt.ts +60 -9
  176. package/src/extraction.ts +11 -8
  177. package/src/orchestration/extraction-queue-coordinator.ts +7 -1
  178. package/src/orchestration/extraction-queue-lane-bias.test.ts +35 -0
  179. package/src/orchestration/extraction-run-helpers.ts +11 -4
  180. package/src/orchestration/extraction-run.test.ts +23 -12
  181. package/src/orchestration/extraction-run.ts +6 -5
  182. package/dist/chunk-CKTKATXL.js.map +0 -1
  183. package/dist/chunk-FE43YKNJ.js.map +0 -1
  184. package/dist/chunk-LALPM2DN.js.map +0 -1
  185. package/dist/chunk-PDXO4LIH.js.map +0 -1
  186. /package/dist/{auto-sync-OOEY2FSA.js.map → auto-sync-BJUAGKI5.js.map} +0 -0
  187. /package/dist/{chunk-3N7I53KR.js.map → chunk-2QQCCUXF.js.map} +0 -0
  188. /package/dist/{chunk-FYHFM64A.js.map → chunk-2RAVHJCD.js.map} +0 -0
  189. /package/dist/{chunk-XYZR3NBU.js.map → chunk-2ZS7CB5H.js.map} +0 -0
  190. /package/dist/{chunk-4TPU36X4.js.map → chunk-4N33L4HY.js.map} +0 -0
  191. /package/dist/{chunk-BFPF5N3H.js.map → chunk-4RASUAN3.js.map} +0 -0
  192. /package/dist/{chunk-R3UQIS3F.js.map → chunk-5AFBFAFX.js.map} +0 -0
  193. /package/dist/{chunk-PY5XP7GR.js.map → chunk-6TIQLG7I.js.map} +0 -0
  194. /package/dist/{chunk-JK5YFQQT.js.map → chunk-76KL37ON.js.map} +0 -0
  195. /package/dist/{chunk-L7MVHAMS.js.map → chunk-7EPEZYX3.js.map} +0 -0
  196. /package/dist/{chunk-A3HLZMHD.js.map → chunk-7KTORRIK.js.map} +0 -0
  197. /package/dist/{chunk-PZ4OA7CP.js.map → chunk-7UTCETGK.js.map} +0 -0
  198. /package/dist/{chunk-2LXROA34.js.map → chunk-AXSQGJSG.js.map} +0 -0
  199. /package/dist/{chunk-5ITPOAKW.js.map → chunk-BANMPRSC.js.map} +0 -0
  200. /package/dist/{chunk-FDXLO6CX.js.map → chunk-CRS2NY44.js.map} +0 -0
  201. /package/dist/{chunk-SSKIXUR5.js.map → chunk-CTWWMEGR.js.map} +0 -0
  202. /package/dist/{chunk-ZNHLUYIT.js.map → chunk-D7HOJFDS.js.map} +0 -0
  203. /package/dist/{chunk-ZX5N5D6M.js.map → chunk-DAOMWGO2.js.map} +0 -0
  204. /package/dist/{chunk-VN3RYYMS.js.map → chunk-DR4TYD56.js.map} +0 -0
  205. /package/dist/{chunk-7DFJ4JX2.js.map → chunk-DTTDMK7Q.js.map} +0 -0
  206. /package/dist/{chunk-YNDLCWXS.js.map → chunk-EZ25VE3G.js.map} +0 -0
  207. /package/dist/{chunk-QJBULLKG.js.map → chunk-F2MVWUNF.js.map} +0 -0
  208. /package/dist/{chunk-N33M4NWM.js.map → chunk-FKLSIQBF.js.map} +0 -0
  209. /package/dist/{chunk-5BESLEU7.js.map → chunk-FQE5QN5Q.js.map} +0 -0
  210. /package/dist/{chunk-VFJ3PBZI.js.map → chunk-FXDQO7VX.js.map} +0 -0
  211. /package/dist/{chunk-BAMF6J4W.js.map → chunk-GCHM5BYL.js.map} +0 -0
  212. /package/dist/{chunk-6SROXED4.js.map → chunk-GRX5BE73.js.map} +0 -0
  213. /package/dist/{chunk-UMGO4LEZ.js.map → chunk-HHCLV572.js.map} +0 -0
  214. /package/dist/{chunk-CIC3WZVO.js.map → chunk-I233SAGS.js.map} +0 -0
  215. /package/dist/{chunk-FBNR3JI5.js.map → chunk-IMT7NTFV.js.map} +0 -0
  216. /package/dist/{chunk-63FIQIER.js.map → chunk-JJ42IDJU.js.map} +0 -0
  217. /package/dist/{chunk-CJERJ724.js.map → chunk-JRHOL6B5.js.map} +0 -0
  218. /package/dist/{chunk-ENKXMLE3.js.map → chunk-K5RGHUX7.js.map} +0 -0
  219. /package/dist/{chunk-VAQIBC2L.js.map → chunk-KQIOW3TG.js.map} +0 -0
  220. /package/dist/{chunk-H4HBQRGI.js.map → chunk-KVM3BS5K.js.map} +0 -0
  221. /package/dist/{chunk-QJG6PEAM.js.map → chunk-KZJEKKK6.js.map} +0 -0
  222. /package/dist/{chunk-N2PXVLV3.js.map → chunk-LANV6I63.js.map} +0 -0
  223. /package/dist/{chunk-U7VEZ2XS.js.map → chunk-LPYGM6RE.js.map} +0 -0
  224. /package/dist/{chunk-WCXWCAUC.js.map → chunk-MDXZIU5X.js.map} +0 -0
  225. /package/dist/{chunk-VUC3DLQ5.js.map → chunk-MOWLANEJ.js.map} +0 -0
  226. /package/dist/{chunk-IK7NPYYU.js.map → chunk-NFQKIZK3.js.map} +0 -0
  227. /package/dist/{chunk-RXAWE76Y.js.map → chunk-O6QSBI3U.js.map} +0 -0
  228. /package/dist/{chunk-5RBHL5TF.js.map → chunk-OA7YDB6A.js.map} +0 -0
  229. /package/dist/{chunk-CXGD3N2Y.js.map → chunk-OVJAQWHO.js.map} +0 -0
  230. /package/dist/{chunk-3GD5SFDT.js.map → chunk-P5FF44G3.js.map} +0 -0
  231. /package/dist/{chunk-5RWIZISF.js.map → chunk-PSUSA5SM.js.map} +0 -0
  232. /package/dist/{chunk-DYZDFOBX.js.map → chunk-Q6S67LHR.js.map} +0 -0
  233. /package/dist/{chunk-KYPFQO43.js.map → chunk-QPD7EYGI.js.map} +0 -0
  234. /package/dist/{chunk-G6V32Q4F.js.map → chunk-SFWQZBPN.js.map} +0 -0
  235. /package/dist/{chunk-DNXQVCIC.js.map → chunk-SUI75NTN.js.map} +0 -0
  236. /package/dist/{chunk-FDLPNFKE.js.map → chunk-T7R42MWB.js.map} +0 -0
  237. /package/dist/{chunk-J7BAJ6BF.js.map → chunk-UCCXPMTP.js.map} +0 -0
  238. /package/dist/{chunk-L4TYD52M.js.map → chunk-VZBKCRU7.js.map} +0 -0
  239. /package/dist/{chunk-T4MKFTJF.js.map → chunk-XHDS6HIX.js.map} +0 -0
  240. /package/dist/{chunk-TKWIUL3D.js.map → chunk-YDGQYG4L.js.map} +0 -0
  241. /package/dist/{chunk-4KUK3KGI.js.map → chunk-YJZDRM33.js.map} +0 -0
  242. /package/dist/{chunk-NU5JRN3A.js.map → chunk-ZDLVHGIC.js.map} +0 -0
  243. /package/dist/{chunk-OJXK5C6Z.js.map → chunk-ZG4GNPRE.js.map} +0 -0
  244. /package/dist/{chunk-IJKO5RVJ.js.map → chunk-ZNYDDZVW.js.map} +0 -0
  245. /package/dist/{first-start-migration-TCPK2I7J.js.map → first-start-migration-CCZ5SM3V.js.map} +0 -0
@@ -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
  },
@@ -144,7 +144,13 @@ export class ExtractionQueueCoordinator {
144
144
  const key = options?.key;
145
145
  const entry: QueueEntry = { run: task, key, backlog: options?.backlog, front: options?.front };
146
146
  if (options?.front) {
147
- this.preemptRunning(options.key);
147
+ const sameKeyArmed =
148
+ key !== undefined &&
149
+ Array.from(this.preemptSlots.values()).some((slot) => slot.key === key && slot.armed !== undefined);
150
+ if (sameKeyArmed || this.preemptSlots.size >= this.concurrency) {
151
+ this.preemptRunning(options.key);
152
+ }
153
+ entry.front = true;
148
154
  this.queue.unshift(entry);
149
155
  } else {
150
156
  this.queue.push(entry);
@@ -183,3 +183,38 @@ test("a front flush starts before queued backlog work (CodeRabbit Major, pure-ba
183
183
  release("bl2");
184
184
  release("flush");
185
185
  });
186
+
187
+ test("a front flush takes the free slot instead of killing armed backlog", async () => {
188
+ const queue = new ExtractionQueueCoordinator(4);
189
+ const aborted: string[] = [];
190
+ const started: string[] = [];
191
+ for (const tag of ["b1", "b2", "b3"]) {
192
+ queue.enqueue(async (preempt) => {
193
+ started.push(tag);
194
+ preempt?.arm(() => aborted.push(tag));
195
+ await new Promise<void>(() => {}); // never settles
196
+ }, { backlog: true });
197
+ }
198
+ await tick();
199
+ assert.deepEqual(started, ["b1", "b2", "b3"]);
200
+ // The invariant reserve leaves one slot free; the flush must use it
201
+ // rather than aborting an armed backlog task.
202
+ queue.enqueue(async () => { started.push("flush"); }, { front: true });
203
+ for (let i = 0; i < 10 && !started.includes("flush"); i += 1) await tick();
204
+ assert.deepEqual(aborted, [], "no victim while a free slot exists");
205
+ assert.deepEqual(started, ["b1", "b2", "b3", "flush"], "the flush ran in the reserved slot");
206
+ });
207
+
208
+ test("a front flush beats queued backlog when the foreground floor is met", async () => {
209
+ const h = harness(2);
210
+ h.enqueue("fg", "f1");
211
+ await tick();
212
+ assert.deepEqual(h.started, ["f1"]);
213
+ // Backlog queued first, then a force flush jumps the queue: front
214
+ // priority outranks the backlog preference for ordinary queued tasks.
215
+ h.enqueue("bg", "b1");
216
+ h.queue.enqueue(async () => { h.started.push("flush"); }, { front: true });
217
+ for (let i = 0; i < 10 && !h.started.includes("flush"); i += 1) await tick();
218
+ assert.deepEqual(h.started.slice(0, 2), ["f1", "flush"],
219
+ "the flush wins the second slot over the queued backlog task");
220
+ });
@@ -4,6 +4,7 @@ import { resolveMemoryLifecycleCapabilities, resolveRecallEnhancementCapabilitie
4
4
  import { log } from "../logger.js";
5
5
  import type { ExtractionRunResult } from "./extraction-run.js";
6
6
  import type { ExtractionEngine } from "../extraction.js";
7
+ import { memoizeExistingEntities, type ExistingEntitiesSource } from "../extraction-entities-source.js";
7
8
 
8
9
  /**
9
10
  * Count of durable outputs an extraction result asks persistence to write
@@ -411,7 +412,7 @@ export async function extractChunkedExtraction(
411
412
  engine: Pick<ExtractionEngine, "extract">,
412
413
  config: PluginConfig,
413
414
  turns: BufferTurn[],
414
- existingEntities: string[],
415
+ existingEntities: ExistingEntitiesSource,
415
416
  signal?: AbortSignal,
416
417
  ): Promise<ExtractionResult> {
417
418
  const budget = config.extractionPromptMaxChars;
@@ -438,11 +439,17 @@ export async function extractChunkedExtraction(
438
439
  entities: [],
439
440
  questions: [],
440
441
  };
441
- const entityNames = [...existingEntities];
442
+ // Carry-forward names found in earlier chunks flow into every later
443
+ // fallback call: the base listing resolves once (memoized), while
444
+ // `foundNames` re-spreads on each call so names found after a first
445
+ // fallback still reach subsequent fallback chunks.
446
+ const foundNames: string[] = [];
447
+ const baseEntities = memoizeExistingEntities(existingEntities);
448
+ const carryForward = async () => [...(await baseEntities()), ...foundNames];
442
449
  let skippedReason: ExtractionResult["extractionSkippedReason"];
443
450
  let providerCalls = 0;
444
451
  for (const chunk of chunks) {
445
- const part = await engine.extract(chunk, entityNames, signal);
452
+ const part = await engine.extract(chunk, carryForward, signal);
446
453
  // A provider failure keeps the single-call surface so the run stays
447
454
  // retryable under the no-drop contract; a per-chunk prefilter skip is
448
455
  // not a failure — later chunks can still carry real facts.
@@ -463,7 +470,7 @@ export async function extractChunkedExtraction(
463
470
  merged.episodeTitle ??= part.episodeTitle;
464
471
  // Entity names found in earlier chunks flow into later calls so the
465
472
  // LLM reuses them instead of inventing variants.
466
- entityNames.push(...part.entities.map((entity) => entity.name));
473
+ foundNames.push(...part.entities.map((entity) => entity.name));
467
474
  }
468
475
  // The connector must derive from the whole claim, not the first chunk —
469
476
  // a mixed claim resolves to no connector, same as one call over the set.
@@ -362,18 +362,6 @@ test("runExtraction bounds storage preparation by its deadline", async () => {
362
362
  };
363
363
  },
364
364
  },
365
- {
366
- name: "listEntityNames",
367
- stage: "during_list_entity_names",
368
- configure: async (harness: Harness) => {
369
- const storage = await harness.storageForNs("default");
370
- const listEntityNames = storage.listEntityNames.bind(storage);
371
- storage.listEntityNames = async () => {
372
- await new Promise((resolve) => setTimeout(resolve, 100));
373
- return listEntityNames();
374
- };
375
- },
376
- },
377
365
  ] as const;
378
366
 
379
367
  for (const scenario of scenarios) {
@@ -439,6 +427,29 @@ test("runExtraction force flush reports a late deadline after clearing committed
439
427
  }
440
428
  });
441
429
 
430
+ test("runExtraction does not list entity names on the local extraction path", async () => {
431
+ const harness = await makeHarness();
432
+ try {
433
+ const storage = await harness.storageForNs("default");
434
+ let listCalls = 0;
435
+ storage.listEntityNames = async () => {
436
+ listCalls += 1;
437
+ return new Promise<string[]>(() => {});
438
+ };
439
+ harness.setRespond(() => successResult());
440
+ const result = await harness.newCoordinator().runExtraction(makeTurns("lazy-entities"), {
441
+ skipCharThreshold: true,
442
+ skipUserTurnThreshold: true,
443
+ clearBufferAfterExtraction: false,
444
+ bufferKey: "lazy-entities",
445
+ });
446
+ assert.equal(listCalls, 0, "local-path extraction must not list the entity store");
447
+ assert.equal(result.status, "completed");
448
+ } finally {
449
+ await harness.cleanup();
450
+ }
451
+ });
452
+
442
453
  test("runExtraction bounds threading pre-persist work by its deadline", async () => {
443
454
  const harness = await makeHarness({ threadingEnabled: true });
444
455
  try {
@@ -847,14 +847,15 @@ export class ExtractionRunCoordinator {
847
847
  log.warn("runExtraction: extraction retry gate check failed; proceeding (fail-open)", err);
848
848
  }
849
849
  }
850
- // Pass existing entity names so the LLM can reuse them instead of inventing variants.
850
+ // Lazy entity list. A half-open probe lists first so a slow store cannot
851
+ // reopen the breaker. false keeps the deadline if extract() absorbs the error.
851
852
  // The probe owner must release on ANY pre-persistence exit too (codex P1):
852
853
  // the big try below only covers from the extract call onward.
853
854
  try {
854
- const existingEntities = await runDeadlineAware(
855
- () => storage.listEntityNames(),
856
- "during_list_entity_names",
857
- );
855
+ let entityNamesPromise: Promise<string[]> | undefined;
856
+ const existingEntities = (): Promise<string[]> =>
857
+ (entityNamesPromise ??= runDeadlineAware(() => storage.listEntityNames(), "during_list_entity_names", false));
858
+ if (extractionProbeOwned) await existingEntities();
858
859
  let result: ExtractionResult;
859
860
  // The half-open probe is bounded: one that gets no answer in time counts as
860
861
  // a provider failure (re-opens the breaker) instead of holding every other