Project Files
src / agents / optimizer.ts
import { completeText, extractJson } from "../llm";
import type { BuildPlan, Patch } from "../types";
export class Optimizer {
constructor(private readonly model: any) {}
async run(input: {
plan: BuildPlan;
snapshot: string;
issues: string[];
memorySummary: string;
}): Promise<Patch[]> {
const prompt = [
"You are the Optimizer agent for Codechecker Forge.",
"Return JSON only. No markdown, no commentary.",
"Fix the issues with minimal diff-based patches.",
"",
"Plan:",
JSON.stringify(input.plan, null, 2),
"",
"Workspace snapshot:",
input.snapshot,
"",
"Issues to fix:",
input.issues.join("\n"),
"",
"Relevant memories:",
input.memorySummary || "(none)",
"",
"Return exactly this JSON shape:",
`{ "patches": [ { "file": "src/index.ts", "operation": "replace", "target": "old", "content": "new" } ] }`
].join("\n");
const raw = await completeText(this.model, prompt, 3200, 0.12);
const parsed = extractJson<{ patches: Patch[] }>(raw);
return Array.isArray(parsed.patches) ? parsed.patches : [];
}
}