(obj)
| 74 | // Single-writer latch: exactly one stdout write, exactly one exit. Mirrors the |
| 75 | // proven pattern in evolver-signal-detect.js / evolver-session-end.js. |
| 76 | function finish(obj) { |
| 77 | if (handled) return; |
| 78 | handled = true; |
| 79 | if (watchdog) { try { clearTimeout(watchdog); } catch (_) {} } |
| 80 | try { process.stdout.write(JSON.stringify(obj || {})); } catch (_) {} |
| 81 | process.exit(0); |
| 82 | } |
| 83 | |
| 84 | function main() { |
| 85 | const mode = getMode(); |