@remnic/core 9.3.688 → 9.3.689

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 (49) hide show
  1. package/dist/access-boundary.js +8 -8
  2. package/dist/access-cli.js +13 -13
  3. package/dist/access-http.js +11 -11
  4. package/dist/access-mcp.js +10 -10
  5. package/dist/access-operations.js +9 -9
  6. package/dist/access-service.js +7 -7
  7. package/dist/{chunk-ZPTISBQU.js → chunk-2SNKUSQC.js} +4 -4
  8. package/dist/{chunk-2KAYTPPT.js → chunk-JPETDXED.js} +5 -5
  9. package/dist/{chunk-B43NZNMG.js → chunk-JZBFL7RI.js} +7 -7
  10. package/dist/{chunk-NN7QYW5W.js → chunk-OWFY6NGQ.js} +2 -2
  11. package/dist/{chunk-S2OU5DZY.js → chunk-QSQW54U5.js} +4 -4
  12. package/dist/{chunk-CCWHPGT4.js → chunk-RHXFYIHA.js} +21 -21
  13. package/dist/{chunk-CTOQEZSN.js → chunk-SAEZIIID.js} +2 -2
  14. package/dist/{chunk-DCWIQFNA.js → chunk-T422SYM6.js} +5 -5
  15. package/dist/{chunk-RVYD6LR3.js → chunk-UHUZXWDX.js} +2 -2
  16. package/dist/{chunk-473JIN2U.js → chunk-UXLZOVCN.js} +3 -3
  17. package/dist/{chunk-2SJCWLQD.js → chunk-W63OY3J7.js} +2 -2
  18. package/dist/{chunk-FUCUR2OZ.js → chunk-XU7363OX.js} +2 -2
  19. package/dist/{chunk-KFBOZYME.js → chunk-Z2M6YTAJ.js} +3 -3
  20. package/dist/cli.js +20 -20
  21. package/dist/conversation-index/backend.js +2 -2
  22. package/dist/index.js +28 -28
  23. package/dist/lcm/engine.js +2 -2
  24. package/dist/lcm/index.js +4 -4
  25. package/dist/namespaces/migrate.js +7 -7
  26. package/dist/namespaces/search.js +6 -6
  27. package/dist/operator-toolkit.js +8 -8
  28. package/dist/orchestrator.js +10 -10
  29. package/dist/recall-pipeline-stages.d.ts +167 -0
  30. package/dist/recall-pipeline-stages.js +61 -0
  31. package/dist/recall-pipeline-stages.js.map +1 -0
  32. package/dist/search/factory.js +5 -5
  33. package/dist/search/index.js +9 -9
  34. package/package.json +2 -2
  35. package/src/recall-pipeline-stages.test.ts +269 -0
  36. package/src/recall-pipeline-stages.ts +294 -0
  37. /package/dist/{chunk-ZPTISBQU.js.map → chunk-2SNKUSQC.js.map} +0 -0
  38. /package/dist/{chunk-2KAYTPPT.js.map → chunk-JPETDXED.js.map} +0 -0
  39. /package/dist/{chunk-B43NZNMG.js.map → chunk-JZBFL7RI.js.map} +0 -0
  40. /package/dist/{chunk-NN7QYW5W.js.map → chunk-OWFY6NGQ.js.map} +0 -0
  41. /package/dist/{chunk-S2OU5DZY.js.map → chunk-QSQW54U5.js.map} +0 -0
  42. /package/dist/{chunk-CCWHPGT4.js.map → chunk-RHXFYIHA.js.map} +0 -0
  43. /package/dist/{chunk-CTOQEZSN.js.map → chunk-SAEZIIID.js.map} +0 -0
  44. /package/dist/{chunk-DCWIQFNA.js.map → chunk-T422SYM6.js.map} +0 -0
  45. /package/dist/{chunk-RVYD6LR3.js.map → chunk-UHUZXWDX.js.map} +0 -0
  46. /package/dist/{chunk-473JIN2U.js.map → chunk-UXLZOVCN.js.map} +0 -0
  47. /package/dist/{chunk-2SJCWLQD.js.map → chunk-W63OY3J7.js.map} +0 -0
  48. /package/dist/{chunk-FUCUR2OZ.js.map → chunk-XU7363OX.js.map} +0 -0
  49. /package/dist/{chunk-KFBOZYME.js.map → chunk-Z2M6YTAJ.js.map} +0 -0
@@ -0,0 +1,61 @@
1
+ import "./chunk-PZ5AY32C.js";
2
+
3
+ // src/recall-pipeline-stages.ts
4
+ var UNDEFINED_TURN_INDEX_DESC_SENTINEL = -1;
5
+ var UNDEFINED_TURN_INDEX_ASC_SENTINEL = Number.MAX_SAFE_INTEGER;
6
+ function unifiedDedupeAndRank(items, config) {
7
+ const transformContent = config.transformContent ?? ((content) => content);
8
+ const direction = config.turnIndexSortDirection ?? "desc";
9
+ const dedupByContent = config.dedupByContent !== false;
10
+ const seenIds = /* @__PURE__ */ new Set();
11
+ const seenContent = /* @__PURE__ */ new Set();
12
+ const survivors = [];
13
+ for (const item of items) {
14
+ const id = resolveItemId(item);
15
+ if (id && seenIds.has(id)) continue;
16
+ const transformedContent = transformContent(item.content, config.intents);
17
+ if (dedupByContent) {
18
+ const contentKey = transformedContent.toLowerCase().replace(/\s+/g, " ").trim();
19
+ if (seenContent.has(contentKey)) continue;
20
+ seenContent.add(contentKey);
21
+ }
22
+ if (id) seenIds.add(id);
23
+ survivors.push({ original: item, transformedContent });
24
+ }
25
+ const scored = survivors.map(({ original, transformedContent }) => ({
26
+ ...original,
27
+ content: transformedContent,
28
+ rank: config.scoreEvidence(original, config.query, config.intents)
29
+ }));
30
+ const filtered = typeof config.rankThreshold === "number" ? scored.filter((item) => item.rank >= config.rankThreshold) : scored;
31
+ return filtered.sort(makeComparator(direction));
32
+ }
33
+ function makeComparator(direction) {
34
+ if (direction === "asc") {
35
+ return (left, right) => {
36
+ if (right.rank !== left.rank) return right.rank - left.rank;
37
+ const leftTurn = typeof left.turnIndex === "number" ? left.turnIndex : UNDEFINED_TURN_INDEX_ASC_SENTINEL;
38
+ const rightTurn = typeof right.turnIndex === "number" ? right.turnIndex : UNDEFINED_TURN_INDEX_ASC_SENTINEL;
39
+ if (leftTurn !== rightTurn) return leftTurn - rightTurn;
40
+ return left.content.localeCompare(right.content);
41
+ };
42
+ }
43
+ return (left, right) => {
44
+ if (right.rank !== left.rank) return right.rank - left.rank;
45
+ const leftTurn = typeof left.turnIndex === "number" ? left.turnIndex : UNDEFINED_TURN_INDEX_DESC_SENTINEL;
46
+ const rightTurn = typeof right.turnIndex === "number" ? right.turnIndex : UNDEFINED_TURN_INDEX_DESC_SENTINEL;
47
+ if (rightTurn !== leftTurn) return rightTurn - leftTurn;
48
+ return (right.score ?? 0) - (left.score ?? 0);
49
+ };
50
+ }
51
+ function resolveItemId(item) {
52
+ if (item.id) return item.id;
53
+ if (item.sessionId && typeof item.turnIndex === "number") {
54
+ return `${item.sessionId}:${item.turnIndex}`;
55
+ }
56
+ return void 0;
57
+ }
58
+ export {
59
+ unifiedDedupeAndRank
60
+ };
61
+ //# sourceMappingURL=recall-pipeline-stages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/recall-pipeline-stages.ts"],"sourcesContent":["/**\n * Issue #1539 PR2 — the staged recall pipeline spine.\n *\n * The four recall pipelines (`targeted-fact-recall.ts`, `response-guidance-\n * recall.ts`, `explicit-cue-recall.ts`, `event-order-recall.ts`) implement\n * the same stage sequence — intent → candidate collection → dedup → rank →\n * filter → slice → metadata insertion → token budgeting — with ~70%\n * near-duplicate code. The most dangerous divergence is the sort\n * comparator: guidance/targeted-fact sort `turnIndex` DESC (recency) while\n * event-order sorts `turnIndex` ASC (chronological). The comparators are\n * byte-identical except for this direction — copy-pasting into a new\n * chronological pipeline silently inverts the ordering.\n *\n * This module centralizes the **dedup + score + threshold-filter + sort**\n * stages behind one declared config object. Per-tier divergence (threshold\n * value, sort direction, content transformation) becomes a declared config\n * field instead of embedded code.\n *\n * **PR 2 scope:** extract the module with NO pipeline changes. PRs 3–6\n * migrate each pipeline to call `unifiedDedupeAndRank` one at a time,\n * re-running the characterization snapshots\n * (`tests/recall-pipeline-unified.test.ts`) to verify byte-for-byte parity.\n *\n * Future PRs will add the remaining stages from the issue's Solution\n * (`mergeAcrossLcmKeys`, `insertMetadata`) once the per-tier hooks are\n * factored out of each pipeline.\n *\n * @see https://github.com/joshuaswarren/remnic/issues/1539\n */\n\nimport type { EvidencePackItem } from \"./evidence-pack.js\";\n\n/** A ranked evidence item: an `EvidencePackItem` with a computed `rank`. */\nexport interface RankedEvidenceItem extends EvidencePackItem {\n rank: number;\n}\n\n/**\n * Sort direction for the turn-index secondary key. This is the divergence\n * issue #1539 identifies: relevance-ranked pipelines (targeted-fact,\n * response-guidance) sort `turnIndex` DESC (recency — latest first); the\n * chronological pipeline (event-order) sorts `turnIndex` ASC (earliest\n * first). The rank primary key is ALWAYS DESC (higher rank first); only\n * the `turnIndex` tiebreaker flips direction.\n */\nexport type TurnIndexSortDirection = \"desc\" | \"asc\";\n\n/**\n * Configuration for the unified dedup + score + threshold-filter + sort\n * pass. Each pipeline declares its divergences as fields here instead of\n * embedding them in pipeline-specific code.\n *\n * The issue's Solution defines the intended full config object\n * (`RecallPipelineConfig`); this interface is extracted incrementally:\n * - PR 2 (this PR): dedup/score/threshold/sort only\n * - PRs 3–6: migrate each pipeline to consume the spine\n * - future: add `mergeAcrossLcmKeys`, `insertMetadata` once the per-tier\n * hooks are factored out of each pipeline\n */\nexport interface UnifiedRankConfig<TIntent> {\n /** The user query — passed to the scorer. */\n query: string;\n /**\n * Per-tier intent classification result (already computed by the caller;\n * intent classification stays per-tier because it is genuinely\n * per-tier per issue #1539 Pitfall 1).\n */\n intents: TIntent[];\n /**\n * Score an item using its ORIGINAL (pre-transform) content. Higher = more\n * relevant. The return value becomes the item's `rank`. For pipelines\n * that don't score (explicit-cue), pass a constant scorer — the config\n * makes the no-scoring policy explicit.\n */\n scoreEvidence: (\n item: EvidencePackItem,\n query: string,\n intents: TIntent[],\n ) => number;\n /**\n * Optional content transformation applied to each surviving item's\n * OUTPUT content (NOT to the content the scorer sees). Per-tier\n * cue-appenders go here:\n * - targeted-fact: `appendNormalizedNumericCues`\n * - response-guidance: `appendGuidanceCues`\n * - event-order: `appendChronologicalCues`\n *\n * The dedup key uses the TRANSFORMED content. This is equivalent to\n * deduping on original content for all existing pipelines because every\n * transform is a deterministic append (same original → same transformed →\n * same key; different originals → different transformed → different key).\n */\n transformContent?: (content: string, intents: TIntent[]) => string;\n /**\n * Whether to deduplicate by normalized (transformed) content in addition to\n * id. Default `true` — matches targeted-fact, response-guidance, and\n * explicit-cue, which all collapse later items sharing a normalized content\n * key. Event-order sets this to `false`: its rank pass\n * (`rankAndSelectEventOrderItems`) deduplicates by turn id only and keeps\n * distinct turns even when two turns share the same cue-appended body\n * (legitimate repeated turns in a chronological transcript). Making this a\n * declared field prevents PR 6's migration from silently dropping valid\n * turns (cursor bugbot a4299851).\n */\n dedupByContent?: boolean;\n /**\n * Items with `rank` below this threshold are dropped. `undefined` = no\n * filter. Event-order declares `rankThreshold: 6` here instead of\n * inlining an undocumented `.filter((item) => item.rank >= 6)` (the\n * \"hardcoded rank threshold that exists in no config and no other\n * pipeline\" from issue #1539's audit).\n */\n rankThreshold?: number;\n /**\n * Sort direction for the `turnIndex` secondary key.\n *\n * - `\"desc\"` (default): relevance-ranked pipelines (targeted-fact,\n * response-guidance) sort `turnIndex` DESC. Undefined `turnIndex`\n * falls to `-1` (bottom of a DESC list). Tertiary tiebreaker:\n * `score DESC`.\n * - `\"asc\"`: the chronological pipeline (event-order) sorts `turnIndex`\n * ASC. Undefined `turnIndex` falls to `Number.MAX_SAFE_INTEGER`\n * (bottom of an ASC list). Tertiary tiebreaker: `content.localeCompare`.\n *\n * The rank primary key is ALWAYS DESC regardless of this setting.\n */\n turnIndexSortDirection?: TurnIndexSortDirection;\n}\n\n/**\n * Sentinel for undefined `turnIndex` when sorting DESC. `-1` sorts below\n * every real turn index (which are `>= 0`), so missing `turn_index` always\n * lands at the bottom of a DESC-ordered list — never wins ordering over a\n * real turn.\n */\nconst UNDEFINED_TURN_INDEX_DESC_SENTINEL = -1;\n\n/**\n * Sentinel for undefined `turnIndex` when sorting ASC.\n * `Number.MAX_SAFE_INTEGER` sorts above every real turn index, so missing\n * `turn_index` always lands at the bottom of an ASC-ordered list.\n */\nconst UNDEFINED_TURN_INDEX_ASC_SENTINEL = Number.MAX_SAFE_INTEGER;\n\n/**\n * Deduplicate, score, threshold-filter, and sort evidence items under one\n * unified policy.\n *\n * **Stage order** (matches every existing pipeline's rank/dedupe function):\n * 1. **dedup** by `id` + normalized content (first-seen wins). The dedup\n * key uses transformed content if `transformContent` is declared.\n * 2. **score** each surviving item on its ORIGINAL content (the transform\n * does not influence the score).\n * 3. **threshold-filter**: drop items with `rank < rankThreshold` (if\n * declared).\n * 4. **sort**: `rank DESC` → `turnIndex` (direction-configurable) →\n * tertiary tiebreaker (`score DESC` for relevance pipelines,\n * `content.localeCompare` for chronological pipelines).\n *\n * This function does NOT slice (`maxResults`), budget, or format — those\n * stages remain per-tier because they interact with per-tier metadata\n * insertion. The issue's Solution describes a future `insertMetadata` hook\n * that will make budget-adjustment uniform; that lands in the per-tier\n * migration PRs.\n *\n * @example\n * // Relevance-ranked pipeline (targeted-fact shape):\n * unifiedDedupeAndRank(items, {\n * query,\n * intents: [],\n * scoreEvidence: (item, q) => scoreTargetedFact(item, q),\n * transformContent: (content) => appendNormalizedNumericCues(content),\n * // turnIndexSortDirection defaults to \"desc\"\n * });\n *\n * @example\n * // Chronological pipeline (event-order shape):\n * unifiedDedupeAndRank(items, {\n * query,\n * intents: [],\n * scoreEvidence: (item, q) => scoreEventOrder(item, q),\n * transformContent: (content) => appendChronologicalCues(content, query),\n * rankThreshold: 6, // declared, not inlined\n * turnIndexSortDirection: \"asc\",\n * });\n */\nexport function unifiedDedupeAndRank<TIntent>(\n items: readonly EvidencePackItem[],\n config: UnifiedRankConfig<TIntent>,\n): RankedEvidenceItem[] {\n const transformContent = config.transformContent ?? ((content: string) => content);\n const direction: TurnIndexSortDirection = config.turnIndexSortDirection ?? \"desc\";\n const dedupByContent = config.dedupByContent !== false;\n\n // Stage 1: dedup by id (+ normalized transformed content when enabled).\n // First-seen wins, matching every existing pipeline. Event-order opts out\n // of content dedup (dedupByContent: false) because it keeps distinct turns\n // even when two turns share the same cue-appended body.\n const seenIds = new Set<string>();\n const seenContent = new Set<string>();\n const survivors: Array<{ original: EvidencePackItem; transformedContent: string }> = [];\n\n for (const item of items) {\n const id = resolveItemId(item);\n if (id && seenIds.has(id)) continue;\n\n const transformedContent = transformContent(item.content, config.intents);\n if (dedupByContent) {\n const contentKey = transformedContent.toLowerCase().replace(/\\s+/g, \" \").trim();\n if (seenContent.has(contentKey)) continue;\n seenContent.add(contentKey);\n }\n if (id) seenIds.add(id);\n survivors.push({ original: item, transformedContent });\n }\n\n // Stage 2: score on ORIGINAL content (transforms don't influence the score).\n const scored: RankedEvidenceItem[] = survivors.map(({ original, transformedContent }) => ({\n ...original,\n content: transformedContent,\n rank: config.scoreEvidence(original, config.query, config.intents),\n }));\n\n // Stage 3: threshold-filter (declared, not inlined).\n const filtered =\n typeof config.rankThreshold === \"number\"\n ? scored.filter((item) => item.rank >= (config.rankThreshold as number))\n : scored;\n\n // Stage 4: sort.\n // rank is ALWAYS DESC (higher rank first).\n // turnIndex direction is configurable: DESC (relevance) or ASC (chronology).\n // The tertiary tiebreaker follows the direction:\n // DESC → score DESC; ASC → content.localeCompare.\n return filtered.sort(makeComparator(direction));\n}\n\n/**\n * Build the sort comparator for the configured direction. Extracted so the\n * comparator's two shapes (DESC / ASC) can be tested independently and so\n * the direction divergence is visible in ONE place.\n */\nfunction makeComparator(\n direction: TurnIndexSortDirection,\n): (left: RankedEvidenceItem, right: RankedEvidenceItem) => number {\n if (direction === \"asc\") {\n // Chronological (event-order): rank DESC → turnIndex ASC → content localeCompare.\n // Matches event-order-recall.ts:159-164 (rankedByScore sort) byte-for-byte.\n return (left, right) => {\n if (right.rank !== left.rank) return right.rank - left.rank;\n const leftTurn =\n typeof left.turnIndex === \"number\"\n ? left.turnIndex\n : UNDEFINED_TURN_INDEX_ASC_SENTINEL;\n const rightTurn =\n typeof right.turnIndex === \"number\"\n ? right.turnIndex\n : UNDEFINED_TURN_INDEX_ASC_SENTINEL;\n if (leftTurn !== rightTurn) return leftTurn - rightTurn;\n return left.content.localeCompare(right.content);\n };\n }\n // Relevance-ranked (targeted-fact, response-guidance):\n // rank DESC → turnIndex DESC → score DESC.\n // Matches targeted-fact-recall.ts:239-245 and response-guidance-recall.ts:374-380\n // byte-for-byte.\n return (left, right) => {\n if (right.rank !== left.rank) return right.rank - left.rank;\n const leftTurn =\n typeof left.turnIndex === \"number\"\n ? left.turnIndex\n : UNDEFINED_TURN_INDEX_DESC_SENTINEL;\n const rightTurn =\n typeof right.turnIndex === \"number\"\n ? right.turnIndex\n : UNDEFINED_TURN_INDEX_DESC_SENTINEL;\n if (rightTurn !== leftTurn) return rightTurn - leftTurn;\n return (right.score ?? 0) - (left.score ?? 0);\n };\n}\n\n\n/**\n * Resolve an evidence item's id. Falls back to `sessionId:turnIndex` when\n * `id` is absent — mirrors every existing pipeline's fallback and\n * `evidence-pack.ts`'s `evidenceItemFallbackId`.\n */\nfunction resolveItemId(item: EvidencePackItem): string | undefined {\n if (item.id) return item.id;\n if (item.sessionId && typeof item.turnIndex === \"number\") {\n return `${item.sessionId}:${item.turnIndex}`;\n }\n return undefined;\n}\n"],"mappings":";;;AAuIA,IAAM,qCAAqC;AAO3C,IAAM,oCAAoC,OAAO;AA4C1C,SAAS,qBACd,OACA,QACsB;AACtB,QAAM,mBAAmB,OAAO,qBAAqB,CAAC,YAAoB;AAC1E,QAAM,YAAoC,OAAO,0BAA0B;AAC3E,QAAM,iBAAiB,OAAO,mBAAmB;AAMjD,QAAM,UAAU,oBAAI,IAAY;AAChC,QAAM,cAAc,oBAAI,IAAY;AACpC,QAAM,YAA+E,CAAC;AAEtF,aAAW,QAAQ,OAAO;AACxB,UAAM,KAAK,cAAc,IAAI;AAC7B,QAAI,MAAM,QAAQ,IAAI,EAAE,EAAG;AAE3B,UAAM,qBAAqB,iBAAiB,KAAK,SAAS,OAAO,OAAO;AACxE,QAAI,gBAAgB;AAClB,YAAM,aAAa,mBAAmB,YAAY,EAAE,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAC9E,UAAI,YAAY,IAAI,UAAU,EAAG;AACjC,kBAAY,IAAI,UAAU;AAAA,IAC5B;AACA,QAAI,GAAI,SAAQ,IAAI,EAAE;AACtB,cAAU,KAAK,EAAE,UAAU,MAAM,mBAAmB,CAAC;AAAA,EACvD;AAGA,QAAM,SAA+B,UAAU,IAAI,CAAC,EAAE,UAAU,mBAAmB,OAAO;AAAA,IACxF,GAAG;AAAA,IACH,SAAS;AAAA,IACT,MAAM,OAAO,cAAc,UAAU,OAAO,OAAO,OAAO,OAAO;AAAA,EACnE,EAAE;AAGF,QAAM,WACJ,OAAO,OAAO,kBAAkB,WAC5B,OAAO,OAAO,CAAC,SAAS,KAAK,QAAS,OAAO,aAAwB,IACrE;AAON,SAAO,SAAS,KAAK,eAAe,SAAS,CAAC;AAChD;AAOA,SAAS,eACP,WACiE;AACjE,MAAI,cAAc,OAAO;AAGvB,WAAO,CAAC,MAAM,UAAU;AACtB,UAAI,MAAM,SAAS,KAAK,KAAM,QAAO,MAAM,OAAO,KAAK;AACvD,YAAM,WACJ,OAAO,KAAK,cAAc,WACtB,KAAK,YACL;AACN,YAAM,YACJ,OAAO,MAAM,cAAc,WACvB,MAAM,YACN;AACN,UAAI,aAAa,UAAW,QAAO,WAAW;AAC9C,aAAO,KAAK,QAAQ,cAAc,MAAM,OAAO;AAAA,IACjD;AAAA,EACF;AAKA,SAAO,CAAC,MAAM,UAAU;AACtB,QAAI,MAAM,SAAS,KAAK,KAAM,QAAO,MAAM,OAAO,KAAK;AACvD,UAAM,WACJ,OAAO,KAAK,cAAc,WACtB,KAAK,YACL;AACN,UAAM,YACJ,OAAO,MAAM,cAAc,WACvB,MAAM,YACN;AACN,QAAI,cAAc,SAAU,QAAO,YAAY;AAC/C,YAAQ,MAAM,SAAS,MAAM,KAAK,SAAS;AAAA,EAC7C;AACF;AAQA,SAAS,cAAc,MAA4C;AACjE,MAAI,KAAK,GAAI,QAAO,KAAK;AACzB,MAAI,KAAK,aAAa,OAAO,KAAK,cAAc,UAAU;AACxD,WAAO,GAAG,KAAK,SAAS,IAAI,KAAK,SAAS;AAAA,EAC5C;AACA,SAAO;AACT;","names":[]}
@@ -2,19 +2,19 @@ import {
2
2
  createConversationIndexRuntime,
3
3
  createConversationSearchBackend,
4
4
  createSearchBackend
5
- } from "../chunk-2KAYTPPT.js";
5
+ } from "../chunk-JPETDXED.js";
6
+ import "../chunk-5CEJH5ZN.js";
6
7
  import "../chunk-WRFKZEO6.js";
7
8
  import "../chunk-CYEPCZN5.js";
8
9
  import "../chunk-LQ6JI4VH.js";
9
10
  import "../chunk-SANZHXY2.js";
10
- import "../chunk-EHISUJFN.js";
11
- import "../chunk-5CEJH5ZN.js";
12
11
  import "../chunk-AER6MT24.js";
12
+ import "../chunk-EHISUJFN.js";
13
13
  import "../chunk-CINZGPSJ.js";
14
- import "../chunk-DCWIQFNA.js";
14
+ import "../chunk-T422SYM6.js";
15
+ import "../chunk-SJHM6I4J.js";
15
16
  import "../chunk-XBZQRZ6G.js";
16
17
  import "../chunk-KCQA46NR.js";
17
- import "../chunk-SJHM6I4J.js";
18
18
  import "../chunk-K43PI6DQ.js";
19
19
  import "../chunk-YNQ6DFSV.js";
20
20
  import "../chunk-O75CRYGF.js";
@@ -2,7 +2,10 @@ import {
2
2
  createConversationIndexRuntime,
3
3
  createConversationSearchBackend,
4
4
  createSearchBackend
5
- } from "../chunk-2KAYTPPT.js";
5
+ } from "../chunk-JPETDXED.js";
6
+ import {
7
+ LanceDbBackend
8
+ } from "../chunk-5CEJH5ZN.js";
6
9
  import {
7
10
  MeilisearchBackend
8
11
  } from "../chunk-WRFKZEO6.js";
@@ -15,20 +18,17 @@ import {
15
18
  import {
16
19
  RemoteSearchBackend
17
20
  } from "../chunk-SANZHXY2.js";
18
- import {
19
- EmbedHelper
20
- } from "../chunk-EHISUJFN.js";
21
- import {
22
- LanceDbBackend
23
- } from "../chunk-5CEJH5ZN.js";
24
21
  import {
25
22
  scanMemoryDir
26
23
  } from "../chunk-AER6MT24.js";
24
+ import {
25
+ EmbedHelper
26
+ } from "../chunk-EHISUJFN.js";
27
27
  import "../chunk-CINZGPSJ.js";
28
- import "../chunk-DCWIQFNA.js";
28
+ import "../chunk-T422SYM6.js";
29
+ import "../chunk-SJHM6I4J.js";
29
30
  import "../chunk-XBZQRZ6G.js";
30
31
  import "../chunk-KCQA46NR.js";
31
- import "../chunk-SJHM6I4J.js";
32
32
  import "../chunk-K43PI6DQ.js";
33
33
  import "../chunk-YNQ6DFSV.js";
34
34
  import "../chunk-O75CRYGF.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "9.3.688",
3
+ "version": "9.3.689",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -2931,7 +2931,7 @@
2931
2931
  "core"
2932
2932
  ],
2933
2933
  "peerDependencies": {
2934
- "@remnic/coding-graph": "^9.3.688"
2934
+ "@remnic/coding-graph": "^9.3.689"
2935
2935
  },
2936
2936
  "peerDependenciesMeta": {
2937
2937
  "@remnic/coding-graph": {
@@ -0,0 +1,269 @@
1
+ // Issue #1539 PR2 — unit tests for the recall pipeline spine module.
2
+ //
3
+ // These tests verify `unifiedDedupeAndRank` produces the correct results for
4
+ // each declared divergence dimension, WITHOUT changing any existing pipeline.
5
+ // PRs 3–6 will migrate each pipeline to call this function; at that point the
6
+ // characterization snapshots (tests/recall-pipeline-unified.test.ts) verify
7
+ // end-to-end byte-for-byte parity.
8
+
9
+ import assert from "node:assert/strict";
10
+ import test from "node:test";
11
+
12
+ import type { EvidencePackItem } from "./evidence-pack.js";
13
+ import {
14
+ unifiedDedupeAndRank,
15
+ type RankedEvidenceItem,
16
+ } from "./recall-pipeline-stages.js";
17
+
18
+ const NO_INTENTS: never[] = [];
19
+ const constantScorer = (_item: EvidencePackItem): number => 10;
20
+
21
+ function item(
22
+ turnIndex: number,
23
+ content: string,
24
+ overrides: Partial<EvidencePackItem> = {},
25
+ ): EvidencePackItem {
26
+ return {
27
+ id: `s1:${turnIndex}`,
28
+ sessionId: "s1",
29
+ turnIndex,
30
+ role: "user",
31
+ content,
32
+ ...overrides,
33
+ };
34
+ }
35
+
36
+ test("unifiedDedupeAndRank: dedup collapses identical ids", () => {
37
+ const items = [
38
+ item(3, "Content A"),
39
+ item(3, "Content A"), // same id → deduped
40
+ ];
41
+ const result = unifiedDedupeAndRank(items, {
42
+ query: "q",
43
+ intents: NO_INTENTS,
44
+ scoreEvidence: constantScorer,
45
+ });
46
+ assert.equal(result.length, 1);
47
+ assert.equal(result[0]?.turnIndex, 3);
48
+ });
49
+
50
+ test("unifiedDedupeAndRank: dedup collapses identical normalized content under different ids", () => {
51
+ const items = [
52
+ item(10, "My monthly expenses are $2,400."),
53
+ item(11, "MY MONTHLY EXPENSES ARE $2,400."), // same normalized content
54
+ ];
55
+ const result = unifiedDedupeAndRank(items, {
56
+ query: "q",
57
+ intents: NO_INTENTS,
58
+ scoreEvidence: constantScorer,
59
+ });
60
+ assert.equal(result.length, 1, "expected content dedup to collapse the two items");
61
+ assert.equal(result[0]?.turnIndex, 10, "first-seen wins");
62
+ });
63
+
64
+ test("unifiedDedupeAndRank: DESC sort (default) orders turnIndex descending on score ties", () => {
65
+ const items = [
66
+ item(2, "Oldest"),
67
+ item(5, "Middle"),
68
+ item(9, "Newest"),
69
+ ];
70
+ const result = unifiedDedupeAndRank(items, {
71
+ query: "q",
72
+ intents: NO_INTENTS,
73
+ scoreEvidence: constantScorer, // all tied → turnIndex DESC
74
+ });
75
+ const turns = result.map((r) => r.turnIndex);
76
+ assert.deepEqual(turns, [9, 5, 2]);
77
+ });
78
+
79
+ test("unifiedDedupeAndRank: ASC sort orders turnIndex ascending on score ties", () => {
80
+ const items = [
81
+ item(30, "Latest"),
82
+ item(10, "Earliest"),
83
+ item(20, "Middle"),
84
+ ];
85
+ const result = unifiedDedupeAndRank(items, {
86
+ query: "q",
87
+ intents: NO_INTENTS,
88
+ scoreEvidence: constantScorer,
89
+ turnIndexSortDirection: "asc",
90
+ });
91
+ const turns = result.map((r) => r.turnIndex);
92
+ assert.deepEqual(turns, [10, 20, 30]);
93
+ });
94
+
95
+ test("unifiedDedupeAndRank: rank primary key is always DESC regardless of turnIndex direction", () => {
96
+ const items = [
97
+ item(1, "Low rank", { score: 0 }),
98
+ item(2, "High rank", { score: 0 }),
99
+ ];
100
+ const result = unifiedDedupeAndRank(items, {
101
+ query: "q",
102
+ intents: NO_INTENTS,
103
+ scoreEvidence: (i) => (i.turnIndex === 2 ? 100 : 1),
104
+ turnIndexSortDirection: "asc",
105
+ });
106
+ // rank DESC wins over turnIndex ASC: turn 2 (rank 100) comes first despite ASC.
107
+ assert.equal(result[0]?.turnIndex, 2);
108
+ assert.equal(result[1]?.turnIndex, 1);
109
+ });
110
+
111
+ test("unifiedDedupeAndRank: rankThreshold drops items below the declared threshold", () => {
112
+ const items = [
113
+ item(1, "Weak", { score: 0 }),
114
+ item(2, "Strong", { score: 0 }),
115
+ item(3, "Medium", { score: 0 }),
116
+ ];
117
+ const result = unifiedDedupeAndRank(items, {
118
+ query: "q",
119
+ intents: NO_INTENTS,
120
+ scoreEvidence: (i) => {
121
+ if (i.turnIndex === 1) return 3;
122
+ if (i.turnIndex === 2) return 10;
123
+ return 6;
124
+ },
125
+ rankThreshold: 6,
126
+ });
127
+ const turns = result.map((r) => r.turnIndex).sort((a, b) => (a ?? 0) - (b ?? 0));
128
+ assert.deepEqual(turns, [2, 3], "turn 1 (rank 3) is below threshold 6 and dropped");
129
+ });
130
+
131
+ test("unifiedDedupeAndRank: transformContent is applied to output but NOT to scorer input", () => {
132
+ const items = [item(5, "original content")];
133
+ let scorerSawTransformed = false;
134
+ const result = unifiedDedupeAndRank(items, {
135
+ query: "q",
136
+ intents: NO_INTENTS,
137
+ scoreEvidence: (i) => {
138
+ if (i.content.includes("APPENDED CUE")) scorerSawTransformed = true;
139
+ return 5;
140
+ },
141
+ transformContent: (content) => `${content}\nAPPENDED CUE`,
142
+ });
143
+ assert.equal(scorerSawTransformed, false, "scorer must see ORIGINAL content");
144
+ assert.ok(result[0]?.content.includes("APPENDED CUE"), "output must have transformed content");
145
+ });
146
+
147
+ test("unifiedDedupeAndRank: undefined turnIndex sorts to the bottom of DESC (-1 sentinel)", () => {
148
+ const items = [
149
+ item(5, "Has turn"),
150
+ { id: "s1:x", sessionId: "s1", role: "user", content: "No turn" }, // no turnIndex
151
+ ];
152
+ const result = unifiedDedupeAndRank(items, {
153
+ query: "q",
154
+ intents: NO_INTENTS,
155
+ scoreEvidence: constantScorer,
156
+ // default DESC
157
+ });
158
+ assert.equal(result[1]?.id, "s1:x", "undefined-turnIndex item sorts last in DESC");
159
+ });
160
+
161
+ test("unifiedDedupeAndRank: undefined turnIndex sorts to the bottom of ASC (MAX sentinel)", () => {
162
+ const items = [
163
+ item(5, "Has turn"),
164
+ { id: "s1:x", sessionId: "s1", role: "user", content: "No turn" },
165
+ ];
166
+ const result = unifiedDedupeAndRank(items, {
167
+ query: "q",
168
+ intents: NO_INTENTS,
169
+ scoreEvidence: constantScorer,
170
+ turnIndexSortDirection: "asc",
171
+ });
172
+ assert.equal(result[1]?.id, "s1:x", "undefined-turnIndex item sorts last in ASC");
173
+ });
174
+
175
+ test("unifiedDedupeAndRank: DESC tertiary tiebreaker is score DESC", () => {
176
+ // Same rank (all tied via constantScorer) AND same turnIndex → score breaks the tie.
177
+ const items = [
178
+ item(5, "Low score", { score: 10 }),
179
+ item(5, "High score", { score: 90 }), // same turn, deduped by content? No — different content
180
+ ];
181
+ // Wait — both have turn 5 so same id "s1:5" → second is deduped. Use different sessions.
182
+ const itemsDistinct: EvidencePackItem[] = [
183
+ { id: "s1:5", sessionId: "s1", turnIndex: 5, role: "user", content: "A", score: 10 },
184
+ { id: "s2:5", sessionId: "s2", turnIndex: 5, role: "user", content: "B", score: 90 },
185
+ ];
186
+ const result = unifiedDedupeAndRank(itemsDistinct, {
187
+ query: "q",
188
+ intents: NO_INTENTS,
189
+ scoreEvidence: constantScorer, // rank tied → turnIndex tied → score DESC
190
+ });
191
+ assert.equal(result[0]?.id, "s2:5", "higher score (90) ranks first on DESC tertiary");
192
+ assert.equal(result[1]?.id, "s1:5");
193
+ });
194
+
195
+ test("unifiedDedupeAndRank: ASC tertiary tiebreaker is content.localeCompare", () => {
196
+ const items: EvidencePackItem[] = [
197
+ { id: "s2:5", sessionId: "s2", turnIndex: 5, role: "user", content: "Banana" },
198
+ { id: "s1:5", sessionId: "s1", turnIndex: 5, role: "user", content: "Apple" },
199
+ ];
200
+ const result = unifiedDedupeAndRank(items, {
201
+ query: "q",
202
+ intents: NO_INTENTS,
203
+ scoreEvidence: constantScorer, // rank tied → turnIndex tied → content localeCompare
204
+ turnIndexSortDirection: "asc",
205
+ });
206
+ assert.equal(result[0]?.content, "Apple", "localeCompare ASC: Apple < Banana");
207
+ assert.equal(result[1]?.content, "Banana");
208
+ });
209
+
210
+ test("unifiedDedupeAndRank: RankedEvidenceItem carries the computed rank", () => {
211
+ const items = [item(1, "content")];
212
+ const result: RankedEvidenceItem[] = unifiedDedupeAndRank(items, {
213
+ query: "q",
214
+ intents: NO_INTENTS,
215
+ scoreEvidence: () => 42,
216
+ });
217
+ assert.equal(result[0]?.rank, 42);
218
+ });
219
+
220
+ test("unifiedDedupeAndRank: fallback id uses sessionId:turnIndex when id is absent", () => {
221
+ const items: EvidencePackItem[] = [
222
+ { sessionId: "s1", turnIndex: 7, role: "user", content: "No explicit id" },
223
+ { sessionId: "s1", turnIndex: 7, role: "user", content: "Same fallback id → deduped" },
224
+ ];
225
+ const result = unifiedDedupeAndRank(items, {
226
+ query: "q",
227
+ intents: NO_INTENTS,
228
+ scoreEvidence: constantScorer,
229
+ });
230
+ assert.equal(result.length, 1, "fallback id dedup must collapse the two items");
231
+ });
232
+
233
+ test("unifiedDedupeAndRank: dedupByContent false keeps distinct ids with identical content (event-order shape)", () => {
234
+ // Event-order's rankAndSelectEventOrderItems deduplicates by turn id only and
235
+ // keeps distinct turns even when two turns share the same cue-appended body.
236
+ // The spine must express that as a declared config field so PR 6's migration
237
+ // does not silently drop valid turns (cursor bugbot a4299851).
238
+ const items: EvidencePackItem[] = [
239
+ item(1, "What time is it?", { id: "s1:1" }),
240
+ item(5, "What time is it?", { id: "s1:5" }),
241
+ ];
242
+ const result = unifiedDedupeAndRank(items, {
243
+ query: "q",
244
+ intents: NO_INTENTS,
245
+ scoreEvidence: constantScorer,
246
+ dedupByContent: false,
247
+ });
248
+ assert.equal(result.length, 2, "distinct ids with identical content must both survive when dedupByContent is false");
249
+ });
250
+
251
+ test("unifiedDedupeAndRank: dedupByContent true (default) still collapses identical content under different ids", () => {
252
+ const items: EvidencePackItem[] = [
253
+ item(1, "Duplicate body", { id: "s1:1" }),
254
+ item(2, "Duplicate body", { id: "s1:2" }),
255
+ ];
256
+ const resultDefault = unifiedDedupeAndRank(items, {
257
+ query: "q",
258
+ intents: NO_INTENTS,
259
+ scoreEvidence: constantScorer,
260
+ });
261
+ assert.equal(resultDefault.length, 1, "default dedupByContent collapses identical content");
262
+ const resultExplicit = unifiedDedupeAndRank(items, {
263
+ query: "q",
264
+ intents: NO_INTENTS,
265
+ scoreEvidence: constantScorer,
266
+ dedupByContent: true,
267
+ });
268
+ assert.equal(resultExplicit.length, 1, "explicit dedupByContent: true collapses identical content");
269
+ });