// --------------------------------------------------------------------------- // Every page address umtool links to, one builder per URL shape. // // The URLs moved in P3 (plans/umtool-redesign.md): /browse became Work (/work) // and the projects (/projects/), the decisions the Inbox (/), and the tools // went under /tools. Each move was a body here and a row in redirects.mjs. A // link written as a literal is a link the next move has to find by hand. // // Two contracts: // - `?note=` is ALWAYS the last parameter. The MCP's notes tool reads a // decision's href and expects it to END in `note=` // (mcp/src/archivalTools.ts), so the builder puts it last whatever else the // query carries. // - Project ids are paths (`quartering-uh-song/videos/mortal-kombat`): each // SEGMENT is encoded, the slashes are not. // // Pure and dependency-free (one .mjs constant), so a client component, a server // page and an e2e spec (e2e/urls.ts) all import the same table, and // `node --test lib/hrefs.test.mjs` runs it without a bundler. // --------------------------------------------------------------------------- import { libraryHref as libraryViewHref } from "./library/filters.mjs"; import { ARTICLES_KEY } from "./articles/key.mjs"; /** A query value; `undefined`, `null`, `false` and "" are left out. */ export type QueryValue = string | number | boolean | null | undefined; export type Query = Record; /** Encode a path id segment by segment, keeping its slashes. */ export function encodePath(id: string): string { return id .split("/") .filter((s) => s.length > 0) .map(encodeURIComponent) .join("/"); } /** * `path` + its query, with `note` last. `true` is written as `1`, the form every * flag here already takes (`?all=1`). */ export function withQuery(path: string, query: Query = {}, note?: string | null): string { const sp = new URLSearchParams(); for (const [k, v] of Object.entries(query)) { if (k === "note") continue; // only ever through `note`, so it stays last if (v === undefined || v === null || v === false || v === "") continue; sp.set(k, v === true ? "1" : String(v)); } if (note) sp.set("note", note); const q = sp.toString(); return q ? `${path}?${q}` : path; } /** Re-point an existing href at a note, keeping `note` last. */ export function withNote(href: string, note: string): string { const hash = href.indexOf("#"); const frag = hash >= 0 ? href.slice(hash) : ""; const bare = hash >= 0 ? href.slice(0, hash) : href; const q = bare.indexOf("?"); const path = q >= 0 ? bare.slice(0, q) : bare; const sp = new URLSearchParams(q >= 0 ? bare.slice(q + 1) : ""); sp.delete("note"); sp.set("note", note); return `${path}?${sp.toString()}${frag}`; } type NoteOpt = { note?: string | null }; // ── the places ────────────────────────────────────────────────────────────── /** * The Inbox. `hidden` lists the calls on parked and done pieces, `muted` the * muted ones. The editor's "make a video" hand-off, `/?from=/` * (VideoPanel, VideoNavStrip), is answered by a redirect to Create * (redirects.mjs, P5) -- build it with createHref({ from }). */ export function homeHref(q: { hidden?: boolean; muted?: boolean } = {}): string { return withQuery("/", q); } /** The Inbox (an alias of homeHref, by the place's name). */ export const inboxHref = homeHref; /** Research (R1). */ export function researchHref(): string { return "/research"; } /** * Work: every piece, faceted. It also reads the old lists' keys -- /browse's * (kind = a project kind, template, state, open, sort), /articles' (status, * notes, audience) and /sites' (site) -- so an old link lands on the same set. */ export type WorkQuery = { q?: string; stage?: string; /** `article`, or a project kind id. */ kind?: string; site?: string; /** active (the default) | parked | done | all. */ life?: string; /** `site`: grouped by site. */ by?: string; template?: string; state?: string; open?: string; status?: string; notes?: string; audience?: string; sort?: string; /** `1`: the recurring reports only -- the series and the living reports (R5). */ recurring?: string; deleted?: string; freed?: string; }; export function workHref(q: WorkQuery = {}): string { return withQuery("/work", q); } export type BrowseQuery = { kind?: string; template?: string; state?: string; open?: string; q?: string; sort?: string; deleted?: string; }; /** Every project, filtered -- /browse became Work, which reads these keys. */ export function browseHref(q: BrowseQuery = {}): string { return workHref(q); } /** The projects index: every project as a grid, by folder (the old /browse page). `new` opens the new-project form. */ export function projectsHref(q: BrowseQuery & { new?: boolean } = {}): string { return withQuery("/projects", q); } export type DecisionsQuery = { severity?: string; kind?: string; project?: string }; /** The decision list became the Inbox. */ export function decisionsHref(_q: DecisionsQuery = {}): string { return "/"; } export type ArticlesQuery = { status?: string; notes?: string; audience?: string; deleted?: string; freed?: string }; /** The article store's articles: Work, kind article, site `articles` (the store). */ export function articlesHref(q: ArticlesQuery = {}): string { return workHref({ kind: "article", site: ARTICLES_KEY, ...q }); } /** * What Create makes (P5): each is a line on /create, `?make=` opens its form. * research a case for a question (R2's board) * article an article from a question: a sweep, or research first * article-board an article from a board (R2's hand-off) * video-article a video from an article: the chain over an iteration * video-board a video from a board (R2's hand-off) * video-recording a video from a recording (`from` = / or a share URL) * video-highlights highlights from a long recording: the clip finder's seed (release 35) * video-report a video from a sweep report on disk * song a song */ export const MAKES = ["research", "article", "article-board", "recurring", "video-article", "video-board", "video-recording", "video-highlights", "video-report", "song"] as const; export type Make = (typeof MAKES)[number]; export const isMake = (v: unknown): v is Make => typeof v === "string" && (MAKES as readonly string[]).includes(v); /** * Create: "What are you making?". `make` opens one line's form; `from` is the * editor's hand-off (a recording, `/`), which opens "Video from a * recording" prefilled. `case` preselects a board, `article` an article. */ export function createHref(q: { make?: Make; from?: string; case?: string; article?: string } = {}): string { return withQuery("/create", q); } /** A new article: Create's "Article from a question" (it was /articles/new). */ export function newArticleHref(): string { return createHref({ make: "article" }); } /** Settings: the generation policy -- routes, models, caps, the key, the extractor, today's spend. */ export function generationPolicyHref(): string { return "/settings/generation"; } /** Settings: the two pages. */ export function settingsHref(): string { return "/settings"; } /** Jobs: the durable queue (lib/queue/), the take renders' records, and the app's own jobs. */ export function jobsHref(): string { return "/jobs"; } /** A queue step's full log, as text (GET /api/queue/log). */ export function queueLogHref(qid: string, attempt: number | null = null): string { return withQuery("/api/queue/log", { qid, ...(attempt ? { attempt: String(attempt) } : {}) }); } /** A take render's full log, takes//render.log, as text (GET /api/report/takes/render). */ export function takeRenderLogHref(project: string, take: string): string { return withQuery("/api/report/takes/render", { project, take, log: "1" }); } /** Settings: the machine -- tools, disk, index, sources, deliverables, recent jobs. */ export function systemHref(): string { return "/settings/system"; } export type SitesQuery = { site?: string; status?: string; notes?: string }; /** Every site's articles: Work, grouped by site. */ export function sitesHref(q: SitesQuery = {}): string { return workHref({ by: "site", ...q }); } /** One site's page; `ws`+`rel` open a workspace file, `#files` scrolls to it. */ export function siteHref(site: string, q: { ws?: string; rel?: string } = {}): string { const base = withQuery(`/sites/${encodeURIComponent(site)}`, q); return q.ws || q.rel ? `${base}#files` : base; } // ── articles ──────────────────────────────────────────────────────────────── export type ArticleRef = { site: string; id: string }; /** * An article piece's address (P4a-2): `tab` one of its nine tabs (absent, or * `overview`, is the Overview; `source` is the Article tab's workspace view); * `project` the video project the video tabs show when it is not the one the * article's Cut opens (an article that claims two); `all` the cut's every quote. */ // `refresh`: the Overview opens the Refresh plan (R4; the suggestion card's action). export type ArticleQuery = { tab?: string; status?: string; ws?: string; rel?: string; project?: string; all?: boolean; refresh?: boolean } & NoteOpt; function articleBase(a: ArticleRef): string { return a.site === ARTICLES_KEY ? `/articles/${encodeURIComponent(a.id)}` : `/sites/${encodeURIComponent(a.site)}/${encodeURIComponent(a.id)}`; } /** An article's page: `/articles/` in the store, `/sites//` on a site. */ export function articleHref(a: ArticleRef, q: ArticleQuery = {}): string { const { note, tab, ...rest } = q; return withQuery(articleBase(a), { ...(tab && tab !== "overview" ? { tab } : {}), ...rest }, note); } /** A recurring report's series (R5): its editions, ticks and schedule. A static segment. */ export function seriesHref(id: string): string { return `/series/${encodeURIComponent(id)}`; } /** One triage run of a recurring report (R6): its tiers, flags and dismissals. */ export function triageHref(schedule: string, k: number): string { return `/series/${encodeURIComponent(schedule)}/triage/${k}`; } /** The evidence walk of one article. */ export function articleEvidenceHref(a: ArticleRef, q: { c?: string } = {}): string { return withQuery(`${articleBase(a)}/evidence`, q); } /** Two revisions of a store article side by side. */ export function articleCompareHref(id: string, q: { a?: string; b?: string } = {}): string { return withQuery(`/articles/${encodeURIComponent(id)}/compare`, q); } // ── projects ──────────────────────────────────────────────────────────────── /** * A project's page. Its own address (no `tab`) is a report video's WORKSPACE (umtool redesign L7a: * components/projects/workspace/) and any other kind's piece page; `tab` opens one of the piece page's tabs * (lib/pieces/tabs.mjs) -- `overview` too, written out, since the bare address is the workspace's. * `all` shows every row of the cut's long list. */ export function projectHref(id: string, q: { tab?: string; all?: boolean } & NoteOpt = {}): string { const { note, tab, ...rest } = q; return withQuery(`/projects/${encodePath(id)}`, { ...(tab ? { tab } : {}), ...rest }, note); } /** The workspace's modes besides Edit (its bare address): the review pass and present (umtool redesign L7b). */ export const WORKSPACE_MODES = ["review", "present"] as const; export type WorkspaceMode = (typeof WORKSPACE_MODES)[number]; export const isWorkspaceMode = (v: unknown): v is WorkspaceMode => typeof v === "string" && (WORKSPACE_MODES as readonly string[]).includes(v); /** * THE WORKSPACE (umtool redesign L7a): a report video's one screen -- the draft playing, its blocks, the * inspector. `block`: open with that block (a timeline entry's id, or `intro`) selected; `at` seconds into it. * `mode` (L7b): `review` the review pass (Keep · Fix · Note per block, a verdict at the end), `present` the viewer * full screen as slides; Edit is the bare address. `take`: a saved version, reviewed or presented read-only. * `slide`: present mode's slide (its `#`). */ export function workspaceHref( id: string, q: { block?: string | null; at?: number | null; mode?: WorkspaceMode | null; take?: string | null; slide?: string | null; all?: boolean; note?: string | null } = {}, ): string { // `all`, `note`: what a take walk's old address carried, kept on its review pass (with a mode only: without one // they are the piece page's keys). return ( withQuery( `/projects/${encodePath(id)}`, { mode: q.mode ?? null, take: q.mode ? (q.take ?? null) : null, block: q.block ?? null, at: q.block && q.at != null && q.at > 0 ? q.at.toFixed(2) : null, all: q.mode ? q.all : null, }, q.mode ? q.note : null, ) + (q.mode === "present" && q.slide ? `#${q.slide}` : "") ); } /** A project by its path, for an id that a tool page shadows at its own URL. */ export function projectAtHref(id: string, q: NoteOpt = {}): string { return withQuery("/projects/at", { path: id }, q.note); } /** The clip bench, one timeline entry. */ /** * A POST ITEM's bench (report-to-video/post-item.mjs): its attachments' trims, * sound and crop, its hold. From Play ("Edit this clip"): Back lands `at` * seconds into the item. */ export function postBenchHref(project: string, id: string, q: { play?: { at?: number | null } | null } = {}): string { const play = q.play; return withQuery( `/projects/${encodePath(project)}/post/${encodeURIComponent(id)}`, play ? { from: "play", at: play.at != null && play.at > 0 ? play.at.toFixed(2) : null } : {}, ); } export function clipBenchHref( project: string, clip: string, q: NoteOpt & { /** * Opened from Play the cut ("Edit this clip"): the bench offers "Back to * the cut", landing `at` seconds into this clip. `take` is the take that * was playing -- said on the bench, because the edit goes to the * project's manifest and not to the take's render. */ play?: { at?: number | null; take?: string | null } | null; } = {}, ): string { const play = q.play; return withQuery( `/projects/${encodePath(project)}/clip/${encodeURIComponent(clip)}`, play ? { from: "play", at: play.at != null && play.at > 0 ? play.at.toFixed(2) : null, take: play.take ?? null } : {}, q.note, ); } /** The claim bench, one ledger entry. */ export function claimBenchHref(project: string, claim: string, q: NoteOpt = {}): string { return withQuery(`/projects/${encodePath(project)}/claim/${encodeURIComponent(claim)}`, {}, q.note); } /** Alternative renders of one part of a cut. */ /** The trailer's beats (promo/trailer-beats.json), or another beat reel's (`?reel=`: promo/-beats.json). */ export function trailerHref(project: string, q: { reel?: string | null } = {}): string { return withQuery(`/projects/${encodePath(project)}/trailer`, { reel: q.reel && q.reel !== "trailer" ? q.reel : null }); } /** A beat reel's Play view: its beats played from a take's rendered master (`take`, else the reel's own choice), from beat `beat`. */ export function reelPlayHref(project: string, q: NoteOpt & { reel?: string | null; take?: string | null; beat?: number | null } = {}): string { return withQuery( `/projects/${encodePath(project)}/trailer/play`, { reel: q.reel && q.reel !== "trailer" ? q.reel : null, take: q.take, beat: q.beat != null && q.beat > 1 ? q.beat : null }, q.note, ); } /** A beat reel's walk: the bench over beat `beat` (from 1) on the take's master; `changed` walks only the beats the take changed. */ export function reelWalkHref(project: string, q: { reel?: string | null; take?: string | null; beat?: number | null; changed?: boolean } = {}): string { return withQuery(`/projects/${encodePath(project)}/trailer/walk`, { reel: q.reel && q.reel !== "trailer" ? q.reel : null, take: q.take, beat: q.beat ?? 1, changed: q.changed ? "1" : null }); } export function takesHref(project: string, q: NoteOpt = {}): string { return withQuery(`/projects/${encodePath(project)}/takes`, {}, q.note); } /** Two takes side by side -- of the project or of its variants (`:` each). */ export function takesCompareHref(project: string, a: string, b: string, q: NoteOpt = {}): string { return withQuery(`/projects/${encodePath(project)}/takes/compare`, { a, b }, q.note); } /** * Walk a take: the take's clips, the walk's start (an overview of every clip, * and where the walk begins). `all`: the walk visits every fetched clip, judged * or not, rather than only the ones still needing a verdict. */ export function takeWalkHref(project: string, take: string, q: NoteOpt & { all?: boolean } = {}): string { return withQuery(`/projects/${encodePath(project)}/takes/${encodeURIComponent(take)}/walk`, { all: q.all }, q.note); } /** A version's review pass (umtool redesign L7b): watched block by block, read-only, its verdict at the end. */ export function versionReviewHref(project: string, take: string): string { return workspaceHref(project, { mode: "review", take }); } /** * The clip bench on one of a take's clips: its saves go into the take's patch, never the project's manifest. * `play`: opened from Play on this take (Edit this clip, on a take with its own timeline) -- the bench offers * "Back to the cut", landing on Play of THIS take `at` seconds into the clip. */ export function takeClipHref( project: string, take: string, clip: string, q: NoteOpt & { all?: boolean; play?: { at?: number | null } | null } = {}, ): string { const play = q.play; return withQuery( `/projects/${encodePath(project)}/takes/${encodeURIComponent(take)}/clip/${encodeURIComponent(clip)}`, { all: q.all, ...(play ? { from: "play", at: play.at != null && play.at > 0 ? play.at.toFixed(2) : null } : {}) }, q.note, ); } /** * OPEN A VERSION IN THE DRAFT (umtool redesign L3; components/projects/OpenInDraftPage.tsx): the page that * asks first -- "Open v1 in draft? Your draft (N edits) is saved as vN+1 first." -- or, when the version is * the draft's parent with no edits, goes straight on (307) to the draft's bench on `clip` (a post item's when * `post`), else to Play of the draft. `play`: opened from Play (the bench's Back returns to Play, `at` seconds * into the clip). */ export function openInDraftHref( project: string, take: string, q: NoteOpt & { clip?: string | null; post?: boolean; play?: { at?: number | null } | null } = {}, ): string { const play = q.play; return withQuery( `/projects/${encodePath(project)}/takes/${encodeURIComponent(take)}/open`, { clip: q.clip ?? null, post: q.clip && q.post ? "1" : null, ...(play ? { from: "play", at: play.at != null && play.at > 0 ? play.at.toFixed(2) : null } : {}), }, q.note, ); } /** What the clip deck (release 34) walks: every instance, the unruled, the doubtful first, the ruled. */ export const CLIP_DECK_SHOWS = ["all", "unruled", "doubtful", "ruled"] as const; export type ClipDeckShow = (typeof CLIP_DECK_SHOWS)[number]; /** The montage clip deck: every instance ruled keep / cut / not him / read aloud (release 34). */ export function clipDeckHref(project: string, q: NoteOpt & { show?: ClipDeckShow } = {}): string { return withQuery(`/projects/${encodePath(project)}/clips`, q.show ? { show: q.show } : {}, q.note); } /** * The clip editor (release 35 C2): the same address as the deck. A cut with * no montage opens it; `mode: "edit"` opens it on a montage too; `clip` * selects one clip. */ export function clipEditorHref(project: string, q: NoteOpt & { clip?: string; mode?: "edit" } = {}): string { return withQuery(`/projects/${encodePath(project)}/clips`, { ...(q.mode ? { mode: q.mode } : {}), ...(q.clip ? { clip: q.clip } : {}) }, q.note); } /** * The Play view (umtool/docs/knobs.md, "Play the cut"): the whole cut played in the browser * in its final look, no render; `take` plays that take (the project's * manifest with its patches). */ export function playHref( project: string, q: NoteOpt & { take?: string | null; /** The project's manifest alone, no take's patch (`?cut=1`): the draft, which is the default too. */ bare?: boolean; /** Start on this clip, `at` seconds into what the page shows of it (the bench's Back to the cut). */ clip?: string | null; at?: number | null; } = {}, ): string { // A BARE `/play` is the workspace's now (umtool redesign L7b: a 308 to the project's own address), so Play's // own page is always asked for with something in its query: `?cut=1` (the draft) when nothing else is. const clip = q.clip || null; return withQuery( `/projects/${encodePath(project)}/play`, { take: q.take, cut: !q.take && (q.bare || (!clip && !q.note)) ? "1" : null, clip, at: clip && q.at != null && q.at > 0 ? q.at.toFixed(2) : null }, q.note, ); } /** * PRESENT MODE (umtool/docs/knobs.md, "Present mode"): the cut -- or `take` -- as slides, navigated like a deck; * `slide` opens on that slide (its id: a post's `/`, a clip's id, `section-`, `day-`). * With no take, the latest take (the working cut), as Play. */ export function presentHref(project: string, q: { take?: string | null; bare?: boolean; slide?: string | null } = {}): string { // The workspace's present mode (umtool redesign L7b); the old `/present` address 308s here. return workspaceHref(project, { mode: "present", take: q.take ?? null, slide: q.slide ?? null }); } /** A video's READS (lane reads-find): every line a voice reads, Find / Replace, the re-read queue -- filtered by state or character. */ export function readsHref(project: string, q: { state?: "stale" | null; character?: string | null } = {}): string { return withQuery(`/projects/${encodePath(project)}/reads`, { ...(q.state ? { state: q.state } : {}), ...(q.character ? { character: q.character } : {}) }); } /** The narration script, card by card. */ export function narrationHref(project: string, q: NoteOpt = {}): string { return withQuery(`/projects/${encodePath(project)}/narration`, {}, q.note); } /** The recording session: a person reads the cut's post items aloud, part by part (lane/post-narration). */ export function narrationRecordHref(project: string, q: { post?: string | null } = {}): string { return withQuery(`/projects/${encodePath(project)}/narration/record`, q.post ? { post: q.post } : {}); } /** The project's voices: each character's voice, auditions, the cast (operator, 6 Nov: per-character voices). */ export function voicesHref(project: string, q: { who?: string | null } = {}): string { return withQuery(`/projects/${encodePath(project)}/voices`, q.who ? { who: q.who } : {}); } /** The drafts review (release 28). */ export function reviewHref(project: string, q: NoteOpt & { view?: "list" } = {}): string { return withQuery(`/projects/${encodePath(project)}/review`, q.view ? { view: q.view } : {}, q.note); } /** One cut of a song; `plan` opens a plan of it, `v` a variant row. */ export function cutHref(song: string, cut: string, q: { plan?: string; v?: string } = {}): string { return withQuery(`/projects/${encodePath(song)}/${encodeURIComponent(cut)}`, q); } // ── tools ─────────────────────────────────────────────────────────────────── /** Every occurrence of a word across the corpus. */ export function findHref(q: Query = {}): string { return withQuery("/tools/find", q); } /** * The phrase finder (release 34): how often phrases were said, by year, and a * montage from one. `q` prefills the first phrase. */ export function phraseFinderHref(q: { q?: string; scan?: string } = {}): string { return withQuery("/tools/phrases", q); } /** The face judger; `cover` opens on one cover's corners. */ export function facesHref(q: { cover?: string } = {}): string { return withQuery("/tools/faces", q); } /** Where the palette comes from, across every song. */ export function sourcesHref(): string { return "/tools/sources"; } /** A trim set's bench. */ export function trimHref(set: string): string { return `/tools/trim/${encodeURIComponent(set)}`; } export type MixQuery = { body?: string; start?: string | number; end?: string | number; from?: string; clip?: string }; /** The mix bench; the deep link is resolved server-side (lib/mix-preset.ts). */ export function mixHref(q: MixQuery = {}): string { return withQuery("/tools/mix", q); } /** A song judging pile (`/tools/song/sort`, `…/salvage`, `…/verify`, `…/keeps`). */ export function pileHref(mode: string, q: { limit?: number; only?: string } = {}): string { return withQuery(`/tools/song/${encodeURIComponent(mode)}`, q); } /** Release 28's verdict bench: could a model propose a fact-check verdict? */ export function benchHref(q: { run?: string; model?: string; verdict?: string } = {}): string { return withQuery("/tools/bench", q); } /** The channel context notes awaiting review (plans/digest-context-review.md): Yes or No on each. */ export function digestContextHref(): string { return "/tools/digest-context"; } /** The Posts library (lane posts-library): a private trending library's topics and posts, judged. */ export function postsLibraryHref(view: Parameters[0] = {}): string { return libraryViewHref(view); } /** Every tool. */ export function toolsHref(): string { return "/tools"; } /** The song tools: the four judging piles. */ export function songToolsHref(): string { return "/tools/song"; } // ── ingredients (lane L5) ─────────────────────────────────────────────────── /** * ONE RECORDING'S LIFE CYCLE (lib/ingredients/stages.mjs): `/ingredients//