// `tsus init [dir]`: scaffold a project with the agent primer (AGENTS.md), a// strict tsconfig, a package.json and a starter module. Existing files are// left alone; --force refreshes AGENTS.md (and only AGENTS.md) to the primer// shipped with this version of the CLI.import fs from "node:fs";import path from "node:path";import { fileURLToPath } from "node:url";const templates = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "templates");const packageJson = (name) => JSON.stringify( { name, private: true, type: "module", scripts: { check: "tsus check", fix: "tsus fix", build: "tsus build", start: "tsus build && node dist/main.js", }, dependencies: { "@tsus/runtime": "^0.1.0" }, devDependencies: { "@tsus/cli": "^0.1.0" }, }, null, 2, ) + "\n";export const initProject = (dir, { force = false } = {}) => { const name = path.basename(path.resolve(dir)).toLowerCase().replace(/[^a-z0-9-]+/g, "-") || "tsus-app"; const files = [ ["AGENTS.md", () => fs.readFileSync(path.join(templates, "AGENTS.md"), "utf8")], ["CLAUDE.md", () => "@AGENTS.md\n"], ["tsconfig.json", () => fs.readFileSync(path.join(templates, "tsconfig.json"), "utf8")], ["package.json", () => packageJson(name)], [".gitignore", () => "node_modules/\ndist/\n"], ["src/main.tsus", () => fs.readFileSync(path.join(templates, "src", "main.tsus"), "utf8")], ]; const written = []; const skipped = []; for (const [rel, content] of files) { const dest = path.join(dir, rel); if (fs.existsSync(dest) && !(force && rel === "AGENTS.md")) { skipped.push(rel); continue; } fs.mkdirSync(path.dirname(dest), { recursive: true }); fs.writeFileSync(dest, content()); written.push(rel); } return { written, skipped };};