MCPcopy
hub / github.com/openai/codex-plugin-cc / handleSessionEnd

Function handleSessionEnd

plugins/codex/scripts/session-lifecycle-hook.mjs:83–114  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

81}
82
83async function handleSessionEnd(input) {
84 const cwd = input.cwd || process.cwd();
85 const brokerSession =
86 loadBrokerSession(cwd) ??
87 (process.env[BROKER_ENDPOINT_ENV]
88 ? {
89 endpoint: process.env[BROKER_ENDPOINT_ENV],
90 pidFile: process.env[PID_FILE_ENV] ?? null,
91 logFile: process.env[LOG_FILE_ENV] ?? null
92 }
93 : null);
94 const brokerEndpoint = brokerSession?.endpoint ?? null;
95 const pidFile = brokerSession?.pidFile ?? null;
96 const logFile = brokerSession?.logFile ?? null;
97 const sessionDir = brokerSession?.sessionDir ?? null;
98 const pid = brokerSession?.pid ?? null;
99
100 if (brokerEndpoint) {
101 await sendBrokerShutdown(brokerEndpoint);
102 }
103
104 cleanupSessionJobs(cwd, input.session_id || process.env[SESSION_ID_ENV]);
105 teardownBrokerSession({
106 endpoint: brokerEndpoint,
107 pidFile,
108 logFile,
109 sessionDir,
110 pid,
111 killProcess: terminateProcessTree
112 });
113 clearBrokerSession(cwd);
114}
115
116async function main() {
117 const input = readHookInput();

Callers 1

mainFunction · 0.85

Calls 5

loadBrokerSessionFunction · 0.90
sendBrokerShutdownFunction · 0.90
teardownBrokerSessionFunction · 0.90
clearBrokerSessionFunction · 0.90
cleanupSessionJobsFunction · 0.85

Tested by

no test coverage detected