Project Files
src / agents / coder.ts
import { completeText, extractJson } from "../llm";
import type { BuildPlan, Patch } from "../types";
export class Coder {
constructor(private readonly model: any) {}
async run(input: {
plan: BuildPlan;
snapshot: string;
issues: string[];
memorySummary: string;
}): Promise<Patch[]> {
const prompt = [
"You are the Coder agent for Codechecker Forge.",
"Return JSON only. No markdown, no commentary.",
"Generate minimal diff-based patches only.",
"Do not rewrite whole files unless necessary.",
"",
"Current plan:",
JSON.stringify(input.plan, null, 2),
"",
"Workspace snapshot:",
input.snapshot,
"",
"Known issues:",
input.issues.length ? input.issues.join("\n") : "(none)",
"",
"Relevant memories:",
input.memorySummary || "(none)",
"",
"Return exactly this JSON shape:",
`{ "patches": [ { "file": "src/index.ts", "operation": "overwrite", "content": "..." } ] }`
].join("\n");
const raw = await completeText(this.model, prompt, 3200, 0.15);
const parsed = extractJson<{ patches: Patch[] }>(raw);
return Array.isArray(parsed.patches) ? parsed.patches : [];
}
}