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
55
56
57
58
59
60
61
62
|
import { BaseAgent, type AgentContext, type AgentResult } from './base-agent.js';
import type { ClaudeResponse } from '../services/claude.service.js';
export class ShieldAgent extends BaseAgent {
name = 'shield';
templateFile = 'shield.md';
model = 'claude-sonnet-4-20250514';
protected getSystemPrompt(): string {
return 'You are a test engineer who writes thorough, practical tests. Focus on verifying requirements and catching regressions. Use appropriate testing frameworks.';
}
protected getMaxTokens(): number {
return 12288;
}
protected parseResponse(response: ClaudeResponse, _ctx: AgentContext): AgentResult {
const content = response.content;
// Extract test files
const files = parseTestFiles(content);
const strategy = extractSection(content, 'Test Strategy') || '';
return {
success: true,
content,
tokensUsed: response.tokensUsed,
model: response.model,
updates: {
// Test files are written by pipeline service
// Test results will be populated after running
},
message: `Generated ${files.length} test file(s)`,
};
}
}
interface TestFile {
path: string;
content: string;
}
function parseTestFiles(text: string): TestFile[] {
const files: TestFile[] = [];
const regex = /```FILE:\s*(.+?)\n([\s\S]*?)```/g;
let match;
while ((match = regex.exec(text)) !== null) {
files.push({
path: match[1].trim(),
content: match[2],
});
}
return files;
}
function extractSection(text: string, heading: string): string | null {
const regex = new RegExp(`###\\s*${heading}\\s*\\n([\\s\\S]*?)(?=###|$)`, 'i');
const match = text.match(regex);
return match ? match[1].trim() : null;
}
|