commit 367717b9c33f1740ae59ee8ced92193cb36b6b4d
parent 1c5b6fd9b3f7f988e3bb0a3f139915df4df06246
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 19:06:05 -0500
umtool: an open never writes a preset-resolved manifest; a version's base is not saved twice (L3 re-review)
1. A legacy rendered take's takes/<id>/video.manifest.json has its preset
RESOLVED (preset deleted, presetApplied set, the preset's render keys laid
in). Compared against the draft it was never a no-op in a project naming a
preset (the 307 straight-on lost), and opening it wrote the resolved
manifest, so the draft stopped following its preset. Now:
- unresolvePreset: presetApplied goes back to `preset`, every render leaf
that is the preset's own value taken out (an override stays); it resolves
to exactly what was rendered;
- a merge-open lays style + patch over the draft by RFC 7386 only (no
resolvePresetLayers), so `preset` stays named;
- a legacy take that is the draft's parent with no edits (main's rule) is a
no-op -- unless an earlier open left its written manifest on the pointer,
when the content decides; content compares ignore key order (sameContent).
2. Opening while the draft IS a version's frozen base byte for byte (only that
version's patch differs, a "No intro") no longer saves a byte-identical vN+1.
3. knobs.md: the preset stays named; Open in draft / Save version refuse
another site's post, and a proxy that rewrites Host must set X-Forwarded-Host.
Tests (versions.test.mjs): a fixture naming the plain-deck preset with a render
override -- the latest legacy take with no edits opens as nothing (openIsNoop
true, nothing written); after an edit it opens naming the preset, the override
kept, resolving to what was rendered; a merge-open keeps the preset named. The
No-intro probe now expects no second copy of v2's base.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 150 insertions(+), 17 deletions(-)
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -635,6 +635,12 @@ expected the cut). A take is a **saved version** — FROZEN:
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).
+- **A preset stays named.** Opening a legacy take never writes a preset-resolved manifest into the draft: the
+ rendered file's `presetApplied` goes back to `preset`, the keys that are the preset's own taken out (an override
+ stays), and a merge lays the patch over the draft without resolving anything. A legacy take that is the draft's
+ parent with no edits opens as nothing (main's rule), so its 307 straight-on holds in a project naming a preset.
+- **Open in draft and Save version refuse another site's post** (`Sec-Fetch-Site`, `Origin` against the request's
+ host). A proxy that rewrites `Host` must set `X-Forwarded-Host` (Caddy keeps `Host`).
- **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/lib/report/versions.mjs b/umtool/lib/report/versions.mjs
@@ -212,10 +212,10 @@ export async function saveVersion(project, { label = null, now = new Date(), for
* @param {Record<string, any>} draft the draft, parsed
*/
export async function openedManifestOf(projectDir, id, draft) {
- const { versionManifestOf } = await import("./takeMaker.mjs");
+ const { loadMontageStyles, mergePatch, versionManifestOf } = await import("./takeMaker.mjs");
const v = await versionManifestOf(projectDir, id);
if (v) return { manifest: v.manifest, how: /** @type {const} */ ("frozen") };
- const { resolveTakeManifest, takeSpecOf } = await import("./takeManifest.mjs");
+ const { takeSpecOf } = await import("./takeManifest.mjs");
const spec = await takeSpecOf(projectDir, id);
if (!spec) throw new VersionRefused(`no take ${id}`);
if (!spec.made) throw new VersionRefused(`take ${id} is only named by a recipe — nothing made to open`);
@@ -225,11 +225,22 @@ export async function openedManifestOf(projectDir, id, draft) {
// a CLI take-scoped edit: `editedAt` after `builtAt`) -- Play ?take= plays the patch, so the open merges it.
const editedSince = typeof doc.editedAt === "string" && doc.editedAt && !(typeof doc.builtAt === "string" && doc.builtAt && doc.editedAt <= doc.builtAt);
const renderedText = doc.draft === true || editedSince ? null : await readFile(path.join(takesDirOf(projectDir), id, MANIFEST), "utf8").catch(() => null);
- if (!ownTimeline && renderedText !== null) {
- const m = JSON.parse(renderedText);
- if (isObj(m) && Array.isArray(m.timeline)) return { manifest: m, how: /** @type {const} */ ("rendered") };
+ const rendered = renderedText !== null ? JSON.parse(renderedText) : null;
+ // NEVER a preset resolved into the draft: the rendered file has its preset laid in (presetApplied); it goes
+ // back to naming it, as the draft did (unresolvePreset), so the draft keeps following its preset.
+ if (!ownTimeline && isObj(rendered) && Array.isArray(rendered.timeline)) return { manifest: await unresolvePreset(rendered), how: /** @type {const} */ ("rendered") };
+ // The take's style and patch merged over the draft as it is (promoteTake's merge) -- RFC 7386 only, the
+ // draft's `preset` left named, never resolved.
+ let stylePatch = null;
+ if (spec.style) {
+ stylePatch = (await loadMontageStyles()).styles[spec.style]?.patch ?? null;
+ if (!stylePatch) {
+ if (isObj(rendered) && Array.isArray(rendered.timeline)) return { manifest: await unresolvePreset(rendered), how: /** @type {const} */ ("rendered") };
+ throw new VersionRefused(`take ${id}: its style "${spec.style}" is not installed, and it has no rendered manifest`);
+ }
}
- const { manifest: merged } = await resolveTakeManifest(projectDir, id, { base: draft, frozen: false });
+ const merged = [stylePatch, spec.patch].filter(Boolean).reduce((m, p) => mergePatch(m, p), draft);
+ if (!isObj(merged) || !Array.isArray(merged.timeline)) throw new VersionRefused(`take ${id}: the patched manifest has no timeline`);
// The build's structure rules, over the draft becoming the take's (promoteTake's check).
const next = JSON.parse(JSON.stringify(draft));
applyStructural(next, (m) => {
@@ -239,6 +250,67 @@ export async function openedManifestOf(projectDir, id, draft) {
return { manifest: next, how: /** @type {const} */ ("merge") };
}
+/**
+ * A manifest with its preset RESOLVED (resolvePresetLayers: `preset` deleted, `presetApplied` set, the
+ * preset's render keys laid in) back to NAMING it: `preset` again, and every render leaf whose value is the
+ * preset's own taken out (the preset puts it back). It resolves to what it was; an override stays. A manifest
+ * not resolved is returned as it is.
+ *
+ * @param {Record<string, any>} m
+ */
+export async function unresolvePreset(m) {
+ if (!isObj(m) || typeof m.presetApplied !== "string" || !m.presetApplied) return m;
+ const { loadPreset } = await import("umtool-report-to-video/presets");
+ let preset;
+ try {
+ preset = loadPreset(m.presetApplied);
+ } catch {
+ return m; // a preset gone: the resolved manifest is all there is
+ }
+ const strip = (node, pre) => {
+ for (const k of Object.keys(pre)) {
+ if (!(k in node)) continue;
+ if (isObj(pre[k]) && isObj(node[k])) {
+ strip(node[k], pre[k]);
+ if (!Object.keys(node[k]).length) delete node[k];
+ } else if (sameContent(node[k], pre[k])) delete node[k];
+ }
+ };
+ const { presetApplied, ...rest } = JSON.parse(JSON.stringify(m));
+ const out = { preset: presetApplied, ...rest };
+ if (isObj(out.render) && isObj(preset.render)) {
+ strip(out.render, preset.render);
+ if (!Object.keys(out.render).length) delete out.render;
+ }
+ return out;
+}
+
+/** Deep equality that ignores key order (a manifest written by another writer orders its keys its own way). */
+export function sameContent(a, b) {
+ const canon = (v) => (Array.isArray(v) ? v.map(canon) : isObj(v) ? Object.fromEntries(Object.keys(v).sort().map((k) => [k, canon(v[k])])) : v);
+ return JSON.stringify(canon(a)) === JSON.stringify(canon(b));
+}
+
+/**
+ * Would opening `id` write nothing? When the draft already holds what it is (by content), or -- main's rule
+ * for a LEGACY take -- it is the draft's parent with no edits since (its rendered file is preset-resolved and
+ * carries its look patch; the draft is the same cut, naming its preset).
+ *
+ * @param {string} projectDir
+ * @param {string} id
+ * @param {Record<string, any>} draft
+ * @param {Awaited<ReturnType<typeof readWorkingCut>>} working
+ * @param {Record<string, any>} opened what openedManifestOf would write
+ */
+async function noopOpen(projectDir, id, draft, working, opened) {
+ if (sameContent(opened, draft)) return true;
+ const legacy = (await frozenBaseText(projectDir, id)) === null;
+ if (!legacy || working.parent?.id !== id || working.edits?.count !== 0) return false;
+ // Opened before (the pointer keeps what that open wrote): the content says it, not the rule.
+ const pointer = await readDraftFile(projectDir);
+ return !(pointer?.from === id && pointer.base);
+}
+
/** The undo point's sidecar: the draft pointer as it was before the write the snapshot takes back. */
export const draftSidecarOf = (snapshotRel) => snapshotRel.replace(/\.manifest\.json$/, ".draft.json");
@@ -271,9 +343,10 @@ export async function openVersion(project, id, { token = null, now = new Date(),
const working = await readWorkingCut(project.dir, { manifestText: text });
// What opening it would write, decided BEFORE anything is saved (a refusal leaves nothing behind).
const { manifest, how } = await openedManifestOf(project.dir, id, draft);
- // Unchanged BY CONTENT: the draft already holds what the version is (a version's "No intro" since its save
- // is not; it opens). The pointer is set when it named another.
- if (JSON.stringify(manifest) === JSON.stringify(draft)) {
+ // Unchanged: the draft already holds what the version is, by content (a version's "No intro" since its
+ // save is not; it opens) -- or a legacy take that is the draft's parent with no edits (main's rule). The
+ // pointer is set when it named another.
+ if (await noopOpen(project.dir, id, draft, working, manifest)) {
if (working.parent?.id !== id || working.parent?.via !== "draft") {
await writeDraft(project.dir, { from: id, hash: hashText(text), at: now.toISOString(), base: how === "frozen" ? null : draft });
}
@@ -282,7 +355,12 @@ export async function openVersion(project, id, { token = null, now = new Date(),
const edits = working.edits?.count ?? null;
const pointerBeforeSave = await readDraftFile(project.dir);
let saved = null;
- if (!working.parent || working.edits === null || working.edits.count > 0) {
+ // Nothing is lost when the draft IS a version's frozen base byte for byte (only that version's patch
+ // differs since -- a "No intro"): no second, byte-identical copy of it.
+ const parentBase = working.parent ? await frozenBaseText(project.dir, working.parent.id) : null;
+ const openedBase = await frozenBaseText(project.dir, id);
+ const kept = parentBase === text || openedBase === text;
+ if (!kept && (!working.parent || working.edits === null || working.edits.count > 0)) {
const r = await saveVersionLocked(project.dir, { now, force: true, why: `Draft before opening ${id}` });
saved = r.saved ? r.id : null;
}
@@ -323,7 +401,7 @@ export async function openIsNoop(projectDir, id) {
const text = await readFile(path.join(projectDir, MANIFEST), "utf8");
const draft = JSON.parse(text);
const { manifest } = await openedManifestOf(projectDir, id, draft);
- return JSON.stringify(manifest) === JSON.stringify(draft);
+ return await noopOpen(projectDir, id, draft, await readWorkingCut(projectDir, { manifestText: text }), manifest);
} catch {
return false;
}
diff --git a/umtool/lib/report/versions.test.mjs b/umtool/lib/report/versions.test.mjs
@@ -316,7 +316,7 @@ test("undo points are pruned to the newest N; a named snapshot is never pruned",
// ---- the review's fixes (L3 review, 9 Nov) ----
-test("a version's patch never masks a draft edit: v2 'No intro' and an intro in the draft is an edit; open(v2) saves the draft, then brings its No intro in; open(v1) after another intro saves it first", async () => {
+test("a version's patch never masks a draft edit: v2 'No intro' and an intro in the draft is an edit; open(v2) brings its No intro in (no byte-identical save of its base); open(v1) after another intro saves it first", async () => {
const { root, dir, proj } = await project();
const setIntro = async (on) => {
const m = JSON.parse(await text(dir));
@@ -339,18 +339,24 @@ test("a version's patch never masks a draft edit: v2 'No intro' and an intro in
const withIntro = await text(dir);
const o2 = await openVersion(proj, "v2");
assert.equal(o2.unchanged, false, "not 'unchanged': v2's No intro is not in the draft");
- assert.equal(o2.saved, "v3", "the draft (with its intro) saved first");
- assert.equal(await readFile(path.join(dir, "takes", "v3", "base.manifest.json"), "utf8"), withIntro);
+ assert.equal(o2.saved, null, "the draft IS v2's base byte for byte: no second copy of it");
+ assert.equal(await readFile(path.join(dir, "takes", "v2", "base.manifest.json"), "utf8"), withIntro, "kept there");
assert.ok(!("intro" in JSON.parse(await text(dir)).render), "v2's No intro reached the draft");
assert.equal((await openVersion(proj, "v2")).unchanged, true, "now the draft holds it");
w = await readWorkingCut(dir);
assert.deepEqual([w.parent?.id, w.edits?.count], ["v2", 0]);
- // An intro added to the draft again: an edit (v2's patch does not hide it), so open(v1) saves it first.
+ // The intro added to the draft again: an edit (v2's patch does not hide it) -- but the draft is v2's base
+ // byte for byte, so open(v1) keeps no second copy of it.
await setIntro(true);
assert.equal((await readWorkingCut(dir)).edits?.count, 1);
+ assert.equal(await text(dir), withIntro);
+ assert.equal((await openVersion(proj, "v1")).saved, null);
+ // A real edit since v1: saved first.
+ await moveEntry(dir, "a", 2);
+ const edited = await text(dir);
const o1 = await openVersion(proj, "v1");
- assert.equal(o1.saved, "v4");
- assert.equal(JSON.parse(await readFile(path.join(dir, "takes", "v4", "base.manifest.json"), "utf8")).render.intro, "boot-dark");
+ assert.equal(o1.saved, "v3");
+ assert.equal(await readFile(path.join(dir, "takes", "v3", "base.manifest.json"), "utf8"), edited);
} finally {
await rm(root, { recursive: true, force: true });
}
@@ -447,3 +453,46 @@ test("a working take rendered while the draft was opened leaves the opened point
await rm(root, { recursive: true, force: true });
}
});
+
+test("a project naming a PRESET: its latest legacy take with no edits opens as nothing (straight on); opened after an edit, the draft keeps naming the preset -- never the resolved manifest", async () => {
+ const { resolvePresetLayers } = await import("umtool-report-to-video/presets");
+ const { openIsNoop, sameContent } = await import("./versions.mjs");
+ const { root, dir, proj } = await project({ ...MANIFEST, preset: "plain-deck", render: { crf: 30 } });
+ try {
+ const render = async (job) => {
+ const file = path.join(job.outDir, `${job.slug}.mp4`);
+ await writeFile(file, "mp4");
+ return { file };
+ };
+ await makeTake(dir, { id: "d1", label: "Draft 1", window: "full" }, { render, styles: {}, probe: async () => 9, record: false, pruneAfter: false });
+ const rendered = await json(path.join(dir, "takes", "d1", "video.manifest.json"));
+ assert.equal(rendered.presetApplied, "plain-deck", "the render's file is preset-resolved");
+ // Make the pointer "latest" again (main's shape: no draft.json), the draft untouched since the render.
+ await rm(path.join(dir, "takes", "draft.json"), { force: true });
+ let w = await readWorkingCut(dir);
+ assert.deepEqual([w.parent?.id, w.edits?.count], ["d1", 0]);
+ assert.equal(await openIsNoop(dir, "d1"), true, "the 307 straight-on is kept");
+ const before = await text(dir);
+ assert.equal((await openVersion(proj, "d1")).unchanged, true);
+ assert.equal(await text(dir), before, "nothing written over the draft");
+ // An edit, then open d1: the rendered cut comes back NAMING its preset.
+ await moveEntry(dir, "c", 0);
+ const o = await openVersion(proj, "d1");
+ assert.equal(o.how, "rendered");
+ const now = JSON.parse(await text(dir));
+ assert.equal(now.preset, "plain-deck");
+ assert.equal(now.presetApplied, undefined);
+ assert.deepEqual(now.render, { crf: 30 }, "the draft's override stays; the preset's keys are the preset's");
+ assert.deepEqual(now.timeline.map((e) => e.id), ["a", "b", "c"]);
+ assert.ok(sameContent(resolvePresetLayers(now), rendered), "it resolves to exactly what was rendered");
+ // A legacy take with its own timeline, merged: the preset stays named too.
+ await mkdir(path.join(dir, "takes", "own"), { recursive: true });
+ await writeFile(path.join(dir, "takes", "own", "take.json"), JSON.stringify({ id: "own", group: "takes", order: 5, label: "own", kind: "different", preview: "preview.mp4", draft: true, patch: { timeline: [clip("b", 21, 24)] } }));
+ const m = await openVersion(proj, "own");
+ assert.equal(m.how, "merge");
+ const after = JSON.parse(await text(dir));
+ assert.deepEqual([after.preset, after.presetApplied, after.render], ["plain-deck", undefined, { crf: 30 }]);
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+});