recallnest 3.0.0 → 3.0.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 (184) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +222 -254
  3. package/README_CN.md +206 -243
  4. package/package.json +3 -2
  5. package/src/capture-engine.ts +26 -4
  6. package/src/context-composer-stable.ts +5 -1
  7. package/src/embedder.ts +24 -0
  8. package/src/env-config.ts +18 -0
  9. package/src/ingest.ts +225 -17
  10. package/src/kg-extractor.ts +17 -0
  11. package/src/memory-output.ts +35 -0
  12. package/src/pivot-apply.ts +52 -1
  13. package/src/pivot-evidence.ts +128 -0
  14. package/src/ppr-traversal.ts +25 -1
  15. package/src/runtime-config.ts +9 -0
  16. package/src/session-engine.ts +11 -4
  17. package/src/session-output.ts +9 -1
  18. package/src/session-store.ts +2 -3
  19. package/src/skill-promotion.ts +67 -1
  20. package/src/__tests__/access-tracker-novelty.test.ts +0 -324
  21. package/src/__tests__/activity-counter.test.ts +0 -125
  22. package/src/__tests__/adaptive-fidelity.test.ts +0 -102
  23. package/src/__tests__/admission-control.test.ts +0 -206
  24. package/src/__tests__/age-label.test.ts +0 -33
  25. package/src/__tests__/anchor-generator.test.ts +0 -67
  26. package/src/__tests__/api-server-security.test.ts +0 -102
  27. package/src/__tests__/auto-consolidation.test.ts +0 -168
  28. package/src/__tests__/auto-recall.test.ts +0 -131
  29. package/src/__tests__/babel-integration.test.ts +0 -144
  30. package/src/__tests__/batch-dedup.test.ts +0 -65
  31. package/src/__tests__/belief-history.test.ts +0 -220
  32. package/src/__tests__/canary-eval.test.ts +0 -114
  33. package/src/__tests__/capture-engine.test.ts +0 -1328
  34. package/src/__tests__/capture-heuristic.test.ts +0 -171
  35. package/src/__tests__/cascade-forget.test.ts +0 -210
  36. package/src/__tests__/category-min-scores.test.ts +0 -116
  37. package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
  38. package/src/__tests__/circuit-breaker.test.ts +0 -99
  39. package/src/__tests__/cluster-consolidation.test.ts +0 -1236
  40. package/src/__tests__/confidence-metadata.test.ts +0 -125
  41. package/src/__tests__/confidence-tracker.test.ts +0 -261
  42. package/src/__tests__/conflict-advisor.test.ts +0 -206
  43. package/src/__tests__/conflict-escalation.test.ts +0 -149
  44. package/src/__tests__/conflict-lifecycle.test.ts +0 -83
  45. package/src/__tests__/conflict-output.test.ts +0 -85
  46. package/src/__tests__/conflict-store.test.ts +0 -418
  47. package/src/__tests__/connector-v1.test.ts +0 -181
  48. package/src/__tests__/consolidation-engine.test.ts +0 -520
  49. package/src/__tests__/constructive-retrieval.test.ts +0 -509
  50. package/src/__tests__/context-collapse-renderer.test.ts +0 -214
  51. package/src/__tests__/context-composer-pins.test.ts +0 -64
  52. package/src/__tests__/context-composer-task-selection.test.ts +0 -24
  53. package/src/__tests__/context-reconstructor.test.ts +0 -65
  54. package/src/__tests__/context-renderer.test.ts +0 -91
  55. package/src/__tests__/continuity-eval.test.ts +0 -275
  56. package/src/__tests__/continuity-schema.test.ts +0 -97
  57. package/src/__tests__/contracts.test.ts +0 -262
  58. package/src/__tests__/conversation-importer.test.ts +0 -692
  59. package/src/__tests__/core-recall-eval.test.ts +0 -235
  60. package/src/__tests__/core-summary.test.ts +0 -109
  61. package/src/__tests__/data-checkup.test.ts +0 -304
  62. package/src/__tests__/decay-exemption.test.ts +0 -129
  63. package/src/__tests__/dedup-actions.test.ts +0 -58
  64. package/src/__tests__/dedup-guard.test.ts +0 -39
  65. package/src/__tests__/deterministic-id.test.ts +0 -39
  66. package/src/__tests__/distill-lock.test.ts +0 -305
  67. package/src/__tests__/distill-session-argshape.test.ts +0 -79
  68. package/src/__tests__/doctor.test.ts +0 -319
  69. package/src/__tests__/dream-pipeline.test.ts +0 -820
  70. package/src/__tests__/dream-scope-isolation.test.ts +0 -386
  71. package/src/__tests__/dream-write-batching.test.ts +0 -211
  72. package/src/__tests__/drill-down.test.ts +0 -108
  73. package/src/__tests__/embedder.test.ts +0 -122
  74. package/src/__tests__/emotion-decay.test.ts +0 -46
  75. package/src/__tests__/emotion-detector.test.ts +0 -56
  76. package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
  77. package/src/__tests__/emotion-retrieval.test.ts +0 -56
  78. package/src/__tests__/entity-resolver.test.ts +0 -58
  79. package/src/__tests__/env-config-invariant.test.ts +0 -80
  80. package/src/__tests__/env-config.test.ts +0 -211
  81. package/src/__tests__/error-signature-boost.test.ts +0 -87
  82. package/src/__tests__/error-signature.test.ts +0 -95
  83. package/src/__tests__/error-taxonomy.test.ts +0 -129
  84. package/src/__tests__/ethics-layer.test.ts +0 -476
  85. package/src/__tests__/event-segmenter.test.ts +0 -153
  86. package/src/__tests__/feature-flags-integration.test.ts +0 -54
  87. package/src/__tests__/frequency-tracker.test.ts +0 -113
  88. package/src/__tests__/freshness.test.ts +0 -186
  89. package/src/__tests__/graph-export.test.ts +0 -489
  90. package/src/__tests__/hotness-blend.test.ts +0 -283
  91. package/src/__tests__/ingest-chunking.test.ts +0 -44
  92. package/src/__tests__/ingest-scope-prefix.test.ts +0 -69
  93. package/src/__tests__/ingest.test.ts +0 -360
  94. package/src/__tests__/interference-detector.test.ts +0 -203
  95. package/src/__tests__/kg-extractor.test.ts +0 -192
  96. package/src/__tests__/kg-store.test.ts +0 -300
  97. package/src/__tests__/llm-client-pivot.test.ts +0 -628
  98. package/src/__tests__/llm-consolidation.test.ts +0 -226
  99. package/src/__tests__/maintenance-locks.test.ts +0 -197
  100. package/src/__tests__/mcp-efficiency.test.ts +0 -288
  101. package/src/__tests__/mcp-related-scopes.test.ts +0 -151
  102. package/src/__tests__/memory-boundaries.test.ts +0 -282
  103. package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -362
  104. package/src/__tests__/memory-evolution.test.ts +0 -271
  105. package/src/__tests__/memory-health-rebalance.test.ts +0 -144
  106. package/src/__tests__/memory-lint.test.ts +0 -421
  107. package/src/__tests__/memory-output.test.ts +0 -224
  108. package/src/__tests__/memory-promotion.test.ts +0 -315
  109. package/src/__tests__/memory-utility.test.ts +0 -256
  110. package/src/__tests__/migrate-dedup-ids.test.ts +0 -65
  111. package/src/__tests__/multi-vector.test.ts +0 -242
  112. package/src/__tests__/narrative-architecture.test.ts +0 -456
  113. package/src/__tests__/noise-filter.test.ts +0 -205
  114. package/src/__tests__/noise-prototype-bank.test.ts +0 -280
  115. package/src/__tests__/obsidian-connector.test.ts +0 -363
  116. package/src/__tests__/omitted-reporting.test.ts +0 -98
  117. package/src/__tests__/openai-contract.test.ts +0 -513
  118. package/src/__tests__/pending-review.test.ts +0 -77
  119. package/src/__tests__/pii-redact.test.ts +0 -333
  120. package/src/__tests__/pivot-apply.test.ts +0 -373
  121. package/src/__tests__/pivot-distill-supervisor.test.ts +0 -457
  122. package/src/__tests__/pivot-distill.test.ts +0 -1178
  123. package/src/__tests__/post-retrieval-filter.test.ts +0 -178
  124. package/src/__tests__/ppr-traversal.test.ts +0 -256
  125. package/src/__tests__/prediction-engine.test.ts +0 -349
  126. package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
  127. package/src/__tests__/preference-guard-smoke.test.ts +0 -211
  128. package/src/__tests__/preference-matcher.test.ts +0 -282
  129. package/src/__tests__/preference-slots.test.ts +0 -205
  130. package/src/__tests__/promotion-distinct-sources.test.ts +0 -162
  131. package/src/__tests__/prospective-memory.test.ts +0 -283
  132. package/src/__tests__/pull-from-macbook-sync-only.test.ts +0 -679
  133. package/src/__tests__/query-entity-detector.test.ts +0 -171
  134. package/src/__tests__/query-expander-alias.test.ts +0 -146
  135. package/src/__tests__/query-expander.test.ts +0 -34
  136. package/src/__tests__/recall-gate.test.ts +0 -266
  137. package/src/__tests__/recall-governor.test.ts +0 -227
  138. package/src/__tests__/recall-mode.test.ts +0 -64
  139. package/src/__tests__/resolve-db-path.test.ts +0 -130
  140. package/src/__tests__/resolve-tier.test.ts +0 -64
  141. package/src/__tests__/result-synthesizer.test.ts +0 -198
  142. package/src/__tests__/resume-context.test.ts +0 -4898
  143. package/src/__tests__/retrieval-eval.test.ts +0 -163
  144. package/src/__tests__/retrieval-trace.test.ts +0 -213
  145. package/src/__tests__/retrieve-audit-revision.test.ts +0 -255
  146. package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
  147. package/src/__tests__/retriever-lazy-init-dispatch.test.ts +0 -123
  148. package/src/__tests__/retroactive-boost.test.ts +0 -223
  149. package/src/__tests__/salience-scoring.test.ts +0 -106
  150. package/src/__tests__/scope-inventory.test.ts +0 -200
  151. package/src/__tests__/scope-policy.test.ts +0 -69
  152. package/src/__tests__/scope-suggester.test.ts +0 -80
  153. package/src/__tests__/session-checkpoint.test.ts +0 -291
  154. package/src/__tests__/session-distiller.test.ts +0 -640
  155. package/src/__tests__/session-gc.test.ts +0 -215
  156. package/src/__tests__/skill-engine.test.ts +0 -552
  157. package/src/__tests__/skill-promotion.test.ts +0 -654
  158. package/src/__tests__/skill-verifier.test.ts +0 -122
  159. package/src/__tests__/source-heartbeat.test.ts +0 -254
  160. package/src/__tests__/stable-context-length-contract.test.ts +0 -62
  161. package/src/__tests__/store-patch-metadata.test.ts +0 -235
  162. package/src/__tests__/store-read-consistency.test.ts +0 -122
  163. package/src/__tests__/store-schema-migration.test.ts +0 -87
  164. package/src/__tests__/store-scope-audit.test.ts +0 -81
  165. package/src/__tests__/store-upsert.test.ts +0 -201
  166. package/src/__tests__/supersede-chain.test.ts +0 -154
  167. package/src/__tests__/synthesis-contract.test.ts +0 -252
  168. package/src/__tests__/synthesis-promotion.test.ts +0 -369
  169. package/src/__tests__/temporal-parser.test.ts +0 -241
  170. package/src/__tests__/temporal-validity.test.ts +0 -160
  171. package/src/__tests__/term-registry-terminal-roster.test.ts +0 -127
  172. package/src/__tests__/term-registry.test.ts +0 -121
  173. package/src/__tests__/tool-error-surfacing.test.ts +0 -98
  174. package/src/__tests__/tool-output-compressor.test.ts +0 -160
  175. package/src/__tests__/topic-tag.test.ts +0 -113
  176. package/src/__tests__/trusted-memory.test.ts +0 -867
  177. package/src/__tests__/ui-server-security.test.ts +0 -93
  178. package/src/__tests__/usage-tracker.test.ts +0 -287
  179. package/src/__tests__/utility-weight.test.ts +0 -57
  180. package/src/__tests__/verbatim-self-recall.test.ts +0 -279
  181. package/src/__tests__/version-manager.test.ts +0 -248
  182. package/src/__tests__/workflow-observation-skill-outcome.test.ts +0 -352
  183. package/src/__tests__/workflow-observation.test.ts +0 -433
  184. package/src/__tests__/write-verifier.test.ts +0 -122
@@ -1,171 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
-
3
- import { autoCapture, extractHeuristic, shouldCapture } from "../capture-heuristic.js";
4
-
5
- // =============================================================================
6
- // shouldCapture
7
- // =============================================================================
8
-
9
- describe("shouldCapture", () => {
10
- it("rejects empty or very short text", () => {
11
- expect(shouldCapture("")).toBe(false);
12
- expect(shouldCapture("hi")).toBe(false);
13
- expect(shouldCapture("short")).toBe(false);
14
- expect(shouldCapture("a".repeat(19))).toBe(false);
15
- });
16
-
17
- it("rejects greetings (EN)", () => {
18
- expect(shouldCapture("hello!")).toBe(false);
19
- expect(shouldCapture("thanks!")).toBe(false);
20
- expect(shouldCapture("ok")).toBe(false);
21
- expect(shouldCapture("got it")).toBe(false);
22
- });
23
-
24
- it("rejects greetings (ZH)", () => {
25
- expect(shouldCapture("好的")).toBe(false);
26
- expect(shouldCapture("谢谢")).toBe(false);
27
- expect(shouldCapture("嗯")).toBe(false);
28
- expect(shouldCapture("是的")).toBe(false);
29
- expect(shouldCapture("收到")).toBe(false);
30
- });
31
-
32
- it("rejects noise (denial patterns from noise-filter)", () => {
33
- expect(shouldCapture("I don't have any information about that topic")).toBe(false);
34
- expect(shouldCapture("No relevant memories found for your query")).toBe(false);
35
- });
36
-
37
- it("accepts meaningful text above threshold", () => {
38
- expect(shouldCapture("I prefer using TypeScript for all my projects because it catches bugs early")).toBe(true);
39
- expect(shouldCapture("我喜欢用 Docker 来管理本地开发环境,因为可以隔离依赖")).toBe(true);
40
- });
41
- });
42
-
43
- // =============================================================================
44
- // extractHeuristic
45
- // =============================================================================
46
-
47
- describe("extractHeuristic", () => {
48
- it("extracts preference signals (EN)", () => {
49
- const items = extractHeuristic("I prefer dark mode for all my editors. The weather is nice today.");
50
- expect(items.length).toBe(1);
51
- expect(items[0].category).toBe("preferences");
52
- expect(items[0].importance).toBe(0.8);
53
- expect(items[0].sourceContext).toBe("preference signal");
54
- expect(items[0].text).toContain("dark mode");
55
- });
56
-
57
- it("extracts preference signals (ZH)", () => {
58
- const items = extractHeuristic("我喜欢用 Bun 而不是 Node.js 来运行 TypeScript 项目");
59
- expect(items.length).toBe(1);
60
- expect(items[0].category).toBe("preferences");
61
- expect(items[0].text).toContain("Bun");
62
- });
63
-
64
- it("extracts identity / profile signals (EN)", () => {
65
- const items = extractHeuristic("My name is Alice and I work at a cultural organization");
66
- expect(items.length).toBe(1);
67
- expect(items[0].category).toBe("profile");
68
- expect(items[0].importance).toBe(0.9);
69
- });
70
-
71
- it("extracts identity / profile signals (ZH)", () => {
72
- const items = extractHeuristic("我是一个医学出身的内容创作者,目前在做AI相关的公众号运营");
73
- expect(items.length).toBe(1);
74
- expect(items[0].category).toBe("profile");
75
- });
76
-
77
- it("extracts decision signals", () => {
78
- const items = extractHeuristic("We decided to use LanceDB as the vector store for this project");
79
- expect(items.length).toBe(1);
80
- expect(items[0].category).toBe("events");
81
- expect(items[0].importance).toBe(0.7);
82
- expect(items[0].sourceContext).toBe("decision signal");
83
- });
84
-
85
- it("extracts correction signals with next sentence", () => {
86
- const items = extractHeuristic(
87
- "Actually, that's wrong. The rate limit is 200 per minute. And the sky is blue."
88
- );
89
- expect(items.length).toBe(1);
90
- expect(items[0].category).toBe("cases");
91
- expect(items[0].importance).toBe(0.85);
92
- // Should include both the correction and the next sentence
93
- expect(items[0].text).toContain("that's wrong");
94
- expect(items[0].text).toContain("rate limit");
95
- });
96
-
97
- it("extracts explicit memory instruction signals (ZH)", () => {
98
- const items = extractHeuristic("记住这个:我的 API key 过期日期是每月 15 号需要更新");
99
- expect(items.length).toBe(1);
100
- expect(items[0].sourceContext).toBe("explicit memory instruction");
101
- expect(items[0].importance).toBe(0.85);
102
- });
103
-
104
- it("extracts pattern / workflow signals", () => {
105
- const items = extractHeuristic("The workflow is: first run tests, then commit, then push to remote");
106
- expect(items.length).toBe(1);
107
- expect(items[0].category).toBe("patterns");
108
- expect(items[0].importance).toBe(0.75);
109
- });
110
-
111
- it("extracts multiple signals from multi-sentence text", () => {
112
- const items = extractHeuristic(
113
- "I prefer using VS Code for editing. My name is Bob and I work at Acme Corp. We decided to migrate to AWS."
114
- );
115
- expect(items.length).toBe(3);
116
- expect(items[0].category).toBe("preferences");
117
- expect(items[1].category).toBe("profile");
118
- expect(items[2].category).toBe("events");
119
- });
120
-
121
- it("caps at MAX_ITEMS_PER_TURN (5)", () => {
122
- const text = [
123
- "I prefer TypeScript over JavaScript.",
124
- "I like dark mode.",
125
- "I love coffee.",
126
- "I want a fast editor.",
127
- "I need good autocomplete.",
128
- "I hate slow builds.",
129
- "I always use ESLint.",
130
- ].join(" ");
131
- const items = extractHeuristic(text);
132
- expect(items.length).toBeLessThanOrEqual(5);
133
- });
134
-
135
- it("returns empty for text with no signals", () => {
136
- const items = extractHeuristic("The function calculates the sum of two numbers and returns the result to the caller");
137
- expect(items.length).toBe(0);
138
- });
139
-
140
- it("filters out sentences shorter than minSentenceLen", () => {
141
- // Short EN sentences below 15 chars should be skipped
142
- const items = extractHeuristic("I like it. That is all there is to say about the matter.");
143
- // "I like it" is 9 chars → filtered
144
- expect(items.every((item) => item.text.length >= 15)).toBe(true);
145
- });
146
- });
147
-
148
- // =============================================================================
149
- // autoCapture (integration)
150
- // =============================================================================
151
-
152
- describe("autoCapture", () => {
153
- it("returns skippedSalience=true for noise", () => {
154
- const result = autoCapture("hello!");
155
- expect(result.skippedSalience).toBe(true);
156
- expect(result.items.length).toBe(0);
157
- });
158
-
159
- it("returns skippedSalience=false with items for valid text", () => {
160
- const result = autoCapture("I prefer using RecallNest for all my memory management needs");
161
- expect(result.skippedSalience).toBe(false);
162
- expect(result.items.length).toBe(1);
163
- expect(result.items[0].category).toBe("preferences");
164
- });
165
-
166
- it("returns skippedSalience=false with empty items for text without signals", () => {
167
- const result = autoCapture("The function calculates the sum of two numbers and returns the result to the caller");
168
- expect(result.skippedSalience).toBe(false);
169
- expect(result.items.length).toBe(0);
170
- });
171
- });
@@ -1,210 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
-
3
- import {
4
- cascadeForget,
5
- DEFAULT_CASCADE_FORGET_CONFIG,
6
- type CascadeForgetConfig,
7
- } from "../cascade-forget.js";
8
- import type { MemoryEntry, MemorySearchResult } from "../store.js";
9
-
10
- // ---------------------------------------------------------------------------
11
- // Helpers
12
- // ---------------------------------------------------------------------------
13
-
14
- function makeEntry(id: string, text: string, overrides: Partial<MemoryEntry> = {}): MemoryEntry {
15
- return {
16
- id,
17
- text,
18
- vector: [1, 0, 0],
19
- category: "events",
20
- scope: "project:test",
21
- importance: 0.6,
22
- timestamp: Date.now() - 7 * 86_400_000,
23
- metadata: "{}",
24
- ...overrides,
25
- };
26
- }
27
-
28
- function createMockStore(
29
- entries: MemoryEntry[],
30
- searchResults: MemorySearchResult[] = [],
31
- ) {
32
- const data = new Map(entries.map(e => [e.id, { ...e }]));
33
- const updates: Array<{ id: string; importance?: number; metadata?: string }> = [];
34
-
35
- return {
36
- updates,
37
- data,
38
- async vectorSearch(_vector: number[], limit = 5, minScore = 0.3, _scopeFilter?: string[]) {
39
- return searchResults.filter(r => r.score >= minScore).slice(0, limit);
40
- },
41
- async update(id: string, upd: any, _scopeFilter?: string[]) {
42
- const entry = data.get(id);
43
- if (!entry) return null;
44
- if (upd.importance !== undefined) entry.importance = upd.importance;
45
- if (upd.metadata !== undefined) entry.metadata = upd.metadata;
46
- updates.push({ id, ...upd });
47
- return entry;
48
- },
49
- } as any;
50
- }
51
-
52
- // ---------------------------------------------------------------------------
53
- // Tests
54
- // ---------------------------------------------------------------------------
55
-
56
- describe("cascade-forget", () => {
57
- it("returns empty when forgotten entry has no vector", async () => {
58
- const store = createMockStore([]);
59
- const result = await cascadeForget(store, {
60
- id: "forgotten-1",
61
- vector: [],
62
- scope: "project:test",
63
- });
64
- expect(result.demotedCount).toBe(0);
65
- });
66
-
67
- it("demotes related entries proportional to similarity", async () => {
68
- const related1 = makeEntry("rel-1", "high similarity", { importance: 0.6 });
69
- const related2 = makeEntry("rel-2", "medium similarity", { importance: 0.6 });
70
-
71
- const searchResults: MemorySearchResult[] = [
72
- { entry: related1, score: 0.95 }, // high sim → big demotion
73
- { entry: related2, score: 0.75 }, // lower sim → small demotion
74
- ];
75
- const store = createMockStore([related1, related2], searchResults);
76
-
77
- const result = await cascadeForget(store, {
78
- id: "forgotten-1",
79
- vector: [1, 0, 0],
80
- scope: "project:test",
81
- });
82
-
83
- expect(result.demotedCount).toBe(2);
84
-
85
- // High similarity (0.95): demotion = 0.3 * (0.95-0.70)/0.30 = 0.25
86
- // New importance: 0.6 - 0.25 = 0.35
87
- expect(store.data.get("rel-1")!.importance).toBeCloseTo(0.35, 1);
88
-
89
- // Medium similarity (0.75): demotion = 0.3 * (0.75-0.70)/0.30 = 0.05
90
- // New importance: 0.6 - 0.05 = 0.55
91
- expect(store.data.get("rel-2")!.importance).toBeCloseTo(0.55, 1);
92
- });
93
-
94
- it("skips the forgotten entry itself", async () => {
95
- const forgotten = makeEntry("forgotten-1", "to be forgotten", { importance: 0.6 });
96
- const searchResults: MemorySearchResult[] = [
97
- { entry: forgotten, score: 1.0 },
98
- ];
99
- const store = createMockStore([forgotten], searchResults);
100
-
101
- const result = await cascadeForget(store, {
102
- id: "forgotten-1",
103
- vector: [1, 0, 0],
104
- scope: "project:test",
105
- });
106
-
107
- expect(result.demotedCount).toBe(0);
108
- });
109
-
110
- it("skips already-archived entries", async () => {
111
- const archived = makeEntry("arch-1", "archived", {
112
- importance: 0.6,
113
- metadata: JSON.stringify({ evolution: { status: "archived" } }),
114
- });
115
- const searchResults: MemorySearchResult[] = [
116
- { entry: archived, score: 0.9 },
117
- ];
118
- const store = createMockStore([archived], searchResults);
119
-
120
- const result = await cascadeForget(store, {
121
- id: "forgotten-1",
122
- vector: [1, 0, 0],
123
- scope: "project:test",
124
- });
125
-
126
- expect(result.demotedCount).toBe(0);
127
- });
128
-
129
- it("respects importance floor", async () => {
130
- const lowEntry = makeEntry("low-1", "already low", { importance: 0.1 });
131
- const searchResults: MemorySearchResult[] = [
132
- { entry: lowEntry, score: 0.95 },
133
- ];
134
- const store = createMockStore([lowEntry], searchResults);
135
-
136
- const result = await cascadeForget(store, {
137
- id: "forgotten-1",
138
- vector: [1, 0, 0],
139
- scope: "project:test",
140
- });
141
-
142
- expect(result.demotedCount).toBe(1);
143
- // 0.1 - 0.25 = -0.15 → clamped to floor 0.05
144
- expect(store.data.get("low-1")!.importance).toBe(0.05);
145
- });
146
-
147
- it("demotes tier when importance drops below threshold", async () => {
148
- const workingEntry = makeEntry("w-1", "working tier", {
149
- importance: 0.6,
150
- metadata: JSON.stringify({ tier: "working" }),
151
- });
152
- const searchResults: MemorySearchResult[] = [
153
- { entry: workingEntry, score: 0.95 },
154
- ];
155
- const store = createMockStore([workingEntry], searchResults);
156
-
157
- const result = await cascadeForget(store, {
158
- id: "forgotten-1",
159
- vector: [1, 0, 0],
160
- scope: "project:test",
161
- });
162
-
163
- expect(result.demotedCount).toBe(1);
164
- const updatedMeta = JSON.parse(store.data.get("w-1")!.metadata!);
165
- // Importance drops to ~0.35, below 0.5 → demoted to peripheral
166
- expect(updatedMeta.tier).toBe("peripheral");
167
- expect(updatedMeta.cascade_forget).toHaveLength(1);
168
- });
169
-
170
- it("respects maxDemotePerForget limit", async () => {
171
- const entries: MemoryEntry[] = [];
172
- const searchResults: MemorySearchResult[] = [];
173
-
174
- for (let i = 0; i < 20; i++) {
175
- const e = makeEntry(`rel-${i}`, `entry ${i}`, { importance: 0.6 });
176
- entries.push(e);
177
- searchResults.push({ entry: e, score: 0.85 });
178
- }
179
-
180
- const store = createMockStore(entries, searchResults);
181
-
182
- const result = await cascadeForget(store, {
183
- id: "forgotten-1",
184
- vector: [1, 0, 0],
185
- scope: "project:test",
186
- });
187
-
188
- expect(result.demotedCount).toBe(10); // default maxDemotePerForget
189
- });
190
-
191
- it("writes audit trail in metadata", async () => {
192
- const related = makeEntry("rel-1", "related note", { importance: 0.6 });
193
- const searchResults: MemorySearchResult[] = [
194
- { entry: related, score: 0.85 },
195
- ];
196
- const store = createMockStore([related], searchResults);
197
-
198
- await cascadeForget(store, {
199
- id: "forgotten-1",
200
- vector: [1, 0, 0],
201
- scope: "project:test",
202
- });
203
-
204
- const meta = JSON.parse(store.data.get("rel-1")!.metadata!);
205
- expect(meta.cascade_forget).toHaveLength(1);
206
- expect(meta.cascade_forget[0].forgottenId).toBe("forgotte"); // first 8 chars
207
- expect(meta.cascade_forget[0].from).toBe(0.6);
208
- expect(typeof meta.cascade_forget[0].to).toBe("number");
209
- });
210
- });
@@ -1,116 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
-
3
- import { DEFAULT_CATEGORY_MIN_SCORES, DEFAULT_RETRIEVAL_CONFIG } from "../retriever.js";
4
- import { RETRIEVAL_PROFILES, applyRetrievalProfile } from "../retrieval-profiles.js";
5
-
6
- const ALL_CATEGORIES = ["profile", "preferences", "entities", "events", "cases", "patterns"];
7
-
8
- describe("DEFAULT_CATEGORY_MIN_SCORES", () => {
9
- it("has entries for all 6 durable categories", () => {
10
- const expected = ["profile", "preferences", "entities", "events", "cases", "patterns"];
11
- for (const cat of expected) {
12
- expect(DEFAULT_CATEGORY_MIN_SCORES[cat]).toBeNumber();
13
- }
14
- });
15
-
16
- it("profile and preferences have lower thresholds than global hardMinScore", () => {
17
- expect(DEFAULT_CATEGORY_MIN_SCORES.profile).toBeLessThan(DEFAULT_RETRIEVAL_CONFIG.hardMinScore);
18
- expect(DEFAULT_CATEGORY_MIN_SCORES.preferences).toBeLessThan(DEFAULT_RETRIEVAL_CONFIG.hardMinScore);
19
- });
20
-
21
- it("cases and patterns have higher thresholds than global hardMinScore", () => {
22
- expect(DEFAULT_CATEGORY_MIN_SCORES.cases).toBeGreaterThan(DEFAULT_RETRIEVAL_CONFIG.hardMinScore);
23
- expect(DEFAULT_CATEGORY_MIN_SCORES.patterns).toBeGreaterThan(DEFAULT_RETRIEVAL_CONFIG.hardMinScore);
24
- });
25
-
26
- it("events threshold equals global hardMinScore", () => {
27
- expect(DEFAULT_CATEGORY_MIN_SCORES.events).toBe(DEFAULT_RETRIEVAL_CONFIG.hardMinScore);
28
- });
29
-
30
- it("all thresholds are in valid range (0, 1)", () => {
31
- for (const [, threshold] of Object.entries(DEFAULT_CATEGORY_MIN_SCORES)) {
32
- expect(threshold).toBeGreaterThan(0);
33
- expect(threshold).toBeLessThan(1);
34
- }
35
- });
36
- });
37
-
38
- describe("retrieval profiles carry scaled category thresholds", () => {
39
- const scopedProfiles = ["writing", "debug", "fact-check"] as const;
40
-
41
- it("default profile does not override category thresholds", () => {
42
- expect(RETRIEVAL_PROFILES.default.overrides.categoryMinScores).toBeUndefined();
43
- const { config } = applyRetrievalProfile(DEFAULT_RETRIEVAL_CONFIG, "default");
44
- expect(config.categoryMinScores).toEqual(DEFAULT_RETRIEVAL_CONFIG.categoryMinScores);
45
- });
46
-
47
- // A partial map is the trap here: Retriever.minScoreFor() falls back to
48
- // hardMinScore — not to DEFAULT_CATEGORY_MIN_SCORES — for unlisted categories.
49
- it("every scoped profile supplies a COMPLETE category map", () => {
50
- for (const name of scopedProfiles) {
51
- const map = RETRIEVAL_PROFILES[name].overrides.categoryMinScores;
52
- expect(map).toBeDefined();
53
- expect(Object.keys(map!).sort()).toEqual([...ALL_CATEGORIES].sort());
54
- }
55
- });
56
-
57
- it("thresholds track each profile's overall looseness", () => {
58
- for (const name of scopedProfiles) {
59
- const { overrides } = RETRIEVAL_PROFILES[name];
60
- const looser = overrides.hardMinScore! < DEFAULT_RETRIEVAL_CONFIG.hardMinScore;
61
- for (const category of ALL_CATEGORIES) {
62
- const scaled = overrides.categoryMinScores![category];
63
- const base = DEFAULT_CATEGORY_MIN_SCORES[category];
64
- if (looser) {
65
- expect(scaled).toBeLessThan(base);
66
- } else {
67
- expect(scaled).toBeGreaterThan(base);
68
- }
69
- }
70
- }
71
- });
72
-
73
- it("preserves the relative ordering of the default map", () => {
74
- const defaultOrder = [...ALL_CATEGORIES].sort(
75
- (a, b) => DEFAULT_CATEGORY_MIN_SCORES[a] - DEFAULT_CATEGORY_MIN_SCORES[b],
76
- );
77
- for (const name of scopedProfiles) {
78
- const map = RETRIEVAL_PROFILES[name].overrides.categoryMinScores!;
79
- const scaledOrder = [...ALL_CATEGORIES].sort((a, b) => map[a] - map[b]);
80
- expect(scaledOrder).toEqual(defaultOrder);
81
- }
82
- });
83
-
84
- it("keeps every scaled threshold in valid range (0, 1)", () => {
85
- for (const name of scopedProfiles) {
86
- const map = RETRIEVAL_PROFILES[name].overrides.categoryMinScores!;
87
- for (const threshold of Object.values(map)) {
88
- expect(threshold).toBeGreaterThan(0);
89
- expect(threshold).toBeLessThan(1);
90
- }
91
- }
92
- });
93
-
94
- it("applyRetrievalProfile propagates the map into the resolved config", () => {
95
- const { config } = applyRetrievalProfile(DEFAULT_RETRIEVAL_CONFIG, "debug");
96
- expect(config.categoryMinScores).toEqual(
97
- RETRIEVAL_PROFILES.debug.overrides.categoryMinScores,
98
- );
99
- });
100
-
101
- it("loosening and tightening both reach category admission", () => {
102
- // debug (0.34) and writing (0.24) are looser than the 0.35 default …
103
- const debug = applyRetrievalProfile(DEFAULT_RETRIEVAL_CONFIG, "debug").config;
104
- const writing = applyRetrievalProfile(DEFAULT_RETRIEVAL_CONFIG, "writing").config;
105
- expect(debug.categoryMinScores!.patterns).toBeLessThan(DEFAULT_CATEGORY_MIN_SCORES.patterns);
106
- expect(writing.categoryMinScores!.events).toBeLessThan(DEFAULT_CATEGORY_MIN_SCORES.events);
107
- // … and writing, being loosest, must admit more than debug.
108
- expect(writing.categoryMinScores!.patterns).toBeLessThan(debug.categoryMinScores!.patterns);
109
-
110
- // fact-check (0.38) is the only tighter profile.
111
- const factCheck = applyRetrievalProfile(DEFAULT_RETRIEVAL_CONFIG, "fact-check").config;
112
- expect(factCheck.categoryMinScores!.patterns).toBeGreaterThan(
113
- DEFAULT_CATEGORY_MIN_SCORES.patterns,
114
- );
115
- });
116
- });