// --------------------------------------------------------------------------- // The generation policy in one line (plans/umtool-redesign.md, P5): Create's // policy chip and the Settings page's head say where each kind of task runs, // grouped by route -- "Claude Code: sweeps · API: report revisions, research · // local: video revisions, drafts" for the balanced preset. // // Plain ESM, no imports: a server page, a client component and `node --test` // read the same function. // --------------------------------------------------------------------------- /** How a route is said. */ export const ROUTE_WORD = { code: "Claude Code", api: "API", local: "local" }; /** The media drafts (release 28) and narration: one word, "drafts", when they agree. */ const DRAFT_TASKS = ["narrate", "cut", "onscreen", "teaser", "flips", "threads", "youtube", "social"]; /** One task's word when it is said alone. */ const TASK_WORD = { sweep: "sweeps", "revise-report": "report revisions", "revise-video": "video revisions", research: "research", narrate: "narration", cut: "cut drafts", onscreen: "on-screen drafts", teaser: "teaser drafts", flips: "flips drafts", threads: "threads drafts", youtube: "YouTube drafts", social: "social post drafts", "clips-suggest": "clip labels", "video-assist": "the video assistant", "propose-groups": "claim groups for a cut", "cast-assign": "character proposals", lookout: "lookouts", }; /** * The routes, grouped: `[{ route, words }]` in the order code → api → local, * each with the tasks that run there in the policy's task order. The draft * tasks read as "drafts" when they all share a route; the two revisions as * "revisions" when they do. * @param {Record} routes task -> route * @param {readonly string[]} [tasks] the order tasks are said in * @returns {{ route: string, words: string[] }[]} */ export function routeGroups(routes, tasks = Object.keys(routes)) { const present = tasks.filter((t) => typeof routes[t] === "string"); const drafts = DRAFT_TASKS.filter((t) => present.includes(t)); const draftsAgree = drafts.length > 1 && drafts.every((t) => routes[t] === routes[drafts[0]]); const revisionsAgree = present.includes("revise-report") && present.includes("revise-video") && routes["revise-report"] === routes["revise-video"]; const said = new Set(); /** @type {Map} */ const by = new Map(); const add = (route, word) => { if (!by.has(route)) by.set(route, []); by.get(route).push(word); }; for (const t of present) { if (said.has(t)) continue; if (draftsAgree && drafts.includes(t)) { drafts.forEach((d) => said.add(d)); add(routes[t], "drafts"); continue; } if (revisionsAgree && (t === "revise-report" || t === "revise-video")) { said.add("revise-report"); said.add("revise-video"); add(routes[t], "revisions"); continue; } said.add(t); add(routes[t], TASK_WORD[t] ?? t); } const order = ["code", "api", "local"]; return [...by.entries()] .sort((a, b) => (order.indexOf(a[0]) + 99) % 99 - (order.indexOf(b[0]) + 99) % 99) .map(([route, words]) => ({ route, words })); } /** * The policy in one line: "Claude Code: sweeps · API: report revisions, * research · local: video revisions, drafts", or "everything on the API". * @param {Record} routes * @param {readonly string[]} [tasks] */ export function routeSummary(routes, tasks) { const groups = routeGroups(routes, tasks); if (groups.length === 1) return `everything ${groups[0].route === "local" ? "local" : `on ${groups[0].route === "api" ? "the API" : "Claude Code"}`}`; return groups.map((g) => `${ROUTE_WORD[g.route] ?? g.route}: ${g.words.join(", ")}`).join(" · "); } /** * The chip's words: "balanced · Claude Code: sweeps · …", or the reason the * policy is unknown. * @param {{ preset: string, routes: Record } | null} generation * @param {readonly string[]} [tasks] */ export function policyChip(generation, tasks) { if (!generation) return "Generation: the editor did not answer"; return `Generation: ${generation.preset} · ${routeSummary(generation.routes, tasks)}`; }