mirror of
https://github.com/dtzp555-max/memory-continuity.git
synced 2026-07-21 21:15:07 +00:00
fix: always update state on agent_end, archive previous state
The agent_end hook was skipping state extraction when CURRENT_STATE.md already contained meaningful content. This meant once a state was written, subsequent conversations never updated it — the next /new would always recover stale data. Now: every session end overwrites CURRENT_STATE.md with the latest conversation state. Previous state is archived to STATE_ARCHIVE_<ts>.md. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -238,20 +238,23 @@ const plugin = {
|
|||||||
const statePath = resolveStatePath(ws);
|
const statePath = resolveStatePath(ws);
|
||||||
if (!statePath) return;
|
if (!statePath) return;
|
||||||
|
|
||||||
// If there's already a meaningful state file, don't overwrite with
|
// Always extract from the latest conversation — the whole point is to
|
||||||
// auto-extracted content (agent or user wrote it explicitly)
|
// capture what happened *this* session so the next session can recover.
|
||||||
const existing = readFile(statePath);
|
const newState = extractStateFromMessages(event?.messages);
|
||||||
if (existing && buildSnapshot(existing)) {
|
if (!newState) {
|
||||||
log.info?.("[memory-continuity] Existing state is meaningful, skipping auto-extract");
|
log.info?.("[memory-continuity] No extractable state from conversation");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract from conversation messages
|
// Archive previous state if it exists
|
||||||
const newState = extractStateFromMessages(event?.messages);
|
const existing = readFile(statePath);
|
||||||
if (!newState) return;
|
if (existing) {
|
||||||
|
const archivePath = statePath.replace(/CURRENT_STATE\.md$/, `STATE_ARCHIVE_${Date.now()}.md`);
|
||||||
|
writeFile(archivePath, existing);
|
||||||
|
}
|
||||||
|
|
||||||
writeFile(statePath, newState);
|
writeFile(statePath, newState);
|
||||||
log.info?.("[memory-continuity] Auto-extracted state from conversation");
|
log.info?.("[memory-continuity] Updated state from conversation");
|
||||||
}, { priority: 90 }); // low priority, run after other hooks
|
}, { priority: 90 }); // low priority, run after other hooks
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user