Skip to content

Commit e000bbe

Browse files
cnwillzwill
andauthored
fix(session-end): always update session summary content (anomalyco#317)
* fix(session-end): always update session summary content Previously, session-end.js would only write content to session files on first creation. Subsequent sessions would only update the timestamp, causing stale content (e.g., old tasks, resolved issues) to persist indefinitely. This fix ensures that every session end updates the summary section with fresh content from the current transcript, keeping cross-session context accurate and relevant. Fixes: anomalyco#187 (partially - addresses stale content issue) Changes: - Remove the blank-template-only check - Replace entire Session Summary section on every session end - Keep timestamp update separate from content update * fix(session-end): match both summary headers and prevent duplicate stats Fixes two issues identified in PR anomalyco#317 code review: 1. CodeRabbit: Updated regex to match both `## Session Summary` and `## Current State` headers, ensuring files created from blank template can be updated with fresh summaries. 2. Cubic: Changed regex lookahead `(?=### Stats|$)` to end-of-string `$` to prevent duplicate `### Stats` sections. The old pattern stopped before `### Stats` without consuming it, but buildSummarySection() also emits a `### Stats` block, causing duplication on each session update. Changes: - Regex now: `/## (?:Session Summary|Current State)[\s\S]*?$/` - Matches both header variants used in blank template and populated sessions - Matches to end-of-string to cleanly replace entire summary section --------- Co-authored-by: will <[email protected]>
1 parent bc64712 commit e000bbe

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎scripts/hooks/session-end.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,15 @@ async function main() {
167167
log(`[SessionEnd] Failed to update timestamp in ${sessionFile}`);
168168
}
169169

170-
// If we have a new summary and the file still has the blank template, replace it
170+
// If we have a new summary, update the session file content
171171
if (summary) {
172172
const existing = readFile(sessionFile);
173-
if (existing && existing.includes('[Session context goes here]')) {
174-
// Use a flexible regex that tolerates CRLF, extra whitespace, and minor template variations
173+
if (existing) {
174+
// Use a flexible regex that matches both "## Session Summary" and "## Current State"
175+
// Match to end-of-string to avoid duplicate ### Stats sections
175176
const updatedContent = existing.replace(
176-
/## Current State\s*\n\s*\[Session context goes here\][\s\S]*?### Context to Load\s*\n```\s*\n\[relevant files\]\s*\n```/,
177-
buildSummarySection(summary)
177+
/## (?:Session Summary|Current State)[\s\S]*?$/ ,
178+
buildSummarySection(summary).trim() + '\n'
178179
);
179180
writeFile(sessionFile, updatedContent);
180181
}

0 commit comments

Comments
 (0)