commit 88d1a7a71c5b48b192382edbe29d2d67eef785c9
parent e7b6125ecbba475cdf6fabf0a97e372f58e4f817
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 12 Nov 2026 20:52:30 -0500
umtool: timeline add-analysis / set-analysis -- the analysis item's CLI twin, on the draft and on a take
`umtool timeline <p> [--take <t>] add-analysis <json|@file> [--id] [--after]
[--dry-run] [--json]` and `set-analysis <id> <json|@file>`: the item into the
cut or the take's timeline only, checked against the ledger as the build
checks it, each write an undo point (the draft's revisions, the take's own);
--dry-run prints every figure with its row. The structural writers refuse an
edit that breaks an analysis item (its audio clip removed from under it).
The CLI table rows; docs/cli.md regenerated.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
9 files changed, 308 insertions(+), 1 deletion(-)
diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md
@@ -117,6 +117,7 @@ Inbox cannot disagree about what is wrong with one.
| `timeline <project> sections [--json]` · `section-move <id>… --to-section N [--start]` · `section-add --after <id> [--label L] [--color C]` · `section-boundary <marker> --after <id>` · `section-remove <marker>` · `section-set <marker> [--label L] [--color C]` · `split <id> <second>` · `flash-forward <id> <from>-<to> (--after <id\|-> \| --to-section N [--start]) [--move] [--quote Q] [--id ID]` | **sections as sections** (the deck's markers; the Cut tab's section bars and row menus): clips moved to a section with every marker following, a section opened, a boundary moved, relabelled, removed — no section emptied, no boundary crossed (**exit 1**) — and every take patch in step synced; **split** (each half's quote from the words, the second half's cite and QR at its second, a marker after the clip following its second half); **flash-forward** a tight copy of a span elsewhere with the clip's attribution and locks, as `repeatOf` the clip (`--move`: out of the clip) ([knobs.md](knobs.md#sections-split-and-flash-forward-editing-the-cut)) |
| `timeline <project> threads [--json]` · `timeline <project> threads --write [--conversation <id>]` | **the cut's conversations** ([report-video.md](report-video.md#thread-reads), `post-conversation.mjs`): each tree of two post items or more — its root, its items' places, whether they play as one run (one scene) or are split by other entries, a reply placed before the post it answers, an item re-reading a post its run already read (with `posts set-item <p> <item> thread.parent.<i>=context`). `--write` gathers each (or the one holding `<id>`: its root, a post, an item, a `thread.group` name) at its first item's place in TREE order (a manual thread: in DATE order) — a post after what it answers, sibling branches by date, each depth first — in ONE write (one undo point); never across a section boundary (gathered within each section, and said) |
| `timeline <project> [--take <t>] add-video <src> [--from S] [--to S] [--fit contain\|cover] [--bass dB] [--gain dB] [--enter cut\|<out>,<in>] [--hold S] [--title T] [--id ID] [--after <id>\|-] [--dry-run] [--json]` · `timeline <project> [--take <t>] set-video <id> <key>=<value>…` | **a video entry** ([report-video.md](report-video.md#a-video-entry)): a file of the project (`src`, relative; probed, its `fileSeconds` written) played FULL FRAME with its own sound, nothing drawn over it, at the end unless `--after` (`-`: the start), into the cut or the take's timeline only (`--take`, an undo point of the take's); `set-video` sets `from= to= fit= audio.bass= audio.gain= enter=cut\|<out>,<in> enter.out= enter.in= holdLast= deck=hidden\|shown title= note= src=` (`key=` clears). `--dry-run`: the entry and its place, nothing written. `--json`: `{ok, op, take?, inserted\|updated {id, at, entry}, revision?}`. **Exit 0 · 1 refused (no such file, take or entry; the build would not take it) · 2 usage** |
+| `timeline <project> [--take <t>] add-analysis <json\|@file> [--id ID] [--after <id>\|-] [--dry-run] [--json]` · `timeline <project> [--take <t>] set-analysis <id> <json\|@file> [--dry-run] [--json]` | **an analysis item** ([report-video.md](report-video.md#the-analysis-item)): an ending drawn from the LEDGER, full frame -- a chart of a named run of his weights (`series`: `{rows}` or `{from, to}`; a delta against the run's start), a `band`, `marks`, a `pace` table (pounds and days computed; a row ending on a bound says over/under), `status`, ONE `reading`, a `footnote`; `audio: {clip, start, end}` plays that clip's sound under it (its citation and QR drawn, its picture not), else silent for `seconds` (7, at most 8). Into the cut or the take's timeline only (`--take`, an undo point of the take's), at the end unless `--after` (`-`: the start); refused for a row the ledger lacks and everything the lint refuses (**exit 1**). `set-analysis` replaces the keys given (`null` removes one). `--dry-run`: every figure with its row, nothing written. `--json`: `{ok, op, take?, inserted\|updated, warnings, figures, revision?}` |
| `timeline <project> insert (--after <id\|-> \| --to-section N \| --group G) post:<channel>/<postId> [--id ID]` | **one post item** among the cut's entries, made as `posts reel` makes one |
| `timeline <project> insert (--after <id\|-> \| --to-section N \| --group G) post-json:<json>\|post-json:@<file> [--id ID]` | **a post item made by hand** — a post no archive holds (one kept only as a picture): `{post: "<channel>/<postId>", author, handle, date, text, media: ["posts-media/…"], parents?, quoted?, subjects?, redact?}`, its media measured, its id `p-<postId>` unless `--id`; refused in the build's words (**exit 1**). Its avatar: `posts avatar <project> <handle> <file>` |
| `scenes <project> <clip> [--black-min 0.05] [--threshold 8] [--pix-th 0.10] [--pad 30 \| --from S --to S] [--json]` | the picture's **scene cuts** (ffmpeg `scdet`, score ≥ threshold) and **black spans** (`blackdetect`) in the clip's fetched window, in SOURCE seconds — for `blur.from`/`blur.to` and trims ([knobs.md](knobs.md#a-clips-picture-blurred)). The window is the one the build would cut from (the project's `out/clips-raw`, the editor's `channels/<slug>/data/<id>/clips/`, a saved source); the extent ± `--pad` inside it is scanned. Nothing is fetched: **exit 1** with no window on disk (`fetch` first) |
@@ -357,6 +358,8 @@ draft (the project's manifest); *project*: a project's other files, or reads; *c
| `timeline <project> groups promote <gid> [--label LABEL]` | a group opens a subsection | form · *draft* |
| `timeline <project> add-video <src> [--from N] [--to N] [--fit contain\|cover] [--bass N] [--gain N] [--enter ENTER] [--hold N] [--title TITLE] [--id ID] [--after AFTER] [--dry-run] [--take TAKE]` | a video entry: a project file full frame | form · *draft* |
| `timeline <project> set-video <id> key=value… [--take TAKE]` | a video entry's knobs | form · *draft* |
+| `timeline <project> add-analysis <item> [--id ID] [--after AFTER] [--dry-run] [--take TAKE]` | an analysis item: an ending drawn from the ledger | form · *draft* |
+| `timeline <project> set-analysis <id> <patch> [--dry-run] [--take TAKE]` | an analysis item's keys (null removes one) | form · *draft* |
| `scenes <project> <clip> [--black-min N] [--threshold N] [--pix-th N] [--pad N] [--from N] [--to N]` | scene cuts and black spans in a clip's fetched window | form · *project* |
| `posts add <project> <post> [--attach ATTACH] [--flag FLAG] [--author AUTHOR] [--id ID] [--thread] [--crop N] [--dry-run]` | a post card from the posts archive | form · *draft* |
| `posts set <project> <post> key=value…` | the Posts table's writer: thread, hide, attach, crop | form · *draft* |
diff --git a/umtool/lib/cli/groups.mjs b/umtool/lib/cli/groups.mjs
@@ -963,6 +963,8 @@ export const GROUPS = [
"**the cut's conversations** ([report-video.md](report-video.md#thread-reads), `post-conversation.mjs`): each tree of two post items or more — its root, its items' places, whether they play as one run (one scene) or are split by other entries, a reply placed before the post it answers, an item re-reading a post its run already read (with `posts set-item <p> <item> thread.parent.<i>=context`). `--write` gathers each (or the one holding `<id>`: its root, a post, an item, a `thread.group` name) at its first item's place in TREE order (a manual thread: in DATE order) — a post after what it answers, sibling branches by date, each depth first — in ONE write (one undo point); never across a section boundary (gathered within each section, and said)"],
["`timeline <project> [--take <t>] add-video <src> [--from S] [--to S] [--fit contain\\|cover] [--bass dB] [--gain dB] [--enter cut\\|<out>,<in>] [--hold S] [--title T] [--id ID] [--after <id>\\|-] [--dry-run] [--json]` · `timeline <project> [--take <t>] set-video <id> <key>=<value>…`",
"**a video entry** ([report-video.md](report-video.md#a-video-entry)): a file of the project (`src`, relative; probed, its `fileSeconds` written) played FULL FRAME with its own sound, nothing drawn over it, at the end unless `--after` (`-`: the start), into the cut or the take's timeline only (`--take`, an undo point of the take's); `set-video` sets `from= to= fit= audio.bass= audio.gain= enter=cut\\|<out>,<in> enter.out= enter.in= holdLast= deck=hidden\\|shown title= note= src=` (`key=` clears). `--dry-run`: the entry and its place, nothing written. `--json`: `{ok, op, take?, inserted\\|updated {id, at, entry}, revision?}`. **Exit 0 · 1 refused (no such file, take or entry; the build would not take it) · 2 usage**"],
+ ["`timeline <project> [--take <t>] add-analysis <json\\|@file> [--id ID] [--after <id>\\|-] [--dry-run] [--json]` · `timeline <project> [--take <t>] set-analysis <id> <json\\|@file> [--dry-run] [--json]`",
+ "**an analysis item** ([report-video.md](report-video.md#the-analysis-item)): an ending drawn from the LEDGER, full frame -- a chart of a named run of his weights (`series`: `{rows}` or `{from, to}`; a delta against the run's start), a `band`, `marks`, a `pace` table (pounds and days computed; a row ending on a bound says over/under), `status`, ONE `reading`, a `footnote`; `audio: {clip, start, end}` plays that clip's sound under it (its citation and QR drawn, its picture not), else silent for `seconds` (7, at most 8). Into the cut or the take's timeline only (`--take`, an undo point of the take's), at the end unless `--after` (`-`: the start); refused for a row the ledger lacks and everything the lint refuses (**exit 1**). `set-analysis` replaces the keys given (`null` removes one). `--dry-run`: every figure with its row, nothing written. `--json`: `{ok, op, take?, inserted\\|updated, warnings, figures, revision?}`"],
["`timeline <project> insert (--after <id\\|-> \\| --to-section N \\| --group G) post:<channel>/<postId> [--id ID]`",
"**one post item** among the cut's entries, made as `posts reel` makes one"],
["`timeline <project> insert (--after <id\\|-> \\| --to-section N \\| --group G) post-json:<json>\\|post-json:@<file> [--id ID]`",
diff --git a/umtool/lib/cli/verbs.mjs b/umtool/lib/cli/verbs.mjs
@@ -478,6 +478,10 @@ function timeline() {
num("--hold"), opt("--title"), opt("--id"), opt("--after"), dry(), takeOpt(),
]),
tl("set-video", "draft", "a video entry's knobs", [id(), pairs({ help: "from= to= fit= audio.gain= …, one per line" }), takeOpt()], B(["video"], { id: "{id}" })),
+ tl("add-analysis", "draft", "an analysis item: an ending drawn from the ledger", [
+ arg("item", { type: "text", atFile: true, help: "the item as JSON (@file: from a terminal)" }), opt("--id"), opt("--after"), dry(), takeOpt(),
+ ]),
+ tl("set-analysis", "draft", "an analysis item's keys (null removes one)", [id(), arg("patch", { type: "text", atFile: true, help: "a JSON patch (@file: from a terminal)" }), dry(), takeOpt()]),
];
}
diff --git a/umtool/lib/report/analysisCli.test.mjs b/umtool/lib/report/analysisCli.test.mjs
@@ -0,0 +1,136 @@
+// `umtool timeline <p> [--take <t>] add-analysis | set-analysis` (timelineCli.mjs analysisVerb): an analysis item into
+// the draft or a take's timeline only, checked against the ledger as the build checks it, every write an undo point;
+// --dry-run prints every figure with its row and writes nothing.
+//
+// Run with: node --test lib/report/analysisCli.test.mjs
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import test from "node:test";
+
+import { draftTake } from "./takeMaker.mjs";
+import { resolveTakeManifest } from "./takeManifest.mjs";
+import { timelineCommand } from "./timelineCli.mjs";
+
+const W = (id, population, date, value, extra = {}) => ({ id, scope: "weight", population, date, value, ...extra });
+const MANIFEST = {
+ schemaVersion: 1,
+ slug: "fixture",
+ title: "Fixture",
+ render: { width: 640, height: 360, fps: 15, transition: 0 },
+ ledgerSchema: {
+ kind: "measure", unit: "lb", bandGapDays: 60, tracks: [{ key: "weight", role: "value", label: "Weight" }],
+ fields: [{ key: "qualifier", label: "Bound", kind: "enum", options: [">", "<", "≈"], render: "cell" }],
+ },
+ ledger: [
+ W("w83", "delta", "2026-07-23", -5),
+ W("w91", "past", "2026-08-03", 349, { asOf: "2026-07-19" }),
+ W("w104", "delta", "2026-09-04", -31.5),
+ W("w110", "current", "2026-09-24", 310.5),
+ W("w115", "current", "2026-10-15", 300, { qualifier: "<" }),
+ W("w118", "current", "2026-10-26", 291.5, { asOf: "2026-10-23" }),
+ ],
+ timeline: [
+ { type: "clip", id: "c01", channel: "chan", video: "vid", start: 100, end: 160, cite: 100 },
+ { type: "clip", id: "c02", channel: "chan", video: "vid", start: 200, end: 260, cite: 200 },
+ ],
+};
+const ITEM = {
+ title: "What his numbers say", kicker: "THE RUN",
+ series: { rows: ["w91", "w104", "w110", "w115", "w118"] },
+ pace: [{ from: "w110", to: "w115" }, { from: "w115", to: "w118" }],
+ reading: "The loss is steady.",
+};
+
+async function project() {
+ const root = await mkdtemp(path.join(tmpdir(), "analysis-cli-"));
+ const reportsRoot = path.join(root, "reports");
+ const dir = path.join(reportsRoot, "proj");
+ await mkdir(dir, { recursive: true });
+ await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(MANIFEST, null, 2) + "\n");
+ await writeFile(path.join(root, "item.json"), JSON.stringify(ITEM));
+ const out = [];
+ const err = [];
+ const run = (...args) => timelineCommand(args, { root: reportsRoot, out: (s) => out.push(s), err: (s) => err.push(s) });
+ return { root, dir, run, out, err, file: `@${path.join(root, "item.json")}` };
+}
+const manifestOf = async (dir) => JSON.parse(await readFile(path.join(dir, "video.manifest.json"), "utf8"));
+
+test("add-analysis --dry-run prints every figure with its row and writes nothing", async () => {
+ const p = await project();
+ try {
+ const before = await readFile(path.join(p.dir, "video.manifest.json"), "utf8");
+ assert.equal(await p.run("proj", "add-analysis", p.file, "--after", "c01", "--dry-run"), 0, p.err.join("\n"));
+ const text = p.out.join("\n");
+ assert.match(text, /would add analysis analysis at 1 \(after c01\) in proj:/);
+ assert.match(text, /point w104: 317\.5 on 2026-09-04 \(-31\.5 from w91 349\)/);
+ assert.match(text, /pace\[0\] 24 Sep → 15 Oct: over −10\.5 lb \(w110 310\.5 → w115 300\), 21 days -- a bound: w115/);
+ assert.match(text, /pace\[1\] 15 → 23 Oct: under −8\.5 lb/);
+ assert.match(text, /warning: .*pace\[0\] ends on a bound/);
+ assert.equal(await readFile(path.join(p.dir, "video.manifest.json"), "utf8"), before);
+ } finally {
+ await rm(p.root, { recursive: true, force: true });
+ }
+});
+
+test("add-analysis and set-analysis on the draft: written, an undo point each, refused for a row the ledger lacks", async () => {
+ const p = await project();
+ try {
+ assert.equal(await p.run("proj", "add-analysis", p.file, "--id", "end", "--json"), 0, p.err.join("\n"));
+ const j = JSON.parse(p.out.join("\n"));
+ assert.equal(j.inserted.id, "end");
+ assert.equal(j.inserted.at, 2);
+ let m = await manifestOf(p.dir);
+ assert.deepEqual(m.timeline.map((e) => e.id), ["c01", "c02", "end"]);
+ assert.equal(m.timeline[2].type, "analysis");
+ const snaps = await readdir(path.join(p.dir, "revisions")).catch(() => []);
+ assert.ok(snaps.some((f) => /auto-before-insert/.test(f)), snaps.join(", "));
+
+ p.out.length = 0;
+ assert.equal(await p.run("proj", "set-analysis", "end", JSON.stringify({ footnote: "His own words.", kicker: null })), 0, p.err.join("\n"));
+ assert.match(p.out.join("\n"), /set analysis end at 2 in proj/);
+ m = await manifestOf(p.dir);
+ assert.equal(m.timeline[2].footnote, "His own words.");
+ assert.equal("kicker" in m.timeline[2], false);
+ assert.ok((await readdir(path.join(p.dir, "revisions"))).some((f) => /auto-before-analysis/.test(f)));
+
+ p.err.length = 0;
+ assert.equal(await p.run("proj", "set-analysis", "end", JSON.stringify({ series: { rows: ["w91", "w999"] } })), 1);
+ assert.match(p.err.join("\n"), /series row w999 is not in the ledger/);
+ assert.equal(await p.run("proj", "set-analysis", "c01", "{}"), 1);
+ assert.equal(await p.run("proj", "add-analysis", JSON.stringify({ ...ITEM, seconds: 12 }), "--id", "x"), 1);
+ assert.match(p.err.join("\n"), /held 12 s with no audio/);
+ // The item's audio clip cannot be taken out from under it.
+ p.err.length = 0;
+ assert.equal(await p.run("proj", "set-analysis", "end", JSON.stringify({ audio: { clip: "c02", start: 210, end: 224 } })), 0, p.err.join("\n"));
+ assert.equal(await p.run("proj", "remove", "c02"), 1);
+ assert.match(p.err.join("\n"), /audio\.clip c02 is not an entry of the cut/);
+ } finally {
+ await rm(p.root, { recursive: true, force: true });
+ }
+});
+
+test("--take: into the take's timeline only, with the take's own undo point", async () => {
+ const p = await project();
+ try {
+ await draftTake(p.dir, { id: "tk", label: "Take", patch: {} });
+ const master = await readFile(path.join(p.dir, "video.manifest.json"), "utf8");
+ assert.equal(await p.run("proj", "--take", "tk", "add-analysis", p.file, "--after", "c01"), 0, p.err.join("\n"));
+ assert.match(p.out.join("\n"), /added analysis analysis at 1 in take tk of proj/);
+ assert.match(p.out.join("\n"), /undo point: takes\/tk\//);
+ assert.equal(await readFile(path.join(p.dir, "video.manifest.json"), "utf8"), master, "the draft is untouched");
+ let m = (await resolveTakeManifest(p.dir, "tk")).manifest;
+ assert.deepEqual(m.timeline.map((e) => e.id), ["c01", "analysis", "c02"]);
+ p.out.length = 0;
+ assert.equal(await p.run("proj", "--take", "tk", "set-analysis", "analysis", JSON.stringify({ reading: "Steady, then a stall." })), 0, p.err.join("\n"));
+ m = (await resolveTakeManifest(p.dir, "tk")).manifest;
+ assert.equal(m.timeline[1].reading, "Steady, then a stall.");
+ assert.equal(await p.run("proj", "--take", "tk", "undo"), 0, p.err.join("\n"));
+ m = (await resolveTakeManifest(p.dir, "tk")).manifest;
+ assert.equal(m.timeline[1].reading, "The loss is steady.");
+ assert.equal(await readFile(path.join(p.dir, "video.manifest.json"), "utf8"), master);
+ } finally {
+ await rm(p.root, { recursive: true, force: true });
+ }
+});
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -42,6 +42,7 @@ import { LOOK_KEYS, applyLookPatch, basicOn, lookOf } from "yt-dlp-transcript-co
import { sideErrors } from "yt-dlp-transcript-common/lib/report/vertical.mjs";
import { validateRoom } from "umtool-report-to-video/room";
import { applyVideoPatch, validateVideoEntries, validateVideoEntry } from "umtool-report-to-video/video-entry";
+import { analysisContext, analysisProblems, applyAnalysisPatch, validateAnalysisEntries } from "umtool-report-to-video/analysis-plan";
import { applySectionEnter } from "./sections.mjs";
import { citeUrlAt, parseClipSpec } from "./clipEditorModel.mjs";
import { addSectionIn, followSplitMarkers, moveBoundaryIn, moveToSectionIn, placeIn, reanchorMarkers, removeBoundaryIn, sectionModel, sectionWords, setSectionIn } from "./sectionEdit.mjs";
@@ -2261,6 +2262,8 @@ function structureErrors(manifest) {
...validateTeasers(manifest),
// A video entry (video-entry.mjs): a file of the project played full frame.
...validateVideoEntries(manifest),
+ // An analysis item (analysis-plan.mjs): its rows in the ledger, its audio clip in the cut.
+ ...validateAnalysisEntries(manifest),
...validateNarration(manifest),
...validateDrafted(manifest),
...validatePublish(manifest),
@@ -4322,6 +4325,33 @@ export async function updateVideoEntry(dir, id, patch, { token = null, at = null
}
/**
+ * SET an analysis item's keys (analysis-plan.mjs applyAnalysisPatch: a key replaced, `null` removed), checked as the
+ * build checks it against the manifest's ledger and cut; one undo point.
+ *
+ * @param {string} dir
+ * @param {string} id
+ * @param {Record<string, unknown>} patch
+ * @param {{ token?: string | null, at?: number | null }} [opts]
+ */
+export async function updateAnalysisEntry(dir, id, patch, { token = null, at = null } = {}) {
+ if (!patch || typeof patch !== "object" || !Object.keys(patch).length) throw new Error("nothing to change");
+ return structural(dir, "analysis", token, (m) => setAnalysisIn(m, id, patch, at));
+}
+
+/** The analysis write's mutation, over a manifest (the draft's or a take's). */
+export function setAnalysisIn(m, id, patch, at = null) {
+ const i = entryIndex(m.timeline, id, at);
+ const e = m.timeline[i];
+ if (e.type !== "analysis") throw new Error(`${id} is a ${e.type ?? "non-analysis"} entry, not an analysis item`);
+ const next = applyAnalysisPatch(e, patch);
+ const probe = { ...m, timeline: m.timeline.map((x, k) => (k === i ? next : x)) };
+ const errors = analysisProblems(next, analysisContext(probe)).errors;
+ if (errors.length) throw new StructureRefused(errors);
+ m.timeline[i] = next;
+ return { id, at: i, entry: next };
+}
+
+/**
* Patch one teaser: its lines, beat, dip, tail and tail wait. A key given as
* null (or "") is removed; a key not given is kept. Checked with the build's
* validateTeaser (which checks the dip too) against the patched entry.
diff --git a/umtool/lib/report/takeEdit.mjs b/umtool/lib/report/takeEdit.mjs
@@ -46,6 +46,7 @@ import {
patchClipEntry,
removeIn,
replaceManifest,
+ setAnalysisIn,
} from "./manifest.mjs";
import { withEditNotes } from "./edit-guard.mjs";
import { benchPrepAfterWrite } from "./benchPrepTrigger.mjs";
@@ -408,6 +409,15 @@ export async function updateTakeVideoEntry(projectDir, id, entryId, patch, { tok
);
}
+/**
+ * SET an analysis item's keys in a TAKE's timeline (manifest.mjs setAnalysisIn), checked as the build checks it
+ * against the take's ledger and cut; an undo point of the take's.
+ */
+export async function updateTakeAnalysisEntry(projectDir, id, entryId, patch, { token = null, at = null, now = new Date() } = {}) {
+ if (!patch || typeof patch !== "object" || !Object.keys(patch).length) throw new Error("nothing to change");
+ return editTakeTimeline(projectDir, id, "analysis", token, (m) => applyStructural(m, (x) => setAnalysisIn(x, entryId, patch, at)), { now });
+}
+
/** A take's label: one line, at most this long. */
export const TAKE_LABEL_MAX = 200;
diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs
@@ -18,6 +18,7 @@
// umtool timeline <project> remove <id> | duplicate <id>
// umtool timeline <project> post <json|@file> | post-remove <id>
// umtool timeline <project> teaser <id> <patch-json|@file>
+// umtool timeline <project> [--take <t>] add-analysis <json|@file> | set-analysis <id> <json|@file>
// umtool timeline <project> undo
// umtool timeline <project> sections | section-move <id…> --to-section N [--start]
// | section-add --after <id> [--label L] [--color C] | section-boundary <k> --after <id>
@@ -93,6 +94,7 @@ import {
redoStructural,
updateClip,
updateTeaser,
+ updateAnalysisEntry,
updateVideoEntry,
upsertPost,
} from "./manifest.mjs";
@@ -192,6 +194,14 @@ export const TIMELINE_USAGE = [
" at the end unless --after (`-`: the start); --from/--to source seconds (no --to: the file's end)",
" umtool timeline <project> [--take <t>] set-video <id> <key>=<value>… from= to= fit= audio.bass= audio.gain=",
" enter=cut|<out>,<in> enter.out= enter.in= holdLast= deck=hidden|shown title= note= src= (`key=` clears)",
+ " umtool timeline <project> [--take <t>] add-analysis <json|@file> [--id ID] [--after <id>|-] [--dry-run] [--json]",
+ " an ANALYSIS ITEM: an ending drawn from the ledger -- a chart of a named run of his weights",
+ " (series: {rows} or {from, to}), band, marks, pace, status, ONE reading, footnote, mark, audio",
+ " ({clip, start, end}: that clip's sound under it) or seconds (silent, at most 8); every figure",
+ " computed from its ledger row; at the end unless --after (`-`: the start); --dry-run prints",
+ " every figure with its row, nothing written",
+ " umtool timeline <project> [--take <t>] set-analysis <id> <json|@file> [--dry-run] [--json]",
+ " its keys replaced (null removes one), checked again against the ledger; an undo point",
" umtool timeline <project> --take <id> [ls | move <id> --to <index> | remove <id> | undo | insert <spec> --after <id>|-]",
" a take's timeline (walk a take): written into the take's patch (takes/<id>/take.json),",
" each write with an undo point of the take's own; the project's manifest is untouched",
@@ -201,7 +211,7 @@ export const TIMELINE_USAGE = [
].join("\n");
const SECTION_VERBS = ["sections", "section-move", "section-add", "section-boundary", "section-remove", "section-set"];
-const VERBS = ["ls", "insert", "add-video", "set-video", "move", "place", "remove", "reject", "wrong-speaker", "removed", "restore", "import-item", "duplicate", "post", "post-remove", "teaser", "undo", "redo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"];
+const VERBS = ["ls", "insert", "add-video", "set-video", "add-analysis", "set-analysis", "move", "place", "remove", "reject", "wrong-speaker", "removed", "restore", "import-item", "duplicate", "post", "post-remove", "teaser", "undo", "redo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"];
const GROUP_VERBS = ["ls", "import", "set", "move", "label", "promote", "remove"];
const VALUED = new Set(["--as", "--group", "--after", "--before", "--to", "--at", "--id", "--section", "--title", "--stream-title", "--date", "--quote", "--cite", "--cite-url", "--take", "--correction", "--note", "--to-section", "--label", "--color", "--level", "--claim", "--conversation", "--from", "--fit", "--bass", "--gain", "--enter", "--hold"]);
/** What `--take <id>` does on a take's timeline (takeEdit.mjs): the walk's structure and its undo. */
@@ -569,6 +579,8 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) =>
const project = await projectOf(projectArg, root);
// A video entry (video-entry.mjs), into the cut or a take's timeline.
if (verb === "add-video" || verb === "set-video") return await videoVerb(project, verb, rest, flags, { out, json });
+ // An analysis item (analysis-plan.mjs), into the cut or a take's timeline.
+ if (verb === "add-analysis" || verb === "set-analysis") return await analysisVerb(project, verb, rest, flags, { out, json });
if (flags.has("--take")) {
// `ls` only reads; a write into a take's patch is the deprecated path (L3 S6).
if (verb !== "ls") err((await import("./takeDeprecation.mjs")).takeEditDeprecation(`timeline ${verb} --take`, { project: project.id, take: String(flags.get("--take")) }));
@@ -1095,6 +1107,100 @@ async function probeSeconds(file) {
}
/**
+ * `umtool timeline <p> [--take <t>] add-analysis <json|@file> …` and `set-analysis <id> <json|@file>`: an ANALYSIS
+ * ITEM (analysis-plan.mjs) put into the cut -- or the take's timeline only -- checked against the cut's ledger as the
+ * build checks it, each write an undo point. `--dry-run`: the entry, its place and every figure it draws with its row,
+ * nothing written. Exit 0 · 1 refused (no such take or entry; a row the ledger lacks, …) · 2 usage.
+ */
+async function analysisVerb(project, verb, rest, flags, { out, json }) {
+ const A = await import("umtool-report-to-video/analysis-plan");
+ const take = flags.has("--take") ? String(flags.get("--take")) : null;
+ const dry = flags.has("--dry-run");
+ const edit = take ? await import("./takeEdit.mjs") : null;
+ let manifest;
+ if (take) {
+ const { resolveTakeManifest } = await import("./takeManifest.mjs");
+ manifest = (await resolveTakeManifest(project.dir, take)).manifest;
+ } else {
+ manifest = await readManifest(project.dir);
+ if (!manifest) throw new CliError(`${project.id} has no manifest`);
+ }
+ const timeline = manifest.timeline ?? [];
+ const where = take ? `take ${take} of ${project.id}` : project.id;
+ // The item checked as the build checks it, in the cut as it will be: its errors refuse, its warnings are said.
+ const judge = (entry, tl) => {
+ const ctx = A.analysisContext({ ...manifest, timeline: tl });
+ const { errors, warnings } = A.analysisProblems(entry, ctx);
+ if (errors.length) throw new Error(errors.join("; "));
+ return { warnings, figures: A.analysisFigures(A.analysisPlan(entry, ctx)) };
+ };
+ let entry;
+ let at;
+ let after = null;
+ let judged;
+ if (verb === "add-analysis") {
+ const raw = await jsonArg(rest[0], "add-analysis");
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new CliError("add-analysis takes the item as a JSON object (or @file)");
+ if (raw.type !== undefined && raw.type !== "analysis") throw new CliError(`add-analysis adds an analysis item, not a ${raw.type}`);
+ const { type: _t, id: rawId, ...keys } = raw;
+ void _t;
+ const id = flags.has("--id") ? String(flags.get("--id")) : typeof rawId === "string" && rawId ? rawId : "analysis";
+ if (timeline.some((e) => e?.id === id)) throw new CliError(`${id} is already in ${where} (--id another, or set-analysis ${id})`);
+ entry = { type: "analysis", id, ...keys };
+ const afterArg = flags.has("--after") ? String(flags.get("--after")) : null;
+ after = afterArg === null ? (timeline.length ? timeline[timeline.length - 1].id : null) : afterArg === "-" || afterArg === "" ? null : afterArg;
+ if (after && !timeline.some((e) => e?.id === after)) throw new Error(`no entry ${after} in ${where}`);
+ at = after ? timeline.findIndex((e) => e?.id === after) + 1 : 0;
+ judged = judge(entry, [...timeline.slice(0, at), entry, ...timeline.slice(at)]);
+ } else {
+ const id = rest[0];
+ if (!id) throw new CliError("set-analysis needs the analysis item's id, then its keys as JSON (or @file)");
+ const patch = await jsonArg(rest[1], "set-analysis");
+ at = timeline.findIndex((e) => e?.id === id);
+ if (at < 0) throw new Error(`no entry ${id} in ${where}`);
+ if (timeline[at].type !== "analysis") throw new Error(`${id} is a ${timeline[at].type ?? "non-analysis"} entry, not an analysis item`);
+ try {
+ entry = A.applyAnalysisPatch(timeline[at], patch);
+ } catch (e) {
+ throw new CliError(e instanceof Error ? e.message : String(e));
+ }
+ judged = judge(entry, timeline.map((e, k) => (k === at ? entry : e)));
+ if (!dry) {
+ const r = take
+ ? await edit.updateTakeAnalysisEntry(project.dir, take, id, patch, { token: await edit.takeToken(project.dir, take) })
+ : await withEditNotes(project, async () => updateAnalysisEntry(project.dir, id, patch, { token: await manifestToken(project.dir) }));
+ return analysisDone(r, { verb, take, where, judged, out, json, project });
+ }
+ }
+ if (dry) {
+ if (json) out(JSON.stringify({ ok: true, op: verb, dryRun: true, ...(take ? { take } : {}), at, ...(verb === "add-analysis" ? { after } : {}), entry, ...judged }, null, 2));
+ else {
+ out(`would ${verb === "add-analysis" ? `add analysis ${entry.id} at ${at}${after ? ` (after ${after})` : " (the start)"}` : `set ${entry.id}`} in ${where}:`);
+ for (const f of judged.figures) out(` ${f}`);
+ for (const w of judged.warnings) out(`warning: ${w}`);
+ }
+ return 0;
+ }
+ const r = take
+ ? await edit.insertTakeEntry(project.dir, take, after, entry, { token: await edit.takeToken(project.dir, take) })
+ : await withEditNotes(project, async () => insertEntry(project.dir, after, entry, { token: await manifestToken(project.dir) }));
+ return analysisDone(r, { verb, take, where, judged, out, json, project });
+}
+
+function analysisDone(result, { verb, take, where, judged, out, json, project }) {
+ const r = result?.result ?? result;
+ if (json) {
+ out(JSON.stringify({ ok: true, op: verb, ...(take ? { take } : {}), [verb === "add-analysis" ? "inserted" : "updated"]: { id: r.id, at: r.at, entry: r.entry },
+ warnings: judged.warnings, figures: judged.figures, ...(result?.revision ? { revision: result.revision.rel } : {}) }, null, 2));
+ return 0;
+ }
+ out(`${verb === "add-analysis" ? "added analysis" : "set analysis"} ${r.id} at ${r.at} in ${where}`);
+ for (const w of judged.warnings) out(`warning: ${w}`);
+ if (take && result?.revision) out(` undo point: takes/${take}/${result.revision.rel} (umtool timeline ${project.id} --take ${take} undo)`);
+ return 0;
+}
+
+/**
* `umtool timeline <p> [--take <t>] add-video <src> …` and `set-video <id> k=v…`: a VIDEO ENTRY
* (video-entry.mjs) put into the cut -- or the take's timeline only -- through the timeline's writers,
* checked as the build checks it. `--dry-run`: the entry and where it goes, nothing written.
diff --git a/umtool/report-to-video/analysis-plan.mjs b/umtool/report-to-video/analysis-plan.mjs
@@ -99,6 +99,21 @@ export function analysisWarnings(manifest, { only = null } = {}) {
}
/**
+ * An analysis entry with `patch` laid over it, key by key: a key given replaces the entry's, `null` removes it, a key
+ * not given is kept. Its `type` and `id` are not a patch's to change. Throws a sentence for a patch that is not an object.
+ */
+export function applyAnalysisPatch(entry, patch) {
+ if (!isObj(patch)) throw new Error("an analysis patch is a JSON object of the entry's keys");
+ for (const k of ["type", "id"]) if (k in patch && patch[k] !== entry?.[k]) throw new Error(`an analysis patch does not change its ${k}`);
+ const next = JSON.parse(JSON.stringify(entry));
+ for (const [k, v] of Object.entries(patch)) {
+ if (v === null) delete next[k];
+ else next[k] = JSON.parse(JSON.stringify(v));
+ }
+ return next;
+}
+
+/**
* The bound a pace row's figure is, from its two ends' qualifiers: the true change against the computed one. Ending
* on "< v" (the weight was under v) the change is LESS than computed (more lost); starting on it, MORE (less lost);
* ">" the other way. Both ends bounding opposite ways: no bound can be said ("unknown"). Null: exact.
diff --git a/umtool/report-to-video/package.json b/umtool/report-to-video/package.json
@@ -19,6 +19,7 @@
"exports": {
"./attribution": "./attribution.mjs",
"./video-entry": "./video-entry.mjs",
+ "./analysis-plan": "./analysis-plan.mjs",
"./site-links": "./site-links.mjs",
"./brand": "./brand.mjs",
"./brand-ids": "./brand-ids.mjs",