recallnest 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +101 -0
- package/README.md +222 -254
- package/README_CN.md +206 -243
- package/package.json +3 -2
- package/src/capture-engine.ts +26 -4
- package/src/context-composer-stable.ts +5 -1
- package/src/embedder.ts +24 -0
- package/src/env-config.ts +18 -0
- package/src/ingest.ts +225 -17
- package/src/kg-extractor.ts +17 -0
- package/src/memory-output.ts +35 -0
- package/src/pivot-apply.ts +52 -1
- package/src/pivot-evidence.ts +128 -0
- package/src/ppr-traversal.ts +25 -1
- package/src/runtime-config.ts +9 -0
- package/src/session-engine.ts +11 -4
- package/src/session-output.ts +9 -1
- package/src/session-store.ts +2 -3
- package/src/skill-promotion.ts +67 -1
- package/src/__tests__/access-tracker-novelty.test.ts +0 -324
- package/src/__tests__/activity-counter.test.ts +0 -125
- package/src/__tests__/adaptive-fidelity.test.ts +0 -102
- package/src/__tests__/admission-control.test.ts +0 -206
- package/src/__tests__/age-label.test.ts +0 -33
- package/src/__tests__/anchor-generator.test.ts +0 -67
- package/src/__tests__/api-server-security.test.ts +0 -102
- package/src/__tests__/auto-consolidation.test.ts +0 -168
- package/src/__tests__/auto-recall.test.ts +0 -131
- package/src/__tests__/babel-integration.test.ts +0 -144
- package/src/__tests__/batch-dedup.test.ts +0 -65
- package/src/__tests__/belief-history.test.ts +0 -220
- package/src/__tests__/canary-eval.test.ts +0 -114
- package/src/__tests__/capture-engine.test.ts +0 -1328
- package/src/__tests__/capture-heuristic.test.ts +0 -171
- package/src/__tests__/cascade-forget.test.ts +0 -210
- package/src/__tests__/category-min-scores.test.ts +0 -116
- package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
- package/src/__tests__/circuit-breaker.test.ts +0 -99
- package/src/__tests__/cluster-consolidation.test.ts +0 -1236
- package/src/__tests__/confidence-metadata.test.ts +0 -125
- package/src/__tests__/confidence-tracker.test.ts +0 -261
- package/src/__tests__/conflict-advisor.test.ts +0 -206
- package/src/__tests__/conflict-escalation.test.ts +0 -149
- package/src/__tests__/conflict-lifecycle.test.ts +0 -83
- package/src/__tests__/conflict-output.test.ts +0 -85
- package/src/__tests__/conflict-store.test.ts +0 -418
- package/src/__tests__/connector-v1.test.ts +0 -181
- package/src/__tests__/consolidation-engine.test.ts +0 -520
- package/src/__tests__/constructive-retrieval.test.ts +0 -509
- package/src/__tests__/context-collapse-renderer.test.ts +0 -214
- package/src/__tests__/context-composer-pins.test.ts +0 -64
- package/src/__tests__/context-composer-task-selection.test.ts +0 -24
- package/src/__tests__/context-reconstructor.test.ts +0 -65
- package/src/__tests__/context-renderer.test.ts +0 -91
- package/src/__tests__/continuity-eval.test.ts +0 -275
- package/src/__tests__/continuity-schema.test.ts +0 -97
- package/src/__tests__/contracts.test.ts +0 -262
- package/src/__tests__/conversation-importer.test.ts +0 -692
- package/src/__tests__/core-recall-eval.test.ts +0 -235
- package/src/__tests__/core-summary.test.ts +0 -109
- package/src/__tests__/data-checkup.test.ts +0 -304
- package/src/__tests__/decay-exemption.test.ts +0 -129
- package/src/__tests__/dedup-actions.test.ts +0 -58
- package/src/__tests__/dedup-guard.test.ts +0 -39
- package/src/__tests__/deterministic-id.test.ts +0 -39
- package/src/__tests__/distill-lock.test.ts +0 -305
- package/src/__tests__/distill-session-argshape.test.ts +0 -79
- package/src/__tests__/doctor.test.ts +0 -319
- package/src/__tests__/dream-pipeline.test.ts +0 -820
- package/src/__tests__/dream-scope-isolation.test.ts +0 -386
- package/src/__tests__/dream-write-batching.test.ts +0 -211
- package/src/__tests__/drill-down.test.ts +0 -108
- package/src/__tests__/embedder.test.ts +0 -122
- package/src/__tests__/emotion-decay.test.ts +0 -46
- package/src/__tests__/emotion-detector.test.ts +0 -56
- package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
- package/src/__tests__/emotion-retrieval.test.ts +0 -56
- package/src/__tests__/entity-resolver.test.ts +0 -58
- package/src/__tests__/env-config-invariant.test.ts +0 -80
- package/src/__tests__/env-config.test.ts +0 -211
- package/src/__tests__/error-signature-boost.test.ts +0 -87
- package/src/__tests__/error-signature.test.ts +0 -95
- package/src/__tests__/error-taxonomy.test.ts +0 -129
- package/src/__tests__/ethics-layer.test.ts +0 -476
- package/src/__tests__/event-segmenter.test.ts +0 -153
- package/src/__tests__/feature-flags-integration.test.ts +0 -54
- package/src/__tests__/frequency-tracker.test.ts +0 -113
- package/src/__tests__/freshness.test.ts +0 -186
- package/src/__tests__/graph-export.test.ts +0 -489
- package/src/__tests__/hotness-blend.test.ts +0 -283
- package/src/__tests__/ingest-chunking.test.ts +0 -44
- package/src/__tests__/ingest-scope-prefix.test.ts +0 -69
- package/src/__tests__/ingest.test.ts +0 -360
- package/src/__tests__/interference-detector.test.ts +0 -203
- package/src/__tests__/kg-extractor.test.ts +0 -192
- package/src/__tests__/kg-store.test.ts +0 -300
- package/src/__tests__/llm-client-pivot.test.ts +0 -628
- package/src/__tests__/llm-consolidation.test.ts +0 -226
- package/src/__tests__/maintenance-locks.test.ts +0 -197
- package/src/__tests__/mcp-efficiency.test.ts +0 -288
- package/src/__tests__/mcp-related-scopes.test.ts +0 -151
- package/src/__tests__/memory-boundaries.test.ts +0 -282
- package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -362
- package/src/__tests__/memory-evolution.test.ts +0 -271
- package/src/__tests__/memory-health-rebalance.test.ts +0 -144
- package/src/__tests__/memory-lint.test.ts +0 -421
- package/src/__tests__/memory-output.test.ts +0 -224
- package/src/__tests__/memory-promotion.test.ts +0 -315
- package/src/__tests__/memory-utility.test.ts +0 -256
- package/src/__tests__/migrate-dedup-ids.test.ts +0 -65
- package/src/__tests__/multi-vector.test.ts +0 -242
- package/src/__tests__/narrative-architecture.test.ts +0 -456
- package/src/__tests__/noise-filter.test.ts +0 -205
- package/src/__tests__/noise-prototype-bank.test.ts +0 -280
- package/src/__tests__/obsidian-connector.test.ts +0 -363
- package/src/__tests__/omitted-reporting.test.ts +0 -98
- package/src/__tests__/openai-contract.test.ts +0 -513
- package/src/__tests__/pending-review.test.ts +0 -77
- package/src/__tests__/pii-redact.test.ts +0 -333
- package/src/__tests__/pivot-apply.test.ts +0 -373
- package/src/__tests__/pivot-distill-supervisor.test.ts +0 -457
- package/src/__tests__/pivot-distill.test.ts +0 -1178
- package/src/__tests__/post-retrieval-filter.test.ts +0 -178
- package/src/__tests__/ppr-traversal.test.ts +0 -256
- package/src/__tests__/prediction-engine.test.ts +0 -349
- package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
- package/src/__tests__/preference-guard-smoke.test.ts +0 -211
- package/src/__tests__/preference-matcher.test.ts +0 -282
- package/src/__tests__/preference-slots.test.ts +0 -205
- package/src/__tests__/promotion-distinct-sources.test.ts +0 -162
- package/src/__tests__/prospective-memory.test.ts +0 -283
- package/src/__tests__/pull-from-macbook-sync-only.test.ts +0 -679
- package/src/__tests__/query-entity-detector.test.ts +0 -171
- package/src/__tests__/query-expander-alias.test.ts +0 -146
- package/src/__tests__/query-expander.test.ts +0 -34
- package/src/__tests__/recall-gate.test.ts +0 -266
- package/src/__tests__/recall-governor.test.ts +0 -227
- package/src/__tests__/recall-mode.test.ts +0 -64
- package/src/__tests__/resolve-db-path.test.ts +0 -130
- package/src/__tests__/resolve-tier.test.ts +0 -64
- package/src/__tests__/result-synthesizer.test.ts +0 -198
- package/src/__tests__/resume-context.test.ts +0 -4898
- package/src/__tests__/retrieval-eval.test.ts +0 -163
- package/src/__tests__/retrieval-trace.test.ts +0 -213
- package/src/__tests__/retrieve-audit-revision.test.ts +0 -255
- package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
- package/src/__tests__/retriever-lazy-init-dispatch.test.ts +0 -123
- package/src/__tests__/retroactive-boost.test.ts +0 -223
- package/src/__tests__/salience-scoring.test.ts +0 -106
- package/src/__tests__/scope-inventory.test.ts +0 -200
- package/src/__tests__/scope-policy.test.ts +0 -69
- package/src/__tests__/scope-suggester.test.ts +0 -80
- package/src/__tests__/session-checkpoint.test.ts +0 -291
- package/src/__tests__/session-distiller.test.ts +0 -640
- package/src/__tests__/session-gc.test.ts +0 -215
- package/src/__tests__/skill-engine.test.ts +0 -552
- package/src/__tests__/skill-promotion.test.ts +0 -654
- package/src/__tests__/skill-verifier.test.ts +0 -122
- package/src/__tests__/source-heartbeat.test.ts +0 -254
- package/src/__tests__/stable-context-length-contract.test.ts +0 -62
- package/src/__tests__/store-patch-metadata.test.ts +0 -235
- package/src/__tests__/store-read-consistency.test.ts +0 -122
- package/src/__tests__/store-schema-migration.test.ts +0 -87
- package/src/__tests__/store-scope-audit.test.ts +0 -81
- package/src/__tests__/store-upsert.test.ts +0 -201
- package/src/__tests__/supersede-chain.test.ts +0 -154
- package/src/__tests__/synthesis-contract.test.ts +0 -252
- package/src/__tests__/synthesis-promotion.test.ts +0 -369
- package/src/__tests__/temporal-parser.test.ts +0 -241
- package/src/__tests__/temporal-validity.test.ts +0 -160
- package/src/__tests__/term-registry-terminal-roster.test.ts +0 -127
- package/src/__tests__/term-registry.test.ts +0 -121
- package/src/__tests__/tool-error-surfacing.test.ts +0 -98
- package/src/__tests__/tool-output-compressor.test.ts +0 -160
- package/src/__tests__/topic-tag.test.ts +0 -113
- package/src/__tests__/trusted-memory.test.ts +0 -867
- package/src/__tests__/ui-server-security.test.ts +0 -93
- package/src/__tests__/usage-tracker.test.ts +0 -287
- package/src/__tests__/utility-weight.test.ts +0 -57
- package/src/__tests__/verbatim-self-recall.test.ts +0 -279
- package/src/__tests__/version-manager.test.ts +0 -248
- package/src/__tests__/workflow-observation-skill-outcome.test.ts +0 -352
- package/src/__tests__/workflow-observation.test.ts +0 -433
- package/src/__tests__/write-verifier.test.ts +0 -122
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import type { RetrievalResult } from "../retriever.js";
|
|
4
|
-
import { formatBriefResults, formatFullResults } from "../memory-output.js";
|
|
5
|
-
import { persistMemoryBatch } from "../capture-engine.js";
|
|
6
|
-
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// Helpers
|
|
9
|
-
// ============================================================================
|
|
10
|
-
|
|
11
|
-
function makeResult(overrides: {
|
|
12
|
-
id?: string;
|
|
13
|
-
text?: string;
|
|
14
|
-
score?: number;
|
|
15
|
-
metadata?: string;
|
|
16
|
-
category?: string;
|
|
17
|
-
importance?: number;
|
|
18
|
-
timestamp?: number;
|
|
19
|
-
} = {}): RetrievalResult {
|
|
20
|
-
return {
|
|
21
|
-
entry: {
|
|
22
|
-
id: overrides.id ?? "abcdef12-3456-7890-abcd-ef1234567890",
|
|
23
|
-
text: overrides.text ?? "Default memory text for testing purposes",
|
|
24
|
-
vector: [0.1, 0.2, 0.3],
|
|
25
|
-
category: overrides.category ?? "events",
|
|
26
|
-
scope: "project:test",
|
|
27
|
-
importance: overrides.importance ?? 0.7,
|
|
28
|
-
timestamp: overrides.timestamp ?? 1_700_000_000_000,
|
|
29
|
-
metadata: overrides.metadata,
|
|
30
|
-
},
|
|
31
|
-
score: overrides.score ?? 0.85,
|
|
32
|
-
sources: {
|
|
33
|
-
vector: { score: 0.8, rank: 1 },
|
|
34
|
-
fused: { score: overrides.score ?? 0.85 },
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function createDeps() {
|
|
40
|
-
const storedEntries: Record<string, unknown>[] = [];
|
|
41
|
-
const conflicts: Record<string, unknown>[] = [];
|
|
42
|
-
let seq = 1;
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
storedEntries,
|
|
46
|
-
conflicts,
|
|
47
|
-
deps: {
|
|
48
|
-
embedder: {
|
|
49
|
-
async embedPassage(_text: string) {
|
|
50
|
-
return [1, 0, 0];
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
store: {
|
|
54
|
-
async store(entry: Record<string, unknown>) {
|
|
55
|
-
const stored = {
|
|
56
|
-
...entry,
|
|
57
|
-
id: `00000000-0000-0000-0000-${String(seq).padStart(12, "0")}`,
|
|
58
|
-
timestamp: 1_700_000_000_000 + seq,
|
|
59
|
-
};
|
|
60
|
-
seq += 1;
|
|
61
|
-
storedEntries.push(stored);
|
|
62
|
-
return stored;
|
|
63
|
-
},
|
|
64
|
-
async search(_params: Record<string, unknown>) {
|
|
65
|
-
return [];
|
|
66
|
-
},
|
|
67
|
-
async getByScope(_scope: string) {
|
|
68
|
-
return [];
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
conflictStore: {
|
|
72
|
-
async save(record: Record<string, unknown>) {
|
|
73
|
-
conflicts.push(record);
|
|
74
|
-
return record;
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
kgExtractor: null,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// ============================================================================
|
|
83
|
-
// MCP-1: list_tools
|
|
84
|
-
// ============================================================================
|
|
85
|
-
|
|
86
|
-
describe("MCP-1: list_tools tier discovery", () => {
|
|
87
|
-
// We test the tier filtering logic directly since we can't easily instantiate the MCP server.
|
|
88
|
-
// The TOOL_TIERS map and tier logic is exercised here.
|
|
89
|
-
|
|
90
|
-
const TOOL_TIERS: Record<string, string> = {
|
|
91
|
-
resume_context: "core",
|
|
92
|
-
search_memory: "core",
|
|
93
|
-
store_memory: "core",
|
|
94
|
-
checkpoint_session: "core",
|
|
95
|
-
latest_checkpoint: "core",
|
|
96
|
-
list_tools: "core",
|
|
97
|
-
set_reminder: "core",
|
|
98
|
-
batch_store: "advanced",
|
|
99
|
-
auto_capture: "advanced",
|
|
100
|
-
store_case: "advanced",
|
|
101
|
-
store_workflow_pattern: "advanced",
|
|
102
|
-
promote_memory: "advanced",
|
|
103
|
-
explain_memory: "advanced",
|
|
104
|
-
distill_memory: "advanced",
|
|
105
|
-
brief_memory: "advanced",
|
|
106
|
-
pin_memory: "advanced",
|
|
107
|
-
list_assets: "advanced",
|
|
108
|
-
list_pins: "advanced",
|
|
109
|
-
memory_stats: "advanced",
|
|
110
|
-
memory_drill_down: "advanced",
|
|
111
|
-
export_memory: "advanced",
|
|
112
|
-
store_skill: "advanced",
|
|
113
|
-
retrieve_skill: "advanced",
|
|
114
|
-
scan_skill_promotions: "governance",
|
|
115
|
-
workflow_observe: "governance",
|
|
116
|
-
workflow_health: "governance",
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
function listToolsForTier(requestedTier: "core" | "advanced" | "full"): string[] {
|
|
120
|
-
const tierOrder: Record<string, number> = { core: 0, advanced: 1, governance: 2 };
|
|
121
|
-
const maxOrder = requestedTier === "full" ? 2 : tierOrder[requestedTier] ?? 1;
|
|
122
|
-
return Object.entries(TOOL_TIERS)
|
|
123
|
-
.filter(([, toolTier]) => (tierOrder[toolTier] ?? 999) <= maxOrder)
|
|
124
|
-
.map(([name]) => name);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
it("returns only core tier tools when tier=core", () => {
|
|
128
|
-
const tools = listToolsForTier("core");
|
|
129
|
-
expect(tools).toContain("resume_context");
|
|
130
|
-
expect(tools).toContain("search_memory");
|
|
131
|
-
expect(tools).toContain("list_tools");
|
|
132
|
-
expect(tools).not.toContain("auto_capture");
|
|
133
|
-
expect(tools).not.toContain("workflow_observe");
|
|
134
|
-
// Core should have exactly our known core tools
|
|
135
|
-
for (const t of tools) {
|
|
136
|
-
expect(TOOL_TIERS[t]).toBe("core");
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("returns core + advanced tools when tier=advanced", () => {
|
|
141
|
-
const tools = listToolsForTier("advanced");
|
|
142
|
-
// Should include core
|
|
143
|
-
expect(tools).toContain("resume_context");
|
|
144
|
-
expect(tools).toContain("search_memory");
|
|
145
|
-
expect(tools).toContain("list_tools");
|
|
146
|
-
// Should include advanced
|
|
147
|
-
expect(tools).toContain("auto_capture");
|
|
148
|
-
expect(tools).toContain("batch_store");
|
|
149
|
-
expect(tools).toContain("explain_memory");
|
|
150
|
-
// Should NOT include governance
|
|
151
|
-
expect(tools).not.toContain("workflow_observe");
|
|
152
|
-
expect(tools).not.toContain("scan_skill_promotions");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("returns all tools when tier=full", () => {
|
|
156
|
-
const tools = listToolsForTier("full");
|
|
157
|
-
expect(tools).toContain("resume_context");
|
|
158
|
-
expect(tools).toContain("auto_capture");
|
|
159
|
-
expect(tools).toContain("workflow_observe");
|
|
160
|
-
expect(tools).toContain("scan_skill_promotions");
|
|
161
|
-
expect(tools.length).toBe(Object.keys(TOOL_TIERS).length);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// ============================================================================
|
|
166
|
-
// MCP-2: formatBriefResults and formatFullResults
|
|
167
|
-
// ============================================================================
|
|
168
|
-
|
|
169
|
-
describe("MCP-2: formatBriefResults", () => {
|
|
170
|
-
it("returns no results message for empty array", () => {
|
|
171
|
-
const result = formatBriefResults([], { query: "test" });
|
|
172
|
-
expect(result).toBe("No results found.");
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("renders correct brief format", () => {
|
|
176
|
-
const results = [
|
|
177
|
-
makeResult({ id: "aabbccdd-1111-2222-3333-444455556666", score: 0.92, text: "User prefers TypeScript for all projects" }),
|
|
178
|
-
makeResult({ id: "11223344-aaaa-bbbb-cccc-ddddeeeeffff", score: 0.78, text: "Project RecallNest uses LanceDB" }),
|
|
179
|
-
];
|
|
180
|
-
const output = formatBriefResults(results, { query: "typescript" });
|
|
181
|
-
expect(output).toContain("Query: typescript");
|
|
182
|
-
expect(output).toContain("Hits: 2");
|
|
183
|
-
expect(output).toContain("#1 aabbccdd 92.0%");
|
|
184
|
-
expect(output).toContain("#2 11223344 78.0%");
|
|
185
|
-
expect(output).toContain("User prefers TypeScript");
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("uses l0_abstract from metadata when available", () => {
|
|
189
|
-
const meta = JSON.stringify({ l0_abstract: "Short L0 summary for this memory" });
|
|
190
|
-
const results = [
|
|
191
|
-
makeResult({ metadata: meta, text: "Very long original text that should not appear in brief mode because the l0_abstract is available" }),
|
|
192
|
-
];
|
|
193
|
-
const output = formatBriefResults(results, { query: "test" });
|
|
194
|
-
expect(output).toContain("Short L0 summary");
|
|
195
|
-
expect(output).not.toContain("Very long original text");
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("each brief result line is at most 120 characters", () => {
|
|
199
|
-
const results = [
|
|
200
|
-
makeResult({ text: "A".repeat(200) }),
|
|
201
|
-
makeResult({ id: "zzzzzzzz-0000-0000-0000-000000000000", text: "Short text" }),
|
|
202
|
-
];
|
|
203
|
-
const output = formatBriefResults(results, { query: "q" });
|
|
204
|
-
const lines = output.split("\n");
|
|
205
|
-
// Only check result lines (starting with #)
|
|
206
|
-
for (const line of lines) {
|
|
207
|
-
if (line.startsWith("#")) {
|
|
208
|
-
expect(line.length).toBeLessThanOrEqual(120);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe("MCP-2: formatFullResults", () => {
|
|
215
|
-
it("includes metadata details in full mode", () => {
|
|
216
|
-
const meta = JSON.stringify({ evolutionStatus: "stable", accessCount: 5, tags: ["ts", "dev"] });
|
|
217
|
-
const results = [
|
|
218
|
-
makeResult({ metadata: meta, importance: 0.85 }),
|
|
219
|
-
];
|
|
220
|
-
const output = formatFullResults(results, { query: "test", profile: "default" });
|
|
221
|
-
expect(output).toContain("meta :");
|
|
222
|
-
expect(output).toContain("evolution=stable");
|
|
223
|
-
expect(output).toContain("accessCount=5");
|
|
224
|
-
expect(output).toContain("importance=0.85");
|
|
225
|
-
expect(output).toContain("tags=[ts, dev]");
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("shows dash for missing metadata fields", () => {
|
|
229
|
-
const results = [makeResult({})];
|
|
230
|
-
const output = formatFullResults(results, { query: "q", profile: "default" });
|
|
231
|
-
expect(output).toContain("evolution=-");
|
|
232
|
-
expect(output).toContain("accessCount=-");
|
|
233
|
-
expect(output).toContain("tags=[-]");
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
// ============================================================================
|
|
238
|
-
// MCP-3: batch_store via persistMemoryBatch
|
|
239
|
-
// ============================================================================
|
|
240
|
-
|
|
241
|
-
describe("MCP-3: batch_store", () => {
|
|
242
|
-
it("stores multiple memories and returns all records", async () => {
|
|
243
|
-
const { deps, storedEntries } = createDeps();
|
|
244
|
-
const stored = await persistMemoryBatch(deps as Parameters<typeof persistMemoryBatch>[0], {
|
|
245
|
-
scope: "project:test",
|
|
246
|
-
source: "agent",
|
|
247
|
-
defaultImportance: 0.7,
|
|
248
|
-
memories: [
|
|
249
|
-
{ text: "Memory one about TypeScript preferences", category: "preferences" },
|
|
250
|
-
{ text: "Memory two about project structure", category: "entities" },
|
|
251
|
-
{ text: "Memory three about debugging workflow", category: "patterns" },
|
|
252
|
-
],
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
expect(stored).toHaveLength(3);
|
|
256
|
-
expect(storedEntries).toHaveLength(3);
|
|
257
|
-
expect(stored[0].disposition).toBe("stored");
|
|
258
|
-
expect(stored[1].disposition).toBe("stored");
|
|
259
|
-
expect(stored[2].disposition).toBe("stored");
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("returns correct disposition counts", async () => {
|
|
263
|
-
const { deps } = createDeps();
|
|
264
|
-
const stored = await persistMemoryBatch(deps as Parameters<typeof persistMemoryBatch>[0], {
|
|
265
|
-
scope: "project:test",
|
|
266
|
-
source: "agent",
|
|
267
|
-
defaultImportance: 0.7,
|
|
268
|
-
memories: [
|
|
269
|
-
{ text: "First memory item" },
|
|
270
|
-
{ text: "Second memory item" },
|
|
271
|
-
],
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
// Count dispositions the same way the MCP handler does
|
|
275
|
-
const counts = { new: 0, deduped: 0, updated: 0 };
|
|
276
|
-
for (const r of stored) {
|
|
277
|
-
if (r.disposition === "deduped") counts.deduped++;
|
|
278
|
-
else if (r.disposition === "updated") counts.updated++;
|
|
279
|
-
else counts.new++;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
expect(counts.new).toBe(2);
|
|
283
|
-
expect(counts.deduped).toBe(0);
|
|
284
|
-
expect(counts.updated).toBe(0);
|
|
285
|
-
expect(`Stored ${stored.length} memories (${counts.new} new, ${counts.deduped} deduped, ${counts.updated} updated)`)
|
|
286
|
-
.toBe("Stored 2 memories (2 new, 0 deduped, 0 updated)");
|
|
287
|
-
});
|
|
288
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { registerCoreTools } from "../mcp-tools-core.js";
|
|
4
|
-
import type { RetrievalContext, RetrievalResult } from "../retriever.js";
|
|
5
|
-
|
|
6
|
-
function makeResult(id: string, scope: string, text: string): RetrievalResult {
|
|
7
|
-
return {
|
|
8
|
-
entry: {
|
|
9
|
-
id,
|
|
10
|
-
text,
|
|
11
|
-
vector: [1, 0, 0],
|
|
12
|
-
category: "events",
|
|
13
|
-
scope,
|
|
14
|
-
importance: 0.8,
|
|
15
|
-
timestamp: Date.parse("2026-06-26T00:00:00.000Z"),
|
|
16
|
-
metadata: "{}",
|
|
17
|
-
},
|
|
18
|
-
score: 0.9,
|
|
19
|
-
sources: {
|
|
20
|
-
vector: { score: 0.9, rank: 1 },
|
|
21
|
-
fused: { score: 0.9 },
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function createSearchHarness(scopeRelations: Record<string, string[]> = {}) {
|
|
27
|
-
const handlers = new Map<string, any>();
|
|
28
|
-
const calls: RetrievalContext[] = [];
|
|
29
|
-
const byScope: Record<string, RetrievalResult[]> = {
|
|
30
|
-
"project:alpha": [
|
|
31
|
-
makeResult("alpha-note", "project:alpha", "Alpha owns the default deployment notes."),
|
|
32
|
-
],
|
|
33
|
-
"project:beta": [
|
|
34
|
-
makeResult("beta-note", "project:beta", "Beta has related deployment follow-up context."),
|
|
35
|
-
],
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const store = {
|
|
39
|
-
async vectorSearch() {
|
|
40
|
-
return [];
|
|
41
|
-
},
|
|
42
|
-
async update() {
|
|
43
|
-
return null;
|
|
44
|
-
},
|
|
45
|
-
async getById() {
|
|
46
|
-
return null;
|
|
47
|
-
},
|
|
48
|
-
async stats() {
|
|
49
|
-
return {
|
|
50
|
-
totalCount: 2,
|
|
51
|
-
scopeCounts: {
|
|
52
|
-
"project:alpha": 1,
|
|
53
|
-
"project:beta": 1,
|
|
54
|
-
},
|
|
55
|
-
categoryCounts: {},
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
registerCoreTools({
|
|
61
|
-
registerTool(name: string, _description: string, _schema: unknown, handler: unknown) {
|
|
62
|
-
handlers.set(name, handler);
|
|
63
|
-
},
|
|
64
|
-
getComponents() {
|
|
65
|
-
return {
|
|
66
|
-
store,
|
|
67
|
-
embedder: {
|
|
68
|
-
async embedPassage() {
|
|
69
|
-
return [1, 0, 0];
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
retriever: {
|
|
73
|
-
async retrieve(context: RetrievalContext) {
|
|
74
|
-
calls.push(context);
|
|
75
|
-
const scope = context.scopeFilter?.[0] ?? "__all__";
|
|
76
|
-
return byScope[scope] ?? [];
|
|
77
|
-
},
|
|
78
|
-
setKGStore() {},
|
|
79
|
-
setLLMClient() {},
|
|
80
|
-
},
|
|
81
|
-
profile: { name: "default" },
|
|
82
|
-
accessTracker: null,
|
|
83
|
-
frequencyTracker: null,
|
|
84
|
-
llm: null,
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
config: {
|
|
88
|
-
dbPath: "data/memory.lance",
|
|
89
|
-
embedding: {
|
|
90
|
-
provider: "openai-compatible",
|
|
91
|
-
apiKey: "test",
|
|
92
|
-
model: "test",
|
|
93
|
-
},
|
|
94
|
-
sources: {},
|
|
95
|
-
scopeRelations,
|
|
96
|
-
},
|
|
97
|
-
checkpointStore: {},
|
|
98
|
-
conflictStore: {},
|
|
99
|
-
workflowObservationStore: {},
|
|
100
|
-
toolDescriptions: new Map(),
|
|
101
|
-
toolTiers: {},
|
|
102
|
-
getKGExtractor: () => null,
|
|
103
|
-
getKGStore: () => null,
|
|
104
|
-
} as any);
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
calls,
|
|
108
|
-
search: handlers.get("search_memory") as (input: Record<string, unknown>) => Promise<{ content: Array<{ text: string }> }>,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
describe("search_memory related scope sidecar", () => {
|
|
113
|
-
it("keeps related scopes out of default scoped search", async () => {
|
|
114
|
-
const harness = createSearchHarness({
|
|
115
|
-
"project:alpha": ["project:beta"],
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const result = await harness.search({
|
|
119
|
-
query: "deployment",
|
|
120
|
-
scope: "project:alpha",
|
|
121
|
-
limit: 5,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
expect(harness.calls.map(call => call.scopeFilter)).toEqual([["project:alpha"]]);
|
|
125
|
-
expect(result.content[0]?.text).toContain("Alpha owns the default deployment notes.");
|
|
126
|
-
expect(result.content[0]?.text).not.toContain("Beta has related deployment follow-up context.");
|
|
127
|
-
expect(result.content[0]?.text).not.toContain("Related scope results");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("adds related scope results only when explicitly requested", async () => {
|
|
131
|
-
const harness = createSearchHarness({
|
|
132
|
-
"project:alpha": ["project:beta"],
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const result = await harness.search({
|
|
136
|
-
query: "deployment",
|
|
137
|
-
scope: "project:alpha",
|
|
138
|
-
limit: 5,
|
|
139
|
-
includeRelatedScopes: true,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(harness.calls.map(call => call.scopeFilter)).toEqual([
|
|
143
|
-
["project:alpha"],
|
|
144
|
-
["project:beta"],
|
|
145
|
-
]);
|
|
146
|
-
expect(result.content[0]?.text).toContain("Alpha owns the default deployment notes.");
|
|
147
|
-
expect(result.content[0]?.text).toContain("Related scope results");
|
|
148
|
-
expect(result.content[0]?.text).toContain("project:beta");
|
|
149
|
-
expect(result.content[0]?.text).toContain("Beta has related deployment follow-up context.");
|
|
150
|
-
});
|
|
151
|
-
});
|