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,291 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import { mkdtempSync, readdirSync, rmSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
-
6
- import { buildSessionCheckpointRecord, buildSessionCheckpointResult, normalizeCheckpointScope, resolveCheckpointScope, type CheckpointQuality } from "../session-engine.js";
7
- import { formatCheckpointRecallSummary, formatCheckpointSaved, formatCheckpointSummary, formatResumeContext } from "../session-output.js";
8
- import { SessionCheckpointStore } from "../session-store.js";
9
-
10
- describe("session checkpoint engine", () => {
11
- it("defaults checkpoint scope to session:<sessionId>", () => {
12
- const record = buildSessionCheckpointRecord({
13
- sessionId: "session-abc",
14
- summary: "Implement checkpoint storage",
15
- });
16
-
17
- expect(resolveCheckpointScope(record)).toBe("session:session-abc");
18
- expect(record.resolvedScope).toBe("session:session-abc");
19
- });
20
- });
21
-
22
- describe("SessionCheckpointStore", () => {
23
- it("saves and retrieves latest checkpoints by scope and session", async () => {
24
- const dir = mkdtempSync(join(tmpdir(), "recallnest-checkpoints-"));
25
- try {
26
- const store = new SessionCheckpointStore(dir);
27
-
28
- const first = await store.save(buildSessionCheckpointRecord({
29
- sessionId: "session-1",
30
- scope: "agent:codex",
31
- summary: "First checkpoint",
32
- nextActions: ["Implement checkpoint_session"],
33
- updatedAt: "2026-03-16T03:00:00.000Z",
34
- }));
35
-
36
- const second = await store.save(buildSessionCheckpointRecord({
37
- sessionId: "session-2",
38
- scope: "agent:codex",
39
- summary: "Second checkpoint",
40
- updatedAt: "2026-03-16T03:05:00.000Z",
41
- }));
42
-
43
- const latestByScope = await store.getLatest({ scope: "agent:codex" });
44
- const latestBySession = await store.getLatest({ sessionId: "session-1" });
45
-
46
- expect(latestByScope?.checkpointId).toBe(second.checkpointId);
47
- expect(latestBySession?.checkpointId).toBe(first.checkpointId);
48
- } finally {
49
- rmSync(dir, { recursive: true, force: true });
50
- }
51
- });
52
-
53
- it("uses idempotencyKey to replace retried checkpoint files", async () => {
54
- const dir = mkdtempSync(join(tmpdir(), "recallnest-checkpoint-idempotency-"));
55
- try {
56
- const store = new SessionCheckpointStore(dir);
57
- const baseInput = {
58
- sessionId: "session-retry",
59
- scope: "project:recallnest",
60
- summary: "Save retry-safe checkpoint state.",
61
- decisions: ["Use explicit idempotency keys for client retries"],
62
- idempotencyKey: "checkpoint-request-123",
63
- };
64
-
65
- const first = await store.save(buildSessionCheckpointRecord({
66
- ...baseInput,
67
- updatedAt: "2026-06-26T01:00:00.000Z",
68
- }));
69
- const retried = await store.save(buildSessionCheckpointRecord({
70
- ...baseInput,
71
- updatedAt: "2026-06-26T01:01:00.000Z",
72
- }));
73
-
74
- expect(retried.checkpointId).toBe(first.checkpointId);
75
- expect(readdirSync(dir).filter((name) => name.endsWith(".json"))).toHaveLength(1);
76
-
77
- const recent = await store.listRecent({ sessionId: "session-retry", limit: 10 });
78
- expect(recent).toHaveLength(1);
79
- expect(recent[0]?.updatedAt).toBe("2026-06-26T01:01:00.000Z");
80
- } finally {
81
- rmSync(dir, { recursive: true, force: true });
82
- }
83
- });
84
- });
85
-
86
- describe("session checkpoint output", () => {
87
- it("formats saved and summary views", () => {
88
- const record = buildSessionCheckpointRecord({
89
- sessionId: "session-xyz",
90
- summary: "Current task is implementing session checkpoints",
91
- decisions: ["Keep checkpoints out of LanceDB"],
92
- openLoops: ["Need resume_context next"],
93
- nextActions: ["Add latest checkpoint API"],
94
- });
95
-
96
- expect(formatCheckpointSaved(record)).toContain("Keep checkpoints out of LanceDB");
97
- expect(formatCheckpointSummary(record)).toContain("Latest checkpoint");
98
- expect(formatCheckpointSummary(null)).toBe("No checkpoint found.");
99
- });
100
-
101
- it("enriches recall checkpoint summaries with missing entity hints only once", () => {
102
- const record = buildSessionCheckpointRecord({
103
- sessionId: "session-entity-hints",
104
- summary: "Raised continuity coverage for RecallNest startup recovery.",
105
- entities: ["RecallNest", "smoke:claude-continuity", "resume_context"],
106
- });
107
-
108
- expect(formatCheckpointRecallSummary(record)).toBe(
109
- "Raised continuity coverage for RecallNest startup recovery. Entities: smoke:claude-continuity, resume_context",
110
- );
111
- });
112
-
113
- it("includes recall-only guidance in formatted resume context output", () => {
114
- const output = formatResumeContext({
115
- summary: "Stable context: Preference: 用户不喜欢 AI 味太重的文案语气。",
116
- resolvedScope: "project:writing",
117
- stableContext: ["Preference: 用户不喜欢 AI 味太重的文案语气。"],
118
- relevantPatterns: [],
119
- recentCases: [],
120
- latestCheckpoint: {
121
- sessionId: "session-writing",
122
- resolvedScope: "project:writing",
123
- summary: "Continue writing-style preference recovery.",
124
- updatedAt: "2026-03-16T04:30:00.000Z",
125
- },
126
- responseMode: "recall-only",
127
- responseGuidance: "Recall-only mode: answer from the recalled stable context item only.",
128
- generatedAt: "2026-03-16T04:40:00.000Z",
129
- });
130
-
131
- expect(output).toContain("Scope: project:writing");
132
- expect(output).toContain("Response mode: recall-only");
133
- expect(output).toContain("Guidance: Recall-only mode");
134
- expect(output).toContain("Stable context:");
135
- });
136
-
137
- it("sanitizes repo-state text out of checkpoint content", () => {
138
- const result = buildSessionCheckpointResult({
139
- sessionId: "session-repo-state",
140
- summary: "Only resumed context in this window. git status shows many modified files.",
141
- task: "Handle git status follow-up",
142
- decisions: ["Keep repo-state out of checkpoints."],
143
- openLoops: ["git status shows many uncommitted changes that still need review"],
144
- nextActions: ["Process modified files after checking git status locally"],
145
- });
146
- const { record } = result;
147
-
148
- expect(record.summary).toBe("Checkpoint captured current task state without repo-state details.");
149
- expect(record.task).toBeUndefined();
150
- expect(record.decisions).toEqual(["Keep repo-state out of checkpoints."]);
151
- expect(record.openLoops).toEqual(["Current repo state still needs local verification if it matters for the next task."]);
152
- expect(record.nextActions).toEqual(["Verify current repo state locally if it matters for the next task."]);
153
- expect(result.sanitization.changed).toBe(true);
154
- expect(result.sanitization.changedFields).toEqual(["summary", "task", "openLoops", "nextActions"]);
155
- });
156
-
157
- it("does not mark sanitization when checkpoint content is already clean", () => {
158
- const result = buildSessionCheckpointResult({
159
- sessionId: "session-clean",
160
- summary: "Continue wiring workflow observations into managed continuity.",
161
- task: "Hook managed continuity observations",
162
- decisions: ["Keep observations out of durable memory."],
163
- openLoops: ["Need to update the managed snippets."],
164
- nextActions: ["Add MCP and HTTP auto-observation coverage."],
165
- });
166
-
167
- expect(result.sanitization.changed).toBe(false);
168
- expect(result.sanitization.changedFields).toEqual([]);
169
- });
170
- });
171
-
172
- describe("checkpoint scope normalization", () => {
173
- it("normalizes bare project names to project: prefix", () => {
174
- expect(normalizeCheckpointScope("recallnest")).toBe("project:recallnest");
175
- expect(normalizeCheckpointScope("RecallNest")).toBe("project:recallnest");
176
- expect(normalizeCheckpointScope("telegram-bridge")).toBe("project:telegram-bridge");
177
- });
178
-
179
- it("preserves existing prefixes but lowercases", () => {
180
- expect(normalizeCheckpointScope("project:RecallNest")).toBe("project:recallnest");
181
- expect(normalizeCheckpointScope("session:abc")).toBe("session:abc");
182
- expect(normalizeCheckpointScope("eval:continuity")).toBe("eval:continuity");
183
- });
184
-
185
- it("applies normalization at save time via resolveCheckpointScope", () => {
186
- expect(resolveCheckpointScope({ sessionId: "s1", scope: "RecallNest" })).toBe("project:recallnest");
187
- expect(resolveCheckpointScope({ sessionId: "s1", scope: "project:RecallNest" })).toBe("project:recallnest");
188
- expect(resolveCheckpointScope({ sessionId: "s1" })).toBe("session:s1");
189
- });
190
-
191
- it("matches checkpoints across scope variants in getLatest", async () => {
192
- const dir = mkdtempSync(join(tmpdir(), "recallnest-scope-norm-"));
193
- try {
194
- const store = new SessionCheckpointStore(dir);
195
-
196
- // Save with bare "recallnest" — will be normalized to "project:recallnest"
197
- await store.save(buildSessionCheckpointRecord({
198
- sessionId: "s-bare",
199
- scope: "recallnest",
200
- summary: "Bare scope checkpoint",
201
- }));
202
-
203
- // Save with "project:RecallNest" — will be normalized to "project:recallnest"
204
- const later = buildSessionCheckpointRecord({
205
- sessionId: "s-cased",
206
- scope: "project:RecallNest",
207
- summary: "Cased scope checkpoint",
208
- });
209
- // Manually set a later timestamp
210
- (later as any).updatedAt = new Date(Date.now() + 1000).toISOString().replace(/\.\d+Z$/, ".000Z");
211
- await store.save(later);
212
-
213
- // Query with canonical "project:recallnest" should find both, return latest
214
- const latest = await store.getLatest({ scope: "project:recallnest" });
215
- expect(latest).not.toBeNull();
216
- expect(latest!.summary).toBe("Cased scope checkpoint");
217
-
218
- // Query with bare "recallnest" should also work
219
- const latestBare = await store.getLatest({ scope: "recallnest" });
220
- expect(latestBare).not.toBeNull();
221
- expect(latestBare!.summary).toBe("Cased scope checkpoint");
222
- } finally {
223
- rmSync(dir, { recursive: true, force: true });
224
- }
225
- });
226
- });
227
-
228
- describe("checkpoint quality gate", () => {
229
- it("classifies checkpoints with fallback summary and empty fields as minimal", () => {
230
- const result = buildSessionCheckpointResult({
231
- sessionId: "s-empty",
232
- scope: "project:recallnest",
233
- summary: "git status shows 5 modified files and 3 untracked files",
234
- });
235
- // Summary was sanitized to fallback, no decisions/openLoops/nextActions
236
- expect(result.quality).toBe("minimal");
237
- expect(result.sanitization.changed).toBe(true);
238
- });
239
-
240
- it("classifies checkpoints with real content as rich", () => {
241
- const result = buildSessionCheckpointResult({
242
- sessionId: "s-rich",
243
- scope: "project:recallnest",
244
- summary: "Completed scope normalization and checkpoint quality gate.",
245
- decisions: ["Normalize scope at save and query time"],
246
- });
247
- expect(result.quality).toBe("rich");
248
- });
249
-
250
- it("classifies checkpoints with fallback summary but structured fields as rich", () => {
251
- const result = buildSessionCheckpointResult({
252
- sessionId: "s-mixed",
253
- scope: "project:recallnest",
254
- summary: "git status shows dirty worktree",
255
- decisions: ["Keep using bun for builds"],
256
- });
257
- // Summary sanitized to fallback but decisions non-empty → still rich
258
- expect(result.quality).toBe("rich");
259
- });
260
-
261
- it("prefers rich checkpoints over minimal ones in getLatest", async () => {
262
- const dir = mkdtempSync(join(tmpdir(), "recallnest-quality-gate-"));
263
- try {
264
- const store = new SessionCheckpointStore(dir);
265
-
266
- // Save a rich checkpoint first (older)
267
- await store.save(buildSessionCheckpointRecord({
268
- sessionId: "s-rich",
269
- scope: "project:recallnest",
270
- summary: "Good checkpoint with real content.",
271
- decisions: ["Keep checkpoints clean"],
272
- updatedAt: "2026-03-22T01:00:00.000Z",
273
- }));
274
-
275
- // Save a minimal checkpoint later (newer) — all-sanitized fallback
276
- await store.save(buildSessionCheckpointRecord({
277
- sessionId: "s-minimal",
278
- scope: "project:recallnest",
279
- summary: "Checkpoint captured current task state without repo-state details.",
280
- updatedAt: "2026-03-22T02:00:00.000Z",
281
- }));
282
-
283
- const latest = await store.getLatest({ scope: "project:recallnest" });
284
- expect(latest).not.toBeNull();
285
- // Should return the rich one even though it's older
286
- expect(latest!.summary).toBe("Good checkpoint with real content.");
287
- } finally {
288
- rmSync(dir, { recursive: true, force: true });
289
- }
290
- });
291
- });