import { writeFile } from "node:fs/promises";
import { makeState, runPromise } from "./t3.ts";
import { run } from "./shell.ts";
const home = process.argv[2]!;
const port = process.argv[3]!;
const { state } = makeState(home, { T3CODE_PORT: port });
const project = await state.project("Exact base demo", { f: "base\n" });
const git = async (...args: string[]) => (await runPromise(run("git", args, { cwd: project }))).stdout.trim();
for (const [branch, content, message] of [["release", "plain\n", "plain release commit"], ["release\u00a0", "nbsp\n", "NBSP release commit"]]) {
 await git("checkout", "main");
 await git("checkout", "-b", branch!);
 await writeFile(`${project}/f`, content!);
 await git("add", "f");
 await git("-c", "user.name=Demo", "-c", "user.email=demo@example.invalid", "commit", "-m", message!);
}
const thread = await state.thread({ project, title: "Exact base worktree", messages: ["ready"] });
await writeFile(`${home}/seed-result.json`, JSON.stringify({ project, thread, expectedHead: await git("rev-parse", "HEAD") }));
console.log("Synthetic project and idle replay thread ready.");
