recallnest 2.2.0 → 2.3.0

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 (249) hide show
  1. package/.env +4 -0
  2. package/CLAUDE.md +1 -1
  3. package/README.md +30 -5
  4. package/README_CN.md +30 -5
  5. package/config.json +55 -0
  6. package/connectors/examples/email-adapter.ts +73 -0
  7. package/connectors/examples/logs-adapter.ts +103 -0
  8. package/connectors/examples/rss-adapter.ts +95 -0
  9. package/logs/daily-recall.error.log +0 -0
  10. package/logs/daily-recall.log +60 -0
  11. package/logs/ingest-2026-04-11.log +110 -0
  12. package/logs/ingest-2026-04-12.log +90 -0
  13. package/logs/ingest-2026-04-13.log +87 -0
  14. package/logs/launchagent-stderr.log +0 -0
  15. package/logs/launchagent-stdout.log +0 -0
  16. package/package.json +1 -1
  17. package/src/cli.ts +30 -0
  18. package/src/connector-types.ts +57 -0
  19. package/src/conversation-importer.ts +25 -1
  20. package/src/data-checkup.ts +31 -1
  21. package/src/doctor.ts +29 -0
  22. package/src/ingest.ts +203 -0
  23. package/src/mcp-server.ts +2 -2
  24. package/src/obsidian-connector.ts +282 -0
  25. package/src/session-schema.ts +2 -2
  26. package/src/source-heartbeat.ts +108 -0
  27. package/.claude-plugin/CLAUDE.md +0 -29
  28. package/.claude-plugin/marketplace.json +0 -18
  29. package/.dockerignore +0 -11
  30. package/.github/workflows/ci.yml +0 -28
  31. package/.mcp.json +0 -9
  32. package/CHANGELOG.md +0 -51
  33. package/DEMO.md +0 -94
  34. package/Dockerfile +0 -20
  35. package/EVAL.md +0 -89
  36. package/FAILURES.md +0 -75
  37. package/OPERATIONS.md +0 -59
  38. package/ROADMAP.md +0 -245
  39. package/SKILL.md +0 -250
  40. package/assets/dashboard.png +0 -0
  41. package/assets/knowledge-graph.png +0 -0
  42. package/assets/recallnest-workbench.png +0 -0
  43. package/assets/screenshots/ui-full.png +0 -0
  44. package/assets/screenshots/ui-overview.png +0 -0
  45. package/assets/screenshots/ui-search.png +0 -0
  46. package/assets/ui/app.js +0 -1031
  47. package/assets/ui/index.html +0 -224
  48. package/assets/ui/styles.css +0 -781
  49. package/assets/wechat-qr.jpg +0 -0
  50. package/bun.lock +0 -337
  51. package/daily-reflections/2026-03-05.md +0 -15
  52. package/daily-reflections/2026-03-06.md +0 -15
  53. package/daily-reflections/2026-03-07.md +0 -7
  54. package/daily-reflections/2026-03-08.md +0 -34
  55. package/daily-reflections/2026-03-09.md +0 -35
  56. package/daily-reflections/2026-03-10.md +0 -36
  57. package/daily-reflections/2026-03-11.md +0 -35
  58. package/daily-reflections/2026-03-12.md +0 -36
  59. package/daily-reflections/2026-03-13.md +0 -35
  60. package/daily-reflections/2026-03-14.md +0 -35
  61. package/daily-reflections/2026-03-15.md +0 -35
  62. package/daily-reflections/2026-03-16.md +0 -41
  63. package/daily-reflections/2026-03-17.md +0 -10
  64. package/daily-reflections/2026-03-18.md +0 -10
  65. package/daily-reflections/2026-03-19.md +0 -10
  66. package/daily-reflections/2026-03-20.md +0 -10
  67. package/daily-reflections/2026-03-21.md +0 -10
  68. package/daily-reflections/2026-03-22.md +0 -10
  69. package/daily-reflections/2026-03-23.md +0 -10
  70. package/daily-reflections/2026-03-24.md +0 -10
  71. package/daily-reflections/2026-03-25.md +0 -32
  72. package/daily-reflections/2026-03-26.md +0 -37
  73. package/daily-reflections/2026-03-27.md +0 -35
  74. package/daily-reflections/2026-03-28.md +0 -35
  75. package/daily-reflections/2026-03-29.md +0 -35
  76. package/daily-reflections/2026-03-30.md +0 -36
  77. package/daily-reflections/2026-03-31.md +0 -35
  78. package/daily-reflections/2026-04-01.md +0 -35
  79. package/daily-reflections/2026-04-02.md +0 -35
  80. package/daily-reflections/2026-04-03.md +0 -37
  81. package/daily-reflections/2026-04-04.md +0 -37
  82. package/daily-reflections/2026-04-05.md +0 -35
  83. package/daily-reflections/2026-04-06.md +0 -36
  84. package/daily-reflections/2026-04-07.md +0 -35
  85. package/daily-reflections/2026-04-08.md +0 -35
  86. package/daily-reflections/2026-04-12.md +0 -35
  87. package/data/alias-map.example.json +0 -22
  88. package/docs/api-reference.md +0 -1291
  89. package/docs/architecture.md +0 -168
  90. package/docs/memory-boundary-contract.md +0 -226
  91. package/docs/memory-categories.md +0 -119
  92. package/docs/pipeline-audit-ultramemory.md +0 -177
  93. package/docs/plans/2026-03-08-query-expansion.md +0 -270
  94. package/docs/plans/2026-03-16-continuity-layer.md +0 -196
  95. package/docs/plans/2026-04-01-recall-boost.md +0 -100
  96. package/docs/plans/mcp-tiering-plan.md +0 -126
  97. package/docs/research/recall-quality-audit-2026-03-22.md +0 -153
  98. package/docs/self-evolution.md +0 -198
  99. package/docs/superpowers/plans/2026-03-19-ingest-pipeline-upgrade.md +0 -782
  100. package/docs/superpowers/plans/2026-04-11-constructive-retrieval-emotion.md +0 -1195
  101. package/docs/superpowers/specs/2026-03-19-ingest-pipeline-upgrade-design.md +0 -77
  102. package/docs/superpowers/specs/2026-03-23-pull-claude-desktop-design.md +0 -95
  103. package/docs/superpowers/specs/2026-04-11-constructive-retrieval-emotion-design.md +0 -398
  104. package/eval/continuity/results-2026-03-16.md +0 -117
  105. package/eval/continuity/results-2026-03-19.md +0 -453
  106. package/eval/continuity/runbook.md +0 -110
  107. package/eval/continuity/seed-cases.md +0 -54
  108. package/eval/reports/2026-03-06-abstract-query-baseline.md +0 -96
  109. package/eval/reports/2026-03-06-aws-ssh-baseline.md +0 -82
  110. package/eval/reports/2026-03-06-baseline.md +0 -82
  111. package/eval/reports/query-expansion.md +0 -138
  112. package/glama.json +0 -6
  113. package/lm +0 -19
  114. package/plan-philosophy-upgrades.md +0 -363
  115. package/plan-product-upgrades.md +0 -155
  116. package/plan-v1.2-distributable.md +0 -105
  117. package/plan.md +0 -140
  118. package/research-memory-evolution.md +0 -440
  119. package/research-rl-agent-memory.md +0 -330
  120. package/scripts/archive-distilled-junk.ts +0 -116
  121. package/scripts/backfill-anchors.ts +0 -130
  122. package/scripts/backfill-l0l1l2.ts +0 -98
  123. package/scripts/blind-scan.ts +0 -588
  124. package/scripts/cleanup-step1-exact-dups.ts +0 -117
  125. package/scripts/cleanup-step2-template-dups.ts +0 -113
  126. package/scripts/cleanup-step3-stale-content.ts +0 -149
  127. package/scripts/cleanup-step4-orphan-scopes.ts +0 -131
  128. package/scripts/delete-distilled-junk.ts +0 -88
  129. package/scripts/diagnose-vector-search.ts +0 -132
  130. package/scripts/distill-facts.ts +0 -305
  131. package/scripts/health-check.ts +0 -343
  132. package/scripts/incremental-ingest.sh +0 -71
  133. package/scripts/migrate-language.ts +0 -75
  134. package/scripts/mlp-health-check.ts +0 -382
  135. package/scripts/pull-claude-desktop.ts +0 -515
  136. package/scripts/re-ingest-cc.sh +0 -66
  137. package/scripts/rebalance-memory-health.ts +0 -181
  138. package/scripts/run-desktop-ingest.sh +0 -11
  139. package/scripts/start-server.sh +0 -12
  140. package/scripts/verify-emotion-decay.ts +0 -148
  141. package/scripts/viz-dashboard.html +0 -423
  142. package/scripts/viz-export.ts +0 -703
  143. package/src/__tests__/access-tracker-novelty.test.ts +0 -228
  144. package/src/__tests__/activity-counter.test.ts +0 -96
  145. package/src/__tests__/admission-control.test.ts +0 -206
  146. package/src/__tests__/anchor-generator.test.ts +0 -67
  147. package/src/__tests__/auto-consolidation.test.ts +0 -168
  148. package/src/__tests__/auto-recall.test.ts +0 -131
  149. package/src/__tests__/babel-integration.test.ts +0 -139
  150. package/src/__tests__/batch-dedup.test.ts +0 -65
  151. package/src/__tests__/capture-engine.test.ts +0 -1144
  152. package/src/__tests__/capture-heuristic.test.ts +0 -171
  153. package/src/__tests__/cascade-forget.test.ts +0 -210
  154. package/src/__tests__/category-min-scores.test.ts +0 -33
  155. package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
  156. package/src/__tests__/circuit-breaker.test.ts +0 -99
  157. package/src/__tests__/cluster-consolidation.test.ts +0 -712
  158. package/src/__tests__/confidence-metadata.test.ts +0 -125
  159. package/src/__tests__/confidence-tracker.test.ts +0 -249
  160. package/src/__tests__/conflict-advisor.test.ts +0 -206
  161. package/src/__tests__/conflict-escalation.test.ts +0 -149
  162. package/src/__tests__/conflict-lifecycle.test.ts +0 -83
  163. package/src/__tests__/conflict-output.test.ts +0 -85
  164. package/src/__tests__/conflict-store.test.ts +0 -374
  165. package/src/__tests__/consolidation-engine.test.ts +0 -181
  166. package/src/__tests__/constructive-retrieval.test.ts +0 -509
  167. package/src/__tests__/context-collapse-renderer.test.ts +0 -214
  168. package/src/__tests__/context-composer-pins.test.ts +0 -64
  169. package/src/__tests__/context-composer-task-selection.test.ts +0 -24
  170. package/src/__tests__/context-reconstructor.test.ts +0 -65
  171. package/src/__tests__/context-renderer.test.ts +0 -91
  172. package/src/__tests__/continuity-eval.test.ts +0 -275
  173. package/src/__tests__/continuity-schema.test.ts +0 -97
  174. package/src/__tests__/conversation-importer.test.ts +0 -692
  175. package/src/__tests__/core-recall-eval.test.ts +0 -235
  176. package/src/__tests__/core-summary.test.ts +0 -109
  177. package/src/__tests__/data-checkup.test.ts +0 -225
  178. package/src/__tests__/decay-exemption.test.ts +0 -84
  179. package/src/__tests__/dedup-actions.test.ts +0 -58
  180. package/src/__tests__/dedup-guard.test.ts +0 -39
  181. package/src/__tests__/deterministic-id.test.ts +0 -39
  182. package/src/__tests__/distill-lock.test.ts +0 -176
  183. package/src/__tests__/doctor.test.ts +0 -303
  184. package/src/__tests__/dream-pipeline.test.ts +0 -232
  185. package/src/__tests__/drill-down.test.ts +0 -108
  186. package/src/__tests__/embedder.test.ts +0 -122
  187. package/src/__tests__/emotion-decay.test.ts +0 -46
  188. package/src/__tests__/emotion-detector.test.ts +0 -56
  189. package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
  190. package/src/__tests__/emotion-retrieval.test.ts +0 -56
  191. package/src/__tests__/entity-resolver.test.ts +0 -58
  192. package/src/__tests__/ethics-layer.test.ts +0 -476
  193. package/src/__tests__/event-segmenter.test.ts +0 -153
  194. package/src/__tests__/feature-flags-integration.test.ts +0 -54
  195. package/src/__tests__/frequency-tracker.test.ts +0 -113
  196. package/src/__tests__/graph-export.test.ts +0 -489
  197. package/src/__tests__/hotness-blend.test.ts +0 -76
  198. package/src/__tests__/ingest.test.ts +0 -360
  199. package/src/__tests__/interference-detector.test.ts +0 -203
  200. package/src/__tests__/kg-extractor.test.ts +0 -184
  201. package/src/__tests__/kg-store.test.ts +0 -198
  202. package/src/__tests__/llm-consolidation.test.ts +0 -226
  203. package/src/__tests__/mcp-efficiency.test.ts +0 -288
  204. package/src/__tests__/memory-boundaries.test.ts +0 -237
  205. package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -243
  206. package/src/__tests__/memory-evolution.test.ts +0 -271
  207. package/src/__tests__/memory-health-rebalance.test.ts +0 -144
  208. package/src/__tests__/memory-lint.test.ts +0 -271
  209. package/src/__tests__/memory-output.test.ts +0 -215
  210. package/src/__tests__/multi-vector.test.ts +0 -242
  211. package/src/__tests__/narrative-architecture.test.ts +0 -456
  212. package/src/__tests__/pending-review.test.ts +0 -77
  213. package/src/__tests__/post-retrieval-filter.test.ts +0 -178
  214. package/src/__tests__/ppr-traversal.test.ts +0 -256
  215. package/src/__tests__/prediction-engine.test.ts +0 -349
  216. package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
  217. package/src/__tests__/preference-guard-smoke.test.ts +0 -211
  218. package/src/__tests__/preference-matcher.test.ts +0 -230
  219. package/src/__tests__/preference-slots.test.ts +0 -205
  220. package/src/__tests__/prospective-memory.test.ts +0 -283
  221. package/src/__tests__/query-entity-detector.test.ts +0 -171
  222. package/src/__tests__/query-expander-alias.test.ts +0 -89
  223. package/src/__tests__/query-expander.test.ts +0 -34
  224. package/src/__tests__/recall-governor.test.ts +0 -227
  225. package/src/__tests__/recall-mode.test.ts +0 -64
  226. package/src/__tests__/result-synthesizer.test.ts +0 -198
  227. package/src/__tests__/resume-context.test.ts +0 -4898
  228. package/src/__tests__/retrieval-trace.test.ts +0 -213
  229. package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
  230. package/src/__tests__/retroactive-boost.test.ts +0 -223
  231. package/src/__tests__/salience-scoring.test.ts +0 -106
  232. package/src/__tests__/scope-inventory.test.ts +0 -200
  233. package/src/__tests__/scope-policy.test.ts +0 -69
  234. package/src/__tests__/session-checkpoint.test.ts +0 -259
  235. package/src/__tests__/session-distiller.test.ts +0 -611
  236. package/src/__tests__/session-gc.test.ts +0 -215
  237. package/src/__tests__/skill-engine.test.ts +0 -546
  238. package/src/__tests__/skill-promotion.test.ts +0 -349
  239. package/src/__tests__/store-scope-audit.test.ts +0 -81
  240. package/src/__tests__/supersede-chain.test.ts +0 -154
  241. package/src/__tests__/temporal-parser.test.ts +0 -241
  242. package/src/__tests__/temporal-validity.test.ts +0 -160
  243. package/src/__tests__/term-registry.test.ts +0 -121
  244. package/src/__tests__/tool-output-compressor.test.ts +0 -133
  245. package/src/__tests__/topic-tag.test.ts +0 -113
  246. package/src/__tests__/trusted-memory.test.ts +0 -828
  247. package/src/__tests__/version-manager.test.ts +0 -213
  248. package/src/__tests__/workflow-observation.test.ts +0 -400
  249. package/src/__tests__/write-verifier.test.ts +0 -122
@@ -1,235 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
-
3
- import { promoteMemory } from "../capture-engine.js";
4
- import { createRetriever } from "../retriever.js";
5
- import { buildRetrievalContext, matchesScopeFilter } from "../scope-policy.js";
6
-
7
- function cosineSimilarity(a: number[], b: number[]): number {
8
- let dot = 0;
9
- let normA = 0;
10
- let normB = 0;
11
- for (let i = 0; i < a.length; i += 1) {
12
- dot += a[i] * b[i];
13
- normA += a[i] * a[i];
14
- normB += b[i] * b[i];
15
- }
16
- const denom = Math.sqrt(normA) * Math.sqrt(normB);
17
- return denom === 0 ? 0 : dot / denom;
18
- }
19
-
20
- function createCoreRetriever(entries: Array<{
21
- id: string;
22
- text: string;
23
- scope: string;
24
- category?: "entities" | "events";
25
- vector: number[];
26
- }>) {
27
- return createRetriever({
28
- hasFtsSupport: false,
29
- async vectorSearch(queryVector: number[], limit = 5, minScore = 0, scopeFilter?: string[]) {
30
- return entries
31
- .filter((entry) => matchesScopeFilter(entry.scope, scopeFilter))
32
- .map((entry) => ({
33
- entry: {
34
- id: entry.id,
35
- text: entry.text,
36
- vector: entry.vector,
37
- category: entry.category || "entities",
38
- scope: entry.scope,
39
- importance: 0.8,
40
- timestamp: Date.parse("2026-03-17T00:00:00.000Z"),
41
- metadata: "{}",
42
- },
43
- score: cosineSimilarity(queryVector, entry.vector),
44
- }))
45
- .filter((result) => result.score >= minScore)
46
- .sort((a, b) => b.score - a.score)
47
- .slice(0, limit);
48
- },
49
- } as any, {
50
- async embedQuery(query: string) {
51
- if (/衰减|公式|曲线|weibull/i.test(query)) return [1, 0, 0];
52
- if (/部署|deploy|region|在哪/i.test(query)) return [0, 1, 0];
53
- return [0, 0, 1];
54
- },
55
- async embedPassage() {
56
- return [0, 0, 1];
57
- },
58
- } as any, {
59
- mode: "vector",
60
- rerank: "none",
61
- filterNoise: false,
62
- hardMinScore: 0,
63
- minScore: 0,
64
- recencyWeight: 0,
65
- timeDecayHalfLifeDays: 0,
66
- });
67
- }
68
-
69
- function createCaptureDeps() {
70
- const storedEntries: any[] = [];
71
- let seq = 1;
72
-
73
- return {
74
- storedEntries,
75
- deps: {
76
- embedder: {
77
- async embedPassage(text: string) {
78
- return [text.length, 1, 0];
79
- },
80
- },
81
- store: {
82
- async store(entry: any) {
83
- const stored = {
84
- ...entry,
85
- id: `00000000-0000-0000-0000-${String(seq).padStart(12, "0")}`,
86
- timestamp: 1_700_000_000_000 + seq,
87
- };
88
- seq += 1;
89
- storedEntries.push(stored);
90
- return stored;
91
- },
92
- async list(_scopeFilter?: string[], category?: string, limit = 20, offset = 0) {
93
- return storedEntries
94
- .filter((entry) => !category || entry.category === category)
95
- .slice(offset, offset + limit);
96
- },
97
- async update(id: string, updates: any) {
98
- const index = storedEntries.findIndex((entry) => entry.id === id);
99
- if (index < 0) return null;
100
- storedEntries[index] = {
101
- ...storedEntries[index],
102
- ...updates,
103
- timestamp: updates.timestamp ?? storedEntries[index].timestamp,
104
- };
105
- return storedEntries[index];
106
- },
107
- async get(id: string) {
108
- return storedEntries.find((entry) => entry.id === id) || null;
109
- },
110
- async getById(id: string) {
111
- return storedEntries.find((entry) => entry.id === id) || null;
112
- },
113
- },
114
- conflictStore: {
115
- async save(record: any) {
116
- return record;
117
- },
118
- async replace(record: any) {
119
- return record;
120
- },
121
- async getOpenByFingerprint() {
122
- return null;
123
- },
124
- async getLatestByFingerprint() {
125
- return null;
126
- },
127
- },
128
- },
129
- };
130
- }
131
-
132
- describe("core recall eval", () => {
133
- it("hits the right memory for a vague associative query within the target scope", async () => {
134
- const retriever = createCoreRetriever([
135
- {
136
- id: "alpha-weibull",
137
- text: "RecallNest uses Weibull decay with beta=0.8 for the core tier.",
138
- scope: "project:alpha",
139
- vector: [1, 0, 0],
140
- },
141
- {
142
- id: "alpha-entity",
143
- text: "RecallNest exposes checkpoint_session and resume_context.",
144
- scope: "project:alpha",
145
- vector: [0, 0, 1],
146
- },
147
- {
148
- id: "beta-deploy",
149
- text: "Project beta deploys in us-east-1.",
150
- scope: "project:beta",
151
- vector: [0, 1, 0],
152
- },
153
- ]);
154
-
155
- const results = await retriever.retrieve(buildRetrievalContext({
156
- query: "那个衰减曲线用的什么公式来着",
157
- limit: 5,
158
- scope: "project:alpha",
159
- }, {
160
- operation: "test:associative-recall",
161
- }));
162
-
163
- expect(results[0]?.entry.id).toBe("alpha-weibull");
164
- expect(results.every((result) => result.entry.scope === "project:alpha")).toBe(true);
165
- });
166
-
167
- it("does not leak results from another scope when default scope is inferred", async () => {
168
- const retriever = createCoreRetriever([
169
- {
170
- id: "alpha-note",
171
- text: "Project alpha stores its API key outside the memory index.",
172
- scope: "project:alpha",
173
- vector: [0, 0, 1],
174
- },
175
- {
176
- id: "beta-deploy",
177
- text: "Project beta deploys in us-east-1.",
178
- scope: "project:beta",
179
- vector: [0, 1, 0],
180
- },
181
- ]);
182
-
183
- const results = await retriever.retrieve(buildRetrievalContext({
184
- query: "部署在哪",
185
- limit: 5,
186
- }, {
187
- operation: "test:scope-isolation",
188
- env: {
189
- RECALLNEST_DEFAULT_SCOPE: "project:alpha",
190
- } as NodeJS.ProcessEnv,
191
- }));
192
-
193
- expect(results.some((result) => result.entry.id === "beta-deploy")).toBe(false);
194
- expect(results.every((result) => result.entry.scope === "project:alpha")).toBe(true);
195
- });
196
-
197
- it("preserves text and provenance when promoting evidence into durable memory", async () => {
198
- const { deps, storedEntries } = createCaptureDeps();
199
- const source = await deps.store.store({
200
- text: "RecallNest uses Weibull decay with beta=0.8 for the core tier.",
201
- vector: [1, 0, 0],
202
- category: "events",
203
- scope: "cc:session-alpha",
204
- importance: 0.5,
205
- metadata: JSON.stringify({
206
- source: "cc",
207
- boundary: {
208
- layer: "evidence",
209
- authority: "transcript-ingest",
210
- conflictPolicy: "append-only",
211
- originalCategory: "entities",
212
- },
213
- }),
214
- });
215
-
216
- const promoted = await promoteMemory(deps as any, {
217
- memoryId: source.id,
218
- category: "entities",
219
- scope: "project:alpha",
220
- source: "agent",
221
- tags: ["core-eval"],
222
- });
223
-
224
- expect(promoted.text).toBe("RecallNest uses Weibull decay with beta=0.8 for the core tier.");
225
- expect(promoted.resolvedScope).toBe("project:alpha");
226
- expect(storedEntries[1]?.text).toBe("RecallNest uses Weibull decay with beta=0.8 for the core tier.");
227
- expect(JSON.parse(storedEntries[1]?.metadata || "{}")).toMatchObject({
228
- promotedFrom: {
229
- memoryId: source.id,
230
- scope: "cc:session-alpha",
231
- category: "events",
232
- },
233
- });
234
- });
235
- });
@@ -1,109 +0,0 @@
1
- /**
2
- * Tests for Tier 3.1: Core Summary — LLM summaries replace raw text in context output.
3
- *
4
- * Validates:
5
- * 1. bestSummaryText() priority chain: core_summary > l1 > l0 > raw text
6
- * 2. formatStableResult uses bestSummaryText
7
- * 3. formatTaskResult uses bestSummaryText
8
- * 4. generateCoreSummary method on LLM client
9
- * 5. buildIngestedEntry includes core_summary in metadata when provided
10
- */
11
- import { describe, expect, it } from "bun:test";
12
- import { bestSummaryText, stripConversationMarkers } from "../context-composer-text.js";
13
-
14
- // ---------------------------------------------------------------------------
15
- // bestSummaryText() priority chain
16
- // ---------------------------------------------------------------------------
17
-
18
- describe("bestSummaryText", () => {
19
- const rawText = "[用户] I am a developer working on memory systems for AI agents";
20
-
21
- it("returns core_summary when available", () => {
22
- const meta = JSON.stringify({
23
- core_summary: "Developer building AI agent memory systems",
24
- l1_overview: "Longer L1 overview text here",
25
- l0_abstract: "Short L0",
26
- });
27
- expect(bestSummaryText(rawText, meta)).toBe("Developer building AI agent memory systems");
28
- });
29
-
30
- it("falls back to l1_overview when no core_summary", () => {
31
- const meta = JSON.stringify({
32
- l1_overview: "L1: Developer working on AI memory",
33
- l0_abstract: "Short L0",
34
- });
35
- expect(bestSummaryText(rawText, meta)).toBe("L1: Developer working on AI memory");
36
- });
37
-
38
- it("falls back to l0_abstract when no core_summary or l1", () => {
39
- const meta = JSON.stringify({
40
- l0_abstract: "Dev + AI memory",
41
- });
42
- expect(bestSummaryText(rawText, meta)).toBe("Dev + AI memory");
43
- });
44
-
45
- it("falls back to stripped raw text when no summaries", () => {
46
- const meta = JSON.stringify({});
47
- expect(bestSummaryText(rawText, meta)).toBe(stripConversationMarkers(rawText));
48
- });
49
-
50
- it("falls back to stripped raw text when metadata is undefined", () => {
51
- expect(bestSummaryText(rawText, undefined)).toBe(stripConversationMarkers(rawText));
52
- });
53
-
54
- it("falls back to stripped raw text when metadata is invalid JSON", () => {
55
- expect(bestSummaryText(rawText, "not-json")).toBe(stripConversationMarkers(rawText));
56
- });
57
-
58
- it("skips empty core_summary string", () => {
59
- const meta = JSON.stringify({
60
- core_summary: "",
61
- l1_overview: "L1 text",
62
- });
63
- expect(bestSummaryText(rawText, meta)).toBe("L1 text");
64
- });
65
-
66
- it("skips empty l1_overview string", () => {
67
- const meta = JSON.stringify({
68
- core_summary: "",
69
- l1_overview: "",
70
- l0_abstract: "L0 text",
71
- });
72
- expect(bestSummaryText(rawText, meta)).toBe("L0 text");
73
- });
74
- });
75
-
76
- // ---------------------------------------------------------------------------
77
- // Metadata integration
78
- // ---------------------------------------------------------------------------
79
-
80
- describe("core_summary in metadata", () => {
81
- it("buildIngestedEntry includes core_summary when provided", () => {
82
- // We test the metadata structure directly since buildIngestedEntry
83
- // is a private function — we verify through the metadata shape
84
- const metadata = JSON.stringify({
85
- source: "test",
86
- l0_abstract: "Short summary",
87
- l1_overview: "Medium summary",
88
- l2_content: "Full text content",
89
- core_summary: "Core distilled summary ≤200 chars",
90
- tier: "working",
91
- boundary: { layer: "durable", authority: "derived" },
92
- });
93
-
94
- const parsed = JSON.parse(metadata);
95
- expect(parsed.core_summary).toBe("Core distilled summary ≤200 chars");
96
- expect(bestSummaryText("raw fallback", metadata)).toBe("Core distilled summary ≤200 chars");
97
- });
98
-
99
- it("metadata without core_summary falls back correctly", () => {
100
- const metadata = JSON.stringify({
101
- source: "test",
102
- l0_abstract: "Short",
103
- l1_overview: "Medium length overview",
104
- l2_content: "Full text",
105
- });
106
-
107
- expect(bestSummaryText("raw text", metadata)).toBe("Medium length overview");
108
- });
109
- });
@@ -1,225 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import { runDataCheckup, formatCheckupReport, type CheckupReport } from "../data-checkup.js";
3
- import type { MemoryEntry, MemoryStore } from "../store.js";
4
-
5
- // ---------------------------------------------------------------------------
6
- // Helpers
7
- // ---------------------------------------------------------------------------
8
-
9
- function makeEntry(overrides: Partial<MemoryEntry> & { id: string }): MemoryEntry {
10
- return {
11
- text: "test memory",
12
- vector: [1, 0, 0, 0, 0],
13
- category: "events",
14
- scope: "project:test",
15
- importance: 0.7,
16
- timestamp: Date.now(),
17
- metadata: JSON.stringify({
18
- evolution: {
19
- status: "active",
20
- version: 1,
21
- accessCount: 0,
22
- lastAccessedAt: null,
23
- supersededBy: null,
24
- consolidatedInto: null,
25
- contributedToPattern: null,
26
- sourceMemories: [],
27
- validFrom: Date.now(),
28
- validUntil: null,
29
- },
30
- }),
31
- ...overrides,
32
- };
33
- }
34
-
35
- function createMockStore(entries: MemoryEntry[]): Pick<MemoryStore, "list" | "stats"> {
36
- return {
37
- async list() { return entries; },
38
- async stats() {
39
- return { totalCount: entries.length, scopeCounts: {}, categoryCounts: {} };
40
- },
41
- } as Pick<MemoryStore, "list" | "stats">;
42
- }
43
-
44
- // ---------------------------------------------------------------------------
45
- // Tests
46
- // ---------------------------------------------------------------------------
47
-
48
- describe("runDataCheckup", () => {
49
- it("returns all-ok for healthy data", async () => {
50
- const entries = [
51
- makeEntry({ id: "a" }),
52
- makeEntry({ id: "b" }),
53
- makeEntry({ id: "c" }),
54
- ];
55
-
56
- const report = await runDataCheckup({
57
- store: createMockStore(entries),
58
- openConflictCount: 0,
59
- });
60
-
61
- expect(report.checks.length).toBe(6);
62
- expect(report.checks.every(c => c.status === "ok")).toBe(true);
63
- expect(report.totalEntries).toBe(3);
64
- });
65
-
66
- it("detects vector dimension inconsistency", async () => {
67
- const entries = [
68
- makeEntry({ id: "a", vector: [1, 0, 0, 0, 0] }),
69
- makeEntry({ id: "b", vector: [1, 0, 0] }), // wrong dim
70
- makeEntry({ id: "c", vector: [1, 0, 0, 0, 0] }),
71
- ];
72
-
73
- const report = await runDataCheckup({
74
- store: createMockStore(entries),
75
- openConflictCount: 0,
76
- });
77
-
78
- const dimCheck = report.checks.find(c => c.name === "vector_dimensions")!;
79
- expect(dimCheck.status).toBe("error");
80
- expect(dimCheck.detail).toContain("1 entries have wrong dimension");
81
- });
82
-
83
- it("detects orphan memories with empty scope", async () => {
84
- const entries = [
85
- makeEntry({ id: "a", scope: "project:test" }),
86
- makeEntry({ id: "b", scope: "" }),
87
- makeEntry({ id: "c", scope: "__schema__" }),
88
- ];
89
-
90
- const report = await runDataCheckup({
91
- store: createMockStore(entries),
92
- openConflictCount: 0,
93
- });
94
-
95
- const orphanCheck = report.checks.find(c => c.name === "orphan_memories")!;
96
- expect(orphanCheck.status).toBe("warning");
97
- expect(orphanCheck.detail).toContain("2 memories");
98
- });
99
-
100
- it("warns about unhealthy tier distribution — too many core", async () => {
101
- // Make 501 core entries (tier resolved from metadata top-level importance >= 0.95)
102
- const entries = Array.from({ length: 501 }, (_, i) =>
103
- makeEntry({
104
- id: `core-${i}`,
105
- importance: 0.99,
106
- metadata: JSON.stringify({
107
- importance: 0.99,
108
- accessCount: 10,
109
- evolution: { status: "active", version: 1, accessCount: 10, lastAccessedAt: null, supersededBy: null, consolidatedInto: null, contributedToPattern: null, sourceMemories: [], validFrom: Date.now(), validUntil: null },
110
- }),
111
- })
112
- );
113
-
114
- const report = await runDataCheckup({
115
- store: createMockStore(entries),
116
- openConflictCount: 0,
117
- });
118
-
119
- const tierCheck = report.checks.find(c => c.name === "tier_distribution")!;
120
- expect(tierCheck.status).toBe("warning");
121
- expect(tierCheck.detail).toContain("core tier has 501");
122
- });
123
-
124
- it("reports conflict backlog levels", async () => {
125
- // 0 = ok
126
- const r0 = await runDataCheckup({ store: createMockStore([]), openConflictCount: 0 });
127
- expect(r0.checks.find(c => c.name === "conflict_backlog")!.status).toBe("ok");
128
-
129
- // 3 = still ok
130
- const r3 = await runDataCheckup({ store: createMockStore([]), openConflictCount: 3 });
131
- expect(r3.checks.find(c => c.name === "conflict_backlog")!.status).toBe("ok");
132
-
133
- // 10 = warning
134
- const r10 = await runDataCheckup({ store: createMockStore([]), openConflictCount: 10 });
135
- expect(r10.checks.find(c => c.name === "conflict_backlog")!.status).toBe("warning");
136
-
137
- // 25 = error
138
- const r25 = await runDataCheckup({ store: createMockStore([]), openConflictCount: 25 });
139
- expect(r25.checks.find(c => c.name === "conflict_backlog")!.status).toBe("error");
140
- });
141
-
142
- it("detects version group issues — single-member group", async () => {
143
- const entries = [
144
- makeEntry({
145
- id: "a",
146
- metadata: JSON.stringify({
147
- version_group: "vg-abc",
148
- version_rank: 2.5,
149
- evolution: { status: "active", version: 1, accessCount: 0, lastAccessedAt: null, supersededBy: null, consolidatedInto: null, contributedToPattern: null, sourceMemories: [], validFrom: Date.now(), validUntil: null },
150
- }),
151
- }),
152
- // vg-abc has only 1 member — suspicious
153
- ];
154
-
155
- const report = await runDataCheckup({
156
- store: createMockStore(entries),
157
- openConflictCount: 0,
158
- });
159
-
160
- const vgCheck = report.checks.find(c => c.name === "version_groups")!;
161
- expect(vgCheck.status).toBe("warning");
162
- expect(vgCheck.detail).toContain("only 1 member");
163
- });
164
-
165
- it("detects version group with missing rank", async () => {
166
- const entries = [
167
- makeEntry({
168
- id: "a",
169
- metadata: JSON.stringify({
170
- version_group: "vg-xyz",
171
- version_rank: 2.0,
172
- evolution: { status: "active", version: 1, accessCount: 0, lastAccessedAt: null, supersededBy: null, consolidatedInto: null, contributedToPattern: null, sourceMemories: [], validFrom: Date.now(), validUntil: null },
173
- }),
174
- }),
175
- makeEntry({
176
- id: "b",
177
- metadata: JSON.stringify({
178
- version_group: "vg-xyz",
179
- // version_rank missing
180
- evolution: { status: "active", version: 1, accessCount: 0, lastAccessedAt: null, supersededBy: null, consolidatedInto: null, contributedToPattern: null, sourceMemories: [], validFrom: Date.now(), validUntil: null },
181
- }),
182
- }),
183
- ];
184
-
185
- const report = await runDataCheckup({
186
- store: createMockStore(entries),
187
- openConflictCount: 0,
188
- });
189
-
190
- const vgCheck = report.checks.find(c => c.name === "version_groups")!;
191
- expect(vgCheck.status).toBe("warning");
192
- expect(vgCheck.detail).toContain("missing rank");
193
- });
194
-
195
- it("handles empty database", async () => {
196
- const report = await runDataCheckup({
197
- store: createMockStore([]),
198
- openConflictCount: 0,
199
- });
200
-
201
- expect(report.totalEntries).toBe(0);
202
- expect(report.checks.every(c => c.status === "ok")).toBe(true);
203
- });
204
- });
205
-
206
- describe("formatCheckupReport", () => {
207
- it("formats report with mix of statuses", () => {
208
- const report: CheckupReport = {
209
- checks: [
210
- { name: "check_a", status: "ok", detail: "all good" },
211
- { name: "check_b", status: "warning", detail: "minor issue" },
212
- { name: "check_c", status: "error", detail: "big problem" },
213
- ],
214
- totalEntries: 100,
215
- timestamp: "2026-04-03T12:00:00.000Z",
216
- };
217
-
218
- const output = formatCheckupReport(report);
219
- expect(output).toContain("[OK] check_a");
220
- expect(output).toContain("[WARN] check_b");
221
- expect(output).toContain("[ERR] check_c");
222
- expect(output).toContain("1 error(s), 1 warning(s), 1 ok");
223
- expect(output).toContain("Total entries scanned: 100");
224
- });
225
- });
@@ -1,84 +0,0 @@
1
- import { describe, it, expect } from "bun:test";
2
- import { isDecayExempt } from "../decay-engine.js";
3
-
4
- describe("HP-7: Decay exemption rules", () => {
5
- describe("Rule 1: core tier + importance ≥ 0.95", () => {
6
- it("exempts explicit core with high importance", () => {
7
- const meta = JSON.stringify({ tier: "core", importance: 0.95 });
8
- expect(isDecayExempt(meta, 0.95)).toBe(true);
9
- });
10
-
11
- it("exempts inferred core (importance ≥ 0.95)", () => {
12
- const meta = JSON.stringify({ importance: 0.96 });
13
- expect(isDecayExempt(meta, 0.96)).toBe(true);
14
- });
15
-
16
- it("does NOT exempt core with importance < 0.95", () => {
17
- const meta = JSON.stringify({ tier: "core", importance: 0.90 });
18
- expect(isDecayExempt(meta, 0.90)).toBe(false);
19
- });
20
-
21
- it("does NOT exempt working tier even with high importance", () => {
22
- const meta = JSON.stringify({ tier: "working", importance: 0.96 });
23
- expect(isDecayExempt(meta, 0.96)).toBe(false);
24
- });
25
- });
26
-
27
- describe("Rule 2: recently accessed (within 7 days)", () => {
28
- it("exempts memory accessed 1 day ago", () => {
29
- const meta = JSON.stringify({
30
- lastAccessedAt: Date.now() - 1 * 86_400_000,
31
- });
32
- expect(isDecayExempt(meta, 0.50)).toBe(true);
33
- });
34
-
35
- it("does NOT exempt memory accessed 8 days ago", () => {
36
- const meta = JSON.stringify({
37
- lastAccessedAt: Date.now() - 8 * 86_400_000,
38
- });
39
- expect(isDecayExempt(meta, 0.50)).toBe(false);
40
- });
41
-
42
- it("does NOT exempt when lastAccessedAt is 0", () => {
43
- const meta = JSON.stringify({ lastAccessedAt: 0 });
44
- expect(isDecayExempt(meta, 0.50)).toBe(false);
45
- });
46
- });
47
-
48
- describe("Rule 3: pinned tag", () => {
49
- it("exempts memory with pinned tag", () => {
50
- const meta = JSON.stringify({ tags: ["workflow", "pinned"] });
51
- expect(isDecayExempt(meta, 0.40)).toBe(true);
52
- });
53
-
54
- it("does NOT exempt without pinned tag", () => {
55
- const meta = JSON.stringify({ tags: ["workflow", "pattern"] });
56
- expect(isDecayExempt(meta, 0.40)).toBe(false);
57
- });
58
- });
59
-
60
- describe("edge cases", () => {
61
- it("returns false for undefined metadata", () => {
62
- expect(isDecayExempt(undefined, 0.95)).toBe(false);
63
- });
64
-
65
- it("returns false for empty metadata", () => {
66
- expect(isDecayExempt("{}", 0.50)).toBe(false);
67
- });
68
-
69
- it("returns false for corrupt metadata", () => {
70
- expect(isDecayExempt("not-json", 0.95)).toBe(false);
71
- });
72
-
73
- it("multiple rules: first match wins", () => {
74
- // Core + pinned + recent — all three rules match
75
- const meta = JSON.stringify({
76
- tier: "core",
77
- importance: 0.98,
78
- lastAccessedAt: Date.now() - 3600000,
79
- tags: ["pinned"],
80
- });
81
- expect(isDecayExempt(meta, 0.98)).toBe(true);
82
- });
83
- });
84
- });