()
| 483 | * Kill terminates the entire process. |
| 484 | */ |
| 485 | const handleKillSession = async () => { |
| 486 | logger.debug('[Codex] Kill session requested - terminating process'); |
| 487 | await handleAbort(); |
| 488 | logger.debug('[Codex] Abort completed, proceeding with termination'); |
| 489 | |
| 490 | try { |
| 491 | // Update lifecycle state to archived before closing |
| 492 | if (session) { |
| 493 | session.updateMetadata((currentMetadata) => ({ |
| 494 | ...currentMetadata, |
| 495 | lifecycleState: 'archived', |
| 496 | lifecycleStateSince: Date.now(), |
| 497 | archivedBy: 'cli', |
| 498 | archiveReason: 'User terminated' |
| 499 | })); |
| 500 | |
| 501 | // Send session death message |
| 502 | session.sendSessionDeath(); |
| 503 | await session.flush(); |
| 504 | await session.close(); |
| 505 | } |
| 506 | |
| 507 | // Force close Codex transport (best-effort) so we don't leave stray processes |
| 508 | try { |
| 509 | await client.disconnect(); |
| 510 | } catch (e) { |
| 511 | logger.debug('[Codex] Error disconnecting Codex during termination', e); |
| 512 | } |
| 513 | |
| 514 | // Stop Happy MCP server |
| 515 | happyServer.stop(); |
| 516 | |
| 517 | logger.debug('[Codex] Session termination complete, exiting'); |
| 518 | process.exit(0); |
| 519 | } catch (error) { |
| 520 | logger.debug('[Codex] Error during session termination:', error); |
| 521 | process.exit(1); |
| 522 | } |
| 523 | }; |
| 524 | |
| 525 | // Register abort handler |
| 526 | session.rpcHandlerManager.registerHandler('abort', handleAbort); |
nothing calls this directly
no test coverage detected