refactor(daemon): route daemon-level diagnostics through one scope helper
Merged
TH
2mo ago+150+150+012345678901234567890123456789-92-92-01234567890123456789
Summary
Daemon-level work that runs outside a request needs its own diagnostics scope, or emitDiagnostic drops its events. That wrapper (withDiagnosticsScope({ session: 'daemon', logPath, … }) plus a forced flush) was written out eight times: seven in daemon-runtime.ts and one in daemon-registration-owner.ts. withDaemonDiagnosticsScope now owns it, and every site uses it.
- Each site keeps its command name and debug flag. The flush now also runs when the body throws, so a failing body keeps its record. Before, only the idle-expiry sweep did that; the startup-diagnostics flush would have lost its events.
- The helper lives at
src/daemon-diagnostics-scope.ts.daemon-runtime.tsalready imports the registration module, so a root module avoids reversing that dependency. - The two call-site comments that repeated the helper's contract are gone.
daemon-runtime.tsshrinks by about 50 lines.
4 files, 242 gross lines.
Validation
At 7262f17b67: pnpm check:affected --run passes. The helper test covers the scope fields, the default and startup command names, and a throwing body that keeps its events and rethrows. Log output is otherwise unchanged: in a debug scope with a log path every event is written as it is emitted, so the extra flushes write nothing.