/** * Stop hook handler — the `/sw:auto` loop driver, plus a one-time close * reminder for ordinary sessions (Stop fires on every turn; handoff automation * lives in PreCompact). * * Decision table (any throw short-circuits to `{}` so ordinary sessions are * never trapped): * * no auto-mode.json | active !== true -> reset counter; close reminder below * every auto increment completed/abandoned -> reset; {} * stale session (auto.maxSessionAge, 7200 s) -> reset; {} * turns > auto.maxTurns (default 20) -> reset; {} // safety stop * stop_hook_active + no progress for 3 turns -> reset; {} // loop guard * no increment to work on -> reset; {} * 0 pending tasks AND all ACs satisfied -> reset; block: all_complete_needs_closure * otherwise (work remains) -> counter + 1; block: