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
package/src/eval.ts
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
import { buildSessionCheckpointRecord, normalizeCheckpointScope } from "./session-engine.js";
|
|
7
|
+
import type { ResumeContextResponse, SessionCheckpointRecord } from "./session-schema.js";
|
|
8
|
+
import { composeResumeContext } from "./context-composer.js";
|
|
9
|
+
import { cleanText } from "./context-composer-text.js";
|
|
10
|
+
import { createComponents, loadConfig, loadDotEnv, type LocalMemoryConfig } from "./runtime-config.js";
|
|
11
|
+
import { logInfo } from "./stderr-log.js";
|
|
12
|
+
import { buildWorkflowObservationRecord } from "./workflow-observation-engine.js";
|
|
13
|
+
import type { WorkflowObservationInput } from "./workflow-observation-schema.js";
|
|
14
|
+
import { WorkflowObservationStore } from "./workflow-observation-store.js";
|
|
15
|
+
|
|
16
|
+
export type ProfileName = "default" | "writing" | "debug" | "fact-check";
|
|
17
|
+
export type EvalMode = "retrieval" | "continuity";
|
|
18
|
+
|
|
19
|
+
export interface RetrievalEvalCase {
|
|
20
|
+
name: string;
|
|
21
|
+
query: string;
|
|
22
|
+
profile?: ProfileName;
|
|
23
|
+
scope?: string;
|
|
24
|
+
limit?: number;
|
|
25
|
+
expectAny?: string[];
|
|
26
|
+
expectAll?: string[];
|
|
27
|
+
expectScopePrefixes?: string[];
|
|
28
|
+
forbid?: string[];
|
|
29
|
+
notes?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ContinuityEvalCase {
|
|
33
|
+
name: string;
|
|
34
|
+
task?: string;
|
|
35
|
+
profile?: ProfileName;
|
|
36
|
+
scope?: string;
|
|
37
|
+
sessionId?: string;
|
|
38
|
+
limitPerSection?: number;
|
|
39
|
+
includeLatestCheckpoint?: boolean;
|
|
40
|
+
checkpoint?: {
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
scope?: string;
|
|
43
|
+
summary: string;
|
|
44
|
+
task?: string;
|
|
45
|
+
decisions?: string[];
|
|
46
|
+
openLoops?: string[];
|
|
47
|
+
nextActions?: string[];
|
|
48
|
+
entities?: string[];
|
|
49
|
+
files?: string[];
|
|
50
|
+
updatedAt?: string;
|
|
51
|
+
};
|
|
52
|
+
expectStableAny?: string[];
|
|
53
|
+
expectStableAll?: string[];
|
|
54
|
+
expectPatternsAny?: string[];
|
|
55
|
+
expectCasesAny?: string[];
|
|
56
|
+
expectCheckpointAny?: string[];
|
|
57
|
+
forbid?: string[];
|
|
58
|
+
notes?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface RetrievalCaseReport {
|
|
62
|
+
mode: "retrieval";
|
|
63
|
+
name: string;
|
|
64
|
+
query: string;
|
|
65
|
+
profile: ProfileName;
|
|
66
|
+
score: number;
|
|
67
|
+
passed: boolean;
|
|
68
|
+
hitCount: number;
|
|
69
|
+
matchedAny: string[];
|
|
70
|
+
matchedAll: string[];
|
|
71
|
+
matchedScopes: string[];
|
|
72
|
+
forbiddenMatches: string[];
|
|
73
|
+
topScopes: string[];
|
|
74
|
+
topSnippet: string;
|
|
75
|
+
notes?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ContinuityCaseReport {
|
|
79
|
+
mode: "continuity";
|
|
80
|
+
name: string;
|
|
81
|
+
task: string;
|
|
82
|
+
profile: ProfileName;
|
|
83
|
+
score: number;
|
|
84
|
+
passed: boolean;
|
|
85
|
+
stableCount: number;
|
|
86
|
+
patternCount: number;
|
|
87
|
+
caseCount: number;
|
|
88
|
+
hasCheckpoint: boolean;
|
|
89
|
+
matchedStableAny: string[];
|
|
90
|
+
matchedStableAll: string[];
|
|
91
|
+
matchedPatternsAny: string[];
|
|
92
|
+
matchedCasesAny: string[];
|
|
93
|
+
matchedCheckpointAny: string[];
|
|
94
|
+
forbiddenMatches: string[];
|
|
95
|
+
stablePreview: string[];
|
|
96
|
+
patternPreview: string[];
|
|
97
|
+
casePreview: string[];
|
|
98
|
+
checkpointSummary: string;
|
|
99
|
+
notes?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type EvalReport = RetrievalCaseReport | ContinuityCaseReport;
|
|
103
|
+
|
|
104
|
+
interface EvalArgs {
|
|
105
|
+
mode: EvalMode;
|
|
106
|
+
casesPath?: string;
|
|
107
|
+
outputPath?: string;
|
|
108
|
+
jsonMode: boolean;
|
|
109
|
+
recordObservations: boolean;
|
|
110
|
+
observationScope?: string;
|
|
111
|
+
observationSource?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface EvalCheckpointLookup {
|
|
115
|
+
getLatest(query?: { sessionId?: string; scope?: string }): Promise<SessionCheckpointRecord | null>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type EvalCaseComponents = Pick<ReturnType<typeof createComponents>, "retriever" | "accessTracker">;
|
|
119
|
+
type EvalComponentFactory = (profileName?: string) => EvalCaseComponents;
|
|
120
|
+
|
|
121
|
+
function createFreshEvalComponentsFactory(config: LocalMemoryConfig): EvalComponentFactory {
|
|
122
|
+
return function createEvalComponentsForCase(profileName?: string) {
|
|
123
|
+
const { retriever, accessTracker } = createComponents(config, profileName);
|
|
124
|
+
return { retriever, accessTracker };
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function buildContinuityEvalRequest(evalCase: ContinuityEvalCase) {
|
|
129
|
+
return {
|
|
130
|
+
task: evalCase.task,
|
|
131
|
+
scope: evalCase.scope,
|
|
132
|
+
sessionId: evalCase.sessionId || evalCase.checkpoint?.sessionId,
|
|
133
|
+
profile: evalCase.profile,
|
|
134
|
+
limitPerSection: evalCase.limitPerSection,
|
|
135
|
+
includeLatestCheckpoint: evalCase.includeLatestCheckpoint,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function parseArgs(args: string[]): EvalArgs {
|
|
140
|
+
const outputIdx = args.indexOf("--output");
|
|
141
|
+
const casesIdx = args.indexOf("--cases");
|
|
142
|
+
const modeIdx = args.indexOf("--mode");
|
|
143
|
+
const observationScopeIdx = args.indexOf("--observation-scope");
|
|
144
|
+
const observationSourceIdx = args.indexOf("--observation-source");
|
|
145
|
+
const modeRaw = modeIdx >= 0 ? args[modeIdx + 1] : "retrieval";
|
|
146
|
+
const mode = modeRaw === "continuity" ? "continuity" : "retrieval";
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
mode,
|
|
150
|
+
casesPath: casesIdx >= 0 ? args[casesIdx + 1] : undefined,
|
|
151
|
+
outputPath: outputIdx >= 0 ? resolve(args[outputIdx + 1]) : undefined,
|
|
152
|
+
jsonMode: args.includes("--json"),
|
|
153
|
+
recordObservations: args.includes("--record-observations"),
|
|
154
|
+
observationScope: observationScopeIdx >= 0 ? args[observationScopeIdx + 1] : undefined,
|
|
155
|
+
observationSource: observationSourceIdx >= 0 ? args[observationSourceIdx + 1] : undefined,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function defaultCasesPath(mode: EvalMode): string {
|
|
160
|
+
return mode === "continuity"
|
|
161
|
+
? resolve(import.meta.dir, "../eval/continuity/cases.json")
|
|
162
|
+
: resolve(import.meta.dir, "../eval/cases.json");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function loadCases<T>(mode: EvalMode, pathArg?: string): T[] {
|
|
166
|
+
const casesPath = pathArg ? resolve(pathArg) : defaultCasesPath(mode);
|
|
167
|
+
return JSON.parse(readFileSync(casesPath, "utf-8")) as T[];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function clip(text: string, maxLen = 140): string {
|
|
171
|
+
return cleanText(text, maxLen);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function matchedTerms(terms: string[] | undefined, haystack: string): string[] {
|
|
175
|
+
return (terms || []).filter((term) => haystack.includes(term.toLowerCase()));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function scoreExpectation(expected: string[] | undefined, matched: string[], weight: number): number {
|
|
179
|
+
if (!expected || expected.length === 0) return weight;
|
|
180
|
+
return (matched.length / expected.length) * weight;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function scoreRetrievalCase(
|
|
184
|
+
evalCase: RetrievalEvalCase,
|
|
185
|
+
results: Array<{ entry: { text: string; scope: string; metadata?: string } }>,
|
|
186
|
+
): RetrievalCaseReport {
|
|
187
|
+
const profile = evalCase.profile || "default";
|
|
188
|
+
const joined = results.map((r) => `${r.entry.scope}\n${r.entry.text}\n${r.entry.metadata || ""}`).join("\n").toLowerCase();
|
|
189
|
+
const scopes = results.map((r) => r.entry.scope);
|
|
190
|
+
const topSnippet = results[0] ? clip(results[0].entry.text) : "-";
|
|
191
|
+
|
|
192
|
+
const matchedAny = matchedTerms(evalCase.expectAny, joined);
|
|
193
|
+
const matchedAll = matchedTerms(evalCase.expectAll, joined);
|
|
194
|
+
const matchedScopes = (evalCase.expectScopePrefixes || []).filter((scope) => scopes.some((item) => item.startsWith(scope)));
|
|
195
|
+
const forbiddenMatches = matchedTerms(evalCase.forbid, joined);
|
|
196
|
+
|
|
197
|
+
let score = 0;
|
|
198
|
+
score += scoreExpectation(evalCase.expectAny, matchedAny, 0.4);
|
|
199
|
+
score += scoreExpectation(evalCase.expectAll, matchedAll, 0.3);
|
|
200
|
+
score += scoreExpectation(evalCase.expectScopePrefixes, matchedScopes, 0.2);
|
|
201
|
+
if (results.length > 0) score += 0.1;
|
|
202
|
+
if (forbiddenMatches.length > 0) score -= 0.3;
|
|
203
|
+
score = Math.max(0, Math.min(1, score));
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
mode: "retrieval",
|
|
207
|
+
name: evalCase.name,
|
|
208
|
+
query: evalCase.query,
|
|
209
|
+
profile,
|
|
210
|
+
score,
|
|
211
|
+
passed: score >= 0.7 && forbiddenMatches.length === 0,
|
|
212
|
+
hitCount: results.length,
|
|
213
|
+
matchedAny,
|
|
214
|
+
matchedAll,
|
|
215
|
+
matchedScopes,
|
|
216
|
+
forbiddenMatches,
|
|
217
|
+
topScopes: scopes.slice(0, 5),
|
|
218
|
+
topSnippet,
|
|
219
|
+
notes: evalCase.notes,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function joinResumeSections(response: ResumeContextResponse): string {
|
|
224
|
+
return [
|
|
225
|
+
response.summary,
|
|
226
|
+
...response.stableContext,
|
|
227
|
+
...response.relevantPatterns,
|
|
228
|
+
...response.recentCases,
|
|
229
|
+
response.latestCheckpoint?.summary || "",
|
|
230
|
+
].join("\n").toLowerCase();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function scoreContinuityCase(
|
|
234
|
+
evalCase: ContinuityEvalCase,
|
|
235
|
+
response: ResumeContextResponse,
|
|
236
|
+
): ContinuityCaseReport {
|
|
237
|
+
const profile = evalCase.profile || "default";
|
|
238
|
+
const stableJoined = response.stableContext.join("\n").toLowerCase();
|
|
239
|
+
const patternJoined = response.relevantPatterns.join("\n").toLowerCase();
|
|
240
|
+
const caseJoined = response.recentCases.join("\n").toLowerCase();
|
|
241
|
+
const checkpointJoined = `${response.latestCheckpoint?.summary || ""}\n${response.summary}`.toLowerCase();
|
|
242
|
+
const joined = joinResumeSections(response);
|
|
243
|
+
|
|
244
|
+
const matchedStableAny = matchedTerms(evalCase.expectStableAny, stableJoined);
|
|
245
|
+
const matchedStableAll = matchedTerms(evalCase.expectStableAll, stableJoined);
|
|
246
|
+
const matchedPatternsAny = matchedTerms(evalCase.expectPatternsAny, patternJoined);
|
|
247
|
+
const matchedCasesAny = matchedTerms(evalCase.expectCasesAny, caseJoined);
|
|
248
|
+
const matchedCheckpointAny = matchedTerms(evalCase.expectCheckpointAny, checkpointJoined);
|
|
249
|
+
const forbiddenMatches = matchedTerms(evalCase.forbid, joined);
|
|
250
|
+
|
|
251
|
+
const expectationScores = [
|
|
252
|
+
{ expected: evalCase.expectStableAny, matched: matchedStableAny, weight: 0.35 },
|
|
253
|
+
{ expected: evalCase.expectStableAll, matched: matchedStableAll, weight: 0.25 },
|
|
254
|
+
{ expected: evalCase.expectPatternsAny, matched: matchedPatternsAny, weight: 0.15 },
|
|
255
|
+
{ expected: evalCase.expectCasesAny, matched: matchedCasesAny, weight: 0.15 },
|
|
256
|
+
{ expected: evalCase.expectCheckpointAny, matched: matchedCheckpointAny, weight: 0.1 },
|
|
257
|
+
].filter((item) => (item.expected || []).length > 0);
|
|
258
|
+
|
|
259
|
+
const totalExpectedWeight = expectationScores.reduce((sum, item) => sum + item.weight, 0);
|
|
260
|
+
const normalizedExpectationScore = totalExpectedWeight > 0
|
|
261
|
+
? expectationScores.reduce((sum, item) => sum + scoreExpectation(item.expected, item.matched, item.weight), 0) / totalExpectedWeight
|
|
262
|
+
: 0.5;
|
|
263
|
+
|
|
264
|
+
let score = normalizedExpectationScore * 0.9;
|
|
265
|
+
if (response.stableContext.length > 0) score += 0.1;
|
|
266
|
+
if (forbiddenMatches.length > 0) score -= 0.3;
|
|
267
|
+
score = Math.max(0, Math.min(1, score));
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
mode: "continuity",
|
|
271
|
+
name: evalCase.name,
|
|
272
|
+
task: evalCase.task || "",
|
|
273
|
+
profile,
|
|
274
|
+
score,
|
|
275
|
+
passed: score >= 0.7 && forbiddenMatches.length === 0,
|
|
276
|
+
stableCount: response.stableContext.length,
|
|
277
|
+
patternCount: response.relevantPatterns.length,
|
|
278
|
+
caseCount: response.recentCases.length,
|
|
279
|
+
hasCheckpoint: Boolean(response.latestCheckpoint),
|
|
280
|
+
matchedStableAny,
|
|
281
|
+
matchedStableAll,
|
|
282
|
+
matchedPatternsAny,
|
|
283
|
+
matchedCasesAny,
|
|
284
|
+
matchedCheckpointAny,
|
|
285
|
+
forbiddenMatches,
|
|
286
|
+
stablePreview: response.stableContext.slice(0, 3).map((item) => clip(item, 120)),
|
|
287
|
+
patternPreview: response.relevantPatterns.slice(0, 3).map((item) => clip(item, 120)),
|
|
288
|
+
casePreview: response.recentCases.slice(0, 3).map((item) => clip(item, 120)),
|
|
289
|
+
checkpointSummary: response.latestCheckpoint ? clip(response.latestCheckpoint.summary, 160) : "-",
|
|
290
|
+
notes: evalCase.notes,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function formatPercent(value: number): string {
|
|
295
|
+
return `${(value * 100).toFixed(1)}%`;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function missingExpectationLabels(evalCase: ContinuityEvalCase, report: ContinuityCaseReport): string[] {
|
|
299
|
+
const missing: string[] = [];
|
|
300
|
+
if ((evalCase.expectStableAny || []).length > report.matchedStableAny.length) missing.push("stable");
|
|
301
|
+
if ((evalCase.expectStableAll || []).length > report.matchedStableAll.length) missing.push("stable-all");
|
|
302
|
+
if ((evalCase.expectPatternsAny || []).length > report.matchedPatternsAny.length) missing.push("patterns");
|
|
303
|
+
if ((evalCase.expectCasesAny || []).length > report.matchedCasesAny.length) missing.push("cases");
|
|
304
|
+
if ((evalCase.expectCheckpointAny || []).length > report.matchedCheckpointAny.length) missing.push("checkpoint");
|
|
305
|
+
return missing;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function buildContinuityEvalObservationInput(
|
|
309
|
+
evalCase: ContinuityEvalCase,
|
|
310
|
+
report: ContinuityCaseReport,
|
|
311
|
+
options: { scope?: string; source?: string } = {},
|
|
312
|
+
): WorkflowObservationInput {
|
|
313
|
+
const missingLabels = missingExpectationLabels(evalCase, report);
|
|
314
|
+
const signal = report.passed
|
|
315
|
+
? "eval-pass"
|
|
316
|
+
: report.forbiddenMatches.length > 0
|
|
317
|
+
? "forbidden-match"
|
|
318
|
+
: missingLabels[0]
|
|
319
|
+
? `missing-${missingLabels[0]}`
|
|
320
|
+
: "low-continuity-score";
|
|
321
|
+
|
|
322
|
+
const summary = report.passed
|
|
323
|
+
? `Continuity eval case ${evalCase.name} passed at ${formatPercent(report.score)}.`
|
|
324
|
+
: `Continuity eval case ${evalCase.name} failed at ${formatPercent(report.score)}${missingLabels.length > 0 ? ` (${missingLabels.join(", ")})` : ""}.`;
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
workflowId: "resume_context",
|
|
328
|
+
outcome: report.passed ? "success" : "failure",
|
|
329
|
+
summary,
|
|
330
|
+
scope: options.scope || evalCase.scope || "eval:continuity",
|
|
331
|
+
source: options.source || "eval",
|
|
332
|
+
signal,
|
|
333
|
+
task: `continuity eval: ${evalCase.name}`,
|
|
334
|
+
tags: [
|
|
335
|
+
"continuity-eval",
|
|
336
|
+
evalCase.profile || "default",
|
|
337
|
+
report.passed ? "pass" : "fail",
|
|
338
|
+
],
|
|
339
|
+
tools: ["resume_context"],
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function summarizeReports(reports: EvalReport[]): { passed: number; average: number } {
|
|
344
|
+
const passed = reports.filter((item) => item.passed).length;
|
|
345
|
+
const average = reports.reduce((sum, item) => sum + item.score, 0) / Math.max(reports.length, 1);
|
|
346
|
+
return { passed, average };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function sortNewestFirst(records: SessionCheckpointRecord[]): SessionCheckpointRecord[] {
|
|
350
|
+
return [...records].sort((a, b) => {
|
|
351
|
+
const timeDiff = Date.parse(b.updatedAt) - Date.parse(a.updatedAt);
|
|
352
|
+
if (timeDiff !== 0) return timeDiff;
|
|
353
|
+
return b.checkpointId.localeCompare(a.checkpointId);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function buildEvalCheckpointRecord(
|
|
358
|
+
evalCase: ContinuityEvalCase,
|
|
359
|
+
index: number,
|
|
360
|
+
): SessionCheckpointRecord | null {
|
|
361
|
+
if (!evalCase.checkpoint) return null;
|
|
362
|
+
|
|
363
|
+
const fallbackSessionId = evalCase.sessionId || `eval-${evalCase.name}-${index + 1}`;
|
|
364
|
+
const record = buildSessionCheckpointRecord({
|
|
365
|
+
sessionId: evalCase.checkpoint.sessionId || fallbackSessionId,
|
|
366
|
+
scope: evalCase.checkpoint.scope || evalCase.scope,
|
|
367
|
+
summary: evalCase.checkpoint.summary,
|
|
368
|
+
task: evalCase.checkpoint.task,
|
|
369
|
+
decisions: evalCase.checkpoint.decisions || [],
|
|
370
|
+
openLoops: evalCase.checkpoint.openLoops || [],
|
|
371
|
+
nextActions: evalCase.checkpoint.nextActions || [],
|
|
372
|
+
entities: evalCase.checkpoint.entities || [],
|
|
373
|
+
files: evalCase.checkpoint.files || [],
|
|
374
|
+
updatedAt: evalCase.checkpoint.updatedAt || "2026-03-16T00:00:00.000Z",
|
|
375
|
+
});
|
|
376
|
+
return record;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function createContinuityEvalCheckpointStore(
|
|
380
|
+
cases: ContinuityEvalCase[],
|
|
381
|
+
): EvalCheckpointLookup {
|
|
382
|
+
const records = cases
|
|
383
|
+
.map((evalCase, index) => buildEvalCheckpointRecord(evalCase, index))
|
|
384
|
+
.filter((record): record is SessionCheckpointRecord => Boolean(record));
|
|
385
|
+
|
|
386
|
+
return {
|
|
387
|
+
async getLatest(query = {}) {
|
|
388
|
+
const normalizedQueryScope = query.scope ? normalizeCheckpointScope(query.scope) : undefined;
|
|
389
|
+
const filtered = records.filter((record) => {
|
|
390
|
+
if (query.sessionId && record.sessionId !== query.sessionId) return false;
|
|
391
|
+
if (normalizedQueryScope && normalizeCheckpointScope(record.resolvedScope ?? "") !== normalizedQueryScope) return false;
|
|
392
|
+
return true;
|
|
393
|
+
});
|
|
394
|
+
const [latest] = sortNewestFirst(filtered);
|
|
395
|
+
return latest || null;
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function markdownRetrievalReport(reports: RetrievalCaseReport[]): string {
|
|
401
|
+
const { passed, average } = summarizeReports(reports);
|
|
402
|
+
|
|
403
|
+
const lines = [
|
|
404
|
+
"# RecallNest Retrieval Eval",
|
|
405
|
+
"",
|
|
406
|
+
`- Generated: ${new Date().toISOString()}`,
|
|
407
|
+
`- Cases: ${reports.length}`,
|
|
408
|
+
`- Passed: ${passed}/${reports.length}`,
|
|
409
|
+
`- Average score: ${formatPercent(average)}`,
|
|
410
|
+
"",
|
|
411
|
+
"| Case | Profile | Score | Pass | Hits | Top scopes |",
|
|
412
|
+
"|------|---------|-------|------|------|------------|",
|
|
413
|
+
...reports.map((item) =>
|
|
414
|
+
`| ${item.name} | ${item.profile} | ${(item.score * 100).toFixed(0)}% | ${item.passed ? "yes" : "no"} | ${item.hitCount} | ${item.topScopes.join(", ") || "-"} |`,
|
|
415
|
+
),
|
|
416
|
+
"",
|
|
417
|
+
"## Case Notes",
|
|
418
|
+
"",
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
for (const item of reports) {
|
|
422
|
+
lines.push(`### ${item.name}`);
|
|
423
|
+
lines.push(`- Query: ${item.query}`);
|
|
424
|
+
lines.push(`- Score: ${(item.score * 100).toFixed(0)}%`);
|
|
425
|
+
lines.push(`- Pass: ${item.passed ? "yes" : "no"}`);
|
|
426
|
+
lines.push(`- Hits: ${item.hitCount}`);
|
|
427
|
+
lines.push(`- Top scopes: ${item.topScopes.join(", ") || "-"}`);
|
|
428
|
+
lines.push(`- Top snippet: ${item.topSnippet}`);
|
|
429
|
+
lines.push(`- Matched any: ${item.matchedAny.join(", ") || "-"}`);
|
|
430
|
+
lines.push(`- Matched all: ${item.matchedAll.join(", ") || "-"}`);
|
|
431
|
+
lines.push(`- Matched scopes: ${item.matchedScopes.join(", ") || "-"}`);
|
|
432
|
+
lines.push(`- Forbidden matches: ${item.forbiddenMatches.join(", ") || "-"}`);
|
|
433
|
+
if (item.notes) lines.push(`- Notes: ${item.notes}`);
|
|
434
|
+
lines.push("");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return lines.join("\n");
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function markdownContinuityReport(reports: ContinuityCaseReport[]): string {
|
|
441
|
+
const { passed, average } = summarizeReports(reports);
|
|
442
|
+
|
|
443
|
+
const lines = [
|
|
444
|
+
"# RecallNest Continuity Eval",
|
|
445
|
+
"",
|
|
446
|
+
`- Generated: ${new Date().toISOString()}`,
|
|
447
|
+
`- Cases: ${reports.length}`,
|
|
448
|
+
`- Passed: ${passed}/${reports.length}`,
|
|
449
|
+
`- Average score: ${formatPercent(average)}`,
|
|
450
|
+
"",
|
|
451
|
+
"| Case | Profile | Score | Pass | Stable | Patterns | Cases | Checkpoint |",
|
|
452
|
+
"|------|---------|-------|------|--------|----------|-------|------------|",
|
|
453
|
+
...reports.map((item) =>
|
|
454
|
+
`| ${item.name} | ${item.profile} | ${(item.score * 100).toFixed(0)}% | ${item.passed ? "yes" : "no"} | ${item.stableCount} | ${item.patternCount} | ${item.caseCount} | ${item.hasCheckpoint ? "yes" : "no"} |`,
|
|
455
|
+
),
|
|
456
|
+
"",
|
|
457
|
+
"## Case Notes",
|
|
458
|
+
"",
|
|
459
|
+
];
|
|
460
|
+
|
|
461
|
+
for (const item of reports) {
|
|
462
|
+
lines.push(`### ${item.name}`);
|
|
463
|
+
lines.push(`- Task: ${item.task || "-"}`);
|
|
464
|
+
lines.push(`- Score: ${(item.score * 100).toFixed(0)}%`);
|
|
465
|
+
lines.push(`- Pass: ${item.passed ? "yes" : "no"}`);
|
|
466
|
+
lines.push(`- Stable items: ${item.stableCount}`);
|
|
467
|
+
lines.push(`- Pattern items: ${item.patternCount}`);
|
|
468
|
+
lines.push(`- Case items: ${item.caseCount}`);
|
|
469
|
+
lines.push(`- Checkpoint present: ${item.hasCheckpoint ? "yes" : "no"}`);
|
|
470
|
+
lines.push(`- Stable preview: ${item.stablePreview.join(" | ") || "-"}`);
|
|
471
|
+
lines.push(`- Pattern preview: ${item.patternPreview.join(" | ") || "-"}`);
|
|
472
|
+
lines.push(`- Case preview: ${item.casePreview.join(" | ") || "-"}`);
|
|
473
|
+
lines.push(`- Checkpoint summary: ${item.checkpointSummary}`);
|
|
474
|
+
lines.push(`- Matched stable any: ${item.matchedStableAny.join(", ") || "-"}`);
|
|
475
|
+
lines.push(`- Matched stable all: ${item.matchedStableAll.join(", ") || "-"}`);
|
|
476
|
+
lines.push(`- Matched patterns any: ${item.matchedPatternsAny.join(", ") || "-"}`);
|
|
477
|
+
lines.push(`- Matched cases any: ${item.matchedCasesAny.join(", ") || "-"}`);
|
|
478
|
+
lines.push(`- Matched checkpoint any: ${item.matchedCheckpointAny.join(", ") || "-"}`);
|
|
479
|
+
lines.push(`- Forbidden matches: ${item.forbiddenMatches.join(", ") || "-"}`);
|
|
480
|
+
if (item.notes) lines.push(`- Notes: ${item.notes}`);
|
|
481
|
+
lines.push("");
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
return lines.join("\n");
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export async function runRetrievalEval(
|
|
488
|
+
cases: RetrievalEvalCase[],
|
|
489
|
+
deps: {
|
|
490
|
+
createEvalComponents?: EvalComponentFactory;
|
|
491
|
+
} = {},
|
|
492
|
+
): Promise<RetrievalCaseReport[]> {
|
|
493
|
+
const config = deps.createEvalComponents ? null : loadConfig();
|
|
494
|
+
const createEvalComponentsForCase = deps.createEvalComponents || createFreshEvalComponentsFactory(config!);
|
|
495
|
+
const reports: RetrievalCaseReport[] = [];
|
|
496
|
+
|
|
497
|
+
for (const [index, evalCase] of cases.entries()) {
|
|
498
|
+
if (cases.length > 1) {
|
|
499
|
+
logInfo(`[INFO] retrieval-eval ${index + 1}/${cases.length}: ${evalCase.name}`);
|
|
500
|
+
}
|
|
501
|
+
const profileName = evalCase.profile || "default";
|
|
502
|
+
const { retriever, accessTracker } = createEvalComponentsForCase(profileName);
|
|
503
|
+
try {
|
|
504
|
+
const results = await retriever.retrieve({
|
|
505
|
+
query: evalCase.query,
|
|
506
|
+
limit: evalCase.limit || 5,
|
|
507
|
+
scopeFilter: evalCase.scope ? [evalCase.scope] : undefined,
|
|
508
|
+
source: "auto-recall",
|
|
509
|
+
});
|
|
510
|
+
const report = scoreRetrievalCase(evalCase, results);
|
|
511
|
+
reports.push(report);
|
|
512
|
+
if (cases.length > 1) {
|
|
513
|
+
logInfo(
|
|
514
|
+
`[INFO] retrieval-eval ${index + 1}/${cases.length} done: ${evalCase.name} ${formatPercent(report.score)} ${report.passed ? "pass" : "fail"}`,
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
} finally {
|
|
518
|
+
accessTracker.destroy();
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return reports;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export async function runContinuityEval(
|
|
526
|
+
cases: ContinuityEvalCase[],
|
|
527
|
+
options: { recordObservations?: boolean; observationScope?: string; observationSource?: string } = {},
|
|
528
|
+
deps: {
|
|
529
|
+
createEvalComponents?: EvalComponentFactory;
|
|
530
|
+
checkpointStore?: EvalCheckpointLookup;
|
|
531
|
+
observationStore?: WorkflowObservationStore | null;
|
|
532
|
+
composeResumeContextFn?: typeof composeResumeContext;
|
|
533
|
+
} = {},
|
|
534
|
+
): Promise<ContinuityCaseReport[]> {
|
|
535
|
+
const config = deps.createEvalComponents ? null : loadConfig();
|
|
536
|
+
const createEvalComponentsForCase = deps.createEvalComponents || createFreshEvalComponentsFactory(config!);
|
|
537
|
+
const checkpointStore = deps.checkpointStore || createContinuityEvalCheckpointStore(cases);
|
|
538
|
+
const observationStore = deps.observationStore === undefined
|
|
539
|
+
? (options.recordObservations ? new WorkflowObservationStore() : null)
|
|
540
|
+
: deps.observationStore;
|
|
541
|
+
const composeResumeContextFn = deps.composeResumeContextFn || composeResumeContext;
|
|
542
|
+
const reports: ContinuityCaseReport[] = [];
|
|
543
|
+
|
|
544
|
+
for (const [index, evalCase] of cases.entries()) {
|
|
545
|
+
if (cases.length > 1) {
|
|
546
|
+
logInfo(`[INFO] continuity-eval ${index + 1}/${cases.length}: ${evalCase.name}`);
|
|
547
|
+
}
|
|
548
|
+
const profileName = evalCase.profile || "default";
|
|
549
|
+
const { retriever, accessTracker } = createEvalComponentsForCase(profileName);
|
|
550
|
+
try {
|
|
551
|
+
const response = await composeResumeContextFn({
|
|
552
|
+
retriever,
|
|
553
|
+
checkpointStore,
|
|
554
|
+
}, buildContinuityEvalRequest(evalCase));
|
|
555
|
+
const report = scoreContinuityCase(evalCase, response);
|
|
556
|
+
reports.push(report);
|
|
557
|
+
if (cases.length > 1) {
|
|
558
|
+
logInfo(
|
|
559
|
+
`[INFO] continuity-eval ${index + 1}/${cases.length} done: ${evalCase.name} ${formatPercent(report.score)} ${report.passed ? "pass" : "fail"}`,
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
if (observationStore) {
|
|
563
|
+
await observationStore.save(buildWorkflowObservationRecord(
|
|
564
|
+
buildContinuityEvalObservationInput(evalCase, report, {
|
|
565
|
+
scope: options.observationScope,
|
|
566
|
+
source: options.observationSource,
|
|
567
|
+
}),
|
|
568
|
+
));
|
|
569
|
+
}
|
|
570
|
+
} finally {
|
|
571
|
+
accessTracker.destroy();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return reports;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function writeOutput(outputPath: string | undefined, text: string): void {
|
|
579
|
+
if (!outputPath) return;
|
|
580
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
581
|
+
writeFileSync(outputPath, text + "\n");
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
async function main() {
|
|
585
|
+
loadDotEnv();
|
|
586
|
+
const args = parseArgs(process.argv.slice(2));
|
|
587
|
+
|
|
588
|
+
if (args.mode === "continuity") {
|
|
589
|
+
const cases = loadCases<ContinuityEvalCase>("continuity", args.casesPath);
|
|
590
|
+
const reports = await runContinuityEval(cases, {
|
|
591
|
+
recordObservations: args.recordObservations,
|
|
592
|
+
observationScope: args.observationScope,
|
|
593
|
+
observationSource: args.observationSource,
|
|
594
|
+
});
|
|
595
|
+
if (args.jsonMode) {
|
|
596
|
+
const payload = JSON.stringify({
|
|
597
|
+
mode: "continuity",
|
|
598
|
+
generatedAt: new Date().toISOString(),
|
|
599
|
+
reports,
|
|
600
|
+
}, null, 2);
|
|
601
|
+
writeOutput(args.outputPath, payload);
|
|
602
|
+
console.log(payload);
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const output = markdownContinuityReport(reports);
|
|
607
|
+
writeOutput(args.outputPath, output);
|
|
608
|
+
console.log(output);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const cases = loadCases<RetrievalEvalCase>("retrieval", args.casesPath);
|
|
613
|
+
const reports = await runRetrievalEval(cases);
|
|
614
|
+
if (args.jsonMode) {
|
|
615
|
+
const payload = JSON.stringify({
|
|
616
|
+
mode: "retrieval",
|
|
617
|
+
generatedAt: new Date().toISOString(),
|
|
618
|
+
reports,
|
|
619
|
+
}, null, 2);
|
|
620
|
+
writeOutput(args.outputPath, payload);
|
|
621
|
+
console.log(payload);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const output = markdownRetrievalReport(reports);
|
|
626
|
+
writeOutput(args.outputPath, output);
|
|
627
|
+
console.log(output);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (import.meta.main) {
|
|
631
|
+
await main();
|
|
632
|
+
}
|