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
package/src/conflict-engine.ts
CHANGED
|
@@ -8,9 +8,14 @@ import {
|
|
|
8
8
|
normalizeCanonicalKey,
|
|
9
9
|
parseMetadataObject,
|
|
10
10
|
} from "./memory-boundaries.js";
|
|
11
|
-
import type { MemoryStore } from "./store.js";
|
|
12
|
-
import {
|
|
13
|
-
|
|
11
|
+
import type { MemoryEntry, MemoryStore } from "./store.js";
|
|
12
|
+
import {
|
|
13
|
+
archiveBeliefVersion,
|
|
14
|
+
BeliefTargetMissingError,
|
|
15
|
+
buildSupersedingBeliefMetadata,
|
|
16
|
+
replaceBeliefVersion,
|
|
17
|
+
} from "./belief-history.js";
|
|
18
|
+
import { parseEvolution, type EvolutionMetadata } from "./memory-evolution.js";
|
|
14
19
|
import {
|
|
15
20
|
type ConflictCandidateInput,
|
|
16
21
|
ConflictCandidateInputSchema,
|
|
@@ -98,7 +103,8 @@ function buildMergedConflictMetadata(
|
|
|
98
103
|
|
|
99
104
|
export interface ResolveConflictDeps {
|
|
100
105
|
// `store`/`upsert` are needed to archive the belief being replaced before overwriting it.
|
|
101
|
-
|
|
106
|
+
// replaceWithArchivedVersion (real MemoryStore) archives and overwrites under one store-write lock.
|
|
107
|
+
store: Pick<MemoryStore, "getById" | "update" | "store"> & Partial<Pick<MemoryStore, "upsert" | "replaceWithArchivedVersion">>;
|
|
102
108
|
embedder: Pick<Embedder, "embedPassage">;
|
|
103
109
|
conflictStore: Pick<ConflictCandidateStore, "getById" | "replace">;
|
|
104
110
|
}
|
|
@@ -151,28 +157,50 @@ export async function resolveConflictCandidate(
|
|
|
151
157
|
// Conflict resolution is the most deliberate belief change there is — accepting the
|
|
152
158
|
// incoming version or merging both used to overwrite the existing row in place, losing
|
|
153
159
|
// precisely the "before" side of the decision. Archive it first.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
const updated = await deps.store.update(existing.id, {
|
|
160
|
+
//
|
|
161
|
+
// With a full MemoryStore the archive and the overwrite share one store-write lock and the
|
|
162
|
+
// row is re-read inside it (2026-10-17): if it was deleted after the lookup above, nothing
|
|
163
|
+
// is written and this throws BeliefTargetMissingError — previously the history row was
|
|
164
|
+
// already committed when update() came back empty.
|
|
165
|
+
const resolution = input.resolution;
|
|
166
|
+
const buildUpdates = (current: MemoryEntry, previousEvo: EvolutionMetadata, historyId: string, resolvedAtMs: number) => ({
|
|
163
167
|
text: nextText,
|
|
164
168
|
vector,
|
|
165
|
-
importance: nextImportance,
|
|
169
|
+
importance: resolution === "merge" ? Math.max(current.importance, record.incoming.importance) : nextImportance,
|
|
166
170
|
category: nextCategory,
|
|
167
171
|
metadata: buildSupersedingBeliefMetadata(
|
|
168
172
|
nextMetadata,
|
|
169
173
|
previousEvo,
|
|
170
174
|
historyId,
|
|
171
175
|
resolvedAtMs,
|
|
172
|
-
`conflict:${
|
|
176
|
+
`conflict:${resolution}`,
|
|
173
177
|
),
|
|
174
178
|
timestamp: resolvedAtMs,
|
|
175
179
|
});
|
|
180
|
+
|
|
181
|
+
let updated: MemoryEntry | null;
|
|
182
|
+
const replace = deps.store.replaceWithArchivedVersion;
|
|
183
|
+
if (replace) {
|
|
184
|
+
const result = await replaceBeliefVersion(
|
|
185
|
+
{
|
|
186
|
+
store: { replaceWithArchivedVersion: replace.bind(deps.store), getById: deps.store.getById.bind(deps.store) },
|
|
187
|
+
embedder: deps.embedder,
|
|
188
|
+
},
|
|
189
|
+
existing,
|
|
190
|
+
({ current, previousEvolution, historyId, now }) => buildUpdates(current, previousEvolution, historyId, now),
|
|
191
|
+
);
|
|
192
|
+
if (result.status !== "replaced") throw new BeliefTargetMissingError(existing.id);
|
|
193
|
+
updated = result.entry;
|
|
194
|
+
} else {
|
|
195
|
+
const resolvedAtMs = Date.now();
|
|
196
|
+
const previousEvo = parseEvolution(existing.metadata, existing.timestamp);
|
|
197
|
+
const { historyId } = await archiveBeliefVersion(
|
|
198
|
+
{ store: deps.store, embedder: deps.embedder },
|
|
199
|
+
existing,
|
|
200
|
+
{ now: resolvedAtMs },
|
|
201
|
+
);
|
|
202
|
+
updated = await deps.store.update(existing.id, buildUpdates(existing, previousEvo, historyId, resolvedAtMs));
|
|
203
|
+
}
|
|
176
204
|
if (!updated) {
|
|
177
205
|
throw new Error(`Failed to update durable memory ${existing.id}`);
|
|
178
206
|
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Semantic Consolidation Engine
|
|
3
3
|
*
|
|
4
4
|
* Borrowed from UltraMemory's consolidation-engine.ts, adapted for RecallNest:
|
|
5
|
-
* - Uses RecallNest's store.vectorSearch()
|
|
5
|
+
* - Uses RecallNest's store.vectorSearch(); metadata writes go through store.patchMetadataBatch()
|
|
6
|
+
* (read inside the store-write lock, rows that no longer exist are skipped — never re-inserted).
|
|
7
|
+
* This line used to say "store.update() (no patchMetadata)"; that stopped being true on 2026-08-14.
|
|
6
8
|
* - Integrates with RecallNest's existing conflict-engine for conflict creation
|
|
7
9
|
* - Uses RecallNest's metadata structure (boundary.layer, canonicalKey, etc.)
|
|
8
10
|
*
|
|
@@ -882,10 +884,20 @@ export interface SynthesisUptakeStats {
|
|
|
882
884
|
scanned: number;
|
|
883
885
|
/** Derived insights found (cluster_insight / cross_memory_pattern). */
|
|
884
886
|
derivedTotal: number;
|
|
885
|
-
/** Derived insights with accessCount > 0 —
|
|
887
|
+
/** Derived insights with accessCount > 0 — touched by at least one retrieval.
|
|
888
|
+
* ⚠️ Inflatable: the MCP search path does not pass `source`, so every search hit
|
|
889
|
+
* increments accessCount (retriever.ts reinforcement gate is `source !== "auto-recall"`).
|
|
890
|
+
* One person running ~300 queries can move this from 3.7% to 7%+ with the store unchanged
|
|
891
|
+
* (2026-08-22 measured: a single 16-query audit moved it 177→186/4749). */
|
|
886
892
|
derivedRead: number;
|
|
887
|
-
/** derivedRead / derivedTotal; null when no derived insights exist. */
|
|
893
|
+
/** derivedRead / derivedTotal; null when no derived insights exist. Read as "touched", not "useful". */
|
|
888
894
|
uptakeRate: number | null;
|
|
895
|
+
/** Derived insights read by ≥2 distinct readers (metadata.distinctReaderCount, maintained by
|
|
896
|
+
* access-tracker with reader-id dedup + novelty gating). A single reader's repeated searches
|
|
897
|
+
* cannot push an entry past 1, so this is the harder-to-inflate uptake signal. */
|
|
898
|
+
derivedReadByMultiple: number;
|
|
899
|
+
/** derivedReadByMultiple / derivedTotal; null when no derived insights exist. */
|
|
900
|
+
multiReaderRate: number | null;
|
|
889
901
|
/** True when the scan hit the cap before exhausting the store. */
|
|
890
902
|
truncated: boolean;
|
|
891
903
|
}
|
|
@@ -894,6 +906,11 @@ export interface SynthesisUptakeStats {
|
|
|
894
906
|
* Measure how many consolidation/dream products were ever read back.
|
|
895
907
|
* 把"升华产物没人用"从体感变成能报警的数字——uptake 长期为 0 说明
|
|
896
908
|
* 升华管线在产出无人消费的内容(或读打点断链)。
|
|
909
|
+
*
|
|
910
|
+
* 两个口径(2026-09-09 加第二个,open-loops「召回可达性抽测」③):
|
|
911
|
+
* - uptakeRate:accessCount>0。**只增不减、可被检索廉价刷高**(见字段注释),
|
|
912
|
+
* 只能读成「被碰过」,不能当「合成产物有用/没用」的证据。保留它是为了历史可比。
|
|
913
|
+
* - multiReaderRate:distinctReaderCount≥2。一个人反复搜刷不高,是更难被扰动的口径。
|
|
897
914
|
*/
|
|
898
915
|
export async function computeSynthesisUptake(
|
|
899
916
|
store: { listPage(opts: { limit?: number; offset?: number; includeVector?: boolean }): Promise<MemoryEntry[]> },
|
|
@@ -905,6 +922,7 @@ export async function computeSynthesisUptake(
|
|
|
905
922
|
let scanned = 0;
|
|
906
923
|
let derivedTotal = 0;
|
|
907
924
|
let derivedRead = 0;
|
|
925
|
+
let derivedReadByMultiple = 0;
|
|
908
926
|
let offset = 0;
|
|
909
927
|
let truncated = false;
|
|
910
928
|
|
|
@@ -918,6 +936,7 @@ export async function computeSynthesisUptake(
|
|
|
918
936
|
try {
|
|
919
937
|
const meta = JSON.parse(e.metadata || "{}") as Record<string, unknown>;
|
|
920
938
|
if (typeof meta.accessCount === "number" && meta.accessCount > 0) derivedRead++;
|
|
939
|
+
if (typeof meta.distinctReaderCount === "number" && meta.distinctReaderCount >= 2) derivedReadByMultiple++;
|
|
921
940
|
} catch { /* broken metadata → counts as unread */ }
|
|
922
941
|
}
|
|
923
942
|
offset += page.length;
|
|
@@ -933,6 +952,8 @@ export async function computeSynthesisUptake(
|
|
|
933
952
|
derivedTotal,
|
|
934
953
|
derivedRead,
|
|
935
954
|
uptakeRate: derivedTotal > 0 ? derivedRead / derivedTotal : null,
|
|
955
|
+
derivedReadByMultiple,
|
|
956
|
+
multiReaderRate: derivedTotal > 0 ? derivedReadByMultiple / derivedTotal : null,
|
|
936
957
|
truncated,
|
|
937
958
|
};
|
|
938
959
|
}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* Reuses existing L0/L1/L2 text stored in metadata by the multi-vector pipeline.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import { fullTextScoreThreshold } from "./env-config.js";
|
|
15
|
+
|
|
14
16
|
// ---------------------------------------------------------------------------
|
|
15
17
|
// Types
|
|
16
18
|
// ---------------------------------------------------------------------------
|
|
@@ -137,7 +139,12 @@ export function collapseResults(
|
|
|
137
139
|
items: CollapseInput[],
|
|
138
140
|
config?: Partial<CollapseConfig>,
|
|
139
141
|
): CollapseOutput[] {
|
|
140
|
-
|
|
142
|
+
// L2 的默认线跟着流行度模式走(legacy 0.85、bounded 0.80,每次调用现读);调用方显式传的 thresholds 原样用。
|
|
143
|
+
const defaults: CollapseConfig = {
|
|
144
|
+
...DEFAULT_COLLAPSE_CONFIG,
|
|
145
|
+
thresholds: { ...DEFAULT_COLLAPSE_CONFIG.thresholds, l2: fullTextScoreThreshold() },
|
|
146
|
+
};
|
|
147
|
+
const cfg: CollapseConfig = { ...defaults, ...config };
|
|
141
148
|
const { thresholds, tokenBudget, stalenessThresholdDays } = cfg;
|
|
142
149
|
|
|
143
150
|
// Sort by score descending (highest relevance first)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PinAsset } from "./memory-assets.js";
|
|
2
2
|
import type { RetrievalResult } from "./retriever.js";
|
|
3
3
|
import type { SessionCheckpointRecord } from "./session-schema.js";
|
|
4
|
+
import { isFallbackSummary } from "./session-engine.js";
|
|
4
5
|
import { selectPinnedContext } from "./context-composer-pins.js";
|
|
5
6
|
import { cleanText, dedupeText } from "./context-composer-text.js";
|
|
6
7
|
import { selectStableResults } from "./context-composer-stable-selection.js";
|
|
@@ -74,7 +75,10 @@ function buildCheckpointStableContext(
|
|
|
74
75
|
if (!checkpoint) return [];
|
|
75
76
|
|
|
76
77
|
const items = [
|
|
77
|
-
|
|
78
|
+
// 兜底文案不占 slot:它零信息,占着会把真正有内容的 decision / next 挤出 limit。
|
|
79
|
+
checkpoint.summary && !isFallbackSummary(checkpoint.summary)
|
|
80
|
+
? `Checkpoint summary: ${checkpoint.summary}`
|
|
81
|
+
: "",
|
|
78
82
|
checkpoint.task ? `Checkpoint focus: ${checkpoint.task}` : "",
|
|
79
83
|
checkpoint.decisions[0] ? `Checkpoint decision: ${checkpoint.decisions[0]}` : "",
|
|
80
84
|
checkpoint.nextActions[0] ? `Checkpoint next: ${checkpoint.nextActions[0]}` : "",
|
package/src/context-composer.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { listPinAssets, type PinAsset } from "./memory-assets.js";
|
|
2
|
+
import { CHECKPOINT_MIRROR_SCOPE } from "./memory-boundaries.js";
|
|
2
3
|
import * as envConfig from "./env-config.js";
|
|
3
4
|
import { buildStableContextSections } from "./context-composer-stable.js";
|
|
4
5
|
import {
|
|
@@ -15,7 +16,7 @@ import {
|
|
|
15
16
|
} from "./context-composer-task-results.js";
|
|
16
17
|
import type { RetrievalContext, RetrievalResult } from "./retriever.js";
|
|
17
18
|
import type { EssentialContext, ResumeContextResponse, SessionCheckpointRecord } from "./session-schema.js";
|
|
18
|
-
import { ResumeContextRequestSchema, ResumeContextResponseSchema } from "./session-schema.js";
|
|
19
|
+
import { COLLAPSED_ITEMS_MAX, ResumeContextRequestSchema, ResumeContextResponseSchema } from "./session-schema.js";
|
|
19
20
|
import { formatCheckpointRecallSummary } from "./session-output.js";
|
|
20
21
|
import {
|
|
21
22
|
STRONG_WORKFLOW_CUE_TERMS,
|
|
@@ -59,6 +60,9 @@ async function retrieveCandidates(
|
|
|
59
60
|
},
|
|
60
61
|
): Promise<RetrievalResult[]> {
|
|
61
62
|
const { category, query, limit, scope } = params;
|
|
63
|
+
// Checkpoint mirror rows are for search_memory; resume_context already reads this session's own
|
|
64
|
+
// checkpoint from the checkpoint store, and its stable / task sections stay as they were.
|
|
65
|
+
const excludeScopes = [CHECKPOINT_MIRROR_SCOPE];
|
|
62
66
|
|
|
63
67
|
if (!scope) {
|
|
64
68
|
return retriever.retrieve({
|
|
@@ -66,6 +70,7 @@ async function retrieveCandidates(
|
|
|
66
70
|
limit,
|
|
67
71
|
...(category ? { category } : {}),
|
|
68
72
|
source: "auto-recall",
|
|
73
|
+
excludeScopes,
|
|
69
74
|
});
|
|
70
75
|
}
|
|
71
76
|
|
|
@@ -76,12 +81,14 @@ async function retrieveCandidates(
|
|
|
76
81
|
...(category ? { category } : {}),
|
|
77
82
|
scopeFilter: [scope],
|
|
78
83
|
source: "auto-recall",
|
|
84
|
+
excludeScopes,
|
|
79
85
|
}),
|
|
80
86
|
retriever.retrieve({
|
|
81
87
|
query,
|
|
82
88
|
limit: Math.min(10, limit * 2),
|
|
83
89
|
...(category ? { category } : {}),
|
|
84
90
|
source: "auto-recall",
|
|
91
|
+
excludeScopes,
|
|
85
92
|
}),
|
|
86
93
|
]);
|
|
87
94
|
|
|
@@ -454,8 +461,10 @@ export async function composeResumeContext(
|
|
|
454
461
|
score: r.score,
|
|
455
462
|
timestamp: r.entry.timestamp,
|
|
456
463
|
}));
|
|
464
|
+
// collapseResults 按分数从高到低输出;五个分区(加补充查询)去重后可能超过 20 条,
|
|
465
|
+
// 超出部分截掉,否则整个 resume_context 被 schema 的上限拒掉(2026-09-24 limitPerSection=4 实测)
|
|
457
466
|
const collapsedItems = collapseInput.length > 0
|
|
458
|
-
? collapseResults(collapseInput)
|
|
467
|
+
? collapseResults(collapseInput).slice(0, COLLAPSED_ITEMS_MAX)
|
|
459
468
|
: undefined;
|
|
460
469
|
|
|
461
470
|
// CC-8: Build essential context from pinned memories, top patterns, and open loops.
|