// The manual's CLI reference (docs/manual.feature DM3, raea.io/docs/reference/cli/): a page a verb, its usage, where it // runs and its flags written from `raea help --json`, so the page says what the binary takes. What the binary can't say // is the page's own: its prose above and below the generated block, and each flag's description in the block's table, // which a rewrite keeps by the flag's name. `check` fails on a block that's out of date, a flag without a description // and a verb missing from GROUPS. // bun tools/manual-ref/cli.ts gen [DIR] rewrite the pages in DIR (docs/manual/reference/cli) // bun tools/manual-ref/cli.ts check [DIR] the pages as gen would write them, every flag described import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs" import path from "node:path" const ROOT = path.resolve(import.meta.dir, "../..") const [mode = "check", dirArg] = process.argv.slice(2) const DIR = path.resolve(dirArg ?? path.join(ROOT, "docs/manual/reference/cli")) const BIN = process.env.RAEA_BIN ?? path.join(ROOT, "target/release/raea") if (mode !== "gen" && mode !== "check") throw new Error("usage: cli.ts gen|check [DIR]") type Flag = { flag: string; values: number } type Verb = { verb: string; usage: string[]; flags: Flag[] | null; args: number | null; access: string; own_parser: boolean } function run(args: string[]): string { const p = Bun.spawnSync([BIN, ...args], { env: { ...process.env, NO_COLOR: "1" } }) return (p.stdout.toString() + p.stderr.toString()).trim() } const verbs: Verb[] = JSON.parse(run(["help", "--json"])).verbs // the index's groups, in the order a reader meets them; every verb is in one const GROUPS: [string, string, string[]][] = [ ["Make", "Render, play and package what you wrote.", ["render", "play", "export-game", "playable", "export", "bundle", "app", "run"]], ["Projects", "The workspace, its projects and what a project holds.", ["init", "workspace", "project", "spec", "component", "part", "add", "brand", "library", "index"]], ["Check", "What's wrong before anyone watches it.", ["check", "judge", "make", "fingerprint", "findings", "scene", "light", "bench", "world", "solid", "next", "doctor", "hook", "traces"]], ["Footage", "Takes, cuts and the camera, from your own media.", ["media", "cut", "frame", "track", "splat", "mezz", "neural"]], ["Sound", "Music read, foley and instruments made on this machine.", ["song", "sounds", "sao", "tokensynth", "setup-audio", "voice"]], ["Generate and 3D tools", "Generated media, physics, light and weathering bakes, clothes and motion for SOMA's body, Blender and Godot.", ["gen", "physics", "bake", "wear", "clothes", "motion", "blender", "godot"]], ["Agents and setup", "What an agent reads and shows the person, and the tools raea installs.", ["guide", "fix", "context", "notes", "show", "skill", "skills", "setup", "bug", "ask"]], ] /** A verb's page: VERB.md, but index.md is this section's own page, so raea index's is indexer.md */ const pageOf = (verb: string) => (verb === "index" ? "indexer.md" : `${verb}.md`) const groupOf = new Map(GROUPS.flatMap(([g, , vs]) => vs.map((v, i) => [v, { g, i }] as const))) // a verb with its own parser lists its forms itself: that list is its usage const OWN_HELP: Record = { media: ["media", "help"], gen: ["gen"], blender: ["blender"], godot: ["godot"], physics: ["physics"], wear: ["wear"] } function ownHelp(v: string): string { return run(OWN_HELP[v] ?? [v]).replace(/^REFUSED\s+/, "").replace(/^usage:\s*/, "").split("\n").map((l) => l.replace(/^\s{7}(raea )/, "$1").trimEnd()).join("\n") } // what follows a flag in its usage: `--frame N`, `--quality draft|high|master|0..1`, `--snapshot T FILE` function valuesOf(v: Verb, f: Flag): string { if (!f.values) return "" const esc = f.flag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") for (const line of v.usage) { const m = new RegExp(`(?:^|[\\s\\[|])${esc}(?:\\s+([^\\s\\[\\]]+))${f.values > 1 ? "(?:\\s+([^\\s\\[\\]]+))" : ""}`).exec(line.split(" (")[0]) if (m) return [m[1], m[2]].filter(Boolean).map((t) => t.replace(/[\]|,;]+$/, "")).filter((t) => !t.startsWith("-")).join(" ") } return f.values === 1 ? "VALUE" : Array.from({ length: f.values }, (_, i) => `V${i + 1}`).join(" ") } const ACCESS: Record = { HEADLESS: "Headless: it needs nothing running and opens no window.", HOST: "Needs the raea app's host running on this machine.", PERSON: "Waits for a person's click in the raea app.", } const accessLine = (a: string) => ACCESS[a] ?? a.split(/, then /).map((p, i) => (i ? "then " : "") + (i ? (ACCESS[p.split(" ")[0]] ?? p).replace(/^W/, "w") : ACCESS[p.split(" ")[0]] ?? p).replace(/\.$/, "") + (p.includes(" to ") ? ` (${p.slice(p.indexOf(" to ") + 1)})` : "")).join("; ") + "." const argsLine = (v: Verb) => (v.own_parser ? "Its arguments go to a parser of its own, whose forms are listed above." : v.args === null ? "Takes any number of arguments besides its flags." : v.args === 0 ? "Takes no arguments besides its flags." : `Takes up to ${v.args} argument${v.args === 1 ? "" : "s"} besides its flags.`) const BEGIN = "" const END = "" const cell = (s: string) => s.replace(/\|/g, "\\|") const uncell = (s: string) => s.replace(/\\\|/g, "|").trim() type Page = { head: string; tail: string; desc: Map; summary: string } function readPage(file: string): Page | null { if (!existsSync(file)) return null const text = readFileSync(file, "utf8") const b = text.indexOf("