recallnest 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/CLAUDE.md +29 -0
- package/.claude-plugin/marketplace.json +18 -0
- package/.env.example +3 -0
- package/.github/workflows/ci.yml +28 -0
- package/.mcp.json +9 -0
- package/CHANGELOG.md +51 -0
- package/CLAUDE.md +42 -0
- package/DEMO.md +94 -0
- package/EVAL.md +89 -0
- package/FAILURES.md +75 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +59 -0
- package/README.md +427 -0
- package/README_CN.md +425 -0
- package/ROADMAP.md +198 -0
- package/assets/recallnest-workbench.png +0 -0
- package/assets/ui/app.js +807 -0
- package/assets/ui/index.html +154 -0
- package/assets/ui/styles.css +605 -0
- package/assets/wechat-qr.jpg +0 -0
- package/config.json.example +38 -0
- package/daily-recall.sh +87 -0
- package/daily-reflections/2026-03-05.md +15 -0
- package/daily-reflections/2026-03-06.md +15 -0
- package/daily-reflections/2026-03-07.md +7 -0
- package/daily-reflections/2026-03-08.md +34 -0
- package/daily-reflections/2026-03-09.md +35 -0
- package/daily-reflections/2026-03-10.md +36 -0
- package/daily-reflections/2026-03-11.md +35 -0
- package/daily-reflections/2026-03-12.md +36 -0
- package/daily-reflections/2026-03-13.md +35 -0
- package/daily-reflections/2026-03-14.md +35 -0
- package/daily-reflections/2026-03-15.md +35 -0
- package/daily-reflections/2026-03-16.md +41 -0
- package/daily-reflections/2026-03-17.md +10 -0
- package/daily-reflections/2026-03-18.md +10 -0
- package/daily-reflections/2026-03-19.md +10 -0
- package/daily-reflections/2026-03-20.md +10 -0
- package/daily-reflections/2026-03-21.md +10 -0
- package/daily-reflections/2026-03-22.md +10 -0
- package/daily-reflections/2026-03-23.md +10 -0
- package/daily-reflections/2026-03-24.md +10 -0
- package/daily-reflections/2026-03-25.md +32 -0
- package/daily-reflections/2026-03-26.md +37 -0
- package/daily-reflections/2026-03-27.md +35 -0
- package/daily-reflections/2026-03-28.md +35 -0
- package/daily-reflections/2026-03-29.md +35 -0
- package/daily-reflections/2026-03-30.md +36 -0
- package/daily-reflections/2026-03-31.md +35 -0
- package/daily-reflections/2026-04-01.md +35 -0
- package/docs/api-reference.md +1291 -0
- package/docs/architecture.md +168 -0
- package/docs/memory-boundary-contract.md +226 -0
- package/docs/memory-categories.md +119 -0
- package/docs/pipeline-audit-ultramemory.md +177 -0
- package/docs/plans/2026-03-08-query-expansion.md +270 -0
- package/docs/plans/2026-03-16-continuity-layer.md +196 -0
- package/docs/plans/mcp-tiering-plan.md +126 -0
- package/docs/research/recall-quality-audit-2026-03-22.md +153 -0
- package/docs/self-evolution.md +198 -0
- package/docs/superpowers/plans/2026-03-19-ingest-pipeline-upgrade.md +782 -0
- package/docs/superpowers/specs/2026-03-19-ingest-pipeline-upgrade-design.md +77 -0
- package/docs/superpowers/specs/2026-03-23-pull-claude-desktop-design.md +95 -0
- package/eval/cases.json +85 -0
- package/eval/continuity/case-seeds.json +90 -0
- package/eval/continuity/cases.json +302 -0
- package/eval/continuity/memory-seeds.json +26 -0
- package/eval/continuity/pattern-seeds.json +100 -0
- package/eval/continuity/results-2026-03-16.md +117 -0
- package/eval/continuity/results-2026-03-19.md +453 -0
- package/eval/continuity/runbook.md +110 -0
- package/eval/continuity/seed-cases.md +54 -0
- package/eval/reports/2026-03-06-abstract-query-baseline.md +96 -0
- package/eval/reports/2026-03-06-aws-ssh-baseline.md +82 -0
- package/eval/reports/2026-03-06-baseline.md +82 -0
- package/eval/reports/query-expansion.md +138 -0
- package/integrations/README.md +57 -0
- package/integrations/claude-code/README.md +133 -0
- package/integrations/claude-code/claude-md-snippet.md +31 -0
- package/integrations/claude-code/setup.sh +66 -0
- package/integrations/claude-code/smoke-continuity.sh +452 -0
- package/integrations/codex/README.md +49 -0
- package/integrations/codex/agents-md-snippet.md +31 -0
- package/integrations/codex/setup.sh +58 -0
- package/integrations/examples/claude-agent-sdk/memory-agent.ts +182 -0
- package/integrations/examples/langchain/memory-chain.py +111 -0
- package/integrations/examples/openai-agents-sdk/memory-agent.py +109 -0
- package/integrations/gemini-cli/README.md +57 -0
- package/integrations/gemini-cli/gemini-md-snippet.md +31 -0
- package/integrations/gemini-cli/setup.sh +64 -0
- package/integrations/shared/install-managed-block.sh +51 -0
- package/lm +19 -0
- package/package.json +50 -0
- package/plan-v1.2-distributable.md +105 -0
- package/scripts/archive-distilled-junk.ts +116 -0
- package/scripts/backfill-l0l1l2.ts +98 -0
- package/scripts/blind-scan.ts +588 -0
- package/scripts/cleanup-step1-exact-dups.ts +117 -0
- package/scripts/cleanup-step2-template-dups.ts +113 -0
- package/scripts/cleanup-step3-stale-content.ts +149 -0
- package/scripts/cleanup-step4-orphan-scopes.ts +131 -0
- package/scripts/delete-distilled-junk.ts +88 -0
- package/scripts/distill-facts.ts +305 -0
- package/scripts/health-check.ts +343 -0
- package/scripts/incremental-ingest.sh +71 -0
- package/scripts/mlp-health-check.ts +382 -0
- package/scripts/pull-claude-desktop.ts +515 -0
- package/scripts/re-ingest-cc.sh +66 -0
- package/scripts/rebalance-memory-health.ts +181 -0
- package/scripts/run-desktop-ingest.sh +11 -0
- package/scripts/start-server.sh +12 -0
- package/scripts/viz-dashboard.html +423 -0
- package/scripts/viz-export.ts +703 -0
- package/src/__tests__/access-tracker-novelty.test.ts +228 -0
- package/src/__tests__/auto-consolidation.test.ts +168 -0
- package/src/__tests__/auto-recall.test.ts +131 -0
- package/src/__tests__/batch-dedup.test.ts +65 -0
- package/src/__tests__/capture-engine.test.ts +1142 -0
- package/src/__tests__/capture-heuristic.test.ts +171 -0
- package/src/__tests__/cascade-forget.test.ts +210 -0
- package/src/__tests__/category-min-scores.test.ts +33 -0
- package/src/__tests__/confidence-tracker.test.ts +196 -0
- package/src/__tests__/conflict-advisor.test.ts +206 -0
- package/src/__tests__/conflict-escalation.test.ts +149 -0
- package/src/__tests__/conflict-lifecycle.test.ts +83 -0
- package/src/__tests__/conflict-output.test.ts +85 -0
- package/src/__tests__/conflict-store.test.ts +374 -0
- package/src/__tests__/consolidation-engine.test.ts +181 -0
- package/src/__tests__/context-composer-pins.test.ts +64 -0
- package/src/__tests__/context-composer-task-selection.test.ts +24 -0
- package/src/__tests__/context-renderer.test.ts +91 -0
- package/src/__tests__/continuity-eval.test.ts +275 -0
- package/src/__tests__/continuity-schema.test.ts +97 -0
- package/src/__tests__/core-recall-eval.test.ts +235 -0
- package/src/__tests__/core-summary.test.ts +109 -0
- package/src/__tests__/dedup-actions.test.ts +58 -0
- package/src/__tests__/deterministic-id.test.ts +39 -0
- package/src/__tests__/doctor.test.ts +303 -0
- package/src/__tests__/drill-down.test.ts +108 -0
- package/src/__tests__/embedder.test.ts +122 -0
- package/src/__tests__/entity-resolver.test.ts +58 -0
- package/src/__tests__/event-segmenter.test.ts +153 -0
- package/src/__tests__/hotness-blend.test.ts +76 -0
- package/src/__tests__/ingest.test.ts +360 -0
- package/src/__tests__/kg-extractor.test.ts +184 -0
- package/src/__tests__/kg-store.test.ts +198 -0
- package/src/__tests__/llm-consolidation.test.ts +226 -0
- package/src/__tests__/memory-boundaries.test.ts +237 -0
- package/src/__tests__/memory-health-rebalance.test.ts +144 -0
- package/src/__tests__/memory-output.test.ts +215 -0
- package/src/__tests__/multi-vector.test.ts +242 -0
- package/src/__tests__/ppr-traversal.test.ts +256 -0
- package/src/__tests__/preference-guard-smoke.test.ts +211 -0
- package/src/__tests__/preference-matcher.test.ts +230 -0
- package/src/__tests__/preference-slots.test.ts +106 -0
- package/src/__tests__/prospective-memory.test.ts +283 -0
- package/src/__tests__/query-entity-detector.test.ts +171 -0
- package/src/__tests__/query-expander.test.ts +34 -0
- package/src/__tests__/recall-mode.test.ts +64 -0
- package/src/__tests__/result-synthesizer.test.ts +198 -0
- package/src/__tests__/resume-context.test.ts +4743 -0
- package/src/__tests__/retrieval-trace.test.ts +213 -0
- package/src/__tests__/retriever-boundary-weight.test.ts +136 -0
- package/src/__tests__/retroactive-boost.test.ts +223 -0
- package/src/__tests__/scope-inventory.test.ts +200 -0
- package/src/__tests__/scope-policy.test.ts +69 -0
- package/src/__tests__/session-checkpoint.test.ts +259 -0
- package/src/__tests__/session-gc.test.ts +215 -0
- package/src/__tests__/store-scope-audit.test.ts +81 -0
- package/src/__tests__/temporal-parser.test.ts +241 -0
- package/src/__tests__/term-registry.test.ts +121 -0
- package/src/__tests__/tool-output-compressor.test.ts +133 -0
- package/src/__tests__/version-manager.test.ts +213 -0
- package/src/__tests__/workflow-observation.test.ts +400 -0
- package/src/access-tracker.ts +316 -0
- package/src/adaptive-retrieval.ts +64 -0
- package/src/api-server.ts +667 -0
- package/src/asset-sync.ts +79 -0
- package/src/auto-consolidation.ts +133 -0
- package/src/auto-gc.ts +124 -0
- package/src/auto-recall.ts +95 -0
- package/src/capture-engine.ts +931 -0
- package/src/capture-heuristic.ts +177 -0
- package/src/cascade-forget.ts +135 -0
- package/src/chunker.ts +253 -0
- package/src/cli.ts +1917 -0
- package/src/confidence-tracker.ts +166 -0
- package/src/conflict-advisor.ts +433 -0
- package/src/conflict-engine.ts +181 -0
- package/src/conflict-escalation.ts +138 -0
- package/src/conflict-lifecycle.ts +67 -0
- package/src/conflict-output.ts +218 -0
- package/src/conflict-schema.ts +130 -0
- package/src/conflict-store.ts +127 -0
- package/src/consolidation-engine.ts +256 -0
- package/src/context-composer-pins.ts +183 -0
- package/src/context-composer-queries.ts +121 -0
- package/src/context-composer-scope.ts +56 -0
- package/src/context-composer-stable-selection.ts +200 -0
- package/src/context-composer-stable.ts +217 -0
- package/src/context-composer-task-fallbacks.ts +36 -0
- package/src/context-composer-task-ranking.ts +197 -0
- package/src/context-composer-task-results.ts +137 -0
- package/src/context-composer-task-selection.ts +342 -0
- package/src/context-composer-text.ts +57 -0
- package/src/context-composer.ts +300 -0
- package/src/context-renderer.ts +179 -0
- package/src/decay-engine.ts +189 -0
- package/src/doctor.ts +543 -0
- package/src/embedder.ts +557 -0
- package/src/entity-resolver.ts +131 -0
- package/src/eval.ts +632 -0
- package/src/event-segmenter.ts +216 -0
- package/src/ingest.ts +1822 -0
- package/src/kg-extractor.ts +217 -0
- package/src/kg-store.ts +353 -0
- package/src/legacy-scope-review.ts +53 -0
- package/src/llm-client.ts +629 -0
- package/src/llm-consolidation.ts +168 -0
- package/src/mcp-server.ts +1337 -0
- package/src/memory-assets.ts +475 -0
- package/src/memory-boundaries.ts +354 -0
- package/src/memory-health-rebalance.ts +220 -0
- package/src/memory-output.ts +474 -0
- package/src/memory-schema.ts +184 -0
- package/src/multi-vector.ts +234 -0
- package/src/noise-filter.ts +155 -0
- package/src/ppr-traversal.ts +279 -0
- package/src/preference-matcher.ts +174 -0
- package/src/preference-slots.ts +259 -0
- package/src/prospective-memory.ts +198 -0
- package/src/query-entity-detector.ts +207 -0
- package/src/query-expander.ts +98 -0
- package/src/result-synthesizer.ts +114 -0
- package/src/retrieval-profiles.ts +101 -0
- package/src/retrieval-trace.ts +94 -0
- package/src/retriever.ts +1338 -0
- package/src/retroactive-boost.ts +154 -0
- package/src/rif.ts +73 -0
- package/src/runtime-config.ts +172 -0
- package/src/schema-utils.ts +56 -0
- package/src/scope-inventory.ts +310 -0
- package/src/scope-policy.ts +142 -0
- package/src/session-engine.ts +168 -0
- package/src/session-output.ts +96 -0
- package/src/session-schema.ts +60 -0
- package/src/session-store.ts +293 -0
- package/src/stderr-log.ts +16 -0
- package/src/store.ts +903 -0
- package/src/temporal-parser.ts +318 -0
- package/src/term-registry.ts +791 -0
- package/src/tool-output-compressor.ts +115 -0
- package/src/tracker.ts +57 -0
- package/src/ui-server.ts +430 -0
- package/src/version-manager.ts +172 -0
- package/src/workflow-observation-engine.ts +316 -0
- package/src/workflow-observation-managed.ts +83 -0
- package/src/workflow-observation-output.ts +86 -0
- package/src/workflow-observation-schema.ts +87 -0
- package/src/workflow-observation-scope-review.ts +409 -0
- package/src/workflow-observation-store.ts +69 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Tier 3.1: Core Summary — LLM summaries replace raw text in context output.
|
|
3
|
+
*
|
|
4
|
+
* Validates:
|
|
5
|
+
* 1. bestSummaryText() priority chain: core_summary > l1 > l0 > raw text
|
|
6
|
+
* 2. formatStableResult uses bestSummaryText
|
|
7
|
+
* 3. formatTaskResult uses bestSummaryText
|
|
8
|
+
* 4. generateCoreSummary method on LLM client
|
|
9
|
+
* 5. buildIngestedEntry includes core_summary in metadata when provided
|
|
10
|
+
*/
|
|
11
|
+
import { describe, expect, it } from "bun:test";
|
|
12
|
+
import { bestSummaryText, stripConversationMarkers } from "../context-composer-text.js";
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// bestSummaryText() priority chain
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
describe("bestSummaryText", () => {
|
|
19
|
+
const rawText = "[用户] I am a developer working on memory systems for AI agents";
|
|
20
|
+
|
|
21
|
+
it("returns core_summary when available", () => {
|
|
22
|
+
const meta = JSON.stringify({
|
|
23
|
+
core_summary: "Developer building AI agent memory systems",
|
|
24
|
+
l1_overview: "Longer L1 overview text here",
|
|
25
|
+
l0_abstract: "Short L0",
|
|
26
|
+
});
|
|
27
|
+
expect(bestSummaryText(rawText, meta)).toBe("Developer building AI agent memory systems");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("falls back to l1_overview when no core_summary", () => {
|
|
31
|
+
const meta = JSON.stringify({
|
|
32
|
+
l1_overview: "L1: Developer working on AI memory",
|
|
33
|
+
l0_abstract: "Short L0",
|
|
34
|
+
});
|
|
35
|
+
expect(bestSummaryText(rawText, meta)).toBe("L1: Developer working on AI memory");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("falls back to l0_abstract when no core_summary or l1", () => {
|
|
39
|
+
const meta = JSON.stringify({
|
|
40
|
+
l0_abstract: "Dev + AI memory",
|
|
41
|
+
});
|
|
42
|
+
expect(bestSummaryText(rawText, meta)).toBe("Dev + AI memory");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("falls back to stripped raw text when no summaries", () => {
|
|
46
|
+
const meta = JSON.stringify({});
|
|
47
|
+
expect(bestSummaryText(rawText, meta)).toBe(stripConversationMarkers(rawText));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("falls back to stripped raw text when metadata is undefined", () => {
|
|
51
|
+
expect(bestSummaryText(rawText, undefined)).toBe(stripConversationMarkers(rawText));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("falls back to stripped raw text when metadata is invalid JSON", () => {
|
|
55
|
+
expect(bestSummaryText(rawText, "not-json")).toBe(stripConversationMarkers(rawText));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("skips empty core_summary string", () => {
|
|
59
|
+
const meta = JSON.stringify({
|
|
60
|
+
core_summary: "",
|
|
61
|
+
l1_overview: "L1 text",
|
|
62
|
+
});
|
|
63
|
+
expect(bestSummaryText(rawText, meta)).toBe("L1 text");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("skips empty l1_overview string", () => {
|
|
67
|
+
const meta = JSON.stringify({
|
|
68
|
+
core_summary: "",
|
|
69
|
+
l1_overview: "",
|
|
70
|
+
l0_abstract: "L0 text",
|
|
71
|
+
});
|
|
72
|
+
expect(bestSummaryText(rawText, meta)).toBe("L0 text");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// Metadata integration
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
describe("core_summary in metadata", () => {
|
|
81
|
+
it("buildIngestedEntry includes core_summary when provided", () => {
|
|
82
|
+
// We test the metadata structure directly since buildIngestedEntry
|
|
83
|
+
// is a private function — we verify through the metadata shape
|
|
84
|
+
const metadata = JSON.stringify({
|
|
85
|
+
source: "test",
|
|
86
|
+
l0_abstract: "Short summary",
|
|
87
|
+
l1_overview: "Medium summary",
|
|
88
|
+
l2_content: "Full text content",
|
|
89
|
+
core_summary: "Core distilled summary ≤200 chars",
|
|
90
|
+
tier: "working",
|
|
91
|
+
boundary: { layer: "durable", authority: "derived" },
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const parsed = JSON.parse(metadata);
|
|
95
|
+
expect(parsed.core_summary).toBe("Core distilled summary ≤200 chars");
|
|
96
|
+
expect(bestSummaryText("raw fallback", metadata)).toBe("Core distilled summary ≤200 chars");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("metadata without core_summary falls back correctly", () => {
|
|
100
|
+
const metadata = JSON.stringify({
|
|
101
|
+
source: "test",
|
|
102
|
+
l0_abstract: "Short",
|
|
103
|
+
l1_overview: "Medium length overview",
|
|
104
|
+
l2_content: "Full text",
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(bestSummaryText("raw text", metadata)).toBe("Medium length overview");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import type { DedupAction, DedupCheckResult } from "../ingest.js";
|
|
3
|
+
|
|
4
|
+
describe("DedupAction types", () => {
|
|
5
|
+
it("DedupCheckResult supports secondaryDeletes", () => {
|
|
6
|
+
const result: DedupCheckResult = {
|
|
7
|
+
action: "store",
|
|
8
|
+
reason: "unique",
|
|
9
|
+
secondaryDeletes: [
|
|
10
|
+
{ id: "abc12345", action: "delete", reason: "outdated by candidate" },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
expect(result.secondaryDeletes).toHaveLength(1);
|
|
14
|
+
expect(result.secondaryDeletes![0].action).toBe("delete");
|
|
15
|
+
expect(result.secondaryDeletes![0].id).toBe("abc12345");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("DedupCheckResult without secondaryDeletes is backward-compatible", () => {
|
|
19
|
+
const result: DedupCheckResult = {
|
|
20
|
+
action: "skip",
|
|
21
|
+
reason: "hard",
|
|
22
|
+
existingText: "existing memory text",
|
|
23
|
+
};
|
|
24
|
+
expect(result.secondaryDeletes).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("DedupAction only supports delete", () => {
|
|
28
|
+
const action: DedupAction = {
|
|
29
|
+
id: "test-id",
|
|
30
|
+
action: "delete",
|
|
31
|
+
reason: "superseded by newer info",
|
|
32
|
+
};
|
|
33
|
+
expect(action.action).toBe("delete");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("multiple secondary deletes are valid", () => {
|
|
37
|
+
const result: DedupCheckResult = {
|
|
38
|
+
action: "store",
|
|
39
|
+
reason: "llm-merge",
|
|
40
|
+
secondaryDeletes: [
|
|
41
|
+
{ id: "id1", action: "delete", reason: "outdated" },
|
|
42
|
+
{ id: "id2", action: "delete", reason: "duplicate of id1" },
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
expect(result.secondaryDeletes).toHaveLength(2);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("empty secondaryDeletes array treated as no actions", () => {
|
|
49
|
+
const result: DedupCheckResult = {
|
|
50
|
+
action: "store",
|
|
51
|
+
reason: "unique",
|
|
52
|
+
secondaryDeletes: [],
|
|
53
|
+
};
|
|
54
|
+
expect(result.secondaryDeletes).toHaveLength(0);
|
|
55
|
+
// In practice, we check .length before executing
|
|
56
|
+
expect((result.secondaryDeletes?.length ?? 0) > 0).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { deterministicId } from "../store.js";
|
|
4
|
+
|
|
5
|
+
describe("deterministicId", () => {
|
|
6
|
+
it("same scope+text always produce the same ID", () => {
|
|
7
|
+
const id1 = deterministicId("project:test", "I prefer TypeScript");
|
|
8
|
+
const id2 = deterministicId("project:test", "I prefer TypeScript");
|
|
9
|
+
expect(id1).toBe(id2);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("different text produces different ID", () => {
|
|
13
|
+
const id1 = deterministicId("project:test", "I prefer TypeScript");
|
|
14
|
+
const id2 = deterministicId("project:test", "I prefer JavaScript");
|
|
15
|
+
expect(id1).not.toBe(id2);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("different scope produces different ID", () => {
|
|
19
|
+
const id1 = deterministicId("project:alpha", "same text");
|
|
20
|
+
const id2 = deterministicId("project:beta", "same text");
|
|
21
|
+
expect(id1).not.toBe(id2);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns UUID-shaped string (8-4-4-4-12)", () => {
|
|
25
|
+
const id = deterministicId("project:test", "hello world");
|
|
26
|
+
expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("handles empty scope gracefully", () => {
|
|
30
|
+
const id = deterministicId("", "some text");
|
|
31
|
+
expect(id).toMatch(/^[0-9a-f]{8}-/);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("handles CJK text", () => {
|
|
35
|
+
const id1 = deterministicId("project:test", "我喜欢用Bun");
|
|
36
|
+
const id2 = deterministicId("project:test", "我喜欢用Bun");
|
|
37
|
+
expect(id1).toBe(id2);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
assessContinuityBaseline,
|
|
5
|
+
assessScopeInventoryReport,
|
|
6
|
+
formatDoctorResults,
|
|
7
|
+
loadContinuityBaselineEntries,
|
|
8
|
+
} from "../doctor.js";
|
|
9
|
+
import type { MemoryEntry } from "../store.js";
|
|
10
|
+
|
|
11
|
+
function buildEntry(
|
|
12
|
+
id: string,
|
|
13
|
+
category: MemoryEntry["category"],
|
|
14
|
+
text: string,
|
|
15
|
+
scope: string,
|
|
16
|
+
metadata: Record<string, unknown> = {},
|
|
17
|
+
): MemoryEntry {
|
|
18
|
+
return {
|
|
19
|
+
id,
|
|
20
|
+
text,
|
|
21
|
+
vector: [],
|
|
22
|
+
category,
|
|
23
|
+
scope,
|
|
24
|
+
importance: 0.8,
|
|
25
|
+
timestamp: Date.parse("2026-03-17T00:00:00.000Z"),
|
|
26
|
+
metadata: JSON.stringify(metadata),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("assessContinuityBaseline", () => {
|
|
31
|
+
it("reports full coverage when all canonical continuity seeds are present", () => {
|
|
32
|
+
const seeds = {
|
|
33
|
+
patterns: [
|
|
34
|
+
{
|
|
35
|
+
title: "Cross-window continuity handoff",
|
|
36
|
+
trigger: "When opening a fresh terminal window",
|
|
37
|
+
steps: ["Call resume_context before coding."],
|
|
38
|
+
outcome: "Fresh windows recover stable context.",
|
|
39
|
+
tools: ["resume_context"],
|
|
40
|
+
importance: 0.9,
|
|
41
|
+
source: "agent",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
cases: [
|
|
45
|
+
{
|
|
46
|
+
title: "Continuity eval checkpoint isolation",
|
|
47
|
+
problem: "Eval reads live checkpoints.",
|
|
48
|
+
solutionSteps: ["Use fixture checkpoints instead."],
|
|
49
|
+
outcome: "Continuity eval becomes deterministic.",
|
|
50
|
+
tools: ["eval:continuity"],
|
|
51
|
+
source: "agent",
|
|
52
|
+
scope: "recallnest",
|
|
53
|
+
importance: 0.85,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
memories: [
|
|
57
|
+
{
|
|
58
|
+
text: "RecallNest is the shared memory layer for Claude Code, Codex, and Gemini CLI.",
|
|
59
|
+
category: "entities",
|
|
60
|
+
scope: "recallnest",
|
|
61
|
+
source: "agent",
|
|
62
|
+
importance: 0.9,
|
|
63
|
+
canonicalKey: "entities:recallnest:shared-memory-layer",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const entries: MemoryEntry[] = [
|
|
69
|
+
buildEntry(
|
|
70
|
+
"pattern-1",
|
|
71
|
+
"patterns",
|
|
72
|
+
"Workflow pattern: Cross-window continuity handoff",
|
|
73
|
+
"memory:agent",
|
|
74
|
+
{ workflowPattern: { title: "Cross-window continuity handoff" } },
|
|
75
|
+
),
|
|
76
|
+
buildEntry(
|
|
77
|
+
"case-1",
|
|
78
|
+
"cases",
|
|
79
|
+
"Case: Continuity eval checkpoint isolation",
|
|
80
|
+
"recallnest",
|
|
81
|
+
{ caseMemory: { title: "Continuity eval checkpoint isolation" } },
|
|
82
|
+
),
|
|
83
|
+
buildEntry(
|
|
84
|
+
"memory-1",
|
|
85
|
+
"entities",
|
|
86
|
+
"RecallNest is the shared memory layer for Claude Code, Codex, and Gemini CLI.",
|
|
87
|
+
"recallnest",
|
|
88
|
+
{ canonicalKey: "entities:recallnest:shared-memory-layer" },
|
|
89
|
+
),
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const assessment = assessContinuityBaseline(entries, seeds as any);
|
|
93
|
+
|
|
94
|
+
expect(assessment.found).toEqual({ patterns: 1, cases: 1, memories: 1 });
|
|
95
|
+
expect(assessment.missing).toEqual({ patterns: [], cases: [], memories: [] });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("reports missing canonical seeds by category", () => {
|
|
99
|
+
const seeds = {
|
|
100
|
+
patterns: [
|
|
101
|
+
{
|
|
102
|
+
title: "Recall before repo exploration",
|
|
103
|
+
trigger: "When startup context is sparse",
|
|
104
|
+
steps: ["Run search_memory before local repo exploration."],
|
|
105
|
+
outcome: "Fresh windows recover task-specific continuity.",
|
|
106
|
+
tools: ["resume_context", "search_memory"],
|
|
107
|
+
importance: 0.9,
|
|
108
|
+
source: "agent",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
cases: [
|
|
112
|
+
{
|
|
113
|
+
title: "RecallNest scope fallback cleanup",
|
|
114
|
+
problem: "Project continuity prefers raw transcript notes.",
|
|
115
|
+
solutionSteps: ["Prefer durable cases and patterns."],
|
|
116
|
+
outcome: "Stable project continuity becomes cleaner.",
|
|
117
|
+
tools: ["resume_context"],
|
|
118
|
+
source: "agent",
|
|
119
|
+
scope: "recallnest",
|
|
120
|
+
importance: 0.85,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
memories: [
|
|
124
|
+
{
|
|
125
|
+
text: "RecallNest continuity revolves around three primitives.",
|
|
126
|
+
category: "entities",
|
|
127
|
+
scope: "recallnest",
|
|
128
|
+
source: "agent",
|
|
129
|
+
importance: 0.9,
|
|
130
|
+
canonicalKey: "entities:recallnest:continuity-primitives",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const entries: MemoryEntry[] = [
|
|
136
|
+
buildEntry(
|
|
137
|
+
"pattern-1",
|
|
138
|
+
"patterns",
|
|
139
|
+
"Workflow pattern: Cross-window continuity handoff",
|
|
140
|
+
"memory:agent",
|
|
141
|
+
{ workflowPattern: { title: "Cross-window continuity handoff" } },
|
|
142
|
+
),
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const assessment = assessContinuityBaseline(entries, seeds as any);
|
|
146
|
+
|
|
147
|
+
expect(assessment.found).toEqual({ patterns: 0, cases: 0, memories: 0 });
|
|
148
|
+
expect(assessment.missing.patterns).toEqual(["Recall before repo exploration"]);
|
|
149
|
+
expect(assessment.missing.cases).toEqual(["RecallNest scope fallback cleanup"]);
|
|
150
|
+
expect(assessment.missing.memories).toEqual(["entities:recallnest:continuity-primitives"]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("loads enough entries for baseline checks when the index is larger than the legacy 5000-entry window", async () => {
|
|
154
|
+
const targetEntry = buildEntry(
|
|
155
|
+
"pattern-target",
|
|
156
|
+
"patterns",
|
|
157
|
+
"Workflow pattern: RecallNest MCP transport rollout",
|
|
158
|
+
"project:recallnest",
|
|
159
|
+
{ workflowPattern: { title: "RecallNest MCP transport rollout" } },
|
|
160
|
+
);
|
|
161
|
+
const entries: MemoryEntry[] = [
|
|
162
|
+
...Array.from({ length: 5000 }, (_, index) => buildEntry(
|
|
163
|
+
`noise-${index}`,
|
|
164
|
+
"patterns",
|
|
165
|
+
`Workflow pattern: Noise ${index}`,
|
|
166
|
+
"memory:agent",
|
|
167
|
+
{ workflowPattern: { title: `Noise ${index}` } },
|
|
168
|
+
)),
|
|
169
|
+
targetEntry,
|
|
170
|
+
];
|
|
171
|
+
const listCalls: Array<[string[] | undefined, string | undefined, number | undefined, number | undefined]> = [];
|
|
172
|
+
const store = {
|
|
173
|
+
async list(scopeFilter?: string[], category?: string, limit = 20, offset = 0): Promise<MemoryEntry[]> {
|
|
174
|
+
listCalls.push([scopeFilter, category, limit, offset]);
|
|
175
|
+
return entries.slice(offset, offset + limit);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const loaded = await loadContinuityBaselineEntries(store as any, entries.length);
|
|
180
|
+
const assessment = assessContinuityBaseline(loaded, {
|
|
181
|
+
patterns: [
|
|
182
|
+
{
|
|
183
|
+
title: "RecallNest MCP transport rollout",
|
|
184
|
+
trigger: "When RecallNest continuity work touches MCP transport wiring under project scope",
|
|
185
|
+
steps: ["Call resume_context with project:recallnest before transport changes."],
|
|
186
|
+
outcome: "RecallNest transport changes stay project-scoped.",
|
|
187
|
+
tools: ["resume_context", "search_memory", "eval:continuity"],
|
|
188
|
+
source: "agent",
|
|
189
|
+
scope: "project:recallnest",
|
|
190
|
+
importance: 0.87,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
cases: [],
|
|
194
|
+
memories: [],
|
|
195
|
+
} as any);
|
|
196
|
+
|
|
197
|
+
expect(listCalls).toEqual([[undefined, undefined, 5001, 0]]);
|
|
198
|
+
expect(assessment.found.patterns).toBe(1);
|
|
199
|
+
expect(assessment.missing.patterns).toEqual([]);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe("assessScopeInventoryReport", () => {
|
|
204
|
+
it("reports a clean scope inventory when no unresolved anomalies remain", () => {
|
|
205
|
+
const result = assessScopeInventoryReport({
|
|
206
|
+
generatedAt: "2026-03-19T08:20:00.000Z",
|
|
207
|
+
sampleLimit: 5,
|
|
208
|
+
totalScannedCount: 42,
|
|
209
|
+
totalAnomalyCount: 0,
|
|
210
|
+
totalInvalidCount: 0,
|
|
211
|
+
totalReviewedCount: 1,
|
|
212
|
+
layers: [
|
|
213
|
+
{
|
|
214
|
+
layer: "memories",
|
|
215
|
+
scannedCount: 40,
|
|
216
|
+
anomalyCount: 0,
|
|
217
|
+
invalidCount: 0,
|
|
218
|
+
reviewedCount: 0,
|
|
219
|
+
counts: { missing: 0, empty: 0, global: 0 },
|
|
220
|
+
samples: [],
|
|
221
|
+
recommendation: "ok",
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
layer: "workflow-observations",
|
|
225
|
+
scannedCount: 2,
|
|
226
|
+
anomalyCount: 0,
|
|
227
|
+
invalidCount: 0,
|
|
228
|
+
reviewedCount: 1,
|
|
229
|
+
counts: { missing: 0, empty: 0, global: 0 },
|
|
230
|
+
samples: [],
|
|
231
|
+
recommendation: "ok",
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(result).toEqual({
|
|
237
|
+
name: "Scope inventory",
|
|
238
|
+
status: "pass",
|
|
239
|
+
message: "0 unresolved anomalies across 42 records; reviewed keeps 1",
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("warns when scope inventory still has unresolved anomalies or invalid files", () => {
|
|
244
|
+
const result = assessScopeInventoryReport({
|
|
245
|
+
generatedAt: "2026-03-19T08:20:00.000Z",
|
|
246
|
+
sampleLimit: 5,
|
|
247
|
+
totalScannedCount: 12,
|
|
248
|
+
totalAnomalyCount: 2,
|
|
249
|
+
totalInvalidCount: 1,
|
|
250
|
+
totalReviewedCount: 0,
|
|
251
|
+
layers: [
|
|
252
|
+
{
|
|
253
|
+
layer: "pins",
|
|
254
|
+
scannedCount: 4,
|
|
255
|
+
anomalyCount: 1,
|
|
256
|
+
invalidCount: 0,
|
|
257
|
+
reviewedCount: 0,
|
|
258
|
+
counts: { missing: 0, empty: 0, global: 1 },
|
|
259
|
+
samples: [{
|
|
260
|
+
layer: "pins",
|
|
261
|
+
id: "pin-legacy-1234",
|
|
262
|
+
kind: "global",
|
|
263
|
+
scope: "global",
|
|
264
|
+
context: "pin",
|
|
265
|
+
preview: "Legacy pin",
|
|
266
|
+
recordedAt: "2026-03-19T08:00:00.000Z",
|
|
267
|
+
}],
|
|
268
|
+
recommendation: "re-pin",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
layer: "workflow-observations",
|
|
272
|
+
scannedCount: 8,
|
|
273
|
+
anomalyCount: 1,
|
|
274
|
+
invalidCount: 1,
|
|
275
|
+
reviewedCount: 0,
|
|
276
|
+
counts: { missing: 1, empty: 0, global: 0 },
|
|
277
|
+
samples: [],
|
|
278
|
+
recommendation: "review",
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
expect(result.status).toBe("warn");
|
|
284
|
+
expect(result.name).toBe("Scope inventory");
|
|
285
|
+
expect(result.message).toContain("2 unresolved anomalies, 1 invalid file(s) across 12 records");
|
|
286
|
+
expect(result.message).toContain("pins:1");
|
|
287
|
+
expect(result.message).toContain("workflow-observations:1 invalid 1");
|
|
288
|
+
expect(result.message).toContain("sample pins:global:pin-lega");
|
|
289
|
+
expect(result.fix).toBe("bun run scope-inventory");
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe("formatDoctorResults", () => {
|
|
294
|
+
it("does not claim all clear when warnings are present", () => {
|
|
295
|
+
const output = formatDoctorResults([
|
|
296
|
+
{ name: "Bun runtime", status: "pass", message: "ok" },
|
|
297
|
+
{ name: "Scope inventory", status: "warn", message: "1 unresolved anomaly", fix: "bun run scope-inventory" },
|
|
298
|
+
]);
|
|
299
|
+
|
|
300
|
+
expect(output).toContain("Review the ⚠️ items above before relying on this environment as a clean baseline.");
|
|
301
|
+
expect(output).not.toContain("All clear.");
|
|
302
|
+
});
|
|
303
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
|
|
3
|
+
describe("Tiered storage: L0/L1/L2 metadata parsing", () => {
|
|
4
|
+
it("parses L0/L1/L2 from metadata JSON", () => {
|
|
5
|
+
const metadata = JSON.stringify({
|
|
6
|
+
l0_abstract: "User prefers TypeScript",
|
|
7
|
+
l1_overview: "User consistently chooses TypeScript over JavaScript for new projects, citing type safety.",
|
|
8
|
+
l2_content: "Full detailed content here...",
|
|
9
|
+
});
|
|
10
|
+
const parsed = JSON.parse(metadata);
|
|
11
|
+
expect(parsed.l0_abstract).toBe("User prefers TypeScript");
|
|
12
|
+
expect(parsed.l1_overview.length).toBeGreaterThan(parsed.l0_abstract.length);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("handles missing L0/L1 fields gracefully", () => {
|
|
16
|
+
const metadata = JSON.stringify({ accessCount: 5 });
|
|
17
|
+
const parsed = JSON.parse(metadata);
|
|
18
|
+
expect(parsed.l0_abstract).toBeUndefined();
|
|
19
|
+
expect(parsed.l1_overview).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("handles malformed metadata JSON", () => {
|
|
23
|
+
const metadata = "not-json";
|
|
24
|
+
let parsed = null;
|
|
25
|
+
try {
|
|
26
|
+
parsed = JSON.parse(metadata);
|
|
27
|
+
} catch {
|
|
28
|
+
// Expected
|
|
29
|
+
}
|
|
30
|
+
expect(parsed).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("Tiered storage: drill-down level selection", () => {
|
|
35
|
+
it("overview level returns L1 when available", () => {
|
|
36
|
+
const meta = {
|
|
37
|
+
l0_abstract: "Short summary",
|
|
38
|
+
l1_overview: "Detailed overview with context and reasoning",
|
|
39
|
+
};
|
|
40
|
+
const fullText = "Very long full text content...";
|
|
41
|
+
const level = "overview";
|
|
42
|
+
|
|
43
|
+
const result = level === "overview" && meta.l1_overview
|
|
44
|
+
? meta.l1_overview
|
|
45
|
+
: fullText;
|
|
46
|
+
|
|
47
|
+
expect(result).toBe(meta.l1_overview);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("overview level falls back to full text when L1 missing", () => {
|
|
51
|
+
const meta: Record<string, string> = { l0_abstract: "Short summary" };
|
|
52
|
+
const fullText = "Very long full text content...";
|
|
53
|
+
const level = "overview";
|
|
54
|
+
|
|
55
|
+
const result = level === "overview" && meta.l1_overview
|
|
56
|
+
? meta.l1_overview
|
|
57
|
+
: fullText;
|
|
58
|
+
|
|
59
|
+
expect(result).toBe(fullText);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("full level always returns full text", () => {
|
|
63
|
+
const meta = {
|
|
64
|
+
l0_abstract: "Short summary",
|
|
65
|
+
l1_overview: "Detailed overview",
|
|
66
|
+
};
|
|
67
|
+
const fullText = "Very long full text content...";
|
|
68
|
+
const level = "full";
|
|
69
|
+
|
|
70
|
+
const result = level === "full" ? fullText : meta.l1_overview || fullText;
|
|
71
|
+
expect(result).toBe(fullText);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("Tiered storage: recallDepthDefault config", () => {
|
|
76
|
+
it("accepts valid depth values", () => {
|
|
77
|
+
for (const depth of ["l0", "l1", "full"]) {
|
|
78
|
+
expect(["l0", "l1", "full"].includes(depth)).toBe(true);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("rejects invalid depth values", () => {
|
|
83
|
+
for (const depth of ["l3", "summary", "compact"]) {
|
|
84
|
+
expect(["l0", "l1", "full"].includes(depth)).toBe(false);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("defaults to full when not set (backward compat)", () => {
|
|
89
|
+
const configValue = undefined;
|
|
90
|
+
const resolved = configValue || "full";
|
|
91
|
+
expect(resolved).toBe("full");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("Tiered storage: L0 injection format", () => {
|
|
96
|
+
it("L0 abstract is compact enough for context injection", () => {
|
|
97
|
+
const l0 = "User prefers TypeScript for all new projects";
|
|
98
|
+
// L0 should be under 100 tokens (~400 chars)
|
|
99
|
+
expect(l0.length).toBeLessThan(400);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("L1 overview provides medium detail", () => {
|
|
103
|
+
const l1 = "## Preference\nUser consistently chooses TypeScript over JavaScript. Cited reasons: type safety, better IDE support, easier refactoring.";
|
|
104
|
+
// L1 should be under 500 tokens (~2000 chars)
|
|
105
|
+
expect(l1.length).toBeLessThan(2000);
|
|
106
|
+
expect(l1.length).toBeGreaterThan(50);
|
|
107
|
+
});
|
|
108
|
+
});
|