commit 9e7a26459483dd22da6b70244199668a69408658
parent 9317f2db79d0b2d4b075b59c9b60865018039fe8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 1 Nov 2026 01:35:54 -0500
umtool: one take-patch helper -- a section edit's in-step marker sync lives in patchMarkers.mjs (syncSectionMarkers) beside the removal re-anchor; sectionPatches.mjs is gone
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
8 files changed, 67 insertions(+), 85 deletions(-)
diff --git a/umtool/app/api/report/timeline/route.ts b/umtool/app/api/report/timeline/route.ts
@@ -54,7 +54,7 @@ export const dynamic = "force-dynamic";
// section-boundary { marker, afterId } drag a boundary (between its neighbours)
// section-remove { marker } the section joins the one before it
// section-set { marker, label?, color? } relabel / recolour a section
-// (each section op brings the take patches' markers along: lib/report/sectionPatches.mjs)
+// (each section op brings the take patches' markers along: lib/report/patchMarkers.mjs syncSectionMarkers)
//
// Every op snapshots the manifest first (`revisions/<stamp>-auto-before-<op>`),
// is checked by the build's own validators, and on a GENERATED manifest leaves
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -239,7 +239,7 @@ boundary, and a marker `{after, label, color}` opens the next section right afte
the new section's. These edits move clips and boundaries together, so no section empties and no boundary crosses
another (each refused in words), and every **take patch in step** (`*.patch.json` beside the manifest whose
markers were the manifest's before the edit) is brought along; a patch whose markers already differed is left, and
-named (`lib/report/sectionEdit.mjs`, `sectionPatches.mjs`). Each is a structural write: an undo point first
+named (`lib/report/sectionEdit.mjs`; `patchMarkers.mjs` syncSectionMarkers, beside the removal re-anchor). Each is a structural write: an undo point first
(**Undo last edit**, `umtool timeline <p> undo`).
| | In umtool | From a terminal | Route |
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -42,7 +42,6 @@ import { validateRoom } from "umtool-report-to-video/room";
import { applySectionEnter } from "./sections.mjs";
import { citeUrlAt, parseClipSpec } from "./clipEditorModel.mjs";
import { addSectionIn, followSplitMarkers, moveBoundaryIn, moveToSectionIn, removeBoundaryIn, sectionModel, sectionWords, setSectionIn } from "./sectionEdit.mjs";
-import { syncSectionPatches } from "./sectionPatches.mjs";
import { normalizeClaim, validateClaims } from "umtool-report-to-video/factcheck";
import { migrateManifest } from "umtool-report-to-video/modules/migrate";
import { loadPreset, resolvePresetLayers } from "umtool-report-to-video/presets";
@@ -64,7 +63,7 @@ import { DELIVERABLES_MODES } from "./storage.mjs";
import { createSnapshot, listSnapshots } from "./snapshots.mjs";
import { benchPrepAfterWrite } from "./benchPrepTrigger.mjs";
import { citeFollow, clockOf, qrFollowsCite } from "./citeFollow.mjs";
-import { syncPatchMarkers } from "./patchMarkers.mjs";
+import { syncPatchMarkers, syncSectionMarkers } from "./patchMarkers.mjs";
import {
DRAFTED_MANIFEST_FIELDS, clearEditedDrafts, isEntryField, publishWarnings, pruneDrafted, validateDrafted, validatePublish,
} from "yt-dlp-transcript-common/lib/report/drafted.mjs";
@@ -2185,7 +2184,7 @@ export async function insertEntry(dir, afterId, spec, { token = null, at = null
// writers move clips between sections, open a section, drag or remove a
// boundary and relabel one -- each a structural write (the undo point, the
// build's checks), the markers checked by the deck's own validateChrome, and
-// then the take patches' markers brought along (sectionPatches.mjs) so the next
+// then the take patches' markers brought along (patchMarkers.mjs syncSectionMarkers) so the next
// `umtool take --patch …` renders the same sections. `umtool timeline <p>
// section …`, the Cut tab's section bars and row menus.
@@ -2214,7 +2213,7 @@ async function sectionWrite(dir, op, token, mutate) {
return r;
});
// `sectionPatches`: a section edit's take-patch sync (`patches` is a removal's, patchMarkers.mjs).
- const sectionPatches = await syncSectionPatches(dir, before, after);
+ const sectionPatches = await syncSectionMarkers(dir, before, after);
return { ...res, sectionPatches };
}
diff --git a/umtool/lib/report/patchMarkers.mjs b/umtool/lib/report/patchMarkers.mjs
@@ -206,3 +206,60 @@ export async function fixStalePatchMarkers(dir, manifest, file) {
}
return { file, notes, left };
}
+
+// ---- a section edit's markers (lane/ui-cut-editing, UI notes item 1) -------
+//
+// A section edit (manifest.mjs moveToSection / addSection / moveSectionBoundary /
+// removeSection / updateSection / splitClip / flashForward) removes no clip, so
+// removedAnchors has nothing to say: the markers themselves moved. The rule is
+// deliberately narrow: a patch whose markers were IN STEP with the manifest's
+// before the edit (the same list, byte for byte) gets the new list; a patch whose
+// markers already differed is somebody's deliberate variant, left as it is and
+// named, never rewritten by a guess. A patch with no markers, or with a timeline
+// of its own (patchMarkersOf), is not touched. The patch's own indent is kept.
+
+/** The indent a JSON file was written with (its first nested line), else 2: a rewrite keeps it. */
+export const indentOf = (text) => /^[[{]\r?\n( +)\S/.exec(String(text ?? ""))?.[1].length ?? 2;
+
+/**
+ * Bring every in-step patch's markers to `after` (the manifest's after the
+ * edit; [] or null: the patch's markers removed with them).
+ *
+ * @param {string} dir the project
+ * @param {unknown[] | null | undefined} before the manifest's markers before the edit
+ * @param {unknown[] | null | undefined} after the manifest's markers after it
+ * @returns {Promise<{ synced: string[], skipped: { file: string, why: string }[] }>}
+ */
+export async function syncSectionMarkers(dir, before, after) {
+ const synced = [];
+ const skipped = [];
+ const was = JSON.stringify(before ?? []);
+ const now = JSON.stringify(after ?? []);
+ if (was === now) return { synced, skipped };
+ for (const name of await patchFilesOf(dir)) {
+ const file = path.join(dir, name);
+ let doc;
+ let text = "";
+ try {
+ text = await readFile(file, "utf8");
+ doc = JSON.parse(text);
+ } catch (e) {
+ skipped.push({ file: name, why: `does not parse (${e instanceof Error ? e.message : e}): not touched` });
+ continue;
+ }
+ const mine = patchMarkersOf(doc);
+ if (!mine) continue;
+ if (JSON.stringify(mine) !== was) {
+ skipped.push({ file: name, why: "its markers were not the manifest's before this edit (a deliberate variant?): left as they are" });
+ continue;
+ }
+ const deck = doc.render.chrome.deck;
+ if (Array.isArray(after) && after.length) deck.markers = JSON.parse(now);
+ else delete deck.markers;
+ const tmp = `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
+ await writeFile(tmp, JSON.stringify(doc, null, indentOf(text)) + "\n", "utf8");
+ await rename(tmp, file);
+ synced.push(name);
+ }
+ return { synced, skipped };
+}
diff --git a/umtool/lib/report/sectionEdit.mjs b/umtool/lib/report/sectionEdit.mjs
@@ -13,7 +13,7 @@
// Everything here is PURE: each function mutates the manifest it is handed and
// returns what it did in words. manifest.mjs runs them inside a structural
// write (the lock, the token, the build's checks, the undo point), and syncs
-// the take patches' markers after (sectionPatches.mjs).
+// the take patches' markers after (patchMarkers.mjs syncSectionMarkers).
//
// The rules, each refused in words rather than repaired silently:
// - a section never ends up with no clip (two markers on one boundary);
diff --git a/umtool/lib/report/sectionEdit.test.mjs b/umtool/lib/report/sectionEdit.test.mjs
@@ -11,7 +11,7 @@ import path from "node:path";
import test from "node:test";
import { addSectionIn, moveBoundaryIn, moveToSectionIn, removeBoundaryIn, sectionModel, setSectionIn } from "./sectionEdit.mjs";
-import { syncSectionPatches } from "./sectionPatches.mjs";
+import { syncSectionMarkers } from "./patchMarkers.mjs";
import {
MANIFEST_NAME,
StructureRefused,
@@ -180,10 +180,10 @@ test("a marker past the deck's limits is refused in its words, nothing written",
}
});
-test("syncSectionPatches keeps the patch's own indent", async () => {
+test("syncSectionMarkers keeps the patch's own indent", async () => {
const dir = await project(deckCut(), { "one.patch.json": JSON.stringify(patchOf([{ after: "b" }]), null, 1) + "\n" });
try {
- await syncSectionPatches(dir, [{ after: "b" }], [{ after: "c" }]);
+ await syncSectionMarkers(dir, [{ after: "b" }], [{ after: "c" }]);
const text = await readFile(path.join(dir, "one.patch.json"), "utf8");
assert.match(text, /^\{\n "render"/);
assert.equal(JSON.parse(text).render.chrome.deck.markers[0].after, "c");
diff --git a/umtool/lib/report/sectionPatches.mjs b/umtool/lib/report/sectionPatches.mjs
@@ -1,74 +0,0 @@
-// TAKE PATCHES KEEP THE CUT'S SECTIONS (UI notes 2026-10-30, item 1).
-//
-// A take patch the operator renders with (`umtool take … --patch
-// draft-1.patch.json`, a `*.patch.json` beside the manifest) may carry
-// `render.chrome.deck.markers` -- the sections -- and a patch's markers REPLACE
-// the manifest's. So a section edit in the manifest that leaves the patch alone
-// is undone at the next take, or refused (a marker naming a clip that is gone):
-// draft-9 of the Ember cut was refused exactly so.
-//
-// The rule here is deliberately narrow: a patch whose markers were IN STEP with
-// the manifest's before the edit (the same list, byte for byte) gets the new
-// list; a patch whose markers already differed is somebody's deliberate
-// variant, left as it is and named in the result, never rewritten by a guess.
-// A patch without markers, or with a timeline of its own (its markers name
-// ITS clips), is not touched. (Removals are lane/ui-cut-integrity's
-// patchMarkers.mjs: a marker after a clip that is gone re-anchored by name.) Each rewrite keeps the patch's
-// own indent (and a trailing newline) and goes through tmp + rename.
-import { readdir, readFile, rename, writeFile } from "node:fs/promises";
-import path from "node:path";
-
-const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
-/** The indent a JSON file was written with (its first nested line), else 2: a rewrite keeps it. */
-export const indentOf = (text) => /^[[{]\r?\n( +)\S/.exec(String(text ?? ""))?.[1].length ?? 2;
-const markersOf = (doc) =>
- isObj(doc) && doc.timeline === undefined && isObj(doc.render?.chrome?.deck) && Array.isArray(doc.render.chrome.deck.markers) ? doc.render.chrome.deck.markers : null;
-
-/** The project's take patches: every `*.patch.json` beside its manifest. */
-async function patchFilesOf(dir) {
- const names = await readdir(dir).catch(() => []);
- return names.filter((n) => /^[A-Za-z0-9][A-Za-z0-9._-]*\.patch\.json$/.test(n)).sort();
-}
-
-/**
- * Bring every in-step patch's markers to `after` (the manifest's markers
- * after the edit; [] or null: the patch's markers removed with them).
- *
- * @param {string} dir the project
- * @param {unknown[] | null | undefined} before the manifest's markers before the edit
- * @param {unknown[] | null | undefined} after the manifest's markers after it
- * @returns {Promise<{ synced: string[], skipped: { file: string, why: string }[] }>}
- */
-export async function syncSectionPatches(dir, before, after) {
- const synced = [];
- const skipped = [];
- const was = JSON.stringify(before ?? []);
- const now = JSON.stringify(after ?? []);
- if (was === now) return { synced, skipped };
- for (const name of await patchFilesOf(dir)) {
- const file = path.join(dir, name);
- let doc;
- let text = "";
- try {
- text = await readFile(file, "utf8");
- doc = JSON.parse(text);
- } catch (e) {
- skipped.push({ file: name, why: `does not parse (${e instanceof Error ? e.message : e}): not touched` });
- continue;
- }
- const mine = markersOf(doc);
- if (!mine) continue;
- if (JSON.stringify(mine) !== was) {
- skipped.push({ file: name, why: "its markers were not the manifest's before this edit (a deliberate variant?): left as they are" });
- continue;
- }
- const deck = doc.render.chrome.deck;
- if (Array.isArray(after) && after.length) deck.markers = JSON.parse(now);
- else delete deck.markers;
- const tmp = `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
- await writeFile(tmp, JSON.stringify(doc, null, indentOf(text)) + "\n", "utf8");
- await rename(tmp, file);
- synced.push(name);
- }
- return { synced, skipped };
-}
diff --git a/umtool/lib/report/trailerBeats.mjs b/umtool/lib/report/trailerBeats.mjs
@@ -25,7 +25,7 @@ import { copyFile, mkdir, readFile, readdir, rename, stat, writeFile } from "nod
import path from "node:path";
import { gappedLength, gapsOf } from "umtool-report-to-video/gaps";
import { TRAILER_XFADE_DEFAULT, TrailerError, parseBeats } from "umtool-report-to-video/trailer";
-import { indentOf } from "./sectionPatches.mjs";
+import { indentOf } from "./patchMarkers.mjs";
import { sectionModel, sectionWords } from "./sectionEdit.mjs";
import { trailerCandidates } from "./trailerCandidates.mjs";