mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
fix(memory): standardize DREAMS trail path
This commit is contained in:
@@ -138,32 +138,6 @@ describe("dreaming markdown storage", () => {
|
||||
expect(content.match(/## 2026-04-05 - REM Sleep/g)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("migrates legacy dreams.md to canonical DREAMS.md on the next inline write", async () => {
|
||||
const workspaceDir = await createTempWorkspace();
|
||||
const legacyPath = path.join(workspaceDir, "dreams.md");
|
||||
await fs.writeFile(legacyPath, "## 2026-04-04 - Light Sleep\nlegacy\n", "utf-8");
|
||||
|
||||
await writeDailyDreamingPhaseBlock({
|
||||
workspaceDir,
|
||||
phase: "light",
|
||||
bodyLines: ["- Candidate: migrated forward"],
|
||||
nowMs: Date.parse("2026-04-05T10:00:00Z"),
|
||||
timezone: "UTC",
|
||||
storage: {
|
||||
mode: "inline",
|
||||
separateReports: false,
|
||||
},
|
||||
});
|
||||
|
||||
const canonicalPath = path.join(workspaceDir, "DREAMS.md");
|
||||
const content = await fs.readFile(canonicalPath, "utf-8");
|
||||
expect(content).toContain("## 2026-04-04 - Light Sleep");
|
||||
expect(content).toContain("## 2026-04-05 - Light Sleep");
|
||||
const workspaceEntries = await fs.readdir(workspaceDir);
|
||||
expect(workspaceEntries).toContain("DREAMS.md");
|
||||
expect(workspaceEntries).not.toContain("dreams.md");
|
||||
});
|
||||
|
||||
it("still writes deep reports to the per-phase report directory", async () => {
|
||||
const workspaceDir = await createTempWorkspace();
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ const DAILY_PHASE_LABELS: Record<Exclude<MemoryDreamingPhaseName, "deep">, strin
|
||||
};
|
||||
|
||||
const DREAMS_FILENAME = "DREAMS.md";
|
||||
const LEGACY_DREAMS_FILENAME = "dreams.md";
|
||||
|
||||
function resolvePhaseMarkers(
|
||||
phase: Exclude<MemoryDreamingPhaseName, "deep">,
|
||||
@@ -62,44 +61,6 @@ function resolveDreamsPath(workspaceDir: string): string {
|
||||
return path.join(workspaceDir, DREAMS_FILENAME);
|
||||
}
|
||||
|
||||
function resolveLegacyDreamsPath(workspaceDir: string): string {
|
||||
return path.join(workspaceDir, LEGACY_DREAMS_FILENAME);
|
||||
}
|
||||
|
||||
async function pathExists(targetPath: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.access(targetPath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function listWorkspaceEntries(workspaceDir: string): Promise<Set<string>> {
|
||||
try {
|
||||
return new Set(await fs.readdir(workspaceDir));
|
||||
} catch {
|
||||
return new Set<string>();
|
||||
}
|
||||
}
|
||||
|
||||
async function prepareDreamsPathForWrite(workspaceDir: string): Promise<string> {
|
||||
const dreamsPath = resolveDreamsPath(workspaceDir);
|
||||
const workspaceEntries = await listWorkspaceEntries(workspaceDir);
|
||||
if (workspaceEntries.has(DREAMS_FILENAME)) {
|
||||
return dreamsPath;
|
||||
}
|
||||
const legacyDreamsPath = resolveLegacyDreamsPath(workspaceDir);
|
||||
if (dreamsPath !== legacyDreamsPath && workspaceEntries.has(LEGACY_DREAMS_FILENAME)) {
|
||||
await fs.rename(legacyDreamsPath, dreamsPath);
|
||||
return dreamsPath;
|
||||
}
|
||||
if (await pathExists(dreamsPath)) {
|
||||
return dreamsPath;
|
||||
}
|
||||
return dreamsPath;
|
||||
}
|
||||
|
||||
function resolveDreamsBlockHeading(
|
||||
phase: Exclude<MemoryDreamingPhaseName, "deep">,
|
||||
isoDay: string,
|
||||
@@ -140,7 +101,7 @@ export async function writeDailyDreamingPhaseBlock(params: {
|
||||
let reportPath: string | undefined;
|
||||
|
||||
if (shouldWriteInline(params.storage)) {
|
||||
inlinePath = await prepareDreamsPathForWrite(params.workspaceDir);
|
||||
inlinePath = resolveDreamsPath(params.workspaceDir);
|
||||
const original = await fs.readFile(inlinePath, "utf-8").catch((err: unknown) => {
|
||||
if ((err as NodeJS.ErrnoException)?.code === "ENOENT") {
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user