Archilyzer · Source

archilyzer

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

commit ba259ebe0cca614047817b60f1fed0683ea331ba
parent d0d700150f2ebdc661a9bc773ba7a9719abeb690
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 18:19:25 -0500

reads undo: the replace hashed only while it is still its own write; the undo restores under the token it checked; its undo point must be the one it made (review 2, N4)

A write landing between the replace's write and its hash (a queue step in another process) was hashed in,
and Undo then wiped it. Now the hash is taken only while the draft's token is the replace's own result;
otherwise the replace is recorded as one Undo cannot take back, and the page says so. undoReplace passes
the token it checked to undoStructural, and the recorded snapshot must be the newest undo point.

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

Diffstat:
Mumtool/lib/report/readsReplace.mjs | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/umtool/lib/report/readsReplace.mjs b/umtool/lib/report/readsReplace.mjs @@ -177,8 +177,12 @@ export async function applyReplace(project, from, to, o = {}) { if (!plan.lines.length) throw new ReplaceError(plan.matches ? `nothing to rewrite: every match is in a read These reads does not change (${plan.skipped.map((s) => s.id).join(", ")})` : `"${from}" is in no read's spoken text`); const { withEditNotes } = await import("./edit-guard.mjs"); const { result, editNotes } = await withEditNotes(project, async () => structuralEdit(project.dir, REPLACE_OP, token, (m) => replaceReadsIn(m, plan.lines), { snapshotEvery: 0 })); - const sha = await draftSha(project.dir); - await withReplaces(project.dir, (records) => ({ records: [...records, { scope: "reads", at: new Date().toISOString(), find: from, to, lines: plan.lines.map((l) => l.id), token: result.token ?? null, sha, snapshot: result.snapshot?.rel ?? null }], result: null })); + await o.onWritten?.(); + // The draft hashed only while it is still the replace's own write (its token): a write landing in between (a queue + // step in another process) is never hashed in -- the replace is then recorded as one Undo cannot take back. + const still = (await manifestToken(project.dir)) === result.token; + const sha = still ? await draftSha(project.dir) : null; + await withReplaces(project.dir, (records) => ({ records: [...records, { scope: "reads", at: new Date().toISOString(), find: from, to, lines: plan.lines.map((l) => l.id), token: result.token ?? null, sha, snapshot: result.snapshot?.rel ?? null, ...(still ? {} : { undoable: false }) }], result: null })); return { plan, result, editNotes }; } @@ -197,20 +201,24 @@ export async function replaceUndoState(project) { ? { scope: "say", available: true, why: null, entry: last.entry, was: last.was ?? null } : { scope: "say", available: false, why: `the entry for "${last.entry.word}" changed since (umtool posts say ${project.id} ls)`, entry: last.entry, was: last.was ?? null }; } + if (last.undoable === false || !last.sha) return { scope: "reads", available: false, why: "the draft changed while the replace was written (another write landed): taking it back could take that back too -- undo from where each was made" }; if ((await draftSha(project.dir)) !== last.sha) return { scope: "reads", available: false, why: "the draft changed after the replace (a re-read landed, or another edit): taking the replace back now would take that back too -- undo those from where they were made" }; const { listSnapshots } = await import("./snapshots.mjs"); const top = (await listSnapshots(project.dir)).find((s) => !s.legacy && s.label?.startsWith(AUTO_SNAPSHOT_PREFIX)); if (!top || top.label !== UNDO_LABEL) return { scope: "reads", available: false, why: "its undo point is no longer the newest" }; + if (last.snapshot && top.rel !== last.snapshot) return { scope: "reads", available: false, why: "its undo point is not the one it made (the newest is another replace's)" }; return { scope: "reads", available: true, why: null }; } /** Take back the newest replace of These reads: refused, in a sentence, unless replaceUndoState says it may be. */ export async function undoReplace(project, { token = null } = {}) { + // The token the check is made against goes with the restore: a write between the two is refused, never undone. + const checked = token ?? (await manifestToken(project.dir)); const st = await replaceUndoState(project); if (!st || st.scope !== "reads") throw new ReplaceError("nothing to undo: the newest replace made here is not one of These reads"); if (!st.available) throw new ReplaceError(`not undone: ${st.why}`); const { withEditNotes } = await import("./edit-guard.mjs"); - const { result } = await withEditNotes(project, async () => undoStructural(project.dir, { token })); + const { result } = await withEditNotes(project, async () => undoStructural(project.dir, { token: checked })); await withReplaces(project.dir, (records) => ({ records: records.slice(0, -1), result: null })); return result; }