Archilyzer · Source

archilyzer

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

commit baf7673b1eb5727caf0307be9dab618531ebf972
parent dedb8bb5071cfaf2ef72ba6d9dafda62548c729c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 10 Nov 2026 18:01:29 -0500

umtool: a redo also ends at any undo point newer than its undo -- a move and its move back leave the draft byte for byte as the undo left it, and redoStructural no longer restores over them ("nothing to redo: an edit since the undo"); pruneAutoSnapshots keeps the newest 50 `undone-*` (UNDONE_KEEP) with their draft pointers, which were never pruned (E5 A3, the L7a redo nits)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diffstat:
Mumtool/lib/report/manifest.mjs | 24++++++++++++++++--------
Mumtool/lib/report/structure.test.mjs | 51++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 66 insertions(+), 9 deletions(-)

diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -2128,6 +2128,8 @@ export function setUndoEveryMs(ms) { } /** The undo points kept: the newest this many `auto-before-*` snapshots (older ones are pruned). */ export const AUTO_SNAPSHOT_KEEP = 200; +/** The undone undo points kept (`undone-*`, what each Undo took back and a Redo can put back): the newest this many. */ +export const UNDONE_KEEP = 50; export const undoEveryMs = () => { const n = /** @type {any} */ (globalThis)[UNDO_EVERY_KEY]; return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : AUTO_SNAPSHOT_EVERY_MS; @@ -2157,21 +2159,23 @@ export async function autoSnapshot(dir, op, { now = Date.now(), every = undoEver * revisions/), removing the older ones and their draft-pointer sidecars * (versions.mjs openVersion) -- and, by the same rule, the newest `keep` of * `undo-saved` (with its `.redo.json` pairing and `.draft.json`) and of - * `redone-*`. Named snapshots and `undone-*` are never touched. Returns the - * names removed. + * `redone-*`; and the newest UNDONE_KEEP `undone-*` (a Redo further back than + * that is gone). Named snapshots are never touched. Returns the names removed. */ export async function pruneAutoSnapshots(dir, keep = AUTO_SNAPSHOT_KEEP) { const all = (await listSnapshots(dir)).filter((x) => !x.legacy); // Each kind the undo stack makes keeps its newest `keep`: the undo points, what an undo replaced (`undo-saved`, - // its redo pairing and draft pointer beside it), and what a redo used up (`redone-*`). + // its redo pairing and draft pointer beside it), and what a redo used up (`redone-*`); what an undo took back + // (`undone-*`, with its draft pointer) its newest UNDONE_KEEP. const kinds = [ - (x) => x.label?.startsWith(AUTO_SNAPSHOT_PREFIX), - (x) => x.label === "undo-saved", - (x) => x.label?.startsWith("redone-"), + [(x) => x.label?.startsWith(AUTO_SNAPSHOT_PREFIX), keep], + [(x) => x.label === "undo-saved", keep], + [(x) => x.label?.startsWith("redone-"), keep], + [(x) => x.label?.startsWith("undone-"), Math.min(keep, UNDONE_KEEP)], ]; const gone = []; - for (const kind of kinds) { - for (const x of all.filter(kind).slice(Math.max(0, keep))) { + for (const [kind, n] of kinds) { + for (const x of all.filter(kind).slice(Math.max(0, n))) { await rm(path.join(dir, x.rel), { force: true }); await rm(path.join(dir, x.rel.replace(/\.manifest\.json$/, ".draft.json")), { force: true }); await rm(path.join(dir, x.rel.replace(/\.manifest\.json$/, ".redo.json")), { force: true }); @@ -4977,6 +4981,10 @@ export async function redoStructural(dir, { token = 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"); + // An undo point newer than that undo is an edit since it, whatever the draft hashes to now: a move and its + // move back leave the bytes as the undo left them, and the redo still ends there (E5 A3). + const headAt = all.indexOf(head); + if (all.slice(0, headAt).some((s) => s.label?.startsWith(AUTO_SNAPSHOT_PREFIX))) throw new Error("nothing to redo: an edit since the undo"); // The draft exactly as that undo left it, or no redo: whatever wrote it since -- a write that took no undo point // (a title, a terminal edit under the throttle, a saved version), the CLI, another process -- would be lost. if (typeof pair.after !== "string" || pair.after !== (await draftStateHash(dir))) throw new Error("the draft changed since the undo — nothing to redo"); diff --git a/umtool/lib/report/structure.test.mjs b/umtool/lib/report/structure.test.mjs @@ -5,7 +5,7 @@ // // Run with: pnpm test:scripts import assert from "node:assert/strict"; -import { mkdtemp, readFile, readdir, rm, utimes, writeFile } from "node:fs/promises"; +import { mkdir, mkdtemp, readFile, readdir, rm, utimes, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; @@ -19,11 +19,13 @@ import { insertEntry, manifestToken, moveEntry, + pruneAutoSnapshots, removeEntry, removePost, redoStructural, updateClip, setUndoEveryMs, + UNDONE_KEEP, undoStructural, updateFactcheck, updateTeaser, @@ -267,6 +269,53 @@ test("redoStructural puts back what each undo took back, newest first, and an ed } }); +test("redo refuses when an undo point is newer than the undo -- a move and its move back leave the draft as the undo left it, and still end the redo", async () => { + const pause = () => new Promise((r) => setTimeout(r, 25)); + const dir = await project(); + setUndoEveryMs(0); + try { + await removeEntry(dir, "c01"); + await pause(); + await undoStructural(dir); + const undoneTo = await readRaw(dir); + await pause(); + // A move and its move back: two undo points since the undo, the manifest byte for byte as the undo left it. + await moveEntry(dir, "c03", 1); + await pause(); + await moveEntry(dir, "c03", 3); + assert.equal(await readRaw(dir), undoneTo); + await assert.rejects(redoStructural(dir), /nothing to redo/); + assert.equal(await readRaw(dir), undoneTo, "nothing restored"); + } finally { + setUndoEveryMs(null); + await rm(dir, { recursive: true }); + } +}); + +test("pruneAutoSnapshots keeps the newest 50 `undone-*` (UNDONE_KEEP); named snapshots are never touched", async () => { + const dir = await project(); + try { + await mkdir(path.join(dir, "revisions"), { recursive: true }); + const text = await readRaw(dir); + const t0 = Date.now() / 1000 - 1000; + for (let i = 0; i < 53; i += 1) { + const stamp = `20260101-0000${String(i).padStart(2, "0")}`; + const f = path.join(dir, "revisions", `${stamp}-undone-move.manifest.json`); + await writeFile(f, text); + await utimes(f, t0 + i, t0 + i); + } + await writeFile(path.join(dir, "revisions", "20250101-000000-before-launch.manifest.json"), text); + const gone = await pruneAutoSnapshots(dir); + assert.equal(UNDONE_KEEP, 50); + assert.deepEqual(gone.sort(), ["00", "01", "02"].map((n) => `20260101-0000${n}-undone-move.manifest.json`)); + const left = await revisions(dir); + assert.equal(left.filter((n) => n.includes("-undone-")).length, 50); + assert.ok(left.includes("20250101-000000-before-launch.manifest.json")); + } finally { + await rm(dir, { recursive: true }); + } +}); + test("redo refuses after ANY write since the undo -- one that took no undo point included -- and keeps it", async () => { const pause = () => new Promise((r) => setTimeout(r, 25)); // (a) every edit its own undo point: move, undo, a title (no undo point), redo -> refused, the title kept.