增加历史版本保存功能
This commit is contained in:
+14
-3
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
||||
import { config } from "../config.js";
|
||||
import { sanitizePersistentLine } from "../utils/persistencePolicy.js";
|
||||
import {
|
||||
atomicWriteFile,
|
||||
atomicWriteFileWithHistory,
|
||||
ensureDirectory,
|
||||
readTextFile,
|
||||
} from "../utils/fileStore.js";
|
||||
@@ -37,12 +37,16 @@ const SUSPICIOUS_MEMORY_PATTERNS = [
|
||||
export class MemoryStore {
|
||||
private writeQueue: Promise<void> = Promise.resolve();
|
||||
|
||||
constructor(private readonly baseDir = config.MEMORY_STORAGE_DIR) {}
|
||||
constructor(
|
||||
private readonly baseDir = config.MEMORY_STORAGE_DIR,
|
||||
private readonly historyDir = join(config.PERSISTENCE_HISTORY_DIR, "memory"),
|
||||
) {}
|
||||
|
||||
async initialize() {
|
||||
await ensureDirectory(this.baseDir);
|
||||
await ensureDirectory(join(this.baseDir, "users"));
|
||||
await ensureDirectory(join(this.baseDir, "workspaces"));
|
||||
await ensureDirectory(this.historyDir);
|
||||
}
|
||||
|
||||
async upsert(scope: MemoryScope, key: string, draft: MemoryDraft) {
|
||||
@@ -60,7 +64,14 @@ export class MemoryStore {
|
||||
|
||||
const entry: MemoryEntry = { content };
|
||||
entries.unshift(entry);
|
||||
await atomicWriteFile(this.filePath(scope, key), renderMemoryMarkdown(scope, entries));
|
||||
await atomicWriteFileWithHistory(
|
||||
this.filePath(scope, key),
|
||||
renderMemoryMarkdown(scope, entries),
|
||||
{
|
||||
historyDir: this.historyDir,
|
||||
rootDir: this.baseDir,
|
||||
},
|
||||
);
|
||||
return { changed: true, entry };
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user