@devflow-tools/memory-engine 0.16.34 → 0.17.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/dist/consolidator.d.ts.map +1 -1
- package/dist/consolidator.js +11 -12
- package/dist/consolidator.js.map +1 -1
- package/dist/event-grouper.d.ts +1 -0
- package/dist/event-grouper.d.ts.map +1 -1
- package/dist/event-grouper.js +18 -13
- package/dist/event-grouper.js.map +1 -1
- package/dist/hybrid-search.d.ts +1 -0
- package/dist/hybrid-search.d.ts.map +1 -1
- package/dist/hybrid-search.js +74 -6
- package/dist/hybrid-search.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-capsule.d.ts +27 -0
- package/dist/memory-capsule.d.ts.map +1 -0
- package/dist/memory-capsule.js +111 -0
- package/dist/memory-capsule.js.map +1 -0
- package/dist/memory-engine.d.ts.map +1 -1
- package/dist/memory-engine.js +75 -34
- package/dist/memory-engine.js.map +1 -1
- package/dist/memory-gate.d.ts +5 -0
- package/dist/memory-gate.d.ts.map +1 -1
- package/dist/memory-gate.js +310 -37
- package/dist/memory-gate.js.map +1 -1
- package/dist/memory-relations.d.ts +3 -0
- package/dist/memory-relations.d.ts.map +1 -0
- package/dist/memory-relations.js +8 -0
- package/dist/memory-relations.js.map +1 -0
- package/dist/memory-relevance.d.ts +4 -0
- package/dist/memory-relevance.d.ts.map +1 -1
- package/dist/memory-relevance.js +27 -6
- package/dist/memory-relevance.js.map +1 -1
- package/dist/memory-store.d.ts +10 -1
- package/dist/memory-store.d.ts.map +1 -1
- package/dist/memory-store.js +78 -21
- package/dist/memory-store.js.map +1 -1
- package/dist/migrations/v12-to-v13.d.ts +3 -0
- package/dist/migrations/v12-to-v13.d.ts.map +1 -0
- package/dist/migrations/v12-to-v13.js +50 -0
- package/dist/migrations/v12-to-v13.js.map +1 -0
- package/dist/semantic-memory-compiler.d.ts +29 -0
- package/dist/semantic-memory-compiler.d.ts.map +1 -0
- package/dist/semantic-memory-compiler.js +148 -0
- package/dist/semantic-memory-compiler.js.map +1 -0
- package/dist/session-summarizer.d.ts +3 -0
- package/dist/session-summarizer.d.ts.map +1 -1
- package/dist/session-summarizer.js.map +1 -1
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-gate.d.ts","sourceRoot":"","sources":["../src/memory-gate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EACpD,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAC5D,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EACxE,iBAAiB,EACjB,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EACtD,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAAwB,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EAAsC,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"memory-gate.d.ts","sourceRoot":"","sources":["../src/memory-gate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EACpD,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAC5D,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EACxE,iBAAiB,EACjB,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EACtD,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAAwB,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EAAsC,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;A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AAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAKpJ,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAK1E,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3D,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAS9D,wBAAwB;IAStC,wFAAwF;IACxF,WAAW,IAAI,IAAI;IAInB,KAAK,IAAI,IAAI;CASd;AA0CD,iBAAS,YAAY,CAAC,KAAK,EAAE;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CAkDT;AAcD,iBAAS,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQnD;AAMD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/memory-gate.js
CHANGED
|
@@ -12,6 +12,8 @@ import { join } from 'node:path';
|
|
|
12
12
|
import { isObservationType, observationDedupKey, } from './observation-types.js';
|
|
13
13
|
import { evaluateObservationQuality } from './observation-quality.js';
|
|
14
14
|
import { mergeSemanticEntities, normalizeEntityKey, normalizeSemanticMemory, } from './semantic-memory.js';
|
|
15
|
+
import { validateEvidenceSpans, validateMemoryCapsules } from './memory-capsule.js';
|
|
16
|
+
import { emitSemanticControlLog } from '@devflow-tools/telemetry';
|
|
15
17
|
const BATCH_CONCEPT_STOP_WORDS = new Set([
|
|
16
18
|
'a', 'an', 'the', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
|
|
17
19
|
'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'should',
|
|
@@ -179,10 +181,12 @@ export class MemoryGate {
|
|
|
179
181
|
if (this.engine && signals.length > 0) {
|
|
180
182
|
try {
|
|
181
183
|
this.engine.recordSignals(signals);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
emitSemanticControlLog({
|
|
185
|
+
event: 'memory.write.completed',
|
|
186
|
+
identity: { projectRoot: this.projectRoot, sessionId: event.sessionId },
|
|
187
|
+
level: 'debug',
|
|
188
|
+
timestamp: Date.now(),
|
|
189
|
+
data: { stage: 'signals', count: signals.length, types: signals.map(signal => signal.type) },
|
|
186
190
|
});
|
|
187
191
|
}
|
|
188
192
|
catch { /* non-critical */ }
|
|
@@ -262,9 +266,9 @@ export class MemoryGate {
|
|
|
262
266
|
.filter(event => sessionId === undefined || event.session_id === sessionId);
|
|
263
267
|
if (events.length === 0)
|
|
264
268
|
return null;
|
|
265
|
-
const groups = groupEventsBySession(events);
|
|
269
|
+
const groups = groupEventsBySession(events, { projectRoot: this.projectRoot });
|
|
266
270
|
const preserveSessionIds = this.getActiveSessionIds(groups);
|
|
267
|
-
const { selected, discarded } = triageGroupsWithDisposition(groups, 8, { preserveSessionIds });
|
|
271
|
+
const { selected, discarded } = triageGroupsWithDisposition(groups, 8, { preserveSessionIds, projectRoot: this.projectRoot });
|
|
268
272
|
const discardedEventIds = discarded.flatMap(group => group.events).map(event => event.id);
|
|
269
273
|
if (discardedEventIds.length > 0) {
|
|
270
274
|
const discardedSessionIds = [...new Set(discarded.flatMap(group => group.events).map(event => event.session_id).filter(Boolean))];
|
|
@@ -382,18 +386,30 @@ export class MemoryGate {
|
|
|
382
386
|
}
|
|
383
387
|
const sourceEvents = engine.store.listAllEvents()
|
|
384
388
|
.filter(event => lease.eventIds.includes(event.id));
|
|
389
|
+
const capsules = validateMemoryCapsules({
|
|
390
|
+
projectRoot: this.projectRoot,
|
|
391
|
+
observations: validObs,
|
|
392
|
+
sourceEvents,
|
|
393
|
+
defaultSourceEventIds: lease.eventIds,
|
|
394
|
+
});
|
|
395
|
+
if (capsules.rejected.length > 0 || capsules.accepted.length !== validObs.length) {
|
|
396
|
+
logInvalidObservationBatch(this.projectRoot, batchId);
|
|
397
|
+
throw new Error(`Distill batch ${batchId} failed semantic capsule validation: ${JSON.stringify(capsules.rejected)}`);
|
|
398
|
+
}
|
|
385
399
|
let committedObservationCount = 0;
|
|
386
400
|
const transaction = this.getStoreDb().transaction(() => {
|
|
387
|
-
for (let index = 0; index <
|
|
388
|
-
const
|
|
401
|
+
for (let index = 0; index < capsules.accepted.length; index++) {
|
|
402
|
+
const acceptedCapsule = capsules.accepted[index];
|
|
403
|
+
const obs = acceptedCapsule.observation;
|
|
404
|
+
const sourceEventIds = acceptedCapsule.capsule.sourceEvidenceIds;
|
|
389
405
|
const quality = evaluateObservationQuality({
|
|
390
406
|
...obs,
|
|
391
407
|
source: 'distill',
|
|
392
|
-
sourceEventIds
|
|
393
|
-
}, sourceEvents);
|
|
408
|
+
sourceEventIds,
|
|
409
|
+
}, sourceEvents.filter(event => sourceEventIds.includes(event.id)));
|
|
394
410
|
const exact = engine.store.findObservationByDedupKey(observationDedupKey(obs.type, obs.title));
|
|
395
411
|
if (exact) {
|
|
396
|
-
engine.store.linkObservationToEvents(exact.id,
|
|
412
|
+
engine.store.linkObservationToEvents(exact.id, sourceEventIds);
|
|
397
413
|
engine.store.incrementObservationAccess(exact.id);
|
|
398
414
|
committedObservationCount += 1;
|
|
399
415
|
continue;
|
|
@@ -422,12 +438,14 @@ export class MemoryGate {
|
|
|
422
438
|
importance: obs.importance ?? 5,
|
|
423
439
|
confidence: obs.confidence,
|
|
424
440
|
source: 'distill',
|
|
425
|
-
sourceEventIds
|
|
441
|
+
sourceEventIds,
|
|
426
442
|
qualityStatus: quality.status,
|
|
427
443
|
quarantineReason: quality.reason,
|
|
428
444
|
qualityDetails: quality.details,
|
|
429
445
|
failureCategory: quality.failureCategory ?? undefined,
|
|
430
446
|
semantic,
|
|
447
|
+
capsule: acceptedCapsule.capsule,
|
|
448
|
+
projection: acceptedCapsule.projection,
|
|
431
449
|
});
|
|
432
450
|
committedObservationCount += 1;
|
|
433
451
|
}
|
|
@@ -437,10 +455,12 @@ export class MemoryGate {
|
|
|
437
455
|
leases.commitLease(batchId);
|
|
438
456
|
});
|
|
439
457
|
transaction();
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
458
|
+
emitSemanticControlLog({
|
|
459
|
+
event: 'memory.write.completed',
|
|
460
|
+
identity: { projectRoot: this.projectRoot, sessionId: lease.sessionIds[0] },
|
|
461
|
+
level: 'info',
|
|
462
|
+
timestamp: Date.now(),
|
|
463
|
+
data: { stage: 'distill_batch', batchId, observationCount: validObs.length, eventsMarked: lease.eventIds.length },
|
|
444
464
|
});
|
|
445
465
|
return validObs.length;
|
|
446
466
|
}
|
|
@@ -483,15 +503,26 @@ export class MemoryGate {
|
|
|
483
503
|
const validObs = validateObservationBatch(observations);
|
|
484
504
|
if (!validObs)
|
|
485
505
|
throw new Error('memory_commit_turn requires at least one valid durable candidate');
|
|
506
|
+
const capsules = validateMemoryCapsules({
|
|
507
|
+
projectRoot: this.projectRoot,
|
|
508
|
+
observations: validObs,
|
|
509
|
+
sourceEvents: [event],
|
|
510
|
+
defaultSourceEventIds: [turnEventId],
|
|
511
|
+
evidenceText: readCanonicalPrompt(event.payload, event.user_message) || undefined,
|
|
512
|
+
});
|
|
513
|
+
if (capsules.rejected.length > 0 || capsules.accepted.length !== validObs.length) {
|
|
514
|
+
throw new Error(`memory_commit_turn failed semantic capsule validation: ${JSON.stringify(capsules.rejected)}`);
|
|
515
|
+
}
|
|
486
516
|
const saved = [];
|
|
487
517
|
const existingIds = new Set(engine.store.listObservations().map(observation => observation.id));
|
|
488
518
|
const turnId = eventTurnId(event, turnEventId);
|
|
489
519
|
this.getStoreDb().transaction(() => {
|
|
490
|
-
for (const
|
|
520
|
+
for (const acceptedCapsule of capsules.accepted) {
|
|
521
|
+
const observation = acceptedCapsule.observation;
|
|
491
522
|
const quality = evaluateObservationQuality({
|
|
492
523
|
...observation,
|
|
493
524
|
source: 'manual',
|
|
494
|
-
sourceEventIds:
|
|
525
|
+
sourceEventIds: acceptedCapsule.capsule.sourceEvidenceIds,
|
|
495
526
|
}, [event]);
|
|
496
527
|
const semantic = normalizeSemanticMemory({
|
|
497
528
|
project: this.projectRoot,
|
|
@@ -523,6 +554,8 @@ export class MemoryGate {
|
|
|
523
554
|
qualityDetails: quality.details,
|
|
524
555
|
failureCategory: quality.failureCategory ?? undefined,
|
|
525
556
|
semantic,
|
|
557
|
+
capsule: acceptedCapsule.capsule,
|
|
558
|
+
projection: acceptedCapsule.projection,
|
|
526
559
|
});
|
|
527
560
|
const row = write.row;
|
|
528
561
|
saved.push({
|
|
@@ -552,6 +585,139 @@ export class MemoryGate {
|
|
|
552
585
|
})();
|
|
553
586
|
return saved;
|
|
554
587
|
}
|
|
588
|
+
async refineExplicitTurnObservations(turnEventId, sessionId, observations) {
|
|
589
|
+
if (!this.engine)
|
|
590
|
+
await this.forceWarmUp();
|
|
591
|
+
const engine = this.requireEngine();
|
|
592
|
+
const event = engine.store.getEvent(turnEventId);
|
|
593
|
+
if (!event || event.session_id !== sessionId) {
|
|
594
|
+
throw new Error(`Memory turn event ${turnEventId} was not found for session ${sessionId}`);
|
|
595
|
+
}
|
|
596
|
+
const sourceText = readCanonicalPrompt(event.payload, event.user_message);
|
|
597
|
+
if (!sourceText)
|
|
598
|
+
throw new Error(`Memory turn event ${turnEventId} has no canonical user prompt`);
|
|
599
|
+
for (const observation of observations) {
|
|
600
|
+
validateEvidenceSpans(sourceText, observation.evidenceSpans ?? []);
|
|
601
|
+
}
|
|
602
|
+
const durableCandidates = observations.filter(observation => observation.disposition !== 'turn_constraint');
|
|
603
|
+
const turnConstraints = observations.filter(observation => observation.disposition === 'turn_constraint');
|
|
604
|
+
const validObs = durableCandidates.length > 0 ? validateObservationBatch(durableCandidates) : [];
|
|
605
|
+
if (!validObs)
|
|
606
|
+
throw new Error('Explicit memory refinement contains invalid durable candidates');
|
|
607
|
+
const capsules = validateMemoryCapsules({
|
|
608
|
+
projectRoot: this.projectRoot,
|
|
609
|
+
observations: validObs,
|
|
610
|
+
sourceEvents: [event],
|
|
611
|
+
defaultSourceEventIds: [turnEventId],
|
|
612
|
+
evidenceText: sourceText,
|
|
613
|
+
requireEvidenceSpans: true,
|
|
614
|
+
});
|
|
615
|
+
if (capsules.rejected.length > 0 || capsules.accepted.length !== validObs.length) {
|
|
616
|
+
throw new Error(`Explicit memory refinement failed evidence validation: ${JSON.stringify(capsules.rejected)}`);
|
|
617
|
+
}
|
|
618
|
+
const existingIds = new Set(engine.store.listObservations().map(observation => observation.id));
|
|
619
|
+
const turnId = eventTurnId(event, turnEventId);
|
|
620
|
+
const memories = [];
|
|
621
|
+
const retiredMemoryIds = [];
|
|
622
|
+
const operations = [];
|
|
623
|
+
this.getStoreDb().transaction(() => {
|
|
624
|
+
for (const acceptedCapsule of capsules.accepted) {
|
|
625
|
+
const observation = acceptedCapsule.observation;
|
|
626
|
+
const semantic = normalizeSemanticMemory({
|
|
627
|
+
project: this.projectRoot,
|
|
628
|
+
type: observation.type,
|
|
629
|
+
title: observation.title,
|
|
630
|
+
narrative: observation.narrative ?? '',
|
|
631
|
+
concepts: observation.concepts,
|
|
632
|
+
subject: observation.subject,
|
|
633
|
+
predicate: observation.predicate,
|
|
634
|
+
value: observation.value,
|
|
635
|
+
polarity: observation.polarity,
|
|
636
|
+
entities: observation.entities,
|
|
637
|
+
temporal: observation.temporal,
|
|
638
|
+
});
|
|
639
|
+
const write = engine.store.acceptSemanticObservation({
|
|
640
|
+
sessionId,
|
|
641
|
+
project: this.projectRoot,
|
|
642
|
+
type: observation.type,
|
|
643
|
+
title: observation.title,
|
|
644
|
+
narrative: observation.narrative,
|
|
645
|
+
facts: [...new Set([...(observation.facts ?? []), ...(observation.evidenceSpans ?? [])])],
|
|
646
|
+
concepts: mergeSemanticEntities(normalizeBatchConcepts(observation), [semantic.subject, semantic.predicate, semantic.value], semantic.entities.map(normalizeEntityKey)),
|
|
647
|
+
importance: Math.max(8, observation.importance),
|
|
648
|
+
confidence: Math.max(0.9, observation.confidence),
|
|
649
|
+
source: 'explicit_intent',
|
|
650
|
+
sourceEventIds: [turnEventId],
|
|
651
|
+
qualityStatus: 'accepted',
|
|
652
|
+
evidenceStatus: 'verified',
|
|
653
|
+
evidenceDetails: (observation.evidenceSpans ?? []).map(span => ({
|
|
654
|
+
kind: 'host_evidence_span',
|
|
655
|
+
source: turnEventId,
|
|
656
|
+
summary: span,
|
|
657
|
+
})),
|
|
658
|
+
semantic,
|
|
659
|
+
capsule: acceptedCapsule.capsule,
|
|
660
|
+
projection: acceptedCapsule.projection,
|
|
661
|
+
preferIncomingNarrative: true,
|
|
662
|
+
});
|
|
663
|
+
const row = write.row;
|
|
664
|
+
operations.push(write.action.toLocaleLowerCase('en-US'));
|
|
665
|
+
memories.push({
|
|
666
|
+
id: row.id,
|
|
667
|
+
type: row.type,
|
|
668
|
+
title: row.title,
|
|
669
|
+
content: row.narrative,
|
|
670
|
+
source: row.source,
|
|
671
|
+
scope: row.project,
|
|
672
|
+
confidence: row.confidence,
|
|
673
|
+
importance: row.importance,
|
|
674
|
+
score: 1,
|
|
675
|
+
createdAt: row.timestamp,
|
|
676
|
+
indexStatus: row.embedding ? 'indexed' : 'pending',
|
|
677
|
+
});
|
|
678
|
+
engine.store.recordPendingTurnObservation({
|
|
679
|
+
turnEventId,
|
|
680
|
+
turnId,
|
|
681
|
+
sessionId,
|
|
682
|
+
project: this.projectRoot,
|
|
683
|
+
observationId: row.id,
|
|
684
|
+
createdByTurn: !existingIds.has(row.id),
|
|
685
|
+
createdAt: event.created_at,
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
const constraintSpans = turnConstraints.flatMap(candidate => candidate.evidenceSpans ?? []);
|
|
689
|
+
const baseline = engine.store.listObservations({ project: this.projectRoot })
|
|
690
|
+
.filter(observation => observation.source === 'explicit_intent')
|
|
691
|
+
.filter(observation => parseLearningStringArray(observation.source_event_ids).includes(turnEventId));
|
|
692
|
+
for (const observation of baseline) {
|
|
693
|
+
if (!constraintSpans.some(span => sameGroundedClause(observation.narrative, span)))
|
|
694
|
+
continue;
|
|
695
|
+
if (engine.store.quarantineObservation(observation.id, 'host_classified_turn_constraint', {
|
|
696
|
+
turnId,
|
|
697
|
+
eventId: turnEventId,
|
|
698
|
+
evidenceSpans: constraintSpans,
|
|
699
|
+
})) {
|
|
700
|
+
retiredMemoryIds.push(observation.id);
|
|
701
|
+
operations.push('retire');
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
})();
|
|
705
|
+
emitSemanticControlLog({
|
|
706
|
+
event: 'memory.semantic.refined',
|
|
707
|
+
identity: { projectRoot: this.projectRoot, sessionId, turnId },
|
|
708
|
+
level: 'info',
|
|
709
|
+
timestamp: Date.now(),
|
|
710
|
+
data: {
|
|
711
|
+
candidateCount: observations.length,
|
|
712
|
+
durableCount: durableCandidates.length,
|
|
713
|
+
turnConstraintCount: turnConstraints.length,
|
|
714
|
+
memoryIds: memories.map(memory => memory.id),
|
|
715
|
+
retiredMemoryIds,
|
|
716
|
+
operations,
|
|
717
|
+
},
|
|
718
|
+
});
|
|
719
|
+
return { memories, retiredMemoryIds, operations };
|
|
720
|
+
}
|
|
555
721
|
async skipTurnEvent(turnEventId, sessionId, reason) {
|
|
556
722
|
if (!this.engine)
|
|
557
723
|
await this.forceWarmUp();
|
|
@@ -612,7 +778,13 @@ export class MemoryGate {
|
|
|
612
778
|
* @deprecated Use saveDistilledObservationsByBatch(batchId, observations) instead.
|
|
613
779
|
*/
|
|
614
780
|
async saveDistilledObservations(observations, sessionId) {
|
|
615
|
-
|
|
781
|
+
emitSemanticControlLog({
|
|
782
|
+
event: 'memory.write.degraded',
|
|
783
|
+
identity: { projectRoot: this.projectRoot, sessionId },
|
|
784
|
+
level: 'warn',
|
|
785
|
+
timestamp: Date.now(),
|
|
786
|
+
data: { stage: 'legacy_distill', reason: 'deprecated_session_write', fallback: 'legacy_compatibility_path' },
|
|
787
|
+
});
|
|
616
788
|
if (!this.engine)
|
|
617
789
|
return 0;
|
|
618
790
|
const validObs = validateObservationBatch(observations);
|
|
@@ -657,10 +829,12 @@ export class MemoryGate {
|
|
|
657
829
|
engine.store.markEventsProcessed(unprocessedIds);
|
|
658
830
|
});
|
|
659
831
|
transaction();
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
832
|
+
emitSemanticControlLog({
|
|
833
|
+
event: 'memory.write.completed',
|
|
834
|
+
identity: { projectRoot: this.projectRoot, sessionId },
|
|
835
|
+
level: 'info',
|
|
836
|
+
timestamp: Date.now(),
|
|
837
|
+
data: { stage: 'legacy_distill', observationCount: validObs.length, eventsMarked: unprocessedIds.length },
|
|
664
838
|
});
|
|
665
839
|
return validObs.length;
|
|
666
840
|
}
|
|
@@ -689,11 +863,12 @@ export class MemoryGate {
|
|
|
689
863
|
const events = this.engine.store.getUnprocessedEvents();
|
|
690
864
|
if (events.length === 0)
|
|
691
865
|
return 0;
|
|
692
|
-
const groups = groupEventsBySession(events, { log: false });
|
|
866
|
+
const groups = groupEventsBySession(events, { log: false, projectRoot: this.projectRoot });
|
|
693
867
|
const preserveSessionIds = this.getActiveSessionIds(groups);
|
|
694
868
|
const { discarded } = triageGroupsWithDisposition(groups, Number.MAX_SAFE_INTEGER, {
|
|
695
869
|
log: false,
|
|
696
870
|
preserveSessionIds,
|
|
871
|
+
projectRoot: this.projectRoot,
|
|
697
872
|
});
|
|
698
873
|
const ids = discarded.flatMap(group => group.events).map(event => event.id);
|
|
699
874
|
return this.engine.store.discardEvents(ids, 'low_value_auto_triage', `auto-triage:${Date.now()}`);
|
|
@@ -726,7 +901,10 @@ export class MemoryGate {
|
|
|
726
901
|
this.projectValid = true;
|
|
727
902
|
}
|
|
728
903
|
this.state = 'warming';
|
|
729
|
-
|
|
904
|
+
emitSemanticControlLog({
|
|
905
|
+
event: 'memory.engine.transitioned', identity: { projectRoot: this.projectRoot }, level: 'info', timestamp: Date.now(),
|
|
906
|
+
data: { from: 'cold', to: 'warming' },
|
|
907
|
+
});
|
|
730
908
|
this.engine = new MemoryEngine(this.projectRoot, this.embedder);
|
|
731
909
|
this.setLeaseStore(new LeaseStore(this.getStoreDb()));
|
|
732
910
|
// Clean up zombie sessions (>24h active)
|
|
@@ -734,7 +912,13 @@ export class MemoryGate {
|
|
|
734
912
|
const zombies = this.engine.store.getZombieSessions(24);
|
|
735
913
|
for (const z of zombies) {
|
|
736
914
|
this.engine.store.closeSession(z.id);
|
|
737
|
-
|
|
915
|
+
emitSemanticControlLog({
|
|
916
|
+
event: 'memory.engine.transitioned',
|
|
917
|
+
identity: { projectRoot: this.projectRoot, sessionId: z.id },
|
|
918
|
+
level: 'warn',
|
|
919
|
+
timestamp: Date.now(),
|
|
920
|
+
data: { from: 'active', to: 'closed', reason: 'zombie_session', ageHours: Math.round((Date.now() - z.created_at) / 3600000) },
|
|
921
|
+
});
|
|
738
922
|
}
|
|
739
923
|
}
|
|
740
924
|
catch { /* non-critical */ }
|
|
@@ -744,7 +928,10 @@ export class MemoryGate {
|
|
|
744
928
|
}
|
|
745
929
|
catch { /* non-critical */ }
|
|
746
930
|
this.state = 'hot';
|
|
747
|
-
|
|
931
|
+
emitSemanticControlLog({
|
|
932
|
+
event: 'memory.engine.transitioned', identity: { projectRoot: this.projectRoot }, level: 'info', timestamp: Date.now(),
|
|
933
|
+
data: { from: 'warming', to: 'hot' },
|
|
934
|
+
});
|
|
748
935
|
}
|
|
749
936
|
// --- IMemoryEngine implementation (delegates to engine when hot) ---
|
|
750
937
|
requireEngine() {
|
|
@@ -827,7 +1014,28 @@ export class MemoryGate {
|
|
|
827
1014
|
async saveExplicitMemoryIntent(content, sessionId, sourceEventId) {
|
|
828
1015
|
if (!this.engine)
|
|
829
1016
|
await this.forceWarmUp();
|
|
830
|
-
|
|
1017
|
+
try {
|
|
1018
|
+
const result = await this.requireEngine().saveExplicitMemoryIntent(content, sessionId, sourceEventId);
|
|
1019
|
+
emitSemanticControlLog({
|
|
1020
|
+
event: 'memory.write.completed',
|
|
1021
|
+
identity: { projectRoot: this.projectRoot, sessionId },
|
|
1022
|
+
level: 'info',
|
|
1023
|
+
timestamp: Date.now(),
|
|
1024
|
+
data: {
|
|
1025
|
+
stage: 'explicit_memory', memoryId: result.id, relatedMemoryIds: result.relatedMemoryIds ?? [],
|
|
1026
|
+
semanticStatus: result.semanticDecision?.status,
|
|
1027
|
+
operations: result.semanticDecision?.operations ?? [],
|
|
1028
|
+
},
|
|
1029
|
+
});
|
|
1030
|
+
return result;
|
|
1031
|
+
}
|
|
1032
|
+
catch (error) {
|
|
1033
|
+
emitSemanticControlLog({
|
|
1034
|
+
event: 'memory.write.degraded', identity: { projectRoot: this.projectRoot, sessionId }, level: 'error', timestamp: Date.now(),
|
|
1035
|
+
data: { stage: 'explicit_memory', reason: memoryErrorReason(error) },
|
|
1036
|
+
});
|
|
1037
|
+
throw error;
|
|
1038
|
+
}
|
|
831
1039
|
}
|
|
832
1040
|
async enrichExplicitMemoryObservation(observationId) {
|
|
833
1041
|
if (!this.engine)
|
|
@@ -897,15 +1105,28 @@ export class MemoryGate {
|
|
|
897
1105
|
const rows = engine.store.listObservationsMissingEmbedding(batchSize, lastId);
|
|
898
1106
|
if (rows.length === 0)
|
|
899
1107
|
break;
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
1108
|
+
const texts = rows.map(row => `${row.title}\n${row.narrative}`);
|
|
1109
|
+
let indexed = [];
|
|
1110
|
+
try {
|
|
1111
|
+
const embeddings = await this.embedder.embedBatch(texts);
|
|
1112
|
+
if (embeddings.length !== rows.length) {
|
|
1113
|
+
throw new Error(`Observation vector count mismatch: ${rows.length} observations, ${embeddings.length} vectors`);
|
|
1114
|
+
}
|
|
1115
|
+
indexed = rows.map((row, index) => ({ id: row.id, embedding: embeddings[index] }));
|
|
1116
|
+
}
|
|
1117
|
+
catch {
|
|
1118
|
+
for (let index = 0; index < rows.length; index++) {
|
|
1119
|
+
try {
|
|
1120
|
+
indexed.push({ id: rows[index].id, embedding: await this.embedder.embed(texts[index]) });
|
|
1121
|
+
}
|
|
1122
|
+
catch {
|
|
1123
|
+
// Keep this observation pending; deterministic retrieval remains available.
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
903
1126
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
})));
|
|
908
|
-
processed += rows.length;
|
|
1127
|
+
if (indexed.length > 0)
|
|
1128
|
+
engine.store.insertObservationEmbeddings(indexed);
|
|
1129
|
+
processed += indexed.length;
|
|
909
1130
|
lastId = rows.at(-1).id;
|
|
910
1131
|
const coverage = engine.store.countObservationVectors();
|
|
911
1132
|
options.onProgress?.({ processed, remaining: coverage.missing, lastId });
|
|
@@ -937,7 +1158,38 @@ export class MemoryGate {
|
|
|
937
1158
|
async search(query, options) {
|
|
938
1159
|
if (!this.engine)
|
|
939
1160
|
await this.forceWarmUp();
|
|
940
|
-
|
|
1161
|
+
const startedAt = Date.now();
|
|
1162
|
+
try {
|
|
1163
|
+
const results = await this.requireEngine().search(query, options);
|
|
1164
|
+
emitSemanticControlLog({
|
|
1165
|
+
event: 'memory.search.completed',
|
|
1166
|
+
identity: {
|
|
1167
|
+
projectRoot: this.projectRoot,
|
|
1168
|
+
sessionId: options?.sessionId,
|
|
1169
|
+
executionId: options?.executionId,
|
|
1170
|
+
requestId: options?.requestId,
|
|
1171
|
+
},
|
|
1172
|
+
level: 'info',
|
|
1173
|
+
timestamp: Date.now(),
|
|
1174
|
+
data: {
|
|
1175
|
+
status: results.length > 0 ? 'selected' : 'empty', selected: results.length,
|
|
1176
|
+
verified: results.filter(result => result.entry.status === 'approved').length,
|
|
1177
|
+
durationMs: Date.now() - startedAt,
|
|
1178
|
+
vectorReady: results.filter(result => (result.scoreDetails?.semanticScore ?? 0) > 0).length,
|
|
1179
|
+
},
|
|
1180
|
+
});
|
|
1181
|
+
return results;
|
|
1182
|
+
}
|
|
1183
|
+
catch (error) {
|
|
1184
|
+
emitSemanticControlLog({
|
|
1185
|
+
event: 'memory.search.completed',
|
|
1186
|
+
identity: { projectRoot: this.projectRoot, sessionId: options?.sessionId, executionId: options?.executionId, requestId: options?.requestId },
|
|
1187
|
+
level: 'error',
|
|
1188
|
+
timestamp: Date.now(),
|
|
1189
|
+
data: { status: 'failed', selected: 0, durationMs: Date.now() - startedAt, reason: memoryErrorReason(error) },
|
|
1190
|
+
});
|
|
1191
|
+
throw error;
|
|
1192
|
+
}
|
|
941
1193
|
}
|
|
942
1194
|
async listMemories(filter) {
|
|
943
1195
|
if (!this.engine)
|
|
@@ -1043,6 +1295,24 @@ function eventTurnId(event, fallbackEventId) {
|
|
|
1043
1295
|
}
|
|
1044
1296
|
return `turn:${fallbackEventId}`;
|
|
1045
1297
|
}
|
|
1298
|
+
function readCanonicalPrompt(payloadJson, userMessage) {
|
|
1299
|
+
if (payloadJson) {
|
|
1300
|
+
try {
|
|
1301
|
+
const payload = JSON.parse(payloadJson);
|
|
1302
|
+
if (typeof payload.prompt === 'string' && payload.prompt.trim())
|
|
1303
|
+
return payload.prompt.trim();
|
|
1304
|
+
}
|
|
1305
|
+
catch { }
|
|
1306
|
+
}
|
|
1307
|
+
return userMessage?.trim() ?? '';
|
|
1308
|
+
}
|
|
1309
|
+
function sameGroundedClause(narrative, evidenceSpan) {
|
|
1310
|
+
const left = narrative.normalize('NFKC').trim().toLocaleLowerCase('en-US');
|
|
1311
|
+
const right = evidenceSpan.normalize('NFKC').trim().toLocaleLowerCase('en-US');
|
|
1312
|
+
if (left.length < 4 || right.length < 4)
|
|
1313
|
+
return false;
|
|
1314
|
+
return left === right || (right.includes(left) && left.length / right.length >= 0.7);
|
|
1315
|
+
}
|
|
1046
1316
|
// --- L1 Rule Scorer (backward compat) ---
|
|
1047
1317
|
function scoreL1Rules(event) {
|
|
1048
1318
|
let score = 0;
|
|
@@ -1104,5 +1374,8 @@ function scoreDialogSignals(message) {
|
|
|
1104
1374
|
}
|
|
1105
1375
|
return maxScore;
|
|
1106
1376
|
}
|
|
1377
|
+
function memoryErrorReason(error) {
|
|
1378
|
+
return (error instanceof Error ? error.message : String(error)).trim().slice(0, 500) || 'memory_operation_failed';
|
|
1379
|
+
}
|
|
1107
1380
|
export { scoreL1Rules, scoreDialogSignals };
|
|
1108
1381
|
//# sourceMappingURL=memory-gate.js.map
|