recallnest 2.6.1 → 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 (207) hide show
  1. package/CHANGELOG.md +292 -0
  2. package/README.md +280 -195
  3. package/README_CN.md +266 -199
  4. package/config.json.example +8 -1
  5. package/docs/api-reference.md +1 -1
  6. package/integrations/README.md +1 -1
  7. package/integrations/agy/README.md +73 -0
  8. package/integrations/agy/setup.sh +75 -0
  9. package/integrations/setup-all.sh +1 -1
  10. package/package.json +7 -5
  11. package/src/access-tracker.ts +10 -1
  12. package/src/activity-counter.ts +69 -11
  13. package/src/age-label.ts +29 -0
  14. package/src/audit-log.ts +35 -0
  15. package/src/auto-gc.ts +97 -30
  16. package/src/capture-engine.ts +26 -4
  17. package/src/cli.ts +224 -10
  18. package/src/consolidation-engine.ts +317 -123
  19. package/src/context-composer-stable.ts +5 -1
  20. package/src/data-checkup.ts +17 -3
  21. package/src/dream-pipeline.ts +90 -12
  22. package/src/embedder.ts +44 -5
  23. package/src/env-config.ts +71 -0
  24. package/src/forget-engine.ts +8 -2
  25. package/src/gateway-server.ts +272 -0
  26. package/src/ingest.ts +248 -22
  27. package/src/kg-extractor.ts +17 -0
  28. package/src/llm-client.ts +86 -25
  29. package/src/mcp-server.ts +2 -1
  30. package/src/mcp-tools-advanced.ts +7 -2
  31. package/src/mcp-tools-core.ts +11 -1
  32. package/src/mcp-tools-governance.ts +45 -3
  33. package/src/memory-evolution.ts +16 -0
  34. package/src/memory-output.ts +47 -8
  35. package/src/memory-promotion.ts +280 -0
  36. package/src/memory-store-port.ts +32 -3
  37. package/src/memory-utility.ts +314 -0
  38. package/src/pivot-apply.ts +52 -1
  39. package/src/pivot-evidence.ts +128 -0
  40. package/src/ppr-traversal.ts +25 -1
  41. package/src/recall-ledger.ts +76 -0
  42. package/src/retriever.ts +82 -9
  43. package/src/runtime-config.ts +9 -0
  44. package/src/scope-policy.ts +22 -1
  45. package/src/session-engine.ts +11 -4
  46. package/src/session-output.ts +13 -4
  47. package/src/session-store.ts +2 -3
  48. package/src/skill-promotion.ts +218 -1
  49. package/src/store.ts +231 -71
  50. package/src/synthesis-contract.ts +286 -0
  51. package/src/version-manager.ts +83 -0
  52. package/src/workflow-observation-schema.ts +26 -0
  53. package/integrations/gemini-cli/README.md +0 -57
  54. package/integrations/gemini-cli/setup.sh +0 -64
  55. package/src/__tests__/access-tracker-novelty.test.ts +0 -304
  56. package/src/__tests__/activity-counter.test.ts +0 -125
  57. package/src/__tests__/adaptive-fidelity.test.ts +0 -102
  58. package/src/__tests__/admission-control.test.ts +0 -206
  59. package/src/__tests__/anchor-generator.test.ts +0 -67
  60. package/src/__tests__/api-server-security.test.ts +0 -102
  61. package/src/__tests__/auto-consolidation.test.ts +0 -168
  62. package/src/__tests__/auto-recall.test.ts +0 -131
  63. package/src/__tests__/babel-integration.test.ts +0 -144
  64. package/src/__tests__/batch-dedup.test.ts +0 -65
  65. package/src/__tests__/belief-history.test.ts +0 -220
  66. package/src/__tests__/canary-eval.test.ts +0 -114
  67. package/src/__tests__/capture-engine.test.ts +0 -1328
  68. package/src/__tests__/capture-heuristic.test.ts +0 -171
  69. package/src/__tests__/cascade-forget.test.ts +0 -210
  70. package/src/__tests__/category-min-scores.test.ts +0 -116
  71. package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
  72. package/src/__tests__/circuit-breaker.test.ts +0 -99
  73. package/src/__tests__/cluster-consolidation.test.ts +0 -945
  74. package/src/__tests__/confidence-metadata.test.ts +0 -125
  75. package/src/__tests__/confidence-tracker.test.ts +0 -261
  76. package/src/__tests__/conflict-advisor.test.ts +0 -206
  77. package/src/__tests__/conflict-escalation.test.ts +0 -149
  78. package/src/__tests__/conflict-lifecycle.test.ts +0 -83
  79. package/src/__tests__/conflict-output.test.ts +0 -85
  80. package/src/__tests__/conflict-store.test.ts +0 -418
  81. package/src/__tests__/connector-v1.test.ts +0 -181
  82. package/src/__tests__/consolidation-engine.test.ts +0 -430
  83. package/src/__tests__/constructive-retrieval.test.ts +0 -509
  84. package/src/__tests__/context-collapse-renderer.test.ts +0 -214
  85. package/src/__tests__/context-composer-pins.test.ts +0 -64
  86. package/src/__tests__/context-composer-task-selection.test.ts +0 -24
  87. package/src/__tests__/context-reconstructor.test.ts +0 -65
  88. package/src/__tests__/context-renderer.test.ts +0 -91
  89. package/src/__tests__/continuity-eval.test.ts +0 -275
  90. package/src/__tests__/continuity-schema.test.ts +0 -97
  91. package/src/__tests__/contracts.test.ts +0 -262
  92. package/src/__tests__/conversation-importer.test.ts +0 -692
  93. package/src/__tests__/core-recall-eval.test.ts +0 -235
  94. package/src/__tests__/core-summary.test.ts +0 -109
  95. package/src/__tests__/data-checkup.test.ts +0 -276
  96. package/src/__tests__/decay-exemption.test.ts +0 -129
  97. package/src/__tests__/dedup-actions.test.ts +0 -58
  98. package/src/__tests__/dedup-guard.test.ts +0 -39
  99. package/src/__tests__/deterministic-id.test.ts +0 -39
  100. package/src/__tests__/distill-lock.test.ts +0 -305
  101. package/src/__tests__/distill-session-argshape.test.ts +0 -79
  102. package/src/__tests__/doctor.test.ts +0 -319
  103. package/src/__tests__/dream-pipeline.test.ts +0 -780
  104. package/src/__tests__/drill-down.test.ts +0 -108
  105. package/src/__tests__/embedder.test.ts +0 -122
  106. package/src/__tests__/emotion-decay.test.ts +0 -46
  107. package/src/__tests__/emotion-detector.test.ts +0 -56
  108. package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
  109. package/src/__tests__/emotion-retrieval.test.ts +0 -56
  110. package/src/__tests__/entity-resolver.test.ts +0 -58
  111. package/src/__tests__/env-config.test.ts +0 -151
  112. package/src/__tests__/error-signature-boost.test.ts +0 -87
  113. package/src/__tests__/error-signature.test.ts +0 -95
  114. package/src/__tests__/error-taxonomy.test.ts +0 -129
  115. package/src/__tests__/ethics-layer.test.ts +0 -476
  116. package/src/__tests__/event-segmenter.test.ts +0 -153
  117. package/src/__tests__/feature-flags-integration.test.ts +0 -54
  118. package/src/__tests__/frequency-tracker.test.ts +0 -113
  119. package/src/__tests__/freshness.test.ts +0 -186
  120. package/src/__tests__/graph-export.test.ts +0 -489
  121. package/src/__tests__/hotness-blend.test.ts +0 -283
  122. package/src/__tests__/ingest-chunking.test.ts +0 -44
  123. package/src/__tests__/ingest.test.ts +0 -360
  124. package/src/__tests__/interference-detector.test.ts +0 -203
  125. package/src/__tests__/kg-extractor.test.ts +0 -192
  126. package/src/__tests__/kg-store.test.ts +0 -300
  127. package/src/__tests__/llm-client-pivot.test.ts +0 -628
  128. package/src/__tests__/llm-consolidation.test.ts +0 -226
  129. package/src/__tests__/maintenance-locks.test.ts +0 -189
  130. package/src/__tests__/mcp-efficiency.test.ts +0 -288
  131. package/src/__tests__/mcp-related-scopes.test.ts +0 -151
  132. package/src/__tests__/memory-boundaries.test.ts +0 -282
  133. package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -345
  134. package/src/__tests__/memory-evolution.test.ts +0 -271
  135. package/src/__tests__/memory-health-rebalance.test.ts +0 -144
  136. package/src/__tests__/memory-lint.test.ts +0 -421
  137. package/src/__tests__/memory-output.test.ts +0 -215
  138. package/src/__tests__/memory-promotion.test.ts +0 -315
  139. package/src/__tests__/migrate-dedup-ids.test.ts +0 -65
  140. package/src/__tests__/multi-vector.test.ts +0 -242
  141. package/src/__tests__/narrative-architecture.test.ts +0 -456
  142. package/src/__tests__/noise-filter.test.ts +0 -205
  143. package/src/__tests__/noise-prototype-bank.test.ts +0 -280
  144. package/src/__tests__/obsidian-connector.test.ts +0 -363
  145. package/src/__tests__/omitted-reporting.test.ts +0 -98
  146. package/src/__tests__/pending-review.test.ts +0 -77
  147. package/src/__tests__/pii-redact.test.ts +0 -333
  148. package/src/__tests__/pivot-apply.test.ts +0 -373
  149. package/src/__tests__/pivot-distill-supervisor.test.ts +0 -457
  150. package/src/__tests__/pivot-distill.test.ts +0 -1178
  151. package/src/__tests__/post-retrieval-filter.test.ts +0 -178
  152. package/src/__tests__/ppr-traversal.test.ts +0 -256
  153. package/src/__tests__/prediction-engine.test.ts +0 -349
  154. package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
  155. package/src/__tests__/preference-guard-smoke.test.ts +0 -211
  156. package/src/__tests__/preference-matcher.test.ts +0 -282
  157. package/src/__tests__/preference-slots.test.ts +0 -205
  158. package/src/__tests__/prospective-memory.test.ts +0 -283
  159. package/src/__tests__/pull-from-macbook-sync-only.test.ts +0 -679
  160. package/src/__tests__/query-entity-detector.test.ts +0 -171
  161. package/src/__tests__/query-expander-alias.test.ts +0 -146
  162. package/src/__tests__/query-expander.test.ts +0 -34
  163. package/src/__tests__/recall-gate.test.ts +0 -266
  164. package/src/__tests__/recall-governor.test.ts +0 -227
  165. package/src/__tests__/recall-mode.test.ts +0 -64
  166. package/src/__tests__/resolve-db-path.test.ts +0 -130
  167. package/src/__tests__/resolve-tier.test.ts +0 -64
  168. package/src/__tests__/result-synthesizer.test.ts +0 -198
  169. package/src/__tests__/resume-context.test.ts +0 -4898
  170. package/src/__tests__/retrieval-eval.test.ts +0 -163
  171. package/src/__tests__/retrieval-trace.test.ts +0 -213
  172. package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
  173. package/src/__tests__/retriever-lazy-init-dispatch.test.ts +0 -123
  174. package/src/__tests__/retroactive-boost.test.ts +0 -223
  175. package/src/__tests__/salience-scoring.test.ts +0 -106
  176. package/src/__tests__/scope-inventory.test.ts +0 -200
  177. package/src/__tests__/scope-policy.test.ts +0 -69
  178. package/src/__tests__/scope-suggester.test.ts +0 -80
  179. package/src/__tests__/session-checkpoint.test.ts +0 -291
  180. package/src/__tests__/session-distiller.test.ts +0 -640
  181. package/src/__tests__/session-gc.test.ts +0 -215
  182. package/src/__tests__/skill-engine.test.ts +0 -552
  183. package/src/__tests__/skill-promotion.test.ts +0 -654
  184. package/src/__tests__/skill-verifier.test.ts +0 -122
  185. package/src/__tests__/source-heartbeat.test.ts +0 -250
  186. package/src/__tests__/stable-context-length-contract.test.ts +0 -62
  187. package/src/__tests__/store-patch-metadata.test.ts +0 -205
  188. package/src/__tests__/store-read-consistency.test.ts +0 -122
  189. package/src/__tests__/store-schema-migration.test.ts +0 -87
  190. package/src/__tests__/store-scope-audit.test.ts +0 -81
  191. package/src/__tests__/store-upsert.test.ts +0 -201
  192. package/src/__tests__/supersede-chain.test.ts +0 -154
  193. package/src/__tests__/temporal-parser.test.ts +0 -241
  194. package/src/__tests__/temporal-validity.test.ts +0 -160
  195. package/src/__tests__/term-registry-terminal-roster.test.ts +0 -127
  196. package/src/__tests__/term-registry.test.ts +0 -121
  197. package/src/__tests__/tool-error-surfacing.test.ts +0 -98
  198. package/src/__tests__/tool-output-compressor.test.ts +0 -160
  199. package/src/__tests__/topic-tag.test.ts +0 -113
  200. package/src/__tests__/trusted-memory.test.ts +0 -839
  201. package/src/__tests__/ui-server-security.test.ts +0 -93
  202. package/src/__tests__/usage-tracker.test.ts +0 -287
  203. package/src/__tests__/version-manager.test.ts +0 -213
  204. package/src/__tests__/workflow-observation-skill-outcome.test.ts +0 -352
  205. package/src/__tests__/workflow-observation.test.ts +0 -433
  206. package/src/__tests__/write-verifier.test.ts +0 -122
  207. /package/integrations/{gemini-cli/gemini-md-snippet.md → agy/agy-md-snippet.md} +0 -0
@@ -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
- });