// `umtool present [--take | --cut] [--json] [--public] [--open] [--url ]`: PRESENT MODE from a // terminal (umtool/docs/knobs.md, "Present mode") -- the viewer's address (`/projects/

/present`), and with // --json the payload it shows (lib/report/present.mjs presentPayload), so an agent can drive it: every slide's id // (a post's `/`, a clip's id, `section-`, `day-`) opens it as `…/present#`. // // Plain ESM: the CLI runs under bare node. import { spawn } from "node:child_process"; import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { umtoolBase } from "./buildRun.mjs"; import { presentPayload } from "./present.mjs"; export const PRESENT_USAGE = [ "usage: umtool present [--take | --cut] [--json] [--public] [--open] [--url ]", "", "PRESENT MODE: the cut as slides, one at a time, navigated like a deck (/projects/

/present). Prints the", "viewer's address and the slides (each one's id, kind, section and date); --json the whole payload (its url", "beside it): every slide in cut order -- a post item's card as Play draws it, its excerpt, its narration take", "and its censor data by kind; a clip's spans from its cached window and the deck's words; section and day", "dividers. With no --take the working draft (the manifest), as Play; --take a saved version; --cut the same as none. --public: the", "payload a public page would carry (the posts censored, no reveal data). --open opens the address (xdg-open).", "A slide opens as #. UMTOOL_URL (else http://localhost:3050) or --url is the app's origin.", ].join("\n"); class CliError extends Error {} /** The viewer's path for a project (lib/hrefs.ts presentHref, in plain ESM). */ export function presentPath(projectId, { take = null, bare = false, slide = null } = {}) { const enc = String(projectId).split("/").filter(Boolean).map(encodeURIComponent).join("/"); const q = new URLSearchParams(); if (take) q.set("take", take); else if (bare) q.set("cut", "1"); const qs = q.toString(); return `/projects/${enc}/present${qs ? `?${qs}` : ""}${slide ? `#${slide}` : ""}`; } /** * @param {string[]} args the words after `present` * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void, env?: Record, open?: (url: string) => void }} [opts] * @returns {Promise} */ export async function presentCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s), env = process.env, open = openUrl } = {}) { try { const words = []; const flags = new Map(); for (let i = 0; i < args.length; i += 1) { const a = args[i]; if (a === "--take" || a === "--url") { if (i + 1 >= args.length) throw new CliError(`${a} needs a value`); flags.set(a, args[++i]); } else if (a.startsWith("--")) flags.set(a, true); else words.push(a); } if (!words[0] || flags.has("--help")) { (flags.has("--help") ? out : err)(PRESENT_USAGE); return flags.has("--help") ? 0 : 2; } for (const f of flags.keys()) if (!["--take", "--cut", "--json", "--public", "--open", "--url"].includes(f)) throw new CliError(`unknown flag ${f}\n\n${PRESENT_USAGE}`); if (flags.has("--take") && flags.has("--cut")) throw new CliError("--take and --cut: one or the other"); const r = await resolveProject(words[0], root); if (r.ambiguous) throw new CliError(`"${words[0]}" is the name of ${r.ambiguous.length} projects — pass its id`); if (!r.project) throw new CliError(`no project matches "${words[0]}"`); const project = r.project; const take = flags.has("--take") ? String(flags.get("--take")) : null; const bare = flags.has("--cut"); const payload = await presentPayload(project, { take, bare, canUncensor: !flags.has("--public") }); if ("error" in payload) throw new CliError(String(payload.error)); const url = `${umtoolBase(flags.get("--url"), env)}${presentPath(project.id, { take, bare })}`; if (flags.has("--json")) out(JSON.stringify({ url, ...payload }, null, 2)); else { const what = payload.take ? `version ${payload.take.id}` : "the draft"; const posts = payload.slides.filter((s) => s.kind === "post").length; out(`${url}`); out(`${project.id} · ${what} · ${payload.slides.length} slide(s), ${posts} post(s) · ${payload.sections.length} section(s)`); for (const s of payload.slides) { const censor = s.kind === "post" && s.censor ? ` [${Object.entries(s.censor.counts).filter(([, n]) => n).map(([k, n]) => `${n} ${k}`).join(", ")}]` : ""; out(` ${s.kind.padEnd(7)} ${s.id}${s.dateLabel ? ` ${s.dateLabel}` : ""} ${String(s.label ?? "").slice(0, 70)}${censor}`); } } if (flags.has("--open")) open(url); return 0; } catch (e) { if (e instanceof CliError) { err(`umtool present: ${e.message}`); return 1; } throw e; } } function openUrl(url) { const cmd = process.platform === "darwin" ? "open" : "xdg-open"; try { spawn(cmd, [url], { detached: true, stdio: "ignore" }).on("error", () => {}).unref(); } catch { // Nothing to open it with: the address is printed above. } }