Skip to content

#1 Persistent memory for AI coding agents based on real-world benchmarks

Preserve recoverable backups for already-suffixed compressed files

JunghwanNA471ccbc61081
diff --git a/src/functions/compress-file.ts b/src/functions/compress-file.ts
index e7a363a6..f339c496 100644
--- a/src/functions/compress-file.ts
+++ b/src/functions/compress-file.ts
@@ -85,7 +85,9 @@ function validateCompression(original: string, compressed: string): string[] {
function resolveBackupPath(filePath: string): string {
const base = basename(filePath, extname(filePath));
- const name = base.endsWith(".original") ? base : `${base}.original`;
+ const name = base.endsWith(".original")
+ ? `${base}.backup`
+ : `${base}.original`;
return join(dirname(filePath), `${name}.md`);
}
diff --git a/test/compress-file.test.ts b/test/compress-file.test.ts
index 8220ed17..a3afc134 100644
--- a/test/compress-file.test.ts
+++ b/test/compress-file.test.ts
@@ -127,4 +127,21 @@ describe("mem::compress-file", () => {
expect(result.details.some((d) => d.includes("url"))).toBe(true);
expect(fileStore.get("/tmp/guide.original.md")).toBeUndefined();
});
+
+ it("uses a distinct backup path for *.original.md inputs", async () => {
+ const path = "/tmp/notes.original.md";
+ fileStore.set(path, "# Title\n\nLong original body.");
+ summarize.mockResolvedValue("# Title\n\nShort body.");
+
+ const result = (await sdk.trigger("mem::compress-file", {
+ filePath: path,
+ })) as { success: boolean; backupPath: string };
+
+ expect(result.success).toBe(true);
+ expect(result.backupPath).toBe("/tmp/notes.original.backup.md");
+ expect(fileStore.get("/tmp/notes.original.backup.md")).toBe(
+ "# Title\n\nLong original body.",
+ );
+ expect(fileStore.get(path)).toBe("# Title\n\nShort body.");
+ });
});