@edihasaj/recall 0.8.7 → 0.8.9
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/dist/{chunk-EXWSATQS.js → chunk-2EKCJ2V3.js} +2 -2
- package/dist/{chunk-EYUHIYTR.js → chunk-5QN5GGCV.js} +18 -3
- package/dist/{chunk-EYUHIYTR.js.map → chunk-5QN5GGCV.js.map} +1 -1
- package/dist/{chunk-B6ZL6O6A.js → chunk-WEA6TDEJ.js} +139 -2
- package/dist/chunk-WEA6TDEJ.js.map +1 -0
- package/dist/{chunk-QGCFA2BM.js → chunk-WZGPE3HG.js} +3 -3
- package/dist/{chunk-GK5UIZQ4.js → chunk-YLWJKWHH.js} +3 -3
- package/dist/cli.js +21 -5
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +5 -5
- package/dist/mcp.js +3 -3
- package/dist/memory-value-N3YHRLO5.js +33 -0
- package/dist/{quality-UKMC4QU2.js → quality-RU6SM34C.js} +3 -3
- package/dist/quality-RU6SM34C.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-B6ZL6O6A.js.map +0 -1
- /package/dist/{chunk-EXWSATQS.js.map → chunk-2EKCJ2V3.js.map} +0 -0
- /package/dist/{chunk-QGCFA2BM.js.map → chunk-WZGPE3HG.js.map} +0 -0
- /package/dist/{chunk-GK5UIZQ4.js.map → chunk-YLWJKWHH.js.map} +0 -0
- /package/dist/{quality-UKMC4QU2.js.map → memory-value-N3YHRLO5.js.map} +0 -0
|
@@ -236,10 +236,97 @@ function recordMemoryValueEvent(db, input) {
|
|
|
236
236
|
injected_tokens_estimate: Math.max(0, Math.round(input.injected_tokens_estimate ?? 0)),
|
|
237
237
|
saved_tokens_estimate: Math.max(0, Math.round(input.saved_tokens_estimate ?? 0)),
|
|
238
238
|
evidence: input.evidence ?? {},
|
|
239
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
239
|
+
created_at: input.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
240
240
|
}).run();
|
|
241
241
|
return id;
|
|
242
242
|
}
|
|
243
|
+
function backfillMemoryValueEvents(db, opts = {}) {
|
|
244
|
+
const rows = db.select({
|
|
245
|
+
id: memoryInjections.id,
|
|
246
|
+
memory_id: memoryInjections.memory_id,
|
|
247
|
+
session_id: memoryInjections.session_id,
|
|
248
|
+
repo: memoryInjections.repo,
|
|
249
|
+
injected_at: memoryInjections.injected_at,
|
|
250
|
+
outcome: memoryInjections.outcome,
|
|
251
|
+
outcome_at: memoryInjections.outcome_at,
|
|
252
|
+
text: memories.text
|
|
253
|
+
}).from(memoryInjections).leftJoin(memories, eq(memoryInjections.memory_id, memories.id)).where(opts.sinceIso ? gte(memoryInjections.injected_at, opts.sinceIso) : void 0).all();
|
|
254
|
+
const existingInjected = new Set(
|
|
255
|
+
db.select({ injection_id: memoryValueEvents.injection_id }).from(memoryValueEvents).where(eq(memoryValueEvents.event_type, "injected")).all().map((row) => row.injection_id).filter((id) => Boolean(id))
|
|
256
|
+
);
|
|
257
|
+
const existingOutcomes = new Set(
|
|
258
|
+
db.select({
|
|
259
|
+
injection_id: memoryValueEvents.injection_id,
|
|
260
|
+
event_type: memoryValueEvents.event_type
|
|
261
|
+
}).from(memoryValueEvents).where(inArray(memoryValueEvents.event_type, ["followed", "overridden", "ignored", "contradicted"])).all().filter((row) => row.injection_id).map((row) => `${row.injection_id}:${row.event_type}`)
|
|
262
|
+
);
|
|
263
|
+
const report = {
|
|
264
|
+
scanned_injections: rows.length,
|
|
265
|
+
inserted_injected: 0,
|
|
266
|
+
inserted_outcomes: 0,
|
|
267
|
+
skipped_existing: 0,
|
|
268
|
+
dry_run: opts.dryRun !== false
|
|
269
|
+
};
|
|
270
|
+
for (const row of rows) {
|
|
271
|
+
if (existingInjected.has(row.id)) {
|
|
272
|
+
report.skipped_existing += 1;
|
|
273
|
+
} else {
|
|
274
|
+
report.inserted_injected += 1;
|
|
275
|
+
if (!report.dry_run) {
|
|
276
|
+
recordMemoryValueEvent(db, {
|
|
277
|
+
memory_id: row.memory_id,
|
|
278
|
+
injection_id: row.id,
|
|
279
|
+
session_id: row.session_id,
|
|
280
|
+
repo: row.repo,
|
|
281
|
+
event_type: "injected",
|
|
282
|
+
source: "system",
|
|
283
|
+
injected_tokens_estimate: estimateTokens(row.text),
|
|
284
|
+
evidence: {
|
|
285
|
+
matched_memory_text: row.text ?? void 0,
|
|
286
|
+
reason: "backfilled from memory_injections"
|
|
287
|
+
},
|
|
288
|
+
created_at: row.injected_at
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (!row.outcome) continue;
|
|
293
|
+
const outcomeKey = `${row.id}:${row.outcome}`;
|
|
294
|
+
if (existingOutcomes.has(outcomeKey)) {
|
|
295
|
+
report.skipped_existing += 1;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
report.inserted_outcomes += 1;
|
|
299
|
+
if (!report.dry_run) {
|
|
300
|
+
recordMemoryValueEvent(db, {
|
|
301
|
+
memory_id: row.memory_id,
|
|
302
|
+
injection_id: row.id,
|
|
303
|
+
session_id: row.session_id,
|
|
304
|
+
repo: row.repo,
|
|
305
|
+
event_type: row.outcome,
|
|
306
|
+
source: "system",
|
|
307
|
+
saved_tokens_estimate: row.outcome === "followed" ? estimateTokens(row.text) : 0,
|
|
308
|
+
evidence: {
|
|
309
|
+
matched_memory_text: row.text ?? void 0,
|
|
310
|
+
reason: "backfilled from memory_injections outcome"
|
|
311
|
+
},
|
|
312
|
+
created_at: row.outcome_at ?? row.injected_at
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return report;
|
|
317
|
+
}
|
|
318
|
+
function formatMemoryValueBackfillReport(report) {
|
|
319
|
+
const lines = [
|
|
320
|
+
"# Memory Value Backfill",
|
|
321
|
+
"",
|
|
322
|
+
`Mode: ${report.dry_run ? "dry-run" : "applied"}`,
|
|
323
|
+
`Scanned injects: ${report.scanned_injections}`,
|
|
324
|
+
`Inserted injected: ${report.inserted_injected}`,
|
|
325
|
+
`Inserted outcomes: ${report.inserted_outcomes}`,
|
|
326
|
+
`Skipped existing: ${report.skipped_existing}`
|
|
327
|
+
];
|
|
328
|
+
return lines.join("\n");
|
|
329
|
+
}
|
|
243
330
|
function recordInjectionValueEvents(db, input) {
|
|
244
331
|
if (!input.session_id || input.memory_ids.length === 0) return 0;
|
|
245
332
|
const rows = db.select({
|
|
@@ -300,6 +387,27 @@ function recordOutcomeValueEvent(db, input) {
|
|
|
300
387
|
}
|
|
301
388
|
});
|
|
302
389
|
}
|
|
390
|
+
function recordCompletionUseValueEvents(db, input) {
|
|
391
|
+
const completionText = input.completion_text.trim();
|
|
392
|
+
if (!completionText) return { recorded: 0, memory_ids: [] };
|
|
393
|
+
const explicitIds = new Set(input.memory_ids ?? []);
|
|
394
|
+
const candidates = injectedMemoriesForCompletionUse(db, input.session_id, input.memory_ids);
|
|
395
|
+
return recordCompletionUseForCandidates(db, input, candidates, (candidate) => {
|
|
396
|
+
if (explicitIds.has(candidate.id)) {
|
|
397
|
+
return {
|
|
398
|
+
matched: true,
|
|
399
|
+
reason: "agent explicitly reported using this injected memory"
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
if (completionUsesMemory(completionText, candidate.text)) {
|
|
403
|
+
return {
|
|
404
|
+
matched: true,
|
|
405
|
+
reason: "assistant completion overlapped an injected memory"
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
return { matched: false };
|
|
409
|
+
});
|
|
410
|
+
}
|
|
303
411
|
async function recordCompletionUseValueEventsSemantic(db, input) {
|
|
304
412
|
const completionText = input.completion_text.trim();
|
|
305
413
|
if (!completionText) return { recorded: 0, memory_ids: [] };
|
|
@@ -380,6 +488,28 @@ function recordCompletionUseForCandidates(db, input, candidates, matcher) {
|
|
|
380
488
|
}
|
|
381
489
|
return { recorded, memory_ids: [...selected.keys()] };
|
|
382
490
|
}
|
|
491
|
+
function detectAndRecordRetrievalMisses(db, input) {
|
|
492
|
+
if (input.correction_texts.length === 0) return [];
|
|
493
|
+
const injected = listInjectedMemoryIdsForSession(db, input.session_id);
|
|
494
|
+
const candidates = candidateMemoriesForMissDetection(db, input.repo ?? null);
|
|
495
|
+
const out = [];
|
|
496
|
+
for (const correctionText of input.correction_texts) {
|
|
497
|
+
const match = bestTextMatch(correctionText, candidates);
|
|
498
|
+
if (!match || match.score < 0.62) continue;
|
|
499
|
+
if (injected.has(match.memory.id)) {
|
|
500
|
+
out.push({ recorded: false, memory_id: match.memory.id, promoted: false });
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
out.push(recordRetrievalMissForMatch(db, {
|
|
504
|
+
...input,
|
|
505
|
+
correction_text: correctionText,
|
|
506
|
+
injected_memory_ids: [...injected],
|
|
507
|
+
memory: match.memory,
|
|
508
|
+
semantic_similarity: void 0
|
|
509
|
+
}));
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
383
513
|
function recordRetrievalMissForMatch(db, input) {
|
|
384
514
|
let promoted = false;
|
|
385
515
|
if (input.memory.status === "candidate") {
|
|
@@ -562,10 +692,17 @@ export {
|
|
|
562
692
|
pathMatchesMemory,
|
|
563
693
|
toolCallTouchesMemory,
|
|
564
694
|
textMatches,
|
|
695
|
+
textMatchScore,
|
|
696
|
+
estimateTokens,
|
|
697
|
+
recordMemoryValueEvent,
|
|
698
|
+
backfillMemoryValueEvents,
|
|
699
|
+
formatMemoryValueBackfillReport,
|
|
565
700
|
recordInjectionValueEvents,
|
|
566
701
|
recordOutcomeValueEvent,
|
|
702
|
+
recordCompletionUseValueEvents,
|
|
567
703
|
recordCompletionUseValueEventsSemantic,
|
|
704
|
+
detectAndRecordRetrievalMisses,
|
|
568
705
|
detectAndRecordRetrievalMissesSemantic,
|
|
569
706
|
computeMemoryValueReport
|
|
570
707
|
};
|
|
571
|
-
//# sourceMappingURL=chunk-
|
|
708
|
+
//# sourceMappingURL=chunk-WEA6TDEJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/models/memory-value.ts","../src/models/memory-injections.ts","../src/text/match.ts"],"sourcesContent":["import { and, desc, eq, gte, inArray, sql } from \"drizzle-orm\";\nimport { randomUUID } from \"node:crypto\";\nimport type { RecallDb } from \"../db/client.js\";\nimport { memories, memoryInjections, memoryValueEvents } from \"../db/schema.js\";\nimport type { ActivitySource, FeedbackOutcome, MemoryItem } from \"../types.js\";\nimport { getMemory, queryMemories, promoteMemory } from \"./memory.js\";\nimport { listInjectedMemoryIdsForSession } from \"./memory-injections.js\";\nimport { textMatchScore } from \"../text/match.js\";\nimport {\n cosineSimilarity,\n generateEmbedding,\n loadEmbedding,\n loadEmbeddingConfigFromEnv,\n} from \"../embeddings/embeddings.js\";\n\nexport type MemoryValueEventType =\n | \"injected\"\n | \"used\"\n | FeedbackOutcome\n | \"retrieval_miss\";\n\nexport interface MemoryValueEvidence {\n context?: string;\n query_text?: string;\n correction_text?: string;\n completion_excerpt?: string;\n explicit_memory_ids?: string[];\n prompt_path?: string;\n reason?: string;\n semantic_similarity?: number;\n matched_memory_text?: string;\n injected_memory_ids?: string[];\n pack_tokens_estimate?: number;\n}\n\nexport interface RecordMemoryValueEventInput {\n memory_id?: string | null;\n injection_id?: string | null;\n feedback_id?: string | null;\n session_id: string;\n repo?: string | null;\n event_type: MemoryValueEventType;\n source: ActivitySource;\n injected_tokens_estimate?: number;\n saved_tokens_estimate?: number;\n evidence?: MemoryValueEvidence;\n created_at?: string;\n}\n\nexport function estimateTokens(text: string | null | undefined): number {\n const trimmed = text?.trim();\n if (!trimmed) return 0;\n return Math.max(1, Math.ceil(trimmed.length / 4));\n}\n\nexport function recordMemoryValueEvent(\n db: RecallDb,\n input: RecordMemoryValueEventInput,\n): string {\n const id = randomUUID();\n db.insert(memoryValueEvents)\n .values({\n id,\n memory_id: input.memory_id ?? null,\n injection_id: input.injection_id ?? null,\n feedback_id: input.feedback_id ?? null,\n session_id: input.session_id,\n repo: input.repo ?? null,\n event_type: input.event_type,\n source: input.source,\n injected_tokens_estimate: Math.max(0, Math.round(input.injected_tokens_estimate ?? 0)),\n saved_tokens_estimate: Math.max(0, Math.round(input.saved_tokens_estimate ?? 0)),\n evidence: (input.evidence ?? {}) as any,\n created_at: input.created_at ?? new Date().toISOString(),\n })\n .run();\n return id;\n}\n\nexport interface MemoryValueBackfillReport {\n scanned_injections: number;\n inserted_injected: number;\n inserted_outcomes: number;\n skipped_existing: number;\n dry_run: boolean;\n}\n\nexport function backfillMemoryValueEvents(\n db: RecallDb,\n opts: { sinceIso?: string; dryRun?: boolean } = {},\n): MemoryValueBackfillReport {\n const rows = db.select({\n id: memoryInjections.id,\n memory_id: memoryInjections.memory_id,\n session_id: memoryInjections.session_id,\n repo: memoryInjections.repo,\n injected_at: memoryInjections.injected_at,\n outcome: memoryInjections.outcome,\n outcome_at: memoryInjections.outcome_at,\n text: memories.text,\n })\n .from(memoryInjections)\n .leftJoin(memories, eq(memoryInjections.memory_id, memories.id))\n .where(opts.sinceIso ? gte(memoryInjections.injected_at, opts.sinceIso) : undefined)\n .all();\n\n const existingInjected = new Set(\n db.select({ injection_id: memoryValueEvents.injection_id })\n .from(memoryValueEvents)\n .where(eq(memoryValueEvents.event_type, \"injected\"))\n .all()\n .map((row) => row.injection_id)\n .filter((id): id is string => Boolean(id)),\n );\n\n const existingOutcomes = new Set(\n db.select({\n injection_id: memoryValueEvents.injection_id,\n event_type: memoryValueEvents.event_type,\n })\n .from(memoryValueEvents)\n .where(inArray(memoryValueEvents.event_type, [\"followed\", \"overridden\", \"ignored\", \"contradicted\"]))\n .all()\n .filter((row) => row.injection_id)\n .map((row) => `${row.injection_id}:${row.event_type}`),\n );\n\n const report: MemoryValueBackfillReport = {\n scanned_injections: rows.length,\n inserted_injected: 0,\n inserted_outcomes: 0,\n skipped_existing: 0,\n dry_run: opts.dryRun !== false,\n };\n\n for (const row of rows) {\n if (existingInjected.has(row.id)) {\n report.skipped_existing += 1;\n } else {\n report.inserted_injected += 1;\n if (!report.dry_run) {\n recordMemoryValueEvent(db, {\n memory_id: row.memory_id,\n injection_id: row.id,\n session_id: row.session_id,\n repo: row.repo,\n event_type: \"injected\",\n source: \"system\",\n injected_tokens_estimate: estimateTokens(row.text),\n evidence: {\n matched_memory_text: row.text ?? undefined,\n reason: \"backfilled from memory_injections\",\n },\n created_at: row.injected_at,\n });\n }\n }\n\n if (!row.outcome) continue;\n const outcomeKey = `${row.id}:${row.outcome}`;\n if (existingOutcomes.has(outcomeKey)) {\n report.skipped_existing += 1;\n continue;\n }\n\n report.inserted_outcomes += 1;\n if (!report.dry_run) {\n recordMemoryValueEvent(db, {\n memory_id: row.memory_id,\n injection_id: row.id,\n session_id: row.session_id,\n repo: row.repo,\n event_type: row.outcome,\n source: \"system\",\n saved_tokens_estimate: row.outcome === \"followed\" ? estimateTokens(row.text) : 0,\n evidence: {\n matched_memory_text: row.text ?? undefined,\n reason: \"backfilled from memory_injections outcome\",\n },\n created_at: row.outcome_at ?? row.injected_at,\n });\n }\n }\n\n return report;\n}\n\nexport function formatMemoryValueBackfillReport(report: MemoryValueBackfillReport): string {\n const lines = [\n \"# Memory Value Backfill\",\n \"\",\n `Mode: ${report.dry_run ? \"dry-run\" : \"applied\"}`,\n `Scanned injects: ${report.scanned_injections}`,\n `Inserted injected: ${report.inserted_injected}`,\n `Inserted outcomes: ${report.inserted_outcomes}`,\n `Skipped existing: ${report.skipped_existing}`,\n ];\n return lines.join(\"\\n\");\n}\n\nexport function recordInjectionValueEvents(\n db: RecallDb,\n input: {\n memory_ids: readonly string[];\n session_id?: string;\n repo?: string | null;\n pack_tokens_estimate?: number;\n source?: ActivitySource;\n },\n): number {\n if (!input.session_id || input.memory_ids.length === 0) return 0;\n\n const rows = db.select({\n id: memoryInjections.id,\n memory_id: memoryInjections.memory_id,\n })\n .from(memoryInjections)\n .where(and(\n eq(memoryInjections.session_id, input.session_id),\n inArray(memoryInjections.memory_id, [...input.memory_ids]),\n ))\n .all();\n\n const existingValueRows = db.select({\n injection_id: memoryValueEvents.injection_id,\n })\n .from(memoryValueEvents)\n .where(and(\n eq(memoryValueEvents.session_id, input.session_id),\n eq(memoryValueEvents.event_type, \"injected\"),\n ))\n .all();\n const seen = new Set(existingValueRows.map((row) => row.injection_id).filter(Boolean));\n\n let recorded = 0;\n for (const row of rows) {\n if (seen.has(row.id)) continue;\n const memory = getMemory(db, row.memory_id);\n recordMemoryValueEvent(db, {\n memory_id: row.memory_id,\n injection_id: row.id,\n session_id: input.session_id,\n repo: input.repo ?? memory?.repo ?? null,\n event_type: \"injected\",\n source: input.source ?? \"system\",\n injected_tokens_estimate: estimateTokens(memory?.text),\n evidence: {\n matched_memory_text: memory?.text,\n pack_tokens_estimate: input.pack_tokens_estimate,\n },\n });\n recorded += 1;\n }\n return recorded;\n}\n\nexport function recordOutcomeValueEvent(\n db: RecallDb,\n input: {\n memory_id: string;\n session_id: string;\n injected: boolean;\n outcome: FeedbackOutcome;\n feedback_id: string;\n context?: string;\n source: ActivitySource;\n },\n): string {\n const memory = getMemory(db, input.memory_id);\n const injection = input.injected\n ? db.select().from(memoryInjections)\n .where(and(\n eq(memoryInjections.memory_id, input.memory_id),\n eq(memoryInjections.session_id, input.session_id),\n ))\n .get()\n : undefined;\n\n const savedTokens = input.outcome === \"followed\"\n ? estimateTokens(memory?.text)\n : 0;\n\n return recordMemoryValueEvent(db, {\n memory_id: input.memory_id,\n injection_id: injection?.id ?? null,\n feedback_id: input.feedback_id,\n session_id: input.session_id,\n repo: memory?.repo ?? injection?.repo ?? null,\n event_type: input.outcome,\n source: input.source,\n injected_tokens_estimate: 0,\n saved_tokens_estimate: savedTokens,\n evidence: {\n context: input.context,\n matched_memory_text: memory?.text,\n },\n });\n}\n\nexport interface CompletionUseResult {\n recorded: number;\n memory_ids: string[];\n}\n\nexport function recordCompletionUseValueEvents(\n db: RecallDb,\n input: {\n session_id: string;\n completion_text: string;\n repo?: string | null;\n memory_ids?: readonly string[];\n source: ActivitySource;\n },\n): CompletionUseResult {\n const completionText = input.completion_text.trim();\n if (!completionText) return { recorded: 0, memory_ids: [] };\n\n const explicitIds = new Set(input.memory_ids ?? []);\n const candidates = injectedMemoriesForCompletionUse(db, input.session_id, input.memory_ids);\n return recordCompletionUseForCandidates(db, input, candidates, (candidate) => {\n if (explicitIds.has(candidate.id)) {\n return {\n matched: true,\n reason: \"agent explicitly reported using this injected memory\",\n };\n }\n if (completionUsesMemory(completionText, candidate.text)) {\n return {\n matched: true,\n reason: \"assistant completion overlapped an injected memory\",\n };\n }\n return { matched: false };\n });\n}\n\nexport async function recordCompletionUseValueEventsSemantic(\n db: RecallDb,\n input: {\n session_id: string;\n completion_text: string;\n repo?: string | null;\n memory_ids?: readonly string[];\n source: ActivitySource;\n },\n): Promise<CompletionUseResult> {\n const completionText = input.completion_text.trim();\n if (!completionText) return { recorded: 0, memory_ids: [] };\n\n const explicitIds = new Set(input.memory_ids ?? []);\n const candidates = injectedMemoriesForCompletionUse(db, input.session_id, input.memory_ids);\n const semanticScores = await semanticScoresForMemories(db, completionText, candidates);\n return recordCompletionUseForCandidates(db, input, candidates, (candidate) => {\n if (explicitIds.has(candidate.id)) {\n return {\n matched: true,\n reason: \"agent explicitly reported using this injected memory\",\n };\n }\n if (completionUsesMemory(completionText, candidate.text)) {\n return {\n matched: true,\n reason: \"assistant completion overlapped an injected memory\",\n };\n }\n const semantic = semanticScores.get(candidate.id);\n if (semantic != null && semantic >= semanticValueThreshold()) {\n return {\n matched: true,\n reason: \"assistant completion semantically matched an injected memory\",\n semantic_similarity: semantic,\n };\n }\n return { matched: false };\n });\n}\n\nfunction recordCompletionUseForCandidates(\n db: RecallDb,\n input: {\n session_id: string;\n completion_text: string;\n repo?: string | null;\n memory_ids?: readonly string[];\n source: ActivitySource;\n },\n candidates: readonly MemoryItem[],\n matcher: (candidate: MemoryItem) => { matched: boolean; reason?: string; semantic_similarity?: number },\n): CompletionUseResult {\n const completionText = input.completion_text.trim();\n const explicitIds = new Set(input.memory_ids ?? []);\n const selected = new Map<string, MemoryItem>();\n const evidenceById = new Map<string, { reason?: string; semantic_similarity?: number }>();\n for (const candidate of candidates) {\n const match = matcher(candidate);\n if (match.matched) {\n selected.set(candidate.id, candidate);\n evidenceById.set(candidate.id, {\n reason: match.reason,\n semantic_similarity: match.semantic_similarity,\n });\n }\n }\n if (selected.size === 0) return { recorded: 0, memory_ids: [] };\n\n const existingRows = db.select({ memory_id: memoryValueEvents.memory_id })\n .from(memoryValueEvents)\n .where(and(\n eq(memoryValueEvents.session_id, input.session_id),\n eq(memoryValueEvents.event_type, \"used\"),\n inArray(memoryValueEvents.memory_id, [...selected.keys()]),\n ))\n .all();\n const alreadyRecorded = new Set(existingRows.map((row) => row.memory_id).filter(Boolean));\n\n let recorded = 0;\n for (const memory of selected.values()) {\n if (alreadyRecorded.has(memory.id)) continue;\n const evidence = evidenceById.get(memory.id);\n const injection = db.select()\n .from(memoryInjections)\n .where(and(\n eq(memoryInjections.memory_id, memory.id),\n eq(memoryInjections.session_id, input.session_id),\n ))\n .get();\n recordMemoryValueEvent(db, {\n memory_id: memory.id,\n injection_id: injection?.id ?? null,\n session_id: input.session_id,\n repo: memory.repo ?? input.repo ?? null,\n event_type: \"used\",\n source: input.source,\n saved_tokens_estimate: estimateTokens(memory.text),\n evidence: {\n completion_excerpt: excerpt(completionText),\n explicit_memory_ids: input.memory_ids ? [...input.memory_ids] : undefined,\n matched_memory_text: memory.text,\n reason: evidence?.reason ?? (explicitIds.has(memory.id)\n ? \"agent explicitly reported using this injected memory\"\n : \"assistant completion overlapped an injected memory\"),\n semantic_similarity: evidence?.semantic_similarity,\n },\n });\n recorded += 1;\n }\n\n return { recorded, memory_ids: [...selected.keys()] };\n}\n\nexport interface RetrievalMissResult {\n recorded: boolean;\n memory_id: string | null;\n promoted: boolean;\n}\n\nexport function detectAndRecordRetrievalMisses(\n db: RecallDb,\n input: {\n correction_texts: readonly string[];\n prompt_text: string;\n session_id: string;\n repo?: string | null;\n path?: string;\n source: ActivitySource;\n },\n): RetrievalMissResult[] {\n if (input.correction_texts.length === 0) return [];\n\n const injected = listInjectedMemoryIdsForSession(db, input.session_id);\n const candidates = candidateMemoriesForMissDetection(db, input.repo ?? null);\n const out: RetrievalMissResult[] = [];\n\n for (const correctionText of input.correction_texts) {\n const match = bestTextMatch(correctionText, candidates);\n if (!match || match.score < 0.62) continue;\n if (injected.has(match.memory.id)) {\n out.push({ recorded: false, memory_id: match.memory.id, promoted: false });\n continue;\n }\n\n out.push(recordRetrievalMissForMatch(db, {\n ...input,\n correction_text: correctionText,\n injected_memory_ids: [...injected],\n memory: match.memory,\n semantic_similarity: undefined,\n }));\n }\n\n return out;\n}\n\nfunction recordRetrievalMissForMatch(\n db: RecallDb,\n input: {\n correction_text: string;\n prompt_text: string;\n session_id: string;\n repo?: string | null;\n path?: string;\n source: ActivitySource;\n injected_memory_ids: string[];\n memory: MemoryItem;\n semantic_similarity?: number;\n },\n): RetrievalMissResult {\n let promoted = false;\n if (input.memory.status === \"candidate\") {\n promoted = promoteMemory(db, input.memory.id, \"repeat_correction\", {\n type: \"repeated_correction\",\n count: input.memory.repetition_count + 1,\n sessions: [input.session_id],\n timestamp: new Date().toISOString(),\n });\n }\n\n recordMemoryValueEvent(db, {\n memory_id: input.memory.id,\n session_id: input.session_id,\n repo: input.memory.repo ?? input.repo ?? null,\n event_type: \"retrieval_miss\",\n source: input.source,\n saved_tokens_estimate: 0,\n evidence: {\n correction_text: input.correction_text,\n query_text: input.prompt_text,\n prompt_path: input.path,\n matched_memory_text: input.memory.text,\n injected_memory_ids: input.injected_memory_ids,\n semantic_similarity: input.semantic_similarity,\n reason: promoted\n ? \"matching candidate was repeated but not injected; promoted for future turns\"\n : input.semantic_similarity != null\n ? \"matching memory semantically matched a repeated correction but was not injected\"\n : \"matching memory existed but was not injected before the correction repeated\",\n },\n });\n\n return { recorded: true, memory_id: input.memory.id, promoted };\n}\n\nexport async function detectAndRecordRetrievalMissesSemantic(\n db: RecallDb,\n input: {\n correction_texts: readonly string[];\n prompt_text: string;\n session_id: string;\n repo?: string | null;\n path?: string;\n source: ActivitySource;\n },\n): Promise<RetrievalMissResult[]> {\n if (input.correction_texts.length === 0) return [];\n\n const injected = listInjectedMemoryIdsForSession(db, input.session_id);\n const candidates = candidateMemoriesForMissDetection(db, input.repo ?? null);\n const out: RetrievalMissResult[] = [];\n\n for (const correctionText of input.correction_texts) {\n const lexical = bestTextMatch(correctionText, candidates);\n const semantic = await bestSemanticMatch(db, correctionText, candidates);\n const match = betterMatch(lexical, semantic);\n if (!match || match.score < 0.62) continue;\n if (injected.has(match.memory.id)) {\n out.push({ recorded: false, memory_id: match.memory.id, promoted: false });\n continue;\n }\n\n const result = recordRetrievalMissForMatch(db, {\n ...input,\n correction_text: correctionText,\n injected_memory_ids: [...injected],\n memory: match.memory,\n semantic_similarity: match.semantic ? match.score : undefined,\n });\n out.push(result);\n }\n\n return out;\n}\n\nexport interface MemoryValueReport {\n window_start: string;\n window_end: string;\n events_total: number;\n injections: number;\n used: number;\n outcomes: Record<string, number>;\n retrieval_misses: number;\n injected_tokens_estimate: number;\n saved_tokens_estimate: number;\n net_tokens_estimate: number;\n top_savers: Array<{\n memory_id: string;\n text: string;\n saved_tokens_estimate: number;\n used: number;\n followed: number;\n }>;\n}\n\nexport function computeMemoryValueReport(\n db: RecallDb,\n opts: { sinceIso?: string } = {},\n): MemoryValueReport {\n const now = new Date();\n const start = opts.sinceIso ?? new Date(now.getTime() - 14 * 86_400_000).toISOString();\n const end = now.toISOString();\n\n const totals = db.select({\n events_total: sql<number>`count(*)`.as(\"events_total\"),\n injections: sql<number>`sum(case when ${memoryValueEvents.event_type} = 'injected' then 1 else 0 end)`.as(\"injections\"),\n used: sql<number>`sum(case when ${memoryValueEvents.event_type} = 'used' then 1 else 0 end)`.as(\"used\"),\n retrieval_misses: sql<number>`sum(case when ${memoryValueEvents.event_type} = 'retrieval_miss' then 1 else 0 end)`.as(\"retrieval_misses\"),\n injected_tokens_estimate: sql<number>`coalesce(sum(${memoryValueEvents.injected_tokens_estimate}), 0)`.as(\"injected_tokens_estimate\"),\n saved_tokens_estimate: sql<number>`coalesce(sum(${memoryValueEvents.saved_tokens_estimate}), 0)`.as(\"saved_tokens_estimate\"),\n })\n .from(memoryValueEvents)\n .where(gte(memoryValueEvents.created_at, start))\n .get();\n\n const outcomeRows = db.select({\n outcome: memoryValueEvents.event_type,\n count: sql<number>`count(*)`.as(\"count\"),\n })\n .from(memoryValueEvents)\n .where(and(\n gte(memoryValueEvents.created_at, start),\n inArray(memoryValueEvents.event_type, [\"followed\", \"overridden\", \"ignored\", \"contradicted\"]),\n ))\n .groupBy(memoryValueEvents.event_type)\n .all();\n\n const topRows = db.select({\n memory_id: memoryValueEvents.memory_id,\n text: memories.text,\n saved_tokens_estimate: sql<number>`coalesce(sum(${memoryValueEvents.saved_tokens_estimate}), 0)`.as(\"saved_tokens_estimate\"),\n used: sql<number>`sum(case when ${memoryValueEvents.event_type} = 'used' then 1 else 0 end)`.as(\"used\"),\n followed: sql<number>`sum(case when ${memoryValueEvents.event_type} = 'followed' then 1 else 0 end)`.as(\"followed\"),\n })\n .from(memoryValueEvents)\n .leftJoin(memories, eq(memoryValueEvents.memory_id, memories.id))\n .where(and(\n gte(memoryValueEvents.created_at, start),\n inArray(memoryValueEvents.event_type, [\"followed\", \"used\"]),\n ))\n .groupBy(memoryValueEvents.memory_id, memories.text)\n .orderBy(desc(sql`coalesce(sum(${memoryValueEvents.saved_tokens_estimate}), 0)`))\n .limit(5)\n .all();\n\n const outcomes: Record<string, number> = {};\n for (const row of outcomeRows) outcomes[row.outcome] = row.count;\n\n const injectedTokens = Number(totals?.injected_tokens_estimate ?? 0);\n const savedTokens = Number(totals?.saved_tokens_estimate ?? 0);\n\n return {\n window_start: start,\n window_end: end,\n events_total: Number(totals?.events_total ?? 0),\n injections: Number(totals?.injections ?? 0),\n used: Number(totals?.used ?? 0),\n outcomes,\n retrieval_misses: Number(totals?.retrieval_misses ?? 0),\n injected_tokens_estimate: injectedTokens,\n saved_tokens_estimate: savedTokens,\n net_tokens_estimate: savedTokens - injectedTokens,\n top_savers: topRows\n .filter((row) => row.memory_id && row.text)\n .map((row) => ({\n memory_id: row.memory_id!,\n text: row.text!,\n saved_tokens_estimate: Number(row.saved_tokens_estimate ?? 0),\n used: Number(row.used ?? 0),\n followed: Number(row.followed ?? 0),\n })),\n };\n}\n\nfunction candidateMemoriesForMissDetection(\n db: RecallDb,\n repo: string | null,\n): MemoryItem[] {\n const repoMemories = repo ? queryMemories(db, { repo }) : [];\n const globalMemories = queryMemories(db, { scope: \"global\" });\n return [...repoMemories, ...globalMemories]\n .filter((memory, index, rows) =>\n (memory.status === \"active\" || memory.status === \"candidate\") &&\n rows.findIndex((candidate) => candidate.id === memory.id) === index\n );\n}\n\nfunction injectedMemoriesForCompletionUse(\n db: RecallDb,\n sessionId: string,\n memoryIds: readonly string[] | undefined,\n): MemoryItem[] {\n const injectedIds = listInjectedMemoryIdsForSession(db, sessionId);\n const wanted = memoryIds && memoryIds.length > 0\n ? [...new Set(memoryIds)].filter((id) => injectedIds.has(id))\n : [...injectedIds];\n if (wanted.length === 0) return [];\n\n return wanted\n .map((id) => getMemory(db, id))\n .filter((memory): memory is MemoryItem => Boolean(memory));\n}\n\nfunction completionUsesMemory(completionText: string, memoryText: string): boolean {\n const match = textMatchScore(completionText, memoryText);\n return match.score >= 0.62 || (match.intersection >= 3 && match.containment >= 0.6);\n}\n\nasync function bestSemanticMatch(\n db: RecallDb,\n text: string,\n memoriesToCheck: readonly MemoryItem[],\n): Promise<{ memory: MemoryItem; score: number; semantic: true } | null> {\n const scores = await semanticScoresForMemories(db, text, memoriesToCheck);\n let best: { memory: MemoryItem; score: number; semantic: true } | null = null;\n for (const memory of memoriesToCheck) {\n const score = scores.get(memory.id);\n if (score == null) continue;\n if (!best || score > best.score) best = { memory, score, semantic: true };\n }\n return best && best.score >= semanticValueThreshold() ? best : null;\n}\n\nfunction betterMatch(\n lexical: { memory: MemoryItem; score: number } | null,\n semantic: { memory: MemoryItem; score: number; semantic: true } | null,\n): { memory: MemoryItem; score: number; semantic?: true } | null {\n if (!lexical) return semantic;\n if (!semantic) return lexical;\n return semantic.score > lexical.score ? semantic : lexical;\n}\n\nfunction bestTextMatch(\n text: string,\n memoriesToCheck: readonly MemoryItem[],\n): { memory: MemoryItem; score: number } | null {\n let best: { memory: MemoryItem; score: number } | null = null;\n for (const memory of memoriesToCheck) {\n const score = textMatchScore(text, memory.text).score;\n if (!best || score > best.score) best = { memory, score };\n }\n return best;\n}\n\nasync function semanticScoresForMemories(\n db: RecallDb,\n text: string,\n memoriesToCheck: readonly MemoryItem[],\n): Promise<Map<string, number>> {\n const config = loadEmbeddingConfigFromEnv();\n if (!config || memoriesToCheck.length === 0) return new Map();\n\n try {\n const query = await generateEmbedding(text, config, \"query\");\n const scores = new Map<string, number>();\n for (const memory of memoriesToCheck) {\n const stored = loadEmbedding(db, memory.id);\n if (!stored || stored.length !== query.length) continue;\n scores.set(memory.id, cosineSimilarity(query, stored));\n }\n return scores;\n } catch {\n return new Map();\n }\n}\n\nfunction semanticValueThreshold(): number {\n const raw = process.env.RECALL_VALUE_SEMANTIC_THRESHOLD;\n if (!raw) return 0.78;\n const parsed = Number.parseFloat(raw);\n return Number.isFinite(parsed) && parsed >= 0 && parsed <= 1 ? parsed : 0.78;\n}\n\nfunction excerpt(text: string): string {\n const compact = text.replace(/\\s+/g, \" \").trim();\n return compact.length <= 320 ? compact : `${compact.slice(0, 319)}…`;\n}\n","import { and, asc, eq, gt, isNull } from \"drizzle-orm\";\nimport { randomUUID } from \"node:crypto\";\nimport type { RecallDb } from \"../db/client.js\";\nimport { memoryInjections } from \"../db/schema.js\";\nimport type { FeedbackOutcome, MemoryInjection, MemoryItem } from \"../types.js\";\nimport { getMemory } from \"./memory.js\";\nimport type { RecentToolCall } from \"../agents/types.js\";\n\ntype MemoryInjectionRow = typeof memoryInjections.$inferSelect;\n\nexport function recordMemoryInjections(\n db: RecallDb,\n input: {\n memory_ids: readonly string[];\n session_id?: string;\n repo?: string | null;\n },\n): number {\n if (!input.session_id || input.memory_ids.length === 0) return 0;\n\n const injectedAt = new Date().toISOString();\n let inserted = 0;\n for (const memoryId of input.memory_ids) {\n const result = db.insert(memoryInjections)\n .values({\n id: randomUUID(),\n memory_id: memoryId,\n session_id: input.session_id,\n repo: input.repo ?? null,\n injected_at: injectedAt,\n outcome: null,\n outcome_at: null,\n })\n .onConflictDoNothing({\n target: [memoryInjections.memory_id, memoryInjections.session_id],\n })\n .run();\n inserted += Number(result.changes ?? 0);\n }\n\n return inserted;\n}\n\nexport function listInjectedMemoryIdsForSession(\n db: RecallDb,\n sessionId: string,\n): Set<string> {\n const rows = db.select({ memory_id: memoryInjections.memory_id })\n .from(memoryInjections)\n .where(eq(memoryInjections.session_id, sessionId))\n .all();\n return new Set(rows.map((row) => row.memory_id));\n}\n\nexport function listPendingMemoryInjections(\n db: RecallDb,\n sessionId: string,\n): Array<MemoryInjection & { memory: MemoryItem | null }> {\n const rows = db.select()\n .from(memoryInjections)\n .where(and(\n eq(memoryInjections.session_id, sessionId),\n isNull(memoryInjections.outcome),\n ))\n .orderBy(asc(memoryInjections.injected_at))\n .all();\n\n return rows.map((row) => ({\n ...rowToMemoryInjection(row),\n memory: getMemory(db, row.memory_id) ?? null,\n }));\n}\n\nexport function resolveMemoryInjectionOutcome(\n db: RecallDb,\n memoryId: string,\n sessionId: string,\n outcome: FeedbackOutcome,\n): boolean {\n const outcomeAt = new Date().toISOString();\n const result = db.update(memoryInjections)\n .set({\n outcome,\n outcome_at: outcomeAt,\n })\n .where(and(\n eq(memoryInjections.memory_id, memoryId),\n eq(memoryInjections.session_id, sessionId),\n isNull(memoryInjections.outcome),\n ))\n .run();\n\n return Number(result.changes ?? 0) > 0;\n}\n\nexport function listToolCallsSince(\n db: RecallDb,\n sessionId: string,\n injectedAt: string,\n): RecentToolCall[] {\n const rows = db.select()\n .from(memoryInjections)\n .where(gt(memoryInjections.injected_at, injectedAt))\n .all();\n void rows;\n return [];\n}\n\nexport function pathMatchesMemory(mem: MemoryItem, targetPath?: string): boolean {\n // Keep in sync with compiler/context.ts pathMatches(): repo, team, and\n // global memories are path-independent. Omitting global here meant global\n // rules could never resolve as followed/relevant after injection.\n if (!targetPath) return mem.scope === \"repo\" || mem.scope === \"team\" || mem.scope === \"global\";\n if (mem.scope === \"repo\" || mem.scope === \"team\" || mem.scope === \"global\") return true;\n if (!mem.path_scope) return true;\n\n const pattern = mem.path_scope;\n if (pattern.endsWith(\"**\")) {\n return targetPath.startsWith(pattern.slice(0, -2));\n }\n if (pattern.includes(\"*\")) {\n const regex = new RegExp(\n \"^\" + pattern.replace(/\\*/g, \"[^/]*\").replace(/\\*\\*/g, \".*\") + \"$\",\n );\n return regex.test(targetPath);\n }\n return targetPath.startsWith(pattern);\n}\n\nexport function toolCallTouchesMemory(\n mem: MemoryItem,\n toolCall: RecentToolCall,\n): boolean {\n if (toolCall.path && pathMatchesMemory(mem, toolCall.path)) return true;\n if (toolCall.input_summary) {\n const inferredPath = extractPath(toolCall.input_summary);\n if (inferredPath && pathMatchesMemory(mem, inferredPath)) return true;\n }\n return mem.scope === \"repo\" || mem.scope === \"team\" || mem.scope === \"global\";\n}\n\nfunction rowToMemoryInjection(row: MemoryInjectionRow): MemoryInjection {\n return {\n id: row.id,\n memory_id: row.memory_id,\n session_id: row.session_id,\n repo: row.repo,\n injected_at: row.injected_at,\n outcome: row.outcome,\n outcome_at: row.outcome_at,\n };\n}\n\nfunction extractPath(text: string): string | undefined {\n const match = text.match(\n /\\b((?:src|lib|app|components|utils|test|spec)\\/[\\w./-]+|[\\w./-]+\\.(?:ts|tsx|js|jsx|py|rs|go|swift|java|rb|json|toml|ya?ml))\\b/,\n );\n return match?.[1];\n}\n","const STOP_WORDS = new Set([\n \"a\",\n \"an\",\n \"and\",\n \"are\",\n \"as\",\n \"at\",\n \"be\",\n \"by\",\n \"call\",\n \"do\",\n \"for\",\n \"from\",\n \"i\",\n \"in\",\n \"import\",\n \"instead\",\n \"is\",\n \"it\",\n \"its\",\n \"just\",\n \"of\",\n \"on\",\n \"only\",\n \"or\",\n \"our\",\n \"please\",\n \"run\",\n \"that\",\n \"the\",\n \"this\",\n \"to\",\n \"use\",\n \"we\",\n \"with\",\n \"you\",\n \"your\",\n]);\n\nconst NEGATION_WORDS = new Set([\n \"avoid\",\n \"dont\",\n \"forbid\",\n \"forbidden\",\n \"never\",\n \"no\",\n \"not\",\n \"stop\",\n]);\n\nexport interface TextMatchScore {\n score: number;\n jaccard: number;\n containment: number;\n intersection: number;\n left_tokens: string[];\n right_tokens: string[];\n}\n\nexport function textMatches(left: string, right: string, threshold: number): boolean {\n return textMatchScore(left, right).score >= threshold;\n}\n\nexport function textMatchScore(left: string, right: string): TextMatchScore {\n const leftTokens = matchTokens(left);\n const rightTokens = matchTokens(right);\n if (leftTokens.length === 0 || rightTokens.length === 0) {\n return {\n score: 0,\n jaccard: 0,\n containment: 0,\n intersection: 0,\n left_tokens: leftTokens,\n right_tokens: rightTokens,\n };\n }\n\n const leftSet = new Set(leftTokens);\n const rightSet = new Set(rightTokens);\n const intersection = [...leftSet].filter((token) => rightSet.has(token)).length;\n const union = new Set([...leftSet, ...rightSet]).size;\n const jaccard = union === 0 ? 0 : intersection / union;\n const smaller = Math.min(leftSet.size, rightSet.size);\n const containment = smaller === 0 ? 0 : intersection / smaller;\n const containmentWeight = smaller < 2 ? 0 : smaller === 2 ? 0.75 : 0.9;\n const score = Math.max(jaccard, containment * containmentWeight);\n\n return {\n score,\n jaccard,\n containment,\n intersection,\n left_tokens: [...leftSet],\n right_tokens: [...rightSet],\n };\n}\n\nexport function matchTokens(text: string): string[] {\n return text\n .toLowerCase()\n .replace(/\\bdo\\s+not\\b/g, \" not \")\n .replace(/\\bdon['’]?t\\b/g, \" dont \")\n .split(/[^a-z0-9]+/)\n .map(normalizeToken)\n .filter((token) => token.length > 1 && !STOP_WORDS.has(token));\n}\n\nfunction normalizeToken(token: string): string {\n if (NEGATION_WORDS.has(token)) return \"not\";\n if (/^es\\d+$/.test(token)) return \"es\";\n if (token === \"ran\" || token === \"running\" || token === \"runs\") return \"run\";\n if (token === \"using\" || token === \"used\" || token === \"uses\") return \"use\";\n if (token.endsWith(\"ies\") && token.length > 4) return `${token.slice(0, -3)}y`;\n if (token.endsWith(\"ing\") && token.length > 5) return token.slice(0, -3);\n if (token.endsWith(\"ed\") && token.length > 4) return token.slice(0, -2);\n if (token.endsWith(\"s\") && token.length > 3) return token.slice(0, -1);\n return token;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,cAAAA,mBAAkB;;;ACA3B,SAAS,kBAAkB;AASpB,SAAS,uBACd,IACA,OAKQ;AACR,MAAI,CAAC,MAAM,cAAc,MAAM,WAAW,WAAW,EAAG,QAAO;AAE/D,QAAM,cAAa,oBAAI,KAAK,GAAE,YAAY;AAC1C,MAAI,WAAW;AACf,aAAW,YAAY,MAAM,YAAY;AACvC,UAAM,SAAS,GAAG,OAAO,gBAAgB,EACtC,OAAO;AAAA,MACN,IAAI,WAAW;AAAA,MACf,WAAW;AAAA,MACX,YAAY,MAAM;AAAA,MAClB,MAAM,MAAM,QAAQ;AAAA,MACpB,aAAa;AAAA,MACb,SAAS;AAAA,MACT,YAAY;AAAA,IACd,CAAC,EACA,oBAAoB;AAAA,MACnB,QAAQ,CAAC,iBAAiB,WAAW,iBAAiB,UAAU;AAAA,IAClE,CAAC,EACA,IAAI;AACP,gBAAY,OAAO,OAAO,WAAW,CAAC;AAAA,EACxC;AAEA,SAAO;AACT;AAEO,SAAS,gCACd,IACA,WACa;AACb,QAAM,OAAO,GAAG,OAAO,EAAE,WAAW,iBAAiB,UAAU,CAAC,EAC7D,KAAK,gBAAgB,EACrB,MAAM,GAAG,iBAAiB,YAAY,SAAS,CAAC,EAChD,IAAI;AACP,SAAO,IAAI,IAAI,KAAK,IAAI,CAAC,QAAQ,IAAI,SAAS,CAAC;AACjD;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QAAQ,MAAsB;AACrC,QAAM,UAAU,KAAK,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAC/C,SAAO,QAAQ,UAAU,MAAM,UAAU,GAAG,QAAQ,MAAM,GAAG,GAAG,CAAC;AACnE;","names":["randomUUID","randomUUID"]}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
listInjectedHistoryIdsForSession,
|
|
12
12
|
signalOutcomeFallback,
|
|
13
13
|
startSessionLifecycle
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5QN5GGCV.js";
|
|
15
15
|
import {
|
|
16
16
|
detectAndRecordRetrievalMissesSemantic,
|
|
17
17
|
listInjectedMemoryIdsForSession,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
recordCompletionUseValueEventsSemantic,
|
|
21
21
|
textMatches,
|
|
22
22
|
toolCallTouchesMemory
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-WEA6TDEJ.js";
|
|
24
24
|
import {
|
|
25
25
|
detectCorrections,
|
|
26
26
|
isHighRiskRule,
|
|
@@ -1095,4 +1095,4 @@ export {
|
|
|
1095
1095
|
readCodexSessionEndInputFromStdin,
|
|
1096
1096
|
dispatchCodexNotify
|
|
1097
1097
|
};
|
|
1098
|
-
//# sourceMappingURL=chunk-
|
|
1098
|
+
//# sourceMappingURL=chunk-WZGPE3HG.js.map
|
|
@@ -32,10 +32,10 @@ import {
|
|
|
32
32
|
scanAndStore,
|
|
33
33
|
sessionEndFallback,
|
|
34
34
|
signalOutcomeFallback
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-5QN5GGCV.js";
|
|
36
36
|
import {
|
|
37
37
|
recordCompletionUseValueEventsSemantic
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-WEA6TDEJ.js";
|
|
39
39
|
import {
|
|
40
40
|
DEFAULT_LEASE_SECONDS,
|
|
41
41
|
TaskClaimConflictError,
|
|
@@ -1197,4 +1197,4 @@ function createRecallMcpServer(db = initDb()) {
|
|
|
1197
1197
|
export {
|
|
1198
1198
|
createRecallMcpServer
|
|
1199
1199
|
};
|
|
1200
|
-
//# sourceMappingURL=chunk-
|
|
1200
|
+
//# sourceMappingURL=chunk-YLWJKWHH.js.map
|
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
readCodexSessionStartInputFromStdin,
|
|
24
24
|
readCodexToolInputFromStdin,
|
|
25
25
|
restoreBackup
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-WZGPE3HG.js";
|
|
27
27
|
import {
|
|
28
28
|
RECALL_DB_USER_VERSION,
|
|
29
29
|
compileContext,
|
|
@@ -66,8 +66,8 @@ import {
|
|
|
66
66
|
summarizeValueRetrievalEval,
|
|
67
67
|
togglePolicy,
|
|
68
68
|
writeRepoContextArtifact
|
|
69
|
-
} from "./chunk-
|
|
70
|
-
import "./chunk-
|
|
69
|
+
} from "./chunk-5QN5GGCV.js";
|
|
70
|
+
import "./chunk-WEA6TDEJ.js";
|
|
71
71
|
import "./chunk-PUMEMKGF.js";
|
|
72
72
|
import {
|
|
73
73
|
autoResolveContradictions,
|
|
@@ -3051,7 +3051,7 @@ evalCmd.command("value-retrieval").description("Run retrieval eval cases synthes
|
|
|
3051
3051
|
});
|
|
3052
3052
|
let snapshot = null;
|
|
3053
3053
|
if (opts.snapshot) {
|
|
3054
|
-
const { computeQualityReport, recordQualitySnapshot } = await import("./quality-
|
|
3054
|
+
const { computeQualityReport, recordQualitySnapshot } = await import("./quality-RU6SM34C.js");
|
|
3055
3055
|
const qualityReport = computeQualityReport(db, { sinceIso: report.since });
|
|
3056
3056
|
snapshot = recordQualitySnapshot(
|
|
3057
3057
|
db,
|
|
@@ -3864,7 +3864,7 @@ maintenanceCmd.command("quality").description("Show injection outcome distributi
|
|
|
3864
3864
|
recordQualitySnapshot,
|
|
3865
3865
|
listQualitySnapshots,
|
|
3866
3866
|
diffQualitySnapshots
|
|
3867
|
-
} = await import("./quality-
|
|
3867
|
+
} = await import("./quality-RU6SM34C.js");
|
|
3868
3868
|
const db = initDb();
|
|
3869
3869
|
if (opts.history) {
|
|
3870
3870
|
const snaps = listQualitySnapshots(db);
|
|
@@ -3921,6 +3921,22 @@ maintenanceCmd.command("quality").description("Show injection outcome distributi
|
|
|
3921
3921
|
}
|
|
3922
3922
|
console.log(formatQualityReport(report));
|
|
3923
3923
|
});
|
|
3924
|
+
maintenanceCmd.command("value-backfill").description("Backfill memory value events from historical injection outcomes").option("--since <iso>", "Only backfill injections at or after this timestamp").option("--apply", "Persist changes (default is dry-run)").option("--json", "Emit raw JSON report").action(async (opts) => {
|
|
3925
|
+
const {
|
|
3926
|
+
backfillMemoryValueEvents,
|
|
3927
|
+
formatMemoryValueBackfillReport
|
|
3928
|
+
} = await import("./memory-value-N3YHRLO5.js");
|
|
3929
|
+
const db = initDb();
|
|
3930
|
+
const report = backfillMemoryValueEvents(db, {
|
|
3931
|
+
sinceIso: opts.since,
|
|
3932
|
+
dryRun: !opts.apply
|
|
3933
|
+
});
|
|
3934
|
+
if (opts.json) {
|
|
3935
|
+
console.log(JSON.stringify(report, null, 2));
|
|
3936
|
+
return;
|
|
3937
|
+
}
|
|
3938
|
+
console.log(formatMemoryValueBackfillReport(report));
|
|
3939
|
+
});
|
|
3924
3940
|
maintenanceCmd.command("usage").description("Summarize LLM API usage (tokens, cost) across recent maintenance runs").option("--since <iso>", "Window start (default: last 30 days)").option("--limit <n>", "Recent-call rows to show", "10").option("--json", "Emit raw JSON summary").action(async (opts) => {
|
|
3925
3941
|
const { summarizeUsage, formatUsageReport } = await import("./usage-KHOLIR3S.js");
|
|
3926
3942
|
const db = initDb();
|