Archilyzer · Source

archilyzer

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

commit 4873cf822c6576d24514942b01d2b86a3118f2e6
parent b815491b6c7004ca1e16eed635f30f41609fe2f0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  9 Nov 2026 23:47:20 -0500

umtool: Add items from another project imports into the DRAFT -- the Cut tab's, `umtool timeline <p> import-item` (L3 S6)

L3 left TakeTools' "Add items from another project" writing a take's patch, the one UI edit that still did.
Every edit lands in the draft now, so it moves to the Cut tab's Options and imports into the project's own cut:
importDraftItems (takeImport.mjs) is importTakeItems with no take -- the same clone (card, context, knobs,
narration with its takes and pick), the same files hard-linked in (imports/<src>/ when another file has the
path), the same placement and "again: updated / unchanged" -- written through the draft's structural writer
(manifest.mjs editDraftStructure: the lock, the build's checks, an undo point of the project's), tried on a copy
first so an unchanged import writes nothing.

- CLI twin: `umtool timeline <p> import-item <src>:<item>[,…] [--after|--before <id>] [--as <id>] [--dry-run]
  [--json]`; registry row, help, cli.md regenerated, knobs.md rows.
- POST /api/report/takes/tools {op: "import"} with no take runs it; with a take, the old take-patch path.
- Take cards drop the control (TakeTools' `editable` prop goes with it); the button says "Import into the draft".

Tests: takeScope.test.mjs (dry run, two items after p-1 hard-linked, again unchanged with no write, before p-1
moved, refusals); take-items.spec through the Cut tab (Preview writes nothing, Import adds p-2 to the draft, the
source untouched, no import on a take card).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/app/api/report/takes/tools/route.ts | 16+++++++++++++---
Mumtool/components/projects/TakeTools.tsx | 33++++++++++++++++++---------------
Mumtool/components/projects/TakesBench.tsx | 2+-
Mumtool/components/projects/report/CutTab.tsx | 4+++-
Mumtool/docs/cli.md | 3++-
Mumtool/docs/knobs.md | 8+++++---
Mumtool/e2e/take-items.spec.ts | 23+++++++++++++++++++++++
Mumtool/lib/cli/groups.mjs | 2+-
Mumtool/lib/cli/verbs.mjs | 3+++
Mumtool/lib/report/manifest.mjs | 14++++++++++++++
Mumtool/lib/report/takeImport.mjs | 70++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Mumtool/lib/report/takeScope.test.mjs | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/timelineCli.mjs | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
13 files changed, 243 insertions(+), 45 deletions(-)

diff --git a/umtool/app/api/report/takes/tools/route.ts b/umtool/app/api/report/takes/tools/route.ts @@ -2,6 +2,7 @@ import { projectRef } from "@/lib/projects"; import { refuseCaller } from "@/lib/report/caller"; import { lintCommand } from "@/lib/report/lintCli.mjs"; import { takeCommand } from "@/lib/report/takeCli.mjs"; +import { timelineCommand } from "@/lib/report/timelineCli.mjs"; import { isTakeId, listTakes } from "@/lib/report/takes.mjs"; import { REPORTS_ROOT } from "@/lib/paths"; import { addStep } from "@/lib/queue/store.mjs"; @@ -18,9 +19,11 @@ export const dynamic = "force-dynamic"; // -> { exit, report: { ok, errors[], warnings[], entries } } // POST { project, take, op: "draft-from", id?, label? } umtool take <p> --id <id> --draft --from <take> --json // -> { exit, id, report } (id: the next free `<take>-d<n>` when none is given) -// POST { project, take, op: "import", refs: "<project>:<item>[,…]", after?, before?, dryRun? } -// umtool take <p> --id <take> --import-item … [--dry-run] --json -// -> { exit, report } +// POST { project, op: "import", refs: "<project>:<item>[,…]", after?, before?, dryRun? } +// umtool timeline <p> import-item … [--dry-run] --json: INTO +// -> { exit, report } THE DRAFT (the Cut tab's Add items from another project; L3: +// every edit lands in the draft). With `take`: the old take +// patch path, umtool take <p> --id <take> --import-item … // POST { project, op: "draft-new", label, group?, style?, patch?, window? } // umtool take <p> --id <slug of label> --label L --draft // -> { exit, id, report } [--group G] [--style S] [--patch-json P] [--full | --at A --dur D] @@ -87,6 +90,13 @@ export async function POST(request: Request) { kickQueue(); return Response.json({ exit: 0, queued: step.qid }, { headers: { "cache-control": "no-store" } }); } + if (body.op === "import" && !take) { + const refs = typeof body.refs === "string" ? body.refs.trim() : ""; + if (!refs) return Response.json({ error: "import needs <project>:<item>[,<item>…]" }, { status: 400 }); + const place = typeof body.after === "string" && body.after ? ["--after", body.after] : typeof body.before === "string" && body.before ? ["--before", body.before] : []; + const exit = await timelineCommand([project.id, "import-item", ...refs.split(/\s+/), ...place, ...(body.dryRun ? ["--dry-run"] : []), "--json"], { root: REPORTS_ROOT, out: io.log, err: io.err }); + return answer(exit); + } if (!take) return Response.json({ error: `${String(body.op)} needs a take` }, { status: 400 }); if (body.op === "draft-from") { let id = typeof body.id === "string" && body.id ? body.id : null; diff --git a/umtool/components/projects/TakeTools.tsx b/umtool/components/projects/TakeTools.tsx @@ -15,8 +15,9 @@ import PlayLink from "./PlayLink"; // // Check before render umtool lint <p> --take <t> // New draft from this take umtool take <p> --id <t>-d<n> --draft --from <t> -// Add items from another umtool take <p> --id <t> --import-item <src>:<a,b> [--after|--before <e>] -// project [--dry-run]: Preview shows the plan, Import does it +// Add items from another umtool timeline <p> import-item <src>:<a,b> [--after|--before <e>] +// project (the Cut tab) [--dry-run]: INTO THE DRAFT (L3: every edit lands there; E1, 9 Nov) -- +// Preview shows the plan, Import does it // --------------------------------------------------------------------------- type Tools = { exit: number; report: Record<string, unknown> | null; said?: string; id?: string; error?: string }; @@ -97,8 +98,8 @@ export function DraftFromButton({ project, take }: { project: string; take: stri type Entry = { id: string; type: string; words?: string }; -/** Add items from another project: cloned into this take only, their files hard-linked in; Preview first. */ -export function ImportItems({ project, take }: { project: string; take: string }) { +/** Add items from another project: cloned into the DRAFT, their files hard-linked in; Preview first. */ +export function ImportItems({ project }: { project: string }) { const router = useRouter(); const [open, setOpen] = useState(false); const [source, setSource] = useState(""); @@ -112,8 +113,8 @@ export function ImportItems({ project, take }: { project: string; take: string } const [done, setDone] = useState<Tools | null>(null); useEffect(() => { if (!open) return; - // The take's entries as Play reads them (its frozen manifest, or its patch over the draft): where an item lands. - void fetch(`/api/report/play-view?${new URLSearchParams({ project, take })}`, { cache: "no-store" }) + // The draft's entries as Play reads them: where an item lands. + void fetch(`/api/report/play-view?${new URLSearchParams({ project })}`, { cache: "no-store" }) .then((r) => r.json()) .then((j) => setEntries(Array.isArray(j.entries) ? (j.entries as { id: string; type: string; heading?: string }[]).map((e) => ({ id: e.id, type: e.type, words: e.heading })) : [])) .catch(() => {}); @@ -121,11 +122,11 @@ export function ImportItems({ project, take }: { project: string; take: string } .then((r) => r.json()) .then((j) => setProjects(((j.pieces ?? []) as { id: string; kind: string }[]).filter((p) => p.kind === "project" && p.id.startsWith("p:")).map((p) => p.id.slice(2)))) .catch(() => {}); - }, [open, project, take]); + }, [open, project]); const refs = items.trim() ? `${source.trim()}:${items.replace(/\s+/g, "")}` : ""; const run = async (dryRun: boolean) => { setBusy(true); - const r = await tool({ project, take, op: "import", refs, ...(where === "after" && anchor ? { after: anchor } : where === "before" && anchor ? { before: anchor } : {}), dryRun }); + const r = await tool({ project, op: "import", refs, ...(where === "after" && anchor ? { after: anchor } : where === "before" && anchor ? { before: anchor } : {}), dryRun }); setBusy(false); if (dryRun) { setPlan(r); @@ -139,14 +140,14 @@ export function ImportItems({ project, take }: { project: string; take: string } const input = "rounded-[3px] border border-seam-2 bg-ground px-1.5 py-[3px] text-[11.5px] text-text outline-none focus:border-signal"; const rows = (t: Tools | null) => ((t?.report as { items?: { id: string; action: string; at?: { index?: number; after?: string | null; before?: string | null } }[] } | null)?.items ?? []); return ( - <span className="inline-flex basis-full flex-col gap-1.5" data-take-import={take}> + <span className="inline-flex basis-full flex-col gap-1.5" data-take-import="draft"> <button type="button" data-action="import-open" aria-expanded={open} onClick={() => setOpen((o) => !o)} className={cn(buttonVariants({ variant: open ? "pressed" : "outline", size: "sm" }), "self-start")}> Add items from another project </button> {open && ( <span className="flex flex-wrap items-center gap-1.5 rounded border border-seam p-2 text-[11.5px]"> - <input data-import-source="" list={`import-projects-${take}`} value={source} onChange={(e) => setSource(e.target.value)} placeholder="project (e.g. emberparadox/mr-obvious-unhinged)" className={cn(input, "w-72 font-mono")} /> - <datalist id={`import-projects-${take}`}> + <input data-import-source="" list="import-projects-draft" value={source} onChange={(e) => setSource(e.target.value)} placeholder="project (e.g. emberparadox/mr-obvious-unhinged)" className={cn(input, "w-72 font-mono")} /> + <datalist id="import-projects-draft"> {projects.filter((p) => p !== project).map((p) => ( <option key={p} value={p} /> ))} @@ -172,7 +173,7 @@ export function ImportItems({ project, take }: { project: string; take: string } Preview </button> <button type="button" data-action="import-go" disabled={busy || !refs || !source.trim()} onClick={() => void run(false)} className={buttonVariants({ variant: "go", size: "sm" })}> - Import into {take} + Import into the draft </button> </span> )} @@ -221,14 +222,16 @@ export function CheckJoinsButton({ project, take }: { project: string; take: str ); } -/** The take's tools, as a take card's or a take walk's row. */ -export default function TakeTools({ project, take, editable = true, rendered = false }: { project: string; take: string; editable?: boolean; rendered?: boolean }) { +/** + * The take's tools, as a take card's row. Add items from another project is the draft's now (the Cut tab): + * a take is not edited in place (L3). + */ +export default function TakeTools({ project, take, rendered = false }: { project: string; take: string; rendered?: boolean }) { return ( <span className="flex flex-wrap items-start gap-1.5" data-take-tools={take}> <LintButton project={project} take={take} /> {rendered && <CheckJoinsButton project={project} take={take} />} <DraftFromButton project={project} take={take} /> - {editable && <ImportItems project={project} take={take} />} </span> ); } diff --git a/umtool/components/projects/TakesBench.tsx b/umtool/components/projects/TakesBench.tsx @@ -902,7 +902,7 @@ function TakeCard({ </button> )} </div> - <TakeTools project={project} take={t.id} editable={walkable} rendered={!!t.builtAt && !t.draft} /> + <TakeTools project={project} take={t.id} rendered={!!t.builtAt && !t.draft} /> <div className="flex flex-wrap items-center gap-1.5" data-take-variants={t.id}> <ForkVariant project={project} take={t.id} ready={ready} /> <CompareWith project={project} take={t.id} options={compareOptions} /> diff --git a/umtool/components/projects/report/CutTab.tsx b/umtool/components/projects/report/CutTab.tsx @@ -17,7 +17,7 @@ import { AddClipToggle } from "../AddClip"; import { Advanced, Options } from "@/components/ui/disclosure"; import PronunciationPanel from "../PronunciationPanel"; import AddPosts from "../AddPosts"; -import { LintButton } from "../TakeTools"; +import { ImportItems, LintButton } from "../TakeTools"; import TightWindowsPanel from "./TightWindowsPanel"; import { clipRecord, storedUrlOf } from "@/lib/clips/stored"; import { Fragment } from "react"; @@ -459,6 +459,8 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor {!postsFirst && <AddPosts project={project.id} channels={postChannels} />} {/* Check before render, on the cut itself (umtool lint <p>): the build's lint and the files its posts name. */} {entries.length > 0 && <LintButton project={project.id} />} + {/* Items of another project into the draft (umtool timeline <p> import-item): cloned, their files linked in. */} + <ImportItems project={project.id} /> {/* A montage's instances, ruled by ear before a render (release 34). */} {montage.length > 0 && ( <Link diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -99,7 +99,7 @@ Inbox cannot disagree about what is wrong with one. | `refresh <article> [--iteration N] [--no-fetch] [--yes] [--json]` · `refresh --check [<article>] [--force]` | the refresh's plan, `--yes` starts it; the daily check now ([refresh.md](refresh.md)) | | `clip <channel>/<video>@<start>-<end> [--snap words] [--title T] [--site <id>] [--folder F] [--json] [--progress ndjson]` | **quick clip**: a basic-mode project (`quick-clips/<slug>`, the footage alone), its window asked of the editor (fetch-windows, followed to its end; Rumble fetched whole), `--snap words` its edges snapped to the words heard (the editor's transcribe op), rendered as the take `clip` (`take <p> --id clip --full`: the heavy slot), then the mp4's path and the share line. `--json`: `{project, output, share: {platform, archive, text}, snapped?}`; `--progress ndjson`: events, the last `quick-clip` (the app's `POST /api/report/quick-clip` job). **Exit 0 · 1 failed (the editor, the render) · 2 usage** ([knobs.md](knobs.md#basic-output-the-footage-alone)) | | `share <project> [<clip>] [--take <t>] [--site <id>] [--json]` | a clip's **share line** (the clip named, else the first): its platform page at the first second it plays and its archive moment, a Rumble folder id as the embed id the archive serves — the twin of **Copy share line** (`GET /api/report/share-line`). `--json`: `{clip, seconds, platform, archive, text}` | -| `timeline <project> [ls] [--json]` · `timeline <project> insert --after <id\|-> <channel>/<video>@<start>-<end> [--id ID] [--section N] [--lock] [--lock-end] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]` · `timeline <project> move <id> --to <index>` · `place <id>… --before <id\|-> [--section N]` · `remove <id>` · `reject <id> <why> [--note T]` · `wrong-speaker <id> [--correction T]` · `duplicate <id>` (`--at <index>` names one of an id's twins) · `post <json\|@file>` · `post-remove <id>` · `teaser <id> <patch-json\|@file>` · `undo` | the **structure** of the cut (the Cut tab's timeline, the On-screen section's teasers and posts) through the writers `POST /api/report/timeline` runs: `ls` prints index, id, type, video, start–end, date and title (`--json` adds the token and the posts); an insert's attribution is a second write through `window`'s writer, its date checked before anything is written; it is written in the manifest's own convention — under the deck `--title` is the deck's title (`onscreen.title`, `--stream-title` the stream's), a cut whose deck titles are dates gets `--date` as one in their format, and the clip takes the section of the clip it goes after (`--section N` names another) and, from the same recording, its deck title and its citation link. `place` is Play's drag on the reel strip: the entries land before that entry (`-`: the end), their clips joining section N (default: the section of the clip they land after), every other clip keeping its own and the markers following, an emptied section refused, each place its own undo point ([knobs.md](knobs.md#the-reel-strip-zoom-and-reorder)). A removal re-anchors what named the clip (a marker to the clip before, a chapter to the next in its section; a pair, a status reference or a deck claim dropped) and prints each `re-anchored:` line; `reject` rejects the clip for `<why>` — `not-matching` or `wrong-speaker` (fact errors: `incorrect`, the note its correction) or `irrelevant`, `repeats`, `weak`, `privacy`, `other` (`rejected`, never a correction) — and removes it, on record in `removed.json` with the reason and the note; `wrong-speaker <id>` is `reject <id> wrong-speaker`; `removed` lists the clips on that record still out of the cut, and `restore <id>` un-rejects one — the entry from the newest revision that holds it (claim, quote, cite and edges as they were) at its old place (after the entry before it there, else before the one after), every later write kept, an undo point first, and what its removal re-anchored or dropped listed as `not put back:` (the Cut tab's **Removed** list, **Restore**); `ls` marks a clip rejected but still in the cut (`[rejected — irrelevant]`) ([report-video.md](report-video.md#verdict--what-the-walk-said)). Every write snapshots the manifest first (`revisions/…-auto-before-<op>`), is refused only for what it breaks in the build's own words (**exit 1**), and on a generated manifest leaves an `edit` note ([report-video.md](report-video.md#structural-edits)) | +| `timeline <project> [ls] [--json]` · `timeline <project> insert --after <id\|-> <channel>/<video>@<start>-<end> [--id ID] [--section N] [--lock] [--lock-end] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]` · `timeline <project> move <id> --to <index>` · `place <id>… --before <id\|-> [--section N]` · `remove <id>` · `reject <id> <why> [--note T]` · `wrong-speaker <id> [--correction T]` · `duplicate <id>` (`--at <index>` names one of an id's twins) · `post <json\|@file>` · `post-remove <id>` · `teaser <id> <patch-json\|@file>` · `undo` | the **structure** of the cut (the Cut tab's timeline, the On-screen section's teasers and posts) through the writers `POST /api/report/timeline` runs: `ls` prints index, id, type, video, start–end, date and title (`--json` adds the token and the posts); an insert's attribution is a second write through `window`'s writer, its date checked before anything is written; it is written in the manifest's own convention — under the deck `--title` is the deck's title (`onscreen.title`, `--stream-title` the stream's), a cut whose deck titles are dates gets `--date` as one in their format, and the clip takes the section of the clip it goes after (`--section N` names another) and, from the same recording, its deck title and its citation link. `place` is Play's drag on the reel strip: the entries land before that entry (`-`: the end), their clips joining section N (default: the section of the clip they land after), every other clip keeping its own and the markers following, an emptied section refused, each place its own undo point ([knobs.md](knobs.md#the-reel-strip-zoom-and-reorder)). A removal re-anchors what named the clip (a marker to the clip before, a chapter to the next in its section; a pair, a status reference or a deck claim dropped) and prints each `re-anchored:` line; `reject` rejects the clip for `<why>` — `not-matching` or `wrong-speaker` (fact errors: `incorrect`, the note its correction) or `irrelevant`, `repeats`, `weak`, `privacy`, `other` (`rejected`, never a correction) — and removes it, on record in `removed.json` with the reason and the note; `wrong-speaker <id>` is `reject <id> wrong-speaker`; `import-item <src>:<item>[,…]` clones items of another project INTO THE DRAFT, as `take --import-item` does into a take (their files hard-linked in, placed `--after`/`--before` an entry or by date, again: updated in place or unchanged; the Cut tab's **Add items from another project**); `removed` lists the clips on that record still out of the cut, and `restore <id>` un-rejects one — the entry from the newest revision that holds it (claim, quote, cite and edges as they were) at its old place (after the entry before it there, else before the one after), every later write kept, an undo point first, and what its removal re-anchored or dropped listed as `not put back:` (the Cut tab's **Removed** list, **Restore**); `ls` marks a clip rejected but still in the cut (`[rejected — irrelevant]`) ([report-video.md](report-video.md#verdict--what-the-walk-said)). Every write snapshots the manifest first (`revisions/…-auto-before-<op>`), is refused only for what it breaks in the build's own words (**exit 1**), and on a generated manifest leaves an `edit` note ([report-video.md](report-video.md#structural-edits)) | | `timeline <project> insert (--to-section N \| --group G) <channel>/<video>@<start>-<end> [--id ID] [--lock] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]` | a clip at the **end of section N**, or **after group G's last clip and one of its clips** (the run stays together): one write, the marker that followed that last clip re-anchored after the new one, so the clip lands in the section and every other clip keeps its own; the attribution as `insert --after`'s. The Candidates panel's Insert is this ([knobs.md](knobs.md#the-candidates-inbox-proposed-clips-picked-by-a-press)) | | `timeline <project> groups [ls] [--json]` · `groups import <file> [--skip-missing] [--drop-empty]` · `groups set <gid\|-> <id…> [--claim C]` · `groups move <gid> --to <index>` · `groups move <gid> --to after <gid>` · `groups label <gid> <claim…>` · `groups promote <gid> [--label L]` · `groups remove <gid>` · `order <file\|@file\|id…>` | **claim groups** (`groups` beside the timeline; the Cut tab's group bars): runs of clips inside one section making one claim — `ls` by section, each group's id, claim and clips (`--json` with the token); `import` a claim-groups file (`{sections: [{label, groups: [{claim, ids}]}]}`) in ONE write — the cut re-ordered to it, its groups the cut's, the markers following; a file section is the deck section of its name, else the one most of its clips are in; **exit 1** for an id the cut lacks (`--skip-missing`) or a section left with no clip (`--drop-empty` removes its marker); `set` (the clips already together), `label`, `remove` (ungroup), `move` the whole group (before the group at that index, or after one, in its section), `promote` (a level-2 marker at its first clip titled with its claim — the one group edit the render sees; `--label` when the claim is over 24); `order` the named entries in the places they hold (every clip keeping its section). A clip moved out of its group's run leaves it; moved alone into the middle of one, it joins. Every write an undo point (`undo`) ([knobs.md](knobs.md#claim-groups-runs-of-clips-that-make-one-claim)) | | `timeline <project> --take <take> [ls \| move <id> --to <index> \| remove <id> \| undo \| insert <spec> --after <id>\|-]` | a **take's** timeline (walk a take): the same structure checks, written into the take's patch, each write with an undo point of the take's own (`takes/<take>/revisions/`); `undo` takes the take's newest edit back, whichever writer made it. `insert` puts a clip (`<channel>/<video>@<start>-<end>`) into the take only (`takeEdit.mjs insertTakeEntry`) -- the app's **+ Add a clip to <take> only** on the take walk page, and Play's **+ Add a clip here** on a take with its own timeline | @@ -299,6 +299,7 @@ draft (the project's manifest); *project*: a project's other files, or reads; *c | `timeline <project> duplicate <id> [--at N]` | an entry twice | form · *draft* | | `timeline <project> reject <id> not-matching\|wrong-speaker\|irrelevant\|repeats\|weak\|privacy\|other [--note NOTE]` | an entry rejected and removed, on the record | form · *draft* | | `timeline <project> wrong-speaker <id> [--correction CORRECTION]` | an entry removed: the wrong speaker | form · *draft* | +| `timeline <project> import-item <refs>… [--after AFTER] [--before BEFORE] [--as AS] [--dry-run]` | items of another project into the draft, their files linked in | form · *draft* | | `timeline <project> removed` | the clips removed on record and still out of the cut | form · *project* | | `timeline <project> restore <id>` | un-reject: a removed clip back as it was, at its old place | form · *draft* | | `timeline <project> post <post>` | a post added, or the one with its id replaced | form · *draft* | diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -1626,6 +1626,7 @@ has the recipe. | | From a terminal | What it writes | |---|---|---| | a draft from another take | `umtool take <p> --id <t> --draft --from <take> [--label L] [--patch F]` | `takes/<t>/take.json`: that take's style and patch (yours over it); nothing rendered | +| items of another project **into the draft** | `umtool timeline <p> import-item <project>:<item>[,<item>…] [--after <entry> \| --before <entry>] [--as <id>] [--dry-run] [--json]` | the same clone into the project's own cut (the draft), one undo point of the project's (`umtool timeline <p> undo`); the Cut tab's Options, **Add items from another project** | | items of another project into the take | `umtool take <p> --id <t> --import-item <project>:<item>[,<item>…] [--after <entry> \| --before <entry>] [--as <id>] [--dry-run] [--json]` | the entries cloned (narration, takes, pick, knobs) into the take's timeline, one undo point; their files **hard-linked** into `<p>` (another file at a path: `imports/<source>/…`); authors' pictures the take lacks into its `postAvatars`. Again: `updated` in place, or `unchanged` (no write) | | a post item's knobs, in the take | `umtool posts set-item <p> <item> k=v … --in-take <t>` (or `--take <t>`) | the take's entry; a piece made context or hidden that its read reads is re-joined first, as on the project | | the read's pieces, in the take | `umtool posts roles <p> <item> --set n=role --in-take <t>` | the take's entry's take parts | @@ -1636,9 +1637,10 @@ has the recipe. | an effect | `umtool posts fx <p> <item> add caption … --in-take <t>` | the take's entry's `fx` | | look, check, take back | `umtool timeline <p> --take <t>` · `umtool lint <p> --take <t>` (exit 0 clean) · `umtool timeline <p> --take <t> undo` | — / — / the take's newest edit, byte for byte | -**In umtool** (lane/ui-simplify): a take card's Options have **Check before render** (the lint), **New draft from this -take** (the next free `<take>-d<n>`) and **Add items from another project** (the project, the items, by date or -after/before an entry; **Preview** is `--dry-run`, then **Import into <take>**); New take has **Save as a draft**. The +**In umtool** (lane/ui-simplify): a take card's Options have **Check before render** (the lint) and **New draft from this +take** (the next free `<take>-d<n>`); **Add items from another project** is the Cut tab's, into the DRAFT (E1, 9 Nov: +the project, the items, by date or after/before an entry; **Preview** is `--dry-run`, then **Import into the draft** — +`umtool timeline <p> import-item`; a take's patch is the terminal's `take --import-item`); New take has **Save as a draft**. The post bench's take-only scope and the take walk's **+ Add a clip to <take> only** are RETIRED (umtool redesign L3: every UI edit lands in the draft — open the take in the draft first); their writes are the terminal's (`--in-take`, `umtool timeline <p> --take <t> insert <spec> --after <id>`, `POST /api/report/post-narration {…, inTake}`). diff --git a/umtool/e2e/take-items.spec.ts b/umtool/e2e/take-items.spec.ts @@ -4,6 +4,7 @@ import { readFileSync, statSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; +import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // A TAKE'S OWN ITEMS (umtool/docs/cli.md, "Edit a take, not the project"): @@ -103,3 +104,25 @@ test("Play on the take plays the imported item: its row between p-1 and p-3, nar await page.goto(urls.playHref(P, { bare: true })); await expect(page.locator("[data-play-row]")).toHaveCount(2); }); + +test("the Cut tab's Add items from another project imports INTO THE DRAFT (L3): Preview writes nothing, Import adds p-2 to the project's cut, its files linked; the source untouched", async ({ page }) => { + await page.goto(urls.projectHref(P, { tab: "cut" })); + await openPanel(page, "options", "cut"); + const box = page.locator('[data-take-import="draft"]'); + await box.locator('[data-action="import-open"]').click(); + await box.locator("[data-import-source]").fill(S); + await box.locator("[data-import-items]").fill("p-2"); + await box.locator('[data-action="import-preview"]').click(); + await expect(page.locator('[data-import-result="plan"] [data-import-row="p-2"]')).toContainText("p-2 added"); + expect(text(DIR), "a preview writes nothing").toBe(projectBefore); + await expect(box.locator('[data-action="import-go"]')).toHaveText("Import into the draft"); + await box.locator('[data-action="import-go"]').click(); + await expect(page.locator('[data-import-result="done"]')).toHaveAttribute("data-import-exit", "0"); + await expect.poll(() => (JSON.parse(text(DIR)).timeline as Entry[]).map((e) => e.id)).toEqual(["p-1", "p-2", "p-3"]); + expect(statSync(path.join(DIR, "narration/posts/2/take-1.orpheus-thread.wav")).ino).toBe(statSync(path.join(SRC, "narration/posts/2/take-1.orpheus-thread.wav")).ino); + expect(text(SRC)).toBe(sourceBefore); + // The take cards no longer carry it: a take is opened in the draft first. + await page.goto(urls.takesHref(P)); + await expect(page.locator(`[data-take-tools="${TAKE}"]`)).toBeVisible(); + await expect(page.locator("[data-take-import]")).toHaveCount(0); +}); diff --git a/umtool/lib/cli/groups.mjs b/umtool/lib/cli/groups.mjs @@ -866,7 +866,7 @@ export const GROUPS = [ ], docs: [ ["`timeline <project> [ls] [--json]` · `timeline <project> insert --after <id\\|-> <channel>/<video>@<start>-<end> [--id ID] [--section N] [--lock] [--lock-end] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]` · `timeline <project> move <id> --to <index>` · `place <id>… --before <id\\|-> [--section N]` · `remove <id>` · `reject <id> <why> [--note T]` · `wrong-speaker <id> [--correction T]` · `duplicate <id>` (`--at <index>` names one of an id's twins) · `post <json\\|@file>` · `post-remove <id>` · `teaser <id> <patch-json\\|@file>` · `undo`", - "the **structure** of the cut (the Cut tab's timeline, the On-screen section's teasers and posts) through the writers `POST /api/report/timeline` runs: `ls` prints index, id, type, video, start–end, date and title (`--json` adds the token and the posts); an insert's attribution is a second write through `window`'s writer, its date checked before anything is written; it is written in the manifest's own convention — under the deck `--title` is the deck's title (`onscreen.title`, `--stream-title` the stream's), a cut whose deck titles are dates gets `--date` as one in their format, and the clip takes the section of the clip it goes after (`--section N` names another) and, from the same recording, its deck title and its citation link. `place` is Play's drag on the reel strip: the entries land before that entry (`-`: the end), their clips joining section N (default: the section of the clip they land after), every other clip keeping its own and the markers following, an emptied section refused, each place its own undo point ([knobs.md](knobs.md#the-reel-strip-zoom-and-reorder)). A removal re-anchors what named the clip (a marker to the clip before, a chapter to the next in its section; a pair, a status reference or a deck claim dropped) and prints each `re-anchored:` line; `reject` rejects the clip for `<why>` — `not-matching` or `wrong-speaker` (fact errors: `incorrect`, the note its correction) or `irrelevant`, `repeats`, `weak`, `privacy`, `other` (`rejected`, never a correction) — and removes it, on record in `removed.json` with the reason and the note; `wrong-speaker <id>` is `reject <id> wrong-speaker`; `removed` lists the clips on that record still out of the cut, and `restore <id>` un-rejects one — the entry from the newest revision that holds it (claim, quote, cite and edges as they were) at its old place (after the entry before it there, else before the one after), every later write kept, an undo point first, and what its removal re-anchored or dropped listed as `not put back:` (the Cut tab's **Removed** list, **Restore**); `ls` marks a clip rejected but still in the cut (`[rejected — irrelevant]`) ([report-video.md](report-video.md#verdict--what-the-walk-said)). Every write snapshots the manifest first (`revisions/…-auto-before-<op>`), is refused only for what it breaks in the build's own words (**exit 1**), and on a generated manifest leaves an `edit` note ([report-video.md](report-video.md#structural-edits))"], + "the **structure** of the cut (the Cut tab's timeline, the On-screen section's teasers and posts) through the writers `POST /api/report/timeline` runs: `ls` prints index, id, type, video, start–end, date and title (`--json` adds the token and the posts); an insert's attribution is a second write through `window`'s writer, its date checked before anything is written; it is written in the manifest's own convention — under the deck `--title` is the deck's title (`onscreen.title`, `--stream-title` the stream's), a cut whose deck titles are dates gets `--date` as one in their format, and the clip takes the section of the clip it goes after (`--section N` names another) and, from the same recording, its deck title and its citation link. `place` is Play's drag on the reel strip: the entries land before that entry (`-`: the end), their clips joining section N (default: the section of the clip they land after), every other clip keeping its own and the markers following, an emptied section refused, each place its own undo point ([knobs.md](knobs.md#the-reel-strip-zoom-and-reorder)). A removal re-anchors what named the clip (a marker to the clip before, a chapter to the next in its section; a pair, a status reference or a deck claim dropped) and prints each `re-anchored:` line; `reject` rejects the clip for `<why>` — `not-matching` or `wrong-speaker` (fact errors: `incorrect`, the note its correction) or `irrelevant`, `repeats`, `weak`, `privacy`, `other` (`rejected`, never a correction) — and removes it, on record in `removed.json` with the reason and the note; `wrong-speaker <id>` is `reject <id> wrong-speaker`; `import-item <src>:<item>[,…]` clones items of another project INTO THE DRAFT, as `take --import-item` does into a take (their files hard-linked in, placed `--after`/`--before` an entry or by date, again: updated in place or unchanged; the Cut tab's **Add items from another project**); `removed` lists the clips on that record still out of the cut, and `restore <id>` un-rejects one — the entry from the newest revision that holds it (claim, quote, cite and edges as they were) at its old place (after the entry before it there, else before the one after), every later write kept, an undo point first, and what its removal re-anchored or dropped listed as `not put back:` (the Cut tab's **Removed** list, **Restore**); `ls` marks a clip rejected but still in the cut (`[rejected — irrelevant]`) ([report-video.md](report-video.md#verdict--what-the-walk-said)). Every write snapshots the manifest first (`revisions/…-auto-before-<op>`), is refused only for what it breaks in the build's own words (**exit 1**), and on a generated manifest leaves an `edit` note ([report-video.md](report-video.md#structural-edits))"], ["`timeline <project> insert (--to-section N \\| --group G) <channel>/<video>@<start>-<end> [--id ID] [--lock] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]`", "a clip at the **end of section N**, or **after group G's last clip and one of its clips** (the run stays together): one write, the marker that followed that last clip re-anchored after the new one, so the clip lands in the section and every other clip keeps its own; the attribution as `insert --after`'s. The Candidates panel's Insert is this ([knobs.md](knobs.md#the-candidates-inbox-proposed-clips-picked-by-a-press))"], ["`timeline <project> groups [ls] [--json]` · `groups import <file> [--skip-missing] [--drop-empty]` · `groups set <gid\\|-> <id…> [--claim C]` · `groups move <gid> --to <index>` · `groups move <gid> --to after <gid>` · `groups label <gid> <claim…>` · `groups promote <gid> [--label L]` · `groups remove <gid>` · `order <file\\|@file\\|id…>`", diff --git a/umtool/lib/cli/verbs.mjs b/umtool/lib/cli/verbs.mjs @@ -363,6 +363,9 @@ function timeline() { tl("duplicate", "draft", "an entry twice", [id(), num("--at")]), tl("reject", "draft", "an entry rejected and removed, on the record", [id(), pick("why", REJECT_WHYS, { required: true }), opt("--note", { type: "text" })]), tl("wrong-speaker", "draft", "an entry removed: the wrong speaker", [id(), opt("--correction", { type: "text" })]), + tl("import-item", "draft", "items of another project into the draft, their files linked in", [ + many("refs", { required: true, item: "ref", help: "<project>:<item>[,<item>…], one per line" }), opt("--after"), opt("--before"), opt("--as"), dry(), + ]), tl("removed", "project", "the clips removed on record and still out of the cut", []), tl("restore", "draft", "un-reject: a removed clip back as it was, at its old place", [arg("id", { help: "the removed clip's id (timeline removed lists them)" })]), tl("post", "draft", "a post added, or the one with its id replaced", [arg("post", { type: "text", atFile: true, help: "JSON (@file: from a terminal)" })]), diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -2478,6 +2478,20 @@ async function structural(dir, op, token, mutate, { snapshotEvery = undefined, p } /** + * A structural edit of the DRAFT by a writer outside this file (takeImport.mjs importDraftItems): `mutate` over + * the manifest in the lock, the build's checks, an undo point, the take patches' markers following -- what every + * structural writer here does. Returns mutate's result with `snapshot` and `token`. + * + * @param {string} dir + * @param {string} op the undo point's name (`auto-before-<op>`) + * @param {string | null} token + * @param {(m: Record<string, any>) => any} mutate + */ +export async function editDraftStructure(dir, op, token, mutate) { + return structural(dir, op, token, (m) => mutate(m)); +} + +/** * Move one entry to `toIndex` (its index in the timeline AFTER the move). * `sectionEnter` is recomputed by report-to-video's own rule (sections.mjs), * and only on a manifest that already uses it. diff --git a/umtool/lib/report/takeImport.mjs b/umtool/lib/report/takeImport.mjs @@ -39,7 +39,7 @@ import { createReadStream } from "node:fs"; import { copyFile, link, lstat, mkdir, readFile, readdir, realpath, stat } from "node:fs/promises"; import path from "node:path"; import { handleKey } from "umtool-report-to-video/post-avatars"; -import { applyStructural } from "./manifest.mjs"; +import { applyStructural, editDraftStructure, manifestToken } from "./manifest.mjs"; import { editTakeManifest, takeToken } from "./takeEdit.mjs"; import { resolveTakeManifest } from "./takeManifest.mjs"; @@ -194,22 +194,44 @@ export function postsInDateOrder(timeline) { } /** - * IMPORT ITEMS OF OTHER PROJECTS INTO A TAKE (see the head of the file). + * Items of other projects INTO THE DRAFT -- the project's own manifest, where every edit lands now (umtool + * redesign L3; E1, 9 Nov: the Cut tab's "Add items from another project"). importTakeItems with no take: the + * same clone, the same files linked in, the same placement and the same "again: unchanged", written through the + * draft's structural writer (an undo point of the project's, `umtool timeline <p> undo`). + * + * @param {{ id: string, dir: string }} project + * @param {Array<{ project: { id: string, dir: string }, item: string, as?: string | null }>} refs + * @param {{ after?: string | null, before?: string | null, dryRun?: boolean, now?: Date }} [opts] + */ +export const importDraftItems = (project, refs, opts = {}) => importTakeItems(project, null, refs, opts); + +/** + * IMPORT ITEMS OF OTHER PROJECTS INTO A TAKE (see the head of the file) -- or, `take` null, into the draft + * (importDraftItems). * * @param {{ id: string, dir: string }} project the take's project - * @param {string} take + * @param {string | null} take * @param {Array<{ project: { id: string, dir: string }, item: string, as?: string | null }>} refs * @param {{ after?: string | null, before?: string | null, dryRun?: boolean, now?: Date }} [opts] */ export async function importTakeItems(project, take, refs, { after = null, before = null, dryRun = false, now = new Date() } = {}) { if (!refs.length) throw new ImportRefused("nothing to import"); if (after && before) throw new ImportRefused("--after or --before, not both"); - const busy = await renderingNow(project.dir, take); + const draft = take === null; + const busy = draft ? null : await renderingNow(project.dir, take); if (busy) throw new ImportRefused(`not imported: ${busy}`); - const takeNow = await resolveTakeManifest(project.dir, take); // throws, naming it, when there is no such take + const takeNow = draft + ? { manifest: JSON.parse(await readFile(path.join(project.dir, "video.manifest.json"), "utf8").catch(() => { throw new ImportRefused(`${project.id} has no video.manifest.json`); })) } + : await resolveTakeManifest(project.dir, take); // throws, naming it, when there is no such take const tl = takeNow.manifest.timeline; const anchor = after ?? before; - if (anchor && !findEntry(tl, anchor)) throw new ImportRefused(`take ${take} has no entry ${anchor} to put the item(s) ${after ? "after" : "before"} (\`umtool timeline ${project.id} --take ${take}\` lists them)`); + if (anchor && !findEntry(tl, anchor)) { + throw new ImportRefused( + draft + ? `the draft has no entry ${anchor} to put the item(s) ${after ? "after" : "before"} (\`umtool timeline ${project.id}\` lists them)` + : `take ${take} has no entry ${anchor} to put the item(s) ${after ? "after" : "before"} (\`umtool timeline ${project.id} --take ${take}\` lists them)`, + ); + } // Each source manifest read once, as it is on disk (never a take of it). /** @type {Map<string, Record<string, any>>} */ @@ -272,14 +294,10 @@ export async function importTakeItems(project, take, refs, { after = null, befor } } - const placed = []; - const write = await editTakeManifest( - project.dir, - take, - "import-item", - await takeToken(project.dir, take), - (m) => - applyStructural(m, (mm) => { + let placed = []; + /** The placement, over a manifest held in memory (the take's resolved one, or the draft's). */ + const place = (mm) => { + placed = []; const timeline = mm.timeline; const order = timeline.map((x) => (isObj(x) ? x.id : null)).join("\n"); let cursor = null; // the id the next item goes after (several items keep their order) @@ -317,9 +335,10 @@ export async function importTakeItems(project, take, refs, { after = null, befor pl.at = { index: i, after: i > 0 ? timeline[i - 1].id : null, before: i + 1 < timeline.length ? timeline[i + 1].id : null }; } return { ids: plans.map((p) => p.id) }; - }), - { now, dryRun }, - ); + }; + const write = draft + ? await writeDraft(project.dir, place, { dryRun }) + : await editTakeManifest(project.dir, take, "import-item", await takeToken(project.dir, take), (m) => applyStructural(m, place), { now, dryRun }); const items = plans.map((p) => { const pl = placed.find((x) => x.id === p.id); const n = isObj(p.entry.narration) ? p.entry.narration : null; @@ -343,7 +362,22 @@ export async function importTakeItems(project, take, refs, { after = null, befor dryRun, unchanged: write.unchanged, items, - revision: write.revision ? `takes/${take}/${write.revision.rel}` : null, + revision: draft ? write.revision : write.revision ? `takes/${take}/${write.revision.rel}` : null, token: write.token, }; } + +/** + * The draft's import write: the placement tried on a copy first -- nothing changed (or a dry run) writes nothing -- + * then done again inside the draft's structural writer, on the file as it is then. `revision`: its undo point. + */ +async function writeDraft(dir, place, { dryRun }) { + const token = await manifestToken(dir); + const now = JSON.parse(await readFile(path.join(dir, "video.manifest.json"), "utf8")); + const tried = clone(now); + applyStructural(tried, place); + if (JSON.stringify(tried) === JSON.stringify(now)) return { unchanged: true, token, revision: null }; + if (dryRun) return { unchanged: false, dryRun: true, token, revision: null }; + const r = await editDraftStructure(dir, "import-item", token, place); + return { unchanged: false, token: r.token, revision: r.snapshot?.rel && !r.snapshot.skipped ? r.snapshot.rel : null }; +} diff --git a/umtool/lib/report/takeScope.test.mjs b/umtool/lib/report/takeScope.test.mjs @@ -278,6 +278,56 @@ test("--import-item: an item of another project cloned into the take with its na assert.match(r.err, /has no entry p-77/); }); +test("timeline import-item: items of another project INTO THE DRAFT -- cloned, files linked, placed; again: unchanged; an undo point; the source untouched", async () => { + const src = await project("dimp-src", [narrated("20", "2026-10-30T12:30:00.000Z"), narrated("21", "2026-10-30T12:40:00.000Z")]); + for (const id of ["20", "21"]) { + await tone(path.join(src.dir, `narration/posts/${id}/take-1.orpheus-thread.wav`)); + await writeFile(path.join(src.dir, `narration/posts/${id}/take-1.parts.json`), "[]"); + } + await project("dimp-dst", [post("1", "2026-10-30T10:00:00.000Z"), post("3", "2026-10-30T13:00:00.000Z")]); + const srcBefore = await text(src); + const timeline = (...a) => cli(timelineCommand, a); + const dst = { dir: path.join(REPORTS, "dimp-dst") }; + const ids = async () => (await readManifest(dst.dir)).timeline.map((e) => e.id); + + // A dry run: the plan, nothing written, nothing linked. + let r = await timeline("dimp-dst", "import-item", "dimp-src:p-20", "--dry-run", "--json"); + assert.equal(r.code, 0, r.err); + let doc = JSON.parse(r.out); + assert.deepEqual([doc.dryRun, doc.take, doc.items[0].at.index], [true, null, 1], "by date: between p-1 and p-3"); + assert.deepEqual(await ids(), ["p-1", "p-3"]); + assert.ok(!(await stat(path.join(dst.dir, "narration/posts/20")).catch(() => null)), "a dry run links nothing"); + + // Into the draft after p-1, in the order named; the files hard-linked; an undo point of the project's. + r = await timeline("dimp-dst", "import-item", "dimp-src:p-21,p-20", "--after", "p-1", "--json"); + assert.equal(r.code, 0, r.err); + doc = JSON.parse(r.out); + assert.deepEqual(doc.items.map((x) => [x.id, x.action]), [["p-21", "added"], ["p-20", "added"]]); + assert.match(doc.revision, /^revisions\/.*-auto-before-import-item\.manifest\.json$/); + assert.deepEqual(await ids(), ["p-1", "p-21", "p-20", "p-3"]); + const [s1, d1] = await Promise.all([stat(path.join(src.dir, "narration/posts/21/take-1.orpheus-thread.wav")), stat(path.join(dst.dir, "narration/posts/21/take-1.orpheus-thread.wav"))]); + assert.equal(d1.ino, s1.ino); + assert.equal(await text(src), srcBefore, "the source is only read"); + + // Again: unchanged, nothing written. + const before = await readFile(path.join(dst.dir, "video.manifest.json"), "utf8"); + r = await timeline("dimp-dst", "import-item", "dimp-src:p-21", "--json"); + doc = JSON.parse(r.out); + assert.deepEqual([doc.unchanged, doc.items[0].action, doc.revision], [true, "unchanged", null]); + assert.equal(await readFile(path.join(dst.dir, "video.manifest.json"), "utf8"), before); + // Words, and the refusals. + r = await timeline("dimp-dst", "import-item", "dimp-src:p-20", "--before", "p-1"); + assert.equal(r.code, 0, r.err); + assert.match(r.out, /p-20: moved from dimp-src:p-20 at 0, before p-1/); + // The undo point of a second import-item inside the undo window is the first's (autoSnapshot's rate). + assert.match(r.out, /the draft: 1 item\(s\)$/); + r = await timeline("dimp-dst", "import-item", "dimp-src:p-20", "--after", "p-77"); + assert.equal(r.code, 1); + assert.match(r.err, /the draft has no entry p-77/); + assert.equal((await timeline("dimp-dst", "import-item", "dimp-src")).code, 2); + assert.equal((await timeline("dimp-dst", "import-item", "dimp-src:p-99")).code, 1); +}); + test("--draft --from <take>: a draft that starts from another take's patch (a --patch over it), its timeline its own", async () => { const a = await project("draft-from", [post("1", "2026-10-30T10:00:00.000Z"), post("2", "2026-10-30T11:00:00.000Z")]); assert.equal((await take("draft-from", "--id", "base", "--label", "Base", "--draft", "--patch-json", JSON.stringify({ timeline: [post("2", "2026-10-30T11:00:00.000Z")], render: { posts: { slurs: { on: false } } } }))).code, 0); diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs @@ -126,6 +126,12 @@ export const TIMELINE_USAGE = [ ` <why> is ${REJECT_REASON_IDS.join("|")} -- not-matching and wrong-speaker are fact`, " errors (incorrect, the note its correction; not-matching needs one), the rest cut reasons (rejected; other needs a note)", " umtool timeline <project> wrong-speaker <id> [--correction TEXT] the same as reject <id> wrong-speaker", + " umtool timeline <project> import-item <src>:<item>[,<item>…] [<src>:…] [--after <id> | --before <id>] [--as <id>] [--dry-run]", + " items of another project INTO THE DRAFT: cloned as they are there (their card, context, knobs,", + " narration with its takes and pick), the files they name hard-linked in (another file at the path:", + " under imports/<src>/), placed after/before an entry (else by date among the posts, else at the end);", + " again: updated in place, or unchanged and nothing written; one undo point (the Cut tab's", + " Add items from another project)", " umtool timeline <project> removed [--json] the clips taken out on record (removed.json) and still out", " umtool timeline <project> restore <id> UN-REJECT: put a removed clip back -- the entry from the newest", " revision that holds it (claim, quote, cite, edges intact) at its old place (after the entry", @@ -189,9 +195,9 @@ 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", "duplicate", "post", "post-remove", "teaser", "undo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"]; +const VERBS = ["ls", "insert", "add-video", "set-video", "move", "place", "remove", "reject", "wrong-speaker", "removed", "restore", "import-item", "duplicate", "post", "post-remove", "teaser", "undo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"]; const GROUP_VERBS = ["ls", "import", "set", "move", "label", "promote", "remove"]; -const VALUED = new Set(["--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"]); +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. */ const TAKE_VERBS = ["ls", "move", "remove", "undo", "insert"]; @@ -583,6 +589,8 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) => if (verb === "threads") return await threadsCommand(project, manifest, { write: flags.has("--write"), only: flags.has("--conversation") ? String(flags.get("--conversation")) : null, json, out }); + if (verb === "import-item") return await importItemsIntoDraft(project, rest, flags, { root, out, err, json }); + if (verb === "removed") { const rows = removedOutOfCut(await readRemoved(project.dir), manifest); if (json) { @@ -941,6 +949,54 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) => } /** + * `umtool timeline <p> import-item <src>:<item>[,…] … [--after|--before <id>] [--as <id>] [--dry-run] [--json]`: + * items of other projects into the DRAFT (takeImport.mjs importDraftItems). EXIT 0 done (or unchanged) · 1 refused + * · 2 usage. + */ +async function importItemsIntoDraft(project, rest, flags, { root, out, err, json }) { + const { ImportRefused, importDraftItems, parseImportRef } = await import("./takeImport.mjs"); + if (!rest.length) throw new CliError("import-item needs <project>:<item>[,<item>…] (the item ids of another project)"); + const refs = []; + for (const raw of rest) { + const r = parseImportRef(raw); + if (!r) throw new CliError(`import-item takes <project>:<item>[,<item>…] (not ${raw})`); + for (const item of r.items) refs.push({ project: await projectOf(r.project, root), item, as: null }); + } + if (flags.has("--as")) { + if (refs.length !== 1) throw new CliError("--as names ONE item's id in the draft: import one item with it"); + refs[0].as = String(flags.get("--as")); + if (!/^[A-Za-z0-9._:-]{1,120}$/.test(refs[0].as)) throw new CliError(`--as ${refs[0].as}: an entry id is letters, digits, dots, dashes`); + } + if (flags.has("--after") && flags.has("--before")) throw new CliError("--after or --before, not both"); + const one = (k) => (typeof flags.get(k) === "string" && flags.get(k) ? String(flags.get(k)) : null); + let r; + try { + r = await importDraftItems(project, refs, { after: one("--after"), before: one("--before"), dryRun: flags.has("--dry-run") }); + } catch (e) { + if (e instanceof ImportRefused) { + err(`umtool timeline: ${e.message}`); + return 1; + } + throw e; + } + if (json) { + out(JSON.stringify({ ok: true, op: "import-item", ...r }, null, 2)); + return 0; + } + for (const x of r.items) { + const at = x.at ? ` at ${x.at.index}${x.at.after ? `, after ${x.at.after}` : ""}${x.at.before ? `, before ${x.at.before}` : ""}` : ""; + out(`${x.id}: ${r.dryRun ? `would be ${x.action}` : x.action} from ${x.ref}${at}`); + if (x.narration) out(` narration: ${x.narration.takes} take(s), pick ${x.narration.pick ?? "none"}${x.narration.file ? ` (${x.narration.file})` : ""}`); + const linked = x.files.filter((f) => !f.how.startsWith("already")); + if (x.files.length) out(` files: ${linked.length} ${r.dryRun ? "to link" : "linked"}, ${x.files.length - linked.length} already there${linked.some((f) => f.was) ? `; renamed (another file had the path): ${linked.filter((f) => f.was).map((f) => `${f.was} -> ${f.path}`).join(", ")}` : ""}`); + if (x.avatars.length) out(` authors' pictures added: ${x.avatars.join(", ")}`); + if (x.missing.length) err(` named but not in ${x.source}: ${x.missing.join(", ")}`); + } + out(r.unchanged ? `the draft: nothing changed (already imported as it is)` : r.dryRun ? `the draft: a dry run, nothing written (would import ${r.items.length} item(s))` : `the draft: ${r.items.length} item(s)${r.revision ? `; undo point ${r.revision} (umtool timeline ${project.id} undo)` : ""}`); + return 0; +} + +/** * `umtool timeline <p> --take <id> ls|move|remove|undo`: a take's timeline * (walk a take). The writes go into the take's patch through takeEdit.mjs -- * the same structure rules, an undo point of the take's own first -- and the