/**
* @fileoverview Role Templates - Subagent role definitions
* @module config/role-templates
*
* Defines specialized roles for subagents including system prompts,
* suggested tools, and behavior configuration.
*/
/**
* @typedef {Object} RoleTemplate
* @property {string} description - Role description
* @property {string} category - Role category (review|security|planning|generation)
* @property {string} system_prompt - System prompt template
* @property {string[]} suggested_tools - Recommended SAB tools
* @property {string} [output_format] - Expected output format
* @property {boolean} [requiresVerdict] - Whether verdict parsing is needed
* @property {boolean} [enableThinking] - Enable thinking mode
* @property {number} [maxTokens] - Maximum response tokens
* @property {string} [preferred_backend] - Preferred AI backend
*/
/**
* Available role templates
* @type {Object.<string, RoleTemplate>}
*/
const roleTemplates = {
'code-reviewer': {
description: 'Code Quality Reviewer',
category: 'review',
system_prompt: `You are an expert code reviewer focused on quality, maintainability, and best practices.
Your review should cover:
1. Code quality and readability
2. Design patterns and architecture
3. Performance considerations
4. Testing coverage
5. Documentation completeness
Provide constructive feedback with specific line numbers and improvement suggestions.`,
suggested_tools: [
'read', // Read files
'review', // Deep code review
'edit_file', // Suggest edits
'ask' // Query AI for analysis
],
output_format: `## Code Review
### Summary
[Brief overview of code quality]
### Issues Found
[List issues with severity: CRITICAL|HIGH|MEDIUM|LOW]
### Recommendations
[Specific actionable improvements]
### Verdict
- **Quality Score**: X/10
- **Status**: APPROVE|APPROVE_WITH_CHANGES|REJECT
- **Reasoning**: [Brief explanation]`,
requiresVerdict: true,
enableThinking: true,
maxTokens: 32768,
// Dynamic capability-based backend selection
required_capabilities: ['code_specialized'],
context_sensitivity: 'medium',
fallback_order: ['local', 'nvidia_qwen', 'gemini']
},
'security-auditor': {
description: 'Security Vulnerability Auditor',
category: 'security',
system_prompt: `You are a security expert performing a comprehensive security audit.
Focus on identifying:
1. SQL injection vulnerabilities
2. XSS (Cross-Site Scripting) risks
3. Authentication/authorization flaws
4. Insecure data handling
5. Dependency vulnerabilities
6. Secrets exposure
7. OWASP Top 10 issues
For each finding, provide:
- Vulnerability type
- Severity (CRITICAL|HIGH|MEDIUM|LOW)
- Affected code location
- Exploitation scenario
- Remediation steps`,
suggested_tools: [
'read', // Read files
'review', // Security review
'validate_changes', // Validate fixes
'ask' // Deep analysis
],
output_format: `## Security Audit Report
### Executive Summary
[High-level security posture assessment]
### Vulnerabilities Detected
[Detailed list with severity, location, and exploitation scenario]
### Remediation Plan
[Prioritized fix recommendations]
### Verdict
- **Security Score**: X/10
- **Risk Level**: CRITICAL|HIGH|MEDIUM|LOW
- **Status**: SECURE|VULNERABLE|CRITICAL_ISSUES
- **Reasoning**: [Brief explanation]`,
requiresVerdict: true,
enableThinking: true,
maxTokens: 32768,
// Dynamic capability-based backend selection
required_capabilities: ['deep_reasoning', 'security_focus'],
context_sensitivity: 'medium',
fallback_order: ['local', 'nvidia_deepseek', 'nvidia_qwen']
},
'planner': {
description: 'Task Planning and Architecture Specialist',
category: 'planning',
system_prompt: `You are a software architect and project planner.
Your role is to:
1. Break down complex tasks into atomic steps
2. Identify dependencies and critical path
3. Suggest optimal implementation order
4. Estimate complexity and effort
5. Recommend tools and patterns
6. Identify potential risks
Create clear, actionable plans that developers can follow immediately.`,
suggested_tools: [
'read', // Understand codebase
'ask', // Analysis and reasoning
'get_analytics' // Performance insights
],
output_format: `## Implementation Plan
### Task Overview
[Brief description and goals]
### Prerequisites
[Required knowledge, tools, or setup]
### Implementation Steps
[Numbered list of atomic tasks with:
- Task description
- Estimated complexity (1-10)
- Dependencies
- Suggested approach]
### Critical Path
[Tasks that block other work]
### Quality Gates
[Testing and validation checkpoints]
### Risk Assessment
[Potential blockers and mitigations]
### Estimated Timeline
[Time estimates for sequential and parallel execution]`,
requiresVerdict: false,
enableThinking: true,
maxTokens: 65536, // Larger for comprehensive plans
// Dynamic capability-based backend selection with context awareness
required_capabilities: ['deep_reasoning'],
context_sensitivity: 'high', // Triggers context-based routing
fallback_order: ['local', 'nvidia_deepseek', 'nvidia_qwen'],
// Context-aware routing rules
routing_rules: {
small_task: { prefer: 'nvidia_deepseek', reason: 'Deep reasoning for architecture' },
large_context: { prefer: 'local', reason: '128K context for large codebases' }
}
},
'refactor-specialist': {
description: 'Code Refactoring Specialist',
category: 'generation',
system_prompt: `You are an expert in code refactoring and design patterns.
Your mission is to:
1. Identify code smells and technical debt
2. Suggest refactoring opportunities
3. Apply SOLID principles
4. Extract reusable components
5. Improve testability
6. Enhance maintainability
Provide refactored code with clear before/after comparisons and explanations.`,
suggested_tools: [
'read', // Read files
'edit_file', // Apply refactoring
'multi_edit', // Batch refactoring
'ask' // Design analysis
],
output_format: `## Refactoring Proposal
### Code Smells Identified
[List problematic patterns]
### Proposed Changes
[Detailed refactoring steps with before/after code]
### Benefits
[Improved maintainability, testability, performance]
### Migration Path
[How to safely apply changes]
### Verdict
- **Code Quality Improvement**: X%
- **Complexity Reduction**: Y%
- **Recommendation**: APPLY|REVIEW_FURTHER|DEFER`,
requiresVerdict: true,
enableThinking: true,
maxTokens: 32768,
// Dynamic capability-based backend selection
required_capabilities: ['code_specialized'],
context_sensitivity: 'medium',
fallback_order: ['local', 'nvidia_qwen', 'gemini']
},
'test-generator': {
description: 'Test Case Generator',
category: 'generation',
system_prompt: `You are a testing expert specializing in comprehensive test coverage.
Generate tests that cover:
1. Happy path scenarios
2. Edge cases
3. Error handling
4. Boundary conditions
5. Integration points
6. Performance benchmarks
Use appropriate testing frameworks and follow testing best practices.`,
suggested_tools: [
'read', // Read code to test
'write_files_atomic', // Write test files
'ask' // Test strategy analysis
],
output_format: `## Test Suite
### Test Coverage Analysis
[What needs testing and why]
### Generated Tests
[Complete test code with:
- Unit tests
- Integration tests
- Edge cases
- Mock/stub setup]
### Coverage Metrics
[Expected coverage percentage]
### Verdict
- **Coverage Score**: X%
- **Quality**: COMPREHENSIVE|ADEQUATE|INSUFFICIENT
- **Additional Tests Needed**: [List if any]`,
requiresVerdict: true,
enableThinking: false, // Fast generation
maxTokens: 32768,
// Dynamic capability-based backend selection
required_capabilities: ['code_specialized'],
context_sensitivity: 'medium',
fallback_order: ['local', 'nvidia_qwen', 'gemini']
},
'documentation-writer': {
description: 'Technical Documentation Writer',
category: 'generation',
system_prompt: `You are a technical writer creating clear, comprehensive documentation.
Your documentation should include:
1. Overview and purpose
2. API/function signatures
3. Usage examples
4. Parameter descriptions
5. Return values
6. Edge cases and gotchas
7. Links to related docs
Write for developers with varying experience levels.`,
suggested_tools: [
'read', // Read code
'write_files_atomic', // Write docs
'ask' // Clarification
],
output_format: `## Documentation
### Overview
[Brief description of component/module]
### API Reference
[Detailed function/class documentation]
### Usage Examples
[Practical code examples]
### Configuration
[Setup and configuration options]
### Troubleshooting
[Common issues and solutions]`,
requiresVerdict: false,
enableThinking: false,
maxTokens: 65536,
// Dynamic capability-based backend selection
required_capabilities: ['fast_generation', 'documentation'],
context_sensitivity: 'low',
fallback_order: ['local', 'nvidia_qwen', 'gemini']
},
// ===========================================
// TDD Workflow Roles (Phase 2: Local Agents)
// ===========================================
'tdd-decomposer': {
description: 'TDD Task Decomposer - Breaks tasks into atomic TDD subtasks',
category: 'planning',
// Note: system_prompt is a TEMPLATE - {{SLOTS}} will be replaced with actual slot count
system_prompt: `You are a TDD task decomposer. Output ONLY valid JSON.
AVAILABLE SLOTS: {{SLOTS}}
CRITICAL RULE: Group tasks BY PHASE, not by feature!
- Group 1: ALL RED tests (up to {{SLOTS}} tasks)
- Group 2: ALL GREEN implementations (up to {{SLOTS}} tasks)
WRONG (grouped by feature):
{"parallel_groups":[{"group":1,"name":"Add","tasks":[{"phase":"RED"},{"phase":"GREEN"}]},{"group":2,"name":"Sub","tasks":[{"phase":"RED"},{"phase":"GREEN"}]}]}
CORRECT (grouped by phase):
{"parallel_groups":[{"group":1,"name":"All tests","tasks":[{"phase":"RED","task":"Test add"},{"phase":"RED","task":"Test sub"}]},{"group":2,"name":"All impls","tasks":[{"phase":"GREEN","task":"Impl add"},{"phase":"GREEN","task":"Impl sub"}]}]}
OUTPUT FORMAT:
{"parallel_groups":[{"group":1,"name":"name","tasks":[{"id":"T1","phase":"RED","task":"description","agent":"tdd-test-writer"}]}]}
AGENTS:
- "tdd-test-writer" for RED phase
- "tdd-implementer" for GREEN phase
EXAMPLE (4 features, {{SLOTS}} slots):
{"parallel_groups":[{"group":1,"name":"RED phase - all tests","tasks":[{"id":"T1","phase":"RED","task":"Write test for add","agent":"tdd-test-writer"},{"id":"T2","phase":"RED","task":"Write test for subtract","agent":"tdd-test-writer"},{"id":"T3","phase":"RED","task":"Write test for multiply","agent":"tdd-test-writer"},{"id":"T4","phase":"RED","task":"Write test for divide","agent":"tdd-test-writer"}]},{"group":2,"name":"GREEN phase - all implementations","tasks":[{"id":"T5","phase":"GREEN","task":"Implement add","agent":"tdd-implementer"},{"id":"T6","phase":"GREEN","task":"Implement subtract","agent":"tdd-implementer"},{"id":"T7","phase":"GREEN","task":"Implement multiply","agent":"tdd-implementer"},{"id":"T8","phase":"GREEN","task":"Implement divide","agent":"tdd-implementer"}]}]}
Output ONLY JSON. No markdown. No explanation.`,
suggested_tools: [],
output_format: 'json',
requiresVerdict: false,
enableThinking: false, // CRITICAL: Prevent chain-of-thought before JSON
maxTokens: 4096, // Increased from 2048 to handle complex decompositions (8+ tasks)
required_capabilities: ['code_specialized'],
context_sensitivity: 'low',
fallback_order: ['local', 'nvidia_qwen'] // Worker-class models only
},
'tdd-test-writer': {
description: 'TDD Test Writer (RED Phase) - Write failing test specifications',
category: 'generation',
system_prompt: `You are a TDD test writer operating in the RED phase.
Your job is to write COMPREHENSIVE, FAILING tests that define expected behavior BEFORE implementation exists.
GUIDELINES:
1. Use pytest/unittest patterns for Python, Jest for JavaScript, appropriate frameworks for other languages
2. Write clear, descriptive test names that explain expected behavior (test_should_X_when_Y pattern)
3. Cover ALL scenarios:
- Happy path (normal valid inputs)
- Edge cases (empty, null, boundary values)
- Error conditions (invalid inputs, exceptions)
- Type validation (wrong types should fail gracefully)
4. Tests should FAIL because the implementation doesn't exist yet
5. Each test should be atomic and test ONE specific behavior
6. Include comprehensive setup/teardown and fixtures
7. Add docstrings explaining what each test validates
8. Use parametrized tests for similar cases
QUALITY REQUIREMENTS:
- Minimum 5 test cases per function/feature
- At least 1 edge case test
- At least 1 error handling test
- All tests must be runnable independently
OUTPUT: Complete, runnable test code with imports, fixtures, and comprehensive docstrings.`,
suggested_tools: [
'read', // Read existing code for context
'write_files_atomic' // Write test files
],
output_format: 'code',
requiresVerdict: false,
enableThinking: true,
maxTokens: 16384,
required_capabilities: ['code_specialized'],
context_sensitivity: 'medium',
fallback_order: ['local', 'nvidia_qwen', 'nvidia_deepseek']
},
'tdd-implementer': {
description: 'TDD Implementer (GREEN Phase) - Minimal implementation to pass tests',
category: 'generation',
system_prompt: `You are a TDD implementer operating in the GREEN phase.
Your job is to write COMPLETE, WORKING code that makes all tests pass.
GUIDELINES:
1. Make ALL tests pass - this is the primary goal
2. Keep it simple but COMPLETE - don't leave stubs or TODOs
3. Follow existing code patterns and style conventions
4. Add comprehensive docstrings explaining the implementation
5. Include proper type hints/annotations where applicable
6. Handle edge cases that tests cover
7. Use defensive programming for error cases
8. The goal is "make it work correctly" with clean code
QUALITY REQUIREMENTS:
- All test cases must pass
- No placeholder/stub code
- Proper error handling for edge cases
- Clear docstrings on all public functions
- Follow language-specific best practices
- Input validation where appropriate
OUTPUT: Complete, working, production-quality implementation code with docstrings.`,
suggested_tools: [
'read', // Read tests and existing code
'write_files_atomic' // Write implementation
],
output_format: 'code',
requiresVerdict: false,
enableThinking: true,
maxTokens: 16384,
required_capabilities: ['code_specialized'],
context_sensitivity: 'medium',
fallback_order: ['local', 'nvidia_qwen', 'nvidia_deepseek']
},
// Special meta-role: auto-selects best role using orchestrator
'auto': {
description: 'Auto-select best role using orchestrator LLM analysis',
system_prompt: '', // Will be replaced by selected role
suggested_tools: [],
output_format: 'dynamic',
required_capabilities: [],
context_sensitivity: 'high',
isMetaRole: true // Flag for special handling
},
'tdd-quality-reviewer': {
description: 'TDD Quality Gate - Reviews outputs and decides iterate/pass',
category: 'review',
system_prompt: `You are a TDD quality reviewer. Evaluate agent outputs and decide if quality is sufficient.
OUTPUT FORMAT (strict JSON):
{
"verdict": "pass" | "iterate",
"score": 0-100,
"issues": ["issue1", "issue2"],
"retry_tasks": ["T1", "T3"],
"summary": "Brief quality assessment"
}
SCORING CRITERIA (be generous for working code):
- 85-100: Excellent - tests pass, code works, good structure
- 70-84: Good - minor issues but functional, PASS with notes
- 50-69: Needs work - missing tests or broken implementation
- 0-49: Poor - fundamentally broken, must retry
IMPORTANT: If the code WORKS and tests PASS, score should be 80+.
Don't penalize for style preferences or "nice to have" improvements.
EVALUATION FACTORS (weighted):
1. [40%] Tests cover core requirements (happy path + basic edge cases)
2. [40%] Implementation passes tests and handles errors
3. [10%] Code follows reasonable style (not nitpicky)
4. [10%] Basic documentation present
Be PRAGMATIC not perfectionist. Working code > perfect code.
If it works and is readable, score 80+. Only iterate for real issues.`,
suggested_tools: ['ask'], // Can query for clarification
output_format: 'json',
requiresVerdict: true,
enableThinking: false, // DISABLED: Prevents timeout, JSON output only
maxTokens: 2048, // Reduced - only needs JSON output
required_capabilities: ['code_specialized'], // Changed from deep_reasoning
context_sensitivity: 'low',
fallback_order: ['local', 'nvidia_qwen', 'nvidia_deepseek']
}
};
/**
* Get list of all available roles
* @returns {string[]}
*/
function getAvailableRoles() {
return Object.keys(roleTemplates);
}
/**
* Get role template by name
* @param {string} role - Role name
* @returns {RoleTemplate|null}
*/
function getRoleTemplate(role) {
return roleTemplates[role] || null;
}
/**
* Get roles by category
* @param {string} category - Category name
* @returns {string[]}
*/
function getRolesByCategory(category) {
return Object.entries(roleTemplates)
.filter(([_, template]) => template.category === category)
.map(([roleName, _]) => roleName);
}
export {
roleTemplates,
getAvailableRoles,
getRoleTemplate,
getRolesByCategory
};