recallnest 2.2.0 → 2.2.1

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 (232) hide show
  1. package/.env +4 -0
  2. package/config.json +55 -0
  3. package/logs/daily-recall.error.log +0 -0
  4. package/logs/daily-recall.log +30 -0
  5. package/logs/ingest-2026-04-11.log +110 -0
  6. package/logs/ingest-2026-04-12.log +90 -0
  7. package/logs/launchagent-stderr.log +0 -0
  8. package/logs/launchagent-stdout.log +0 -0
  9. package/package.json +1 -1
  10. package/.claude-plugin/CLAUDE.md +0 -29
  11. package/.claude-plugin/marketplace.json +0 -18
  12. package/.dockerignore +0 -11
  13. package/.github/workflows/ci.yml +0 -28
  14. package/.mcp.json +0 -9
  15. package/CHANGELOG.md +0 -51
  16. package/DEMO.md +0 -94
  17. package/Dockerfile +0 -20
  18. package/EVAL.md +0 -89
  19. package/FAILURES.md +0 -75
  20. package/OPERATIONS.md +0 -59
  21. package/ROADMAP.md +0 -245
  22. package/SKILL.md +0 -250
  23. package/assets/dashboard.png +0 -0
  24. package/assets/knowledge-graph.png +0 -0
  25. package/assets/recallnest-workbench.png +0 -0
  26. package/assets/screenshots/ui-full.png +0 -0
  27. package/assets/screenshots/ui-overview.png +0 -0
  28. package/assets/screenshots/ui-search.png +0 -0
  29. package/assets/ui/app.js +0 -1031
  30. package/assets/ui/index.html +0 -224
  31. package/assets/ui/styles.css +0 -781
  32. package/assets/wechat-qr.jpg +0 -0
  33. package/bun.lock +0 -337
  34. package/daily-reflections/2026-03-05.md +0 -15
  35. package/daily-reflections/2026-03-06.md +0 -15
  36. package/daily-reflections/2026-03-07.md +0 -7
  37. package/daily-reflections/2026-03-08.md +0 -34
  38. package/daily-reflections/2026-03-09.md +0 -35
  39. package/daily-reflections/2026-03-10.md +0 -36
  40. package/daily-reflections/2026-03-11.md +0 -35
  41. package/daily-reflections/2026-03-12.md +0 -36
  42. package/daily-reflections/2026-03-13.md +0 -35
  43. package/daily-reflections/2026-03-14.md +0 -35
  44. package/daily-reflections/2026-03-15.md +0 -35
  45. package/daily-reflections/2026-03-16.md +0 -41
  46. package/daily-reflections/2026-03-17.md +0 -10
  47. package/daily-reflections/2026-03-18.md +0 -10
  48. package/daily-reflections/2026-03-19.md +0 -10
  49. package/daily-reflections/2026-03-20.md +0 -10
  50. package/daily-reflections/2026-03-21.md +0 -10
  51. package/daily-reflections/2026-03-22.md +0 -10
  52. package/daily-reflections/2026-03-23.md +0 -10
  53. package/daily-reflections/2026-03-24.md +0 -10
  54. package/daily-reflections/2026-03-25.md +0 -32
  55. package/daily-reflections/2026-03-26.md +0 -37
  56. package/daily-reflections/2026-03-27.md +0 -35
  57. package/daily-reflections/2026-03-28.md +0 -35
  58. package/daily-reflections/2026-03-29.md +0 -35
  59. package/daily-reflections/2026-03-30.md +0 -36
  60. package/daily-reflections/2026-03-31.md +0 -35
  61. package/daily-reflections/2026-04-01.md +0 -35
  62. package/daily-reflections/2026-04-02.md +0 -35
  63. package/daily-reflections/2026-04-03.md +0 -37
  64. package/daily-reflections/2026-04-04.md +0 -37
  65. package/daily-reflections/2026-04-05.md +0 -35
  66. package/daily-reflections/2026-04-06.md +0 -36
  67. package/daily-reflections/2026-04-07.md +0 -35
  68. package/daily-reflections/2026-04-08.md +0 -35
  69. package/daily-reflections/2026-04-12.md +0 -35
  70. package/data/alias-map.example.json +0 -22
  71. package/docs/api-reference.md +0 -1291
  72. package/docs/architecture.md +0 -168
  73. package/docs/memory-boundary-contract.md +0 -226
  74. package/docs/memory-categories.md +0 -119
  75. package/docs/pipeline-audit-ultramemory.md +0 -177
  76. package/docs/plans/2026-03-08-query-expansion.md +0 -270
  77. package/docs/plans/2026-03-16-continuity-layer.md +0 -196
  78. package/docs/plans/2026-04-01-recall-boost.md +0 -100
  79. package/docs/plans/mcp-tiering-plan.md +0 -126
  80. package/docs/research/recall-quality-audit-2026-03-22.md +0 -153
  81. package/docs/self-evolution.md +0 -198
  82. package/docs/superpowers/plans/2026-03-19-ingest-pipeline-upgrade.md +0 -782
  83. package/docs/superpowers/plans/2026-04-11-constructive-retrieval-emotion.md +0 -1195
  84. package/docs/superpowers/specs/2026-03-19-ingest-pipeline-upgrade-design.md +0 -77
  85. package/docs/superpowers/specs/2026-03-23-pull-claude-desktop-design.md +0 -95
  86. package/docs/superpowers/specs/2026-04-11-constructive-retrieval-emotion-design.md +0 -398
  87. package/eval/continuity/results-2026-03-16.md +0 -117
  88. package/eval/continuity/results-2026-03-19.md +0 -453
  89. package/eval/continuity/runbook.md +0 -110
  90. package/eval/continuity/seed-cases.md +0 -54
  91. package/eval/reports/2026-03-06-abstract-query-baseline.md +0 -96
  92. package/eval/reports/2026-03-06-aws-ssh-baseline.md +0 -82
  93. package/eval/reports/2026-03-06-baseline.md +0 -82
  94. package/eval/reports/query-expansion.md +0 -138
  95. package/glama.json +0 -6
  96. package/lm +0 -19
  97. package/plan-philosophy-upgrades.md +0 -363
  98. package/plan-product-upgrades.md +0 -155
  99. package/plan-v1.2-distributable.md +0 -105
  100. package/plan.md +0 -140
  101. package/research-memory-evolution.md +0 -440
  102. package/research-rl-agent-memory.md +0 -330
  103. package/scripts/archive-distilled-junk.ts +0 -116
  104. package/scripts/backfill-anchors.ts +0 -130
  105. package/scripts/backfill-l0l1l2.ts +0 -98
  106. package/scripts/blind-scan.ts +0 -588
  107. package/scripts/cleanup-step1-exact-dups.ts +0 -117
  108. package/scripts/cleanup-step2-template-dups.ts +0 -113
  109. package/scripts/cleanup-step3-stale-content.ts +0 -149
  110. package/scripts/cleanup-step4-orphan-scopes.ts +0 -131
  111. package/scripts/delete-distilled-junk.ts +0 -88
  112. package/scripts/diagnose-vector-search.ts +0 -132
  113. package/scripts/distill-facts.ts +0 -305
  114. package/scripts/health-check.ts +0 -343
  115. package/scripts/incremental-ingest.sh +0 -71
  116. package/scripts/migrate-language.ts +0 -75
  117. package/scripts/mlp-health-check.ts +0 -382
  118. package/scripts/pull-claude-desktop.ts +0 -515
  119. package/scripts/re-ingest-cc.sh +0 -66
  120. package/scripts/rebalance-memory-health.ts +0 -181
  121. package/scripts/run-desktop-ingest.sh +0 -11
  122. package/scripts/start-server.sh +0 -12
  123. package/scripts/verify-emotion-decay.ts +0 -148
  124. package/scripts/viz-dashboard.html +0 -423
  125. package/scripts/viz-export.ts +0 -703
  126. package/src/__tests__/access-tracker-novelty.test.ts +0 -228
  127. package/src/__tests__/activity-counter.test.ts +0 -96
  128. package/src/__tests__/admission-control.test.ts +0 -206
  129. package/src/__tests__/anchor-generator.test.ts +0 -67
  130. package/src/__tests__/auto-consolidation.test.ts +0 -168
  131. package/src/__tests__/auto-recall.test.ts +0 -131
  132. package/src/__tests__/babel-integration.test.ts +0 -139
  133. package/src/__tests__/batch-dedup.test.ts +0 -65
  134. package/src/__tests__/capture-engine.test.ts +0 -1144
  135. package/src/__tests__/capture-heuristic.test.ts +0 -171
  136. package/src/__tests__/cascade-forget.test.ts +0 -210
  137. package/src/__tests__/category-min-scores.test.ts +0 -33
  138. package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
  139. package/src/__tests__/circuit-breaker.test.ts +0 -99
  140. package/src/__tests__/cluster-consolidation.test.ts +0 -712
  141. package/src/__tests__/confidence-metadata.test.ts +0 -125
  142. package/src/__tests__/confidence-tracker.test.ts +0 -249
  143. package/src/__tests__/conflict-advisor.test.ts +0 -206
  144. package/src/__tests__/conflict-escalation.test.ts +0 -149
  145. package/src/__tests__/conflict-lifecycle.test.ts +0 -83
  146. package/src/__tests__/conflict-output.test.ts +0 -85
  147. package/src/__tests__/conflict-store.test.ts +0 -374
  148. package/src/__tests__/consolidation-engine.test.ts +0 -181
  149. package/src/__tests__/constructive-retrieval.test.ts +0 -509
  150. package/src/__tests__/context-collapse-renderer.test.ts +0 -214
  151. package/src/__tests__/context-composer-pins.test.ts +0 -64
  152. package/src/__tests__/context-composer-task-selection.test.ts +0 -24
  153. package/src/__tests__/context-reconstructor.test.ts +0 -65
  154. package/src/__tests__/context-renderer.test.ts +0 -91
  155. package/src/__tests__/continuity-eval.test.ts +0 -275
  156. package/src/__tests__/continuity-schema.test.ts +0 -97
  157. package/src/__tests__/conversation-importer.test.ts +0 -692
  158. package/src/__tests__/core-recall-eval.test.ts +0 -235
  159. package/src/__tests__/core-summary.test.ts +0 -109
  160. package/src/__tests__/data-checkup.test.ts +0 -225
  161. package/src/__tests__/decay-exemption.test.ts +0 -84
  162. package/src/__tests__/dedup-actions.test.ts +0 -58
  163. package/src/__tests__/dedup-guard.test.ts +0 -39
  164. package/src/__tests__/deterministic-id.test.ts +0 -39
  165. package/src/__tests__/distill-lock.test.ts +0 -176
  166. package/src/__tests__/doctor.test.ts +0 -303
  167. package/src/__tests__/dream-pipeline.test.ts +0 -232
  168. package/src/__tests__/drill-down.test.ts +0 -108
  169. package/src/__tests__/embedder.test.ts +0 -122
  170. package/src/__tests__/emotion-decay.test.ts +0 -46
  171. package/src/__tests__/emotion-detector.test.ts +0 -56
  172. package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
  173. package/src/__tests__/emotion-retrieval.test.ts +0 -56
  174. package/src/__tests__/entity-resolver.test.ts +0 -58
  175. package/src/__tests__/ethics-layer.test.ts +0 -476
  176. package/src/__tests__/event-segmenter.test.ts +0 -153
  177. package/src/__tests__/feature-flags-integration.test.ts +0 -54
  178. package/src/__tests__/frequency-tracker.test.ts +0 -113
  179. package/src/__tests__/graph-export.test.ts +0 -489
  180. package/src/__tests__/hotness-blend.test.ts +0 -76
  181. package/src/__tests__/ingest.test.ts +0 -360
  182. package/src/__tests__/interference-detector.test.ts +0 -203
  183. package/src/__tests__/kg-extractor.test.ts +0 -184
  184. package/src/__tests__/kg-store.test.ts +0 -198
  185. package/src/__tests__/llm-consolidation.test.ts +0 -226
  186. package/src/__tests__/mcp-efficiency.test.ts +0 -288
  187. package/src/__tests__/memory-boundaries.test.ts +0 -237
  188. package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -243
  189. package/src/__tests__/memory-evolution.test.ts +0 -271
  190. package/src/__tests__/memory-health-rebalance.test.ts +0 -144
  191. package/src/__tests__/memory-lint.test.ts +0 -271
  192. package/src/__tests__/memory-output.test.ts +0 -215
  193. package/src/__tests__/multi-vector.test.ts +0 -242
  194. package/src/__tests__/narrative-architecture.test.ts +0 -456
  195. package/src/__tests__/pending-review.test.ts +0 -77
  196. package/src/__tests__/post-retrieval-filter.test.ts +0 -178
  197. package/src/__tests__/ppr-traversal.test.ts +0 -256
  198. package/src/__tests__/prediction-engine.test.ts +0 -349
  199. package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
  200. package/src/__tests__/preference-guard-smoke.test.ts +0 -211
  201. package/src/__tests__/preference-matcher.test.ts +0 -230
  202. package/src/__tests__/preference-slots.test.ts +0 -205
  203. package/src/__tests__/prospective-memory.test.ts +0 -283
  204. package/src/__tests__/query-entity-detector.test.ts +0 -171
  205. package/src/__tests__/query-expander-alias.test.ts +0 -89
  206. package/src/__tests__/query-expander.test.ts +0 -34
  207. package/src/__tests__/recall-governor.test.ts +0 -227
  208. package/src/__tests__/recall-mode.test.ts +0 -64
  209. package/src/__tests__/result-synthesizer.test.ts +0 -198
  210. package/src/__tests__/resume-context.test.ts +0 -4898
  211. package/src/__tests__/retrieval-trace.test.ts +0 -213
  212. package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
  213. package/src/__tests__/retroactive-boost.test.ts +0 -223
  214. package/src/__tests__/salience-scoring.test.ts +0 -106
  215. package/src/__tests__/scope-inventory.test.ts +0 -200
  216. package/src/__tests__/scope-policy.test.ts +0 -69
  217. package/src/__tests__/session-checkpoint.test.ts +0 -259
  218. package/src/__tests__/session-distiller.test.ts +0 -611
  219. package/src/__tests__/session-gc.test.ts +0 -215
  220. package/src/__tests__/skill-engine.test.ts +0 -546
  221. package/src/__tests__/skill-promotion.test.ts +0 -349
  222. package/src/__tests__/store-scope-audit.test.ts +0 -81
  223. package/src/__tests__/supersede-chain.test.ts +0 -154
  224. package/src/__tests__/temporal-parser.test.ts +0 -241
  225. package/src/__tests__/temporal-validity.test.ts +0 -160
  226. package/src/__tests__/term-registry.test.ts +0 -121
  227. package/src/__tests__/tool-output-compressor.test.ts +0 -133
  228. package/src/__tests__/topic-tag.test.ts +0 -113
  229. package/src/__tests__/trusted-memory.test.ts +0 -828
  230. package/src/__tests__/version-manager.test.ts +0 -213
  231. package/src/__tests__/workflow-observation.test.ts +0 -400
  232. package/src/__tests__/write-verifier.test.ts +0 -122
@@ -1,77 +0,0 @@
1
- import { describe, it, expect } from "bun:test";
2
- import {
3
- parseEvolution,
4
- patchEvolution,
5
- defaultEvolution,
6
- buildPendingReviewMetadata,
7
- isPendingReview,
8
- resolvePendingReview,
9
- isActiveMemory,
10
- } from "../memory-evolution.js";
11
-
12
- describe("HP-6: Pending review (delayed judgment)", () => {
13
- describe("buildPendingReviewMetadata", () => {
14
- it("marks entry as pending_review", () => {
15
- const meta = patchEvolution("{}", defaultEvolution());
16
- const result = buildPendingReviewMetadata(meta);
17
- const evo = parseEvolution(result);
18
- expect(evo.status).toBe("pending_review");
19
- });
20
-
21
- it("preserves other evolution fields", () => {
22
- const meta = patchEvolution("{}", { ...defaultEvolution(), accessCount: 5 });
23
- const result = buildPendingReviewMetadata(meta);
24
- const evo = parseEvolution(result);
25
- expect(evo.status).toBe("pending_review");
26
- expect(evo.accessCount).toBe(5);
27
- });
28
- });
29
-
30
- describe("isPendingReview", () => {
31
- it("returns true for pending_review status", () => {
32
- const meta = buildPendingReviewMetadata(patchEvolution("{}", defaultEvolution()));
33
- expect(isPendingReview(meta)).toBe(true);
34
- });
35
-
36
- it("returns false for active status", () => {
37
- const meta = patchEvolution("{}", defaultEvolution());
38
- expect(isPendingReview(meta)).toBe(false);
39
- });
40
-
41
- it("returns false for undefined", () => {
42
- expect(isPendingReview(undefined)).toBe(false);
43
- });
44
- });
45
-
46
- describe("resolvePendingReview", () => {
47
- it("transitions pending_review → active", () => {
48
- const meta = buildPendingReviewMetadata(patchEvolution("{}", defaultEvolution()));
49
- expect(parseEvolution(meta).status).toBe("pending_review");
50
-
51
- const resolved = resolvePendingReview(meta);
52
- expect(parseEvolution(resolved).status).toBe("active");
53
- });
54
- });
55
-
56
- describe("isActiveMemory includes pending_review", () => {
57
- it("active → true", () => {
58
- const meta = patchEvolution("{}", defaultEvolution());
59
- expect(isActiveMemory(meta)).toBe(true);
60
- });
61
-
62
- it("pending_review → true (participates in search)", () => {
63
- const meta = buildPendingReviewMetadata(patchEvolution("{}", defaultEvolution()));
64
- expect(isActiveMemory(meta)).toBe(true);
65
- });
66
-
67
- it("superseded → false", () => {
68
- const meta = patchEvolution("{}", { ...defaultEvolution(), status: "superseded" });
69
- expect(isActiveMemory(meta)).toBe(false);
70
- });
71
-
72
- it("archived → false", () => {
73
- const meta = patchEvolution("{}", { ...defaultEvolution(), status: "archived" });
74
- expect(isActiveMemory(meta)).toBe(false);
75
- });
76
- });
77
- });
@@ -1,178 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
-
3
- import { filterByRelevance, type FilterConfig } from "../post-retrieval-filter.js";
4
- import type { LLMClient } from "../llm-client.js";
5
- import type { RetrievalResult } from "../retriever.js";
6
-
7
- // ---------------------------------------------------------------------------
8
- // Helpers
9
- // ---------------------------------------------------------------------------
10
-
11
- function makeResult(id: string, text: string, score: number): RetrievalResult {
12
- return {
13
- entry: {
14
- id,
15
- text,
16
- vector: [],
17
- category: "events",
18
- scope: "test",
19
- importance: 0.5,
20
- timestamp: Date.now(),
21
- },
22
- score,
23
- sources: {},
24
- };
25
- }
26
-
27
- function makeMockLLM(response: boolean[] | null, shouldThrow = false): LLMClient {
28
- return {
29
- chatJson: async () => {
30
- if (shouldThrow) throw new Error("LLM failure");
31
- return response;
32
- },
33
- } as unknown as LLMClient;
34
- }
35
-
36
- // ---------------------------------------------------------------------------
37
- // Tests
38
- // ---------------------------------------------------------------------------
39
-
40
- describe("filterByRelevance", () => {
41
- it("returns empty array for empty results", async () => {
42
- const llm = makeMockLLM([]);
43
- const out = await filterByRelevance([], "some query", llm);
44
- expect(out).toEqual([]);
45
- });
46
-
47
- it("returns original results when query is empty", async () => {
48
- const results = [makeResult("a", "hello", 0.8)];
49
- const llm = makeMockLLM([true]);
50
- const out = await filterByRelevance(results, "", llm);
51
- expect(out).toEqual(results);
52
- });
53
-
54
- it("returns all when LLM marks all as relevant", async () => {
55
- const results = [
56
- makeResult("a", "TypeScript project setup", 0.9),
57
- makeResult("b", "Docker deployment notes", 0.85),
58
- ];
59
- const llm = makeMockLLM([true, true]);
60
- const out = await filterByRelevance(results, "project setup", llm);
61
- expect(out).toHaveLength(2);
62
- expect(out[0].entry.id).toBe("a");
63
- expect(out[1].entry.id).toBe("b");
64
- });
65
-
66
- it("filters out items LLM marks as irrelevant", async () => {
67
- const results = [
68
- makeResult("a", "TypeScript project setup", 0.9),
69
- makeResult("b", "Favorite pizza recipe", 0.85),
70
- makeResult("c", "Docker deployment notes", 0.8),
71
- ];
72
- const llm = makeMockLLM([true, false, true]);
73
- const out = await filterByRelevance(results, "project deployment", llm);
74
- expect(out).toHaveLength(2);
75
- expect(out[0].entry.id).toBe("a");
76
- expect(out[1].entry.id).toBe("c");
77
- });
78
-
79
- it("drops items below minScoreForFilter without LLM call", async () => {
80
- const results = [
81
- makeResult("a", "High score item", 0.9),
82
- makeResult("b", "Low score item", 0.3),
83
- makeResult("c", "Very low score", 0.1),
84
- ];
85
- // LLM only sees 1 item (the one above threshold)
86
- const llm = makeMockLLM([true]);
87
- const out = await filterByRelevance(results, "test query", llm);
88
- expect(out).toHaveLength(1);
89
- expect(out[0].entry.id).toBe("a");
90
- });
91
-
92
- it("returns all candidates when all are below minScoreForFilter", async () => {
93
- const results = [
94
- makeResult("a", "Low score A", 0.3),
95
- makeResult("b", "Low score B", 0.2),
96
- ];
97
- const llm = makeMockLLM([]);
98
- const out = await filterByRelevance(results, "test query", llm);
99
- expect(out).toHaveLength(0);
100
- });
101
-
102
- it("truncates to maxItems", async () => {
103
- const results = Array.from({ length: 15 }, (_, i) =>
104
- makeResult(`item-${i}`, `Memory item ${i}`, 0.9 - i * 0.01),
105
- );
106
- // LLM receives only 5 items, marks all as relevant
107
- const cfg: Partial<FilterConfig> = { maxItems: 5 };
108
- const llm = makeMockLLM([true, true, true, true, true]);
109
- const out = await filterByRelevance(results, "test query", llm, cfg);
110
- expect(out).toHaveLength(5);
111
- expect(out[0].entry.id).toBe("item-0");
112
- expect(out[4].entry.id).toBe("item-4");
113
- });
114
-
115
- it("returns candidates on LLM failure (graceful fallback)", async () => {
116
- const results = [
117
- makeResult("a", "Important memory", 0.9),
118
- makeResult("b", "Another memory", 0.85),
119
- ];
120
- const llm = makeMockLLM(null, true);
121
- const out = await filterByRelevance(results, "test query", llm);
122
- // Should return all candidates, not lose data
123
- expect(out).toHaveLength(2);
124
- expect(out[0].entry.id).toBe("a");
125
- });
126
-
127
- it("returns candidates when LLM returns non-array", async () => {
128
- const results = [
129
- makeResult("a", "Important memory", 0.9),
130
- ];
131
- const llm = makeMockLLM(null);
132
- const out = await filterByRelevance(results, "test query", llm);
133
- expect(out).toHaveLength(1);
134
- });
135
-
136
- it("uses l0_abstract from metadata when available", async () => {
137
- const result = makeResult("a", "Very long raw text that should not be used", 0.9);
138
- result.entry.metadata = JSON.stringify({ l0_abstract: "Short summary" });
139
- const calls: string[] = [];
140
- const llm = {
141
- chatJson: async (_sys: string, user: string) => {
142
- calls.push(user);
143
- return [true];
144
- },
145
- } as unknown as LLMClient;
146
-
147
- await filterByRelevance([result], "test", llm);
148
- expect(calls[0]).toContain("Short summary");
149
- expect(calls[0]).not.toContain("Very long raw text");
150
- });
151
-
152
- it("handles custom minScoreForFilter", async () => {
153
- const results = [
154
- makeResult("a", "High", 0.9),
155
- makeResult("b", "Medium", 0.6),
156
- makeResult("c", "Low", 0.4),
157
- ];
158
- const cfg: Partial<FilterConfig> = { minScoreForFilter: 0.65 };
159
- const llm = makeMockLLM([true]);
160
- const out = await filterByRelevance(results, "test", llm, cfg);
161
- expect(out).toHaveLength(1);
162
- expect(out[0].entry.id).toBe("a");
163
- });
164
-
165
- it("handles shorter LLM verdict array than candidates", async () => {
166
- const results = [
167
- makeResult("a", "Memory A", 0.9),
168
- makeResult("b", "Memory B", 0.85),
169
- makeResult("c", "Memory C", 0.8),
170
- ];
171
- // LLM returns fewer verdicts than items
172
- const llm = makeMockLLM([true, false]);
173
- const out = await filterByRelevance(results, "test", llm);
174
- // Only first item passes (index 0 = true, index 1 = false, index 2 = out of bounds)
175
- expect(out).toHaveLength(1);
176
- expect(out[0].entry.id).toBe("a");
177
- });
178
- });
@@ -1,256 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import {
3
- buildGraph,
4
- pprTraverse,
5
- pprFromTriples,
6
- edgeWeight,
7
- DEFAULT_PPR_CONFIG,
8
- } from "../ppr-traversal.js";
9
- import type { KGTriple, NeighborhoodResult } from "../kg-store.js";
10
-
11
- // ============================================================================
12
- // Helpers
13
- // ============================================================================
14
-
15
- function makeTriple(
16
- subject: string,
17
- predicate: string,
18
- object: string,
19
- confidence = 0.9,
20
- id?: string,
21
- ): KGTriple {
22
- return {
23
- id: id ?? `${subject}-${predicate}-${object}`,
24
- scope: "test",
25
- subject,
26
- predicate,
27
- object,
28
- confidence,
29
- source_memory_id: `mem-${subject}-${object}`,
30
- source_text: `${subject} ${predicate} ${object}`,
31
- timestamp: Date.now(),
32
- };
33
- }
34
-
35
- function makeNeighborhood(triples: KGTriple[]): NeighborhoodResult[] {
36
- const entities = new Set<string>();
37
- for (const t of triples) {
38
- entities.add(t.subject);
39
- entities.add(t.object);
40
- }
41
- return [...entities].map(entity => ({
42
- entity,
43
- triples: triples.filter(t => t.subject === entity || t.object === entity),
44
- hops: 0,
45
- }));
46
- }
47
-
48
- // ============================================================================
49
- // edgeWeight
50
- // ============================================================================
51
-
52
- describe("edgeWeight", () => {
53
- it("returns known weights for standard predicates", () => {
54
- expect(edgeWeight("created_by")).toBe(0.95);
55
- expect(edgeWeight("uses")).toBe(0.90);
56
- expect(edgeWeight("related_to")).toBe(0.50);
57
- });
58
-
59
- it("returns default weight for unknown predicates", () => {
60
- expect(edgeWeight("unknown_predicate")).toBe(0.60);
61
- });
62
- });
63
-
64
- // ============================================================================
65
- // buildGraph
66
- // ============================================================================
67
-
68
- describe("buildGraph", () => {
69
- it("builds undirected graph from neighborhood", () => {
70
- const triples = [
71
- makeTriple("Alice", "uses", "Python"),
72
- makeTriple("Alice", "works_with", "Bob"),
73
- ];
74
- const neighborhood = makeNeighborhood(triples);
75
- const graph = buildGraph(neighborhood);
76
-
77
- expect(graph.nodes.size).toBe(3); // Alice, Python, Bob
78
- expect(graph.adj.get("Alice")?.length).toBe(2); // -> Python, -> Bob
79
- expect(graph.adj.get("Python")?.length).toBe(1); // -> Alice
80
- expect(graph.adj.get("Bob")?.length).toBe(1); // -> Alice
81
- });
82
-
83
- it("deduplicates triples by id", () => {
84
- const t = makeTriple("Alice", "uses", "Python", 0.9, "same-id");
85
- const neighborhood: NeighborhoodResult[] = [
86
- { entity: "Alice", triples: [t], hops: 0 },
87
- { entity: "Python", triples: [t], hops: 1 },
88
- ];
89
- const graph = buildGraph(neighborhood);
90
-
91
- // Should only have 1 edge per direction despite appearing in 2 neighborhood entries
92
- expect(graph.adj.get("Alice")?.length).toBe(1);
93
- expect(graph.adj.get("Python")?.length).toBe(1);
94
- });
95
-
96
- it("handles empty neighborhood", () => {
97
- const graph = buildGraph([]);
98
- expect(graph.nodes.size).toBe(0);
99
- expect(graph.adj.size).toBe(0);
100
- });
101
- });
102
-
103
- // ============================================================================
104
- // pprTraverse — convergence
105
- // ============================================================================
106
-
107
- describe("pprTraverse", () => {
108
- it("converges on a simple chain A -> B -> C", () => {
109
- const triples = [
110
- makeTriple("A", "uses", "B"),
111
- makeTriple("B", "uses", "C"),
112
- ];
113
- const graph = buildGraph(makeNeighborhood(triples));
114
- const results = pprTraverse(graph, ["A"]);
115
-
116
- // A should have highest score (it's the seed)
117
- expect(results.length).toBeGreaterThan(0);
118
- expect(results[0].entity).toBe("A");
119
-
120
- // B should score higher than C (closer to seed)
121
- const bResult = results.find(r => r.entity === "B");
122
- const cResult = results.find(r => r.entity === "C");
123
- expect(bResult).toBeDefined();
124
- expect(cResult).toBeDefined();
125
- expect(bResult!.score).toBeGreaterThan(cResult!.score);
126
- });
127
-
128
- it("respects hop limits", () => {
129
- const triples = [
130
- makeTriple("A", "uses", "B"),
131
- makeTriple("B", "uses", "C"),
132
- makeTriple("C", "uses", "D"),
133
- ];
134
- const graph = buildGraph(makeNeighborhood(triples));
135
- const results = pprTraverse(graph, ["A"], { hopLimit: 1 });
136
-
137
- // With hopLimit=1, only A and B should be reachable
138
- const entities = results.map(r => r.entity);
139
- expect(entities).toContain("A");
140
- expect(entities).toContain("B");
141
- expect(entities).not.toContain("C");
142
- expect(entities).not.toContain("D");
143
- });
144
-
145
- it("handles multiple seed entities", () => {
146
- const triples = [
147
- makeTriple("A", "uses", "C"),
148
- makeTriple("B", "uses", "C"),
149
- ];
150
- const graph = buildGraph(makeNeighborhood(triples));
151
- const results = pprTraverse(graph, ["A", "B"]);
152
-
153
- // C should be reachable from both seeds
154
- const cResult = results.find(r => r.entity === "C");
155
- expect(cResult).toBeDefined();
156
- expect(cResult!.hops).toBe(1);
157
- });
158
-
159
- it("returns empty for empty graph", () => {
160
- const graph = buildGraph([]);
161
- const results = pprTraverse(graph, ["A"]);
162
- expect(results).toEqual([]);
163
- });
164
-
165
- it("returns empty when seeds not in graph", () => {
166
- const triples = [makeTriple("X", "uses", "Y")];
167
- const graph = buildGraph(makeNeighborhood(triples));
168
- const results = pprTraverse(graph, ["NotInGraph"]);
169
- expect(results).toEqual([]);
170
- });
171
-
172
- it("respects topK limit", () => {
173
- const triples = [
174
- makeTriple("A", "uses", "B"),
175
- makeTriple("A", "uses", "C"),
176
- makeTriple("A", "uses", "D"),
177
- makeTriple("A", "uses", "E"),
178
- ];
179
- const graph = buildGraph(makeNeighborhood(triples));
180
- const results = pprTraverse(graph, ["A"], { topK: 2 });
181
- expect(results.length).toBe(2);
182
- });
183
-
184
- it("computes shortest paths correctly", () => {
185
- const triples = [
186
- makeTriple("A", "uses", "B"),
187
- makeTriple("B", "uses", "C"),
188
- ];
189
- const graph = buildGraph(makeNeighborhood(triples));
190
- const results = pprTraverse(graph, ["A"]);
191
-
192
- const aResult = results.find(r => r.entity === "A");
193
- const bResult = results.find(r => r.entity === "B");
194
- const cResult = results.find(r => r.entity === "C");
195
-
196
- expect(aResult?.hops).toBe(0);
197
- expect(aResult?.path).toEqual(["A"]);
198
- expect(bResult?.hops).toBe(1);
199
- expect(bResult?.path).toEqual(["A", "B"]);
200
- expect(cResult?.hops).toBe(2);
201
- expect(cResult?.path).toEqual(["A", "B", "C"]);
202
- });
203
-
204
- it("edge weights affect scores — stronger predicates yield higher scores", () => {
205
- // Two separate subgraphs from same seed
206
- const triples = [
207
- makeTriple("A", "created_by", "B", 1.0), // weight 0.95
208
- makeTriple("A", "related_to", "C", 1.0), // weight 0.50
209
- ];
210
- const graph = buildGraph(makeNeighborhood(triples));
211
- const results = pprTraverse(graph, ["A"]);
212
-
213
- const bResult = results.find(r => r.entity === "B");
214
- const cResult = results.find(r => r.entity === "C");
215
- expect(bResult).toBeDefined();
216
- expect(cResult).toBeDefined();
217
- // B should score higher due to stronger edge weight
218
- expect(bResult!.score).toBeGreaterThan(cResult!.score);
219
- });
220
-
221
- it("all scores sum to approximately 1.0 (probability distribution)", () => {
222
- const triples = [
223
- makeTriple("A", "uses", "B"),
224
- makeTriple("B", "uses", "C"),
225
- makeTriple("C", "uses", "A"), // cycle
226
- ];
227
- const graph = buildGraph(makeNeighborhood(triples));
228
- const results = pprTraverse(graph, ["A"], { maxIterations: 50 });
229
-
230
- const totalScore = results.reduce((sum, r) => sum + r.score, 0);
231
- // PPR scores approximate a probability distribution
232
- expect(totalScore).toBeGreaterThan(0.8);
233
- expect(totalScore).toBeLessThan(1.2);
234
- });
235
- });
236
-
237
- // ============================================================================
238
- // pprFromTriples (convenience)
239
- // ============================================================================
240
-
241
- describe("pprFromTriples", () => {
242
- it("works with raw triples", () => {
243
- const triples = [
244
- makeTriple("Alice", "uses", "Python"),
245
- makeTriple("Alice", "works_at", "Google"),
246
- ];
247
- const results = pprFromTriples(triples, ["Alice"]);
248
-
249
- expect(results.length).toBeGreaterThan(0);
250
- expect(results[0].entity).toBe("Alice");
251
-
252
- const entities = results.map(r => r.entity);
253
- expect(entities).toContain("Python");
254
- expect(entities).toContain("Google");
255
- });
256
- });