From d7a562fc454432c05a97e0bec2bbae5f9e8b1ff5 Mon Sep 17 00:00:00 2001 From: Kjell Tore Guttormsen Date: Sat, 11 Apr 2026 00:43:08 +0200 Subject: [PATCH] feat(linkedin): auto-prune content history entries older than 90 days Adds pruneContentHistory call to session-start.mjs after week rollover. Uses dynamic import() for state-updater.mjs. Non-critical: silently skipped on failure. Co-Authored-By: Claude Opus 4.6 --- .../hooks/scripts/session-start.mjs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/linkedin-thought-leadership/hooks/scripts/session-start.mjs b/plugins/linkedin-thought-leadership/hooks/scripts/session-start.mjs index 9ee2816..ea09793 100644 --- a/plugins/linkedin-thought-leadership/hooks/scripts/session-start.mjs +++ b/plugins/linkedin-thought-leadership/hooks/scripts/session-start.mjs @@ -149,6 +149,19 @@ if (existsSync(STATE_FILE)) { weekResetNote = `Warning: Week rollover failed (${err.message}). Manual reset may be needed.`; } + // Auto-prune Recent Posts entries older than 90 days + try { + const currentState = readFileSync(STATE_FILE, 'utf-8'); + const { pruneContentHistory } = await import('./state-updater.mjs'); + const pruneResult = pruneContentHistory(currentState, 90); + if (pruneResult && pruneResult.pruned > 0) { + writeFileSync(STATE_FILE, pruneResult.content, 'utf-8'); + weekResetNote += (weekResetNote ? ' ' : '') + `Auto-pruned ${pruneResult.pruned} posts older than 90 days from Recent Posts.`; + } + } catch { + // Non-critical: don't block session start on pruning failure + } + // Build status line let statusLine = `LinkedIn: ${postsThisWeek}/${weeklyGoal} posts this week | Streak: ${currentStreak} days`; if (lastPostDate && lastPostDate !== 'null') {