Archilyzer · Source

archilyzer

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

commit 49fafbd3dbcadd9b93b5925cd1c72ae8c4ca66af
parent 6a0467477a555e6d05e71de89849fa9958b59a2a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  9 Nov 2026 18:06:57 -0500

umtool: one undo stack -- every app edit its own undo point, trims included, pruned to 200 (L3 S5)

In the app every edit takes an undo point of its own: instrumentation.ts sets
UMTOOL_UNDO_EVERY_MS=0, which autoSnapshot reads as its default throttle (a
terminal keeps the two minutes, so an agent's burst is one step back). A
clip's moved edge is an undo point now too (auto-before-trim; a verdict alone
is not -- the bench's own Undo takes it back), so two trims a minute apart are
two Undo last edits. Only the newest 200 auto-before-* snapshots are kept
(pruneAutoSnapshots; named, undo-saved and undone-* are never touched), and
two in one second are two files (snapshots.mjs, S2). undoStructural restores
the newest, the draft pointer beside it.

e2e: undo.spec "two trims a moment apart, then two undos" (its own
undo-trim-fixture); cut-sections' Undo takes back one move at a time, and its
bar-drag test waits for the redraw before the second drag. knobs.md: "One undo
stack".

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

Diffstat:
Mumtool/docs/knobs.md | 6++++++
Mumtool/e2e/cut-sections.spec.ts | 9++++++++-
Mumtool/e2e/fixtures/make-fixture.mjs | 9+++++++++
Mumtool/e2e/undo.spec.ts | 28++++++++++++++++++++++++++++
Mumtool/instrumentation.ts | 4++++
Mumtool/lib/report/manifest.mjs | 55++++++++++++++++++++++++++++++++++++++++++++++---------
Mumtool/lib/report/versions.test.mjs | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 152 insertions(+), 10 deletions(-)

diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -627,6 +627,12 @@ expected the cut). A take is a **saved version** — FROZEN: `take --promote` merges it: a walk made since its render is what opens), another legacy take as the manifest it was rendered from (as `takes pick` copies it). Opening the draft's own parent with no edits writes nothing — its Open in draft page goes straight on (308) to the draft's bench. +- **One undo stack.** In the app every edit is its own undo point (`revisions/<stamp>-auto-before-<op>`, the server + runs with `UMTOOL_UNDO_EVERY_MS=0`) — a clip's edges included (`auto-before-trim`) — so two trims a minute apart + are two **Undo last edit**s; from a terminal the old throttle stands (one per op every two minutes, so an agent's + burst is one step back). Two undo points in one second are two files (the stamp gains its milliseconds, + `20261109-143012.457-auto-before-trim`), and only the newest 200 `auto-before-*` are kept. A verdict alone is not an + undo point (the bench's own Undo takes it back). - **The pick is not touched.** Neither saving nor opening moves or unpins the pick in `verdicts.json` (**Use this take** still does). - **Old addresses.** The take walk (`/projects/<p>/takes/<t>/walk`) and a take's bench (`…/takes/<t>/clip/<id>`) are diff --git a/umtool/e2e/cut-sections.spec.ts b/umtool/e2e/cut-sections.spec.ts @@ -72,7 +72,9 @@ test("move to section…: the clip lands at the section's end, the markers and t await expect.poll(order).toEqual(["c02", "c04", "c03", "c05", "c06", "c01"]); expect(afters()).toEqual(["c04", "c03"]); await expect.poll(patchAfters).toEqual(["c04", "c03"]); - // Undo takes back the burst (one undo point per op within two minutes: manifest.mjs autoSnapshot). + // Undo takes back one move at a time (one undo stack, L3: in the app every op is its own undo point). + await page.getByTestId("timeline-undo").click(); + await expect.poll(order).toEqual(["c02", "c03", "c04", "c05", "c06", "c01"]); await page.getByTestId("timeline-undo").click(); await expect.poll(order).toEqual(["c01", "c02", "c03", "c04", "c05", "c06"]); }); @@ -124,6 +126,11 @@ test("a section bar dragged onto a clip moves the boundary; a clip dropped on a await page.locator("[data-bar-handle='1']").dragTo(page.locator("li[data-entry='c03'][data-kind]")); await expect.poll(afters).toEqual(["c02", "c03"]); expect(patchAfters()).toEqual(["c02", "c03"]); + // The page has redrawn the bars where the file now has them (a drag on the old rows would land nowhere). + await expect + .poll(() => page.locator("[data-testid=timeline-list] > li").evaluateAll((els) => els.map((e) => e.getAttribute("data-entry") ?? `§${e.getAttribute("data-section-bar")}`))) + .toEqual(["§0", "c01", "c02", "§1", "c03", "§2", "c04", "c05", "c06"]); + await page.waitForLoadState("networkidle"); // Not past its neighbour: onto c01 is refused in words. await page.locator("[data-bar-handle='1']").dragTo(page.locator("li[data-entry='c01'][data-kind]")); await expect(page.getByTestId("timeline-error")).toContainText("would cross or touch"); diff --git a/umtool/e2e/fixtures/make-fixture.mjs b/umtool/e2e/fixtures/make-fixture.mjs @@ -2144,6 +2144,15 @@ makePlayCutFixture({ reports, deckManifest, cachedWindow: path.join(REPORT, "out rmSync(path.join(dvDir, "takes"), { recursive: true, force: true }); } +// One undo stack (undo.spec.ts, WRITES): two trims a moment apart, then two undos -- its own copy. +{ + const { dir: unDir } = makePlayCutFixture({ + reports, deckManifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4"), + name: "undo-trim-fixture", title: "The Undo Trim Fixture", video: "vid1", + }); + rmSync(path.join(unDir, "takes"), { recursive: true, force: true }); +} + // TWO MORE cached windows for vid1, and they are the regression rather than // decoration. // diff --git a/umtool/e2e/undo.spec.ts b/umtool/e2e/undo.spec.ts @@ -1,4 +1,7 @@ import { test, expect } from "@playwright/test"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; import { caps, NO_SONG_DATA } from "./capabilities"; // Undo, and the window a card is left on. @@ -141,3 +144,28 @@ test("a card remembers the window it was left on, and R returns it to the server await page.keyboard.press("r"); await expect.poll(async () => (await selText.textContent())!).toBe(original); }); + +// ONE UNDO STACK (umtool redesign L3, S5): in the app every edit is its own undo point -- two trims a moment +// apart (well inside the terminal's two-minute throttle) are two Undos on the Cut tab's Undo last edit +// (POST /api/report/timeline {op: "undo"}; the trims are PUT /api/report/window, the bench's save), each putting back exactly the one before. undo-trim-fixture +// (make-fixture.mjs) is this test's own. +test("two trims a moment apart, then two undos: each undo takes back one trim", async ({ request }) => { + const P = "reports/undo-trim-fixture"; + const FILE = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song", "reports", "undo-trim-fixture", "video.manifest.json"); + const c01 = () => (JSON.parse(readFileSync(FILE, "utf8")).timeline as { id: string; start: number; end: number }[]).find((e) => e.id === "c01")!; + const t0 = readFileSync(FILE, "utf8"); + expect(c01().end).toBe(3); + let r = await request.put("/api/report/window", { data: { project: P, clip: "c01", end: 2.8 } }); + expect(r.ok(), await r.text()).toBe(true); + const t1 = readFileSync(FILE, "utf8"); + r = await request.put("/api/report/window", { data: { project: P, clip: "c01", end: 2.6 } }); + expect(r.ok(), await r.text()).toBe(true); + expect(c01().end).toBe(2.6); + r = await request.post("/api/report/timeline", { data: { project: P, op: "undo" } }); + expect(r.ok(), await r.text()).toBe(true); + expect((await r.json()).op).toBe("trim"); + expect(readFileSync(FILE, "utf8")).toBe(t1); + r = await request.post("/api/report/timeline", { data: { project: P, op: "undo" } }); + expect(r.ok(), await r.text()).toBe(true); + expect(readFileSync(FILE, "utf8")).toBe(t0); +}); diff --git a/umtool/instrumentation.ts b/umtool/instrumentation.ts @@ -1,4 +1,5 @@ // Next.js instrumentation hook: register() runs once when the server starts. +// It says every app edit is its own undo point (UMTOOL_UNDO_EVERY_MS=0), and // umtool arms ONE thing here, the durable queue's runner (lib/queue/runner.ts), // so the steps an agent queued (`umtool queue add`) run in the app -- the live // unit -- and survive the session that queued them. A step that was running @@ -12,6 +13,9 @@ import { isIdleBoot } from "yt-dlp-transcript-common/lib/idleBoot"; export async function register() { if (process.env.NEXT_RUNTIME !== "nodejs") return; + // ONE UNDO STACK (umtool redesign L3): every edit made in the app is its own undo point (lib/report/manifest.mjs + // autoSnapshot; a terminal keeps the two-minute throttle). Set before anything else, idle boot included. + process.env.UMTOOL_UNDO_EVERY_MS ??= "0"; if (isIdleBoot()) return; try { const { queueRunnerEnabled, startQueueRunner } = await import("./lib/queue/runner"); diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -287,8 +287,11 @@ export async function updateClip(dir, clipId, patch, { token = null, edit = "tri const manifest = JSON.parse(raw); const { entry, before, citeFollowed } = patchClipEntry(manifest, clipId, patch, { edit, now, raw, dir }); // A gap cut or removed (gaps.mjs) changes what the clip IS in the cut, as a - // split does: an undo point first (`umtool timeline <p> undo`, the Cut tab's Undo). - const snapshot = GAP_PATCH_KEYS.some((k) => patch[k] !== undefined) ? await autoSnapshot(dir, "gaps") : null; + // split does, and so does a moved edge (one undo stack, L3 S5): an undo point + // first (`umtool timeline <p> undo`, the Cut tab's Undo). + const gaps = GAP_PATCH_KEYS.some((k) => patch[k] !== undefined); + const moved = !!before && (entry.start !== before.start || entry.end !== before.end); + const snapshot = gaps ? await autoSnapshot(dir, "gaps") : moved ? await autoSnapshot(dir, "trim") : null; const nextToken = await writeManifestAtomic(dir, manifest); // A moved extent may need a new bench excerpt: queued, never waited for. if (entry.start !== before.start || entry.end !== before.end) benchPrepAfterWrite(dir, [clipId]); @@ -2078,11 +2081,18 @@ const ARTICLE_SEGMENT_RE = /^[a-z0-9][a-z0-9-]{0,63}$/; // // Every writer above changes the fields of something already in the manifest. // These change WHAT IS IN IT -- the order of the timeline, which entries it -// holds, a teaser's lines, the posts, the fact-check's labels -- so they are -// the edits a person wants to take back. Each one snapshots the manifest into -// revisions/ first (`auto-before-<op>`, at most one per op every two minutes, -// so a burst of drags is one step back), and `undoStructural` restores the -// newest of those. +// holds, a teaser's lines, the posts, the fact-check's labels, a clip's edges +// -- so they are the edits a person wants to take back. Each one snapshots the +// manifest into revisions/ first (`auto-before-<op>`), and `undoStructural` +// restores the newest of those. +// +// ONE UNDO STACK (umtool redesign L3, S5): in the APP every op takes its own +// undo point (`every: 0` -- instrumentation.ts sets UMTOOL_UNDO_EVERY_MS=0), +// so two trims a minute apart are two Undos; from a terminal the old throttle +// stands (at most one per op every two minutes: an agent's burst is one step +// back). Two in one second are two files (snapshots.mjs stamps the +// milliseconds), and only the newest AUTO_SNAPSHOT_KEEP `auto-before-*` are +// kept -- the oldest pruned as a new one is taken. // // Same four rules as the rest of the file: the mtime token, tmp + rename under // the lock, 2 dp, and validation by the BUILD's own checks (deck.mjs, @@ -2095,7 +2105,15 @@ const ARTICLE_SEGMENT_RE = /^[a-z0-9][a-z0-9-]{0,63}$/; // --------------------------------------------------------------------------- export const AUTO_SNAPSHOT_PREFIX = "auto-before-"; +/** The terminal's throttle; the app runs with UMTOOL_UNDO_EVERY_MS=0 (every op its own undo point). */ const AUTO_SNAPSHOT_EVERY_MS = 2 * 60 * 1000; +/** The undo points kept: the newest this many `auto-before-*` snapshots (older ones are pruned). */ +export const AUTO_SNAPSHOT_KEEP = 200; +const undoEveryMs = () => { + const raw = process.env.UMTOOL_UNDO_EVERY_MS; + const n = raw === undefined || raw === "" ? NaN : Number(raw); + return Number.isFinite(n) && n >= 0 ? n : AUTO_SNAPSHOT_EVERY_MS; +}; const ENTRY_ID_RE = /^[A-Za-z0-9_-]{1,64}$/; /** @@ -2103,17 +2121,36 @@ const ENTRY_ID_RE = /^[A-Za-z0-9_-]{1,64}$/; * same op was taken in the last two minutes. Never fatal: an undo point that * cannot be taken is reported, and the edit still lands. */ -export async function autoSnapshot(dir, op, { now = Date.now(), every = AUTO_SNAPSHOT_EVERY_MS } = {}) { +export async function autoSnapshot(dir, op, { now = Date.now(), every = undoEveryMs(), keep = AUTO_SNAPSHOT_KEEP } = {}) { const label = `${AUTO_SNAPSHOT_PREFIX}${op}`; try { const recent = every > 0 ? (await listSnapshots(dir)).find((s) => !s.legacy && s.label === label) : null; if (recent && now - recent.mtimeMs < every) return { skipped: true, rel: recent.rel }; - return { skipped: false, ...(await createSnapshot(dir, { label })) }; + const made = await createSnapshot(dir, { label }); + await pruneAutoSnapshots(dir, keep).catch(() => {}); + return { skipped: false, ...made }; } catch (e) { return { skipped: true, error: e instanceof Error ? e.message : String(e) }; } } +/** + * Keep the newest `keep` undo points (`auto-before-*` snapshots in + * revisions/), removing the older ones and their draft-pointer sidecars + * (versions.mjs openVersion). Named snapshots, `undo-saved` and `undone-*` + * are never touched. Returns the names removed. + */ +export async function pruneAutoSnapshots(dir, keep = AUTO_SNAPSHOT_KEEP) { + const auto = (await listSnapshots(dir)).filter((x) => !x.legacy && x.label?.startsWith(AUTO_SNAPSHOT_PREFIX)); + const gone = []; + for (const x of auto.slice(Math.max(0, keep))) { + await rm(path.join(dir, x.rel), { force: true }); + await rm(path.join(dir, x.rel.replace(/\.manifest\.json$/, ".draft.json")), { force: true }); + gone.push(x.name); + } + return gone; +} + /** The index of entry `id`: `at` when it names it, else the only entry with that id. */ export function entryIndex(timeline, id, at = null) { if (at !== null && at !== undefined) { diff --git a/umtool/lib/report/versions.test.mjs b/umtool/lib/report/versions.test.mjs @@ -258,3 +258,54 @@ test("umtool takes save | open | freeze, with --json", async () => { await rm(root, { recursive: true, force: true }); } }); + +test("one undo stack: in the app (UMTOOL_UNDO_EVERY_MS=0) two trims a moment apart are two undo points, undone one by one; the terminal keeps the throttle", async () => { + const { root, dir } = await project(); + const was = process.env.UMTOOL_UNDO_EVERY_MS; + try { + const t0 = await text(dir); + // The terminal (no env): the second trim of a burst takes no undo point of its own. + delete process.env.UMTOOL_UNDO_EVERY_MS; + const a = await updateClip(dir, "a", { end: 9 }); + const b = await updateClip(dir, "a", { end: 8 }); + assert.equal(a.snapshot?.skipped, false); + assert.equal(b.snapshot?.skipped, true); + await writeFile(path.join(dir, "video.manifest.json"), t0); + await rm(path.join(dir, "revisions"), { recursive: true, force: true }); + // The app: each its own. + process.env.UMTOOL_UNDO_EVERY_MS = "0"; + await updateClip(dir, "a", { end: 9 }); + const t1 = await text(dir); + await updateClip(dir, "a", { end: 8 }); + // A verdict alone is not an undo point (the bench keeps its own undo for those). + const v = await updateClip(dir, "b", { verdict: "confirmed" }, { edit: "verdict" }); + assert.equal(v.snapshot, undefined); + await undoStructural(dir); + const back1 = JSON.parse(await text(dir)); + assert.equal(back1.timeline[0].end, 9); + assert.deepEqual(JSON.parse(t1).timeline[0], back1.timeline[0]); + await undoStructural(dir); + assert.equal(JSON.parse(await text(dir)).timeline[0].end, 10); + } finally { + if (was === undefined) delete process.env.UMTOOL_UNDO_EVERY_MS; + else process.env.UMTOOL_UNDO_EVERY_MS = was; + await rm(root, { recursive: true, force: true }); + } +}); + +test("undo points are pruned to the newest N; a named snapshot is never pruned", async () => { + const { root, dir } = await project(); + try { + const { autoSnapshot, pruneAutoSnapshots } = await import("./manifest.mjs"); + const named = await createSnapshot(dir, { label: "keep-me" }); + for (let i = 0; i < 5; i += 1) await autoSnapshot(dir, `op${i}`, { every: 0, keep: 1000 }); + assert.equal((await listSnapshots(dir)).length, 6); + const gone = await pruneAutoSnapshots(dir, 3); + assert.equal(gone.length, 2); + const left = await listSnapshots(dir); + assert.deepEqual(left.filter((x) => x.label?.startsWith("auto-before-")).map((x) => x.label), ["auto-before-op4", "auto-before-op3", "auto-before-op2"]); + assert.ok(left.some((x) => x.name === named.name)); + } finally { + await rm(root, { recursive: true, force: true }); + } +});