| 36 | } |
| 37 | |
| 38 | function run(input) { |
| 39 | let event; |
| 40 | try { |
| 41 | event = JSON.parse(input); |
| 42 | } catch { |
| 43 | // Malformed input — skip logging, do not block |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | const toolName = event.tool_name || ''; |
| 48 | if (!LOGGED_TOOLS.has(toolName)) { |
| 49 | return; // Not a tool we log — skip |
| 50 | } |
| 51 | |
| 52 | // Fleet agent identity — bound to the spawning agent when inside a subagent |
| 53 | const agentId = event.agent_id || null; |
| 54 | const agentType = event.agent_type || null; |
| 55 | |
| 56 | // Derive a human-readable target string from tool input |
| 57 | let target = ''; |
| 58 | const inp = event.tool_input || {}; |
| 59 | if (toolName === 'Edit' || toolName === 'Write') { |
| 60 | target = inp.file_path || inp.path || ''; |
| 61 | } else if (toolName === 'Bash') { |
| 62 | target = inp.command || ''; |
| 63 | } else if (toolName === 'Agent') { |
| 64 | target = inp.prompt || inp.description || ''; |
| 65 | } |
| 66 | |
| 67 | // Truncate to 200 chars to keep the log compact |
| 68 | if (target.length > 200) { |
| 69 | target = target.slice(0, 197) + '...'; |
| 70 | } |
| 71 | |
| 72 | health.writeAuditLog('tool-call', { |
| 73 | tool: toolName, |
| 74 | target, |
| 75 | agent_id: agentId, |
| 76 | agent_type: agentType, |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | main(); |