Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"prepare": "tsc",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"fake": "tsx scripts/fake.ts"
"fake": "tsx scripts/fake.ts",
"try": "tsx scripts/try.ts"
},
"dependencies": {
"@codehands/contracts": "file:../../codehands-contracts"
"@codehands/contracts": "file:../../codehands-contracts",
"execa": "^10.2.0"
},
"devDependencies": {
"@types/node": "^26.6.5",
Expand Down
134 changes: 134 additions & 0 deletions runner/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions runner/scripts/try.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// pnpm try [repoPath] [prompt] [--approve | --reject]: one real run through the runner, one event per line.
// Without a flag it asks approve / reject / keep at the end (or keeps, when not in a terminal).
// Costs real money (capped by budgetUsd below). Run scripts/reset-fixture.sh afterwards.
import { randomUUID } from "node:crypto";
import { homedir } from "node:os";
import { join } from "node:path";
import { createInterface } from "node:readline/promises";
import { createRunner } from "../src/index.js";

const flags = process.argv.slice(2).filter((a) => a.startsWith("--"));
const [repoPath = join(homedir(), "codehands-fixtures", "date-bug"), prompt = "Fix the failing test. Run npm test to check."] =
process.argv.slice(2).filter((a) => !a.startsWith("--"));

const runner = createRunner();
const sessionId = randomUUID();
let finished = false;
for await (const e of runner.start({ sessionId, repoPath, prompt, agent: "claude-code", model: "sonnet", budgetUsd: 0.5 })) {
const p = e.payload;
const detail = p.reason ?? p.command ?? p.path ?? (typeof p.text === "string" ? p.text.slice(0, 80) : "") ?? "";
const extra = e.type === "test.result" ? ` passed=${p.passed}` : e.type === "task.finished" ? ` $${p.total_cost_usd}` : "";
console.log(`${String(e.seq).padStart(3)} ${e.type.padEnd(17)} ${String(detail).replace(/\s+/g, " ")}${extra}`);
if (e.type === "task.finished") finished = true;
}
if (!finished) process.exit(1);

console.log(`\n${(await runner.diff(sessionId)).stat}\n`);

let choice = flags.includes("--approve") ? "a" : flags.includes("--reject") ? "r" : "k";
if (!flags.length && process.stdin.isTTY) {
const rl = createInterface({ input: process.stdin, output: process.stdout });
choice = (await rl.question("approve, reject or keep? [a/r/k] ")).trim().toLowerCase()[0] ?? "k";
rl.close();
}

if (choice === "a") {
const { branch, commit } = await runner.approve(sessionId, prompt);
console.log(`approved: ${branch} @ ${commit.slice(0, 7)} (git log ${branch} --oneline -1)`);
} else if (choice === "r") {
await runner.reject(sessionId);
console.log("rejected: worktree and branch deleted");
} else {
console.log("kept: the worktree is still there, see `git worktree list` in the repo");
}
Loading
Loading