recallnest 2.3.0 → 2.5.4
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.
- package/CHANGELOG.md +150 -0
- package/README.md +17 -31
- package/README_CN.md +12 -22
- package/assets/ui/app.js +1031 -0
- package/assets/ui/index.html +224 -0
- package/assets/ui/styles.css +781 -0
- package/config.json.example +4 -1
- package/docs/api-reference.md +1291 -0
- package/docs/architecture.md +168 -0
- package/docs/connector-spec.md +126 -0
- package/eval/cases-canary.json +58 -0
- package/eval/cases-scope-robustness.json +278 -0
- package/eval/cases.json +117 -20
- package/package.json +22 -1
- package/src/__tests__/access-tracker-novelty.test.ts +238 -0
- package/src/__tests__/activity-counter.test.ts +125 -0
- package/src/__tests__/adaptive-fidelity.test.ts +102 -0
- package/src/__tests__/admission-control.test.ts +206 -0
- package/src/__tests__/anchor-generator.test.ts +67 -0
- package/src/__tests__/auto-consolidation.test.ts +168 -0
- package/src/__tests__/auto-recall.test.ts +131 -0
- package/src/__tests__/babel-integration.test.ts +144 -0
- package/src/__tests__/batch-dedup.test.ts +65 -0
- package/src/__tests__/canary-eval.test.ts +114 -0
- package/src/__tests__/capture-engine.test.ts +1238 -0
- package/src/__tests__/capture-heuristic.test.ts +171 -0
- package/src/__tests__/cascade-forget.test.ts +210 -0
- package/src/__tests__/category-min-scores.test.ts +33 -0
- package/src/__tests__/cc8-cc1-essential-context.test.ts +298 -0
- package/src/__tests__/circuit-breaker.test.ts +99 -0
- package/src/__tests__/cluster-consolidation.test.ts +782 -0
- package/src/__tests__/confidence-metadata.test.ts +125 -0
- package/src/__tests__/confidence-tracker.test.ts +261 -0
- package/src/__tests__/conflict-advisor.test.ts +206 -0
- package/src/__tests__/conflict-escalation.test.ts +149 -0
- package/src/__tests__/conflict-lifecycle.test.ts +83 -0
- package/src/__tests__/conflict-output.test.ts +85 -0
- package/src/__tests__/conflict-store.test.ts +374 -0
- package/src/__tests__/connector-v1.test.ts +181 -0
- package/src/__tests__/consolidation-engine.test.ts +333 -0
- package/src/__tests__/constructive-retrieval.test.ts +509 -0
- package/src/__tests__/context-collapse-renderer.test.ts +214 -0
- package/src/__tests__/context-composer-pins.test.ts +64 -0
- package/src/__tests__/context-composer-task-selection.test.ts +24 -0
- package/src/__tests__/context-reconstructor.test.ts +65 -0
- package/src/__tests__/context-renderer.test.ts +91 -0
- package/src/__tests__/continuity-eval.test.ts +275 -0
- package/src/__tests__/continuity-schema.test.ts +97 -0
- package/src/__tests__/contracts.test.ts +216 -0
- package/src/__tests__/conversation-importer.test.ts +692 -0
- package/src/__tests__/core-recall-eval.test.ts +235 -0
- package/src/__tests__/core-summary.test.ts +109 -0
- package/src/__tests__/data-checkup.test.ts +276 -0
- package/src/__tests__/decay-exemption.test.ts +84 -0
- package/src/__tests__/dedup-actions.test.ts +58 -0
- package/src/__tests__/dedup-guard.test.ts +39 -0
- package/src/__tests__/deterministic-id.test.ts +39 -0
- package/src/__tests__/distill-lock.test.ts +305 -0
- package/src/__tests__/distill-session-argshape.test.ts +79 -0
- package/src/__tests__/doctor.test.ts +319 -0
- package/src/__tests__/dream-pipeline.test.ts +321 -0
- package/src/__tests__/drill-down.test.ts +108 -0
- package/src/__tests__/embedder.test.ts +122 -0
- package/src/__tests__/emotion-decay.test.ts +46 -0
- package/src/__tests__/emotion-detector.test.ts +56 -0
- package/src/__tests__/emotion-phase1-integration.test.ts +153 -0
- package/src/__tests__/emotion-retrieval.test.ts +56 -0
- package/src/__tests__/entity-resolver.test.ts +58 -0
- package/src/__tests__/env-config.test.ts +151 -0
- package/src/__tests__/error-signature-boost.test.ts +87 -0
- package/src/__tests__/error-signature.test.ts +95 -0
- package/src/__tests__/error-taxonomy.test.ts +129 -0
- package/src/__tests__/ethics-layer.test.ts +476 -0
- package/src/__tests__/event-segmenter.test.ts +153 -0
- package/src/__tests__/feature-flags-integration.test.ts +54 -0
- package/src/__tests__/frequency-tracker.test.ts +113 -0
- package/src/__tests__/graph-export.test.ts +489 -0
- package/src/__tests__/hotness-blend.test.ts +76 -0
- package/src/__tests__/ingest-chunking.test.ts +44 -0
- package/src/__tests__/ingest.test.ts +360 -0
- package/src/__tests__/interference-detector.test.ts +203 -0
- package/src/__tests__/kg-extractor.test.ts +192 -0
- package/src/__tests__/kg-store.test.ts +300 -0
- package/src/__tests__/llm-consolidation.test.ts +226 -0
- package/src/__tests__/maintenance-locks.test.ts +174 -0
- package/src/__tests__/mcp-efficiency.test.ts +288 -0
- package/src/__tests__/mcp-related-scopes.test.ts +151 -0
- package/src/__tests__/memory-boundaries.test.ts +250 -0
- package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +345 -0
- package/src/__tests__/memory-evolution.test.ts +271 -0
- package/src/__tests__/memory-health-rebalance.test.ts +144 -0
- package/src/__tests__/memory-lint.test.ts +421 -0
- package/src/__tests__/memory-output.test.ts +215 -0
- package/src/__tests__/memory-promotion.test.ts +315 -0
- package/src/__tests__/migrate-dedup-ids.test.ts +65 -0
- package/src/__tests__/multi-vector.test.ts +242 -0
- package/src/__tests__/narrative-architecture.test.ts +456 -0
- package/src/__tests__/noise-filter.test.ts +205 -0
- package/src/__tests__/obsidian-connector.test.ts +363 -0
- package/src/__tests__/omitted-reporting.test.ts +98 -0
- package/src/__tests__/pending-review.test.ts +77 -0
- package/src/__tests__/pii-redact.test.ts +314 -0
- package/src/__tests__/post-retrieval-filter.test.ts +178 -0
- package/src/__tests__/ppr-traversal.test.ts +256 -0
- package/src/__tests__/prediction-engine.test.ts +349 -0
- package/src/__tests__/predictive-prospective-memory.test.ts +416 -0
- package/src/__tests__/preference-guard-smoke.test.ts +211 -0
- package/src/__tests__/preference-matcher.test.ts +230 -0
- package/src/__tests__/preference-slots.test.ts +205 -0
- package/src/__tests__/prospective-memory.test.ts +283 -0
- package/src/__tests__/query-entity-detector.test.ts +171 -0
- package/src/__tests__/query-expander-alias.test.ts +146 -0
- package/src/__tests__/query-expander.test.ts +34 -0
- package/src/__tests__/recall-governor.test.ts +227 -0
- package/src/__tests__/recall-mode.test.ts +64 -0
- package/src/__tests__/result-synthesizer.test.ts +198 -0
- package/src/__tests__/resume-context.test.ts +4898 -0
- package/src/__tests__/retrieval-trace.test.ts +213 -0
- package/src/__tests__/retriever-boundary-weight.test.ts +136 -0
- package/src/__tests__/retroactive-boost.test.ts +223 -0
- package/src/__tests__/salience-scoring.test.ts +106 -0
- package/src/__tests__/scope-inventory.test.ts +200 -0
- package/src/__tests__/scope-policy.test.ts +69 -0
- package/src/__tests__/scope-suggester.test.ts +80 -0
- package/src/__tests__/session-checkpoint.test.ts +291 -0
- package/src/__tests__/session-distiller.test.ts +640 -0
- package/src/__tests__/session-gc.test.ts +215 -0
- package/src/__tests__/skill-engine.test.ts +552 -0
- package/src/__tests__/skill-promotion.test.ts +601 -0
- package/src/__tests__/skill-verifier.test.ts +122 -0
- package/src/__tests__/source-heartbeat.test.ts +250 -0
- package/src/__tests__/store-patch-metadata.test.ts +205 -0
- package/src/__tests__/store-scope-audit.test.ts +81 -0
- package/src/__tests__/store-upsert.test.ts +184 -0
- package/src/__tests__/supersede-chain.test.ts +154 -0
- package/src/__tests__/temporal-parser.test.ts +241 -0
- package/src/__tests__/temporal-validity.test.ts +160 -0
- package/src/__tests__/term-registry.test.ts +121 -0
- package/src/__tests__/tool-error-surfacing.test.ts +98 -0
- package/src/__tests__/tool-output-compressor.test.ts +160 -0
- package/src/__tests__/topic-tag.test.ts +113 -0
- package/src/__tests__/trusted-memory.test.ts +839 -0
- package/src/__tests__/usage-tracker.test.ts +287 -0
- package/src/__tests__/version-manager.test.ts +213 -0
- package/src/__tests__/workflow-observation-skill-outcome.test.ts +352 -0
- package/src/__tests__/workflow-observation.test.ts +433 -0
- package/src/__tests__/write-verifier.test.ts +122 -0
- package/src/access-tracker.ts +38 -32
- package/src/activity-counter.ts +46 -18
- package/src/aliases.ts +133 -0
- package/src/api-server.ts +27 -7
- package/src/audit-log.ts +4 -2
- package/src/auto-consolidation.ts +8 -3
- package/src/auto-gc.ts +85 -21
- package/src/capture-engine.ts +54 -21
- package/src/cli.ts +169 -37
- package/src/confidence-tracker.ts +36 -18
- package/src/consolidation-engine.ts +109 -11
- package/src/context-composer.ts +8 -1
- package/src/data-checkup.ts +95 -6
- package/src/distill-lock.ts +194 -15
- package/src/doctor.ts +9 -2
- package/src/dream-pipeline.ts +118 -34
- package/src/env-config.ts +77 -0
- package/src/error-signature.ts +153 -0
- package/src/error-taxonomy.ts +115 -0
- package/src/eval.ts +251 -6
- package/src/idempotency.ts +8 -0
- package/src/ingest.ts +31 -10
- package/src/kg-extractor.ts +6 -2
- package/src/kg-store.ts +236 -44
- package/src/llm-consolidation.ts +2 -1
- package/src/mcp-server.ts +85 -1799
- package/src/mcp-tool-deps.ts +48 -0
- package/src/mcp-tools-advanced.ts +941 -0
- package/src/mcp-tools-core.ts +633 -0
- package/src/mcp-tools-governance.ts +475 -0
- package/src/memory-boundaries.ts +3 -1
- package/src/memory-evolution.ts +73 -1
- package/src/memory-lint.ts +183 -10
- package/src/memory-output.ts +114 -3
- package/src/memory-promotion.ts +246 -0
- package/src/memory-schema.ts +25 -2
- package/src/memory-store-port.ts +43 -0
- package/src/multi-vector.ts +2 -1
- package/src/narrative-schema.ts +2 -1
- package/src/noise-filter.ts +57 -6
- package/src/pii-detector.ts +157 -5
- package/src/query-expander.ts +90 -9
- package/src/result-synthesizer.ts +2 -1
- package/src/retention-policy.ts +2 -1
- package/src/retriever.ts +259 -139
- package/src/runtime-config.ts +8 -1
- package/src/scope-suggester.ts +113 -0
- package/src/session-distiller.ts +23 -2
- package/src/session-engine.ts +2 -1
- package/src/session-schema.ts +1 -0
- package/src/session-store.ts +5 -0
- package/src/skill-engine.ts +78 -0
- package/src/skill-promotion.ts +247 -47
- package/src/skill-schema.ts +16 -3
- package/src/skill-verifier.ts +152 -0
- package/src/store.ts +267 -38
- package/src/tool-output-compressor.ts +3 -1
- package/src/ui-server.ts +2 -1
- package/src/usage-tracker.ts +242 -0
- package/src/version-manager.ts +3 -2
- package/src/workflow-observation-engine.ts +2 -1
- package/src/workflow-observation-schema.ts +2 -1
- package/src/workflow-observation-store.ts +6 -2
- package/.env +0 -4
- package/CLAUDE.md +0 -46
- package/config.json +0 -55
- package/daily-recall.sh +0 -110
- package/logs/daily-recall.error.log +0 -0
- package/logs/daily-recall.log +0 -60
- package/logs/ingest-2026-04-11.log +0 -110
- package/logs/ingest-2026-04-12.log +0 -90
- package/logs/ingest-2026-04-13.log +0 -87
- package/logs/launchagent-stderr.log +0 -0
- package/logs/launchagent-stdout.log +0 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
assessContinuityBaseline,
|
|
5
|
+
assessScopeInventoryReport,
|
|
6
|
+
describeSecretPresence,
|
|
7
|
+
formatDoctorResults,
|
|
8
|
+
loadContinuityBaselineEntries,
|
|
9
|
+
} from "../doctor.js";
|
|
10
|
+
import type { MemoryEntry } from "../store.js";
|
|
11
|
+
|
|
12
|
+
function buildEntry(
|
|
13
|
+
id: string,
|
|
14
|
+
category: MemoryEntry["category"],
|
|
15
|
+
text: string,
|
|
16
|
+
scope: string,
|
|
17
|
+
metadata: Record<string, unknown> = {},
|
|
18
|
+
): MemoryEntry {
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
text,
|
|
22
|
+
vector: [],
|
|
23
|
+
category,
|
|
24
|
+
scope,
|
|
25
|
+
importance: 0.8,
|
|
26
|
+
timestamp: Date.parse("2026-03-17T00:00:00.000Z"),
|
|
27
|
+
metadata: JSON.stringify(metadata),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("assessContinuityBaseline", () => {
|
|
32
|
+
it("reports full coverage when all canonical continuity seeds are present", () => {
|
|
33
|
+
const seeds = {
|
|
34
|
+
patterns: [
|
|
35
|
+
{
|
|
36
|
+
title: "Cross-window continuity handoff",
|
|
37
|
+
trigger: "When opening a fresh terminal window",
|
|
38
|
+
steps: ["Call resume_context before coding."],
|
|
39
|
+
outcome: "Fresh windows recover stable context.",
|
|
40
|
+
tools: ["resume_context"],
|
|
41
|
+
importance: 0.9,
|
|
42
|
+
source: "agent",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
cases: [
|
|
46
|
+
{
|
|
47
|
+
title: "Continuity eval checkpoint isolation",
|
|
48
|
+
problem: "Eval reads live checkpoints.",
|
|
49
|
+
solutionSteps: ["Use fixture checkpoints instead."],
|
|
50
|
+
outcome: "Continuity eval becomes deterministic.",
|
|
51
|
+
tools: ["eval:continuity"],
|
|
52
|
+
source: "agent",
|
|
53
|
+
scope: "recallnest",
|
|
54
|
+
importance: 0.85,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
memories: [
|
|
58
|
+
{
|
|
59
|
+
text: "RecallNest is the shared memory layer for Claude Code, Codex, and Gemini CLI.",
|
|
60
|
+
category: "entities",
|
|
61
|
+
scope: "recallnest",
|
|
62
|
+
source: "agent",
|
|
63
|
+
importance: 0.9,
|
|
64
|
+
canonicalKey: "entities:recallnest:shared-memory-layer",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const entries: MemoryEntry[] = [
|
|
70
|
+
buildEntry(
|
|
71
|
+
"pattern-1",
|
|
72
|
+
"patterns",
|
|
73
|
+
"Workflow pattern: Cross-window continuity handoff",
|
|
74
|
+
"memory:agent",
|
|
75
|
+
{ workflowPattern: { title: "Cross-window continuity handoff" } },
|
|
76
|
+
),
|
|
77
|
+
buildEntry(
|
|
78
|
+
"case-1",
|
|
79
|
+
"cases",
|
|
80
|
+
"Case: Continuity eval checkpoint isolation",
|
|
81
|
+
"recallnest",
|
|
82
|
+
{ caseMemory: { title: "Continuity eval checkpoint isolation" } },
|
|
83
|
+
),
|
|
84
|
+
buildEntry(
|
|
85
|
+
"memory-1",
|
|
86
|
+
"entities",
|
|
87
|
+
"RecallNest is the shared memory layer for Claude Code, Codex, and Gemini CLI.",
|
|
88
|
+
"recallnest",
|
|
89
|
+
{ canonicalKey: "entities:recallnest:shared-memory-layer" },
|
|
90
|
+
),
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
const assessment = assessContinuityBaseline(entries, seeds as any);
|
|
94
|
+
|
|
95
|
+
expect(assessment.found).toEqual({ patterns: 1, cases: 1, memories: 1 });
|
|
96
|
+
expect(assessment.missing).toEqual({ patterns: [], cases: [], memories: [] });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("reports missing canonical seeds by category", () => {
|
|
100
|
+
const seeds = {
|
|
101
|
+
patterns: [
|
|
102
|
+
{
|
|
103
|
+
title: "Recall before repo exploration",
|
|
104
|
+
trigger: "When startup context is sparse",
|
|
105
|
+
steps: ["Run search_memory before local repo exploration."],
|
|
106
|
+
outcome: "Fresh windows recover task-specific continuity.",
|
|
107
|
+
tools: ["resume_context", "search_memory"],
|
|
108
|
+
importance: 0.9,
|
|
109
|
+
source: "agent",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
cases: [
|
|
113
|
+
{
|
|
114
|
+
title: "RecallNest scope fallback cleanup",
|
|
115
|
+
problem: "Project continuity prefers raw transcript notes.",
|
|
116
|
+
solutionSteps: ["Prefer durable cases and patterns."],
|
|
117
|
+
outcome: "Stable project continuity becomes cleaner.",
|
|
118
|
+
tools: ["resume_context"],
|
|
119
|
+
source: "agent",
|
|
120
|
+
scope: "recallnest",
|
|
121
|
+
importance: 0.85,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
memories: [
|
|
125
|
+
{
|
|
126
|
+
text: "RecallNest continuity revolves around three primitives.",
|
|
127
|
+
category: "entities",
|
|
128
|
+
scope: "recallnest",
|
|
129
|
+
source: "agent",
|
|
130
|
+
importance: 0.9,
|
|
131
|
+
canonicalKey: "entities:recallnest:continuity-primitives",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const entries: MemoryEntry[] = [
|
|
137
|
+
buildEntry(
|
|
138
|
+
"pattern-1",
|
|
139
|
+
"patterns",
|
|
140
|
+
"Workflow pattern: Cross-window continuity handoff",
|
|
141
|
+
"memory:agent",
|
|
142
|
+
{ workflowPattern: { title: "Cross-window continuity handoff" } },
|
|
143
|
+
),
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
const assessment = assessContinuityBaseline(entries, seeds as any);
|
|
147
|
+
|
|
148
|
+
expect(assessment.found).toEqual({ patterns: 0, cases: 0, memories: 0 });
|
|
149
|
+
expect(assessment.missing.patterns).toEqual(["Recall before repo exploration"]);
|
|
150
|
+
expect(assessment.missing.cases).toEqual(["RecallNest scope fallback cleanup"]);
|
|
151
|
+
expect(assessment.missing.memories).toEqual(["entities:recallnest:continuity-primitives"]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("loads enough entries for baseline checks when the index is larger than the legacy 5000-entry window", async () => {
|
|
155
|
+
const targetEntry = buildEntry(
|
|
156
|
+
"pattern-target",
|
|
157
|
+
"patterns",
|
|
158
|
+
"Workflow pattern: RecallNest MCP transport rollout",
|
|
159
|
+
"project:recallnest",
|
|
160
|
+
{ workflowPattern: { title: "RecallNest MCP transport rollout" } },
|
|
161
|
+
);
|
|
162
|
+
const entries: MemoryEntry[] = [
|
|
163
|
+
...Array.from({ length: 5000 }, (_, index) => buildEntry(
|
|
164
|
+
`noise-${index}`,
|
|
165
|
+
"patterns",
|
|
166
|
+
`Workflow pattern: Noise ${index}`,
|
|
167
|
+
"memory:agent",
|
|
168
|
+
{ workflowPattern: { title: `Noise ${index}` } },
|
|
169
|
+
)),
|
|
170
|
+
targetEntry,
|
|
171
|
+
];
|
|
172
|
+
const listCalls: Array<[string[] | undefined, string | undefined, number | undefined, number | undefined]> = [];
|
|
173
|
+
const store = {
|
|
174
|
+
async list(scopeFilter?: string[], category?: string, limit = 20, offset = 0): Promise<MemoryEntry[]> {
|
|
175
|
+
listCalls.push([scopeFilter, category, limit, offset]);
|
|
176
|
+
return entries.slice(offset, offset + limit);
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const loaded = await loadContinuityBaselineEntries(store as any, entries.length);
|
|
181
|
+
const assessment = assessContinuityBaseline(loaded, {
|
|
182
|
+
patterns: [
|
|
183
|
+
{
|
|
184
|
+
title: "RecallNest MCP transport rollout",
|
|
185
|
+
trigger: "When RecallNest continuity work touches MCP transport wiring under project scope",
|
|
186
|
+
steps: ["Call resume_context with project:recallnest before transport changes."],
|
|
187
|
+
outcome: "RecallNest transport changes stay project-scoped.",
|
|
188
|
+
tools: ["resume_context", "search_memory", "eval:continuity"],
|
|
189
|
+
source: "agent",
|
|
190
|
+
scope: "project:recallnest",
|
|
191
|
+
importance: 0.87,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
cases: [],
|
|
195
|
+
memories: [],
|
|
196
|
+
} as any);
|
|
197
|
+
|
|
198
|
+
expect(listCalls).toEqual([[undefined, undefined, 5001, 0]]);
|
|
199
|
+
expect(assessment.found.patterns).toBe(1);
|
|
200
|
+
expect(assessment.missing.patterns).toEqual([]);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("assessScopeInventoryReport", () => {
|
|
205
|
+
it("reports a clean scope inventory when no unresolved anomalies remain", () => {
|
|
206
|
+
const result = assessScopeInventoryReport({
|
|
207
|
+
generatedAt: "2026-03-19T08:20:00.000Z",
|
|
208
|
+
sampleLimit: 5,
|
|
209
|
+
totalScannedCount: 42,
|
|
210
|
+
totalAnomalyCount: 0,
|
|
211
|
+
totalInvalidCount: 0,
|
|
212
|
+
totalReviewedCount: 1,
|
|
213
|
+
layers: [
|
|
214
|
+
{
|
|
215
|
+
layer: "memories",
|
|
216
|
+
scannedCount: 40,
|
|
217
|
+
anomalyCount: 0,
|
|
218
|
+
invalidCount: 0,
|
|
219
|
+
reviewedCount: 0,
|
|
220
|
+
counts: { missing: 0, empty: 0, global: 0 },
|
|
221
|
+
samples: [],
|
|
222
|
+
recommendation: "ok",
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
layer: "workflow-observations",
|
|
226
|
+
scannedCount: 2,
|
|
227
|
+
anomalyCount: 0,
|
|
228
|
+
invalidCount: 0,
|
|
229
|
+
reviewedCount: 1,
|
|
230
|
+
counts: { missing: 0, empty: 0, global: 0 },
|
|
231
|
+
samples: [],
|
|
232
|
+
recommendation: "ok",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
expect(result).toEqual({
|
|
238
|
+
name: "Scope inventory",
|
|
239
|
+
status: "pass",
|
|
240
|
+
message: "0 unresolved anomalies across 42 records; reviewed keeps 1",
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("warns when scope inventory still has unresolved anomalies or invalid files", () => {
|
|
245
|
+
const result = assessScopeInventoryReport({
|
|
246
|
+
generatedAt: "2026-03-19T08:20:00.000Z",
|
|
247
|
+
sampleLimit: 5,
|
|
248
|
+
totalScannedCount: 12,
|
|
249
|
+
totalAnomalyCount: 2,
|
|
250
|
+
totalInvalidCount: 1,
|
|
251
|
+
totalReviewedCount: 0,
|
|
252
|
+
layers: [
|
|
253
|
+
{
|
|
254
|
+
layer: "pins",
|
|
255
|
+
scannedCount: 4,
|
|
256
|
+
anomalyCount: 1,
|
|
257
|
+
invalidCount: 0,
|
|
258
|
+
reviewedCount: 0,
|
|
259
|
+
counts: { missing: 0, empty: 0, global: 1 },
|
|
260
|
+
samples: [{
|
|
261
|
+
layer: "pins",
|
|
262
|
+
id: "pin-legacy-1234",
|
|
263
|
+
kind: "global",
|
|
264
|
+
scope: "global",
|
|
265
|
+
context: "pin",
|
|
266
|
+
preview: "Legacy pin",
|
|
267
|
+
recordedAt: "2026-03-19T08:00:00.000Z",
|
|
268
|
+
}],
|
|
269
|
+
recommendation: "re-pin",
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
layer: "workflow-observations",
|
|
273
|
+
scannedCount: 8,
|
|
274
|
+
anomalyCount: 1,
|
|
275
|
+
invalidCount: 1,
|
|
276
|
+
reviewedCount: 0,
|
|
277
|
+
counts: { missing: 1, empty: 0, global: 0 },
|
|
278
|
+
samples: [],
|
|
279
|
+
recommendation: "review",
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(result.status).toBe("warn");
|
|
285
|
+
expect(result.name).toBe("Scope inventory");
|
|
286
|
+
expect(result.message).toContain("2 unresolved anomalies, 1 invalid file(s) across 12 records");
|
|
287
|
+
expect(result.message).toContain("pins:1");
|
|
288
|
+
expect(result.message).toContain("workflow-observations:1 invalid 1");
|
|
289
|
+
expect(result.message).toContain("sample pins:global:pin-lega");
|
|
290
|
+
expect(result.fix).toBe("bun run scope-inventory");
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe("formatDoctorResults", () => {
|
|
295
|
+
it("does not claim all clear when warnings are present", () => {
|
|
296
|
+
const output = formatDoctorResults([
|
|
297
|
+
{ name: "Bun runtime", status: "pass", message: "ok" },
|
|
298
|
+
{ name: "Scope inventory", status: "warn", message: "1 unresolved anomaly", fix: "bun run scope-inventory" },
|
|
299
|
+
]);
|
|
300
|
+
|
|
301
|
+
expect(output).toContain("Review the ⚠️ items above before relying on this environment as a clean baseline.");
|
|
302
|
+
expect(output).not.toContain("All clear.");
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe("describeSecretPresence", () => {
|
|
307
|
+
it("reports only presence and never includes the configured value", () => {
|
|
308
|
+
const secret = "sensitive-value-that-must-not-appear";
|
|
309
|
+
const message = describeSecretPresence(secret, "placeholder");
|
|
310
|
+
|
|
311
|
+
expect(message).toBe("set");
|
|
312
|
+
expect(message).not.toContain(secret);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("does not treat an absent or placeholder value as configured", () => {
|
|
316
|
+
expect(describeSecretPresence(undefined, "placeholder")).toBeNull();
|
|
317
|
+
expect(describeSecretPresence("placeholder", "placeholder")).toBeNull();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, beforeAll, afterAll } from "bun:test";
|
|
2
|
+
import { mkdtempSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { runDream, formatDreamResult, type DreamResult } from "../dream-pipeline.js";
|
|
6
|
+
import type { MemoryEntry, MemoryStore } from "../store.js";
|
|
7
|
+
import type { LLMClient } from "../llm-client.js";
|
|
8
|
+
import type { Embedder } from "../embedder.js";
|
|
9
|
+
import { resetWriteCount } from "../activity-counter.js";
|
|
10
|
+
|
|
11
|
+
// Isolate the activity-counter (default path = <dataDir>/activity-stats.json) to a temp
|
|
12
|
+
// dir so these tests never read/write the repo's data/activity-stats.json that the
|
|
13
|
+
// production dream scheduler uses.
|
|
14
|
+
let __origDataDir: string | undefined;
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
__origDataDir = process.env.RECALLNEST_DATA_DIR;
|
|
17
|
+
process.env.RECALLNEST_DATA_DIR = mkdtempSync(join(tmpdir(), "rn-dp-datadir-"));
|
|
18
|
+
});
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
if (__origDataDir === undefined) delete process.env.RECALLNEST_DATA_DIR;
|
|
21
|
+
else process.env.RECALLNEST_DATA_DIR = __origDataDir;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Helpers
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
function makeEntry(overrides: Partial<MemoryEntry> & { id: string }): MemoryEntry {
|
|
29
|
+
return {
|
|
30
|
+
text: "test memory",
|
|
31
|
+
vector: [1, 0, 0, 0, 0],
|
|
32
|
+
category: "events",
|
|
33
|
+
scope: "project:test",
|
|
34
|
+
importance: 0.5,
|
|
35
|
+
timestamp: Date.now(),
|
|
36
|
+
metadata: JSON.stringify({
|
|
37
|
+
evolution: {
|
|
38
|
+
status: "active",
|
|
39
|
+
version: 1,
|
|
40
|
+
accessCount: 0,
|
|
41
|
+
lastAccessedAt: null,
|
|
42
|
+
supersededBy: null,
|
|
43
|
+
consolidatedInto: null,
|
|
44
|
+
contributedToPattern: null,
|
|
45
|
+
sourceMemories: [],
|
|
46
|
+
validFrom: Date.now(),
|
|
47
|
+
validUntil: null,
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
...overrides,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function createMockStore(entries: MemoryEntry[]): MemoryStore {
|
|
55
|
+
const stored: MemoryEntry[] = [...entries];
|
|
56
|
+
let storeCounter = 0;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
async list() { return stored; },
|
|
60
|
+
async stats() {
|
|
61
|
+
return {
|
|
62
|
+
totalCount: stored.length,
|
|
63
|
+
scopeCounts: {},
|
|
64
|
+
categoryCounts: {},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
async store(entry: Partial<MemoryEntry>) {
|
|
68
|
+
const full = {
|
|
69
|
+
id: entry.id || `dream-${storeCounter++}`,
|
|
70
|
+
text: entry.text || "",
|
|
71
|
+
vector: entry.vector || [],
|
|
72
|
+
category: entry.category || "events",
|
|
73
|
+
scope: entry.scope || "project:test",
|
|
74
|
+
importance: entry.importance || 0.5,
|
|
75
|
+
timestamp: Date.now(),
|
|
76
|
+
metadata: entry.metadata || "{}",
|
|
77
|
+
} as MemoryEntry;
|
|
78
|
+
stored.push(full);
|
|
79
|
+
return full;
|
|
80
|
+
},
|
|
81
|
+
async update(id: string, upd: Partial<MemoryEntry>) {
|
|
82
|
+
const entry = stored.find(e => e.id === id);
|
|
83
|
+
if (entry && upd.metadata) entry.metadata = upd.metadata;
|
|
84
|
+
return entry || { id, text: "", vector: [], category: "events", scope: "project:test", importance: 0.5, timestamp: Date.now(), metadata: "{}" } as MemoryEntry;
|
|
85
|
+
},
|
|
86
|
+
async getById(id: string) {
|
|
87
|
+
return stored.find(e => e.id === id) || null;
|
|
88
|
+
},
|
|
89
|
+
// 模拟 store.patchMetadata 单写通道:读最新 metadata → patchFn → 写回。
|
|
90
|
+
async patchMetadata(
|
|
91
|
+
id: string,
|
|
92
|
+
patchFn: (meta: Record<string, unknown>, entry: MemoryEntry) => Record<string, unknown>,
|
|
93
|
+
_scopeFilter?: string[],
|
|
94
|
+
) {
|
|
95
|
+
const entry = stored.find(e => e.id === id);
|
|
96
|
+
if (!entry) return null;
|
|
97
|
+
let meta: Record<string, unknown>;
|
|
98
|
+
try {
|
|
99
|
+
const parsed: unknown = JSON.parse(entry.metadata || "{}");
|
|
100
|
+
meta = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
|
|
101
|
+
? (parsed as Record<string, unknown>)
|
|
102
|
+
: {};
|
|
103
|
+
} catch {
|
|
104
|
+
meta = {};
|
|
105
|
+
}
|
|
106
|
+
entry.metadata = JSON.stringify(patchFn(meta, entry));
|
|
107
|
+
return entry;
|
|
108
|
+
},
|
|
109
|
+
async vectorSearch(_vec: number[], limit: number, _threshold: number, _scopes?: string[]) {
|
|
110
|
+
return stored.slice(0, limit).map(e => ({ entry: e, score: 0.85 }));
|
|
111
|
+
},
|
|
112
|
+
} as unknown as MemoryStore;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function createMockLLM(): LLMClient {
|
|
116
|
+
return {
|
|
117
|
+
async generateL0() { return "consolidated insight"; },
|
|
118
|
+
async extractPattern() { return "discovered pattern"; },
|
|
119
|
+
} as unknown as LLMClient;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function createMockEmbedder(): Pick<Embedder, "embedPassage"> {
|
|
123
|
+
return {
|
|
124
|
+
async embedPassage() { return [0.5, 0.5, 0, 0, 0]; },
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Tests
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
describe("runDream", () => {
|
|
133
|
+
beforeEach(() => {
|
|
134
|
+
// Reset the activity counter for the test scope between tests (per-scope API).
|
|
135
|
+
resetWriteCount("project:test");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("skips when write count is below threshold", async () => {
|
|
139
|
+
const store = createMockStore([makeEntry({ id: "a" })]);
|
|
140
|
+
const result = await runDream({
|
|
141
|
+
store,
|
|
142
|
+
llm: createMockLLM(),
|
|
143
|
+
embedder: createMockEmbedder(),
|
|
144
|
+
scope: "project:test",
|
|
145
|
+
config: { minWritesForDream: 10 },
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(result.ran).toBe(false);
|
|
149
|
+
expect(result.reason).toContain("insufficient_writes");
|
|
150
|
+
expect(result.phases.length).toBe(1);
|
|
151
|
+
expect(result.phases[0].phase).toBe("orient");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("persists usageStatus snapshots during gather (P0 B-1, flag on)", async () => {
|
|
155
|
+
process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL = "true";
|
|
156
|
+
try {
|
|
157
|
+
const coldMeta = JSON.stringify({
|
|
158
|
+
accessCount: 8, // injection >= 6, useCount 0 -> cold
|
|
159
|
+
evolution: { status: "active", version: 1 },
|
|
160
|
+
});
|
|
161
|
+
const entries = [
|
|
162
|
+
makeEntry({ id: "cold-1", metadata: coldMeta }),
|
|
163
|
+
makeEntry({ id: "fresh-1" }), // unused 默认态:不写快照,防全库写放大
|
|
164
|
+
];
|
|
165
|
+
const store = createMockStore(entries);
|
|
166
|
+
|
|
167
|
+
const result = await runDream({
|
|
168
|
+
store,
|
|
169
|
+
llm: createMockLLM(),
|
|
170
|
+
embedder: createMockEmbedder(),
|
|
171
|
+
scope: "project:test",
|
|
172
|
+
force: true,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(result.ran).toBe(true);
|
|
176
|
+
const cold = await store.getById("cold-1");
|
|
177
|
+
expect(JSON.parse(cold!.metadata!).usage.usageStatus).toBe("cold");
|
|
178
|
+
const fresh = await store.getById("fresh-1");
|
|
179
|
+
expect(JSON.parse(fresh!.metadata!).usage).toBeUndefined();
|
|
180
|
+
const gather = result.phases.find(p => p.phase === "gather");
|
|
181
|
+
expect(gather!.detail).toContain("usage snapshot: 1");
|
|
182
|
+
} finally {
|
|
183
|
+
delete process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("skips usageStatus snapshots when use signal is inactive (flag off)", async () => {
|
|
188
|
+
delete process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL;
|
|
189
|
+
const coldMeta = JSON.stringify({
|
|
190
|
+
accessCount: 8,
|
|
191
|
+
evolution: { status: "active", version: 1 },
|
|
192
|
+
});
|
|
193
|
+
const store = createMockStore([makeEntry({ id: "cold-1", metadata: coldMeta })]);
|
|
194
|
+
const result = await runDream({
|
|
195
|
+
store,
|
|
196
|
+
llm: createMockLLM(),
|
|
197
|
+
embedder: createMockEmbedder(),
|
|
198
|
+
scope: "project:test",
|
|
199
|
+
force: true,
|
|
200
|
+
});
|
|
201
|
+
expect(result.ran).toBe(true);
|
|
202
|
+
const cold = await store.getById("cold-1");
|
|
203
|
+
expect(JSON.parse(cold!.metadata!).usage).toBeUndefined();
|
|
204
|
+
const gather = result.phases.find(p => p.phase === "gather");
|
|
205
|
+
expect(gather!.detail).not.toContain("usage snapshot");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("runs when forced despite low write count", async () => {
|
|
209
|
+
const entries = [
|
|
210
|
+
makeEntry({ id: "a", vector: [0.9, 0.1, 0, 0, 0] }),
|
|
211
|
+
makeEntry({ id: "b", vector: [0.88, 0.12, 0, 0, 0] }),
|
|
212
|
+
makeEntry({ id: "c", vector: [0.92, 0.08, 0, 0, 0] }),
|
|
213
|
+
];
|
|
214
|
+
const store = createMockStore(entries);
|
|
215
|
+
const result = await runDream({
|
|
216
|
+
store,
|
|
217
|
+
llm: createMockLLM(),
|
|
218
|
+
embedder: createMockEmbedder(),
|
|
219
|
+
scope: "project:test",
|
|
220
|
+
force: true,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
expect(result.ran).toBe(true);
|
|
224
|
+
expect(result.phases.length).toBe(4);
|
|
225
|
+
expect(result.phases.map(p => p.phase)).toEqual(["orient", "gather", "consolidate", "prune"]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("completes early with too few active entries", async () => {
|
|
229
|
+
const store = createMockStore([
|
|
230
|
+
makeEntry({ id: "a" }),
|
|
231
|
+
]);
|
|
232
|
+
const result = await runDream({
|
|
233
|
+
store,
|
|
234
|
+
llm: createMockLLM(),
|
|
235
|
+
embedder: createMockEmbedder(),
|
|
236
|
+
scope: "project:test",
|
|
237
|
+
force: true,
|
|
238
|
+
config: { minClusterSize: 3 },
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(result.ran).toBe(true);
|
|
242
|
+
expect(result.reason).toBe("completed_early");
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("works without LLM (null) — only deterministic consolidation", async () => {
|
|
246
|
+
const entries = [
|
|
247
|
+
makeEntry({ id: "a", vector: [0.9, 0.1, 0, 0, 0] }),
|
|
248
|
+
makeEntry({ id: "b", vector: [0.88, 0.12, 0, 0, 0] }),
|
|
249
|
+
makeEntry({ id: "c", vector: [0.92, 0.08, 0, 0, 0] }),
|
|
250
|
+
];
|
|
251
|
+
const store = createMockStore(entries);
|
|
252
|
+
const result = await runDream({
|
|
253
|
+
store,
|
|
254
|
+
llm: null,
|
|
255
|
+
embedder: createMockEmbedder(),
|
|
256
|
+
scope: "project:test",
|
|
257
|
+
force: true,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
expect(result.ran).toBe(true);
|
|
261
|
+
expect(result.stats.insightsGenerated).toBe(0); // No LLM = no insights
|
|
262
|
+
expect(result.stats.patternsExtracted).toBe(0);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("reports correct stats structure", async () => {
|
|
266
|
+
const entries = [
|
|
267
|
+
makeEntry({ id: "a", vector: [0.9, 0.1, 0, 0, 0] }),
|
|
268
|
+
makeEntry({ id: "b", vector: [0.88, 0.12, 0, 0, 0] }),
|
|
269
|
+
makeEntry({ id: "c", vector: [0.92, 0.08, 0, 0, 0] }),
|
|
270
|
+
];
|
|
271
|
+
const store = createMockStore(entries);
|
|
272
|
+
const result = await runDream({
|
|
273
|
+
store,
|
|
274
|
+
llm: createMockLLM(),
|
|
275
|
+
embedder: createMockEmbedder(),
|
|
276
|
+
scope: "project:test",
|
|
277
|
+
force: true,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
expect(result.stats.totalMemories).toBeGreaterThanOrEqual(0);
|
|
281
|
+
expect(result.stats.activeMemories).toBeGreaterThanOrEqual(0);
|
|
282
|
+
expect(typeof result.stats.clustersFound).toBe("number");
|
|
283
|
+
expect(typeof result.stats.insightsGenerated).toBe("number");
|
|
284
|
+
expect(typeof result.stats.patternsExtracted).toBe("number");
|
|
285
|
+
expect(typeof result.stats.mergedCount).toBe("number");
|
|
286
|
+
expect(typeof result.stats.archivedCount).toBe("number");
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("formatDreamResult", () => {
|
|
291
|
+
it("formats skipped dream", () => {
|
|
292
|
+
const result: DreamResult = {
|
|
293
|
+
ran: false,
|
|
294
|
+
reason: "insufficient_writes (3/10)",
|
|
295
|
+
phases: [{ phase: "orient", detail: "50 memories, 3 writes" }],
|
|
296
|
+
stats: { totalMemories: 50, activeMemories: 0, writesSinceLastDream: 3, clustersFound: 0, insightsGenerated: 0, patternsExtracted: 0, mergedCount: 0, archivedCount: 0 },
|
|
297
|
+
};
|
|
298
|
+
const output = formatDreamResult(result);
|
|
299
|
+
expect(output).toContain("skipped");
|
|
300
|
+
expect(output).toContain("insufficient_writes");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("formats completed dream with all phases", () => {
|
|
304
|
+
const result: DreamResult = {
|
|
305
|
+
ran: true,
|
|
306
|
+
phases: [
|
|
307
|
+
{ phase: "orient", detail: "100 memories, 15 writes" },
|
|
308
|
+
{ phase: "gather", detail: "80 active entries" },
|
|
309
|
+
{ phase: "consolidate", detail: "3 clusters, 1 merged, 2 insights, 1 pattern" },
|
|
310
|
+
{ phase: "prune", detail: "5 entries archived" },
|
|
311
|
+
],
|
|
312
|
+
stats: { totalMemories: 100, activeMemories: 80, writesSinceLastDream: 15, clustersFound: 3, insightsGenerated: 2, patternsExtracted: 1, mergedCount: 1, archivedCount: 5 },
|
|
313
|
+
};
|
|
314
|
+
const output = formatDreamResult(result);
|
|
315
|
+
expect(output).toContain("Dream completed");
|
|
316
|
+
expect(output).toContain("[orient]");
|
|
317
|
+
expect(output).toContain("[consolidate]");
|
|
318
|
+
expect(output).toContain("[prune]");
|
|
319
|
+
expect(output).toContain("Patterns: 1");
|
|
320
|
+
});
|
|
321
|
+
});
|