
























@@ -72,6 +72,7 @@ type RunPhaseIfTriggeredParams = {
7272);
7373const LIGHT_SLEEP_EVENT_TEXT = "__openclaw_memory_core_light_sleep__";
7474const REM_SLEEP_EVENT_TEXT = "__openclaw_memory_core_rem_sleep__";
75+const MEMORY_DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
7576const DAILY_MEMORY_FILENAME_RE = /^(\d{4}-\d{2}-\d{2})\.md$/;
7677const DAILY_INGESTION_STATE_RELATIVE_PATH = path.join("memory", ".dreams", "daily-ingestion.json");
7778const DAILY_INGESTION_SCORE = 0.62;
@@ -386,6 +387,7 @@ type DailyIngestionBatch = {
386387type DailyIngestionFileState = {
387388mtimeMs: number;
388389size: number;
390+lastDreamingDayIngested?: string;
389391};
390392391393type DailyIngestionState = {
@@ -417,9 +419,11 @@ function normalizeDailyIngestionState(raw: unknown): DailyIngestionState {
417419if (!Number.isFinite(mtimeMs) || mtimeMs < 0 || !Number.isFinite(size) || size < 0) {
418420continue;
419421}
422+const lastDreamingDayIngested = normalizeMemoryDay(file.lastDreamingDayIngested);
420423files[key] = {
421424mtimeMs: Math.floor(mtimeMs),
422425size: Math.floor(size),
426+ ...(lastDreamingDayIngested ? { lastDreamingDayIngested } : {}),
423427};
424428}
425429return {
@@ -428,6 +432,14 @@ function normalizeDailyIngestionState(raw: unknown): DailyIngestionState {
428432};
429433}
430434435+function normalizeMemoryDay(value: unknown): string | undefined {
436+if (typeof value !== "string") {
437+return undefined;
438+}
439+const day = value.trim();
440+return MEMORY_DAY_RE.test(day) ? day : undefined;
441+}
442+431443async function readDailyIngestionState(workspaceDir: string): Promise<DailyIngestionState> {
432444const statePath = resolveDailyIngestionStatePath(workspaceDir);
433445try {
@@ -1065,6 +1077,7 @@ async function collectDailyIngestionBatches(params: {
10651077lookbackDays: number;
10661078limit: number;
10671079nowMs: number;
1080+ingestionDreamingDay: string;
10681081state: DailyIngestionState;
10691082}): Promise<DailyIngestionCollectionResult> {
10701083const memoryDir = path.join(params.workspaceDir, "memory");
@@ -1119,11 +1132,15 @@ async function collectDailyIngestionBatches(params: {
11191132previous !== undefined &&
11201133previous.mtimeMs === fingerprint.mtimeMs &&
11211134previous.size === fingerprint.size;
1122-if (!unchanged) {
1123-changed = true;
1124-} else {
1135+const previousDreamingDay = normalizeMemoryDay(previous?.lastDreamingDayIngested);
1136+if (unchanged && previousDreamingDay === params.ingestionDreamingDay) {
1137+nextFiles[relativePath] = {
1138+ ...fingerprint,
1139+lastDreamingDayIngested: previousDreamingDay,
1140+};
11251141continue;
11261142}
1143+changed = true;
1127114411281145const raw = await fs.readFile(filePath, "utf-8").catch((err: unknown) => {
11291146if ((err as NodeJS.ErrnoException)?.code === "ENOENT") {
@@ -1155,6 +1172,10 @@ async function collectDailyIngestionBatches(params: {
11551172}
11561173batches.push({ day: file.day, results });
11571174total += results.length;
1175+nextFiles[relativePath] = {
1176+ ...fingerprint,
1177+lastDreamingDayIngested: params.ingestionDreamingDay,
1178+};
11581179if (total >= totalCap) {
11591180break;
11601181}
@@ -1189,14 +1210,15 @@ async function ingestDailyMemorySignals(params: {
11891210timezone?: string;
11901211}): Promise<void> {
11911212const state = await readDailyIngestionState(params.workspaceDir);
1213+const ingestionDayBucket = formatMemoryDreamingDay(params.nowMs, params.timezone);
11921214const collected = await collectDailyIngestionBatches({
11931215workspaceDir: params.workspaceDir,
11941216lookbackDays: params.lookbackDays,
11951217limit: params.limit,
11961218nowMs: params.nowMs,
1219+ingestionDreamingDay: ingestionDayBucket,
11971220 state,
11981221});
1199-const ingestionDayBucket = formatMemoryDreamingDay(params.nowMs, params.timezone);
12001222for (const batch of collected.batches) {
12011223await recordShortTermRecalls({
12021224workspaceDir: params.workspaceDir,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。