feat: sync memory with filesystem tree (#685)

Co-authored-by: Letta <noreply@letta.com>
Co-authored-by: cpacker <packercharles@gmail.com>
This commit is contained in:
Kevin Lin
2026-01-26 21:48:57 -08:00
committed by GitHub
parent 57f99b906b
commit 7ab97e404d
16 changed files with 1815 additions and 249 deletions

View File

@@ -24,6 +24,12 @@ import {
} from "./agent/context";
import { createAgent } from "./agent/create";
import { ensureSkillsBlocks, ISOLATED_BLOCK_LABELS } from "./agent/memory";
import {
ensureMemoryFilesystemBlock,
formatMemorySyncSummary,
syncMemoryFilesystem,
updateMemoryFilesystemBlock,
} from "./agent/memoryFilesystem";
import { sendMessageStream } from "./agent/message";
import { getModelUpdateArgs } from "./agent/model";
import { SessionStats } from "./agent/stats";
@@ -580,6 +586,36 @@ export async function handleHeadlessCommand(
}
}
// Sync filesystem-backed memory before creating conversations (only if memfs is enabled)
if (settingsManager.isMemfsEnabled(agent.id)) {
try {
await ensureMemoryFilesystemBlock(agent.id);
const syncResult = await syncMemoryFilesystem(agent.id);
if (syncResult.conflicts.length > 0) {
console.error(
`Memory filesystem sync conflicts detected (${syncResult.conflicts.length}). Run in interactive mode to resolve.`,
);
process.exit(1);
}
await updateMemoryFilesystemBlock(agent.id);
if (
syncResult.updatedBlocks.length > 0 ||
syncResult.createdBlocks.length > 0 ||
syncResult.deletedBlocks.length > 0 ||
syncResult.updatedFiles.length > 0 ||
syncResult.createdFiles.length > 0 ||
syncResult.deletedFiles.length > 0
) {
console.log(formatMemorySyncSummary(syncResult));
}
} catch (error) {
console.error(
`Memory filesystem sync failed: ${error instanceof Error ? error.message : String(error)}`,
);
process.exit(1);
}
}
// Determine which blocks to isolate for the conversation
let isolatedBlockLabels: string[] = [];
if (!noSkillsFlag) {