summaryrefslogtreecommitdiff
path: root/admin-panel/src/server/agents/ranger.ts
blob: f1f391823d233cfc3e949438c0262a9cafebe302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { BaseAgent, type AgentContext, type AgentResult } from './base-agent.js';
import type { ClaudeResponse } from '../services/claude.service.js';

export class RangerAgent extends BaseAgent {
  name = 'ranger';
  templateFile = 'ranger.md';
  model = 'claude-sonnet-4-20250514';

  protected getSystemPrompt(): string {
    return 'You are a QA engineer making the final pass/fail decision. Be fair but thorough. Only pass tasks that genuinely meet their acceptance criteria.';
  }

  protected parseResponse(response: ClaudeResponse, _ctx: AgentContext): AgentResult {
    const content = response.content;
    const firstLine = content.split('\n')[0].trim().toUpperCase();
    const passed = firstLine.includes('PASS');
    const verdict: 'approve' | 'reject' = passed ? 'approve' : 'reject';

    const testEntry = {
      agent: 'ranger',
      verdict: passed ? 'pass' : 'fail',
      content,
      timestamp: new Date().toISOString(),
    };

    const updates: Record<string, unknown> = {};

    let currentResults: unknown[];
    try {
      currentResults = JSON.parse(_ctx.testResults || '[]');
    } catch {
      currentResults = [];
    }
    currentResults.push(testEntry);
    updates.test_results = JSON.stringify(currentResults);

    if (passed) {
      updates.status = 'done';
      updates.completed_at = new Date().toISOString();
    } else {
      updates.status = 'impl'; // Send back to builder
    }

    return {
      success: true,
      content,
      tokensUsed: response.tokensUsed,
      model: response.model,
      updates,
      verdict,
      message: `Final verdict: ${passed ? 'PASS' : 'FAIL'}`,
    };
  }
}