From 2fc42661cfcd66adad48fdf5fac5eec00fb72469 Mon Sep 17 00:00:00 2001 From: dtzp555 Date: Mon, 16 Mar 2026 17:10:29 +1000 Subject: [PATCH] fix: always update state on agent_end, archive previous state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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_.md. Co-Authored-By: Claude Opus 4.6 --- index.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index d9e93b3..8d53c6a 100644 --- a/index.js +++ b/index.js @@ -238,20 +238,23 @@ const plugin = { const statePath = resolveStatePath(ws); if (!statePath) return; - // If there's already a meaningful state file, don't overwrite with - // auto-extracted content (agent or user wrote it explicitly) - const existing = readFile(statePath); - if (existing && buildSnapshot(existing)) { - log.info?.("[memory-continuity] Existing state is meaningful, skipping auto-extract"); + // Always extract from the latest conversation — the whole point is to + // capture what happened *this* session so the next session can recover. + const newState = extractStateFromMessages(event?.messages); + if (!newState) { + log.info?.("[memory-continuity] No extractable state from conversation"); return; } - // Extract from conversation messages - const newState = extractStateFromMessages(event?.messages); - if (!newState) return; + // Archive previous state if it exists + const existing = readFile(statePath); + if (existing) { + const archivePath = statePath.replace(/CURRENT_STATE\.md$/, `STATE_ARCHIVE_${Date.now()}.md`); + writeFile(archivePath, existing); + } 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 // ------------------------------------------------------------------