From 07f44cc1c3b9c0d29b3f57e074cfb865a5d14fe8 Mon Sep 17 00:00:00 2001 From: Tibsfox Date: Tue, 3 Mar 2026 03:09:43 -0800 Subject: [PATCH] fix(hooks): make context monitor advisory instead of imperative The context monitor uses imperative language ("STOP new work immediately. Save state NOW") that overrides user preferences and causes autonomous state saves in non-GSD sessions. Replace with advisory messaging that informs the user and respects their control. - Detect GSD-active sessions via .planning/STATE.md - GSD sessions: warn user, reference /gsd:pause-work, but don't command autonomous saves (STATE.md already tracks state) - Non-GSD sessions: inform user, explicitly say "Do NOT autonomously save state unless the user asks" - Remove all imperative language (STOP, NOW, immediately) Closes #884 Co-Authored-By: Claude Opus 4.6 --- hooks/gsd-context-monitor.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/hooks/gsd-context-monitor.js b/hooks/gsd-context-monitor.js index c3f5630c3..4bb216e3b 100644 --- a/hooks/gsd-context-monitor.js +++ b/hooks/gsd-context-monitor.js @@ -100,16 +100,30 @@ process.stdin.on('end', () => { warnData.lastLevel = currentLevel; fs.writeFileSync(warnPath, JSON.stringify(warnData)); - // Build warning message + // Detect if GSD is active (has .planning/STATE.md in working directory) + const cwd = data.cwd || process.cwd(); + const isGsdActive = fs.existsSync(path.join(cwd, '.planning', 'STATE.md')); + + // Build advisory warning message (never use imperative commands that + // override user preferences — see #884) let message; if (isCritical) { - message = `CONTEXT MONITOR CRITICAL: Usage at ${usedPct}%. Remaining: ${remaining}%. ` + - 'STOP new work immediately. Save state NOW and inform the user that context is nearly exhausted. ' + - 'If using GSD, run /gsd:pause-work to save execution state.'; + message = isGsdActive + ? `CONTEXT CRITICAL: Usage at ${usedPct}%. Remaining: ${remaining}%. ` + + 'Context is nearly exhausted. Do NOT start new complex work or write handoff files — ' + + 'GSD state is already tracked in STATE.md. Inform the user so they can run ' + + '/gsd:pause-work at the next natural stopping point.' + : `CONTEXT CRITICAL: Usage at ${usedPct}%. Remaining: ${remaining}%. ` + + 'Context is nearly exhausted. Inform the user that context is low and ask how they ' + + 'want to proceed. Do NOT autonomously save state or write handoff files unless the user asks.'; } else { - message = `CONTEXT MONITOR WARNING: Usage at ${usedPct}%. Remaining: ${remaining}%. ` + - 'Begin wrapping up current task. Do not start new complex work. ' + - 'If using GSD, consider /gsd:pause-work to save state.'; + message = isGsdActive + ? `CONTEXT WARNING: Usage at ${usedPct}%. Remaining: ${remaining}%. ` + + 'Context is getting limited. Avoid starting new complex work. If not between ' + + 'defined plan steps, inform the user so they can prepare to pause.' + : `CONTEXT WARNING: Usage at ${usedPct}%. Remaining: ${remaining}%. ` + + 'Be aware that context is getting limited. Avoid unnecessary exploration or ' + + 'starting new complex work.'; } const output = {