Archilyzer · Source

archilyzer

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

commit 0e7cf8157cfc88e54d146d5b1c1196262f75da85
parent 4743eb00578d831b95a00e83d7466164693088ce
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 10 Nov 2026 15:14:07 -0500

umtool: every ⌘K run that ends done and names a project announces a write to it, whatever its target, and even after the palette closed -- the palette watches each run to its end; POST /api/cli says the project's resolved id (L8b review 2)

`links --embed-ids` (target "project") writes the draft with an undo point, and the workspace never heard: its
next Undo was refused once on a stale token. The form no longer announces (it is gone when a queued narrate
ends after an Escape): it tells the palette its run ended (onEnded), and the palette -- mounted for the page's
life -- polls every run it started until it ends, and announces MANIFEST_CHANGED for a done one with the
project id the server resolved (`project` in POST /api/cli's answer: the positional's, else a project flag's),
which is what the workspace matches. e2e: links from a Rumble clip's menu (block-menus-rumble-fixture, a copy
of inspector-rumble-fixture), the workspace's token moves, ONE Undo puts the draft back.

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

Diffstat:
Mumtool/app/api/cli/route.ts | 15++++++++++-----
Mumtool/components/shell/CommandForm.tsx | 39++++++++++++++++++++++++---------------
Mumtool/components/shell/JumpPalette.tsx | 49++++++++++++++++++++++++++++++++++++++++++++++++-
Mumtool/e2e/block-menus.spec.ts | 28++++++++++++++++++++++++++++
Mumtool/e2e/fixtures/make-fixture.mjs | 10++++++++++
5 files changed, 120 insertions(+), 21 deletions(-)

diff --git a/umtool/app/api/cli/route.ts b/umtool/app/api/cli/route.ts @@ -20,7 +20,9 @@ export const dynamic = "force-dynamic"; // pathname + search>, what the page is about -- { project, clip, post, take } // GET ?job=<id>[&since=N] { job }: the app job a form started (lib/jobs.ts jobView, its log from N) // GET ?qid=<qid> { step, log }: a queued form's step and its log's last lines -// POST { verb, values, confirm? } -> 202 { job, line } | 202 { queued: { qid }, line } +// POST { verb, values, confirm? } -> 202 { job, line, project } | 202 { queued: { qid }, line, project } +// (`project`: the resolved id of the project it names, or null -- the page announces a +// write to that project when the run ends done) // the row's args validated and built into argv HERE (lib/cli/argv.mjs); // a row with `queue` (it renders, or holds the heavy slot) is added to the // durable queue, any other runs as one job on the app's runner @@ -131,6 +133,8 @@ export async function POST(request: Request) { // A project arg is one the CLI will find: said here, not as the job's first line. let project: string | null = null; let projectDir: string | null = null; + // The project the run is about, for the page (the positional's, else a flag's: `cast audition --project`). + let named: string | null = null; for (const a of row.args) { const v = values[a.name]; if (a.type !== "project" || typeof v !== "string" || !v.trim()) continue; @@ -140,7 +144,7 @@ export async function POST(request: Request) { if (a.name === "project") { project = r.project.id; projectDir = r.project.dir; - } + } else named ??= r.project.id; } // A file a form names is a file of THE project, by its realpath; it runs as that absolute path // (a row whose CLI joins it to the project itself: as typed). @@ -153,6 +157,7 @@ export async function POST(request: Request) { } const built = buildArgv(row, run); if (!built.ok) return Response.json({ error: built.error, field: built.field ?? null }, { status: 400, headers }); + named = project ?? named; const take = row.args.filter((a) => a.context === "take").map((a) => values[a.name]).find((v): v is string => typeof v === "string" && !!v.trim()) ?? null; const line = cliLine(built.argv); const label = `⌘K: umtool ${built.argv.join(" ")}`.slice(0, 160); @@ -163,7 +168,7 @@ export async function POST(request: Request) { const recent = ((await listSteps(queueDir())) as Array<{ qid: string; argv: string[]; state: string; createdAt: string; by?: string }>).find( (s) => (s.state === "queued" || s.state === "running") && JSON.stringify(s.argv) === same && Date.now() - Date.parse(s.createdAt) < DEDUPE_MS, ); - if (recent) return Response.json({ ok: true, queued: { qid: recent.qid }, deduped: true, line, queue: queueRunnerStatus() }, { status: 200, headers }); + if (recent) return Response.json({ ok: true, queued: { qid: recent.qid }, deduped: true, line, project: named, queue: queueRunnerStatus() }, { status: 200, headers }); const step = (await addStep(queueDir(), { argv: built.argv, label, @@ -173,7 +178,7 @@ export async function POST(request: Request) { ...(row.timeoutMin ? { timeoutMin: row.timeoutMin } : {}), })) as { qid: string }; kickQueue(); - return Response.json({ ok: true, queued: { qid: step.qid }, line, queue: queueRunnerStatus() }, { status: 202, headers }); + return Response.json({ ok: true, queued: { qid: step.qid }, line, project: named, queue: queueRunnerStatus() }, { status: 202, headers }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 409, headers }); } @@ -181,5 +186,5 @@ export async function POST(request: Request) { const running = runningJob(); if (running) return Response.json({ error: `a job is already running (${running.kind}) — run this when it is done`, running: jobView(running, running.log.length) }, { status: 409, headers }); const job = startJob(`umtool ${verb}`, [{ cwd: UMTOOL_DIR, env: {}, label: `umtool ${built.argv.join(" ")}`.slice(0, 200), argv: [process.execPath, umtoolCli(), ...built.argv], timeoutMs: (row.timeoutMin ?? 15) * 60_000 }], { project }); - return Response.json({ ok: true, job: jobView(job), line }, { status: 202, headers }); + return Response.json({ ok: true, job: jobView(job), line, project: named }, { status: 202, headers }); } diff --git a/umtool/components/shell/CommandForm.tsx b/umtool/components/shell/CommandForm.tsx @@ -2,7 +2,6 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { buildArgv, cliLine, confirmOf } from "@/lib/cli/argv.mjs"; -import { announceManifestChanged } from "@/components/projects/timelineApi"; import { cn } from "@/lib/utils"; // --------------------------------------------------------------------------- @@ -18,9 +17,9 @@ import { cn } from "@/lib/utils"; // // A workspace block's menu (lane block-menus L8b) opens this same form with // `prefill`: what the block filled in (verbs.mjs fromBlockValues), over the -// page's context; the focus goes to the first arg still to give. A run of a -// draft verb that ends done announces the write (MANIFEST_CHANGED), so the -// page under the palette reads its draft again. +// page's context; the focus goes to the first arg still to give. When a run +// ends the form says so (onEnded); the palette, which watches every run to its +// end even after this form is gone, announces a done run's write. // --------------------------------------------------------------------------- export type CliArg = { name: string; type: string; required?: boolean; choices?: string[]; default?: unknown; help?: string; repeat?: boolean; context?: string }; @@ -39,7 +38,16 @@ export type CliVerb = { export type CliContext = { project: string | null; clip: string | null; post: string | null; take: string | null }; export type Value = string | boolean; /** A run the palette keeps: its form's values and what it started. */ -export type CliRun = { verb: string; values: Record<string, Value>; kind: "job" | "queued"; id: string; line: string; at: number }; +export type CliRun = { + verb: string; + values: Record<string, Value>; + kind: "job" | "queued"; + id: string; + line: string; + at: number; + /** The project it names, resolved by the server (its id): a done run announces a write to it. */ + project: string | null; +}; type Run = | { kind: "job"; id: string; state: string; log: string[]; next: number; error: string | null; exitCode: number | null } @@ -68,6 +76,7 @@ export default function CommandForm({ resume = null, prefill = null, onStarted, + onEnded, }: { row: CliVerb; ctx: CliContext; @@ -77,6 +86,8 @@ export default function CommandForm({ /** A run started before (the palette's Runs): its values, and it is followed again. */ resume?: CliRun | null; onStarted?: (run: CliRun) => void; + /** What Run started ended (done, failed, cancelled, blocked): its id. */ + onEnded?: (id: string, state: string) => void; }) { const [values, setValues] = useState<Record<string, Value>>(() => (resume ? resume.values : initialValues(row, ctx, prefill))); const [run, setRun] = useState<Run | null>(() => @@ -155,14 +166,12 @@ export default function CommandForm({ if (el) el.scrollTop = el.scrollHeight; }, [run?.log.length]); - // A draft verb's run done: the page under the palette (the workspace, the Cut tab) reads its draft again. - const announced = useRef(false); - const draftProject = row.target === "draft" && typeof values.project === "string" && values.project.trim() ? values.project.trim() : null; + // The run's end, told up at once (the palette also watches it, for after this form is gone). + const runId = run ? (run.kind === "job" ? run.id : run.qid) : null; useEffect(() => { - if (run?.state !== "done" || announced.current || !draftProject) return; - announced.current = true; - announceManifestChanged(draftProject); - }, [run?.state, draftProject]); + if (runId && run && TERMINAL.has(run.state)) onEnded?.(runId, run.state); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [runId, run?.state]); const set = (name: string, v: Value) => setValues((cur) => ({ ...cur, [name]: v })); @@ -176,7 +185,6 @@ export default function CommandForm({ setAsking(null); setPosting(true); setRefused(null); - announced.current = false; try { const r = await fetch("/api/cli", { method: "POST", @@ -189,6 +197,7 @@ export default function CommandForm({ confirm?: string; job?: { id: string; state: string; log: string[]; next: number; error: string | null; exitCode: number | null }; queued?: { qid: string }; + project?: string | null; queue?: { armed: boolean }; }; if (!r.ok) { @@ -196,10 +205,10 @@ export default function CommandForm({ else setRefused(j.error ?? `HTTP ${r.status}`); } else if (j.job) { setRun({ kind: "job", id: j.job.id, state: j.job.state, log: j.job.log, next: j.job.next, error: j.job.error, exitCode: j.job.exitCode }); - onStarted?.({ verb: row.verb, values, kind: "job", id: j.job.id, line: j.line ?? line ?? "", at: Date.now() }); + onStarted?.({ verb: row.verb, values, kind: "job", id: j.job.id, line: j.line ?? line ?? "", at: Date.now(), project: j.project ?? null }); } else if (j.queued) { setRun({ kind: "queued", qid: j.queued.qid, state: "queued", log: [], error: null, exitCode: null, runnerUp: !!j.queue?.armed }); - onStarted?.({ verb: row.verb, values, kind: "queued", id: j.queued.qid, line: j.line ?? line ?? "", at: Date.now() }); + onStarted?.({ verb: row.verb, values, kind: "queued", id: j.queued.qid, line: j.line ?? line ?? "", at: Date.now(), project: j.project ?? null }); } } catch (e) { setRefused(e instanceof Error ? e.message : String(e)); diff --git a/umtool/components/shell/JumpPalette.tsx b/umtool/components/shell/JumpPalette.tsx @@ -22,6 +22,7 @@ import { phraseFinderHref, } from "@/lib/hrefs"; import { MODES } from "@/lib/types"; +import { announceManifestChanged } from "@/components/projects/timelineApi"; import { cn } from "@/lib/utils"; import CommandForm, { type CliContext, type CliRun, type CliVerb, type Value } from "./CommandForm"; @@ -49,6 +50,12 @@ import CommandForm, { type CliContext, type CliRun, type CliVerb, type Value } f // A WORKSPACE BLOCK'S MENU (lane block-menus L8b) opens a verb's form here, the // same form, with `umtool:command` ({ row, values }: the row and what the // block filled in) -- one form component, one Runs list, one POST /api/cli. +// +// EVERY RUN IS WATCHED TO ITS END here, open or closed (the palette is mounted +// once, for the page's life): a run that ends done and names a project +// announces a write to it (MANIFEST_CHANGED, by the id the server resolved), +// whatever its target -- `links --embed-ids` writes the draft too -- and a +// queued one that ends after an Escape still does. A re-read is cheap. // --------------------------------------------------------------------------- export const JUMP_EVENT = "umtool:jump"; @@ -140,6 +147,44 @@ export default function JumpPalette() { const [resume, setResume] = useState<CliRun | null>(null); const [runs, setRuns] = useState<CliRun[]>([]); const [prefill, setPrefill] = useState<Record<string, Value> | null>(null); + // The runs' ends: each told once (the form tells it at once; the watcher below for the rest). + const ended = useRef(new Set<string>()); + const runsRef = useRef(runs); + runsRef.current = runs; + const endRun = useCallback((id: string, state: string) => { + if (ended.current.has(id)) return; + ended.current.add(id); + const r = runsRef.current.find((x) => x.id === id); + if (state === "done" && r?.project) announceManifestChanged(r.project); + }, []); + const anyRunning = runs.some((r) => !ended.current.has(r.id)); + useEffect(() => { + if (!anyRunning) return; + let live = true; + const t = setInterval(async () => { + for (const r of runsRef.current) { + if (ended.current.has(r.id)) continue; + try { + const url = r.kind === "job" ? `/api/cli?job=${encodeURIComponent(r.id)}&since=1000000` : `/api/cli?qid=${encodeURIComponent(r.id)}`; + const res = await fetch(url, { cache: "no-store" }); + if (!live) return; + if (res.status === 404) { + endRun(r.id, "gone"); + continue; + } + const j = (await res.json()) as { job?: { state: string }; step?: { state: string } }; + const state = j.job?.state ?? j.step?.state ?? ""; + if (["done", "failed", "cancelled", "blocked"].includes(state)) endRun(r.id, state); + } catch { + /* the next turn asks again */ + } + } + }, 1500); + return () => { + live = false; + clearInterval(t); + }; + }, [anyRunning, runs, endRun]); const show = useCallback(() => { setQ(""); @@ -307,8 +352,10 @@ export default function JumpPalette() { resume={resume} prefill={resume ? null : prefill} onStarted={(r) => { - setRuns((cur) => [r, ...cur.filter((x) => x.id !== r.id)].slice(0, 8)); + runsRef.current = [r, ...runsRef.current.filter((x) => x.id !== r.id)].slice(0, 8); + setRuns(runsRef.current); }} + onEnded={endRun} onBack={() => { setForm(null); setResume(null); diff --git a/umtool/e2e/block-menus.spec.ts b/umtool/e2e/block-menus.spec.ts @@ -262,3 +262,31 @@ test("a variant twin: Remove takes the entry on screen, never its twin; a twin t writeFileSync(path.join(DIR, "video.manifest.json"), original); } }); + +test("links from a Rumble clip's menu writes the draft (target project): the run's end is heard, and ONE Undo takes it back", async ({ page }) => { + const R = "reports/block-menus-rumble-fixture"; + const file = path.join(DIR, "..", "block-menus-rumble-fixture", "video.manifest.json"); + const before = readFileSync(file, "utf8"); + const siteVideo = () => (JSON.parse(readFileSync(file, "utf8")) as { timeline: { id: string; siteVideo?: string }[] }).timeline.find((e) => e.id === "r01")?.siteVideo ?? null; + await page.goto(urls.workspaceHref(R)); + await expect(page.locator("[data-ws-strip] [data-ws-block]")).toHaveCount(3); + await expect(page.locator("dialog[data-jump][data-ready]")).toBeAttached({ timeout: 60_000 }); + await expect(page.locator("[data-workspace]")).toHaveAttribute("data-ws-token", /./); + const token = await page.locator("[data-workspace]").getAttribute("data-ws-token"); + + await block(page, "r01").click({ button: "right" }); + await menuOf(page, "r01").locator('[data-ws-menu-verb="links"]').click(); + const form = palette(page).locator('[data-cli-form="links"]'); + await expect(form.locator('[data-cli-arg="--embed-ids"] input')).toBeChecked(); + await expect(form.locator('[data-cli-arg="--clips"] input')).toHaveValue("r01"); + await form.locator("[data-cli-run]").click(); + await expect(form.locator("[data-cli-state]")).toHaveAttribute("data-cli-state", "done", { timeout: 90_000 }); + expect(siteVideo()).toBe("v7emb01"); + await page.keyboard.press("Escape"); + await expect(palette(page)).toBeHidden(); + // The palette told the workspace (by the project's id): it has the draft's new token before Undo is pressed. + await expect(page.locator("[data-workspace]")).not.toHaveAttribute("data-ws-token", token ?? "", { timeout: 15_000 }); + await page.locator("[data-ws-undo]").click(); + await expect(page.locator("[data-ws-undo-said]")).toContainText("Undone"); + await expect.poll(() => readFileSync(file, "utf8"), { timeout: 15_000 }).toBe(before); +}); diff --git a/umtool/e2e/fixtures/make-fixture.mjs b/umtool/e2e/fixtures/make-fixture.mjs @@ -2203,6 +2203,16 @@ makePlayCutFixture({ reports, deckManifest, cachedWindow: path.join(REPORT, "out // (inspector-fixture.mjs), each with a take the specs check is never written. await makeInspectorFixtures({ reports, channels: CHANNELS, deckManifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4"), makePlayCutFixture }); +// A BLOCK'S MENU on a Rumble cut (block-menus.spec.ts, L8b, WRITES): inspector-rumble-fixture copied whole -- r01 +// cites a URL-slug folder, so `links --embed-ids --clips r01` from its menu writes the draft (an undo point). +{ + const { cpSync } = await import("node:fs"); + const bmr = path.join(reports, "block-menus-rumble-fixture"); + cpSync(path.join(reports, "inspector-rumble-fixture"), bmr, { recursive: true }); + const f = path.join(bmr, "video.manifest.json"); + writeFileSync(f, JSON.stringify({ ...JSON.parse(readFileSync(f, "utf8")), slug: "block-menus-rumble-fixture", title: "The Block Menus Rumble Fixture" }, null, 2) + "\n"); +} + // One undo stack (undo.spec.ts, WRITES): two trims a moment apart, then two undos -- its own copy. { const { dir: unDir } = makePlayCutFixture({