Archilyzer · Source

archilyzer

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

commit c266f4adccb48106ef26955eae5175606843288d
parent 5ff69ce01425586d8539d420443d44931653f90e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed,  4 Nov 2026 23:47:07 -0500

umtool: umtool lint <project> [--take <t>] -- the build's lint on the cut or on a take's resolved manifest, plus the files its post items name (a picked read or an attachment not in the project is an error); a re-import where the items already stand reads unchanged, not moved

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

Diffstat:
Mumtool/bin/umtool.mjs | 5+++++
Aumtool/lib/report/lintCli.mjs | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/takeImport.mjs | 3+++
Mumtool/lib/report/takeScope.test.mjs | 27+++++++++++++++++++++++++++
4 files changed, 166 insertions(+), 0 deletions(-)

diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -75,6 +75,7 @@ // [--draft] record it without rendering (walk it first) · --id <id> --promote [--anyway] make it the cut // [--priority] render mode for the take's lifetime: the machine is the render's (AGENTS.md "Render mode") // --id <id> --import-item <project>:<item>[,…] [--after|--before <entry>] items of another project into the take +// umtool lint <project> [--take <id>] [--json] the manifest lint (lint.mjs) on the cut or a take, + the files it names // umtool takes make <project> [--recipe F | --all-styles] | styles | pick <project> <take> [--anyway] // | ls <project> | relabel <project> <take> <label> | supersede <project> <take> [--by T] [--clear] // | delete <project> <take> [--dry-run] [--force] take housekeeping @@ -969,6 +970,9 @@ function usage() { " umtool take <project> --id <id> --import-item <project>:<item>[,<item>…] [--after <entry>|--before <entry>]", " [--as <id>] [--dry-run] [--json] items of ANOTHER project cloned into the take (its patch), their", " narration and pick kept, the files they name hard-linked into this project; again: updated or unchanged", + " umtool lint <project> [--take <id>] [--variant sourced|full] [--final] [--json] the manifest lint a build runs", + " first, on the project's manifest or a take's (its patches applied), and the files its post items", + " name (a picked read, an attachment not in the project: an error) -- exit 0 clean, 1 an error", " umtool take <project> --id <id> --promote [--anyway] make this the cut: the take's patch applied to the", " manifest, one undo point (revisions/…-auto-before-promote-take)", " umtool take status <project> [--id <id>] [--json] [--log] [--tail N] the take's render record (every render", @@ -1130,6 +1134,7 @@ const COMMANDS = { notes: async () => process.exit(await notesCommand(argv.slice(argv.indexOf("notes") + 1))), // The take maker (release 33): lib/report/takeCli.mjs. take: async () => process.exit(await (await import("../lib/report/takeCli.mjs")).takeCommand(argv.slice(argv.indexOf("take") + 1))), + lint: async () => process.exit(await (await import("../lib/report/lintCli.mjs")).lintCommand(argv.slice(argv.indexOf("lint") + 1))), takes: async () => process.exit(await (await import("../lib/report/takeCli.mjs")).takesCommand(argv.slice(argv.indexOf("takes") + 1))), // The durable queue and every render's record (4 Nov 2026): lib/queue/cli.mjs. queue: async () => diff --git a/umtool/lib/report/lintCli.mjs b/umtool/lib/report/lintCli.mjs @@ -0,0 +1,131 @@ +// `umtool lint <project> [--take <t>]`: THE MANIFEST LINT (report-to-video/lint.mjs, what a build runs before it +// renders a frame) from umtool, on the project's manifest or on a TAKE's -- the take's manifest resolved as its +// render resolves it (the project's now + its style's and its own patches) and written beside the project's +// manifest for the lint, so a relative path in it is read as the render reads it -- plus the FILES the post items +// name: a post item whose picked read, attachment or context media is not in the project would render a broken +// item (a take's imported items are hard-linked in by `umtool take --import-item`; this says when one is not). +// +// exit 0 no error (warnings said) · 1 an error · 2 usage +import { rm, stat, writeFile } from "node:fs/promises"; +import path from "node:path"; +import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; + +export const LINT_USAGE = [ + "usage: umtool lint <project> [--take <take>] [--variant sourced|full] [--final] [--json]", + " the manifest lint (report-to-video/lint.mjs, what a build runs before it renders) on the project's manifest, or", + " with --take on the take's (its patches applied, as its render reads it), and the files its post items name: a", + " picked read, an attachment, a context post's media not in the project is an ERROR; another named file a warning.", + " Exit 0 no error · 1 an error · 2 usage.", +].join("\n"); + +const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); +const exists = async (f) => !!(await stat(f).catch(() => null)); + +/** + * The files the post items of `manifest` name that are not in `dir`: `{ errors, warnings }`. + * An error: the picked narration take, an attachment (`media[].src`), a context post's or a link's media. + * A warning: any other narration take the item keeps. + * @param {Record<string, any>} manifest + * @param {string} dir + */ +export async function namedFileProblems(manifest, dir) { + const errors = []; + const warnings = []; + for (const e of Array.isArray(manifest?.timeline) ? manifest.timeline : []) { + if (!isObj(e) || e.type !== "post") continue; + const takes = Array.isArray(e.narration?.takes) ? e.narration.takes : []; + const pick = Number.isInteger(e.narration?.pick) ? e.narration.pick : 0; + for (const [i, t] of takes.entries()) { + if (typeof t?.file !== "string" || (await exists(path.join(dir, t.file)))) continue; + if (i === pick && e.narration?.off !== true) errors.push(`timeline ${e.id}: its picked read ${t.file} is not in the project`); + else warnings.push(`timeline ${e.id}: its take ${i + 1} (${t.file}) is not in the project`); + } + const media = [ + ...(Array.isArray(e.media) ? e.media.map((m, i) => [`media[${i}]`, m]) : []), + ...(Array.isArray(e.parents) ? e.parents.flatMap((p, k) => (Array.isArray(p?.media) ? p.media.map((m, i) => [`parents[${k}].media[${i}]`, m]) : [])) : []), + ...(Array.isArray(e.links) ? e.links.flatMap((l, k) => (Array.isArray(l?.media) ? l.media.map((m, i) => [`links[${k}].media[${i}]`, m]) : [])) : []), + ]; + for (const [where, m] of media) { + const src = isObj(m) ? m.src : typeof m === "string" ? m : null; + if (typeof src !== "string" || /^[a-z][a-z0-9+.-]*:/i.test(src)) continue; + if (!(await exists(path.join(dir, src)))) errors.push(`timeline ${e.id}.${where}: ${src} is not in the project`); + } + } + return { errors, warnings }; +} + +/** + * @param {string[]} args the words after `lint` + * @param {{ reportsRoot?: string, log?: (s: string) => void, err?: (s: string) => void }} [opts] + */ +export async function lintCommand(args, { reportsRoot = REPORTS_ROOT, log = console.log, err = console.error } = {}) { + const valued = new Set(["--take", "--variant"]); + const flags = new Map(); + const positional = []; + for (let i = 0; i < args.length; i += 1) { + const a = args[i]; + if (valued.has(a)) { + if (args[i + 1] === undefined) { + err(`${a} needs a value\n${LINT_USAGE}`); + return 2; + } + flags.set(a, args[++i]); + } else if (a.startsWith("--")) flags.set(a, true); + else positional.push(a); + } + if (flags.has("--help") || positional.length !== 1) { + (flags.has("--help") ? log : err)(LINT_USAGE); + return flags.has("--help") ? 0 : 2; + } + const variant = String(flags.get("--variant") ?? "sourced"); + if (!["sourced", "full"].includes(variant)) { + err(`--variant takes sourced or full\n${LINT_USAGE}`); + return 2; + } + const r = await resolveProject(positional[0], reportsRoot); + if (r.ambiguous || !r.project) { + err(r.ambiguous ? `"${positional[0]}" is the name of ${r.ambiguous.length} projects — pass its id` : `no project matches "${positional[0]}"`); + return 2; + } + const project = r.project; + const take = flags.has("--take") ? String(flags.get("--take")) : null; + const { lintManifestFile, lintReport } = await import("umtool-report-to-video/lint"); + const { selectVariant } = await import("umtool-report-to-video/build-video"); + let file = path.join(project.dir, "video.manifest.json"); + let manifest; + let scratch = null; + try { + if (take) { + const { resolveTakeManifest } = await import("./takeManifest.mjs"); + try { + manifest = (await resolveTakeManifest(project.dir, take)).manifest; + } catch (e) { + err(e instanceof Error ? e.message : String(e)); + return 1; + } + // Beside the project's manifest, as the render's own (.take-<t>.render.json) is: its paths read as the render's. + scratch = path.join(project.dir, `.take-${take}.lint.json`); + await writeFile(scratch, JSON.stringify(manifest, null, 2) + "\n", "utf8"); + file = scratch; + } else { + const { readFile } = await import("node:fs/promises"); + manifest = JSON.parse(await readFile(file, "utf8").catch(() => "null")); + if (!isObj(manifest)) { + err(`${project.id} has no readable video.manifest.json`); + return 1; + } + } + const lint = await lintManifestFile(file, { variant, final: flags.has("--final") }); + const files = await namedFileProblems(selectVariant(manifest, variant), project.dir); + const errors = [...lint.errors, ...files.errors]; + const warnings = [...lint.warnings, ...files.warnings]; + if (flags.has("--json")) log(JSON.stringify({ ok: errors.length === 0, project: project.id, take, variant, entries: manifest.timeline?.length ?? 0, errors, warnings }, null, 2)); + else { + for (const line of lintReport({ errors, warnings })) log(line); + log(`${project.id}${take ? ` take ${take}` : ""}: ${manifest.timeline?.length ?? 0} entries, ${errors.length ? "NOT ready to render" : "ready to render as far as the lint can tell"}`); + } + return errors.length ? 1 : 0; + } finally { + if (scratch) await rm(scratch, { force: true }); + } +} diff --git a/umtool/lib/report/takeImport.mjs b/umtool/lib/report/takeImport.mjs @@ -281,6 +281,7 @@ export async function importTakeItems(project, take, refs, { after = null, befor (m) => applyStructural(m, (mm) => { const timeline = mm.timeline; + const order = timeline.map((x) => (isObj(x) ? x.id : null)).join("\n"); let cursor = null; // the id the next item goes after (several items keep their order) for (const p of plans) { const at = timeline.findIndex((x) => isObj(x) && x.id === p.id); @@ -308,6 +309,8 @@ export async function importTakeItems(project, take, refs, { after = null, befor if (Object.keys(p.avatars).length) mm.postAvatars = { ...(isObj(mm.postAvatars) ? mm.postAvatars : {}), ...p.avatars }; placed.push({ id: p.id, action }); } + // Placed where it already stood, as it was: unchanged, not moved. + if (timeline.map((x) => (isObj(x) ? x.id : null)).join("\n") === order) for (const pl of placed) if (pl.action === "moved") pl.action = "unchanged"; // Where each one stands now (a dry run says it too). for (const pl of placed) { const i = timeline.findIndex((x) => isObj(x) && x.id === pl.id); diff --git a/umtool/lib/report/takeScope.test.mjs b/umtool/lib/report/takeScope.test.mjs @@ -17,6 +17,7 @@ import { updateRender } from "./manifest.mjs"; import { readManifest } from "../projects/report.mjs"; import { resolveTakeManifest } from "./takeManifest.mjs"; import { postsInDateOrder, parseImportRef } from "./takeImport.mjs"; +import { lintCommand, namedFileProblems } from "./lintCli.mjs"; import { postsCommand } from "./postsCli.mjs"; import { takeCommand } from "./takeCli.mjs"; import { timelineCommand } from "./timelineCli.mjs"; @@ -240,6 +241,15 @@ test("--import-item: an item of another project cloned into the take with its na doc = JSON.parse(r.out); assert.equal(doc.items[0].action, "updated"); assert.equal(doc.items[0].at.index, 1, "in place"); + // Again with the same --after: where they already stand, as they are -- unchanged, no write. + const revs2 = (await listTakeRevisions(dst.dir, "t1")).length; + r = await take("imp-dst", "--id", "t1", "--import-item", "imp-src:p-11,p-10", "--after", "p-1", "--json"); + doc = JSON.parse(r.out); + assert.deepEqual([doc.unchanged, ...doc.items.map((x) => x.action)], [true, "unchanged", "unchanged"]); + assert.equal((await listTakeRevisions(dst.dir, "t1")).length, revs2); + // The lint of the take: every file its items name is there. + const files = await namedFileProblems((await resolveTakeManifest(dst.dir, "t1")).manifest, dst.dir); + assert.deepEqual(files, { errors: [], warnings: [] }); // Refusals: no such item (1), a malformed ref (2), an anchor not in the take (1). assert.equal((await take("imp-dst", "--id", "t1", "--import-item", "imp-src:p-99")).code, 1); assert.equal((await take("imp-dst", "--id", "t1", "--import-item", "imp-src")).code, 2); @@ -271,3 +281,20 @@ test("the editor's token: the environment's, else the editor's env files'; an ex assert.throws(() => editorFromEnv({ WORKER_TOKEN: "" }, [file]), /WORKER_TOKEN is not set/); assert.throws(() => editorFromEnv({}, [path.join(dir, "missing")]), (e) => /WORKER_TOKEN is not set/.test(e.message) && !e.message.includes("from-the-file")); }); + +test("umtool lint --take: the take's manifest linted as its render reads it, and a picked read not in the project is an ERROR (exit 1)", async () => { + const a = await project("lint-a", [narrated("1", "2026-10-30T10:00:00.000Z")]); + assert.equal((await take("lint-a", "--id", "t1", "--label", "T", "--draft")).code, 0); + let r = await cli(lintCommand, ["lint-a", "--take", "t1", "--json"]); + let doc = JSON.parse(r.out); + assert.equal(r.code, 1); + assert.ok(doc.errors.some((e) => /timeline p-1: its picked read narration\/posts\/1\/take-1\.orpheus-thread\.wav is not in the project/.test(e)), doc.errors.join("\n")); + await tone(path.join(a.dir, "narration/posts/1/take-1.orpheus-thread.wav")); + r = await cli(lintCommand, ["lint-a", "--take", "t1", "--json"]); + doc = JSON.parse(r.out); + assert.equal(doc.errors.filter((e) => /not in the project/.test(e)).length, 0, doc.errors.join("\n")); + assert.equal(doc.take, "t1"); + assert.ok(!(await stat(path.join(a.dir, ".take-t1.lint.json")).catch(() => null)), "the scratch manifest is gone"); + assert.equal((await cli(lintCommand, ["lint-a", "--take", "nope"])).code, 1); + assert.equal((await cli(lintCommand, [])).code, 2); +});