Update project files

This commit is contained in:
2026-05-22 15:00:14 +09:00
parent 132d130ff1
commit 8016ef18fa
29 changed files with 1353 additions and 804 deletions
+10 -1
View File
@@ -17,13 +17,16 @@ export class LongTermMemory {
private store: LongTermStore;
private filePath: string;
private dirty = false;
/** Hard cap on retained entries — oldest are trimmed when exceeded. Default 100 (matches MemoryConfig.longTermMaxEntries). */
private maxEntries: number;
constructor(brainPath: string) {
constructor(brainPath: string, maxEntries = 100) {
const memoryDir = path.join(brainPath, 'memory');
if (!fs.existsSync(memoryDir)) {
fs.mkdirSync(memoryDir, { recursive: true });
}
this.filePath = path.join(memoryDir, 'long_term.json');
this.maxEntries = maxEntries > 0 ? maxEntries : 100;
this.store = this.load();
}
@@ -62,6 +65,12 @@ export class LongTermMemory {
referenceCount: 0
};
this.store.entries.push(entry);
// Enforce the retention cap — drop the oldest entries (by createdAt) once
// over the limit. The store array is append-ordered, so the oldest are at
// the front; we trim from there.
if (this.store.entries.length > this.maxEntries) {
this.store.entries.splice(0, this.store.entries.length - this.maxEntries);
}
this.dirty = true;
this.save();
return entry;