import { Agent } from "thinkwell:agent";
import { CLAUDE_CODE } from "thinkwell:connectors";
/** @JSONSchema */
interface ReviewResult {
summary: string;
issues: Array<{
file: string;
line: number;
description: string;
}>;
}
/** @JSONSchema */
interface FixPlan {
steps: string[];
estimatedEffort: "trivial" | "small" | "medium" | "large";
}
async function reviewCode(projectPath: string) {
const agent = await Agent.connect(CLAUDE_CODE);
const session = await agent.createSession({ cwd: projectPath });
try {
// First turn: review the code
const review = await session
.think(ReviewResult.Schema)
.text("Review the code in this project for bugs and improvements")
.run();
console.log(`Review: ${review.summary}`);
console.log(`Found ${review.issues.length} issues\n`);
// Second turn: create a fix plan based on the review
const plan = await session
.think(FixPlan.Schema)
.text("Create a plan to fix the most critical issues you found")
.run();
console.log(`Estimated effort: ${plan.estimatedEffort}`);
console.log("Steps:");
plan.steps.forEach((step, i) => console.log(`${i + 1}. ${step}`));
} finally {
session.close();
agent.close();
}
}
reviewCode("/path/to/project");