refactor(daemon): extract shutdown handling from session-state dispatcher

Merged
TH
11d ago
+369-329

Summary

Part of #3424 (CRAP burn-down, umbrella #3414). Layer 2 of 4; stacks on #3455 (boot extraction).

Extracts the shutdown path: handleShutdownCommand moves from src/daemon/handlers/session-state.ts to src/daemon/handlers/session-shutdown.ts with its exclusive helpers (isDaemonRuntimeFailure, describeShutdownError, requestForegroundShutdownAfterRelease, resolveShutdownWaitMs) and the module-local terminal-state constants. session-state.ts's shutdown branch delegates. No behavior change.

  • handleShutdownCommand: 15 (already < 30; moved so the dispatcher keeps shedding complexity).
  • handleSessionStateCommands: 20 at this layer (34 before layer 1; 4 at stack top).
  • Tests split one-to-one: session-boot-shutdown.test.ts → session-shutdown.test.ts (boot half already lives in session-boot.test.ts from layer 1). The descriptor source-slice test (command-descriptor-shutdown-runtime-execution.test.ts) retargets to session-shutdown.ts — its contract is "the dispatcher does not execute runtime calls", so it follows the moved code, not the filename.

Part of the stacked split of session-state.ts for #3424 (umbrella #3414).

Validation

  • pnpm check:affected --run on this head: all runnable checks passed (2026-10-12).
  • pnpm check:layering: pass; session-shutdown.ts registered in daemon-layer-manifest.json (daemon-sessions).

Created by Apex.