| 128 | void mcpManager.startAll().catch(err => logger.warn(`MCP background startup error: ${err?.message ?? err}`)); |
| 129 | |
| 130 | // Graceful shutdown — also fires SessionEnd hooks |
| 131 | const shutdown = async (): Promise<void> => { |
| 132 | logger.info('Shutting down...'); |
| 133 | try { |
| 134 | if (hooks.hasAny('SessionEnd')) { |
| 135 | await hooks.dispatch('SessionEnd', { event: 'SessionEnd', sessionId: 'shutdown', cwd: process.cwd() }); |
| 136 | } |
| 137 | } catch (err) { logger.debug('SessionEnd hook failed', { err }); } |
| 138 | try { |
| 139 | const m = getMCPManager(); |
| 140 | if (m) await m.stopAll(); |
| 141 | } catch {} |
| 142 | process.exit(0); |
| 143 | }; |
| 144 | process.once('SIGINT', shutdown); |
| 145 | process.once('SIGTERM', shutdown); |