MCPcopy Create free account
hub / github.com/SethGammon/Citadel / main

Function main

hooks_src/session-end.js:69–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 fs.writeFileSync(path.join(telemetryDir, 'session-end.lock'), sessionId, 'utf8');
68 } catch { /* non-critical */ }
69}
70
71function main() {
72 let input = '';
73 process.stdin.setEncoding('utf8');
74 process.stdin.on('data', (chunk) => { input += chunk; });
75 process.stdin.on('end', () => {
76 let event = {};
77 try { event = JSON.parse(input); } catch { /* partial input ok */ }
78
79 const sessionId = event.session_id || null;
80
81 // Idempotency: skip if we've already run for this session_id.
82 // This is what makes the hook safe under Codex's SessionEnd→Stop collapse.
83 if (alreadyFiredForSession(sessionId)) {
84 process.exit(0);
85 }
86 recordFiredForSession(sessionId);
87
88 health.increment('session-end', 'count');
89
90 // Log session end
91 health.logTiming('session-end', 0, {
92 event: 'session-end',
93 session_id: sessionId,
94 });
95
96 // Log session cost data to telemetry
97 logSessionCost(event);
98
99 // Increment trust counters for contextual appropriateness
100 incrementTrustCounters();
101
102 // Check for active campaigns and mark continuation point
103 markCampaignContinuation();
104
105 // Clean up expired dynamic directories per organization manifest
106 cleanupDynamicDirectories();
107
108 // Sweep expired consent markers, one-time tokens, and stale lockdirs
109 runStateHygiene();
110
111 // Update daemon state if this was a daemon-driven session
112 updateDaemonState();
113
114 // Write doc sync queue entry (Tier 6 - processed by next session or doc-sync hook)
115 queueDocSync();
116
117 // Snapshot only opted-in durable knowledge. Active execution state,
118 // telemetry, consent, and runtime configuration never enter this store.
119 syncRepositoryMemory();
120

Callers 1

session-end.jsFile · 0.70

Calls 9

alreadyFiredForSessionFunction · 0.85
recordFiredForSessionFunction · 0.85
logSessionCostFunction · 0.85
incrementTrustCountersFunction · 0.85
markCampaignContinuationFunction · 0.85
runStateHygieneFunction · 0.85
updateDaemonStateFunction · 0.85
queueDocSyncFunction · 0.70

Tested by

no test coverage detected