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 <noreply@anthropic.com>
This commit is contained in:
Tibsfox
2026-03-03 03:09:43 -08:00
committed by Lex Christopherson
parent 90e7d30839
commit 07f44cc1c3

View File

@@ -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 = {