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

Function main

hooks_src/subagent-stop.js:18–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16const health = require('./harness-health-util');
17
18function main() {
19 let input = '';
20 process.stdin.setEncoding('utf8');
21 process.stdin.on('data', (chunk) => { input += chunk; });
22 process.stdin.on('end', () => {
23 let event = {};
24 try { event = JSON.parse(input); } catch { /* partial input ok */ }
25
26 const agentId = event.agent_id || event.subagent_id || null;
27 const status = event.status || event.stop_reason || 'unknown';
28 const agentType = event.subagent_type || event.agent_type || null;
29 const outputTokens = event.output_tokens || null;
30
31 health.increment('subagent-stop', 'count');
32
33 // Log to telemetry for timeline reconstruction
34 health.logTiming('subagent-stop', 0, {
35 event: 'subagent-stop',
36 agent_id: agentId,
37 agent_type: agentType,
38 status,
39 output_tokens: outputTokens,
40 });
41
42 // Abnormal terminations go to audit — these are things to investigate
43 const abnormal = status && !['end_turn', 'success', 'completed', 'stop_sequence'].includes(status.toLowerCase());
44 if (abnormal) {
45 health.writeAuditLog('subagent-abnormal-stop', {
46 agent_id: agentId,
47 agent_type: agentType,
48 status,
49 severity: 'medium',
50 });
51 }
52
53 process.exit(0);
54 });
55}
56
57main();

Callers 1

subagent-stop.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected