commit f682e1a92f6acd681fadc2f0ae2e002d419e0507
parent fdd20646ecb4f0261fe0d9fc7df3937c1394026e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 13 Oct 2026 13:32:27 -0400
mcp, common: release 27 S9 after S11 — research runs through generate and gen run
generate passes a research run's autonomy (propose, limits, auto; refused
for any other task), shows the enqueue's warnings, says when a sweep
continuing a research run is routed to code, and summarises a research
iteration by its phase, notes and proposals with what is the operator's to
approve and how to continue it. generation_policy and `gen set` name the
research route; `gen run --autonomy`; gen.md and the README say so.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
8 files changed, 148 insertions(+), 34 deletions(-)
diff --git a/.claude/commands/gen.md b/.claude/commands/gen.md
@@ -9,16 +9,19 @@ each task. Use the archilyzer MCP tools only; run no script for it.
1. Call `mcp__archilyzer__generation_policy` with no arguments and read the routes, the models and the day's spend.
2. Map the request below to tasks: `sweep` (a new cited report), `revise-report` (a new iteration of an article's
report from feedback), `revise-video` (a new iteration of its video cut: cards, narration, title), `narrate`
- (card narration drafts for a done iteration's cut). The clip fetches, voices, render and podcast are the
+ (card narration drafts for a done iteration's cut), `research` (find what the corpus lacks and propose
+ acquisitions — archive.org imports, channels, posts — under an autonomy: propose, limits or auto; a sweep with
+ the research run's iteration continues it over the widened scope). The clip fetches, voices, render and podcast are the
pipeline's code, not generation: the operator runs that chain from umtool (the article's Iterations tab).
3. For each task routed to `api` or `local`, call `mcp__archilyzer__generate` with the task, the article, its
- inputs (question and channels for a sweep; iteration and concrete feedback for a revision; iteration for a
- narration) and `wait: true`, and do not redo its work yourself. If it answers still running, call it again with
+ inputs (question and channels for a sweep or research run; iteration and concrete feedback for a revision;
+ iteration for a narration) and `wait: true`, and do not redo its work yourself. If it answers still running, call it again with
the job, article and iteration it names — never start the same task twice. Then REVIEW what it made, as its
answer says: read the iteration's files, spot-check its quotes with `mcp__archilyzer__get_transcript`, read the
ops it refused and its checks, and tell the operator what is good and what is not. Recommend making it current
(the operator does that in umtool) or a revision; for a revision, call `generate` again with that feedback.
- Edit an iteration's files by hand only if the operator asks.
+ A research run's proposals are the operator's to approve (umtool's research queue); say which you would approve
+ and why. Edit an iteration's files by hand only if the operator asks.
4. For each task routed to `code`, do it yourself as usual: `/sweep` for a report (its plan reads the same
policy).
5. `via: "api"` or `"local"` on `generate` (or `via=` in a `/sweep` request) overrides one run when the operator asks
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -37,8 +37,8 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `archilyzer reports iterations` | `<articleId> [--json]` | an article's iterations (transcripts/reports/<id>/iterations/): each one's kind, model, status, cost, lineage and what it revised or copied, the current article and current video marked (exit 1 when an iteration.json is unsound; 2 for no such article) |
| `archilyzer gen policy` | `[--json]` | the generation policy: where each task runs (code = Claude Code, api = the Claude API, local = the local model), the models, the caps and the day's Claude API spend — from the editor, or settings.json when none answers |
| `archilyzer gen preset` | `<code\|balanced\|api\|local>` | route every generation task by a preset (its routes are written; settings.generation.routes) |
-| `archilyzer gen set` | `<task> <code\|api\|local>` | route one generation task (sweep, revise-report, revise-video, narrate) |
-| `archilyzer gen run` | `<task> [<question\|feedback>] --article <id> [--via api\|local\|code] [--model <m>] [--iteration <n>] [--channels a,b] [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--copy-of <n>] [--max-usd <usd>] [--cards a,b] [--force] [--source <handle>\|--build <id>] [--wait]` | enqueue a report-draft job as `pnpm ops report-draft` does (--wait follows it); EXITS 3 and runs nothing when the task is routed to code (Claude Code does it; --via overrides once) |
+| `archilyzer gen set` | `<task> <code\|api\|local>` | route one generation task (sweep, revise-report, revise-video, narrate, research) |
+| `archilyzer gen run` | `<task> [<question\|feedback>] --article <id> [--via api\|local\|code] [--model <m>] [--iteration <n>] [--channels a,b] [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--copy-of <n>] [--max-usd <usd>] [--cards a,b] [--force] [--autonomy propose\|limits\|auto] [--source <handle>\|--build <id>] [--wait]` | enqueue a report-draft job as `pnpm ops report-draft` does (--wait follows it; `sweep --iteration <n>` continues research run n); EXITS 3 and runs nothing when the task is routed to code (Claude Code does it; --via overrides once) |
| `archilyzer reports move-to-articles` | `[--keep <site>/<id>,…] [--drafts] [--apply]` | ONE-OFF (release 26): every report a site lists, but the pages named by --keep, moved to transcripts/reports/ as an article — audience private, published in reports/index.json in the sites' order (a report with problems as a draft), dropped from its site; --drafts moves unlisted ones too. A dry run printing the plan unless --apply *(passthrough)* |
| `archilyzer reports convert` | `<sweep\|ask\|manifest> <in> --out <report.json> [--channels-dir <dir>] [--id <id>] [--title <title>]` | a /sweep report (markdown), an /ask answer or a report-to-video manifest as a report.json, written only when it validates (--channels-dir: widen spans from the cues, find posts' channels) |
| `archilyzer reports to-manifest` | `<report.json> --out <manifest.json> [--channels-dir <dir>] [--site-origin <url>]` | a starter report-to-video manifest from a report (a chapter card per section, a claim's still and clips stamped with its verdict, its posts) |
diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts
@@ -415,14 +415,14 @@ export const COMMANDS: Command[] = [
},
{
path: ["gen", "set"],
- usage: "<task> <code|api|local> route one generation task (sweep, revise-report, revise-video, narrate)",
+ usage: "<task> <code|api|local> route one generation task (sweep, revise-report, revise-video, narrate, research)",
maxPositionals: 2,
run: async (ctx) => (await import("./gen")).genSetRow(ctx),
},
{
path: ["gen", "run"],
usage:
- "<task> [<question|feedback>] --article <id> [--via api|local|code] [--model <m>] [--iteration <n>] [--channels a,b] [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--copy-of <n>] [--max-usd <usd>] [--cards a,b] [--force] [--source <handle>|--build <id>] [--wait] enqueue a report-draft job as `pnpm ops report-draft` does (--wait follows it); EXITS 3 and runs nothing when the task is routed to code (Claude Code does it; --via overrides once)",
+ "<task> [<question|feedback>] --article <id> [--via api|local|code] [--model <m>] [--iteration <n>] [--channels a,b] [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--copy-of <n>] [--max-usd <usd>] [--cards a,b] [--force] [--autonomy propose|limits|auto] [--source <handle>|--build <id>] [--wait] enqueue a report-draft job as `pnpm ops report-draft` does (--wait follows it; `sweep --iteration <n>` continues research run n); EXITS 3 and runs nothing when the task is routed to code (Claude Code does it; --via overrides once)",
flags: {
via: "string",
article: "string",
@@ -437,6 +437,7 @@ export const COMMANDS: Command[] = [
"max-usd": "string",
cards: "string",
force: "boolean",
+ autonomy: "string",
source: "string",
build: "string",
wait: "boolean",
diff --git a/common/bin/gen.test.ts b/common/bin/gen.test.ts
@@ -28,7 +28,7 @@ function capture() {
const BALANCED: GenPolicy = {
preset: "balanced",
- routes: { sweep: "code", "revise-report": "api", "revise-video": "local", narrate: "local" },
+ routes: { sweep: "code", "revise-report": "api", "revise-video": "local", narrate: "local", research: "api" },
models: { api: "claude-sonnet-5-5", local: "qwen3:8b", extractor: "claude-haiku-4-5" },
caps: { sweep: 5, revision: 2, narration: 1, daily: 20, max: 10 },
};
@@ -73,9 +73,9 @@ test("gen preset writes the preset's routes; gen set writes one; nonsense is a u
const m = memoryStore();
const deps = { store: async () => m.store, runOps: async () => 0, out: c.out };
assert.equal(await gen.setMain({ preset: "local" }, deps), 0);
- assert.deepEqual(m.written[0], { sweep: "local", "revise-report": "local", "revise-video": "local", narrate: "local" });
+ assert.deepEqual(m.written[0], { sweep: "local", "revise-report": "local", "revise-video": "local", narrate: "local", research: "local" });
assert.equal(await gen.setMain({ task: "sweep", route: "api" }, deps), 0);
- assert.deepEqual(m.written[1], { sweep: "api", "revise-report": "local", "revise-video": "local", narrate: "local" });
+ assert.deepEqual(m.written[1], { sweep: "api", "revise-report": "local", "revise-video": "local", narrate: "local", research: "local" });
assert.ok(c.lines.includes("(written to the editor at http://editor.test)"));
for (const o of [{ preset: "cheap" }, { task: "sweep", route: "cloud" }, { task: "sweep" }, { task: "teaser", route: "api" }]) {
assert.equal(await gen.setMain(o, deps), 2, JSON.stringify(o));
@@ -157,11 +157,11 @@ test("the editor store: through the ops API with the token; refused → error; n
assert.equal(store.offline, false);
assert.equal((await store.read()).preset, "balanced");
assert.deepEqual(await store.usage(), { day: "2026-10-13", usd: 0.5, jobs: 1, daily: 20 });
- const saved = await store.writeRoutes({ sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api" });
+ const saved = await store.writeRoutes({ sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" });
assert.equal(saved.preset, "api");
assert.ok(sent.every((s) => s.auth === "Bearer tok" && s.url.startsWith("http://editor.test/api/ops/")));
assert.deepEqual(sent.find((s) => s.method === "POST")!.body, {
- patch: { generation: { routes: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api" } } },
+ patch: { generation: { routes: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" } } },
});
const refusing = (async () => new Response(JSON.stringify({ ok: false, error: "unauthorized" }), { status: 401 })) as unknown as typeof fetch;
@@ -197,3 +197,16 @@ test("the offline store reads and writes settings.json through the settings writ
assert.equal(await gen.setMain({ preset: "api" }, { store: async () => store, runOps: async () => 0, out: c.out }), 0);
assert.equal((await store.read()).preset, "api");
});
+
+test("gen run research takes --autonomy; nothing else does", async () => {
+ assert.deepEqual(gen.runBody("research", "what is missing?", { article: "synth-a", channels: "synth-kitchen", autonomy: "limits" }), {
+ task: "research",
+ article: "synth-a",
+ question: "what is missing?",
+ channels: ["synth-kitchen"],
+ autonomy: "limits",
+ });
+ assert.deepEqual(gen.runBody("sweep", undefined, { article: "synth-a", autonomy: "auto" }), { error: "gen run: --autonomy is a research run's" });
+ // A continuation: a sweep naming the research run.
+ assert.deepEqual(gen.runBody("sweep", undefined, { article: "synth-a", iteration: "4", force: true }), { task: "sweep", article: "synth-a", iteration: 4, force: true });
+});
diff --git a/common/bin/gen.ts b/common/bin/gen.ts
@@ -66,7 +66,7 @@ export type GenDeps = {
out?: Out;
};
-const TASKS_HELP = "sweep, revise-report, revise-video, narrate (and research once the editor runs it)";
+const TASKS_HELP = "sweep, revise-report, revise-video, narrate, research";
const isRoute = (v: unknown): v is GenerationRoute => typeof v === "string" && (GENERATION_ROUTES as readonly string[]).includes(v);
export function policyFrom(value: unknown): GenPolicy | null {
@@ -279,6 +279,11 @@ export function runBody(task: string, text: string | undefined, flags: Record<st
body.maxUsd = n;
}
if (flags.force === true) body.force = true;
+ const autonomy = str("autonomy");
+ if (autonomy !== undefined) {
+ if (task !== "research") return { error: "gen run: --autonomy is a research run's" };
+ body.autonomy = autonomy;
+ }
return body;
}
diff --git a/mcp/README.md b/mcp/README.md
@@ -36,8 +36,8 @@ only).
| `enqueue` | Queue archival work on a channel the editor archives, as its page's buttons do (`POST /api/ops/<kind>`): `sync` (`full`), `download-missing`, `retry-bucket` (`bucket`, `ids` — the way to download chosen videos), `transcribe-bucket` (`ids`), `fetch-posts` (`full` / `older`), `import-video` (`url`). Answers the job id; the editor runs it on its own queues at each platform's pace. Only when the operator asks. Needs the editor. |
| `channel_coverage` | What a channel **holds** on the editor's disk by date (`GET /api/ops/coverage`): count, first and last day, per year, and every gap longer than `gap_days` (30); `date_from` / `date_to` narrow it, `list` lists the videos. Each video is dated by its **recorded date** when the channel has a title rule (a VOD mirror, release 20), else its upload date. Needs the editor. |
| `notes` | The operator's notes in umtool on articles and report-video projects: `list` (every open note, by target), `read` (`target` as `list` names it — the digest with anchors resolved and the source file to edit). `reply` (`note_id`, `text`, `resolve`) writes the reply in umtool (`POST /api/notes` with `Authorization: Bearer <WORKER_TOKEN>`), which stamps it "agent" — never the operator's; its `target` is found from the open notes when omitted. Edit the note's source file and regenerate first. Needs `UMTOOL_URL`; a reply needs `WORKER_TOKEN` (the editor's own, which umtool reads too — a 401 means umtool holds another). |
-| `generation_policy` | The operator's generation balance (`settings.generation`, `GET /api/ops/settings?key=generation`): for each task — `sweep`, `revise-report`, `revise-video`, `narrate` — whether this Claude Code session (`code`), the Claude API (`api`) or the local model (`local`) does it, on which model; the caps; and the day's Claude API spend against the daily cap (`GET /api/ops/generation-usage`). `preset` (`code`, `balanced`, `api`, `local`) or `task` + `route` rewrites the routes (`POST /api/ops/settings`) — only when the operator asks. Never shows the API key. Needs the editor. |
-| `generate` | Run a generation task as a `report-draft` job on the editor (`POST /api/ops/report-draft`): `sweep` (`question`, `channels`, `from`/`to`), `revise-report` / `revise-video` (`iteration`, `feedback`), `narrate` (`iteration`, `cards`, `force`), `research` (once the editor runs it); `copyOf` runs an iteration again on another model. The model is `model`, else `via`'s route, else the policy's route — a task routed to `code` is refused (do it in the session). `wait: true` follows the job (one poll every 5 s, a progress notification each, up to `wait_seconds`, default 90, max 300; resume with `job`) and answers the iteration: status, cost per model, ops applied and refused, checks, and where its files are on the editor's disk (`GET /api/ops/iterations`), with the review to do before anything is made current. Needs the editor. |
+| `generation_policy` | The operator's generation balance (`settings.generation`, `GET /api/ops/settings?key=generation`): for each task — `sweep`, `revise-report`, `revise-video`, `narrate`, `research` — whether this Claude Code session (`code`), the Claude API (`api`) or the local model (`local`) does it, on which model; the caps; and the day's Claude API spend against the daily cap (`GET /api/ops/generation-usage`). `preset` (`code`, `balanced`, `api`, `local`) or `task` + `route` rewrites the routes (`POST /api/ops/settings`) — only when the operator asks. Never shows the API key. Needs the editor. |
+| `generate` | Run a generation task as a `report-draft` job on the editor (`POST /api/ops/report-draft`): `sweep` (`question`, `channels`, `from`/`to`), `revise-report` / `revise-video` (`iteration`, `feedback`), `narrate` (`iteration`, `cards`, `force`), `research` (`question`, `channels`, `autonomy`: `propose`, `limits` or `auto`; a `sweep` with the run's `iteration` continues it over the widened scope); `copyOf` runs an iteration again on another model. The model is `model`, else `via`'s route, else the policy's route — a task routed to `code` is refused (do it in the session). `wait: true` follows the job (one poll every 5 s, a progress notification each, up to `wait_seconds`, default 90, max 300; resume with `job`) and answers the iteration: status, cost per model, ops applied and refused, checks, and where its files are on the editor's disk (`GET /api/ops/iterations`), with the review to do before anything is made current. Needs the editor. |
| `open_link` | Paste an archilyzer viewer **share link** to re-run that exact search here (query tree + every filter, at full fidelity) — plan, results and corpus handle in **one** call. `dry_run:true` for the plan alone. |
| `list_sources` | Show the **default** corpus and, with a hub, its member sites as ready-to-paste handles. A site with reports says how many; a cited-only site says it is one. |
| `resolve_source` | Turn a URL or site name into the canonical `source` handle and check it can be read. Changes nothing. |
diff --git a/mcp/src/generation.test.ts b/mcp/src/generation.test.ts
@@ -18,7 +18,7 @@ import {
const POLICY = {
preset: "balanced",
- routes: { sweep: "code", "revise-report": "api", "revise-video": "local", narrate: "local" },
+ routes: { sweep: "code", "revise-report": "api", "revise-video": "local", narrate: "local", research: "api" },
models: { api: "claude-sonnet-5-5", local: "qwen3:8b", extractor: "claude-haiku-4-5" },
caps: { sweep: 5, revision: 2, narration: 1, daily: 20, max: 10 },
cacheTtl: "5m",
@@ -61,7 +61,12 @@ function editor(opts: { policy?: Record<string, unknown>; runPolls?: number; end
if (u.pathname === "/api/ops/settings" && s.method === "GET") return { status: 200, body: { ok: true, key: "generation", value: policy } };
if (u.pathname === "/api/ops/settings" && s.method === "POST") {
const routes = (s.body as { patch: { generation: { routes: Record<string, string> } } }).patch.generation.routes;
- const presets: Record<string, string> = { "code,code,code,code": "code", "api,api,api,api": "api", "local,local,local,local": "local", "code,api,local,local": "balanced" };
+ const presets: Record<string, string> = {
+ "code,code,code,code,code": "code",
+ "api,api,api,api,api": "api",
+ "local,local,local,local,local": "local",
+ "code,api,local,local,api": "balanced",
+ };
policy = { ...policy, routes: routes as typeof policy.routes, preset: presets[Object.values(routes).join(",")] ?? "custom" };
return { status: 200, body: { ok: true, changed: ["generation"], value: { generation: policy } } };
}
@@ -109,6 +114,7 @@ test("generation_policy reads the routes, models, caps and the day's spend — n
assert.match(a.text, /- sweep → code \(this Claude Code session\)/);
assert.match(a.text, /- revise-report → api \(the Claude API, claude-sonnet-5-5\)/);
assert.match(a.text, /- narrate → local \(the local model, qwen3:8b\)/);
+ assert.match(a.text, /- research → api \(the Claude API, claude-sonnet-5-5\)/);
assert.match(a.text, /extractor claude-haiku-4-5/);
assert.match(a.text, /sweep \$5\.00 · revision \$2\.00 · narration \$1\.00 · any job at most \$10\.00 · daily \$20\.00/);
assert.match(a.text, /Today \(2026-10-13, UTC\): \$1\.75 spent on the Claude API in 2 job\(s\) of the \$20\.00 daily cap/);
@@ -124,7 +130,7 @@ test("generation_policy sets a preset as its routes, and one route alone", async
assert.equal(a.isError, undefined, a.text);
const post = e.sentOf("/api/ops/settings").find((s) => s.method === "POST")!;
assert.deepEqual(post.body, {
- patch: { generation: { routes: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api" } } },
+ patch: { generation: { routes: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" } } },
});
assert.match(a.text, /^Set preset api\./);
assert.match(a.text, /preset \*\*api\*\*/);
@@ -133,7 +139,7 @@ test("generation_policy sets a preset as its routes, and one route alone", async
const post2 = e.sentOf("/api/ops/settings").filter((s) => s.method === "POST")[1];
// The whole routes object (the writer merges one level; a nested object replaces).
assert.deepEqual(post2.body, {
- patch: { generation: { routes: { sweep: "local", "revise-report": "api", "revise-video": "api", narrate: "api" } } },
+ patch: { generation: { routes: { sweep: "local", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" } } },
});
assert.match(one.text, /^Routed sweep to local\./);
assert.match(one.text, /preset \*\*custom\*\*/);
@@ -153,7 +159,7 @@ test("generation_policy refuses a muddle before it asks the editor", async () =>
}
assert.equal(e.sent.length, 0);
const unknown = await generationPolicyTool({ task: "teaser", route: "api" }, e.deps as never);
- assert.match(unknown.text, /no task "teaser" — the policy routes sweep, revise-report, revise-video, narrate/);
+ assert.match(unknown.text, /no task "teaser" — the policy routes sweep, revise-report, revise-video, narrate, research/);
assert.equal(e.sent.filter((s) => s.method === "POST").length, 0);
const none = await generationPolicyTool({}, fakeEditor(() => ({ status: 200, body: {} }), {}).deps as never);
assert.equal(none.isError, true);
@@ -313,3 +319,49 @@ test("the server serves both tools, and sweep_plan routes by the policy it reads
assert.equal(isError(gen), false, textOf(gen));
assert.match(textOf(gen), /queued as job job-1/);
});
+
+test("generate: research takes its autonomy; a continuation is a sweep with the run's iteration", async () => {
+ const e = editor();
+ const a = await generateTool(
+ { task: "research", article: "synth-a", question: "what is missing?", channels: ["synth-kitchen"], autonomy: "limits" },
+ e.deps as never,
+ );
+ assert.equal(a.isError, undefined, a.text);
+ assert.deepEqual(e.sentOf("/api/ops/report-draft")[0].body, {
+ task: "research",
+ article: "synth-a",
+ question: "what is missing?",
+ channels: ["synth-kitchen"],
+ autonomy: "limits",
+ });
+ const wrong = await generateTool({ task: "sweep", article: "synth-a", question: "q", channels: ["x"], autonomy: "auto" }, e.deps as never);
+ assert.match(wrong.text, /autonomy is a research run's/);
+ const bad = await generateTool({ task: "research", article: "synth-a", question: "q", autonomy: "yolo" }, e.deps as never);
+ assert.match(bad.text, /autonomy is one of propose, limits, auto/);
+ // Continuing a research run with sweeps routed to code: say so, enqueue nothing.
+ const cont = await generateTool({ task: "sweep", article: "synth-a", iteration: 4 }, e.deps as never);
+ assert.equal(cont.isError, true);
+ assert.match(cont.text, /a sweep continuing research run i4 is routed to Claude Code/);
+ assert.equal(e.sentOf("/api/ops/report-draft").length, 1);
+ const via = await generateTool({ task: "sweep", article: "synth-a", iteration: 4, via: "api", force: true }, e.deps as never);
+ assert.deepEqual(e.sentOf("/api/ops/report-draft")[1].body, { task: "sweep", article: "synth-a", iteration: 4, force: true, model: "claude-sonnet-5-5" });
+ assert.equal(via.isError, undefined, via.text);
+});
+
+test("generate: a research run's summary is its phase and proposals, with what is the operator's", async () => {
+ const e = editor({
+ iteration: {
+ kind: "research",
+ ops: undefined,
+ checks: [],
+ research: { autonomy: "propose", phase: "wait", notes: ["p01 waits for approval: a new channel"] },
+ },
+ });
+ const a = await generateTool({ job: "job-1", article: "synth-a", iteration: 3 }, e.deps as never);
+ assert.match(a.text, /Research: phase wait, autonomy propose/);
+ assert.match(a.text, /- p01 waits for approval: a new channel/);
+ assert.match(a.text, /\*\*Review its proposals\*\*/);
+ assert.match(a.text, /the yes or no is theirs \(umtool's research queue, or `pnpm ops research-approve`\)/);
+ assert.match(a.text, /generate with task "sweep", article "synth-a", iteration: 3, wait: true/);
+ assert.doesNotMatch(a.text, /Review it — you are the reviewer/);
+});
diff --git a/mcp/src/generation.ts b/mcp/src/generation.ts
@@ -5,6 +5,7 @@ import {
GENERATION_TASKS,
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 { reviewGuidance, type GenerationRoute, type PlanGeneration } from "./instructions";
@@ -41,8 +42,7 @@ export type GenerationPolicy = PlanGeneration & {
};
export type GenerationUsageDay = { day: string; usd: number; jobs: number; daily: number };
-// The tasks `generate` takes: the policy's, and `research` (S11 makes it run;
-// the editor refuses it until then, in its own words).
+// The tasks `generate` takes: the policy's (research included, S11).
export const GENERATE_TASKS = [...new Set<string>([...GENERATION_TASKS, "research"])];
const ARTICLE_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
@@ -264,6 +264,12 @@ export function validateGenerateArgs(args: Record<string, unknown>): { ok: true;
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);
@@ -354,6 +360,8 @@ type IterationView = {
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;
@@ -403,11 +411,28 @@ export function renderIterationSummary(
for (const [name, p] of present) if (name !== "turns.jsonl") lines.push(` - ${name}: ${p}`);
}
if (it.projectDir) lines.push(`Video project: ${it.projectDir}`);
- if (status === "done") lines.push("", reviewGuidance());
+ 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") 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<Followed, { kind: "ended" }>,
@@ -497,10 +522,13 @@ export async function generateTool(
const p = read.policy;
if (req.via) body.model = p.models[req.via];
else if (p.routes[task] === "code") {
+ const continuing = task === "sweep" && typeof body.iteration === "number";
return {
- text:
- `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.`,
+ 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,
};
}
@@ -511,11 +539,13 @@ export async function generateTool(
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 = 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" : "making"} ${article} i${n}` : ` for ${article}`) +
(body.model ? ` on ${String(body.model)}` : " on the policy's model") +
- ".";
+ "." +
+ warnings.map((w) => `\n⚠ ${w}`).join("");
if (!req.wait) {
return {
text:
@@ -536,7 +566,7 @@ 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, narrate — whether this " +
+ "generation task — sweep (a new cited report), revise-report, revise-video, narrate, research — 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 " +
@@ -550,7 +580,7 @@ export const GENERATION_TOOLS = [
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, narrate." },
+ task: { type: "string", description: "Route one task (with route): sweep, revise-report, revise-video, narrate, research." },
route: { type: "string", enum: [...GENERATION_ROUTES], description: "Where that task runs." },
},
additionalProperties: false,
@@ -564,8 +594,9 @@ export const GENERATION_TOOLS = [
"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; narrate voices a done iteration's cut; research (when the editor supports " +
- "it) searches, proposes acquisitions and sweeps. copyOf runs an iteration again on another model. " +
+ "iteration and feedback; narrate voices a done iteration's cut; 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. " +
"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 " +
@@ -579,7 +610,8 @@ export const GENERATION_TOOLS = [
iteration: {
type: "integer",
minimum: 1,
- description: "revise-report / revise-video: the iteration revised; narrate: the iteration voiced; with job: the iteration to summarise.",
+ description:
+ "revise-report / revise-video: the iteration revised; narrate: the iteration voiced; 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." },
@@ -591,7 +623,15 @@ export const GENERATION_TOOLS = [
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." },
- force: { type: "boolean", description: "narrate: redraft cards that already have narration." },
+ force: {
+ type: "boolean",
+ description: "narrate: redraft cards that already have narration; 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'.",
+ },
wait: { type: "boolean", description: "Follow the job and return its iteration's summary (default false)." },
wait_seconds: {
type: "number",