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,283 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "bun:test";
|
|
2
|
-
import { computeHotnessScore, parseAccessMetadata } from "../access-tracker.js";
|
|
3
|
-
import { TraceCollector } from "../retrieval-trace.js";
|
|
4
|
-
import {
|
|
5
|
-
createRetriever,
|
|
6
|
-
DEFAULT_CATEGORY_MIN_SCORES,
|
|
7
|
-
} from "../retriever.js";
|
|
8
|
-
|
|
9
|
-
function applyHotnessBlend(
|
|
10
|
-
score: number,
|
|
11
|
-
accessCount: number,
|
|
12
|
-
lastAccessedAt: number,
|
|
13
|
-
): number {
|
|
14
|
-
const retriever = createRetriever({} as any, {} as any, { hotnessWeight: 0.15 });
|
|
15
|
-
retriever.setAccessTracker({} as any);
|
|
16
|
-
const results = [{
|
|
17
|
-
entry: {
|
|
18
|
-
id: "hotness-test",
|
|
19
|
-
text: "hotness test",
|
|
20
|
-
vector: [],
|
|
21
|
-
category: "events",
|
|
22
|
-
scope: "test:hotness",
|
|
23
|
-
importance: 0.5,
|
|
24
|
-
timestamp: Date.now(),
|
|
25
|
-
metadata: JSON.stringify({ accessCount, lastAccessedAt }),
|
|
26
|
-
},
|
|
27
|
-
score,
|
|
28
|
-
sources: {},
|
|
29
|
-
}];
|
|
30
|
-
return (retriever as any).applyHotnessBlend(results)[0].score;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe("computeHotnessScore", () => {
|
|
34
|
-
it("returns 0 for zero accesses", () => {
|
|
35
|
-
expect(computeHotnessScore(0, Date.now())).toBe(0);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("returns positive score for accessed memories", () => {
|
|
39
|
-
const score = computeHotnessScore(5, Date.now());
|
|
40
|
-
expect(score).toBeGreaterThan(0);
|
|
41
|
-
expect(score).toBeLessThanOrEqual(1);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("higher access count yields higher score", () => {
|
|
45
|
-
const now = Date.now();
|
|
46
|
-
const low = computeHotnessScore(1, now);
|
|
47
|
-
const mid = computeHotnessScore(5, now);
|
|
48
|
-
const high = computeHotnessScore(50, now);
|
|
49
|
-
expect(low).toBeLessThan(mid);
|
|
50
|
-
expect(mid).toBeLessThan(high);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("recent access yields higher score than old access", () => {
|
|
54
|
-
const now = Date.now();
|
|
55
|
-
const recent = computeHotnessScore(5, now);
|
|
56
|
-
const weekAgo = computeHotnessScore(5, now - 7 * 86_400_000);
|
|
57
|
-
const monthAgo = computeHotnessScore(5, now - 30 * 86_400_000);
|
|
58
|
-
expect(recent).toBeGreaterThan(weekAgo);
|
|
59
|
-
expect(weekAgo).toBeGreaterThan(monthAgo);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("decays to near-zero for very old accesses", () => {
|
|
63
|
-
const score = computeHotnessScore(5, Date.now() - 365 * 86_400_000);
|
|
64
|
-
expect(score).toBeLessThan(0.01);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("caps at 1.0 even with extreme access counts", () => {
|
|
68
|
-
const score = computeHotnessScore(10_000, Date.now());
|
|
69
|
-
expect(score).toBeLessThanOrEqual(1.0);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("respects custom decay rate", () => {
|
|
73
|
-
const now = Date.now();
|
|
74
|
-
const fast = computeHotnessScore(5, now - 7 * 86_400_000, 0.5);
|
|
75
|
-
const slow = computeHotnessScore(5, now - 7 * 86_400_000, 0.01);
|
|
76
|
-
expect(slow).toBeGreaterThan(fast);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("parseAccessMetadata", () => {
|
|
81
|
-
it("parses valid metadata", () => {
|
|
82
|
-
const meta = JSON.stringify({ accessCount: 5, lastAccessedAt: 1234567890 });
|
|
83
|
-
const result = parseAccessMetadata(meta);
|
|
84
|
-
expect(result.accessCount).toBe(5);
|
|
85
|
-
expect(result.lastAccessedAt).toBe(1234567890);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("returns defaults for missing fields", () => {
|
|
89
|
-
const result = parseAccessMetadata("{}");
|
|
90
|
-
expect(result.accessCount).toBe(0);
|
|
91
|
-
expect(result.lastAccessedAt).toBe(0);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("handles undefined input", () => {
|
|
95
|
-
const result = parseAccessMetadata(undefined);
|
|
96
|
-
expect(result.accessCount).toBe(0);
|
|
97
|
-
expect(result.lastAccessedAt).toBe(0);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("handles malformed JSON", () => {
|
|
101
|
-
const result = parseAccessMetadata("not-json");
|
|
102
|
-
expect(result.accessCount).toBe(0);
|
|
103
|
-
expect(result.lastAccessedAt).toBe(0);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("applyHotnessBlend", () => {
|
|
108
|
-
it("does not penalize a zero-access row", () => {
|
|
109
|
-
expect(applyHotnessBlend(0.6, 0, 0)).toBe(0.6);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("preserves the existing blend formula for an accessed row", () => {
|
|
113
|
-
const futureAccess = Date.now() + 60_000;
|
|
114
|
-
const hotness = computeHotnessScore(5, futureAccess);
|
|
115
|
-
expect(applyHotnessBlend(0.6, 5, futureAccess)).toBeCloseTo(
|
|
116
|
-
0.6 * 0.85 + hotness * 0.15,
|
|
117
|
-
12,
|
|
118
|
-
);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("still applies the existing penalty when an accessed row's hotness decays to zero", () => {
|
|
122
|
-
expect(computeHotnessScore(1, 1)).toBe(0);
|
|
123
|
-
expect(applyHotnessBlend(0.6, 1, 1)).toBeCloseTo(0.6 * 0.85, 12);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("cold-start hotness pipeline regression", () => {
|
|
128
|
-
it("recalls a78ad478 without dropping control dd05b422", async () => {
|
|
129
|
-
const query = "owner 模型 任务锁 并发 谁在干活 责任层 资源层";
|
|
130
|
-
const now = Date.now();
|
|
131
|
-
const text = `${query} `.repeat(80).slice(0, 1900);
|
|
132
|
-
|
|
133
|
-
expect(text).toHaveLength(1900);
|
|
134
|
-
|
|
135
|
-
function metadata(
|
|
136
|
-
source: "agent" | "manual",
|
|
137
|
-
confidence: number,
|
|
138
|
-
accessCount: number,
|
|
139
|
-
): string {
|
|
140
|
-
const lastAccessedAt = accessCount > 0 ? now : 0;
|
|
141
|
-
|
|
142
|
-
return JSON.stringify({
|
|
143
|
-
source,
|
|
144
|
-
confidence: {
|
|
145
|
-
score: confidence,
|
|
146
|
-
reliability: source === "manual" ? "direct" : "inferred",
|
|
147
|
-
},
|
|
148
|
-
accessCount,
|
|
149
|
-
lastAccessedAt,
|
|
150
|
-
boundary: {
|
|
151
|
-
layer: "durable",
|
|
152
|
-
authority: "structured-memory",
|
|
153
|
-
conflictPolicy: "latest-wins",
|
|
154
|
-
originalCategory: "patterns",
|
|
155
|
-
},
|
|
156
|
-
evolution: {
|
|
157
|
-
status: "active",
|
|
158
|
-
version: 1,
|
|
159
|
-
accessCount,
|
|
160
|
-
lastAccessedAt: accessCount > 0 ? lastAccessedAt : null,
|
|
161
|
-
validFrom: now,
|
|
162
|
-
validUntil: null,
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const candidates = [
|
|
168
|
-
{
|
|
169
|
-
entry: {
|
|
170
|
-
id: "a78ad478",
|
|
171
|
-
text,
|
|
172
|
-
vector: [1, 0, 0],
|
|
173
|
-
category: "patterns",
|
|
174
|
-
scope: "project:hippo-wiki",
|
|
175
|
-
importance: 0.8,
|
|
176
|
-
timestamp: now,
|
|
177
|
-
metadata: metadata("agent", 0.7, 0),
|
|
178
|
-
},
|
|
179
|
-
score: 0.8628,
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
entry: {
|
|
183
|
-
id: "dd05b422",
|
|
184
|
-
text,
|
|
185
|
-
vector: [0.99, 0.01, 0],
|
|
186
|
-
category: "patterns",
|
|
187
|
-
scope: "project:hippo-wiki",
|
|
188
|
-
importance: 0.8,
|
|
189
|
-
timestamp: now,
|
|
190
|
-
metadata: metadata("manual", 0.9, 4),
|
|
191
|
-
},
|
|
192
|
-
score: 0.8579,
|
|
193
|
-
},
|
|
194
|
-
];
|
|
195
|
-
|
|
196
|
-
let vectorSearchCalls = 0;
|
|
197
|
-
|
|
198
|
-
const store = {
|
|
199
|
-
hasFtsSupport: false,
|
|
200
|
-
async vectorSearch(
|
|
201
|
-
_queryVector: number[],
|
|
202
|
-
limit: number,
|
|
203
|
-
minScore: number,
|
|
204
|
-
scopeFilter?: string[],
|
|
205
|
-
) {
|
|
206
|
-
vectorSearchCalls += 1;
|
|
207
|
-
return candidates
|
|
208
|
-
.filter(candidate => candidate.score >= minScore)
|
|
209
|
-
.filter(candidate =>
|
|
210
|
-
!scopeFilter || scopeFilter.includes(candidate.entry.scope),
|
|
211
|
-
)
|
|
212
|
-
.slice(0, limit);
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const embedder = {
|
|
217
|
-
async embedQuery() {
|
|
218
|
-
return [1, 0, 0];
|
|
219
|
-
},
|
|
220
|
-
async embedPassage() {
|
|
221
|
-
return [1, 0, 0];
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const retriever = createRetriever(
|
|
226
|
-
store as any,
|
|
227
|
-
embedder as any,
|
|
228
|
-
{
|
|
229
|
-
mode: "vector",
|
|
230
|
-
rerank: "none",
|
|
231
|
-
candidatePoolSize: 5,
|
|
232
|
-
minScore: 0.3,
|
|
233
|
-
hardMinScore: 0.38,
|
|
234
|
-
recencyHalfLifeDays: 14,
|
|
235
|
-
recencyWeight: 0.15,
|
|
236
|
-
lengthNormAnchor: 700,
|
|
237
|
-
timeDecayHalfLifeDays: 60,
|
|
238
|
-
hotnessWeight: 0.15,
|
|
239
|
-
filterNoise: false,
|
|
240
|
-
enableRIF: false,
|
|
241
|
-
sourceDiversity: 0,
|
|
242
|
-
multiHop: false,
|
|
243
|
-
},
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
retriever.setAccessTracker({
|
|
247
|
-
computeEffectiveHalfLife(baseHalfLife: number) {
|
|
248
|
-
return baseHalfLife;
|
|
249
|
-
},
|
|
250
|
-
recordAccess() {
|
|
251
|
-
throw new Error("pipeline regression must not record access");
|
|
252
|
-
},
|
|
253
|
-
} as any);
|
|
254
|
-
|
|
255
|
-
const trace = new TraceCollector();
|
|
256
|
-
const results = await retriever.retrieve({
|
|
257
|
-
query,
|
|
258
|
-
limit: 5,
|
|
259
|
-
scopeFilter: ["project:hippo-wiki"],
|
|
260
|
-
category: "patterns",
|
|
261
|
-
source: "auto-recall",
|
|
262
|
-
trace,
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
const ids = results.map(result => result.entry.id);
|
|
266
|
-
const cold = results.find(result => result.entry.id === "a78ad478");
|
|
267
|
-
const hardMin = trace
|
|
268
|
-
.finalize(query, "vector")
|
|
269
|
-
.stages.find(stage => stage.name === "hard_min_score");
|
|
270
|
-
|
|
271
|
-
expect(ids).toContain("a78ad478");
|
|
272
|
-
expect(ids).toContain("dd05b422");
|
|
273
|
-
expect(cold?.score).toBeGreaterThanOrEqual(
|
|
274
|
-
DEFAULT_CATEGORY_MIN_SCORES.patterns,
|
|
275
|
-
);
|
|
276
|
-
expect(hardMin).toMatchObject({
|
|
277
|
-
inputCount: 2,
|
|
278
|
-
outputCount: 2,
|
|
279
|
-
droppedCount: 0,
|
|
280
|
-
});
|
|
281
|
-
expect(vectorSearchCalls).toBe(1);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { groupTurnsIntoChunks } from "../ingest.js";
|
|
4
|
-
import { isNoise } from "../noise-filter.js";
|
|
5
|
-
|
|
6
|
-
// P1 defence-in-depth: groupTurnsIntoChunks pre-filters whole turns via
|
|
7
|
-
// filterNoiseTurns BEFORE chunking, but long turns then get split — and the
|
|
8
|
-
// split fragments were never re-checked. A long turn whose tail is orphaned
|
|
9
|
-
// context-JSON therefore leaks severed JSON field-lines as standalone chunks.
|
|
10
|
-
// This guards that no chunk survives as noise, without over-deleting real talk.
|
|
11
|
-
|
|
12
|
-
function userTurn(text: string) {
|
|
13
|
-
return { role: "user" as const, text, timestamp: "2026-05-21T00:00:00Z", sessionId: "s1" };
|
|
14
|
-
}
|
|
15
|
-
function assistantTurn(text: string) {
|
|
16
|
-
return { role: "assistant" as const, text, timestamp: "2026-05-21T00:00:01Z", sessionId: "s1" };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe("groupTurnsIntoChunks — post-split noise filtering (P1)", () => {
|
|
20
|
-
it("drops severed context-JSON fragments produced by splitting a long turn", () => {
|
|
21
|
-
// Real-content opener (passes turn-level filterNoiseTurns), then a long tail
|
|
22
|
-
// of orphaned JSON field-lines that chunking peels into standalone chunks.
|
|
23
|
-
const opener = "我们今天把记忆系统这周的进展过一遍,重点是噪声治理和召回质量的提升。".repeat(8);
|
|
24
|
-
const jsonTail = Array.from(
|
|
25
|
-
{ length: 60 },
|
|
26
|
-
(_, i) => `"time": "2026-05-21T15:${String(i).padStart(2, "0")}:03.796Z",`,
|
|
27
|
-
).join("\n");
|
|
28
|
-
const chunks = groupTurnsIntoChunks([userTurn(`${opener}\n${jsonTail}`)]);
|
|
29
|
-
|
|
30
|
-
expect(chunks.length).toBeGreaterThan(0); // real content survives
|
|
31
|
-
// No chunk may survive as a recognizable noise fragment.
|
|
32
|
-
expect(chunks.every((c) => !isNoise(c.text))).toBe(true);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("keeps a normal long Q&A conversation intact (no over-deletion)", () => {
|
|
36
|
-
const longQuestion = "你帮我想想这个方案怎么落地,我担心几个点没考虑周全,得一起捋一捋。".repeat(20);
|
|
37
|
-
const longAnswer = "可以分三步走,先做最小验证看效果,再逐步扩展覆盖面,最后补回归测试兜底。".repeat(20);
|
|
38
|
-
const chunks = groupTurnsIntoChunks([userTurn(longQuestion), assistantTurn(longAnswer)]);
|
|
39
|
-
|
|
40
|
-
expect(chunks.length).toBeGreaterThan(0);
|
|
41
|
-
expect(chunks.every((c) => !isNoise(c.text))).toBe(true); // real talk not deleted
|
|
42
|
-
expect(chunks.some((c) => c.text.includes("最小验证"))).toBe(true); // content retained
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 每个会话来源的 scope 前缀必须在 memory-boundaries 的清单里登记。
|
|
3
|
-
*
|
|
4
|
-
* 这条约束是承重的,不是整洁问题:TRANSCRIPT_SCOPE_PREFIXES 决定了会话碎片
|
|
5
|
-
* 会不会被降权到 evidence 层。漏登记一个前缀,那个端的 shell 输出就会被当成
|
|
6
|
-
* 「用户说过的话」提炼成 durable 结论——kimi 与 antigravity 就这么漏过
|
|
7
|
-
* (2026-07 进栈,直到 2026-08-01 才发现库里一直被当结论对待)。
|
|
8
|
-
*
|
|
9
|
-
* 所以加新 ingest 源时,这个测试会在你只改了 config.json / cli.ts 却忘了
|
|
10
|
-
* 登记前缀的时候变红。
|
|
11
|
-
*/
|
|
12
|
-
import { describe, expect, it } from "bun:test";
|
|
13
|
-
import { readFileSync } from "node:fs";
|
|
14
|
-
import { join } from "node:path";
|
|
15
|
-
import { isTranscriptIngestSource, isTranscriptScope } from "../memory-boundaries.js";
|
|
16
|
-
|
|
17
|
-
const config = JSON.parse(
|
|
18
|
-
readFileSync(join(import.meta.dir, "..", "..", "config.json"), "utf8"),
|
|
19
|
-
) as { sources: Record<string, { path: string; glob: string; description?: string }> };
|
|
20
|
-
|
|
21
|
-
// config 源名 → 它写进库的 scope 前缀。
|
|
22
|
-
// desktop 沿用 cc 前缀是历史行为(Claude Desktop 导出的就是 CC 格式对话)。
|
|
23
|
-
const SOURCE_SCOPE_PREFIX: Record<string, string | null> = {
|
|
24
|
-
cc: "cc",
|
|
25
|
-
codex: "codex",
|
|
26
|
-
gemini: "gemini",
|
|
27
|
-
kimi: "kimi",
|
|
28
|
-
desktop: "cc",
|
|
29
|
-
minis: "minis",
|
|
30
|
-
memory: null, // markdown 记忆文件,不是会话记录,不走 transcript 降权
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
describe("ingest 源的 scope 前缀登记", () => {
|
|
34
|
-
it("config.json 里每个源都在本测试的映射表里有交代", () => {
|
|
35
|
-
for (const name of Object.keys(config.sources)) {
|
|
36
|
-
expect(
|
|
37
|
-
Object.prototype.hasOwnProperty.call(SOURCE_SCOPE_PREFIX, name),
|
|
38
|
-
).toBe(true);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("每个会话类来源的 scope 都被判定为 transcript 证据(会被降权)", () => {
|
|
43
|
-
for (const [name, prefix] of Object.entries(SOURCE_SCOPE_PREFIX)) {
|
|
44
|
-
if (prefix === null) continue;
|
|
45
|
-
// 断言里带上源名,红的时候直接看得出是哪个源漏登记
|
|
46
|
-
expect(`${name}:${isTranscriptScope(`${prefix}:abcd1234`)}`).toBe(`${name}:true`);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("minis 源已接线:config 有条目且前缀被降权识别", () => {
|
|
51
|
-
expect(config.sources.minis).toBeDefined();
|
|
52
|
-
expect(config.sources.minis.glob).toBe("*.jsonl");
|
|
53
|
-
expect(isTranscriptScope("minis:9f3e7a21")).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("同一个前缀也必须在 source 清单里登记(两道闸,漏一道就静默失真)", () => {
|
|
57
|
-
// isTranscriptScope 看 scope、isTranscriptSource 看条目的 source 字段。
|
|
58
|
-
// 只登记前者时降权仍然生效,错误不会报出来,只会让「按来源过滤」查不准。
|
|
59
|
-
for (const [name, prefix] of Object.entries(SOURCE_SCOPE_PREFIX)) {
|
|
60
|
-
if (prefix === null) continue;
|
|
61
|
-
expect(`${name}:${isTranscriptIngestSource(prefix)}`).toBe(`${name}:true`);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("一条反向断言:没登记过的前缀不会被误判成 transcript", () => {
|
|
66
|
-
expect(isTranscriptScope("project:recallnest")).toBe(false);
|
|
67
|
-
expect(isTranscriptScope("memory:pivot")).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
});
|