recallnest 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +304 -0
- package/README.md +251 -258
- package/README_CN.md +226 -247
- package/assets/ui/app.js +6 -1
- package/bin/recallnest.mjs +20 -37
- package/docs/api-reference.md +8 -0
- package/docs/architecture.md +18 -13
- package/eval/cases-canary.json +107 -9
- package/integrations/examples/claude-agent-sdk/memory-agent.ts +2 -0
- package/integrations/examples/langchain/memory-chain.py +4 -0
- package/integrations/examples/openai-agents-sdk/memory-agent.py +4 -0
- package/package.json +12 -3
- package/src/activity-counter.ts +1 -0
- package/src/adaptive-retrieval.ts +23 -0
- package/src/api-server.ts +13 -11
- package/src/asset-sync.ts +26 -2
- package/src/audit-log.ts +2 -0
- package/src/auto-gc.ts +4 -3
- package/src/belief-history.ts +137 -31
- package/src/capture-engine.ts +459 -71
- package/src/cascade-forget.ts +7 -3
- package/src/checkpoint-mirror.ts +417 -0
- package/src/cli.ts +574 -54
- package/src/conflict-engine.ts +43 -15
- package/src/consolidation-engine.ts +24 -3
- package/src/context-collapse-renderer.ts +8 -1
- package/src/context-composer-stable.ts +5 -1
- package/src/context-composer.ts +11 -2
- package/src/distill-lock.ts +246 -74
- package/src/dream-pipeline.ts +3 -1
- package/src/embedder.ts +24 -0
- package/src/env-config.ts +136 -0
- package/src/flock.ts +97 -0
- package/src/forget-engine.ts +342 -58
- package/src/gateway-server.ts +4 -0
- package/src/ingest-plan.ts +56 -0
- package/src/ingest.ts +294 -121
- package/src/kg-contradiction.ts +753 -0
- package/src/kg-extractor.ts +17 -0
- package/src/kg-store.ts +1 -1
- package/src/known-item-eval.ts +455 -0
- package/src/llm-client.ts +13 -26
- package/src/llm-consolidation.ts +2 -2
- package/src/mcp-tool-deps.ts +6 -0
- package/src/mcp-tools-advanced.ts +80 -45
- package/src/mcp-tools-core.ts +23 -17
- package/src/mcp-tools-governance.ts +13 -7
- package/src/memory-assets.ts +144 -8
- package/src/memory-boundaries.ts +19 -0
- package/src/memory-evolution.ts +9 -0
- package/src/memory-lint.ts +1 -1
- package/src/memory-output.ts +311 -14
- package/src/memory-reconcile.ts +1437 -0
- package/src/memory-schema.ts +11 -0
- package/src/memory-store-port.ts +1 -0
- package/src/minis-archive.ts +151 -0
- package/src/noise-filter.ts +15 -2
- package/src/pii-detector.ts +31 -1
- package/src/pivot-apply.ts +55 -5
- package/src/pivot-evidence.ts +128 -0
- package/src/ppr-traversal.ts +25 -1
- package/src/preference-matcher.ts +40 -28
- package/src/prospective-memory.ts +7 -4
- package/src/retriever.ts +297 -57
- package/src/retroactive-boost.ts +3 -2
- package/src/runtime-config.ts +15 -1
- package/src/scope-policy.ts +1 -0
- package/src/session-distiller.ts +6 -2
- package/src/session-engine.ts +11 -4
- package/src/session-output.ts +20 -1
- package/src/session-schema.ts +5 -2
- package/src/session-store.ts +59 -12
- package/src/skill-promotion.ts +67 -1
- package/src/store-receipts.ts +109 -0
- package/src/store-write-budget.ts +37 -0
- package/src/store.ts +298 -57
- package/src/text-fingerprint.ts +25 -0
- package/src/trigger-store.ts +443 -0
- package/src/ui-server.ts +22 -21
- package/src/version-manager.ts +19 -5
- package/src/write-verifier.ts +16 -11
- 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,282 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
buildStructuredMemoryBoundary,
|
|
5
|
-
buildDefaultCanonicalKey,
|
|
6
|
-
extractBoundaryMetadata,
|
|
7
|
-
extractMemoryProvenance,
|
|
8
|
-
extractPromotedFrom,
|
|
9
|
-
extractProvenanceHistory,
|
|
10
|
-
extractProvenanceHistoryCount,
|
|
11
|
-
resolveIngestBoundary,
|
|
12
|
-
shouldUseStableMemoryResult,
|
|
13
|
-
} from "../memory-boundaries.js";
|
|
14
|
-
|
|
15
|
-
describe("memory boundaries", () => {
|
|
16
|
-
it("downgrades transcript-derived profile facts into evidence events", () => {
|
|
17
|
-
const resolved = resolveIngestBoundary({
|
|
18
|
-
source: "cc",
|
|
19
|
-
scope: "cc:abc123",
|
|
20
|
-
category: "profile",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(resolved.category).toBe("events");
|
|
24
|
-
expect(resolved.boundary.layer).toBe("evidence");
|
|
25
|
-
expect(resolved.boundary.authority).toBe("transcript-ingest");
|
|
26
|
-
expect(resolved.boundary.downgradedFrom).toBe("profile");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// 端清单回归:memory-boundaries.ts 的 TRANSCRIPT_SOURCES / TRANSCRIPT_SCOPE_PREFIXES
|
|
30
|
-
// 历史上漏过两次(kimi 2026-07-19 进栈、antigravity 07-29 进栈,都到 08-01 才发现)。
|
|
31
|
-
// 根因不是"忘了改",是**没有断言**——纯判断步骤没有测试撑着就会被跳过。
|
|
32
|
-
// ⚠️ 接入新端时:先在下面的清单里加一行让测试变红,再去改常量把它变绿。
|
|
33
|
-
it.each([
|
|
34
|
-
["cc", "cc:abc123"],
|
|
35
|
-
["codex", "codex:abc123"],
|
|
36
|
-
["gemini", "gemini:abc123"],
|
|
37
|
-
["kimi", "kimi:abc123"],
|
|
38
|
-
["antigravity", "antigravity:abc123"],
|
|
39
|
-
["minis", "minis:abc123"],
|
|
40
|
-
])("downgrades transcript profile facts for end %s", (source, scope) => {
|
|
41
|
-
const resolved = resolveIngestBoundary({ source, scope, category: "profile" });
|
|
42
|
-
|
|
43
|
-
expect(resolved.boundary.layer).toBe("evidence");
|
|
44
|
-
expect(resolved.boundary.authority).toBe("transcript-ingest");
|
|
45
|
-
expect(resolved.category).toBe("events");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// 反向断言:确认上面那组不是同义反复(如果任何 source 都被降权,那组测试就永远绿、
|
|
49
|
-
// 等于没测)。一个不在清单里的来源必须**不**被当成 transcript。
|
|
50
|
-
it("does not downgrade sources outside the transcript end list", () => {
|
|
51
|
-
const resolved = resolveIngestBoundary({
|
|
52
|
-
source: "manual",
|
|
53
|
-
scope: "memory:pivot",
|
|
54
|
-
category: "profile",
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
expect(resolved.boundary.layer).not.toBe("evidence");
|
|
58
|
-
expect(resolved.category).toBe("profile");
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("keeps transcript cases searchable but marks them as evidence", () => {
|
|
62
|
-
const resolved = resolveIngestBoundary({
|
|
63
|
-
source: "codex",
|
|
64
|
-
scope: "codex:session1",
|
|
65
|
-
category: "cases",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(resolved.category).toBe("cases");
|
|
69
|
-
expect(resolved.boundary.layer).toBe("evidence");
|
|
70
|
-
expect(resolved.boundary.authority).toBe("transcript-ingest");
|
|
71
|
-
expect(resolved.boundary.originalCategory).toBe("cases");
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("marks structured memory as durable authority", () => {
|
|
75
|
-
const boundary = buildStructuredMemoryBoundary("preferences");
|
|
76
|
-
|
|
77
|
-
expect(boundary).toEqual({
|
|
78
|
-
layer: "durable",
|
|
79
|
-
authority: "structured-memory",
|
|
80
|
-
conflictPolicy: "latest-wins",
|
|
81
|
-
originalCategory: "preferences",
|
|
82
|
-
note: "Structured memory writes are the durable source inside RecallNest.",
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("builds slot-aware canonical keys for atomic brand-item preferences", () => {
|
|
87
|
-
expect(buildDefaultCanonicalKey({
|
|
88
|
-
category: "preferences",
|
|
89
|
-
text: "我喜欢吃麦当劳的麦辣鸡翅",
|
|
90
|
-
})).toBe("preferences:brand-item:麦当劳:麦辣鸡翅");
|
|
91
|
-
|
|
92
|
-
expect(buildDefaultCanonicalKey({
|
|
93
|
-
category: "preferences",
|
|
94
|
-
text: "User prefers concise, direct replies.",
|
|
95
|
-
})).toBe("preferences:reply-style:concise:direct");
|
|
96
|
-
|
|
97
|
-
expect(buildDefaultCanonicalKey({
|
|
98
|
-
category: "preferences",
|
|
99
|
-
text: "Uses Bun over Node.",
|
|
100
|
-
})).toBe("preferences:tool-choice:bun:over:node");
|
|
101
|
-
|
|
102
|
-
expect(buildDefaultCanonicalKey({
|
|
103
|
-
category: "preferences",
|
|
104
|
-
text: "我喜欢吃麦当劳的麦旋风、板烧鸡腿堡和麦辣鸡翅",
|
|
105
|
-
})).toBe("preferences:我喜欢吃麦当劳的麦旋风-板烧鸡腿堡和麦辣鸡翅");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("builds distinct canonical keys for different implicit-usage preferences (#6 regression)", () => {
|
|
109
|
-
// 修复前 implicit-usage slot 无专属分支,落到 tool-choice 三元支、preferredTool/avoidedTool
|
|
110
|
-
// 均 undefined → 全部坍缩成 'preferences:implicit-usage:over',不同隐式偏好在 latest-wins
|
|
111
|
-
// 下互相覆盖丢数据。现在用 slot.subject 区分。
|
|
112
|
-
const figma = buildDefaultCanonicalKey({ category: "preferences", text: "I use Figma for design" });
|
|
113
|
-
const python = buildDefaultCanonicalKey({ category: "preferences", text: "I use Python for scripting" });
|
|
114
|
-
const sony = buildDefaultCanonicalKey({ category: "preferences", text: "我有一台索尼相机" });
|
|
115
|
-
|
|
116
|
-
expect(figma).toBe("preferences:implicit-usage:figma");
|
|
117
|
-
expect(python).toBe("preferences:implicit-usage:python");
|
|
118
|
-
expect(new Set([figma, python, sony]).size).toBe(3);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("rejects transcript/evidence stable recall and keeps durable stable recall", () => {
|
|
122
|
-
expect(shouldUseStableMemoryResult({
|
|
123
|
-
category: "preferences",
|
|
124
|
-
scope: "cc:session",
|
|
125
|
-
metadata: JSON.stringify({
|
|
126
|
-
boundary: {
|
|
127
|
-
layer: "evidence",
|
|
128
|
-
authority: "transcript-ingest",
|
|
129
|
-
conflictPolicy: "append-only",
|
|
130
|
-
},
|
|
131
|
-
}),
|
|
132
|
-
})).toBe(false);
|
|
133
|
-
|
|
134
|
-
expect(shouldUseStableMemoryResult({
|
|
135
|
-
category: "preferences",
|
|
136
|
-
scope: "memory:agent",
|
|
137
|
-
metadata: JSON.stringify({
|
|
138
|
-
boundary: buildStructuredMemoryBoundary("preferences"),
|
|
139
|
-
}),
|
|
140
|
-
})).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("parses valid boundary metadata and ignores malformed payloads", () => {
|
|
144
|
-
expect(extractBoundaryMetadata(JSON.stringify({
|
|
145
|
-
boundary: buildStructuredMemoryBoundary("patterns"),
|
|
146
|
-
}))).toEqual(buildStructuredMemoryBoundary("patterns"));
|
|
147
|
-
|
|
148
|
-
expect(extractBoundaryMetadata("{not-json")).toBeNull();
|
|
149
|
-
expect(extractBoundaryMetadata(JSON.stringify({
|
|
150
|
-
boundary: { layer: "durable", authority: "oops" },
|
|
151
|
-
}))).toBeNull();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("extracts promotedFrom provenance and canonical keys", () => {
|
|
155
|
-
const metadata = JSON.stringify({
|
|
156
|
-
canonicalKey: "user-reply-style",
|
|
157
|
-
boundary: buildStructuredMemoryBoundary("preferences"),
|
|
158
|
-
promotedFrom: {
|
|
159
|
-
memoryId: "12345678-1234-1234-1234-123456789abc",
|
|
160
|
-
scope: "cc:session1",
|
|
161
|
-
category: "events",
|
|
162
|
-
source: "cc",
|
|
163
|
-
boundary: {
|
|
164
|
-
layer: "evidence",
|
|
165
|
-
authority: "transcript-ingest",
|
|
166
|
-
conflictPolicy: "append-only",
|
|
167
|
-
originalCategory: "preferences",
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
expect(extractPromotedFrom(metadata)).toEqual({
|
|
173
|
-
memoryId: "12345678-1234-1234-1234-123456789abc",
|
|
174
|
-
scope: "cc:session1",
|
|
175
|
-
category: "events",
|
|
176
|
-
source: "cc",
|
|
177
|
-
boundary: {
|
|
178
|
-
layer: "evidence",
|
|
179
|
-
authority: "transcript-ingest",
|
|
180
|
-
conflictPolicy: "append-only",
|
|
181
|
-
originalCategory: "preferences",
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
expect(extractProvenanceHistory(metadata)).toEqual([{
|
|
186
|
-
memoryId: "12345678-1234-1234-1234-123456789abc",
|
|
187
|
-
scope: "cc:session1",
|
|
188
|
-
category: "events",
|
|
189
|
-
source: "cc",
|
|
190
|
-
boundary: {
|
|
191
|
-
layer: "evidence",
|
|
192
|
-
authority: "transcript-ingest",
|
|
193
|
-
conflictPolicy: "append-only",
|
|
194
|
-
originalCategory: "preferences",
|
|
195
|
-
},
|
|
196
|
-
}]);
|
|
197
|
-
expect(extractProvenanceHistoryCount(metadata)).toBe(1);
|
|
198
|
-
|
|
199
|
-
expect(extractMemoryProvenance({
|
|
200
|
-
scope: "memory:agent",
|
|
201
|
-
metadata,
|
|
202
|
-
})).toEqual({
|
|
203
|
-
boundary: buildStructuredMemoryBoundary("preferences"),
|
|
204
|
-
canonicalKey: "user-reply-style",
|
|
205
|
-
promotedFrom: {
|
|
206
|
-
memoryId: "12345678-1234-1234-1234-123456789abc",
|
|
207
|
-
scope: "cc:session1",
|
|
208
|
-
category: "events",
|
|
209
|
-
source: "cc",
|
|
210
|
-
boundary: {
|
|
211
|
-
layer: "evidence",
|
|
212
|
-
authority: "transcript-ingest",
|
|
213
|
-
conflictPolicy: "append-only",
|
|
214
|
-
originalCategory: "preferences",
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
provenanceHistory: [{
|
|
218
|
-
memoryId: "12345678-1234-1234-1234-123456789abc",
|
|
219
|
-
scope: "cc:session1",
|
|
220
|
-
category: "events",
|
|
221
|
-
source: "cc",
|
|
222
|
-
boundary: {
|
|
223
|
-
layer: "evidence",
|
|
224
|
-
authority: "transcript-ingest",
|
|
225
|
-
conflictPolicy: "append-only",
|
|
226
|
-
originalCategory: "preferences",
|
|
227
|
-
},
|
|
228
|
-
}],
|
|
229
|
-
provenanceHistoryCount: 1,
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("prefers explicit provenance history over fallback promotedFrom metadata", () => {
|
|
234
|
-
const metadata = JSON.stringify({
|
|
235
|
-
canonicalKey: "preferences:brand-item:麦当劳:麦辣鸡翅",
|
|
236
|
-
boundary: buildStructuredMemoryBoundary("preferences"),
|
|
237
|
-
promotedFrom: {
|
|
238
|
-
memoryId: "12345678-1234-1234-1234-123456789abc",
|
|
239
|
-
scope: "cc:session1",
|
|
240
|
-
category: "events",
|
|
241
|
-
source: "cc",
|
|
242
|
-
},
|
|
243
|
-
provenanceHistory: [
|
|
244
|
-
{
|
|
245
|
-
memoryId: "aaaaaaaa-1234-1234-1234-123456789abc",
|
|
246
|
-
scope: "cc:session-food-1",
|
|
247
|
-
category: "events",
|
|
248
|
-
source: "cc",
|
|
249
|
-
observedAt: "2026-03-17T04:00:00.000Z",
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
memoryId: "bbbbbbbb-1234-1234-1234-123456789abc",
|
|
253
|
-
scope: "cc:session-food-2",
|
|
254
|
-
category: "events",
|
|
255
|
-
source: "codex",
|
|
256
|
-
observedAt: "2026-03-17T05:00:00.000Z",
|
|
257
|
-
},
|
|
258
|
-
],
|
|
259
|
-
provenanceHistoryCount: 2,
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
expect(extractProvenanceHistory(metadata)).toEqual([
|
|
263
|
-
{
|
|
264
|
-
memoryId: "aaaaaaaa-1234-1234-1234-123456789abc",
|
|
265
|
-
scope: "cc:session-food-1",
|
|
266
|
-
category: "events",
|
|
267
|
-
source: "cc",
|
|
268
|
-
observedAt: "2026-03-17T04:00:00.000Z",
|
|
269
|
-
boundary: null,
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
memoryId: "bbbbbbbb-1234-1234-1234-123456789abc",
|
|
273
|
-
scope: "cc:session-food-2",
|
|
274
|
-
category: "events",
|
|
275
|
-
source: "codex",
|
|
276
|
-
observedAt: "2026-03-17T05:00:00.000Z",
|
|
277
|
-
boundary: null,
|
|
278
|
-
},
|
|
279
|
-
]);
|
|
280
|
-
expect(extractProvenanceHistoryCount(metadata)).toBe(2);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for Memory Evolution Phase B-2 (Archive Strategy),
|
|
3
|
-
* B-3 (LLM Importance Assessment), and E-1 (Multi-factor Retrieval Scoring).
|
|
4
|
-
*/
|
|
5
|
-
import { describe, expect, test } from "bun:test";
|
|
6
|
-
import {
|
|
7
|
-
parseEvolution,
|
|
8
|
-
computeDecayScore,
|
|
9
|
-
computeUsageAdjustedDecayScore,
|
|
10
|
-
buildArchivedMetadata,
|
|
11
|
-
isActiveMemory,
|
|
12
|
-
patchEvolution,
|
|
13
|
-
type EvolutionMetadata,
|
|
14
|
-
} from "../memory-evolution.js";
|
|
15
|
-
import {
|
|
16
|
-
maybeRunGc,
|
|
17
|
-
resetGcTimestamp,
|
|
18
|
-
DEFAULT_AUTO_GC_CONFIG,
|
|
19
|
-
type AutoGcConfig,
|
|
20
|
-
} from "../auto-gc.js";
|
|
21
|
-
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// B-2: Archive Strategy Tests
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
|
|
26
|
-
describe("B-2: Archive Strategy", () => {
|
|
27
|
-
test("buildArchivedMetadata sets status to archived", () => {
|
|
28
|
-
const meta = JSON.stringify({ evolution: { status: "active", version: 1 } });
|
|
29
|
-
const archived = buildArchivedMetadata(meta);
|
|
30
|
-
const evo = parseEvolution(archived);
|
|
31
|
-
expect(evo.status).toBe("archived");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("archived memory is not active", () => {
|
|
35
|
-
const meta = JSON.stringify({ evolution: { status: "archived", version: 1 } });
|
|
36
|
-
expect(isActiveMemory(meta)).toBe(false);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("active memory is active", () => {
|
|
40
|
-
const meta = JSON.stringify({ evolution: { status: "active", version: 1 } });
|
|
41
|
-
expect(isActiveMemory(meta)).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("auto-gc with evolution system", () => {
|
|
45
|
-
function makeStore(entries: Array<{
|
|
46
|
-
id: string;
|
|
47
|
-
importance: number;
|
|
48
|
-
timestamp: number;
|
|
49
|
-
metadata: string;
|
|
50
|
-
}>) {
|
|
51
|
-
const data = new Map(entries.map(e => [e.id, {
|
|
52
|
-
...e,
|
|
53
|
-
text: "test",
|
|
54
|
-
vector: [1, 0, 0],
|
|
55
|
-
category: "events",
|
|
56
|
-
scope: "project:test",
|
|
57
|
-
}]));
|
|
58
|
-
const updates: Array<{ id: string; metadata: string }> = [];
|
|
59
|
-
return {
|
|
60
|
-
store: {
|
|
61
|
-
stats: async () => ({ totalCount: data.size, scopeCounts: {}, categoryCounts: {} }),
|
|
62
|
-
repairSingletonVersionGroups: async () => 0,
|
|
63
|
-
list: async () => Array.from(data.values()),
|
|
64
|
-
listPage: async (opts: { limit?: number; offset?: number } = {}) => {
|
|
65
|
-
const { limit = 1000, offset = 0 } = opts;
|
|
66
|
-
return Array.from(data.values()).slice(offset, offset + limit);
|
|
67
|
-
},
|
|
68
|
-
update: async (id: string, patch: { metadata: string }) => {
|
|
69
|
-
updates.push({ id, metadata: patch.metadata });
|
|
70
|
-
const entry = data.get(id);
|
|
71
|
-
if (!entry) return null;
|
|
72
|
-
entry.metadata = patch.metadata;
|
|
73
|
-
return entry;
|
|
74
|
-
},
|
|
75
|
-
// 2026-08-14 auto-gc 批量归档通道:以 data 最新行起底应用 patchFn(生产语义)
|
|
76
|
-
patchMetadataBatch: async (
|
|
77
|
-
patches: Array<{ id: string; patchFn: (meta: Record<string, unknown>, entry: unknown) => Record<string, unknown> }>,
|
|
78
|
-
) => {
|
|
79
|
-
let written = 0;
|
|
80
|
-
for (const { id, patchFn } of patches) {
|
|
81
|
-
const entry = data.get(id);
|
|
82
|
-
if (!entry) continue;
|
|
83
|
-
let meta: Record<string, unknown>;
|
|
84
|
-
try { meta = JSON.parse(entry.metadata || "{}") as Record<string, unknown>; } catch { meta = {}; }
|
|
85
|
-
entry.metadata = JSON.stringify(patchFn(meta, entry));
|
|
86
|
-
updates.push({ id, metadata: entry.metadata });
|
|
87
|
-
written++;
|
|
88
|
-
}
|
|
89
|
-
return written;
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
updates,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
test("archives low-decay-score memories", async () => {
|
|
97
|
-
resetGcTimestamp();
|
|
98
|
-
const now = Date.now();
|
|
99
|
-
const oldTimestamp = now - 120 * 86_400_000; // 120 days ago
|
|
100
|
-
const activeMeta = JSON.stringify({
|
|
101
|
-
evolution: {
|
|
102
|
-
status: "active",
|
|
103
|
-
version: 1,
|
|
104
|
-
accessCount: 0,
|
|
105
|
-
lastAccessedAt: null,
|
|
106
|
-
validFrom: oldTimestamp,
|
|
107
|
-
validUntil: null,
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const { store, updates } = makeStore([
|
|
112
|
-
{ id: "old-low", importance: 0.1, timestamp: oldTimestamp, metadata: activeMeta },
|
|
113
|
-
]);
|
|
114
|
-
|
|
115
|
-
const config: AutoGcConfig = {
|
|
116
|
-
...DEFAULT_AUTO_GC_CONFIG,
|
|
117
|
-
minMemoryCount: 1,
|
|
118
|
-
minHoursSinceLastGc: 0,
|
|
119
|
-
decayScoreThreshold: 0.2,
|
|
120
|
-
minAgeDays: 30,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const result = await maybeRunGc(store as any, config);
|
|
124
|
-
expect(result.triggered).toBe(true);
|
|
125
|
-
expect(result.archivedCount).toBe(1);
|
|
126
|
-
expect(updates.length).toBe(1);
|
|
127
|
-
|
|
128
|
-
const archivedEvo = parseEvolution(updates[0].metadata);
|
|
129
|
-
expect(archivedEvo.status).toBe("archived");
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test("skips pinned memories (importance >= 0.95)", async () => {
|
|
133
|
-
resetGcTimestamp();
|
|
134
|
-
const now = Date.now();
|
|
135
|
-
const oldTimestamp = now - 120 * 86_400_000;
|
|
136
|
-
const activeMeta = JSON.stringify({
|
|
137
|
-
evolution: {
|
|
138
|
-
status: "active",
|
|
139
|
-
version: 1,
|
|
140
|
-
accessCount: 0,
|
|
141
|
-
lastAccessedAt: null,
|
|
142
|
-
validFrom: oldTimestamp,
|
|
143
|
-
validUntil: null,
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const { store, updates } = makeStore([
|
|
148
|
-
{ id: "pinned", importance: 0.95, timestamp: oldTimestamp, metadata: activeMeta },
|
|
149
|
-
]);
|
|
150
|
-
|
|
151
|
-
const config: AutoGcConfig = {
|
|
152
|
-
...DEFAULT_AUTO_GC_CONFIG,
|
|
153
|
-
minMemoryCount: 1,
|
|
154
|
-
minHoursSinceLastGc: 0,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const result = await maybeRunGc(store as any, config);
|
|
158
|
-
expect(result.triggered).toBe(true);
|
|
159
|
-
expect(result.archivedCount).toBe(0);
|
|
160
|
-
expect(updates.length).toBe(0);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test("usage-adjusted GC is gated and can archive cold high-frequency memories", async () => {
|
|
164
|
-
const savedUsageDecay = process.env.RECALLNEST_USAGE_DECAY;
|
|
165
|
-
const savedConstructive = process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL;
|
|
166
|
-
try {
|
|
167
|
-
const now = Date.now();
|
|
168
|
-
const oldTimestamp = now - 180 * 86_400_000;
|
|
169
|
-
const coldMeta = JSON.stringify({
|
|
170
|
-
accessCount: 10,
|
|
171
|
-
evolution: {
|
|
172
|
-
status: "active",
|
|
173
|
-
version: 1,
|
|
174
|
-
accessCount: 10,
|
|
175
|
-
lastAccessedAt: now,
|
|
176
|
-
validFrom: oldTimestamp,
|
|
177
|
-
validUntil: null,
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
const config: AutoGcConfig = {
|
|
181
|
-
...DEFAULT_AUTO_GC_CONFIG,
|
|
182
|
-
minMemoryCount: 1,
|
|
183
|
-
minHoursSinceLastGc: 0,
|
|
184
|
-
decayScoreThreshold: 0.15,
|
|
185
|
-
minAgeDays: 30,
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
delete process.env.RECALLNEST_USAGE_DECAY;
|
|
189
|
-
delete process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL;
|
|
190
|
-
resetGcTimestamp();
|
|
191
|
-
const withoutFlag = makeStore([
|
|
192
|
-
{ id: "cold-no-flag", importance: 0.05, timestamp: oldTimestamp, metadata: coldMeta },
|
|
193
|
-
]);
|
|
194
|
-
const baseline = await maybeRunGc(withoutFlag.store as any, config);
|
|
195
|
-
expect(baseline.archivedCount).toBe(0);
|
|
196
|
-
expect(withoutFlag.updates).toHaveLength(0);
|
|
197
|
-
|
|
198
|
-
process.env.RECALLNEST_USAGE_DECAY = "true";
|
|
199
|
-
process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL = "true";
|
|
200
|
-
resetGcTimestamp();
|
|
201
|
-
const withFlag = makeStore([
|
|
202
|
-
{ id: "cold-with-flag", importance: 0.05, timestamp: oldTimestamp, metadata: coldMeta },
|
|
203
|
-
]);
|
|
204
|
-
const adjusted = await maybeRunGc(withFlag.store as any, config);
|
|
205
|
-
expect(adjusted.archivedCount).toBe(1);
|
|
206
|
-
expect(withFlag.updates).toHaveLength(1);
|
|
207
|
-
} finally {
|
|
208
|
-
if (savedUsageDecay === undefined) delete process.env.RECALLNEST_USAGE_DECAY;
|
|
209
|
-
else process.env.RECALLNEST_USAGE_DECAY = savedUsageDecay;
|
|
210
|
-
if (savedConstructive === undefined) delete process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL;
|
|
211
|
-
else process.env.RECALLNEST_CONSTRUCTIVE_RETRIEVAL = savedConstructive;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test("skips recently created memories", async () => {
|
|
216
|
-
resetGcTimestamp();
|
|
217
|
-
const recentMeta = JSON.stringify({
|
|
218
|
-
evolution: {
|
|
219
|
-
status: "active",
|
|
220
|
-
version: 1,
|
|
221
|
-
accessCount: 0,
|
|
222
|
-
lastAccessedAt: null,
|
|
223
|
-
validFrom: Date.now(),
|
|
224
|
-
validUntil: null,
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
const { store, updates } = makeStore([
|
|
229
|
-
{ id: "recent", importance: 0.1, timestamp: Date.now(), metadata: recentMeta },
|
|
230
|
-
]);
|
|
231
|
-
|
|
232
|
-
const config: AutoGcConfig = {
|
|
233
|
-
...DEFAULT_AUTO_GC_CONFIG,
|
|
234
|
-
minMemoryCount: 1,
|
|
235
|
-
minHoursSinceLastGc: 0,
|
|
236
|
-
minAgeDays: 30,
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
const result = await maybeRunGc(store as any, config);
|
|
240
|
-
expect(result.triggered).toBe(true);
|
|
241
|
-
expect(result.archivedCount).toBe(0);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test("does not trigger when below memory threshold", async () => {
|
|
245
|
-
resetGcTimestamp();
|
|
246
|
-
const { store } = makeStore([
|
|
247
|
-
{ id: "one", importance: 0.1, timestamp: Date.now() - 90 * 86_400_000, metadata: "{}" },
|
|
248
|
-
]);
|
|
249
|
-
|
|
250
|
-
const result = await maybeRunGc(store as any, {
|
|
251
|
-
...DEFAULT_AUTO_GC_CONFIG,
|
|
252
|
-
minMemoryCount: 1000,
|
|
253
|
-
});
|
|
254
|
-
expect(result.triggered).toBe(false);
|
|
255
|
-
expect(result.reason).toBe("below_memory_threshold");
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// ---------------------------------------------------------------------------
|
|
261
|
-
// E-1: Access Count Boost Tests (via computeDecayScore)
|
|
262
|
-
// ---------------------------------------------------------------------------
|
|
263
|
-
|
|
264
|
-
describe("E-1: Multi-factor Retrieval Scoring", () => {
|
|
265
|
-
test("higher accessCount produces higher decay score", () => {
|
|
266
|
-
const base: EvolutionMetadata = {
|
|
267
|
-
status: "active",
|
|
268
|
-
version: 1,
|
|
269
|
-
accessCount: 0,
|
|
270
|
-
lastAccessedAt: null,
|
|
271
|
-
supersededBy: null,
|
|
272
|
-
consolidatedInto: null,
|
|
273
|
-
sourceMemories: [],
|
|
274
|
-
validFrom: Date.now() - 30 * 86_400_000,
|
|
275
|
-
validUntil: null,
|
|
276
|
-
};
|
|
277
|
-
const lowAccess = computeDecayScore(base, 0.5);
|
|
278
|
-
const highAccess = computeDecayScore({ ...base, accessCount: 10, lastAccessedAt: Date.now() }, 0.5);
|
|
279
|
-
expect(highAccess).toBeGreaterThan(lowAccess);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
test("higher importance produces higher decay score", () => {
|
|
283
|
-
const base: EvolutionMetadata = {
|
|
284
|
-
status: "active",
|
|
285
|
-
version: 1,
|
|
286
|
-
accessCount: 2,
|
|
287
|
-
lastAccessedAt: Date.now() - 86_400_000,
|
|
288
|
-
supersededBy: null,
|
|
289
|
-
consolidatedInto: null,
|
|
290
|
-
sourceMemories: [],
|
|
291
|
-
validFrom: Date.now() - 30 * 86_400_000,
|
|
292
|
-
validUntil: null,
|
|
293
|
-
};
|
|
294
|
-
const lowImportance = computeDecayScore(base, 0.3);
|
|
295
|
-
const highImportance = computeDecayScore(base, 0.9);
|
|
296
|
-
expect(highImportance).toBeGreaterThan(lowImportance);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
test("older memories without access have lower decay scores", () => {
|
|
300
|
-
const recent: EvolutionMetadata = {
|
|
301
|
-
status: "active",
|
|
302
|
-
version: 1,
|
|
303
|
-
accessCount: 0,
|
|
304
|
-
lastAccessedAt: null,
|
|
305
|
-
supersededBy: null,
|
|
306
|
-
consolidatedInto: null,
|
|
307
|
-
sourceMemories: [],
|
|
308
|
-
validFrom: Date.now() - 7 * 86_400_000,
|
|
309
|
-
validUntil: null,
|
|
310
|
-
};
|
|
311
|
-
const old: EvolutionMetadata = {
|
|
312
|
-
...recent,
|
|
313
|
-
validFrom: Date.now() - 180 * 86_400_000,
|
|
314
|
-
};
|
|
315
|
-
expect(computeDecayScore(recent, 0.5)).toBeGreaterThan(computeDecayScore(old, 0.5));
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
describe("P0 B-2: usage-adjusted GC scoring", () => {
|
|
320
|
-
const now = Date.now();
|
|
321
|
-
const oldColdEvo: EvolutionMetadata = {
|
|
322
|
-
status: "active",
|
|
323
|
-
version: 1,
|
|
324
|
-
accessCount: 10,
|
|
325
|
-
lastAccessedAt: now,
|
|
326
|
-
supersededBy: null,
|
|
327
|
-
supersedes: null,
|
|
328
|
-
evolutionNote: null,
|
|
329
|
-
consolidatedInto: null,
|
|
330
|
-
contributedToPattern: null,
|
|
331
|
-
sourceMemories: [],
|
|
332
|
-
validFrom: now - 180 * 86_400_000,
|
|
333
|
-
validUntil: null,
|
|
334
|
-
eventTime: null,
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
test("discounts frequency only for cold memories in GC scoring", () => {
|
|
338
|
-
const metadata = JSON.stringify({ accessCount: 10 });
|
|
339
|
-
const base = computeDecayScore(oldColdEvo, 0.05, now, metadata);
|
|
340
|
-
const adjusted = computeUsageAdjustedDecayScore(oldColdEvo, 0.05, now, metadata);
|
|
341
|
-
|
|
342
|
-
expect(base).toBeGreaterThan(0.15);
|
|
343
|
-
expect(adjusted).toBeLessThan(base);
|
|
344
|
-
expect(adjusted).toBeLessThan(0.15);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
test("does not discount pending reminders or promoted memories", () => {
|
|
348
|
-
const pendingReminder = JSON.stringify({
|
|
349
|
-
accessCount: 10,
|
|
350
|
-
prospective: { status: "pending" },
|
|
351
|
-
});
|
|
352
|
-
const promoted = JSON.stringify({
|
|
353
|
-
accessCount: 10,
|
|
354
|
-
promotedTo: "memory:durable-target",
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
expect(computeUsageAdjustedDecayScore(oldColdEvo, 0.05, now, pendingReminder))
|
|
358
|
-
.toBe(computeDecayScore(oldColdEvo, 0.05, now, pendingReminder));
|
|
359
|
-
expect(computeUsageAdjustedDecayScore(oldColdEvo, 0.05, now, promoted))
|
|
360
|
-
.toBe(computeDecayScore(oldColdEvo, 0.05, now, promoted));
|
|
361
|
-
});
|
|
362
|
-
});
|