recallnest 1.4.1 → 2.2.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/.env +4 -0
- package/CLAUDE.md +7 -3
- package/README.md +202 -130
- package/README_CN.md +263 -190
- package/bin/recallnest.mjs +62 -0
- package/config.json +55 -0
- package/daily-recall.sh +23 -0
- package/integrations/setup-all.sh +31 -0
- package/logs/daily-recall.error.log +0 -0
- package/logs/daily-recall.log +30 -0
- package/logs/ingest-2026-04-11.log +110 -0
- package/logs/ingest-2026-04-12.log +90 -0
- package/logs/launchagent-stderr.log +0 -0
- package/logs/launchagent-stdout.log +0 -0
- package/package.json +10 -3
- package/src/access-tracker.ts +3 -2
- package/src/activity-counter.ts +109 -0
- package/src/adaptive-retrieval.ts +6 -5
- package/src/admission-control.ts +163 -0
- package/src/anchor-generator.ts +80 -0
- package/src/api-server.ts +10 -0
- package/src/audit-log.ts +122 -0
- package/src/auto-gc.ts +98 -29
- package/src/auto-recall.ts +33 -4
- package/src/capture-engine.ts +372 -23
- package/src/cascade-forget.ts +3 -2
- package/src/cli.ts +107 -5
- package/src/compat.ts +22 -0
- package/src/confidence-tracker.ts +210 -47
- package/src/conflict-store.ts +12 -3
- package/src/consolidation-engine.ts +296 -8
- package/src/context-collapse-renderer.ts +222 -0
- package/src/context-composer-stable-selection.ts +5 -1
- package/src/context-composer.ts +239 -4
- package/src/context-reconstructor.ts +404 -0
- package/src/conversation-importer.ts +441 -0
- package/src/data-checkup.ts +232 -0
- package/src/decay-engine.ts +84 -0
- package/src/distill-lock.ts +122 -0
- package/src/doctor.ts +8 -10
- package/src/dream-pipeline.ts +227 -0
- package/src/emotion-detector.ts +90 -0
- package/src/eval.ts +3 -2
- package/src/forget-engine.ts +269 -0
- package/src/frequency-tracker.ts +175 -0
- package/src/graph-export.ts +644 -0
- package/src/ingest.ts +36 -6
- package/src/interference-detector.ts +187 -0
- package/src/kg-extractor.ts +15 -24
- package/src/kg-store.ts +2 -1
- package/src/language-hook.ts +67 -0
- package/src/llm-client.ts +289 -6
- package/src/mcp-server.ts +707 -80
- package/src/memory-assets.ts +22 -5
- package/src/memory-evolution.ts +365 -0
- package/src/memory-lint.ts +429 -0
- package/src/memory-output.ts +69 -0
- package/src/memory-schema.ts +74 -2
- package/src/narrative-schema.ts +79 -0
- package/src/narrative-tagger.ts +164 -0
- package/src/pii-detector.ts +98 -0
- package/src/post-retrieval-filter.ts +76 -0
- package/src/prediction-engine.ts +253 -0
- package/src/preference-slots.ts +65 -2
- package/src/prospective-memory.ts +215 -0
- package/src/query-expander.ts +67 -0
- package/src/recall-governor.ts +183 -0
- package/src/retention-policy.ts +90 -0
- package/src/retriever.ts +828 -55
- package/src/rif.ts +34 -8
- package/src/runtime-config.ts +23 -8
- package/src/scope-inventory.ts +4 -3
- package/src/scope-policy.ts +4 -0
- package/src/session-distiller.ts +307 -0
- package/src/session-output.ts +40 -0
- package/src/session-schema.ts +37 -0
- package/src/session-store.ts +7 -2
- package/src/skill-engine.ts +208 -0
- package/src/skill-promotion.ts +293 -0
- package/src/skill-schema.ts +39 -0
- package/src/store.ts +96 -10
- package/src/topic-tag.ts +66 -0
- package/src/tracker.ts +3 -1
- package/src/ui-server.ts +80 -8
- package/src/workflow-observation-scope-review.ts +2 -1
- package/src/workflow-observation-store.ts +2 -1
- package/src/write-verifier.ts +126 -0
- package/.claude-plugin/CLAUDE.md +0 -29
- package/.claude-plugin/marketplace.json +0 -18
- package/.github/workflows/ci.yml +0 -28
- package/.mcp.json +0 -9
- package/CHANGELOG.md +0 -51
- package/DEMO.md +0 -94
- package/EVAL.md +0 -89
- package/FAILURES.md +0 -75
- package/OPERATIONS.md +0 -59
- package/ROADMAP.md +0 -198
- package/assets/recallnest-workbench.png +0 -0
- package/assets/ui/app.js +0 -807
- package/assets/ui/index.html +0 -154
- package/assets/ui/styles.css +0 -605
- package/assets/wechat-qr.jpg +0 -0
- package/daily-reflections/2026-03-05.md +0 -15
- package/daily-reflections/2026-03-06.md +0 -15
- package/daily-reflections/2026-03-07.md +0 -7
- package/daily-reflections/2026-03-08.md +0 -34
- package/daily-reflections/2026-03-09.md +0 -35
- package/daily-reflections/2026-03-10.md +0 -36
- package/daily-reflections/2026-03-11.md +0 -35
- package/daily-reflections/2026-03-12.md +0 -36
- package/daily-reflections/2026-03-13.md +0 -35
- package/daily-reflections/2026-03-14.md +0 -35
- package/daily-reflections/2026-03-15.md +0 -35
- package/daily-reflections/2026-03-16.md +0 -41
- package/daily-reflections/2026-03-17.md +0 -10
- package/daily-reflections/2026-03-18.md +0 -10
- package/daily-reflections/2026-03-19.md +0 -10
- package/daily-reflections/2026-03-20.md +0 -10
- package/daily-reflections/2026-03-21.md +0 -10
- package/daily-reflections/2026-03-22.md +0 -10
- package/daily-reflections/2026-03-23.md +0 -10
- package/daily-reflections/2026-03-24.md +0 -10
- package/daily-reflections/2026-03-25.md +0 -32
- package/daily-reflections/2026-03-26.md +0 -37
- package/daily-reflections/2026-03-27.md +0 -35
- package/daily-reflections/2026-03-28.md +0 -35
- package/daily-reflections/2026-03-29.md +0 -35
- package/daily-reflections/2026-03-30.md +0 -36
- package/daily-reflections/2026-03-31.md +0 -35
- package/daily-reflections/2026-04-01.md +0 -35
- package/docs/api-reference.md +0 -1291
- package/docs/architecture.md +0 -168
- package/docs/memory-boundary-contract.md +0 -226
- package/docs/memory-categories.md +0 -119
- package/docs/pipeline-audit-ultramemory.md +0 -177
- package/docs/plans/2026-03-08-query-expansion.md +0 -270
- package/docs/plans/2026-03-16-continuity-layer.md +0 -196
- package/docs/plans/mcp-tiering-plan.md +0 -126
- package/docs/research/recall-quality-audit-2026-03-22.md +0 -153
- package/docs/self-evolution.md +0 -198
- package/docs/superpowers/plans/2026-03-19-ingest-pipeline-upgrade.md +0 -782
- package/docs/superpowers/specs/2026-03-19-ingest-pipeline-upgrade-design.md +0 -77
- package/docs/superpowers/specs/2026-03-23-pull-claude-desktop-design.md +0 -95
- package/eval/continuity/results-2026-03-16.md +0 -117
- package/eval/continuity/results-2026-03-19.md +0 -453
- package/eval/continuity/runbook.md +0 -110
- package/eval/continuity/seed-cases.md +0 -54
- package/eval/reports/2026-03-06-abstract-query-baseline.md +0 -96
- package/eval/reports/2026-03-06-aws-ssh-baseline.md +0 -82
- package/eval/reports/2026-03-06-baseline.md +0 -82
- package/eval/reports/query-expansion.md +0 -138
- package/lm +0 -19
- package/plan-v1.2-distributable.md +0 -105
- package/scripts/archive-distilled-junk.ts +0 -116
- package/scripts/backfill-l0l1l2.ts +0 -98
- package/scripts/blind-scan.ts +0 -588
- package/scripts/cleanup-step1-exact-dups.ts +0 -117
- package/scripts/cleanup-step2-template-dups.ts +0 -113
- package/scripts/cleanup-step3-stale-content.ts +0 -149
- package/scripts/cleanup-step4-orphan-scopes.ts +0 -131
- package/scripts/delete-distilled-junk.ts +0 -88
- package/scripts/distill-facts.ts +0 -305
- package/scripts/health-check.ts +0 -343
- package/scripts/incremental-ingest.sh +0 -71
- package/scripts/mlp-health-check.ts +0 -382
- package/scripts/pull-claude-desktop.ts +0 -515
- package/scripts/re-ingest-cc.sh +0 -66
- package/scripts/rebalance-memory-health.ts +0 -181
- package/scripts/run-desktop-ingest.sh +0 -11
- package/scripts/start-server.sh +0 -12
- package/scripts/viz-dashboard.html +0 -423
- package/scripts/viz-export.ts +0 -703
- package/src/__tests__/access-tracker-novelty.test.ts +0 -228
- package/src/__tests__/auto-consolidation.test.ts +0 -168
- package/src/__tests__/auto-recall.test.ts +0 -131
- package/src/__tests__/batch-dedup.test.ts +0 -65
- package/src/__tests__/capture-engine.test.ts +0 -1142
- 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 -33
- package/src/__tests__/confidence-tracker.test.ts +0 -196
- 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 -374
- package/src/__tests__/consolidation-engine.test.ts +0 -181
- 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-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__/core-recall-eval.test.ts +0 -235
- package/src/__tests__/core-summary.test.ts +0 -109
- package/src/__tests__/dedup-actions.test.ts +0 -58
- package/src/__tests__/deterministic-id.test.ts +0 -39
- package/src/__tests__/doctor.test.ts +0 -303
- package/src/__tests__/drill-down.test.ts +0 -108
- package/src/__tests__/embedder.test.ts +0 -122
- package/src/__tests__/entity-resolver.test.ts +0 -58
- package/src/__tests__/event-segmenter.test.ts +0 -153
- package/src/__tests__/hotness-blend.test.ts +0 -76
- package/src/__tests__/ingest.test.ts +0 -360
- package/src/__tests__/kg-extractor.test.ts +0 -184
- package/src/__tests__/kg-store.test.ts +0 -198
- package/src/__tests__/llm-consolidation.test.ts +0 -226
- package/src/__tests__/memory-boundaries.test.ts +0 -237
- package/src/__tests__/memory-health-rebalance.test.ts +0 -144
- package/src/__tests__/memory-output.test.ts +0 -215
- package/src/__tests__/multi-vector.test.ts +0 -242
- package/src/__tests__/ppr-traversal.test.ts +0 -256
- package/src/__tests__/preference-guard-smoke.test.ts +0 -211
- package/src/__tests__/preference-matcher.test.ts +0 -230
- package/src/__tests__/preference-slots.test.ts +0 -106
- package/src/__tests__/prospective-memory.test.ts +0 -283
- package/src/__tests__/query-entity-detector.test.ts +0 -171
- package/src/__tests__/query-expander.test.ts +0 -34
- package/src/__tests__/recall-mode.test.ts +0 -64
- package/src/__tests__/result-synthesizer.test.ts +0 -198
- package/src/__tests__/resume-context.test.ts +0 -4743
- package/src/__tests__/retrieval-trace.test.ts +0 -213
- package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
- package/src/__tests__/retroactive-boost.test.ts +0 -223
- package/src/__tests__/scope-inventory.test.ts +0 -200
- package/src/__tests__/scope-policy.test.ts +0 -69
- package/src/__tests__/session-checkpoint.test.ts +0 -259
- package/src/__tests__/session-gc.test.ts +0 -215
- package/src/__tests__/store-scope-audit.test.ts +0 -81
- package/src/__tests__/temporal-parser.test.ts +0 -241
- package/src/__tests__/term-registry.test.ts +0 -121
- package/src/__tests__/tool-output-compressor.test.ts +0 -133
- package/src/__tests__/version-manager.test.ts +0 -213
- package/src/__tests__/workflow-observation.test.ts +0 -400
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
buildMemoryHealthRebalancePlan,
|
|
5
|
-
computeRebalancedImportance,
|
|
6
|
-
getMemoryHealthAccessCount,
|
|
7
|
-
getStoredMemoryTier,
|
|
8
|
-
parseMemoryHealthMetadata,
|
|
9
|
-
resolveRebalancedTier,
|
|
10
|
-
summarizeMemoryHealthPlans,
|
|
11
|
-
} from "../memory-health-rebalance.js";
|
|
12
|
-
|
|
13
|
-
const datasetStats = {
|
|
14
|
-
maxAccessCount: 19,
|
|
15
|
-
minTimestamp: Date.parse("2026-03-02T00:00:00.000Z"),
|
|
16
|
-
maxTimestamp: Date.parse("2026-03-19T00:00:00.000Z"),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe("memory health rebalance", () => {
|
|
20
|
-
it("parses metadata safely and supports both accessCount key styles", () => {
|
|
21
|
-
expect(parseMemoryHealthMetadata("{")).toEqual({});
|
|
22
|
-
expect(getMemoryHealthAccessCount({ accessCount: 3 })).toBe(3);
|
|
23
|
-
expect(getMemoryHealthAccessCount({ access_count: 4 })).toBe(4);
|
|
24
|
-
expect(getStoredMemoryTier({ tier: "working" })).toBe("working");
|
|
25
|
-
expect(getStoredMemoryTier({ tier: "unknown" })).toBe("unknown");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("demotes dead memories to peripheral even when they already had a hotter tier", () => {
|
|
29
|
-
const plan = buildMemoryHealthRebalancePlan({
|
|
30
|
-
id: "dead-memory",
|
|
31
|
-
importance: 0.8,
|
|
32
|
-
timestamp: datasetStats.minTimestamp,
|
|
33
|
-
metadata: JSON.stringify({ tier: "working", accessCount: 0 }),
|
|
34
|
-
}, datasetStats);
|
|
35
|
-
|
|
36
|
-
expect(resolveRebalancedTier("working", 0)).toBe("peripheral");
|
|
37
|
-
expect(plan.targetTier).toBe("peripheral");
|
|
38
|
-
expect(plan.deadMemoryRow).toBe(true);
|
|
39
|
-
expect(plan.deadMemoryDemoted).toBe(true);
|
|
40
|
-
expect(plan.nextImportance).toBeGreaterThanOrEqual(0.3);
|
|
41
|
-
expect(plan.nextImportance).toBeLessThanOrEqual(0.5);
|
|
42
|
-
expect(plan.nextMetadata.tier).toBe("peripheral");
|
|
43
|
-
expect(plan.nextMetadata.importance).toBe(plan.nextImportance);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("backfills unknown tiers from access counts", () => {
|
|
47
|
-
const corePlan = buildMemoryHealthRebalancePlan({
|
|
48
|
-
id: "unknown-core",
|
|
49
|
-
importance: 0.7,
|
|
50
|
-
timestamp: datasetStats.maxTimestamp,
|
|
51
|
-
metadata: JSON.stringify({ accessCount: 6 }),
|
|
52
|
-
}, datasetStats);
|
|
53
|
-
const workingPlan = buildMemoryHealthRebalancePlan({
|
|
54
|
-
id: "unknown-working",
|
|
55
|
-
importance: 0.7,
|
|
56
|
-
timestamp: datasetStats.maxTimestamp,
|
|
57
|
-
metadata: JSON.stringify({ accessCount: 3 }),
|
|
58
|
-
}, datasetStats);
|
|
59
|
-
|
|
60
|
-
expect(corePlan.currentTier).toBe("unknown");
|
|
61
|
-
expect(corePlan.targetTier).toBe("core");
|
|
62
|
-
expect(corePlan.tierBackfilled).toBe(true);
|
|
63
|
-
expect(corePlan.nextImportance).toBeGreaterThanOrEqual(0.85);
|
|
64
|
-
expect(corePlan.nextImportance).toBeLessThanOrEqual(0.95);
|
|
65
|
-
|
|
66
|
-
expect(workingPlan.targetTier).toBe("working");
|
|
67
|
-
expect(workingPlan.nextImportance).toBeGreaterThanOrEqual(0.6);
|
|
68
|
-
expect(workingPlan.nextImportance).toBeLessThanOrEqual(0.8);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("keeps existing non-dead tiers and only reshapes importance within the tier band", () => {
|
|
72
|
-
const lowPlan = buildMemoryHealthRebalancePlan({
|
|
73
|
-
id: "working-low",
|
|
74
|
-
importance: 0.6,
|
|
75
|
-
timestamp: datasetStats.minTimestamp,
|
|
76
|
-
metadata: JSON.stringify({ tier: "working", accessCount: 2 }),
|
|
77
|
-
}, datasetStats);
|
|
78
|
-
const highPlan = buildMemoryHealthRebalancePlan({
|
|
79
|
-
id: "working-high",
|
|
80
|
-
importance: 0.8,
|
|
81
|
-
timestamp: datasetStats.maxTimestamp,
|
|
82
|
-
metadata: JSON.stringify({ tier: "working", accessCount: 5 }),
|
|
83
|
-
}, datasetStats);
|
|
84
|
-
|
|
85
|
-
expect(lowPlan.targetTier).toBe("working");
|
|
86
|
-
expect(highPlan.targetTier).toBe("working");
|
|
87
|
-
expect(lowPlan.nextImportance).toBeLessThan(highPlan.nextImportance);
|
|
88
|
-
expect(lowPlan.nextImportance).toBeGreaterThanOrEqual(0.6);
|
|
89
|
-
expect(highPlan.nextImportance).toBeLessThanOrEqual(0.8);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("uses access_count and existing importance together instead of hard-overwriting values", () => {
|
|
93
|
-
const cooler = computeRebalancedImportance(0.6, "core", 6, 19, 0.2);
|
|
94
|
-
const hotter = computeRebalancedImportance(0.9, "core", 19, 19, 0.9);
|
|
95
|
-
|
|
96
|
-
expect(cooler).toBeGreaterThanOrEqual(0.85);
|
|
97
|
-
expect(hotter).toBeLessThanOrEqual(0.95);
|
|
98
|
-
expect(hotter).toBeGreaterThan(cooler);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("uses recency to spread dead peripheral memories within the peripheral band", () => {
|
|
102
|
-
const older = buildMemoryHealthRebalancePlan({
|
|
103
|
-
id: "dead-old",
|
|
104
|
-
importance: 0.35,
|
|
105
|
-
timestamp: datasetStats.minTimestamp,
|
|
106
|
-
metadata: JSON.stringify({ accessCount: 0 }),
|
|
107
|
-
}, datasetStats);
|
|
108
|
-
const newer = buildMemoryHealthRebalancePlan({
|
|
109
|
-
id: "dead-new",
|
|
110
|
-
importance: 0.35,
|
|
111
|
-
timestamp: datasetStats.maxTimestamp,
|
|
112
|
-
metadata: JSON.stringify({ accessCount: 0 }),
|
|
113
|
-
}, datasetStats);
|
|
114
|
-
|
|
115
|
-
expect(older.targetTier).toBe("peripheral");
|
|
116
|
-
expect(newer.targetTier).toBe("peripheral");
|
|
117
|
-
expect(older.nextImportance).toBeGreaterThanOrEqual(0.3);
|
|
118
|
-
expect(newer.nextImportance).toBeLessThanOrEqual(0.5);
|
|
119
|
-
expect(newer.nextImportance).toBeGreaterThan(older.nextImportance);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("summarizes rebalance plans for reporting", () => {
|
|
123
|
-
const summary = summarizeMemoryHealthPlans([
|
|
124
|
-
buildMemoryHealthRebalancePlan({
|
|
125
|
-
id: "a",
|
|
126
|
-
importance: 0.7,
|
|
127
|
-
timestamp: datasetStats.minTimestamp,
|
|
128
|
-
metadata: JSON.stringify({ accessCount: 0 }),
|
|
129
|
-
}, datasetStats),
|
|
130
|
-
buildMemoryHealthRebalancePlan({
|
|
131
|
-
id: "b",
|
|
132
|
-
importance: 0.7,
|
|
133
|
-
timestamp: datasetStats.maxTimestamp,
|
|
134
|
-
metadata: JSON.stringify({ tier: "working", accessCount: 4 }),
|
|
135
|
-
}, datasetStats),
|
|
136
|
-
]);
|
|
137
|
-
|
|
138
|
-
expect(summary.totalRows).toBe(2);
|
|
139
|
-
expect(summary.changedRows).toBe(2);
|
|
140
|
-
expect(summary.deadMemoryRows).toBe(1);
|
|
141
|
-
expect(summary.tierBackfills).toBe(1);
|
|
142
|
-
expect(summary.importanceChanges).toBe(2);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { formatExplainResults, formatSearchResults } from "../memory-output.js";
|
|
4
|
-
import type { RetrievalResult } from "../retriever.js";
|
|
5
|
-
|
|
6
|
-
function buildResult(id: string, metadata: Record<string, unknown>): RetrievalResult {
|
|
7
|
-
return {
|
|
8
|
-
entry: {
|
|
9
|
-
id,
|
|
10
|
-
text: "User prefers concise, direct replies.",
|
|
11
|
-
vector: [],
|
|
12
|
-
category: "preferences",
|
|
13
|
-
scope: "memory:agent",
|
|
14
|
-
importance: 0.8,
|
|
15
|
-
timestamp: Date.parse("2026-03-16T00:00:00.000Z"),
|
|
16
|
-
metadata: JSON.stringify(metadata),
|
|
17
|
-
},
|
|
18
|
-
score: 0.91,
|
|
19
|
-
sources: {
|
|
20
|
-
vector: { score: 0.9, rank: 1 },
|
|
21
|
-
bm25: { score: 0.8, rank: 2 },
|
|
22
|
-
fused: { score: 0.91 },
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe("memory output", () => {
|
|
28
|
-
it("includes provenance in search results", () => {
|
|
29
|
-
const output = formatSearchResults([
|
|
30
|
-
buildResult("abcd1234-0000-0000-0000-000000000001", {
|
|
31
|
-
source: "agent",
|
|
32
|
-
canonicalKey: "user-reply-style",
|
|
33
|
-
boundary: {
|
|
34
|
-
layer: "durable",
|
|
35
|
-
authority: "structured-memory",
|
|
36
|
-
conflictPolicy: "latest-wins",
|
|
37
|
-
originalCategory: "preferences",
|
|
38
|
-
},
|
|
39
|
-
promotedFrom: {
|
|
40
|
-
memoryId: "feedface-0000-0000-0000-000000000001",
|
|
41
|
-
scope: "cc:session1",
|
|
42
|
-
category: "events",
|
|
43
|
-
boundary: {
|
|
44
|
-
layer: "evidence",
|
|
45
|
-
authority: "transcript-ingest",
|
|
46
|
-
conflictPolicy: "append-only",
|
|
47
|
-
originalCategory: "preferences",
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
provenanceHistory: [
|
|
51
|
-
{
|
|
52
|
-
memoryId: "feedface-0000-0000-0000-000000000001",
|
|
53
|
-
scope: "cc:session1",
|
|
54
|
-
category: "events",
|
|
55
|
-
source: "cc",
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
memoryId: "deadbeef-0000-0000-0000-000000000002",
|
|
59
|
-
scope: "cc:session2",
|
|
60
|
-
category: "events",
|
|
61
|
-
source: "cc",
|
|
62
|
-
observedAt: "2026-03-17T04:30:00.000Z",
|
|
63
|
-
boundary: {
|
|
64
|
-
layer: "evidence",
|
|
65
|
-
authority: "transcript-ingest",
|
|
66
|
-
conflictPolicy: "append-only",
|
|
67
|
-
originalCategory: "preferences",
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
provenanceHistoryCount: 2,
|
|
72
|
-
preferenceSlot: {
|
|
73
|
-
type: "brand-item",
|
|
74
|
-
brand: "麦当劳",
|
|
75
|
-
item: "麦辣鸡翅",
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
], {
|
|
79
|
-
query: "reply style",
|
|
80
|
-
profile: "default",
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
expect(output).toContain("prov : durable/structured-memory");
|
|
84
|
-
expect(output).toContain("key:user-reply-style");
|
|
85
|
-
expect(output).toContain("promoted:feedface<-evidence/transcript-ingest");
|
|
86
|
-
expect(output).toContain("history:2");
|
|
87
|
-
expect(output).toContain("observed:deadbeef@2026-03-17");
|
|
88
|
-
expect(output).toContain("slot:brand-item:麦当劳:麦辣鸡翅");
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("includes provenance in explain results", () => {
|
|
92
|
-
const output = formatExplainResults([
|
|
93
|
-
buildResult("abcd1234-0000-0000-0000-000000000001", {
|
|
94
|
-
source: "cc",
|
|
95
|
-
boundary: {
|
|
96
|
-
layer: "evidence",
|
|
97
|
-
authority: "transcript-ingest",
|
|
98
|
-
conflictPolicy: "append-only",
|
|
99
|
-
originalCategory: "preferences",
|
|
100
|
-
downgradedFrom: "preferences",
|
|
101
|
-
},
|
|
102
|
-
}),
|
|
103
|
-
], {
|
|
104
|
-
query: "reply style",
|
|
105
|
-
profile: "writing",
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(output).toContain("prov : evidence/transcript-ingest");
|
|
109
|
-
expect(output).toContain("downgraded:preferences");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("renders reply-style slots in provenance summaries", () => {
|
|
113
|
-
const output = formatSearchResults([
|
|
114
|
-
buildResult("abcd1234-0000-0000-0000-000000000002", {
|
|
115
|
-
source: "agent",
|
|
116
|
-
canonicalKey: "preferences:reply-style:concise:direct",
|
|
117
|
-
boundary: {
|
|
118
|
-
layer: "durable",
|
|
119
|
-
authority: "structured-memory",
|
|
120
|
-
conflictPolicy: "latest-wins",
|
|
121
|
-
originalCategory: "preferences",
|
|
122
|
-
},
|
|
123
|
-
preferenceSlot: {
|
|
124
|
-
type: "reply-style",
|
|
125
|
-
traits: ["concise", "direct"],
|
|
126
|
-
},
|
|
127
|
-
}),
|
|
128
|
-
], {
|
|
129
|
-
query: "reply style",
|
|
130
|
-
profile: "default",
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(output).toContain("slot:reply-style:concise:direct");
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("renders tool-choice slots in provenance summaries", () => {
|
|
137
|
-
const output = formatSearchResults([
|
|
138
|
-
buildResult("abcd1234-0000-0000-0000-000000000003", {
|
|
139
|
-
source: "agent",
|
|
140
|
-
canonicalKey: "preferences:tool-choice:bun:over:node",
|
|
141
|
-
boundary: {
|
|
142
|
-
layer: "durable",
|
|
143
|
-
authority: "structured-memory",
|
|
144
|
-
conflictPolicy: "latest-wins",
|
|
145
|
-
originalCategory: "preferences",
|
|
146
|
-
},
|
|
147
|
-
preferenceSlot: {
|
|
148
|
-
type: "tool-choice",
|
|
149
|
-
preferredTool: "bun",
|
|
150
|
-
avoidedTool: "node",
|
|
151
|
-
},
|
|
152
|
-
}),
|
|
153
|
-
], {
|
|
154
|
-
query: "tool choice",
|
|
155
|
-
profile: "default",
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
expect(output).toContain("slot:tool-choice:bun:over:node");
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("does not render slot provenance for plain preferences canonical keys", () => {
|
|
162
|
-
const output = formatSearchResults([
|
|
163
|
-
buildResult("abcd1234-0000-0000-0000-000000000004", {
|
|
164
|
-
source: "agent",
|
|
165
|
-
canonicalKey: "preferences:这段文案简洁直接-先别改",
|
|
166
|
-
boundary: {
|
|
167
|
-
layer: "durable",
|
|
168
|
-
authority: "structured-memory",
|
|
169
|
-
conflictPolicy: "latest-wins",
|
|
170
|
-
originalCategory: "preferences",
|
|
171
|
-
},
|
|
172
|
-
}),
|
|
173
|
-
buildResult("abcd1234-0000-0000-0000-000000000005", {
|
|
174
|
-
source: "agent",
|
|
175
|
-
canonicalKey: "preferences:文档里写了-uses-bun-over-node-的迁移说明",
|
|
176
|
-
boundary: {
|
|
177
|
-
layer: "durable",
|
|
178
|
-
authority: "structured-memory",
|
|
179
|
-
conflictPolicy: "latest-wins",
|
|
180
|
-
originalCategory: "preferences",
|
|
181
|
-
},
|
|
182
|
-
}),
|
|
183
|
-
], {
|
|
184
|
-
query: "preferences",
|
|
185
|
-
profile: "default",
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
expect(output).toContain("key:preferences:这段文案简洁直接-先别改");
|
|
189
|
-
expect(output).toContain("key:preferences:文档里写了-uses-bun-over-node-的迁移说明");
|
|
190
|
-
expect(output).not.toContain("slot:reply-style:");
|
|
191
|
-
expect(output).not.toContain("slot:tool-choice:");
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("does not render slot provenance in explain output for plain preferences canonical keys", () => {
|
|
195
|
-
const output = formatExplainResults([
|
|
196
|
-
buildResult("abcd1234-0000-0000-0000-000000000006", {
|
|
197
|
-
source: "agent",
|
|
198
|
-
canonicalKey: "preferences:这段文案简洁直接-先别改",
|
|
199
|
-
boundary: {
|
|
200
|
-
layer: "durable",
|
|
201
|
-
authority: "structured-memory",
|
|
202
|
-
conflictPolicy: "latest-wins",
|
|
203
|
-
originalCategory: "preferences",
|
|
204
|
-
},
|
|
205
|
-
}),
|
|
206
|
-
], {
|
|
207
|
-
query: "draft note",
|
|
208
|
-
profile: "default",
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
expect(output).toContain("key:preferences:这段文案简洁直接-先别改");
|
|
212
|
-
expect(output).not.toContain("slot:reply-style:");
|
|
213
|
-
expect(output).not.toContain("slot:tool-choice:");
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, beforeEach, afterEach } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
blendMultiVectorScores,
|
|
5
|
-
cosineSimilarity,
|
|
6
|
-
DEFAULT_BLEND_CONFIG,
|
|
7
|
-
embedMultiVector,
|
|
8
|
-
extractMultiVectorText,
|
|
9
|
-
isMultiVectorEnabled,
|
|
10
|
-
tokenize,
|
|
11
|
-
textOverlapScore,
|
|
12
|
-
adaptiveBlendConfig,
|
|
13
|
-
} from "../multi-vector.js";
|
|
14
|
-
|
|
15
|
-
describe("isMultiVectorEnabled", () => {
|
|
16
|
-
const original = process.env.RECALLNEST_MULTI_VECTOR;
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
if (original === undefined) {
|
|
20
|
-
delete process.env.RECALLNEST_MULTI_VECTOR;
|
|
21
|
-
} else {
|
|
22
|
-
process.env.RECALLNEST_MULTI_VECTOR = original;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("returns false by default", () => {
|
|
27
|
-
delete process.env.RECALLNEST_MULTI_VECTOR;
|
|
28
|
-
expect(isMultiVectorEnabled()).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("returns true when set to 'true'", () => {
|
|
32
|
-
process.env.RECALLNEST_MULTI_VECTOR = "true";
|
|
33
|
-
expect(isMultiVectorEnabled()).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("extractMultiVectorText", () => {
|
|
38
|
-
it("extracts L0 and L1 from valid metadata", () => {
|
|
39
|
-
const meta = JSON.stringify({
|
|
40
|
-
l0_abstract: "User prefers TypeScript",
|
|
41
|
-
l1_overview: "User consistently chooses TypeScript over JavaScript for type safety",
|
|
42
|
-
});
|
|
43
|
-
const result = extractMultiVectorText(meta);
|
|
44
|
-
expect(result.l0).toBe("User prefers TypeScript");
|
|
45
|
-
expect(result.l1).toContain("TypeScript");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("returns empty for missing fields", () => {
|
|
49
|
-
const meta = JSON.stringify({ source: "manual" });
|
|
50
|
-
const result = extractMultiVectorText(meta);
|
|
51
|
-
expect(result.l0).toBeUndefined();
|
|
52
|
-
expect(result.l1).toBeUndefined();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("returns empty for undefined metadata", () => {
|
|
56
|
-
const result = extractMultiVectorText(undefined);
|
|
57
|
-
expect(result.l0).toBeUndefined();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("skips very short L0/L1 text (<=5 chars)", () => {
|
|
61
|
-
const meta = JSON.stringify({ l0_abstract: "abc", l1_overview: "short" });
|
|
62
|
-
const result = extractMultiVectorText(meta);
|
|
63
|
-
expect(result.l0).toBeUndefined();
|
|
64
|
-
expect(result.l1).toBeUndefined();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe("embedMultiVector", () => {
|
|
69
|
-
const mockEmbedder = {
|
|
70
|
-
async embedPassage(text: string) {
|
|
71
|
-
return [text.length, 0.5, 0.1];
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
it("returns null vectors when disabled", async () => {
|
|
76
|
-
delete process.env.RECALLNEST_MULTI_VECTOR;
|
|
77
|
-
const result = await embedMultiVector(mockEmbedder, JSON.stringify({
|
|
78
|
-
l0_abstract: "Some abstract text here",
|
|
79
|
-
}));
|
|
80
|
-
expect(result.vector_l0).toBeNull();
|
|
81
|
-
expect(result.vector_l1).toBeNull();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("generates vectors when enabled and text available", async () => {
|
|
85
|
-
process.env.RECALLNEST_MULTI_VECTOR = "true";
|
|
86
|
-
const result = await embedMultiVector(mockEmbedder, JSON.stringify({
|
|
87
|
-
l0_abstract: "User prefers TypeScript",
|
|
88
|
-
l1_overview: "Detailed overview of TypeScript preference with reasoning",
|
|
89
|
-
}));
|
|
90
|
-
expect(result.vector_l0).not.toBeNull();
|
|
91
|
-
expect(result.vector_l1).not.toBeNull();
|
|
92
|
-
expect(result.vector_l0![0]).toBe("User prefers TypeScript".length);
|
|
93
|
-
// Cleanup
|
|
94
|
-
delete process.env.RECALLNEST_MULTI_VECTOR;
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("returns null for missing L0/L1 text even when enabled", async () => {
|
|
98
|
-
process.env.RECALLNEST_MULTI_VECTOR = "true";
|
|
99
|
-
const result = await embedMultiVector(mockEmbedder, JSON.stringify({ source: "manual" }));
|
|
100
|
-
expect(result.vector_l0).toBeNull();
|
|
101
|
-
expect(result.vector_l1).toBeNull();
|
|
102
|
-
delete process.env.RECALLNEST_MULTI_VECTOR;
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe("blendMultiVectorScores", () => {
|
|
107
|
-
it("returns main score when no L0/L1 available", () => {
|
|
108
|
-
expect(blendMultiVectorScores(0.8, null, null)).toBe(0.8);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("blends with L0 only", () => {
|
|
112
|
-
const blended = blendMultiVectorScores(0.8, 0.9, null);
|
|
113
|
-
// (0.8 * 0.65 + 0.9 * 0.20) / (0.65 + 0.20) = (0.52 + 0.18) / 0.85
|
|
114
|
-
expect(blended).toBeCloseTo(0.824, 2);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("blends with both L0 and L1", () => {
|
|
118
|
-
const blended = blendMultiVectorScores(0.8, 0.9, 0.7);
|
|
119
|
-
// (0.8*0.65 + 0.9*0.20 + 0.7*0.15) / (0.65+0.20+0.15) = (0.52+0.18+0.105)/1.0
|
|
120
|
-
expect(blended).toBeCloseTo(0.805, 2);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("supports custom weights", () => {
|
|
124
|
-
const config = { vectorWeight: 0.5, l0Weight: 0.3, l1Weight: 0.2 };
|
|
125
|
-
const blended = blendMultiVectorScores(0.8, 0.9, 0.7, config);
|
|
126
|
-
expect(blended).toBeCloseTo(0.81, 2);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe("cosineSimilarity", () => {
|
|
131
|
-
it("returns 1 for identical vectors", () => {
|
|
132
|
-
expect(cosineSimilarity([1, 0, 0], [1, 0, 0])).toBeCloseTo(1.0, 5);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("returns 0 for orthogonal vectors", () => {
|
|
136
|
-
expect(cosineSimilarity([1, 0, 0], [0, 1, 0])).toBeCloseTo(0.0, 5);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("returns -1 for opposite vectors", () => {
|
|
140
|
-
expect(cosineSimilarity([1, 0, 0], [-1, 0, 0])).toBeCloseTo(-1.0, 5);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("returns 0 for empty vectors", () => {
|
|
144
|
-
expect(cosineSimilarity([], [])).toBe(0);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("returns 0 for mismatched dimensions", () => {
|
|
148
|
-
expect(cosineSimilarity([1, 0], [1, 0, 0])).toBe(0);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// ===========================================================================
|
|
153
|
-
// Tier 4.3: Text-overlap multi-vector scoring
|
|
154
|
-
// ===========================================================================
|
|
155
|
-
|
|
156
|
-
describe("tokenize", () => {
|
|
157
|
-
it("tokenizes English text, removes stop words", () => {
|
|
158
|
-
const tokens = tokenize("The user prefers TypeScript for projects");
|
|
159
|
-
expect(tokens).toContain("user");
|
|
160
|
-
expect(tokens).toContain("prefers");
|
|
161
|
-
expect(tokens).toContain("typescript");
|
|
162
|
-
expect(tokens).toContain("projects");
|
|
163
|
-
expect(tokens).not.toContain("the");
|
|
164
|
-
expect(tokens).not.toContain("for");
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("tokenizes Chinese text into unigrams, removes stop words", () => {
|
|
168
|
-
const tokens = tokenize("用户喜欢使用TypeScript编程");
|
|
169
|
-
expect(tokens).toContain("用");
|
|
170
|
-
expect(tokens).toContain("户");
|
|
171
|
-
expect(tokens).toContain("喜");
|
|
172
|
-
expect(tokens).toContain("欢");
|
|
173
|
-
expect(tokens).toContain("typescript");
|
|
174
|
-
expect(tokens).not.toContain("的");
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("handles mixed CJK and English", () => {
|
|
178
|
-
const tokens = tokenize("RecallNest 记忆服务 is great");
|
|
179
|
-
expect(tokens).toContain("recallnest");
|
|
180
|
-
expect(tokens).toContain("记");
|
|
181
|
-
expect(tokens).toContain("忆");
|
|
182
|
-
expect(tokens).toContain("服");
|
|
183
|
-
expect(tokens).toContain("务");
|
|
184
|
-
expect(tokens).toContain("great");
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("returns empty for empty/whitespace input", () => {
|
|
188
|
-
expect(tokenize("")).toEqual([]);
|
|
189
|
-
expect(tokenize(" ")).toEqual([]);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe("textOverlapScore", () => {
|
|
194
|
-
it("returns 1.0 when query fully matches a concise abstract", () => {
|
|
195
|
-
const score = textOverlapScore("TypeScript preference", "TypeScript preference");
|
|
196
|
-
expect(score).toBeGreaterThan(0.8);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("returns higher score for L0 abstract than L2 full text on topic query", () => {
|
|
200
|
-
const query = "TypeScript projects";
|
|
201
|
-
const l0 = "User prefers TypeScript for all projects";
|
|
202
|
-
const l2 = "The user mentioned that they have been working with React and JavaScript for three years. They recently started using TypeScript for their projects because of type safety. They also mentioned Python for data science work.";
|
|
203
|
-
|
|
204
|
-
const l0Score = textOverlapScore(query, l0);
|
|
205
|
-
const l2Score = textOverlapScore(query, l2);
|
|
206
|
-
expect(l0Score).toBeGreaterThan(l2Score);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("returns 0 for completely unrelated texts", () => {
|
|
210
|
-
const score = textOverlapScore("TypeScript projects", "天气很好适合出去玩");
|
|
211
|
-
expect(score).toBe(0);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("returns 0 for empty query", () => {
|
|
215
|
-
expect(textOverlapScore("", "some text")).toBe(0);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("returns 0 for empty candidate", () => {
|
|
219
|
-
expect(textOverlapScore("some query", "")).toBe(0);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
describe("adaptiveBlendConfig", () => {
|
|
224
|
-
it("boosts L0/L1 for short queries (≤3 tokens)", () => {
|
|
225
|
-
const config = adaptiveBlendConfig(2);
|
|
226
|
-
expect(config.l0Weight).toBe(0.25);
|
|
227
|
-
expect(config.l1Weight).toBe(0.25);
|
|
228
|
-
expect(config.vectorWeight).toBe(0.50);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("uses default for medium queries (4-10 tokens)", () => {
|
|
232
|
-
const config = adaptiveBlendConfig(7);
|
|
233
|
-
expect(config).toEqual(DEFAULT_BLEND_CONFIG);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it("favors L2 for long queries (>10 tokens)", () => {
|
|
237
|
-
const config = adaptiveBlendConfig(15);
|
|
238
|
-
expect(config.vectorWeight).toBe(0.80);
|
|
239
|
-
expect(config.l0Weight).toBe(0.10);
|
|
240
|
-
expect(config.l1Weight).toBe(0.10);
|
|
241
|
-
});
|
|
242
|
-
});
|