| 21 | const health = require('./harness-health-util'); |
| 22 | |
| 23 | function main() { |
| 24 | let input = ''; |
| 25 | process.stdin.setEncoding('utf8'); |
| 26 | process.stdin.on('data', (chunk) => { input += chunk; }); |
| 27 | process.stdin.on('end', () => { |
| 28 | let event = {}; |
| 29 | try { event = JSON.parse(input); } catch { /* partial input ok */ } |
| 30 | |
| 31 | const agentId = event.agent_id || event.subagent_id || null; |
| 32 | const agentType = event.subagent_type || event.agent_type || null; |
| 33 | const sessionId = event.session_id || null; |
| 34 | const description = event.description || null; |
| 35 | |
| 36 | health.increment('subagent-start', 'count'); |
| 37 | |
| 38 | // Log the agent spawn with full identity context |
| 39 | health.logTiming('subagent-start', 0, { |
| 40 | event: 'subagent-start', |
| 41 | agent_id: agentId, |
| 42 | agent_type: agentType, |
| 43 | session_id: sessionId, |
| 44 | description: description ? description.slice(0, 120) : null, |
| 45 | }); |
| 46 | |
| 47 | // Audit log for fleet campaigns — spawning an agent is a meaningful action |
| 48 | if (agentType && agentType !== 'unknown') { |
| 49 | health.writeAuditLog('subagent-spawn', { |
| 50 | agent_id: agentId, |
| 51 | agent_type: agentType, |
| 52 | description: description ? description.slice(0, 120) : null, |
| 53 | severity: 'low', |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | process.exit(0); |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | main(); |