import { GENERATION_PRESETS, GENERATION_PRESET_NAMES, GENERATION_ROUTES, GENERATION_TASKS, isStepTask, type GenerationPreset, } from "yt-dlp-transcript-common/lib/generationSettings"; import { AUTONOMIES } from "yt-dlp-transcript-common/lib/report/draft/research/decide"; import { describeEditorFailure, editorGet, editorPost, type EditorAnswer } from "./editorOps"; import type { FetchClipDeps, PollProgress } from "./fetchClip"; import { mediaReviewGuidance, reviewGuidance, type GenerationRoute, type PlanGeneration } from "./instructions"; import type { ToolAnswer } from "./archivalTools"; // An iteration's run records — the model's turns, the sweep's trace, the model // log — are read through the editor (the run page, `umtool model-log`), never // listed as paths on the editor's disk. const RUN_RECORD_FILES: ReadonlySet = new Set(["turns.jsonl", "trace.jsonl", "calls.jsonl", "calls-text.jsonl"]); // ─── The Claude Code balance (release 27 S9; D8) ─── // // Report and video generation runs in the editor, as `report-draft` jobs on // the Claude API or the local model, routed per task by settings.generation. // These two tools are Claude Code's side of that balance: // // generation_policy GET /api/ops/settings?key=generation (the routes) // GET /api/ops/generation-usage (the day's spend) // POST /api/ops/settings {patch: {generation: {routes}}} // — a preset or one route, ONLY when the operator asks // generate POST /api/ops/report-draft (enqueue) // GET /api/ops/job/?tail=N (follow) // GET /api/ops/iterations?article=&n= (the result) // // The release 19 ruling keeps settings out of the MCP; D8 (ratified // 2026-10-13) makes the generation ROUTES the one exception, so the operator // can move the balance from a Claude Code session. Nothing else in settings is // reachable, and the API key never is: it is not a setting (only its file's // path is, and the editor redacts that), and this module renders neither. // // Pure apart from the injected deps (env, fetch, sleep, now); server.ts adapts. export type GenerationDeps = FetchClipDeps; // The policy as the editor answers it (sanitizeGeneration's output). export type GenerationPolicy = PlanGeneration & { models: { api: string; local: string; extractor?: string }; caps?: { sweep?: number; revision?: number; narration?: number; daily?: number; max?: number }; }; export type GenerationUsageDay = { day: string; usd: number; jobs: number; daily: number }; // The tasks `generate` takes: the policy's (research included, S11). // Not `frames`: a frame scan is `frame-scan`, not a generation of an article. // Not `cast-assign` (characters C3): its answers mean nothing until umtool lays them over its own proposed rows // (`umtool cast assign

--model`); a session answers it with `pnpm ops report-draft` and `answers`. // A lookout run is `pnpm ops lookout-run`, not a generation this tool starts. export const GENERATE_TASKS = [...new Set([...GENERATION_TASKS.filter((t) => t !== "frames" && t !== "cast-assign" && t !== "lookout"), "research"])]; const ARTICLE_RE = /^[a-z0-9][a-z0-9-]{0,63}$/; const JOB_RE = /^[A-Za-z0-9_-]+$/; const trimmed = (v: unknown) => (typeof v === "string" ? v.trim() : ""); const isRoute = (v: unknown): v is GenerationRoute => typeof v === "string" && (GENERATION_ROUTES as readonly string[]).includes(v); // The editor's `generation` block, or why not. function policyOf(value: unknown): GenerationPolicy | null { if (!value || typeof value !== "object") return null; const v = value as Record; const routes = v.routes && typeof v.routes === "object" ? (v.routes as Record) : null; const models = v.models && typeof v.models === "object" ? (v.models as Record) : null; if (!routes || !models || typeof models.api !== "string" || typeof models.local !== "string") return null; const r: Record = {}; for (const [task, route] of Object.entries(routes)) if (isRoute(route)) r[task] = route; return { preset: typeof v.preset === "string" ? v.preset : "custom", routes: r, models: { api: models.api, local: models.local, ...(typeof models.extractor === "string" ? { extractor: models.extractor } : {}), }, ...(v.caps && typeof v.caps === "object" ? { caps: v.caps as GenerationPolicy["caps"] } : {}), }; } export async function readPolicy( deps: GenerationDeps, ): Promise<{ ok: true; policy: GenerationPolicy } | { ok: false; answer: Exclude | null }> { const a = await editorGet(deps, "/api/ops/settings?key=generation"); if (a.kind !== "ok") return { ok: false, answer: a }; const policy = policyOf(a.body.value); return policy ? { ok: true, policy } : { ok: false, answer: null }; } async function readUsage(deps: GenerationDeps): Promise { const a = await editorGet(deps, "/api/ops/generation-usage"); if (a.kind !== "ok") return describeEditorFailure("the day's spend", a); const b = a.body; if (typeof b.usd !== "number" || typeof b.day !== "string") return "the day's spend: the editor's answer carried none"; return { day: b.day, usd: b.usd, jobs: Number(b.jobs) || 0, daily: Number(b.daily) || 0 }; } // What a plan needs: the policy when the editor answers, else nothing (with a // note when an editor was configured and did not answer). export async function planGeneration(deps: GenerationDeps): Promise<{ generation?: PlanGeneration; note?: string }> { const r = await readPolicy(deps); if (r.ok) return { generation: { preset: r.policy.preset, routes: r.policy.routes, models: { api: r.policy.models.api, local: r.policy.models.local } } }; if (r.answer?.kind === "no_editor") return {}; return { note: `the generation policy could not be read (${r.answer ? describeEditorFailure("generation_policy", r.answer) : "the editor's answer carried no generation block"}) — ` + `this plan is for this session`, }; } const usd = (n: number) => `$${n.toFixed(2)}`; export function renderPolicy(p: GenerationPolicy, usage: GenerationUsageDay | string | null, changed?: string): string { const lines: string[] = []; if (changed) lines.push(changed, ""); lines.push(`Generation policy (settings.generation): preset **${p.preset}**`); for (const [task, route] of Object.entries(p.routes)) { lines.push( `- ${task} → ${route}` + (route === "code" ? " (this Claude Code session)" : ` (${route === "api" ? "the Claude API" : "the local model"}, ${p.models[route]})`), ); } lines.push( `Models: api ${p.models.api} · local ${p.models.local}${p.models.extractor ? ` · extractor ${p.models.extractor}` : ""}`, ); const c = p.caps; if (c) { const parts = [ c.sweep !== undefined ? `sweep ${usd(c.sweep)}` : "", c.revision !== undefined ? `revision ${usd(c.revision)}` : "", c.narration !== undefined ? `narration ${usd(c.narration)}` : "", c.max !== undefined ? `any job at most ${usd(c.max)}` : "", c.daily !== undefined ? (c.daily > 0 ? `daily ${usd(c.daily)}` : "no daily cap") : "", ].filter(Boolean); if (parts.length) lines.push(`Caps (Claude API, per job unless said): ${parts.join(" · ")}`); } if (typeof usage === "string") lines.push(`Today's spend: unknown (${usage})`); else if (usage) { lines.push( `Today (${usage.day}, UTC): ${usd(usage.usd)} spent on the Claude API in ${usage.jobs} job(s)` + (usage.daily > 0 ? ` of the ${usd(usage.daily)} daily cap` : ""), ); } lines.push( "", "A task routed to api or local: call generate (wait: true) and REVIEW what it makes. " + "A task routed to code: do it in this session (/sweep for a report). " + "Change the routes only when the operator asks (generation_policy with preset, or task and route).", ); return lines.join("\n"); } // ─── generation_policy ─── export async function generationPolicyTool(args: Record, deps: GenerationDeps): Promise { const preset = trimmed(args.preset); const task = trimmed(args.task); const route = trimmed(args.route); if (preset && (task || route)) { return { text: "generation_policy: give a preset, or a task and its route — not both", isError: true }; } if ((task && !route) || (route && !task)) { return { text: "generation_policy: a route change names both task and route (code, api or local)", isError: true }; } if (preset && !(GENERATION_PRESET_NAMES as string[]).includes(preset)) { return { text: `generation_policy: preset is one of ${GENERATION_PRESET_NAMES.join(", ")}`, isError: true }; } if (route && !isRoute(route)) { return { text: `generation_policy: route is one of ${GENERATION_ROUTES.join(", ")}`, isError: true }; } const read = await readPolicy(deps); if (!read.ok) { return { text: read.answer ? describeEditorFailure("generation_policy", read.answer) : "generation_policy: the editor's answer carried no generation block", isError: true, }; } const policy = read.policy; if (!preset && !task) return { text: renderPolicy(policy, await readUsage(deps)) }; if (task && !Object.hasOwn(policy.routes, task)) { return { text: `generation_policy: no task "${task}" — the policy routes ${Object.keys(policy.routes).join(", ")}`, isError: true }; } // The ROUTES are the truth (S6): a preset is written as its routes, and the // preset is read back from them. The patch names the whole routes object — // the settings writer merges one level, so a nested object replaces. const routes: Record = preset ? { ...policy.routes, ...GENERATION_PRESETS[preset as GenerationPreset] } : { ...policy.routes, [task]: route as GenerationRoute }; const a = await editorPost(deps, "/api/ops/settings", { patch: { generation: { routes } } }); if (a.kind !== "ok") return { text: describeEditorFailure("generation_policy", a), isError: true }; const saved = policyOf((a.body.value as Record | undefined)?.generation) ?? { ...policy, routes }; const what = preset ? `Set preset ${preset}.` : `Routed ${task} to ${route}.`; return { text: renderPolicy(saved, await readUsage(deps), what) }; } // ─── generate ─── export const GENERATE_POLL_MS = 5000; export const DEFAULT_GENERATE_WAIT_SECONDS = 90; export const MAX_GENERATE_WAIT_SECONDS = 300; const RESULT_MARKER = "@@report-draft "; const SUMMARY_TAIL = 60; type Body = Record; export type GenerateRequest = | { kind: "start"; body: Body; via?: "api" | "local"; wait: boolean; waitSeconds: number } | { kind: "resume"; job: string; article?: string; iteration?: number; waitSeconds: number }; function waitSecondsOf(v: unknown): number | null { if (v === undefined) return DEFAULT_GENERATE_WAIT_SECONDS; if (typeof v !== "number" || !Number.isFinite(v) || v < 0) return null; return Math.min(MAX_GENERATE_WAIT_SECONDS, Math.round(v)); } // The arguments, checked as far as the tool can say without asking; the // editor judges the rest (controller/reportDraft.ts parseReportDraftBody). export function validateGenerateArgs(args: Record): { ok: true; request: GenerateRequest } | { ok: false; error: string } { const bad = (error: string) => ({ ok: false as const, error: `generate: ${error}` }); const waitSeconds = waitSecondsOf(args.wait_seconds); if (waitSeconds === null) return bad("wait_seconds is a number of seconds, 0 or more"); const intOf = (k: string): number | undefined | null => { const v = args[k]; if (v === undefined) return undefined; return typeof v === "number" && Number.isInteger(v) && v >= 1 ? v : null; }; const job = trimmed(args.job); if (job) { if (!JOB_RE.test(job)) return bad(`"${job}" is not a job id`); const article = trimmed(args.article); if (article && !ARTICLE_RE.test(article)) return bad(`"${article}" is not an article id`); const iteration = intOf("iteration"); if (iteration === null) return bad("iteration is an iteration number (1, 2, …)"); return { ok: true, request: { kind: "resume", job, ...(article ? { article } : {}), ...(iteration ? { iteration } : {}), waitSeconds }, }; } const task = trimmed(args.task); if (!GENERATE_TASKS.includes(task)) return bad(`task is one of ${GENERATE_TASKS.join(", ")}`); if (task === CLIPS_SUGGEST) return validateClipsSuggestArgs(args, waitSeconds); if (task === VIDEO_ASSIST) return validateVideoAssistArgs(args, waitSeconds); if (task === PROPOSE_GROUPS) return validateProposeGroupsArgs(args, waitSeconds); if (args.project !== undefined || args.answers !== undefined || args.proposals !== undefined) return bad("project, proposals and answers are a clips-suggest job's"); if (args.request !== undefined || args.scope !== undefined || args.note !== undefined) return bad("request, scope and note are a video-assist job's"); const article = trimmed(args.article); if (!ARTICLE_RE.test(article)) return bad("article is an article id (a lowercase slug: a-z, 0-9, -)"); const body: Body = { task, article }; for (const k of ["iteration", "copyOf"] as const) { const n = intOf(k); if (n === null) return bad(`${k} is an iteration number (1, 2, …)`); if (n !== undefined) body[k] = n; } if (args.source !== undefined && args.source !== null) { const src = trimmed(args.source); if (!/^(local|remote|hub):\S+/.test(src)) return bad("source is a corpus handle: remote:, hub: or local:

"); if (task !== "sweep" && task !== "research") return bad("source is a sweep's or a research run's (the corpus it reads)"); body.source = src; } for (const k of ["model", "extractorModel", "feedback", "question", "from", "to"] as const) { if (args[k] === undefined) continue; const v = trimmed(args[k]); if (!v) return bad(`${k} is text`); body[k] = v; } if (body.extractorModel !== undefined) { if (task !== "sweep") return bad("extractorModel is a sweep's (the extractor an API sweep reads batches with)"); if (!String(body.extractorModel).startsWith("claude-")) return bad("extractorModel is a Claude model id: an API sweep's extractor runs on the API"); } for (const k of ["channels", "cards", "entries"] as const) { if (args[k] === undefined) continue; const v = args[k]; if (!Array.isArray(v) || v.length === 0 || v.some((x) => typeof x !== "string" || !x.trim())) { return bad(`${k} is a non-empty list of names`); } body[k] = v.map((x: string) => x.trim()); } if (args.maxUsd !== undefined) { if (typeof args.maxUsd !== "number" || !(args.maxUsd > 0)) return bad("maxUsd is a positive number of dollars"); body.maxUsd = args.maxUsd; } if (args.force !== undefined) { if (typeof args.force !== "boolean") return bad("force is true or false"); body.force = args.force; } if (args.autonomy !== undefined) { const a = trimmed(args.autonomy); if (!(AUTONOMIES as readonly string[]).includes(a)) return bad(`autonomy is one of ${AUTONOMIES.join(", ")}`); if (task !== "research") return bad("autonomy is a research run's"); body.autonomy = a; } let via: "api" | "local" | undefined; if (args.via !== undefined) { const v = trimmed(args.via); if (v !== "api" && v !== "local") return bad('via is "api" or "local" (a task routed to code is this session\'s)'); if (body.model) return bad("give model or via, not both"); via = v; } // A media draft (release 28) is a step on a done iteration: it names it. if (isStepTask(task)) { if (body.iteration === undefined) return bad(`a ${task} draft names the iteration it drafts on (iteration)`); if (body.copyOf !== undefined) return bad(`a ${task} draft is a step on its iteration: it has no copyOf`); for (const k of ["question", "feedback", "channels", "from", "to"] as const) { if (body[k] !== undefined) return bad(`${k} is not a ${task} draft's: it drafts from the iteration's report and cut`); } } else if (body.entries !== undefined) return bad("entries is a media draft's (cut, onscreen, teaser, flips, threads, narrate, youtube, social)"); if (args.wait !== undefined && typeof args.wait !== "boolean") return bad("wait is true or false"); return { ok: true, request: { kind: "start", body, ...(via ? { via } : {}), wait: args.wait === true, waitSeconds } }; } // ─── clips-suggest (release 36 lane D): the clip finder's labels, on a umtool project ─── const CLIPS_SUGGEST = "clips-suggest"; const PROPOSAL_RE = /^[A-Za-z0-9._:-]{1,64}$/; function validateClipsSuggestArgs(args: Record, waitSeconds: number): { ok: true; request: GenerateRequest } | { ok: false; error: string } { const bad = (error: string) => ({ ok: false as const, error: `generate: ${error}` }); const project = trimmed(args.project); if (!project.startsWith("/")) return bad("a clips-suggest job names its project: the reactions project's absolute directory (project)"); for (const k of ["article", "iteration", "copyOf", "question", "channels", "feedback", "from", "to", "cards", "entries", "force", "autonomy", "extractorModel"] as const) { if (args[k] !== undefined) return bad(`${k} is not a clips-suggest job's (it reads its project)`); } const body: Body = { task: CLIPS_SUGGEST, project }; if (args.model !== undefined) { const m = trimmed(args.model); if (!m) return bad("model is text"); body.model = m; } if (args.maxUsd !== undefined) { if (typeof args.maxUsd !== "number" || !(args.maxUsd > 0)) return bad("maxUsd is a positive number of dollars"); body.maxUsd = args.maxUsd; } if (args.proposals !== undefined) { const v = args.proposals; if (!Array.isArray(v) || !v.length || v.some((x) => typeof x !== "string" || !PROPOSAL_RE.test(x.trim()))) return bad("proposals is a non-empty list of proposal ids"); body.proposals = v.map((x: string) => x.trim()); } if (args.answers !== undefined) { if (!args.answers || typeof args.answers !== "object" || Array.isArray(args.answers)) return bad('answers is {"items": [{"id", "label", "why", "score"}]}'); if (body.model) return bad("answers are this session's: no model"); body.answers = args.answers; } let via: "api" | "local" | undefined; if (args.via !== undefined) { const v = trimmed(args.via); if (v !== "api" && v !== "local") return bad('via is "api" or "local"'); if (body.model || body.answers) return bad("give model, via or answers — one"); via = v; } if (args.wait !== undefined && typeof args.wait !== "boolean") return bad("wait is true or false"); return { ok: true, request: { kind: "start", body, ...(via ? { via } : {}), wait: args.wait === true, waitSeconds } }; } // ─── video-assist (release 38 lane E): the video assistant, on a umtool project ─── const VIDEO_ASSIST = "video-assist"; const NOTE_RE = /^n_[a-z0-9]{4,32}$/; function validateVideoAssistArgs(args: Record, waitSeconds: number): { ok: true; request: GenerateRequest } | { ok: false; error: string } { const bad = (error: string) => ({ ok: false as const, error: `generate: ${error}` }); const project = trimmed(args.project); if (!project.startsWith("/")) return bad("a video-assist job names its project: the video project's absolute directory (project)"); for (const k of ["article", "iteration", "copyOf", "question", "channels", "feedback", "from", "to", "cards", "entries", "force", "autonomy", "extractorModel", "proposals"] as const) { if (args[k] !== undefined) return bad(`${k} is not a video-assist job's (it reads its project)`); } const body: Body = { task: VIDEO_ASSIST, project }; if (args.request !== undefined) { const r = trimmed(args.request); if (!r) return bad("request is what to change, in words"); body.request = r; } if (args.note !== undefined) { const n = trimmed(args.note); if (!NOTE_RE.test(n)) return bad("note is a note id (n_…)"); body.note = n; } if (!body.request && !body.note) return bad("a video-assist job needs its request (what to change), or the note whose text is one"); if (body.request && body.note) return bad("give request or note, not both"); if (args.scope !== undefined) { const sc = trimmed(args.scope); if (!["look", "clips", "fx", "all"].includes(sc)) return bad("scope is look, clips, fx or all"); body.scope = sc; } if (args.model !== undefined) { const m = trimmed(args.model); if (!m) return bad("model is text"); body.model = m; } if (args.maxUsd !== undefined) { if (typeof args.maxUsd !== "number" || !(args.maxUsd > 0)) return bad("maxUsd is a positive number of dollars"); body.maxUsd = args.maxUsd; } if (args.answers !== undefined) { if (!args.answers || typeof args.answers !== "object" || Array.isArray(args.answers)) return bad('answers is {"ops": [{"op", "id", "key", "value"}], "reply"}'); if (body.model) return bad("answers are this session's: no model"); body.answers = args.answers; } let via: "api" | "local" | undefined; if (args.via !== undefined) { const v = trimmed(args.via); if (v !== "api" && v !== "local") return bad('via is "api" or "local"'); if (body.model || body.answers) return bad("give model, via or answers — one"); via = v; } if (args.wait !== undefined && typeof args.wait !== "boolean") return bad("wait is true or false"); return { ok: true, request: { kind: "start", body, ...(via ? { via } : {}), wait: args.wait === true, waitSeconds } }; } // ─── propose-groups (lane L4): claim groups proposed for a umtool project's cut ─── const PROPOSE_GROUPS = "propose-groups"; function validateProposeGroupsArgs(args: Record, waitSeconds: number): { ok: true; request: GenerateRequest } | { ok: false; error: string } { const bad = (error: string) => ({ ok: false as const, error: `generate: ${error}` }); const project = trimmed(args.project); if (!project.startsWith("/")) return bad("a propose-groups job names its project: the video project's absolute directory (project)"); for (const k of ["article", "iteration", "copyOf", "question", "channels", "feedback", "from", "to", "cards", "entries", "force", "autonomy", "extractorModel", "proposals", "scope", "note"] as const) { if (args[k] !== undefined) return bad(`${k} is not a propose-groups job's (it reads its project)`); } const body: Body = { task: PROPOSE_GROUPS, project }; if (args.request !== undefined) { const r = trimmed(args.request); if (r) body.request = r; } if (args.model !== undefined) { const m = trimmed(args.model); if (!m) return bad("model is text"); body.model = m; } if (args.maxUsd !== undefined) { if (typeof args.maxUsd !== "number" || !(args.maxUsd > 0)) return bad("maxUsd is a positive number of dollars"); body.maxUsd = args.maxUsd; } if (args.answers !== undefined) { if (!args.answers || typeof args.answers !== "object" || Array.isArray(args.answers)) return bad('answers is {"groups": [{"section", "claim", "ids", "why"}]}'); if (body.model) return bad("answers are this session's: no model"); body.answers = args.answers; } let via: "api" | "local" | undefined; if (args.via !== undefined) { const v = trimmed(args.via); if (v !== "api" && v !== "local") return bad('via is "api" or "local"'); if (body.model || body.answers) return bad("give model, via or answers — one"); via = v; } if (args.wait !== undefined && typeof args.wait !== "boolean") return bad("wait is true or false"); return { ok: true, request: { kind: "start", body, ...(via ? { via } : {}), wait: args.wait === true, waitSeconds } }; } type GroupsPlanView = { estimate?: { inputTokens?: number }; request?: { system?: string; user?: string } }; // The `code` route: this session proposes the groups the editor's plan describes. export function renderProposeGroupsRequest(body: Body, plan: GroupsPlanView, preset: string): string { const r = plan.request ?? {}; return [ `generate propose-groups: routed to Claude Code (preset ${preset}) — propose the claim groups for this cut in this session.`, `Read the cut below and give the groups, each {"section", "claim", "ids", "why"}: clips standing together in one section that make one claim.`, `Then call generate with task "propose-groups", project "${String(body.project)}"${body.request ? `, the same request ${JSON.stringify(String(body.request))}` : ""}, answers: {"groups": [...]} and wait: true — ` + "the editor checks each group exactly as a model's (clips not together, across a section boundary or in a group already are refused, with the reason) and writes group-proposals.json. " + "They are PROPOSALS: the operator accepts or rejects each in umtool (the Cut tab). Never write that file or the manifest yourself.", "", "## The instructions", r.system ?? "", "", "## The cut", r.user ?? "", ].join("\n"); } type GroupsMarker = { project?: string; groups?: { proposed?: number; refused?: number; file?: string | null } }; function proposeGroupsSummary(f: Extract, m: Marker & GroupsMarker): ToolAnswer { const g = m.groups ?? {}; const lines = [ `generate propose-groups: job ${f.job.id} ended **${f.job.status}** — ${m.summary ?? m.status ?? ""}`.trim(), `Project: ${m.project ?? "?"} · ${g.proposed ?? 0} proposed, ${g.refused ?? 0} refused` + (m.usd ? ` · $${m.usd.toFixed(4)}` : ""), "", "These are proposals in group-proposals.json: the operator accepts or rejects each in umtool (the Cut tab's group proposals). Nothing in the cut changed.", ]; return { text: lines.join("\n"), isError: f.job.status !== "done" }; } type AssistPlanView = { scope?: string; estimate?: { inputTokens?: number }; request?: { system?: string; user?: string } }; // The `code` route: this session answers the request the editor's plan names. export function renderVideoAssistRequest(body: Body, plan: AssistPlanView, preset: string): string { const r = plan.request ?? {}; const said = body.note ? `note ${String(body.note)}` : `request ${JSON.stringify(String(body.request ?? ""))}`; return [ `generate video-assist: routed to Claude Code (preset ${preset}) — answer this request on the project in this session (scope ${plan.scope ?? "all"}).`, `Read the project's settings below and give the ops that carry out the request, each {"op", "id", "key", "value"}, and a one-sentence reply.`, `Then call generate with task "video-assist", project "${String(body.project)}", the same ${said}${body.scope ? `, scope "${String(body.scope)}"` : ""}, answers: {"ops": [...], "reply": "..."} and wait: true — ` + "the editor checks your ops exactly as a model's (a value outside its bounds is refused, with the reason) and writes assist-proposals.json. " + "They are PROPOSALS: the operator applies them in umtool (the Look panel's Ask box). Never write that file or the manifest yourself.", "", "## The instructions", r.system ?? "", "", "## The project", r.user ?? "", ].join("\n"); } type AssistMarker = { project?: string; assist?: { proposed?: number; refused?: number; diff?: string[]; note?: string } }; function videoAssistSummary(f: Extract, m: Marker & AssistMarker): ToolAnswer { const a = m.assist ?? {}; const lines = [ `generate video-assist: job ${f.job.id} ended **${f.job.status}** — ${m.summary ?? m.status ?? ""}`.trim(), `Project: ${m.project ?? "?"} · ${a.proposed ?? 0} proposed, ${a.refused ?? 0} refused` + (m.usd ? ` · $${m.usd.toFixed(4)}` : ""), ...(a.diff ?? []).map((d) => `- ${d}`), "", "These are proposals in assist-proposals.json: the operator applies them in umtool (the Build tab's Look panel, Ask box: Apply / Dismiss" + (a.note ? `; the reply on note ${a.note} carries an Apply too` : "") + "). Nothing in the cut changed.", ]; return { text: lines.join("\n"), isError: f.job.status !== "done" }; } type SuggestPlanView = { proposals?: number; calls?: number; wordsFrom?: string; estimate?: { inputTokens?: number; outputTokens?: number; usd?: number }; request?: { system?: string; user?: string; ids?: string[] }; }; // The `code` route: this session answers the request the editor's plan names. export function renderClipsSuggestRequest(project: string, plan: SuggestPlanView, preset: string): string { const r = plan.request ?? {}; return [ `generate clips-suggest: routed to Claude Code (preset ${preset}) — label these ${plan.proposals ?? r.ids?.length ?? 0} proposals in this session.`, `Words from ${plan.wordsFrom ?? "?"}. Read the moments below and give, for EVERY id, a label (at most six words), why (one plain sentence) and score (1–10).`, `Then call generate with task "clips-suggest", project "${project}", answers: {"items": [{"id", "label", "why", "score"}, …]} and wait: true — ` + "the editor reads your answers exactly as a model's (a label over six words is refused) and writes clip-suggestions.json. " + "Never write that file, the manifest or a clip yourself; the labels never edit a clip.", "", "## The instructions", r.system ?? "", "", "## The moments", r.user ?? "", ].join("\n"); } function clipsSuggestSummary(f: Extract, m: Marker): ToolAnswer { const s = m.suggestions ?? {}; const lines = [ `generate clips-suggest: job ${f.job.id} ended **${f.job.status}** — ${m.summary ?? m.status ?? ""}`.trim(), `Project: ${m.project ?? "?"} · ${s.labelled ?? 0} labelled, ${s.refused ?? 0} refused, ${s.failed ?? 0} in failed batches` + (m.usd ? ` · $${m.usd.toFixed(4)}` : ""), "", "The labels are suggestions: the operator sees them in umtool's clip editor (Sort by the assistant's rank) and keeps, cuts or brings in clips there. Nothing in the cut changed.", ]; return { text: lines.join("\n"), isError: f.job.status !== "done" }; } type JobView = { id: string; status: string; kind?: string; detail?: string; queue?: { key: string; position: number; queued: number } }; type Followed = | { kind: "ended"; job: JobView; tail: string[] } | { kind: "waiting"; job: JobView; waited: number; last?: string } | { kind: "error"; text: string }; const ENDED = new Set(["done", "failed", "cancelled"]); async function jobOnce(deps: GenerationDeps, id: string, tail: number): Promise<{ job: JobView; tail: string[] } | { error: string }> { const a = await editorGet(deps, `/api/ops/job/${encodeURIComponent(id)}?tail=${tail}`); if (a.kind === "refused" && a.status === 404) return { error: `generate: the editor knows no job ${id}` }; if (a.kind !== "ok") return { error: `${describeEditorFailure("generate", a)} (job ${id} keeps running on the editor; resume with job: "${id}")` }; const job = a.body.job as JobView | undefined; if (!job || typeof job.status !== "string") return { error: "generate: the editor's answer carried no job" }; return { job, tail: Array.isArray(a.body.tail) ? (a.body.tail as unknown[]).map(String) : [] }; } // Poll the job politely (every GENERATE_POLL_MS) until it ends or the wait // runs out. A wait that runs out is not a failure: the job keeps running. export async function followGeneration( deps: GenerationDeps, id: string, waitSeconds: number, onPoll?: (p: PollProgress) => void | Promise, ): Promise { const started = deps.now(); const deadline = started + waitSeconds * 1000; const waited = () => Math.round((deps.now() - started) / 1000); let polls = 0; for (;;) { const r = await jobOnce(deps, id, 1); if ("error" in r) return { kind: "error", text: r.error }; if (ENDED.has(r.job.status)) { const full = await jobOnce(deps, id, SUMMARY_TAIL); return "error" in full ? { kind: "ended", job: r.job, tail: r.tail } : { kind: "ended", job: full.job, tail: full.tail }; } const last = r.tail[r.tail.length - 1]; if (deps.now() >= deadline) return { kind: "waiting", job: r.job, waited: waited(), ...(last ? { last } : {}) }; polls++; if (onPoll) { try { await onPoll({ jobId: id, status: last ? `${r.job.status}: ${last.slice(0, 120)}` : r.job.status, polls, waited: waited() }); } catch { /* a progress report is a courtesy */ } } await deps.sleep(GENERATE_POLL_MS); } } type Marker = { article?: string; iteration?: number; task?: string; status?: string; summary?: string; usd?: number; minutes?: number; // A verdicts job's (release 29 M8): no iteration (0). verdicts?: { proposed?: number; failed?: number; skipped?: number; promptVersion?: string }; // A clips-suggest job's (release 36 lane D): a project, no article. project?: string; suggestions?: { labelled?: number; refused?: number; failed?: number }; }; // What to do with verdict proposals: they are the operator's to rule. export const VERDICTS_REVIEW_GUIDANCE = "**The proposals are the operator's to rule**: they wait in umtool's Inbox (Review → Review verdicts) on the " + "article's tab, where each is approved or rejected; `pnpm ops verdict-review` does the same when the operator " + "asks. Never set a claim's verdict yourself, and never rule claims in this session in a proposal's place."; function verdictsSummary(f: Extract, m: Marker): ToolAnswer { const v = m.verdicts ?? {}; const lines = [ `generate verdicts: job ${f.job.id} ended **${f.job.status}** — ${m.summary ?? m.status ?? ""}`.trim(), `Article: ${m.article ?? "?"} · ${v.proposed ?? 0} proposed, ${v.failed ?? 0} failed, ${v.skipped ?? 0} skipped` + (v.promptVersion ? ` · prompt v${v.promptVersion}` : "") + (m.usd ? ` · $${m.usd.toFixed(4)}` : ""), "", VERDICTS_REVIEW_GUIDANCE, ]; return { text: lines.join("\n"), isError: f.job.status !== "done" }; } export function resultMarkerOf(tail: readonly string[]): Marker | null { for (let i = tail.length - 1; i >= 0; i--) { const at = tail[i].indexOf(RESULT_MARKER); if (at < 0) continue; try { return JSON.parse(tail[i].slice(at + RESULT_MARKER.length)) as Marker; } catch { return null; } } return null; } type IterationView = { n: number; kind: string; model: string; status: string; error?: string; parent: number | null; copyOf: number | null; usage: Record; ops?: { applied: unknown[]; refused: unknown[] }; minutes?: number; checks?: { name: string; ok: boolean; detail?: string }[]; steps?: { task: string; model?: string; status: string; cost?: number; jobId?: string; detail?: string }[]; projectDir?: string; // A research run's (S11): its autonomy, phase and notes. research?: { autonomy?: string; phase?: string; notes?: string[]; continuedBy?: number }; }; const MAX_LISTED = 12; // A refused op as the tasks store it: the op's own fields plus `why`. function opLine(o: unknown): string { const r = (o ?? {}) as { op?: { op?: string } | string; why?: string }; const name = typeof r.op === "string" ? r.op : (r.op?.op ?? "op"); return `${name}${r.why ? `: ${r.why}` : ""}`; } export function renderIterationSummary( o: { task: string; article: string; jobId: string; marker: Marker | null; iteration: IterationView; dir?: string; files?: Record }, ): string { const it = o.iteration; const step = isStepTask(o.task) ? [...(it.steps ?? [])].reverse().find((s) => s.task === o.task && s.jobId === o.jobId) : undefined; const status = step?.status ?? o.marker?.status ?? it.status; const lines: string[] = []; lines.push(`generate: ${o.task} of ${o.article} i${it.n} — **${status}** on ${step?.model ?? it.model} (job ${o.jobId})`); // A media draft's work is the video project's (release 29 D1): it comes // first, above the iteration's own files. const projectFirst = isStepTask(o.task) && !!it.projectDir; if (projectFirst) lines.push(`Video project: ${it.projectDir}`); if (o.marker?.summary) lines.push(o.marker.summary); if (it.error && status !== "done") lines.push(`error: ${it.error}`); if (step?.detail) lines.push(`${o.task === "narrate" ? "narration" : o.task}: ${step.detail}`); const per = Object.entries(it.usage ?? {}).filter(([, u]) => u.usd > 0); const total = step ? (step.cost ?? 0) : per.reduce((s, [, u]) => s + u.usd, 0); const minutes = o.marker?.minutes ?? it.minutes; lines.push( `Cost: ${usd(total)}` + (!step && per.length > 1 ? ` (${per.map(([m, u]) => `${m} ${usd(u.usd)}`).join(", ")})` : "") + (typeof minutes === "number" ? ` · ${minutes.toFixed(1)} min` : ""), ); if (it.ops) { const refused = it.ops.refused ?? []; lines.push(`Ops: ${it.ops.applied?.length ?? 0} applied, ${refused.length} refused`); for (const r of refused.slice(0, MAX_LISTED)) lines.push(` - refused ${opLine(r)}`); if (refused.length > MAX_LISTED) lines.push(` - … (+${refused.length - MAX_LISTED} more)`); } const checks = it.checks ?? []; if (checks.length) { const failing = checks.filter((c) => !c.ok); lines.push(`Checks: ${checks.length - failing.length} passed, ${failing.length} not`); for (const c of failing.slice(0, MAX_LISTED)) lines.push(` - ${c.name}${c.detail ? `: ${c.detail}` : ""}`); if (failing.length > MAX_LISTED) lines.push(` - … (+${failing.length - MAX_LISTED} more)`); } if (o.dir) { const present = Object.entries(o.files ?? {}).filter(([, p]) => p) as [string, string][]; lines.push(`Where (the editor's disk): ${o.dir}`); for (const [name, p] of present) if (!RUN_RECORD_FILES.has(name)) lines.push(` - ${name}: ${p}`); } if (it.projectDir && !projectFirst) lines.push(`Video project: ${it.projectDir}`); if (it.kind === "research") { const r = it.research ?? {}; lines.push(`Research: phase ${r.phase ?? "?"}, autonomy ${r.autonomy ?? "?"}${r.continuedBy ? `, continued by i${r.continuedBy}` : ""}`); for (const note of (r.notes ?? []).slice(0, MAX_LISTED)) lines.push(` - ${note}`); if (status === "done") lines.push("", researchGuidance(o.article, it.n)); } else if (status === "done" && isStepTask(o.task)) lines.push("", mediaReviewGuidance(o.task, it.projectDir)); else if (status === "done") lines.push("", reviewGuidance()); else if (status === "failed") lines.push("", "It failed: say why to the operator. Running it again, or here instead, is their call."); return lines.join("\n"); } // What to do with a finished research run: its proposals are the operator's to // approve, and a sweep over the widened scope continues it. function researchGuidance(article: string, n: number): string { return ( `**Review its proposals** (\`proposals.json\` above): each acquisition's action, reason and evidence, ` + `and which were enqueued, wait or were refused. Tell the operator which you would approve and why; the ` + `yes or no is theirs (umtool's research queue, or \`pnpm ops research-approve\`) — not yours unless they ask. ` + `When nothing waits (phase ready), continue it into a sweep over the widened scope: generate with task "sweep", ` + `article "${article}", iteration: ${n}, wait: true — then review that iteration as any sweep.` ); } async function summarise( deps: GenerationDeps, f: Extract, hint: { task?: string; article?: string; iteration?: number }, ): Promise { const marker = resultMarkerOf(f.tail); if (marker?.task === "verdicts") return verdictsSummary(f, marker); if (marker?.task === CLIPS_SUGGEST) return clipsSuggestSummary(f, marker); if (marker?.task === VIDEO_ASSIST) return videoAssistSummary(f, marker as Marker & AssistMarker); if (marker?.task === PROPOSE_GROUPS) return proposeGroupsSummary(f, marker as Marker & GroupsMarker); const article = marker?.article ?? hint.article; const n = marker?.iteration ?? hint.iteration; const task = marker?.task ?? hint.task ?? "report-draft"; const logTail = f.tail.filter((l) => !l.includes(RESULT_MARKER)).slice(-8); if (!article || !n) { return { text: `generate: job ${f.job.id} ended **${f.job.status}**${f.job.detail ? ` (${f.job.detail})` : ""}; its log names no iteration ` + `(pass article and iteration to read it).` + (logTail.length ? `\n\nlast log lines:\n\`\`\`\n${logTail.join("\n")}\n\`\`\`` : ""), isError: f.job.status !== "done", }; } const a = await editorGet(deps, `/api/ops/iterations?article=${encodeURIComponent(article)}&n=${n}`); if (a.kind !== "ok") { return { text: `generate: job ${f.job.id} ended ${f.job.status}; ${article} i${n} could not be read: ${describeEditorFailure("generate", a)}`, isError: true, }; } const iteration = a.body.iteration as IterationView; const text = renderIterationSummary({ task, article, jobId: f.job.id, marker, iteration, ...(typeof a.body.dir === "string" ? { dir: a.body.dir } : {}), ...(a.body.files && typeof a.body.files === "object" ? { files: a.body.files as Record } : {}), }); const failed = f.job.status !== "done"; return { text: failed && logTail.length ? `${text}\n\nlast log lines:\n\`\`\`\n${logTail.join("\n")}\n\`\`\`` : text, isError: failed, }; } function waitingText(f: Extract, hint: { article?: string; iteration?: number }): string { const q = f.job.queue; const where = f.job.status === "queued" && q && q.position > 0 ? ` (position ${q.position} of ${q.queued} on ${q.key})` : ""; const resume = [`job: "${f.job.id}"`, hint.article ? `article: "${hint.article}"` : "", hint.iteration ? `iteration: ${hint.iteration}` : ""] .filter(Boolean) .join(", "); return ( `Still ${f.job.status}${where} after ${f.waited}s.` + (f.last ? ` Last log line: ${f.last}` : "") + `\nCall generate again with ${resume} to keep waiting — never start the same task again. ` + `A sweep takes minutes; nothing is lost while you wait.` ); } export async function generateTool( args: Record, deps: GenerationDeps, onPoll?: (p: PollProgress) => void | Promise, ): Promise { const v = validateGenerateArgs(args); if (!v.ok) return { text: v.error, isError: true }; const req = v.request; if (req.kind === "resume") { const f = await followGeneration(deps, req.job, req.waitSeconds, onPoll); if (f.kind === "error") return { text: f.text, isError: true }; if (f.kind === "waiting") return { text: `generate: job ${req.job}. ${waitingText(f, req)}` }; return summarise(deps, f, req); } const body = { ...req.body }; const task = String(body.task); // Who runs it: the asked model, the asked route's model, else the policy's // route — and a task routed to code is this session's, not the editor's. // A session's clips-suggest answers run on no model: straight to the editor. if (!body.model && body.answers === undefined) { const read = await readPolicy(deps); if (!read.ok) { return { text: read.answer ? describeEditorFailure("generate", read.answer) : "generate: the editor's answer carried no generation block", isError: true, }; } const p = read.policy; if (req.via) body.model = p.models[req.via]; else if (task === CLIPS_SUGGEST && body.answers === undefined && p.routes[task] === "code") { // The session labels them: the editor's plan is the request. const plan = await editorPost(deps, "/api/ops/report-draft", { ...body, dryRun: true }); if (plan.kind !== "ok") return { text: describeEditorFailure("generate", plan), isError: true }; return { text: renderClipsSuggestRequest(String(body.project), (plan.body.plan ?? {}) as SuggestPlanView, p.preset) }; } else if (task === VIDEO_ASSIST && body.answers === undefined && p.routes[task] === "code") { // The session answers it: the editor's plan is the request. const plan = await editorPost(deps, "/api/ops/report-draft", { ...body, dryRun: true }); if (plan.kind !== "ok") return { text: describeEditorFailure("generate", plan), isError: true }; return { text: renderVideoAssistRequest(body, (plan.body.plan ?? {}) as AssistPlanView, p.preset) }; } else if (task === PROPOSE_GROUPS && body.answers === undefined && p.routes[task] === "code") { // The session proposes them: the editor's plan is the request. const plan = await editorPost(deps, "/api/ops/report-draft", { ...body, dryRun: true }); if (plan.kind !== "ok") return { text: describeEditorFailure("generate", plan), isError: true }; return { text: renderProposeGroupsRequest(body, (plan.body.plan ?? {}) as GroupsPlanView, p.preset) }; } else if (task === "verdicts" && p.routes[task] === "code") { // Verdicts are not a session's to make: the bench's bar names the models. return { text: `generate: verdicts is routed to Claude Code (preset ${p.preset}), and verdict proposals run only on a model ` + `that cleared the verdict bench's bar (settings.generation.verdicts.models) — name one as model. ` + `This session never proposes or rules claims' verdicts itself.`, isError: true, }; } else if (p.routes[task] === "code") { const continuing = task === "sweep" && typeof body.iteration === "number"; return { text: continuing ? `generate: a sweep continuing research run i${String(body.iteration)} is routed to Claude Code (preset ${p.preset}) — ` + `sweep its widened channels here (sweep_plan), or, when the operator asks, pass via: "api" or "local" to run it on the editor.` : `generate: ${task} is routed to Claude Code (preset ${p.preset}) — do it in this session ` + `(sweep_plan for a sweep). Pass via: "api" or "local" only when the operator asks to run it elsewhere.`, isError: true, }; } } const a = await editorPost(deps, "/api/ops/report-draft", body); if (a.kind !== "ok") return { text: describeEditorFailure("generate", a), isError: true }; const jobId = typeof a.body.jobId === "string" ? a.body.jobId : ""; const n = typeof a.body.iteration === "number" ? a.body.iteration : undefined; if (!jobId) return { text: `generate: the editor accepted it and started no job (${JSON.stringify(a.body)})`, isError: true }; const article = task === CLIPS_SUGGEST || task === VIDEO_ASSIST || task === PROPOSE_GROUPS ? "" : String(body.article); const warnings = Array.isArray(a.body.warnings) ? (a.body.warnings as unknown[]).map(String) : []; const head = `generate ${task}: queued as job ${jobId}` + (n ? `, ${task === "narrate" ? "narrating" : isStepTask(task) ? `drafting its ${task} on` : "making"} ${article} i${n}` : ` for ${article || String(body.project ?? "")}`) + (body.model ? ` on ${String(body.model)}` : " on the policy's model") + "." + warnings.map((w) => `\n⚠ ${w}`).join(""); if (!req.wait) { return { text: `${head} It runs on the editor's draft queue. Follow it with generate (job: "${jobId}"${article ? `, article: "${article}"` : ""}` + `${n ? `, iteration: ${n}` : ""}, wait: true), or get_job.`, }; } const f = await followGeneration(deps, jobId, req.waitSeconds, onPoll); if (f.kind === "error") return { text: `${head}\n${f.text}`, isError: true }; if (f.kind === "waiting") return { text: `${head}\n${waitingText(f, { article, ...(n ? { iteration: n } : {}) })}` }; return summarise(deps, f, { task, article, ...(n ? { iteration: n } : {}) }); } // ─── The tool definitions (server.ts's TOOLS takes them in order) ─── export const GENERATION_TOOLS = [ { name: "generation_policy", description: "The operator's generation balance (settings.generation, read from the local editor): for each " + "generation task — sweep (a new cited report), revise-report, revise-video, research, and the media drafts on a " + "video cut (cut, onscreen, teaser, flips, threads, narrate, youtube, social) — whether this " + "Claude Code session does it (code), the Claude API does it (api) or the local model does it " + "(local), on which model; the spend caps; and the day's Claude API spend against the daily cap. " + "With preset (code, balanced, api, local) it routes every task at once; with task and route it " + "routes one — ONLY when the operator asks to move the balance. Never shows the API key. Needs " + "ARCHILYZER_EDITOR_URL and WORKER_TOKEN.", inputSchema: { type: "object", properties: { preset: { type: "string", enum: [...GENERATION_PRESET_NAMES], description: "Route every task by this preset: code (all here), balanced, api, local.", }, task: { type: "string", description: "Route one task (with route): sweep, revise-report, revise-video, research, cut, onscreen, teaser, flips, threads, narrate, youtube, social.", }, route: { type: "string", enum: [...GENERATION_ROUTES], description: "Where that task runs." }, }, additionalProperties: false, }, }, { name: "generate", description: "Run a generation task on the local editor as a report-draft job — on the Claude API or the " + "local model, by the policy's route (generation_policy) unless model or via says otherwise — and, " + "with wait: true, follow it and return the iteration it made: status, cost, the ops applied and " + "refused, the checks, and where its files are on the editor's disk. task sweep makes a new " + "iteration of article from question over channels; revise-report and revise-video make one from " + "iteration and feedback; research finds what the corpus lacks " + "and proposes acquisitions under its autonomy (propose, limits, auto), and task sweep with a research " + "run's iteration continues it over the widened scope. copyOf runs an iteration again on another model. " + "The media drafts are steps on a done iteration's video cut (iteration names it): cut (which cited clips, in " + "what order), onscreen (each clip's title and subtitle), teaser (its lines), flips (THEN/NOW pairs), threads, " + "narrate (each card's narration), youtube (the upload's title and summary) and social (posts for X and Bluesky, " + "text only, the link added by code); each drafted field is marked " + "for the operator's review, and a field the operator wrote is never replaced. " + "A task routed to code is refused: do it in this session. The wait is bounded (wait_seconds, " + "default 90, at most 300) and polite (one poll every 5 s, a progress notification each); if the " + "job is still running it answers its id — call again with job (and article, iteration) to keep " + "waiting; the job keeps running either way. Then REVIEW what it made before anything is made " + "current. Needs ARCHILYZER_EDITOR_URL and WORKER_TOKEN.", inputSchema: { type: "object", properties: { task: { type: "string", enum: GENERATE_TASKS, description: "What to generate." }, article: { type: "string", description: "The article id (a lowercase slug). A sweep may name a new one." }, iteration: { type: "integer", minimum: 1, description: "revise-report / revise-video: the iteration revised; a media draft (cut, onscreen, teaser, flips, threads, narrate, youtube, social): the done iteration whose cut it drafts; sweep: the research run it continues; with job: the iteration to summarise.", }, question: { type: "string", description: "sweep / research: the question, in words." }, channels: { type: "array", items: { type: "string" }, description: "sweep / research: the channel slugs to read." }, source: { type: "string", description: "sweep / research: the corpus the editor reads and the sweep cites — a handle (remote:, hub:). " + "Omitted: this server's default corpus when it is a published archive or a hub, else the editor's own build holding the channels.", }, from: { type: "string", description: "sweep: only videos on or after this date (YYYY-MM-DD)." }, to: { type: "string", description: "sweep: only videos on or before this date (YYYY-MM-DD)." }, feedback: { type: "string", description: "A revision's feedback: what to change, concretely." }, copyOf: { type: "integer", minimum: 1, description: "Run this iteration again (same kind and inputs) on model or via." }, model: { type: "string", description: "The model to run on (else the route's)." }, extractorModel: { type: "string", description: "sweep on the API: the Claude model its extractor reads batches with (else the settings' extractor).", }, via: { type: "string", enum: ["api", "local"], description: "Run on this route's model instead of the policy's route — only when the operator asks." }, maxUsd: { type: "number", description: "An API job's cap in USD (else the task's default; never above the settings' max)." }, cards: { type: "array", items: { type: "string" }, description: "narrate: only these card ids." }, entries: { type: "array", items: { type: "string" }, description: "A media draft (narrate, cut, onscreen, teaser, flips, threads, youtube, social): only these entry ids." }, force: { type: "boolean", description: "A media draft: re-draft fields a model drafted (a field the operator wrote is never replaced; its draft is kept as an alternative); a sweep continuing a research run: continue while proposals still wait.", }, autonomy: { type: "string", enum: [...AUTONOMIES], description: "research: propose (every acquisition waits for the operator), limits (within the caps), auto (all through the editor) — default the settings'.", }, project: { type: "string", description: "clips-suggest: the reactions project's absolute directory (umtool's clip finder) — labels, a why and a rank for its proposals, into clip-suggestions.json (never a clip). Routed to code: the answer is the request, which this session labels and returns as answers. video-assist and propose-groups: the video project's absolute directory (its video.manifest.json); propose-groups proposes claim groups for its cut into group-proposals.json, which the operator accepts or rejects in umtool.", }, proposals: { type: "array", items: { type: "string" }, description: "clips-suggest: only these proposal ids." }, request: { type: "string", description: 'video-assist: what to change on the video project, in words ("make the joins 0.15 s with less smear") — one ask whose checked edits land in the project\'s assist-proposals.json as proposals the operator applies in umtool. Routed to code: the answer is the request, which this session answers and returns as answers. propose-groups: optional words for the ask ("group the October clips by day").', }, scope: { type: "string", enum: ["look", "clips", "fx", "all"], description: "video-assist: what the ask may touch (default all)." }, note: { type: "string", description: "video-assist: a note on the whole project (n_…) whose text is the request; the proposals are posted to it as the agent's reply." }, answers: { type: "object", description: 'clips-suggest routed to code: this session\'s labels, {"items": [{"id", "label" (≤ 6 words), "why" (one sentence), "score" (1–10)}]}; video-assist routed to code: {"ops": [{"op", "id", "key", "value"}], "reply"}; propose-groups routed to code: {"groups": [{"section", "claim", "ids", "why"}]} — read as a model\'s answer, written by the editor.', }, wait: { type: "boolean", description: "Follow the job and return its iteration's summary (default false)." }, wait_seconds: { type: "number", description: `How long to follow it before answering with its job id (default ${DEFAULT_GENERATE_WAIT_SECONDS}, max ${MAX_GENERATE_WAIT_SECONDS}).`, }, job: { type: "string", description: "Resume: the job id an earlier call returned. Every argument but article, iteration and wait_seconds is then ignored.", }, }, additionalProperties: false, }, }, ] as const;