Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 04e6d1de9f19db6b8a4538c459cc45c11a2d08a6
parent 5376032212bfd70e182d47e5eb99b90c376a2c4d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  2 Nov 2026 13:37:25 -0500

umtool new: <folder>/<slug> or --folder <folder> -- the project made in a folder of the reports tree, its id the path under the root (routed /projects/<folder>/<slug>); a folder segment that will not route, the reserved one, one past the walk's depth, or a folder that is itself a project is refused

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/bin/umtool.mjs | 15+++++++++------
Mumtool/lib/projects/scaffold.mjs | 77++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Aumtool/lib/scaffold-folder.test.mjs | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 151 insertions(+), 17 deletions(-)

diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -46,7 +46,7 @@ // --draft-all is Draft everything: the drafts between manifest and the fast build; // --deck adds the on-screen deck to a cut with none before the flips // umtool index [--rebuild] [--prune] [--since MS] [--json] -// umtool new <slug> [--kind report-video] [--from <report.md>|<share URL>|<channel>/<id>] +// umtool new <slug> | <folder>/<slug> [--folder <folder>] [--kind report-video] [--from <report.md>|<share URL>|<channel>/<id>] // [--site-origin URL] [--seed chapters|frames [--target S]] [--brand archilyzer-media] // umtool doctor [--json] exit 1 if the report pipeline is missing a tool // or the media root is set and not there @@ -900,6 +900,8 @@ function usage() { " --deck adds a step before the flips: the minimal on-screen deck on a cut with none", " umtool index [--rebuild] [--prune] [--since MS] [--json]", " umtool new <slug> [--from <report.md>|<share URL>|<channel>/<id>] [--site-origin URL] [--seed chapters|frames]", + " <folder>/<slug>, or --folder <folder>: the project in a folder of the reports tree (its id", + " <folder>/<slug>, routed /projects/<folder>/<slug>) — a spin-off beside its parent", " --seed frames: a draft supercut from the video's frame scan (pnpm ops frame-scan) — the events", " ranked (scoops, milestones, swings, pots, level-ups) into --target <seconds> (default 240), the", " deck on with the stats region drawing frameScan.overlay over each clip", @@ -1639,7 +1641,7 @@ async function cmdNew() { const slug = positional[0]; if (!slug) { die( - "usage: umtool new <slug> [--kind report-video] [--title T]\n" + + "usage: umtool new <slug> | <folder>/<slug> [--folder <folder>] [--kind report-video] [--title T]\n" + " [--from <sweep-report.md> | <share URL> | <channel>/<videoId>]\n" + " [--site-origin <url>] [--seed chapters|frames [--target <seconds>]] [--brand archilyzer-media]\n" + " [--seed phrase --phrase <regex> --channels a,b [--prefer <slug>] [--exclude <regex>] [--max N]]\n" + @@ -1654,6 +1656,7 @@ async function cmdNew() { r = await scaffoldReportVideo({ root: REPORTS_ROOT, slug, + folder: val("--folder") ?? null, title: val("--title"), from: val("--from") ?? null, siteOrigin: val("--site-origin") ?? null, @@ -1683,8 +1686,8 @@ async function cmdNew() { if (val("--seed") === "reactions" && !has("--no-analyze")) { const { clipsCommand } = await import("../lib/report/reactions.mjs"); const log = json ? (s) => console.error(s) : (s) => console.log(s); - if (!json) console.log(`${r.dir}\n running umtool clips analyze ${slug} …`); - analyzed = await clipsCommand(["analyze", slug], { log, err: (s) => console.error(s) }); + if (!json) console.log(`${r.dir}\n running umtool clips analyze ${r.id} …`); + analyzed = await clipsCommand(["analyze", r.id], { log, err: (s) => console.error(s) }); } if (json) return out({ ok: true, ...r, ...(analyzed !== null ? { analyzed: analyzed === 0 } : {}) }); @@ -1709,6 +1712,6 @@ async function cmdNew() { console.log(` Two finished videos shipped with QR codes that resolve to nothing.`); } console.log(` 2. write the timeline (umtool/docs/authoring.md)`); - console.log(` 3. umtool check ${slug}`); - console.log(` 4. umtool build ${slug} --preset fast`); + console.log(` 3. umtool check ${r.id}`); + console.log(` 4. umtool build ${r.id} --preset fast`); } diff --git a/umtool/lib/projects/scaffold.mjs b/umtool/lib/projects/scaffold.mjs @@ -3,7 +3,7 @@ // different skeletons. // // Plain ESM: `umtool new` runs from a terminal with no server. -import { mkdir, readFile, stat, writeFile } from "node:fs/promises"; +import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { BRAND_IDS } from "umtool-report-to-video/brand-ids"; import { FRAMES_CUT_DEFAULTS, framesCut } from "umtool-report-to-video/frames-cut"; @@ -11,6 +11,8 @@ import { capInstances, instancesAsClips, phraseScan } from "yt-dlp-transcript-co import { PARAM_BOUNDS, normalizeScope } from "yt-dlp-transcript-common/lib/clips/clips.mjs"; import { writeReactions } from "yt-dlp-transcript-common/lib/clips/reactions.mjs"; import { GLOBAL_CHANNELS_DIR, MANIFEST_NAME } from "./report.mjs"; +import { RESERVED_BROWSE, detectKind, skipsDir } from "./kinds.mjs"; +import { MAX_DEPTH, isSegment } from "./walk.mjs"; export const SLUG_RE = /^[a-z0-9][a-z0-9-]*$/; // A channel's directory name: mixed case is a channel too (HasanAbiVODs3); no separators, no dot first. @@ -237,6 +239,60 @@ const capNote = (max, kept, found) => : `Capped at ${max} (--max): all ${found} instance(s) kept`; /** + * Where a new project goes: `slug` alone (REPORTS_ROOT's top level), `folder` + * + `slug`, or `slug` given as `folder/slug` (2 Nov: `umtool new + * emberparadox/kirsche` refused, and the only way into a folder was + * `REPORTS_DIR=~/reports/emberparadox umtool new kirsche`). The id is the path + * under the root, as walkProjects names it, so the project routes as + * `/projects/<folder>/<slug>`. + * + * Refused: a slug that will not route; a folder segment that will not + * (walk.mjs isSegment), is a dot-directory, a directory the walk skips, or the + * reserved first segment; deeper than the walk looks (MAX_DEPTH); a folder + * that IS a project, or sits inside one -- a project is a leaf, so one made + * under it would never be listed. + * + * @param {string} root + * @param {string} slugArg + * @param {string | null} folderArg + * @returns {Promise<{ id: string, slug: string, folder: string | null }>} + */ +export async function projectPlace(root, slugArg, folderArg = null) { + const raw = String(slugArg ?? "").replace(/^\/+|\/+$/g, ""); + const parts = raw.split("/"); + const slug = parts.pop() ?? ""; + const folderParts = [ + ...String(folderArg ?? "").replace(/^\/+|\/+$/g, "").split("/").filter(Boolean), + ...parts, + ]; + if (!SLUG_RE.test(slug)) { + throw new Error(`"${slug}" will not route — use lower-case letters, digits and dashes`); + } + for (const seg of folderParts) { + if (!isSegment(seg) || seg.startsWith(".") || skipsDir(seg)) throw new Error(`folder "${folderParts.join("/")}": "${seg}" will not route`); + } + if (folderParts.length && RESERVED_BROWSE.includes(folderParts[0])) { + throw new Error(`folder "${folderParts[0]}" is a reserved address (/projects/${folderParts[0]}/…) — the project would never be reached`); + } + if (folderParts.length + 1 > MAX_DEPTH) { + throw new Error(`${[...folderParts, slug].join("/")} is ${folderParts.length + 1} levels deep; the project list looks ${MAX_DEPTH} down`); + } + // A folder that is a project (or is inside one): the new project would be a leaf's child. + for (let i = 1; i <= folderParts.length; i += 1) { + const at = path.join(root, ...folderParts.slice(0, i)); + const names = await readdir(at).then((n) => new Set(n), () => null); + if (!names) break; + let declared = null; + if (names.has("project.json")) declared = await readFile(path.join(at, "project.json"), "utf8").then((t) => JSON.parse(t), () => null); + if (detectKind(names, declared)) { + throw new Error(`${folderParts.slice(0, i).join("/")} is a project, not a folder — a project inside it would never be listed`); + } + } + const folder = folderParts.length ? folderParts.join("/") : null; + return { id: folder ? `${folder}/${slug}` : slug, slug, folder }; +} + +/** * Write the project. Refuses an existing directory and a slug that will not * route; everything else it cannot know is written EMPTY so `check` blocks. * @@ -259,12 +315,10 @@ const capNote = (max, kept, found) => * * @param {{ root: string, slug: string, title?: string, from?: string | null, siteOrigin?: string | null, seed?: string | null, brand?: string | null, channelsDir?: string, timeline?: Record<string, unknown>[] | null, timelineFrom?: string | null, target?: number, phrase?: string | null, channels?: string[] | null, prefer?: string | null, exclude?: string | null, scan?: { instances: any[], hits: any[], dropped: any[], scanned: number } | null, max?: number | null, laughMin?: number, scope?: [number, number | null] | "auto" | null, segment?: string | null, sitesDir?: string }} args */ -export async function scaffoldReportVideo({ root, slug, title, from = null, siteOrigin = null, seed = null, brand = null, channelsDir = GLOBAL_CHANNELS_DIR(), timeline = null, timelineFrom = null, target = undefined, phrase = null, channels = null, prefer = null, exclude = null, scan: given = null, max = null, laughMin = undefined, scope = null, segment = null, sitesDir = undefined }) { - if (!SLUG_RE.test(String(slug ?? ""))) { - throw new Error(`"${slug}" will not route — use lower-case letters, digits and dashes`); - } - const dir = path.join(root, slug); - if (dir !== path.resolve(root, slug) || path.dirname(dir) !== path.resolve(root)) { +export async function scaffoldReportVideo({ root, slug: slugArg, folder: folderArg = null, title, from = null, siteOrigin = null, seed = null, brand = null, channelsDir = GLOBAL_CHANNELS_DIR(), timeline = null, timelineFrom = null, target = undefined, phrase = null, channels = null, prefer = null, exclude = null, scan: given = null, max = null, laughMin = undefined, scope = null, segment = null, sitesDir = undefined }) { + const { id, slug, folder } = await projectPlace(root, slugArg, folderArg); + const dir = path.join(root, ...id.split("/")); + if (dir !== path.resolve(root, id) || path.dirname(dir) !== path.resolve(root, folder ?? ".")) { throw new Error("refusing to create outside the tree"); } if (await stat(dir).then(() => true, () => false)) throw new Error(`${dir} already exists`); @@ -426,11 +480,11 @@ export async function scaffoldReportVideo({ root, slug, title, from = null, site const used = pass.doc.proposals.filter((p) => p.used); const host = pass.doc.speakers.find((s) => s.role === "host"); notes.push(`${pass.doc.proposals.length} proposal(s), ${used.length} in the cut: ${Math.round(used.reduce((n, p) => n + p.end - p.start, 0))} s of a ${pass.doc.params.target} s target (--target)`); - notes.push(`the host: speaker ${host ? host.index : "?"} of ${pass.doc.speakers.length} (by turn statistics — flip it in the clip editor or with umtool clips propose ${slug} --host N)`); + notes.push(`the host: speaker ${host ? host.index : "?"} of ${pass.doc.speakers.length} (by turn statistics — flip it in the clip editor or with umtool clips propose ${id} --host N)`); notes.push(...(pass.notes ?? [])); const read = pass.doc.params.scope; - if (read) notes.push(`only ${read[0]}–${read[1] ?? "the end"} s of the recording is read (--scope${reactionsScope === "auto" ? ` auto${pass.doc.segment ? `: ${pass.doc.segment}` : ""}` : ""}; umtool clips segments ${slug} lists the narrated videos)`); - notes.push(`laughs from the transcript only (${pass.doc.laughs.length}); umtool clips analyze ${slug} runs the laugh scan and the voices on the sound, then proposes again`); + if (read) notes.push(`only ${read[0]}–${read[1] ?? "the end"} s of the recording is read (--scope${reactionsScope === "auto" ? ` auto${pass.doc.segment ? `: ${pass.doc.segment}` : ""}` : ""}; umtool clips segments ${id} lists the narrated videos)`); + notes.push(`laughs from the transcript only (${pass.doc.laughs.length}); umtool clips analyze ${id} runs the laugh scan and the voices on the sound, then proposes again`); if (pass.rec.wordsFrom === "cues") notes.push("no word timings: edges sit on the cues; pnpm ops transcribe {path, words:true, out: <project>/words.json} gives words, then umtool clips propose"); if (!pass.doc.proposals.length) notes.push("nothing to propose: no host comments or laughs were found"); } @@ -541,7 +595,8 @@ export async function scaffoldReportVideo({ root, slug, title, from = null, site return { dir, kind: "report-video", - id: slug, + id, + ...(folder ? { folder } : {}), title: finalTitle, from: src, citations: citations.length, diff --git a/umtool/lib/scaffold-folder.test.mjs b/umtool/lib/scaffold-folder.test.mjs @@ -0,0 +1,76 @@ +// `umtool new <folder>/<slug>` and `umtool new <slug> --folder <folder>`: a +// project made inside a folder of the reports tree, its id the path under the +// root, routed as walkProjects routes it (2 Nov: `umtool new +// emberparadox/kirsche` refused "will not route", and the way in was +// REPORTS_DIR=<folder>). +// +// Run with: pnpm test:scripts +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { projectPlace, scaffoldReportVideo } from "./projects/scaffold.mjs"; +import { walkProjects } from "./projects/walk.mjs"; + +const CLI = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "bin", "umtool.mjs"); + +test("folder/slug and --folder both make <folder>/<slug>, an id that routes and lists in its folder", async (t) => { + const tmp = await mkdtemp(path.join(os.tmpdir(), "umtool-new-folder-")); + t.after(() => rm(tmp, { recursive: true, force: true })); + const root = path.join(tmp, "reports"); + // The parent: a project already in the folder. + const r1 = await scaffoldReportVideo({ root, slug: "emberparadox/in-her-words", channelsDir: path.join(tmp, "channels") }); + assert.equal(r1.id, "emberparadox/in-her-words"); + assert.equal(r1.folder, "emberparadox"); + assert.equal(r1.dir, path.join(root, "emberparadox", "in-her-words")); + const r2 = await scaffoldReportVideo({ root, slug: "kirsche", folder: "emberparadox", channelsDir: path.join(tmp, "channels") }); + assert.equal(r2.id, "emberparadox/kirsche"); + assert.equal(r2.dir, path.join(root, "emberparadox", "kirsche")); + const doc = JSON.parse(await readFile(path.join(r2.dir, "video.manifest.json"), "utf8")); + assert.equal(doc.slug, "kirsche", "the manifest's slug is the project's own name"); + const listed = await walkProjects(root); + assert.deepEqual( + listed.map((p) => [p.id, p.folder, p.routing]), + [ + ["emberparadox/in-her-words", "emberparadox", "ok"], + ["emberparadox/kirsche", "emberparadox", "ok"], + ], + ); + // A flat slug is as it was. + const r3 = await scaffoldReportVideo({ root, slug: "flat-one", channelsDir: path.join(tmp, "channels") }); + assert.equal(r3.id, "flat-one"); + assert.equal(r3.folder, undefined); + await assert.rejects(scaffoldReportVideo({ root, slug: "emberparadox/kirsche", channelsDir: path.join(tmp, "channels") }), /already exists/); +}); + +test("what will not route is refused before anything is written", async (t) => { + const tmp = await mkdtemp(path.join(os.tmpdir(), "umtool-new-folder-")); + t.after(() => rm(tmp, { recursive: true, force: true })); + const root = path.join(tmp, "reports"); + await assert.rejects(projectPlace(root, "Kirsche", "emberparadox"), /will not route/); + await assert.rejects(projectPlace(root, "kirsche", "../out"), /will not route/); + await assert.rejects(projectPlace(root, "kirsche", ".hidden"), /will not route/); + await assert.rejects(projectPlace(root, "at/kirsche"), /reserved/); + await assert.rejects(projectPlace(root, "a/b/c/d/e"), /levels deep/); + // Inside a project: a project is a leaf, so the new one would never be listed. + await mkdir(path.join(root, "parent"), { recursive: true }); + await writeFile(path.join(root, "parent", "video.manifest.json"), "{}\n"); + await assert.rejects(projectPlace(root, "parent/child"), /is a project, not a folder/); + assert.deepEqual(await projectPlace(root, "/a/b/"), { id: "a/b", slug: "b", folder: "a" }); + assert.deepEqual(await projectPlace(root, "c", "a/b"), { id: "a/b/c", slug: "c", folder: "a/b" }); + assert.equal(await stat(path.join(root, "a")).then(() => true, () => false), false); +}); + +test("the CLI: umtool new <folder>/<slug> and --folder print the project's id in their next steps", async (t) => { + const tmp = await mkdtemp(path.join(os.tmpdir(), "umtool-new-folder-")); + t.after(() => rm(tmp, { recursive: true, force: true })); + const env = { ...process.env, REPORTS_DIR: path.join(tmp, "reports"), CHANNELS_DIR: path.join(tmp, "channels"), UMTOOL_CACHE_DIR: path.join(tmp, "cache") }; + const a = JSON.parse(execFileSync(process.execPath, [CLI, "new", "emberparadox/kirsche", "--json"], { env, encoding: "utf8" })); + assert.equal(a.id, "emberparadox/kirsche"); + const b = execFileSync(process.execPath, [CLI, "new", "kirsche-2", "--folder", "emberparadox"], { env, encoding: "utf8" }); + assert.match(b, /umtool check emberparadox\/kirsche-2/); + assert.ok((await stat(path.join(tmp, "reports", "emberparadox", "kirsche-2", "video.manifest.json"))).isFile()); +});