fix(daemon): judge the state directory before writing a state diagnostic
Summary
Part of #4649. Put daemon startup markers, log I/O, and shutdown reports behind one private-state directory and verified-file boundary. Unsafe or unreadable diagnostics fail independently of daemon startup and graceful stop. A shutdown report counts only when its author matches the stopped process lifetime.
The final review round preserves native path resolution, including Windows drive-relative paths with a same-drive working directory. It keeps optional reads nonfatal, checks descriptor mode before use, and requires a matching staging entry before cleanup. Script publication adoption remains a separate slice.
Validation
At a71bef41b8d8d93ce0e9780d98ffb786d3433a72 (current head: the state-directory rule split into its own module at the review's ask): pnpm build, pnpm format, pnpm lint, pnpm typecheck, pnpm check:layering and the eager-closure budgets suite (915 tests) passed, plus focused unit-core suites for host-kit (749), daemon-contracts, daemon-client, capture-kit and the state-privacy / log-publication / registration-owner suites (1,848). The three files the review named now sit under the 1000-line rule: atomic-publish.ts 308, script-destination.ts 724, verified-file.ts 614, state-directory.ts 404. The read-leaves-mode-alone test was re-checked against its mutation at this head and still fails when the read narrows the mode.
At c44b5d9b85757ec549534033135d5a44c74d1e82, pnpm install --frozen-lockfile && pnpm build, pnpm format, and seven focused unit-core suites passed (1,066 tests), including eager-closure and staged-file cleanup. pnpm check:affected --run --head HEAD failed in the unit stage (receipt run-8j2oDx): seven fuzz/release tests timed out and an unhandled ECONNRESET was reported near a limrun test. Cause is unproven; earlier stages passed. GitHub CI owns full validation.
At the preceding head c88d1a6, pnpm test:coverage passed 21,625 tests and wrote its stamp with a clean checkout; GitHub Coverage passed. Apple macOS smoke failed in three Swift transport tests with loopback address-in-use errors. The same tests passed on main's 7b6500c run; the unrelated failure was rerun.