import { query } from "@anthropic-ai/claude-agent-sdk"; import { readFileSync } from "fs"; import { resolve } from "path"; // 2-build-one.ts — Single builder agent. // Reads a spec file, sends it as context, and lets one agent build a layer. // Generic: swap the spec file to build anything. const SPEC_PATH = resolve(import.meta.dir, "sample/spec.md"); const REPO_DIR = resolve(import.meta.dir, "../../../multi-agent"); const spec = readFileSync(SPEC_PATH, "utf-8"); const systemPrompt = `You are a domain modeler. Build the domain model layer for the project described in the spec below. Create all model files: records, enums, value objects with proper validation. Write unit tests for each model. After building, run the test command from the spec. If tests pass: git add -A && git commit -m "feat: add domain models" If tests fail: fix and retry. Only create files for the model layer — do not build controllers, repositories, or other layers. ## Spec ${spec}`; console.log("Single builder agent"); console.log(` Spec: ${SPEC_PATH}`); console.log(` Repo: ${REPO_DIR}\n`); const q = query({ prompt: "Build the domain model layer as described in your system prompt. Create all model classes with validation, write tests, run them, and commit if green.", options: { systemPrompt, allowedTools: ["Read", "Write", "Edit", "Bash", "Glob", "Grep"], maxTurns: 40, cwd: REPO_DIR, permissionMode: "bypassPermissions", }, }); for await (const msg of q) { if (msg.type === "assistant" && msg.message) { for (const block of msg.message.content) { if (block.type === "tool_use") { const detail = block.input?.file_path ?? block.input?.command ?? block.input?.pattern ?? ""; const short = typeof detail === "string" ? detail.slice(0, 100) : JSON.stringify(detail).slice(0, 100); console.log(` [MODELS] ${block.name}(${short})`); } } } if (msg.type === "result") { console.log( `\nDone [${msg.subtype}, $${msg.total_cost_usd.toFixed(4)}]` ); } }