commit 16648cf22ac4962e4c635841bf491972bff93ecd
parent 8ac41ca13e231d1f4bb878fcc514e226a58cc180
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 26 Oct 2026 22:06:15 -0400
umtool link: a manifest names its article through a writer -- what settles link-ambiguous without a hand edit
An article two projects share a slug with links to neither until one
manifest carries a top-level "article" (lib/articles/links.mjs, the second
way), and nothing wrote that key: the inbox's advice ("name the article in its
manifest") was a hand edit. updateArticleLink (lib/report/manifest.mjs) writes
or clears it under the manifest lock, snapshotted first (auto-before-link), in
the CLI's formatting; `umtool link <project> <site>/<report> | --clear` runs it
through the same edit guard as `umtool window`, so a generated manifest gets an
edit note for its generator. A link to an article not (yet) there is said, not
refused.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs
@@ -98,7 +98,7 @@ import { createSnapshot, listSnapshots, readSnapshot } from "../lib/report/snaps
import { diffManifests, formatChange } from "../lib/report/manifest-diff.mjs";
import { EXPORT_FORMATS, exportProject } from "../lib/report/export.mjs";
import path from "node:path";
-import { updateClip, updateStorage } from "../lib/report/manifest.mjs";
+import { updateArticleLink, updateClip, updateStorage } from "../lib/report/manifest.mjs";
import { withEditNotes } from "../lib/report/edit-guard.mjs";
import { hms } from "umtool-report-to-video/attribution";
import { buildSteps, checkSourcesSteps, PRESETS } from "../lib/report/driver.mjs";
@@ -106,13 +106,14 @@ import { sourceCountOf } from "umtool-report-to-video/manifest-sources";
import { runBuildOverHttp, umtoolBase } from "../lib/report/buildRun.mjs";
import { CHAIN_STEP_NAMES, chainStepsOf, planChain } from "../lib/report/chain.mjs";
import { spawn } from "node:child_process";
+import { stat } from "node:fs/promises";
import { openIndex, signRecord } from "../lib/projects/index-db.mjs";
import { pipelineProcessesFor } from "../lib/report/busy.mjs";
import { probeTools } from "../lib/tools.mjs";
import { notesCommand } from "../lib/annotations/cli.mjs";
import { scaffoldReportVideo } from "../lib/projects/scaffold.mjs";
import { rootsReport } from "../lib/system/roots.mjs";
-import { ARTICLES_DIR, MEDIA_ROOT, MEDIA_TIERED } from "../lib/paths.mjs";
+import { ARTICLES_DIR, ARTICLES_KEY, MEDIA_ROOT, MEDIA_TIERED, SITES_DIR } from "../lib/paths.mjs";
import {
deliverablesState,
moveDeliverables,
@@ -713,6 +714,8 @@ function usage() {
" a schedule is written through the editor: `pnpm ops report-schedule`)",
" umtool folders [--json]",
" umtool kinds [--json]",
+ " umtool link <project> <site>/<report> | --clear [--json] the manifest names its article (a top-level",
+ " `article`): what settles link-ambiguous; noted for the generator on a generated manifest",
" umtool window <project> <clip> [--start S] [--end E] [--lock|--lock-end|…]",
" attribution too: --title, --date YYYY-MM-DD, --cite, --cite-url, --quote",
" --correction TEXT what the REPORT got wrong here (never rendered)",
@@ -819,6 +822,7 @@ function usage() {
const COMMANDS = {
ls: cmdLs,
window: cmdWindow,
+ link: cmdLink,
// The video knobs (plans/video-knobs-ui.md): lib/report/knobsCli.mjs.
set: async () => process.exit(await (await import("../lib/report/knobsCli.mjs")).setCommand(argv.slice(argv.indexOf("set") + 1))),
look: async () => process.exit(await (await import("../lib/report/knobsCli.mjs")).lookCommand(argv.slice(argv.indexOf("look") + 1))),
@@ -1005,6 +1009,42 @@ async function cmdWindow() {
}
}
+// `umtool link <project> <site>/<report>`: the manifest names the article it is
+// the video of (lib/articles/links.mjs, the second way). Through the writer the
+// app would use (lib/report/manifest.mjs updateArticleLink: the lock, the
+// snapshot, the CLI's formatting) and the same edit guard as `window`.
+async function cmdLink() {
+ const p = await pick(positional[0]);
+ const clear = has("--clear");
+ const article = clear ? null : positional[1];
+ if (!clear && !article) die("which article? `umtool link <project> <site>/<report>` (or --clear)");
+ // A link to an article that is not there links nothing. Said, not refused:
+ // the article may be on its way (a site's report is written by the editor).
+ let missing = false;
+ if (article) {
+ const [site, report] = String(article).split("/");
+ const dir =
+ site === ARTICLES_KEY ? path.join(ARTICLES_DIR, report ?? "") : path.join(SITES_DIR, site ?? "", "reports", report ?? "");
+ missing = !(await stat(dir).then((st) => st.isDirectory(), () => false));
+ }
+ try {
+ const { result: res, editNotes } = await withEditNotes(p, () => updateArticleLink(p.dir, article));
+ if (json) return out({ ok: true, project: p.id, ...res, missing, editNotes });
+ if (!res.changed) console.log(`${p.id}: already ${res.article ? `linked to ${res.article}` : "unlinked"} — nothing written`);
+ else console.log(`${p.id}: article ${res.was ?? "(none)"} -> ${res.article ?? "(none)"}`);
+ if (missing) console.log(` no article at ${article} yet — the link waits for it`);
+ if (editNotes && (editNotes.added || editNotes.updated || editNotes.errors.length)) {
+ console.log(
+ editNotes.errors.length
+ ? ` edit NOT noted (${editNotes.errors.join("; ")}) — ${editNotes.generatedBy} will overwrite it on the next rebuild`
+ : ` edit noted for ${editNotes.generatedBy} — port it into the generator's inputs, or its next rebuild drops it`,
+ );
+ }
+ } catch (e) {
+ die(e?.message ?? String(e));
+ }
+}
+
// What the REPORT got wrong, collected for the next pass.
//
// Markdown, and the moment link is the QR's own target -- so a bullet can be
diff --git a/umtool/lib/report/article-link.test.mjs b/umtool/lib/report/article-link.test.mjs
@@ -0,0 +1,46 @@
+// updateArticleLink: the writer behind `umtool link`, the only way to settle a
+// link-ambiguous article (two projects share its slug) without a hand edit.
+//
+// Run with: pnpm test:scripts
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import test from "node:test";
+
+import { updateArticleLink } from "./manifest.mjs";
+
+test("names the article, is a no-op when it already does, clears, and refuses a bad id", async () => {
+ const dir = await mkdtemp(path.join(tmpdir(), "article-link-"));
+ try {
+ await mkdir(dir, { recursive: true });
+ const file = path.join(dir, "video.manifest.json");
+ const manifest = { schemaVersion: 1, slug: "polemic-flips", title: "T", timeline: [{ type: "clip", id: "a", video: "v", start: 1, end: 2 }] };
+ await writeFile(file, JSON.stringify(manifest, null, 2) + "\n");
+
+ const r1 = await updateArticleLink(dir, "articles/polemic-flips");
+ assert.equal(r1.changed, true);
+ assert.equal(r1.was, null);
+ const after = JSON.parse(await readFile(file, "utf8"));
+ assert.equal(after.article, "articles/polemic-flips");
+ assert.deepEqual(after.timeline, manifest.timeline, "nothing else moves");
+ // The CLI's formatting (indent 2, trailing newline), so the diff is one line.
+ assert.match(await readFile(file, "utf8"), /\n {2}"article": "articles\/polemic-flips"\n\}\n$/);
+ // Snapshotted first.
+ assert.ok((await readdir(path.join(dir, "revisions"))).some((f) => f.includes("auto-before-link")));
+
+ const r2 = await updateArticleLink(dir, "articles/polemic-flips");
+ assert.equal(r2.changed, false);
+
+ await assert.rejects(updateArticleLink(dir, "polemic-flips"), /<site>\/<report>/);
+ await assert.rejects(updateArticleLink(dir, "articles/Polemic Flips"), /<site>\/<report>/);
+ await assert.rejects(updateArticleLink(dir, "../x/y"), /<site>\/<report>/);
+
+ const r3 = await updateArticleLink(dir, null);
+ assert.equal(r3.changed, true);
+ assert.equal(r3.was, "articles/polemic-flips");
+ assert.equal("article" in JSON.parse(await readFile(file, "utf8")), false);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -1301,6 +1301,46 @@ export async function updateStorage(dir, { deliverables } = {}, { token = null }
}
+/**
+ * The manifest's article link: a top-level `"article": "<site>/<report>"`
+ * (lib/articles/links.mjs, the second way -- the one a person or an agent
+ * chooses). It is what settles `link-ambiguous`: an article two projects share
+ * a slug with links to neither until one of them names it, and nothing wrote
+ * the key but a hand edit. The build never reads it.
+ *
+ * `null` (or "") removes it. Snapshotted first (`auto-before-link`); a no-op
+ * writes nothing.
+ *
+ * @param {string} dir
+ * @param {string | null} article `<site>/<report>`, e.g. `articles/polemic-flips`
+ * @param {{ token?: string | null }} [opts]
+ * @returns {Promise<{ article: string | null, was: string | null, token: string | null, changed: boolean, snapshot?: unknown }>}
+ */
+export async function updateArticleLink(dir, article, { token = null } = {}) {
+ const next = article == null || String(article).trim() === "" ? null : String(article).trim();
+ if (next !== null) {
+ const parts = next.split("/");
+ if (parts.length !== 2 || !parts.every((x) => ARTICLE_SEGMENT_RE.test(x))) {
+ throw new Error(`an article is <site>/<report> (e.g. articles/polemic-flips), not ${JSON.stringify(article)}`);
+ }
+ }
+ return withManifestLock(async () => {
+ const current = await manifestToken(dir);
+ if (token !== null && current !== token) throw new StaleToken(token, current);
+ const manifest = JSON.parse(await readFile(manifestFile(dir), "utf8"));
+ const was = typeof manifest.article === "string" ? manifest.article : null;
+ if (was === next) return { article: was, was, token: current, changed: false };
+ const snapshot = await autoSnapshot(dir, "link");
+ if (next === null) delete manifest.article;
+ else manifest.article = next;
+ const nextToken = await writeManifestAtomic(dir, manifest);
+ return { article: next, was, token: nextToken, changed: true, snapshot };
+ });
+}
+/** A site id or a report id: lib/paths.mjs SEGMENT_RE, which this file does not import. */
+const ARTICLE_SEGMENT_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
+
+
// ---------------------------------------------------------------------------
// STRUCTURE: re-ordering the cut, and the edits that add or remove a thing.
//