Archilyzer · Source

archilyzer

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

commit 00ba1af2a70e1fc5fc8847a09cfc02c96081e107
parent cfd2d911f7a0e1606af69b12253d1897ac434ab8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun,  1 Nov 2026 00:18:28 -0400

umtool: a stale take patch is settled from its row -- Take the cut's markers (umtool patch-markers <p> [<file>] --fix)

Each patch marker after a clip that is not in the cut takes the `after` of the cut's marker with the same label (the manifest's markers are re-anchored by every structural write); one no marker shares a label with is left and named. POST /api/report/patch-markers; tests and docs.

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

Diffstat:
Aumtool/app/api/report/patch-markers/route.ts | 41+++++++++++++++++++++++++++++++++++++++++
Mumtool/bin/umtool.mjs | 4++++
Mumtool/components/projects/report/DecisionSettle.tsx | 31++++++++++++++++++++++++-------
Mumtool/docs/cli.md | 1+
Mumtool/docs/inbox.md | 2+-
Mumtool/docs/knobs.md | 4+++-
Mumtool/e2e/cut-integrity.spec.ts | 3+++
Mumtool/lib/decisions.ts | 3++-
Mumtool/lib/projects/report.mjs | 5++++-
Mumtool/lib/report/cut-integrity.test.mjs | 33+++++++++++++++++++++++++++++++--
Mumtool/lib/report/linksCli.mjs | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/patchMarkers.mjs | 41+++++++++++++++++++++++++++++++++++++++++
12 files changed, 210 insertions(+), 13 deletions(-)

diff --git a/umtool/app/api/report/patch-markers/route.ts b/umtool/app/api/report/patch-markers/route.ts @@ -0,0 +1,41 @@ +import { projectRef } from "@/lib/projects"; +import { readManifest } from "@/lib/projects/report.mjs"; +import { fixStalePatchMarkers, stalePatchMarkers } from "@/lib/report/patchMarkers.mjs"; +import { refuseCaller } from "@/lib/report/caller"; + +export const dynamic = "force-dynamic"; + +// A TAKE PATCH'S MARKERS, BACK ON THE CUT (lib/report/patchMarkers.mjs; UI +// notes #6). The patch-markers-stale row's "Take the cut's markers", and +// `umtool patch-markers <project> <file> --fix`: each marker after a clip +// that is not in the cut takes the `after` of the cut's marker with the same +// label; one no marker of the cut shares a label with is left, and named. +// +// GET ?project=<id> every stale patch marker +// POST { project, file } settle that patch +const headers = { "cache-control": "no-store" }; + +export async function GET(request: Request) { + const url = new URL(request.url); + const project = await projectRef(url.searchParams.get("project") ?? ""); + if (!project) return Response.json({ error: "no such project" }, { status: 404, headers }); + const m = await readManifest(project.dir); + return Response.json({ stale: m ? await stalePatchMarkers(project.dir, m) : [] }, { headers }); +} + +export async function POST(request: Request) { + const refused = refuseCaller(request, "/api/report/patch-markers"); + if (refused) return refused; + const b = (await request.json().catch(() => null)) as { project?: unknown; file?: unknown } | null; + if (!b || typeof b !== "object") return Response.json({ error: "bad json" }, { status: 400, headers }); + const project = await projectRef(String(b.project ?? "")); + if (!project) return Response.json({ error: "no such project" }, { status: 404, headers }); + const m = await readManifest(project.dir); + if (!m) return Response.json({ error: "the project has no video.manifest.json" }, { status: 400, headers }); + try { + const r = await fixStalePatchMarkers(project.dir, m, String(b.file ?? "")); + return Response.json({ ok: true, ...r }, { headers }); + } catch (e) { + return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400, headers }); + } +} diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -766,6 +766,8 @@ function usage() { " umtool check [<project>] [--json] exit 1 on anything blocking", " umtool links <project> [--json] [--fix] do the clip QRs open on their sites? (corpus.json -> slugToPage", " -> the shard's record; polite, cached; out/links.json, which check reads); exit 1 when one is dead", + " umtool patch-markers <project> [<file>.patch.json] [--fix] [--json] take patches whose deck markers name a", + " clip not in the cut; --fix gives each the after of the cut's marker of the same label", " umtool decisions [--json]", " umtool inbox [--all] [--json] the decisions, grouped and ranked as the inbox shows them", " (--all: the hidden ones on parked/done pieces, and the quiet group)", @@ -972,6 +974,8 @@ const COMMANDS = { trailer: async () => process.exit(await (await import("../lib/report/trailerCli.mjs")).trailerCommand(argv.slice(argv.indexOf("trailer") + 1))), // Do the QR links open on their sites (UI notes #8): lib/report/linksCli.mjs. links: async () => process.exit(await (await import("../lib/report/linksCli.mjs")).linksCommand(argv.slice(argv.indexOf("links") + 1))), + // A take patch's markers back on the cut (UI notes #6): lib/report/linksCli.mjs. + "patch-markers": async () => process.exit(await (await import("../lib/report/linksCli.mjs")).patchMarkersCommand(argv.slice(argv.indexOf("patch-markers") + 1))), // The clip deck's rulings (release 34): lib/report/rulingsCli.mjs. rulings: async () => process.exit(await (await import("../lib/report/rulingsCli.mjs")).rulingsCommand(argv.slice(argv.indexOf("rulings") + 1))), // Fetch windows and stand-ins (release 35 O1): lib/report/fetchCli.mjs, standInsCli.mjs. diff --git a/umtool/components/projects/report/DecisionSettle.tsx b/umtool/components/projects/report/DecisionSettle.tsx @@ -36,14 +36,22 @@ export default function DecisionSettle({ headers: { "content-type": "application/json" }, body: JSON.stringify({ project, clip: settle.clip, ...settle.patch, ...(token ? { token } : {}) }), }) - : await fetch("/api/report/links", { - method: "POST", - headers: { "content-type": "application/json" }, - body: JSON.stringify({ project }), - }); + : settle.kind === "patch-markers" + ? await fetch("/api/report/patch-markers", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, file: settle.file }), + }) + : await fetch("/api/report/links", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project }), + }); const j = (await r.json().catch(() => ({}))) as { error?: string; verdicts?: { ok: number; dead: unknown[]; unverified: unknown[]; archive: number }; + notes?: string[]; + left?: { label: string | null; after: string }[]; }; if (!r.ok) { setErr(j.error ?? `HTTP ${r.status}`); @@ -52,6 +60,13 @@ export default function DecisionSettle({ if (settle.kind === "check-links" && j.verdicts) { const v = j.verdicts; setSaid(`${v.ok} of ${v.archive} open · ${v.dead.length} dead · ${v.unverified.length} not verified`); + } else if (settle.kind === "patch-markers") { + const moved = j.notes?.length ?? 0; + const left = j.left ?? []; + setSaid( + `${moved} marker${moved === 1 ? "" : "s"} moved` + + (left.length ? ` · left by hand: ${left.map((l) => `${l.label ? `"${l.label}"` : "a marker"} after ${l.after}`).join(", ")}` : ""), + ); } else setSaid("saved"); router.refresh(); } catch (e) { @@ -65,14 +80,16 @@ export default function DecisionSettle({ <span className="inline-flex items-center gap-2" data-settle={settle.kind}> <button type="button" - data-settle-button={settle.kind === "patch" ? settle.clip : "links"} + data-settle-button={settle.kind === "patch" ? settle.clip : settle.kind === "patch-markers" ? settle.file : "links"} disabled={busy} onClick={() => void run()} className={buttonVariants({ variant: settle.kind === "patch" ? "go" : "outline", size: "sm" })} title={ settle.kind === "patch" ? `writes ${Object.keys(settle.patch).join(", ")} on ${settle.clip} through the window writer` - : "resolves every clip QR against the site it links (corpus.json → the shard's record), one request at a time" + : settle.kind === "patch-markers" + ? `each marker of ${settle.file} after a clip that is gone takes the cut's marker of the same label` + : "resolves every clip QR against the site it links (corpus.json → the shard's record), one request at a time per host" } > {busy ? (settle.kind === "check-links" ? "Checking…" : "Saving…") : settle.label} diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -26,6 +26,7 @@ Inbox cannot disagree about what is wrong with one. | `window <project> <clip> --verdict confirmed\|incorrect [--correction T]` · `window <project> <clip> --reject <why> [--note T]` | what the walk said: `--reject` is the walk's **Reject ▾** kept in place (`not-matching`/`wrong-speaker`: incorrect, the note its correction; `irrelevant`/`repeats`/`weak`/`privacy`/`other`: rejected, the note its `rejectNote`); `umtool timeline <p> reject` takes it out ([report-video.md](report-video.md#verdict--what-the-walk-said)) | | `window <project> <clip> --walk-note T` · `--star` / `--no-star` · `--repeat-of <clip>` | what the walk said that is not a verdict: an editorial note (not a correction) and the ★ favourite, a trailer candidate (`trailer <project> --candidates [--json]` lists them as beats); a deliberate repeat ([knobs.md](knobs.md#a-clip)) | | `links <project> [--json] [--fix]` | do the clip QRs open on their sites? `corpus.json` → the channel's manifest → `slugToPage` → the shard's record, one request at a time, shards from the cue cache; recorded in `out/links.json`, which `check` reads (`link-dead` blocking, `links-unverified`, `links-unchecked`); `--fix` rewrites a Twitch id the site serves as `v<id>`; **exit 1** when a link is dead ([knobs.md](knobs.md#do-the-qr-links-open)) | +| `patch-markers <project> [<file>.patch.json] [--fix] [--json]` | take patches whose deck markers name a clip not in the cut (a take made with one is refused); `--fix` gives each the `after` of the cut's marker of the same label; **exit 1** when one is left ([knobs.md](knobs.md#take-patches-follow-a-removal)) | | `window <project> <clip> --take <take> …` | a **take's** clip (walk a take): the same fields, written into the take's patch (`takes/<take>/take.json`) with an undo point first; the project's manifest is untouched ([clip-bench.md](clip-bench.md#walking-a-take)) | | `walk <project> [--take <take>] [--all] [--json]` | the clip bench's **walk**: every clip in walk order with its window, verdict and whether a fetched file holds it, and (→) the ones the walk visits — fetched and needing a verdict; `--all` every fetched one; `--take` walks a take (a draft too); the bench's address to start at | | `link <project> <site>/<report>` · `link <project> --clear` | the manifest names the article it is the video of (settles `link-ambiguous`) | diff --git a/umtool/docs/inbox.md b/umtool/docs/inbox.md @@ -66,7 +66,7 @@ on (`decisionTab`, `songTabOfSection`). | `clip-mid-sentence` | open | the cut lands inside a cue that does not close a sentence, and `lockEnd` is unset | Trim to the sentence | | `window-overlap` | open/info | two clips from one source overlap; the row offers **It's deliberate: `<later>` repeats `<earlier>`** (`repeatOf` through the window writer) | Fix the windows | | `clip-cite-off` | open | the clock (`cite`) or the QR's `t=` (a citeUrl naming this recording) more than 5 s before what the clip plays, or after it: "the clock and the QR point 78 s before the clip (cite 25:22, it plays 26:40–26:50)"; **Move to 26:40** | Move the cite to the clip | -| `patch-markers-stale` | open | a take patch beside the manifest (`*.patch.json`) whose deck markers name a clip not in the cut — a take made with it is refused | Fix the take patch | +| `patch-markers-stale` | open | a take patch beside the manifest (`*.patch.json`) whose deck markers name a clip not in the cut — a take made with it is refused; **Take the cut's markers** (the cut's marker of the same label) | Fix the take patch | | `link-dead` | blocking | the recorded link check (`umtool links`, out/links.json) found clip QRs that don't open on their site — one row per site, the clips and the first reason | Fix the links | | `links-unverified` | info | the link check could not reach a site (offline, a timeout, no corpus.json) | Check links again | | `links-unchecked` | info | archive links never checked, or changed since the check | Check links | diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -68,7 +68,9 @@ manifest's (`lib/report/patchMarkers.mjs`): a marker after a removed clip moves or is dropped when there is none; `umtool timeline` prints each change (`draft-1.patch.json: deck marker 1 ("Sex appeal") moved from after ow2b to after ow2`). A patch with a `timeline` of its own is left alone. An **undo** restores the manifest, not the patches. Anything still naming a clip that is not in -the cut is the check's `patch-markers-stale` row (open: a take made with it is refused). +the cut is the check's `patch-markers-stale` row (open: a take made with it is refused), with **Take the +cut's markers** (`umtool patch-markers <p> [<file>] --fix`): each such marker takes the `after` of the +cut's marker with the same label; one no marker of the cut shares a label with is left, and named. ## Do the QR links open? diff --git a/umtool/e2e/cut-integrity.spec.ts b/umtool/e2e/cut-integrity.spec.ts @@ -205,4 +205,7 @@ test("#6 removing a clip re-anchors the take patch's markers; the hand-made one await expect(row(page, "patch-markers-stale", "draft-1.patch.json")).toContainText('"Hand-made" after gone — a take made with --patch draft-1.patch.json is refused'); await expect(row(page, "patch-markers-stale", "draft-1.patch.json")).not.toContainText("After four"); await shot(page, "6-patch-markers-stale"); + // Take the cut's markers: nothing in the cut is called "Hand-made", so it is left, and said. + await row(page, "patch-markers-stale", "draft-1.patch.json").locator('[data-settle-button="draft-1.patch.json"]').click(); + await expect(page.locator("[data-settle-said]")).toContainText('0 markers moved · left by hand: "Hand-made" after gone'); }); diff --git a/umtool/lib/decisions.ts b/umtool/lib/decisions.ts @@ -88,7 +88,8 @@ export type Decision = { */ settle?: | { kind: "patch"; clip: string; patch: Record<string, unknown>; label: string } - | { kind: "check-links"; label: string }; + | { kind: "check-links"; label: string } + | { kind: "patch-markers"; file: string; label: string }; /** The clips a project-wide row is about (a site's dead links). */ clips?: string[]; diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -1357,7 +1357,10 @@ export async function reportDecisions(ctx, summary) { `${p.markers.length === 1 ? "a deck marker names a clip" : `${p.markers.length} deck markers name clips`} not in the cut: ` + `${named.slice(0, 4).join(", ")}${named.length > 4 ? ` and ${named.length - 4} more` : ""} — a take made with --patch ${p.file} is refused`, "open", - { fix: `edit ${p.file}: render.chrome.deck.markers[].after must name clips of the cut (umtool timeline ${id} ls)` }, + { + fix: `umtool patch-markers ${id} ${p.file} --fix # each takes the cut's marker of the same label; the rest by hand`, + settle: { kind: "patch-markers", file: p.file, label: "Take the cut's markers" }, + }, ); } diff --git a/umtool/lib/report/cut-integrity.test.mjs b/umtool/lib/report/cut-integrity.test.mjs @@ -11,9 +11,9 @@ import test from "node:test"; import { citeFollow, citeOffsets, citeUrlSecond, offsetFrom, parseT, playedSpan, withT } from "./citeFollow.mjs"; import { patchClipEntry, removeEntry, updateClip } from "./manifest.mjs"; -import { removedAnchors, reanchorPatch, stalePatchMarkers } from "./patchMarkers.mjs"; +import { fixStalePatchMarkers, removedAnchors, reanchorPatch, stalePatchMarkers } from "./patchMarkers.mjs"; import { archiveLinkOf, checkLinks, linkVerdicts, linksOf, runLinkCheck } from "./linkCheck.mjs"; -import { linksCommand } from "./linksCli.mjs"; +import { linksCommand, patchMarkersCommand } from "./linksCli.mjs"; import { candidateBeats, trailerCandidates } from "./trailerCandidates.mjs"; import { decisionsFor } from "../projects/core.mjs"; import { walkProjects } from "../projects/walk.mjs"; @@ -214,6 +214,35 @@ test("removing a clip re-anchors the take patches beside the manifest; the check } }); +test("Take the cut's markers: a stale patch marker takes the cut's marker of the same label; an unmatched one is left and named", async () => { + const p = await project( + [{ id: "a", start: 10, end: 20 }, { id: "b", start: 30, end: 40 }], + { + render: markersRender([{ after: "a", label: "Sex appeal" }]), + files: { "draft-1.patch.json": { render: { chrome: { deck: { markers: [{ after: "ow2b", label: "Sex appeal", color: "#e070d0" }, { after: "zz", label: "Nobody" }] } } } } }, + }, + ); + try { + const rows = (await p.decisions()).filter((d) => d.kind === "patch-markers-stale"); + assert.deepEqual(rows[0].settle, { kind: "patch-markers", file: "draft-1.patch.json", label: "Take the cut's markers" }); + assert.match(rows[0].fix, /^umtool patch-markers cut draft-1.patch.json --fix/); + const lines = []; + const code = await patchMarkersCommand(["cut", "--fix"], { root: p.reportsRoot, out: (s) => lines.push(s), err: (s) => lines.push(s) }); + assert.equal(code, 1, "one is left"); + assert.deepEqual(lines, [ + `draft-1.patch.json: deck marker 0 ("Sex appeal") moved from after ow2b to after a, where the cut's "Sex appeal" is`, + `draft-1.patch.json: "Nobody" is after zz, which is not in the cut`, + ]); + const patch = JSON.parse(await readFile(path.join(p.dir, "draft-1.patch.json"), "utf8")); + assert.deepEqual(patch.render.chrome.deck.markers[0], { after: "a", label: "Sex appeal", color: "#e070d0" }); + const m = JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); + assert.deepEqual((await fixStalePatchMarkers(p.dir, m, "draft-1.patch.json")).left, [{ index: 1, label: "Nobody", after: "zz" }]); + await assert.rejects(fixStalePatchMarkers(p.dir, m, "../video.manifest.json"), /not a take patch/); + } finally { + await p.done(); + } +}); + // ---- the check rows ------------------------------------------------------------ test("clip-cite-off: the clock and the QR N s before the clip, with the settle and the fix", async () => { diff --git a/umtool/lib/report/linksCli.mjs b/umtool/lib/report/linksCli.mjs @@ -104,3 +104,58 @@ export async function linksCommand(args, { root = REPORTS_ROOT, out = (s) => con return e instanceof CliError ? 2 : 1; } } + +export const PATCH_MARKERS_USAGE = [ + "usage: umtool patch-markers <project> [<file>.patch.json] [--fix] [--json]", + "", + "The take patches beside the manifest (*.patch.json, what `umtool take --patch` reads) whose deck markers", + "name a clip that is not in the cut -- a take made with one is refused. Structural writes re-anchor them", + "by themselves; this is for the rest. --fix: each such marker takes the `after` of the cut's marker with", + "the same label; one no marker of the cut shares a label with is left, and named. Exit 1 when one is left.", +].join("\n"); + +/** + * `umtool patch-markers …` + * @param {string[]} args the words after `patch-markers` + * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void }} [opts] + * @returns {Promise<number>} + */ +export async function patchMarkersCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s) } = {}) { + try { + const words = args.filter((a) => !a.startsWith("--")); + const flags = new Set(args.filter((a) => a.startsWith("--"))); + for (const f of flags) if (!["--json", "--fix", "--help"].includes(f)) throw new CliError(`unknown flag ${f}`); + if (!words[0] || flags.has("--help")) { + (flags.has("--help") ? out : err)(PATCH_MARKERS_USAGE); + return flags.has("--help") ? 0 : 2; + } + 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 m = await readManifest(project.dir); + if (!m) throw new CliError(`${project.id} has no video.manifest.json`); + const { stalePatchMarkers, fixStalePatchMarkers } = await import("./patchMarkers.mjs"); + let stale = await stalePatchMarkers(project.dir, m); + if (words[1]) stale = stale.filter((s) => s.file === words[1]); + const fixed = []; + if (flags.has("--fix")) { + for (const s of stale) if (!s.error) fixed.push(await fixStalePatchMarkers(project.dir, m, s.file)); + stale = (await stalePatchMarkers(project.dir, m)).filter((s) => !words[1] || s.file === words[1]); + } + if (flags.has("--json")) { + out(JSON.stringify({ ok: stale.length === 0, project: project.id, stale, ...(flags.has("--fix") ? { fixed } : {}) }, null, 2)); + return stale.length ? 1 : 0; + } + for (const f of fixed) for (const n of f.notes) out(`${f.file}: ${n}`); + if (!stale.length) out(`${project.id}: every take patch's markers name clips of the cut`); + for (const s of stale) { + if (s.error) out(`${s.file}: does not read (${s.error})`); + for (const mk of s.markers) out(`${s.file}: ${mk.label ? `"${mk.label}"` : `marker ${mk.index}`} is after ${mk.after}, which is not in the cut`); + } + return stale.length ? 1 : 0; + } catch (e) { + err(`umtool patch-markers: ${e instanceof Error ? e.message : String(e)}`); + return e instanceof CliError ? 2 : 1; + } +} diff --git a/umtool/lib/report/patchMarkers.mjs b/umtool/lib/report/patchMarkers.mjs @@ -165,3 +165,44 @@ export async function stalePatchMarkers(dir, manifest) { } return out; } + +/** + * Settle a stale patch: every marker after a clip that is not in the cut + * takes the `after` of the CUT's marker with the same label (the manifest's + * own markers are re-anchored by every structural write, so they say where + * that section starts now). A marker no marker of the cut shares a label with + * is left as it is, and named. The file is rewritten whole, tmp + rename. + * + * @param {string} dir + * @param {Record<string, any>} manifest + * @param {string} file a `*.patch.json` beside the manifest, by name + * @returns {Promise<{ file: string, notes: string[], left: Array<{ index: number, label: string | null, after: string }> }>} + */ +export async function fixStalePatchMarkers(dir, manifest, file) { + if (!PATCH_FILE_RE.test(String(file ?? ""))) throw new Error(`${file} is not a take patch beside the manifest (*.patch.json)`); + const full = path.join(dir, file); + const patch = JSON.parse(await readFile(full, "utf8")); + const markers = patchMarkersOf(patch); + if (!markers) return { file, notes: [], left: [] }; + const ids = new Set((manifest?.timeline ?? []).filter(isClip).map((e) => e.id)); + const cut = Array.isArray(manifest?.render?.chrome?.deck?.markers) ? manifest.render.chrome.deck.markers : []; + const byLabel = new Map(cut.filter((mk) => isObj(mk) && typeof mk.label === "string" && ids.has(String(mk.after ?? "").trim())).map((mk) => [mk.label.trim(), String(mk.after).trim()])); + const notes = []; + const left = []; + markers.forEach((mk, index) => { + const after = isObj(mk) ? String(mk.after ?? "").trim() : ""; + if (!after || ids.has(after)) return; + const label = typeof mk.label === "string" ? mk.label : null; + const to = label ? byLabel.get(label.trim()) : undefined; + if (to) { + mk.after = to; + notes.push(`deck marker ${index} ("${label}") moved from after ${after} to after ${to}, where the cut's "${label}" is`); + } else left.push({ index, label, after }); + }); + if (notes.length) { + const tmp = `${full}.tmp-${process.pid}`; + await writeFile(tmp, `${JSON.stringify(patch, null, 2)}\n`); + await rename(tmp, full); + } + return { file, notes, left }; +}