/ src / agents / run-single.js
run-single.js
 1  #!/usr/bin/env node
 2  
 3  /**
 4   * Single Agent Runner
 5   *
 6   * Lightweight runner for spawned agents (vs runner.js which runs all agents).
 7   * Used by real-time notification system to spawn agents immediately.
 8   *
 9   * Usage: node src/agents/run-single.js <agent-name>
10   * Example: node src/agents/run-single.js qa
11   */
12  
13  import { DeveloperAgent } from './developer.js';
14  import { QAAgent } from './qa.js';
15  import { SecurityAgent } from './security.js';
16  import { ArchitectAgent } from './architect.js';
17  import { TriageAgent } from './triage.js';
18  import { MonitorAgent } from './monitor.js';
19  import Logger from '../utils/logger.js';
20  
21  const logger = new Logger('AgentRunner:Single');
22  
23  const AGENTS = {
24    developer: DeveloperAgent,
25    qa: QAAgent,
26    security: SecurityAgent,
27    architect: ArchitectAgent,
28    triage: TriageAgent,
29    monitor: MonitorAgent,
30  };
31  
32  // Get agent name from CLI args
33  const agentName = process.argv[2];
34  
35  if (!agentName || !AGENTS[agentName]) {
36    logger.error(`Invalid agent name: ${agentName}`);
37    logger.info(`Usage: node src/agents/run-single.js <agent-name>`);
38    logger.info(`Valid agents: ${Object.keys(AGENTS).join(', ')}`);
39    process.exit(1);
40  }
41  
42  // Get task limit from env var
43  const limit = parseInt(process.env.AGENT_MAX_TASKS_PER_CYCLE || '5', 10);
44  
45  // Instantiate and run agent
46  const AgentClass = AGENTS[agentName];
47  const agent = new AgentClass();
48  
49  logger.info(`Starting ${agentName} agent (limit: ${limit} tasks)`);
50  
51  try {
52    const processed = await agent.pollTasks(limit);
53    logger.success(`${agentName} agent completed: processed ${processed} tasks`);
54    process.exit(0);
55  } catch (error) {
56    logger.error(`${agentName} agent failed:`, error);
57    process.exit(1);
58  }