Archilyzer · Source

archilyzer

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

commit 718884c05c2ea59aa8637fd8d51233f619c30132
parent a0e15e72fc9a85b3e796917d17f558e8a2d787e4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 10 Nov 2026 09:35:56 -0500

umtool: redo -- what the newest undo took back, put back (redoStructural; timeline op redo; umtool timeline <p> redo)

An undo now leaves `<undo-saved>.redo.json` naming the undo point it restored. A redo restores that undo-saved
byte for byte while it is still the newest of the undo-saved and auto-before snapshots (no edit since: an edit
ends the redo, as in every editor), renames the undone point back to auto-before-<op> (the next Undo takes the
redone edit back again) and the undo-saved to redone-<op>. Several undos redo newest first; the draft pointer an
"Undo open vN" carried comes back with it. The workspace's Redo (L7a); the verb registry row and cli.md.

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

Diffstat:
Mumtool/app/api/report/timeline/route.ts | 7++++++-
Mumtool/docs/cli.md | 1+
Mumtool/lib/cli/verbs.mjs | 1+
Mumtool/lib/report/manifest.mjs | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/structure.test.mjs | 44++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/timelineCli.mjs | 8+++++++-
6 files changed, 123 insertions(+), 2 deletions(-)

diff --git a/umtool/app/api/report/timeline/route.ts b/umtool/app/api/report/timeline/route.ts @@ -18,6 +18,7 @@ import { removeWrongSpeaker, removePost, undoStructural, + redoStructural, updateFactcheck, updateSection, updateTeaser, @@ -57,6 +58,7 @@ export const dynamic = "force-dynamic"; // post-remove { id } // factcheck { factcheck: { verdicts?, stamp?, tally? } | null } // undo {} restore the newest auto snapshot +// redo {} put back what the newest undo took back (no edit since) // place { ids: [id…], before: id | null, section? } a drop on Play's reel strip: before that entry // (null: the end), the clips joining that section; its own undo point // section-move { ids: [id…], section, position?: "start" | "end" } clips into a section @@ -171,6 +173,9 @@ export async function POST(request: Request) { return updateFactcheck(dir, (body.factcheck ?? null) as Record<string, unknown> | null, { token }); case "undo": return undoStructural(dir, { token }); + case "redo": + // What the newest undo took back, put back (no edit since it): the workspace's Redo. + return redoStructural(dir, { token }); case "place": return placeEntries(dir, Array.isArray(body.ids) ? body.ids.map(String) : [id], { token, @@ -214,7 +219,7 @@ export async function POST(request: Request) { case "group-promote": return promoteGroup(dir, String(body.group ?? ""), { label: typeof body.label === "string" ? body.label : null }, { token }); default: - throw new Error("op must be move, place, remove, reject, wrong-speaker, duplicate, insert, teaser, post, post-remove, factcheck, undo, section-move, section-add, section-boundary, section-remove, section-set, order, group-set, group-label, group-remove, group-move or group-promote"); + throw new Error("op must be move, place, remove, reject, wrong-speaker, duplicate, insert, teaser, post, post-remove, factcheck, undo, redo, section-move, section-add, section-boundary, section-remove, section-set, order, group-set, group-label, group-remove, group-move or group-promote"); } }; diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -314,6 +314,7 @@ draft (the project's manifest); *project*: a project's other files, or reads; *c | `timeline <project> teaser <id> <patch>` | a teaser's lines, beat, dip, tail | form · *draft* | | `timeline <project> teaser-insert [--at end\|start] [--after AFTER] [--before BEFORE] [--id ID] [--beat N] [--line LINE…] [--lines-json JSON]` | a teaser or closing card inserted (default at the end) | form · *draft* | | `timeline <project> undo [--take TAKE]` | the newest automatic snapshot back | form · *draft* | +| `timeline <project> redo` | what the newest undo took back, put back (no edit since it) | form · *draft* | | `timeline <project> sections` | the deck's sections and their clips | form · *project* | | `timeline <project> section-move <ids>… --to-section N [--start]` | clips to the end (or start) of section N | form · *draft* | | `timeline <project> section-add --after AFTER [--label LABEL] [--color COLOR] [--level 1\|2]` | a new section after a clip | form · *draft* | diff --git a/umtool/lib/cli/verbs.mjs b/umtool/lib/cli/verbs.mjs @@ -388,6 +388,7 @@ function timeline() { opt("--lines-json", { type: "json", atFile: true, help: "the lines as JSON, each a string or {text, break?, hold?} (@file: from a terminal)" }), ]), tl("undo", "draft", "the newest automatic snapshot back", [takeOpt({ help: "a take's own undo" })]), + tl("redo", "draft", "what the newest undo took back, put back (no edit since it)", []), tl("sections", "project", "the deck's sections and their clips", []), tl("section-move", "draft", "clips to the end (or start) of section N", [ids(), num("--to-section", { required: true }), bool("--start")]), tl("section-add", "draft", "a new section after a clip", [opt("--after", { required: true }), opt("--label"), opt("--color"), pick("--level", ["1", "2"])]), diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -4765,6 +4765,8 @@ export async function undoStructural(dir, { token = null } = {}) { await rename(tmp, file); const undone = target.rel.replace(`-${target.label}.manifest.json`, `-undone-${op}.manifest.json`); await rename(path.join(dir, target.rel), path.join(dir, undone)).catch(() => {}); + // Which undo point this undo took back, beside the state it replaced: what a Redo pairs (redoStructural). + if (saved) await writeFile(path.join(dir, saved.replace(/\.manifest\.json$/, ".redo.json")), JSON.stringify({ undone, op }) + "\n", "utf8").catch(() => {}); // An undo point that carries the DRAFT POINTER as it was (versions.mjs openVersion: `<snapshot>.draft.json`): // the draft's parent goes back with the manifest, so "Undo open v1" leaves the draft named as it was. const sidecar = path.join(dir, target.rel.replace(/\.manifest\.json$/, ".draft.json")); @@ -4772,6 +4774,11 @@ export async function undoStructural(dir, { token = null } = {}) { let draft = undefined; if (side !== undefined) { const draftFile = path.join(dir, "takes", "draft.json"); + // The pointer as it is now rides with `undo-saved`, so a Redo puts it back with the manifest (redoStructural). + if (saved) { + const now = await readFile(draftFile, "utf8").then((t) => JSON.parse(t), () => null); + await writeFile(path.join(dir, saved.replace(/\.manifest\.json$/, ".draft.json")), JSON.stringify(now, null, 2) + "\n", "utf8").catch(() => {}); + } if (side && typeof side === "object" && typeof side.from === "string" && side.from) { const tmpD = `${draftFile}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`; await writeFile(tmpD, JSON.stringify(side, null, 2) + "\n", "utf8"); @@ -4788,6 +4795,63 @@ export async function undoStructural(dir, { token = null } = {}) { } /** + * Put back what the newest Undo took back (umtool redesign L7a: the workspace's Redo; `umtool timeline <p> redo`). + * + * An undo keeps the manifest it replaced as `undo-saved` and renames the undo point it restored `undone-<op>` + * (undoStructural). A redo is possible while the newest of the `undo-saved` and `auto-before-*` snapshots is an + * `undo-saved` -- no edit has been made since the undo (an edit takes an undo point, and the redo is gone, as in + * every editor). It restores that `undo-saved` byte for byte, renames it `redone-<op>` (never used again), and + * renames the `undone-<op>` that undo took back (named beside it, `<undo-saved>.redo.json`) back to + * `auto-before-<op>`, so the next Undo takes the redone edit back again. + * Several undos redo in turn, newest first. The draft pointer an undo carried (`.draft.json`) comes back with it. + * + * @param {string} dir + * @param {{ token?: string | null }} [opts] + */ +export async function redoStructural(dir, { token = null } = {}) { + return withManifestLock(async () => { + const current = await manifestToken(dir); + if (token !== null && current !== token) throw new StaleToken(token, current); + const all = (await listSnapshots(dir)).filter((s) => !s.legacy); + const head = all.find((s) => s.label === "undo-saved" || s.label?.startsWith(AUTO_SNAPSHOT_PREFIX)); + const pair = head?.label === "undo-saved" ? await readFile(path.join(dir, head.rel.replace(/\.manifest\.json$/, ".redo.json")), "utf8").then((t) => JSON.parse(t), () => null) : null; + const undone = pair && typeof pair.undone === "string" ? all.find((s) => s.rel === pair.undone && s.label?.startsWith("undone-")) : null; + if (!head || !undone) throw new Error("nothing to redo: no undo since the last edit"); + const op = undone.label.slice("undone-".length); + const text = await readFile(path.join(dir, head.rel), "utf8"); + JSON.parse(text); + const file = manifestFile(dir); + const tmp = `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`; + await writeFile(tmp, text, "utf8"); + await rename(tmp, file); + const side = (rel) => path.join(dir, rel.replace(/\.manifest\.json$/, ".draft.json")); + const back = undone.rel.replace(`-${undone.label}.manifest.json`, `-${AUTO_SNAPSHOT_PREFIX}${op}.manifest.json`); + await rename(path.join(dir, undone.rel), path.join(dir, back)).catch(() => {}); + await rename(side(undone.rel), side(back)).catch(() => {}); + const done = head.rel.replace(/-undo-saved\.manifest\.json$/, `-redone-${op}.manifest.json`); + await rename(path.join(dir, head.rel), path.join(dir, done)).catch(() => {}); + await rm(path.join(dir, head.rel.replace(/\.manifest\.json$/, ".redo.json")), { force: true }); + // The draft pointer as it was before the undo (undoStructural kept it beside `undo-saved`). + const pointer = await readFile(side(head.rel), "utf8").then((t) => JSON.parse(t), () => undefined); + let draft = undefined; + if (pointer !== undefined) { + const draftFile = path.join(dir, "takes", "draft.json"); + if (pointer && typeof pointer === "object" && typeof pointer.from === "string" && pointer.from) { + const tmpD = `${draftFile}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`; + await writeFile(tmpD, JSON.stringify(pointer, null, 2) + "\n", "utf8"); + await rename(tmpD, draftFile); + draft = pointer; + } else { + await rm(draftFile, { force: true }); + draft = null; + } + await rm(side(head.rel), { force: true }); + } + return { restored: head.rel, op, token: await manifestToken(dir), ...(draft !== undefined ? { draft } : {}) }; + }); +} + +/** * THE ONE DOOR FOR A WRITER OUTSIDE THIS FILE (umtool redesign L6: inspectorEdits.mjs -- the * provenance, the title, a teaser inserted, the published embed ids): `structural`'s write as it is -- * the token, the read inside the lock, `mutate` (which throws to refuse), the build's checks, the diff --git a/umtool/lib/report/structure.test.mjs b/umtool/lib/report/structure.test.mjs @@ -21,6 +21,8 @@ import { moveEntry, removeEntry, removePost, + redoStructural, + setUndoEveryMs, undoStructural, updateFactcheck, updateTeaser, @@ -222,6 +224,48 @@ test("undoStructural restores the newest automatic snapshot, keeps the current s } }); +test("redoStructural puts back what each undo took back, newest first, and an edit since ends it", async () => { + const dir = await project(); + setUndoEveryMs(0); + const pause = () => new Promise((r) => setTimeout(r, 25)); + try { + const original = await readRaw(dir); + await assert.rejects(redoStructural(dir), /nothing to redo/); + await moveEntry(dir, "c03", 1); + const afterMove = await readRaw(dir); + await pause(); + await removeEntry(dir, "c01"); + const afterRemove = await readRaw(dir); + await pause(); + await assert.rejects(redoStructural(dir), /nothing to redo/, "no undo yet"); + await undoStructural(dir); + await pause(); + await undoStructural(dir); + assert.equal(await readRaw(dir), original); + await pause(); + const r1 = await redoStructural(dir); + assert.equal(r1.op, "move"); + assert.equal(await readRaw(dir), afterMove, "the move, byte for byte"); + await pause(); + const r2 = await redoStructural(dir); + assert.equal(r2.op, "remove"); + assert.equal(await readRaw(dir), afterRemove, "the remove, byte for byte"); + await assert.rejects(redoStructural(dir), /nothing to redo/, "both redone"); + // The redone edits undo again, in order. + await pause(); + await undoStructural(dir); + assert.equal(await readRaw(dir), afterMove); + // A stale token is refused; an edit since the undo ends the redo. + await assert.rejects(redoStructural(dir, { token: "nope" }), StaleToken); + await pause(); + await moveEntry(dir, "c02", 1); + await assert.rejects(redoStructural(dir), /nothing to redo/); + } finally { + setUndoEveryMs(null); + await rm(dir, { recursive: true }); + } +}); + test("a manifest that already has a build problem can still be re-ordered", async () => { const m = base(); m.posts[0].attachTo = "gone"; // already broken before the edit diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs @@ -86,6 +86,7 @@ import { removeGroup, setGroup, undoStructural, + redoStructural, updateClip, updateTeaser, updateVideoEntry, @@ -131,6 +132,7 @@ export const TIMELINE_USAGE = [ " --line \"<text>\" [--break \"<its end>\"] [--hold S] [--line …] | --lines-json <json|@file>", " a TEASER OR CLOSING CARD inserted (default at the end, id close; at the start, cold)", " umtool timeline <project> undo restore the newest automatic snapshot", + " umtool timeline <project> redo put back what the newest undo took back (no edit since it)", " umtool timeline <project> sections [--json] the deck's sections: §, label, colour, its marker, its clips", " umtool timeline <project> section-move <id> [<id>…] --to-section N [--start]", " clips to the end (--start: the start) of section N, every marker following", @@ -184,7 +186,7 @@ export const TIMELINE_USAGE = [ ].join("\n"); const SECTION_VERBS = ["sections", "section-move", "section-add", "section-boundary", "section-remove", "section-set"]; -const VERBS = ["ls", "insert", "add-video", "set-video", "move", "place", "remove", "reject", "wrong-speaker", "duplicate", "post", "post-remove", "teaser", "undo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"]; +const VERBS = ["ls", "insert", "add-video", "set-video", "move", "place", "remove", "reject", "wrong-speaker", "duplicate", "post", "post-remove", "teaser", "undo", "redo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"]; const GROUP_VERBS = ["ls", "import", "set", "move", "label", "promote", "remove"]; const VALUED = new Set(["--group", "--after", "--before", "--to", "--at", "--id", "--section", "--title", "--stream-title", "--date", "--quote", "--cite", "--cite-url", "--take", "--correction", "--note", "--to-section", "--label", "--color", "--level", "--claim", "--conversation", "--from", "--fit", "--bass", "--gain", "--enter", "--hold"]); /** What `--take <id>` does on a take's timeline (takeEdit.mjs): the walk's structure and its undo. */ @@ -743,6 +745,10 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) => ({ result, editNotes } = await write((token) => undoStructural(project.dir, { token }))); break; } + case "redo": { + ({ result, editNotes } = await write((token) => redoStructural(project.dir, { token }))); + break; + } case "section-move": { if (!rest.length) throw new CliError("section-move needs one or more clip ids"); const section = intFlag(flags, "--to-section");