fix(memory): use auto-incrementing id as tick proxy for recency scoring

Events recorded with tick: 0 now get a meaningful tick value from the
service's internal counter, ensuring selectForPrompt recency scoring
works correctly. Also fixed preferTypes to accept readonly arrays.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-08 22:09:01 +00:00
parent ccb53d8a17
commit ce2caa4ae1
2 changed files with 6 additions and 3 deletions
+5 -2
View File
@@ -6,7 +6,7 @@ export interface EventMemoryService {
getRecentEvents(entityId: EntityId, count: number): MemoryEvent[];
selectForPrompt(entityId: EntityId, opts: {
maxCount: number;
preferTypes?: MemoryEventType[];
preferTypes?: readonly MemoryEventType[];
preferEntityId?: EntityId;
}): MemoryEvent[];
onEventRecorded: ((entityId: EntityId, event: MemoryEvent) => void) | null;
@@ -29,9 +29,12 @@ export function createEventMemoryService(maxEvents = 50): EventMemoryService {
onEventRecorded: null,
record(entityId: EntityId, eventData: Omit<MemoryEvent, 'id'>): MemoryEvent {
const id = nextId++;
const event: MemoryEvent = {
id: nextId++,
id,
...eventData,
// Use auto-incrementing id as tick proxy when caller passes 0
tick: eventData.tick || id,
};
const buf = getBuffer(entityId);
+1 -1
View File
@@ -166,7 +166,7 @@ function describeRecentEvents(
const events = eventMemoryService.selectForPrompt(entityId, {
maxCount: 5,
preferTypes: preferTypes as any,
preferTypes,
});
if (events.length > 0) {
return events.map(e => `- ${e.detail}`).join('\n');