task-routing.js
1 /** 2 * Task Routing Configuration 3 * 4 * Central source of truth for task type to agent mapping. 5 * All agents should use this for delegation. 6 */ 7 8 /** 9 * Task type to agent mapping 10 * 11 * Key: task_type 12 * Value: correct agent name 13 */ 14 export const TASK_ROUTING = { 15 // Developer tasks 16 fix_bug: 'developer', 17 implement_feature: 'developer', 18 refactor_code: 'developer', 19 apply_feedback: 'developer', 20 implementation_plan: 'developer', 21 22 // QA tasks 23 write_test: 'qa', 24 verify_fix: 'qa', 25 check_coverage: 'qa', 26 run_tests: 'qa', 27 exploratory_testing: 'qa', 28 29 // Security tasks 30 audit_code: 'security', 31 scan_dependencies: 'security', 32 verify_compliance: 'security', 33 scan_secrets: 'security', 34 threat_model: 'security', 35 fix_security_issue: 'security', 36 review_dependency_update: 'security', 37 generate_sbom: 'security', 38 39 // Architect tasks 40 design_proposal: 'architect', 41 technical_review: 'architect', 42 review_design: 'architect', 43 suggest_refactor: 'architect', 44 update_documentation: 'architect', 45 check_documentation_freshness: 'architect', 46 check_complexity: 'architect', 47 audit_documentation: 'architect', 48 check_branch_health: 'architect', 49 profile_performance: 'architect', 50 review_documentation: 'architect', 51 design_optimization: 'architect', 52 53 // Triage tasks 54 classify_error: 'triage', 55 route_task: 'triage', 56 prioritize_tasks: 'triage', 57 58 // Monitor tasks 59 scan_logs: 'monitor', 60 check_agent_health: 'monitor', 61 check_process_compliance: 'monitor', 62 detect_anomaly: 'monitor', 63 check_pipeline_health: 'monitor', 64 check_slo_compliance: 'monitor', 65 bootstrap_monitor: 'monitor', 66 }; 67 68 /** 69 * Get correct agent for a task type 70 * 71 * @param {string} taskType - Task type 72 * @returns {string} - Correct agent name, or 'triage' if unknown 73 */ 74 export function getAgentForTaskType(taskType) { 75 return TASK_ROUTING[taskType] || 'triage'; 76 } 77 78 /** 79 * Check if task type is valid 80 * 81 * @param {string} taskType - Task type 82 * @returns {boolean} - True if task type is recognized 83 */ 84 export function isValidTaskType(taskType) { 85 return taskType in TASK_ROUTING; 86 } 87 88 /** 89 * Get all task types for an agent 90 * 91 * @param {string} agentName - Agent name 92 * @returns {string[]} - List of task types this agent can handle 93 */ 94 export function getTaskTypesForAgent(agentName) { 95 return Object.entries(TASK_ROUTING) 96 .filter(([, agent]) => agent === agentName) 97 .map(([taskType]) => taskType); 98 } 99 100 /** 101 * Validate task assignment 102 * 103 * @param {string} taskType - Task type 104 * @param {string} assignedTo - Agent assigned to 105 * @returns {{valid: boolean, correctAgent?: string, reason?: string}} 106 */ 107 export function validateTaskAssignment(taskType, assignedTo) { 108 const correctAgent = getAgentForTaskType(taskType); 109 110 if (correctAgent === assignedTo) { 111 return { valid: true }; 112 } 113 114 return { 115 valid: false, 116 correctAgent, 117 reason: `Task type '${taskType}' should be assigned to '${correctAgent}', not '${assignedTo}'`, 118 }; 119 }