// The agents installed on this machine and whether node9 really checks them // (docs roadmap/active/agents-on-machines-design.md). Rides in the add-ons // report of the policy snapshot. Only the agent id and the verdict leave the // machine: no path, no hook file content, no MCP server name (those are // reported as add-ons already). import os from 'os'; import { getAgentWiring, type AgentWiringRow } from '../agent-wiring'; import { agentVerdict, type AgentGapReason, type AgentProtection } from '../agent-verdict'; export interface AddonAgent { /** The AGENT_SPECS id: 'claude', 'codex', 'cursor', 'vscode', ... */ id: string; /** The verdict `node9 doctor` prints for this agent. */ protection: AgentProtection; /** Why, when it is not plainly protected. */ reason?: AgentGapReason; /** 'hooks' (hooks or a plugin file) or 'mcp' (MCP calls only). */ via: 'hooks' | 'mcp'; } const MAX_AGENTS = 20; /** An agent is reported when it is on the machine or node9 is wired into it. */ function onMachine(row: AgentWiringRow, reason: AgentGapReason | undefined): boolean { return row.installed || row.present || reason !== 'not-set-up'; } export function collectAgents( home: string = os.homedir(), wiring: (home: string) => AgentWiringRow[] = getAgentWiring ): AddonAgent[] { const out: AddonAgent[] = []; for (const row of wiring(home)) { let verdict; try { verdict = agentVerdict(row, home); } catch { continue; // one unreadable agent must not hide the others } if (!onMachine(row, verdict.reason)) continue; out.push({ id: row.id, protection: verdict.protection, ...(verdict.reason ? { reason: verdict.reason } : {}), // Protected through its MCP entry alone (Codex can be): MCP calls only. via: verdict.protection !== 'not-protected' && !verdict.anyHookWired && row.mcpProtected ? 'mcp' : row.protection, }); } return out.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, MAX_AGENTS); }