Archilyzer · Source

archilyzer

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

commit 4e081ceb3ed6c329a840d28bb5459cbeee3c8063
parent 26578d986efeacb8ab6f32e0d8dee1f5f5b5cc77
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 06:22:15 -0500

create: a sweep's source is offered -- the editor's corpus or a connected archive, preselected with no local corpus; MCP generate passes it (demo epic D1 item 2)

"Article from a question" (NewArticleForm) gets a Source field: the Local
corpus (the editor's channels) and every published archive the source picker
offers, connected archives first (/api/articles/sources). The channel picker
lists the chosen source's channels -- an archive's from its corpus.json
(/api/articles/channels?source=, through openSource, so only an offered handle
opens) -- and the sweep or research body carries `source`. With no local
corpus (the editor holds no channel of its own) the first archive is
preselected (lib/articles/createSources.ts).

The research board likewise: with no composed local build, listSources orders
the archives first, so every default (`sources[0]`, openSource with no
handle) is the first archive; the local entry stays offered, "no build".

MCP generate takes `source` (sweep / research only) and, when the call names
none, passes this server's default when that is a published archive or a hub
(generateArgsWithSource); a local corpus is not sent -- the editor picks its
own build, as before. The routed-sweep instruction says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diffstat:
Mmcp/src/generation.test.ts | 18++++++++++++++++++
Mmcp/src/generation.ts | 12++++++++++++
Mmcp/src/instructions.ts | 4+++-
Mmcp/src/server.ts | 17++++++++++++++++-
Mumtool/app/api/articles/channels/route.ts | 24++++++++++++++++++++----
Aumtool/app/api/articles/sources/route.ts | 21+++++++++++++++++++++
Mumtool/components/articles/NewArticleForm.tsx | 59+++++++++++++++++++++++++++++++++++++++++++++++++++--------
Aumtool/lib/articles/createSources.test.ts | 26++++++++++++++++++++++++++
Aumtool/lib/articles/createSources.ts | 20++++++++++++++++++++
Aumtool/lib/research/sources.test.ts | 43+++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/research/sources.ts | 11+++++++++--
Mumtool/package.json | 2+-
12 files changed, 240 insertions(+), 17 deletions(-)

diff --git a/mcp/src/generation.test.ts b/mcp/src/generation.test.ts @@ -571,3 +571,21 @@ test("generate propose-groups: a project (words optional); routed to code, the p assert.match(b.text, /Project: \/r\/p · 1 proposed, 0 refused/); assert.match(b.text, /Nothing in the cut changed/); }); + +// demo epic D1: a sweep over a published archive names it to the editor. +test("generate carries source for a sweep or research run, refuses it elsewhere", async () => { + const { generateArgsWithSource } = await import("./server"); + const ok = validateGenerateArgs({ task: "sweep", article: "a", question: "q", channels: ["c"], source: "remote:https://stub.test" }); + assert.equal(ok.ok, true); + assert.equal((ok as { request: { body: Record<string, unknown> } }).request.body.source, "remote:https://stub.test"); + const bad = validateGenerateArgs({ task: "revise-report", article: "a", iteration: 1, feedback: "x", source: "remote:https://stub.test" }); + assert.match(String((bad as { error: string }).error), /source is a sweep's or a research run's/); + assert.match(String((validateGenerateArgs({ task: "sweep", article: "a", question: "q", channels: ["c"], source: "nope" }) as { error: string }).error), /corpus handle/); + // The server's resolution: the canonical handle of a remote or hub, never a local dir; only sweep and research. + const remote = { handle: "remote:https://stub.test", spec: { kind: "remote" as const, url: "https://stub.test" } }; + assert.equal(generateArgsWithSource({ task: "sweep", source: "https://stub.test/" }, remote).source, "remote:https://stub.test"); + assert.equal(generateArgsWithSource({ task: "research" }, remote).source, "remote:https://stub.test"); + assert.equal("source" in generateArgsWithSource({ task: "narrate", source: "x" }, remote), false); + const local = { handle: "local:/x", spec: { kind: "local" as const, dir: "/x" } }; + assert.equal("source" in generateArgsWithSource({ task: "sweep" }, local), false); +}); diff --git a/mcp/src/generation.ts b/mcp/src/generation.ts @@ -249,6 +249,12 @@ export function validateGenerateArgs(args: Record<string, unknown>): { ok: true; 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:<url>, hub:<url> or local:<dir>"); + 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]); @@ -955,6 +961,12 @@ export const GENERATION_TOOLS = [ }, 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:<archive origin>, hub:<url>). " + + "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." }, diff --git a/mcp/src/instructions.ts b/mcp/src/instructions.ts @@ -369,7 +369,9 @@ function generateSweepStep(req: PromptRequest, r: { route: GenerationRoute; mode `${r.route === "code" ? "Claude Code" : ROUTE_WORDS[r.route]}${r.model ? ` (${r.model})` : ""} by ${r.by}. ` + `Call \`generate\` with task: "sweep", ${article}, ${question}, ${channels}${model}, ` + `wait: true (add from/to, YYYY-MM-DD, when I named a period). The editor runs ` + - `it as a report-draft job on its own corpus build and caps; the article's ` + + `it as a report-draft job, under its caps, over the corpus the call names in \`source\` — ` + + `omitted, this server's default when that is a published archive (remote:<origin>) or a hub, ` + + `else the editor's own build holding the channels — and the sweep cites that archive; the article's ` + `iteration is what it makes, never its published report. If the answer ` + `says it is still running, call \`generate\` again with the job, article ` + `and iteration it names and wait: true — never enqueue the same sweep ` + diff --git a/mcp/src/server.ts b/mcp/src/server.ts @@ -1347,7 +1347,7 @@ export function createServer( case "generate": return fromAnswer( await generateTool( - args, + generateArgsWithSource(args, resolved), fetchClipDeps, progressNotifier(ctx.mcpReq._meta?.progressToken, ctx.mcpReq.notify), ), @@ -2655,6 +2655,21 @@ async function describeDigest( return out.length > 1 ? out.join("\n") : ""; } +// generate's `source` (demo epic D1): the corpus a sweep or a research run +// reads and cites. The call's own `source`, resolved to its canonical handle, +// when it names a published archive or a hub — and, when it names none, this +// server's default if that is one: an MCP pointed at jeralyzer.pages.dev asks +// the editor to sweep jeralyzer.pages.dev, not whatever build it holds. A +// LOCAL corpus is not sent: the editor picks its own build holding the +// channels, as before. Only a sweep or a research run carries it. +export function generateArgsWithSource(args: Record<string, unknown>, resolved: Pick<ResolvedSource, "handle" | "spec">): Record<string, unknown> { + const { source: _asked, ...rest } = args; + const task = typeof args.task === "string" ? args.task.trim() : ""; + if (task !== "sweep" && task !== "research") return rest; + if (resolved.spec.kind === "local") return rest; + return { ...rest, source: resolved.handle }; +} + // ─── Source discovery: list_sources / resolve_source ─── // A one-line human description of a source spec's target (kind + where it diff --git a/umtool/app/api/articles/channels/route.ts b/umtool/app/api/articles/channels/route.ts @@ -1,12 +1,28 @@ -import { errorResponse, listEditorChannels } from "@/lib/articles/generation"; +import { errorResponse, listEditorChannels, type EditorChannel } from "@/lib/articles/generation"; +import { SourceError, openSource } from "@/lib/research/sources"; export const dynamic = "force-dynamic"; -// The editor's channels, for /articles/new's picker (GET /api/ops/channels). -export async function GET() { +// The channels /articles/new's picker offers (GET /api/ops/channels): the +// editor's own, or — `?source=remote:<origin>` (demo epic D1 item 2) — that +// published archive's, from its corpus.json. Only an offered source opens +// (lib/research/sources.ts openSource refuses any other handle). A remote-only +// channel is not offered as the editor's own: it holds no transcripts. +export async function GET(request: Request) { try { - return Response.json({ channels: await listEditorChannels() }, { headers: { "cache-control": "no-store" } }); + const source = new URL(request.url).searchParams.get("source")?.trim(); + if (!source) { + const channels = (await listEditorChannels()).filter((c) => c.kind !== "remote-only"); + return Response.json({ channels }, { headers: { "cache-control": "no-store" } }); + } + const opened = await openSource(source); + const refs = await opened.source.listChannels(); + const channels: EditorChannel[] = refs + .map((c) => ({ slug: c.slug, name: c.name ?? c.slug, kind: "video", platform: (c as { platform?: string }).platform ?? null, sites: [] })) + .sort((a, b) => a.name.localeCompare(b.name)); + return Response.json({ channels, source: opened.option.handle }, { headers: { "cache-control": "no-store" } }); } catch (err) { + if (err instanceof SourceError) return Response.json({ error: err.message }, { status: err.status }); return errorResponse(err); } } diff --git a/umtool/app/api/articles/sources/route.ts b/umtool/app/api/articles/sources/route.ts @@ -0,0 +1,21 @@ +import { errorResponse, listEditorChannels } from "@/lib/articles/generation"; +import { createSourcesOf } from "@/lib/articles/createSources"; +import { listSources } from "@/lib/research/sources"; + +export const dynamic = "force-dynamic"; + +// The corpora "Article from a question" may sweep (demo epic D1 item 2): the +// editor's own (its channels and the build holding them; handle "") and every +// published archive the source picker offers (connected archives first). With +// no local corpus — the editor holds no channel of its own — and an archive to +// offer, the first archive is preselected. +// +// GET -> { sources: [{ handle, label, detail? }], preselect } +export async function GET() { + try { + const [sources, channels] = await Promise.all([listSources(), listEditorChannels().catch(() => null)]); + return Response.json(createSourcesOf(sources, channels), { headers: { "cache-control": "no-store" } }); + } catch (err) { + return errorResponse(err); + } +} diff --git a/umtool/components/articles/NewArticleForm.tsx b/umtool/components/articles/NewArticleForm.tsx @@ -43,19 +43,23 @@ const AUTONOMY_SAYS: Record<Autonomy, string> = { }; // Exported for Create's recurring form (R5): the same picker, the same channels. -export function ChannelPicker({ value, onChange }: { value: string[]; onChange: (v: string[]) => void }) { +// `source` (demo epic D1): a published archive's handle lists ITS channels +// (its corpus.json); none, the editor's own. +export function ChannelPicker({ value, onChange, source = "" }: { value: string[]; onChange: (v: string[]) => void; source?: string }) { const [all, setAll] = useState<EditorChannel[] | null>(null); const [error, setError] = useState(""); const [q, setQ] = useState(""); useEffect(() => { - fetch("/api/articles/channels", { cache: "no-store" }) + setAll(null); + setError(""); + fetch(source ? `/api/articles/channels?source=${encodeURIComponent(source)}` : "/api/articles/channels", { cache: "no-store" }) .then(async (r) => { const b = await r.json(); if (!r.ok) throw new Error(b.error ?? `HTTP ${r.status}`); setAll(b.channels); }) .catch((e) => setError((e as Error).message)); - }, []); + }, [source]); const shown = useMemo(() => { const k = q.trim().toLowerCase(); return (all ?? []).filter((c) => !k || c.slug.includes(k) || c.name.toLowerCase().includes(k)).slice(0, 80); @@ -97,7 +101,7 @@ export function ChannelPicker({ value, onChange }: { value: string[]; onChange: <button type="button" aria-pressed={value.includes(c.slug)} - title={`${c.slug}${c.sites.length ? ` · on ${c.sites.join(", ")}` : " · on no site"}`} + title={`${c.slug}${source ? "" : c.sites.length ? ` · on ${c.sites.join(", ")}` : " · on no site"}`} className={`rounded border px-1.5 py-0.5 text-[12px] hover:bg-[var(--color-panel-2)] ${value.includes(c.slug) ? "border-[var(--color-muted)] bg-[var(--color-panel-2)] text-[var(--color-text)]" : "border-[var(--color-line)]"}`} onClick={() => toggle(c.slug)} > @@ -157,6 +161,21 @@ export default function NewArticleForm({ const [id, setId] = useState(""); const [question, setQuestion] = useState(""); const [channels, setChannels] = useState<string[]>([]); + // The corpus the sweep reads and cites (demo epic D1): "" the editor's own, + // else a published archive's handle. Preselected when the editor holds no + // channel and an archive is connected (/api/articles/sources). + const [sources, setSources] = useState<{ handle: string; label: string; detail?: string }[] | null>(null); + const [source, setSource] = useState(""); + useEffect(() => { + fetch("/api/articles/sources", { cache: "no-store" }) + .then(async (r) => { + const b = await r.json(); + if (!r.ok) throw new Error(b.error ?? `HTTP ${r.status}`); + setSources(b.sources); + if (b.preselect) setSource(b.preselect); + }) + .catch(() => setSources([])); + }, []); const [from, setFrom] = useState(""); const [to, setTo] = useState(""); const [title, setTitle] = useState(""); @@ -205,6 +224,7 @@ export default function NewArticleForm({ article: id, question, ...(channels.length ? { channels } : {}), + ...(source ? { source } : {}), model, ...(begin === "sweep" ? extractorBody(model, extractor, policy?.generation.models.extractor) : {}), ...(from ? { from } : {}), @@ -288,10 +308,33 @@ export default function NewArticleForm({ </div> </fieldset> ) : ( - <div className="flex flex-col gap-1"> - <span className="micro">channels{begin === "research" ? " (optional)" : ""}</span> - <ChannelPicker value={channels} onChange={setChannels} /> - </div> + <> + {sources && sources.length > 1 && ( + <label className="flex flex-col gap-1"> + <span className="micro">source</span> + <select + className={`${field} max-w-md`} + aria-label="source" + value={source} + onChange={(e) => { + setSource(e.target.value); + setChannels([]); + }} + > + {sources.map((s) => ( + <option key={s.handle || "local"} value={s.handle}> + {s.label} + {s.detail ? ` · ${s.detail}` : ""} + </option> + ))} + </select> + </label> + )} + <div className="flex flex-col gap-1"> + <span className="micro">channels{begin === "research" ? " (optional)" : ""}</span> + <ChannelPicker value={channels} onChange={setChannels} source={source} /> + </div> + </> )} <div className="flex flex-wrap items-end gap-4"> diff --git a/umtool/lib/articles/createSources.test.ts b/umtool/lib/articles/createSources.test.ts @@ -0,0 +1,26 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { createSourcesOf } from "./createSources"; +import type { SourceOption } from "../research/types"; + +const SOURCES: SourceOption[] = [ + { handle: "local:/x/export/public", kind: "local", label: "Local corpus" }, + { handle: "remote:https://stub.test", kind: "remote", label: "Stubalyzer", detail: "connected · stub.test" }, + { handle: "hub:https://hub.test", kind: "hub", label: "Hub" }, +]; +const ch = (slug: string, kind = "video") => ({ slug, name: slug, kind, platform: null, sites: [] }); + +test("Create offers the editor's corpus and each published archive, hubs aside", () => { + const r = createSourcesOf(SOURCES, [ch("alpha")]); + assert.deepEqual(r.sources.map((s) => s.handle), ["", "remote:https://stub.test"]); + assert.equal(r.preselect, ""); +}); + +test("with no local corpus the first archive is preselected; a remote-only channel is not a corpus", () => { + assert.equal(createSourcesOf(SOURCES, []).preselect, "remote:https://stub.test"); + assert.equal(createSourcesOf(SOURCES, [ch("stub-alpha", "remote-only")]).preselect, "remote:https://stub.test"); + // The editor did not answer: nothing is assumed. + assert.equal(createSourcesOf(SOURCES, null).preselect, ""); + // No archive to offer: the local corpus, empty or not. + assert.equal(createSourcesOf(SOURCES.slice(0, 1), []).preselect, ""); +}); diff --git a/umtool/lib/articles/createSources.ts b/umtool/lib/articles/createSources.ts @@ -0,0 +1,20 @@ +import type { SourceOption } from "@/lib/research/types"; +import type { EditorChannel } from "./generation"; + +// THE CREATE FORM'S SOURCES (demo epic D1 item 2), pure so it is tested +// without an editor: the editor's own corpus (handle "") first, then each +// published archive (`remote:<origin>`) the source picker offers. The first +// archive is preselected when the editor holds no channel of its own — a +// fresh clone with an archive connected sweeps that archive by default. A +// remote-only channel (held only to fetch an archive's clips) is not a local +// corpus. An editor that did not answer (null) preselects nothing: the form +// says it is down. +export type CreateSource = { handle: string; label: string; detail?: string }; + +export function createSourcesOf(sources: SourceOption[], editorChannels: EditorChannel[] | null): { sources: CreateSource[]; preselect: string } { + const local: CreateSource = { handle: "", label: "Local corpus", detail: "the editor's channels" }; + const remote = sources.filter((s) => s.kind === "remote").map((s) => ({ handle: s.handle, label: s.label, ...(s.detail ? { detail: s.detail } : {}) })); + const ownChannels = editorChannels?.filter((c) => c.kind !== "remote-only").length ?? null; + const preselect = ownChannels === 0 && remote.length > 0 ? remote[0].handle : ""; + return { sources: [local, ...remote], preselect }; +} diff --git a/umtool/lib/research/sources.test.ts b/umtool/lib/research/sources.test.ts @@ -0,0 +1,43 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; + +// The source picker (demo epic D1): connected archives are offered through +// the one resolver; with no local build, the first archive is the default. +const root = await mkdtemp(path.join(os.tmpdir(), "umtool-sources-")); +const local = path.join(root, "public"); +const settingsFile = path.join(root, "settings.json"); +await mkdir(path.join(root, "sites", "mysite"), { recursive: true }); +await writeFile(path.join(root, "sites", "mysite", "site.json"), JSON.stringify({ siteUrl: "https://stub.test/", siteTitle: "From site.json" })); +await writeFile(settingsFile, JSON.stringify({ remoteArchives: [{ id: "stub", origin: "https://stub.test", title: "Stubalyzer", addedAt: "2026-11-11T00:00:00Z" }] })); +process.env.SITES_DIR = path.join(root, "sites"); +process.env.SETTINGS_FILE = settingsFile; +process.env.TRANSCRIPT_LOCAL_DIR = local; +process.env.TRANSCRIPT_HUB_URL = ""; +process.env.TRANSCRIPT_SITE_URL = "https://env.test"; +const { listSources } = await import("./sources"); + +test.after(() => rm(root, { recursive: true, force: true })); + +test("no local build: the connected archives come first, site.json's duplicate is dropped, the env's is offered", async () => { + const s = await listSources(); + assert.deepEqual( + s.map((x) => [x.handle, x.label]), + [ + ["remote:https://stub.test", "Stubalyzer"], + ["remote:https://env.test", "env.test"], + [`local:${local}`, "Local corpus"], + ], + ); + assert.equal(s[2].detail, "this machine · no build"); +}); + +test("with a local build the local corpus is the default, the archives after it", async () => { + await mkdir(local, { recursive: true }); + await writeFile(path.join(local, "corpus.json"), JSON.stringify({ site: { title: "Mine" } })); + const s = await listSources(); + assert.equal(s[0].handle, `local:${local}`); + assert.deepEqual(s.slice(1).map((x) => x.handle), ["remote:https://stub.test", "remote:https://env.test"]); +}); diff --git a/umtool/lib/research/sources.ts b/umtool/lib/research/sources.ts @@ -54,7 +54,7 @@ async function readJson<T>(file: string): Promise<T | null> { } } -/** Every corpus the ask bar may read, the local one first. */ +/** Every corpus the ask bar may read, the default first: the local one, unless it has no build and an archive is offered. */ export async function listSources(): Promise<SourceOption[]> { const dir = localDir(); const corpus = await readJson<{ site?: { title?: string } }>(path.join(/* turbopackIgnore: true */ dir, "corpus.json")); @@ -91,7 +91,14 @@ export async function listSources(): Promise<SourceOption[]> { detail: `published · ${url.replace(/^https?:\/\//, "")}`, }); } - out.push(...sites); + // NO LOCAL CORPUS (no composed corpus.json on this machine — a fresh + // clone) and an archive to read: the archives come first, so the default + // source (`sources[0]` everywhere, and openSource with no handle) is the + // first archive (demo epic D1 item 2). The local entry stays offered, last. + if (!corpus && sites.length > 0) { + out[0] = { ...out[0], detail: "this machine · no build" }; + out.unshift(...sites); + } else out.push(...sites); const hub = hubUrl(settings); if (hub) out.push({ handle: `hub:${hub}`, kind: "hub", label: "Hub", detail: `every listed site · ${hub.replace(/^https?:\/\//, "")}` }); return out; diff --git a/umtool/package.json b/umtool/package.json @@ -8,7 +8,7 @@ "build": "next build", "start": "next start --port ${UMTOOL_PORT:-3050}", "typecheck": "tsc --noEmit", - "test": "tsx --test lib/brandIcon.test.ts lib/research/*.test.ts lib/inbox/*.test.ts lib/clips/*.test.ts components/projects/bench/*.test.ts", + "test": "tsx --test lib/brandIcon.test.ts lib/articles/*.test.ts lib/research/*.test.ts lib/inbox/*.test.ts lib/clips/*.test.ts components/projects/bench/*.test.ts", "e2e": "node ../scripts/worktree.mjs run -- node ../scripts/queue-lock.mjs --name e2e-umtool --estimate 1500 --prebuild umtool --ports UMTOOL_E2E_PORT:3051,EDITOR_STUB_PORT:3052 -- playwright test" }, "dependencies": {