Archilyzer · Source

archilyzer

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

commit 319122839c7ae974163cea04f356f010323aa401
parent 576ef87799c1d2ac1603f7bf1231733db9423574
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 13:28:00 -0400

mcp, common: release 27 S9 — the repo's /gen over the MCP tools; README and env docs

.claude/commands/gen.md: the policy from generation_policy, routed tasks
through generate and reviewed, code tasks done in the session, the balance
moved only when the operator asks. mcp/README.md gains the two tools and a
/gen paragraph; WORKER_TOKEN and ARCHILYZER_EDITOR_URL name them and
`archilyzer gen` (ENVIRONMENT.md regenerated).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
A.claude/commands/gen.md | 45+++++++++++++++++++++++++++++++++++++++++++++
MENVIRONMENT.md | 4++--
Mcommon/lib/envVars.ts | 4++--
Mmcp/README.md | 23++++++++++++++++++-----
Mmcp/src/editorOps.ts | 4+++-
5 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/.claude/commands/gen.md b/.claude/commands/gen.md @@ -0,0 +1,45 @@ +--- +description: Media generation (reports, revisions, video cuts, narration) routed by the operator's balance policy — Claude Code, the Claude API, or the local model +--- + +The operator balances media-generation work between this Claude Code session, the Claude API (billed apart from +the Code plan) and the local model (free). The policy — `settings.generation`, in the editor — decides who does +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 + 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 + 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. +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 + for it. To move the balance itself, `generation_policy` with `preset` (code, balanced, api, local) or with + `task` and `route` — only when the operator asks. + +The request: + +$ARGUMENTS + +<!-- +The repo's /gen (release 27 S9, D8). It replaces the stopgap's user-level +command of the same name, which drove the stopgap's own scripts; that one is +retired with the stopgap (release 27 S10). + +Same editing caveats as `.claude/commands/sweep.md`: no `$1` placeholders in +this body (they tokenize), and the `mcp__archilyzer__` prefix is the MCP +server's name as registered on this machine (AGENTS.md: register it as +`archilyzer`). The tools need an editor: the MCP registered with +ARCHILYZER_EDITOR_URL and WORKER_TOKEN. + +The routing and review discipline lives in the server (`mcp/src/generation.ts` +and `mcp/src/instructions.ts`), not here. +--> diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md @@ -57,7 +57,7 @@ Tokens, credentials and knobs a running process reads. Most configuration is not | Variable | Default | What it does | Read by | |---|---|---|---| -| `WORKER_TOKEN` | unset (both surfaces off) | Bearer token for the remote-worker API and for `/api/ops/*` (`pnpm ops`; the MCP's `fetch_clip`, `enqueue`, `get_job`, `channel_coverage` and `get_transcript`'s editor fallback), and for an agent's write to umtool's notes (the MCP's `notes` reply, stamped "agent"; umtool reads it from its environment, else the editor's `editor/.env`). Set the same value on every end. | common/lib/workerToken.ts, scripts/archilyzer-ops.mjs, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, mcp/src/archivalTools.ts, umtool/lib/annotations/agentAuth.mjs | +| `WORKER_TOKEN` | unset (both surfaces off) | Bearer token for the remote-worker API and for `/api/ops/*` (`pnpm ops` and `archilyzer gen`; the MCP's `fetch_clip`, `enqueue`, `get_job`, `channel_coverage`, `generation_policy`, `generate` and `get_transcript`'s editor fallback), and for an agent's write to umtool's notes (the MCP's `notes` reply, stamped "agent"; umtool reads it from its environment, else the editor's `editor/.env`). Set the same value on every end. | common/lib/workerToken.ts, scripts/archilyzer-ops.mjs, common/bin/gen.ts, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, mcp/src/archivalTools.ts, umtool/lib/annotations/agentAuth.mjs | | `ANTHROPIC_API_KEY` | unset (the API key file is read instead) | The Claude API key for report and video generation on the API (release 27): read first, before the mode-600 key file the generation settings name. Sent only to the Messages API in `x-api-key`; never logged, and never in an error, a job record or a transcript. | common/lib/llm/anthropic.ts | | `SYNC_HEARTBEAT_SECONDS` | `settings.syncScheduler.heartbeatSeconds` | Overrides the editor's in-process sync heartbeat. `0` = no internal timer (tick from cron instead). | editor/app/scheduler/heartbeat.ts | | `SYNC_TICK_URL` | `http://127.0.0.1:3001/api/scheduler/tick` | Where `archilyzer sync tick` (cron's heartbeat) posts. | common/bin/sync-tick.ts | @@ -98,7 +98,7 @@ Tokens, credentials and knobs a running process reads. Most configuration is not | `ARCHILYZER_INDEX_ALLOW_HELD` | off | `1` lets a FULL index rebuild (a schema change, or no index yet) proceed while a channel's media cannot be read; that channel stays out of the index until its media is back and the index is built again. Unset, such a build refuses and names each channel. | common/controller/buildIndex.ts | | `UV_THREADPOOL_SIZE` | `16` for the editor (`4` is Node's own) | Threads in Node's pool for filesystem calls. A call on a stalled drive holds one until the drive answers, so the editor starts with 16. It buys time for calls already in flight and isolates nothing: the storage health probe and its gate keep new calls off a stalled drive. | Node's libuv (set by editor/package.json `start` and docker/entrypoint.sh) | | `MCP_IO_STATS` | off | `1` turns on per-call I/O accounting, for `mcp/bench`. | common/lib/archive/io-stats.ts | -| `ARCHILYZER_EDITOR_URL` | `http://localhost:3001` | Which editor `pnpm ops` and the MCP's editor-backed tools (`fetch_clip`, `enqueue`, `get_job`, `channel_coverage`, `get_transcript`'s fallback) talk to, and whose `/api/pulse` `archilyzer storage migrate-tier` asks before it refuses to run beside it. | scripts/archilyzer-ops.mjs, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, umtool, common/bin/migrate-media-tier.ts | +| `ARCHILYZER_EDITOR_URL` | `http://localhost:3001` | Which editor `pnpm ops`, `archilyzer gen` and the MCP's editor-backed tools (`fetch_clip`, `enqueue`, `get_job`, `channel_coverage`, `generation_policy`, `generate`, `get_transcript`'s fallback) talk to, and whose `/api/pulse` `archilyzer storage migrate-tier` asks before it refuses to run beside it. | scripts/archilyzer-ops.mjs, common/bin/gen.ts, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, umtool, common/bin/migrate-media-tier.ts | | `ARCHILYZER_AGENT` | `cli` | Who is asking, recorded as the provenance of a curated-tag write through `pnpm ops`. | scripts/archilyzer-ops.mjs | | `DIARIZE_ENGINE_KIND` | `sherpa-onnx` | The diarization engine: `sherpa-onnx` or `sortformer`. | scripts/diarize.mjs | | `DIARIZE_ENGINE_CMD` | the bundled sherpa script | The engine command the wrapper runs. | scripts/diarize.mjs | diff --git a/common/lib/envVars.ts b/common/lib/envVars.ts @@ -93,7 +93,7 @@ const DECLARED: EnvVarDecl[] = [ paths("STAGIT_BIN", "`stagit` on PATH, then `~/.local/bin/stagit`", "stagit, which renders the source's history pages (`/source/git/`: the log and a page per commit with its diff). Optional: without it the source is published without them. See [PUBLISH.md](PUBLISH.md)."), // ── runtime ──────────────────────────────────────────────────────────── - { name: "WORKER_TOKEN", audience: "runtime", default: "unset (both surfaces off)", readBy: "common/lib/workerToken.ts, scripts/archilyzer-ops.mjs, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, mcp/src/archivalTools.ts, umtool/lib/annotations/agentAuth.mjs", doc: "Bearer token for the remote-worker API and for `/api/ops/*` (`pnpm ops`; the MCP's `fetch_clip`, `enqueue`, `get_job`, `channel_coverage` and `get_transcript`'s editor fallback), and for an agent's write to umtool's notes (the MCP's `notes` reply, stamped \"agent\"; umtool reads it from its environment, else the editor's `editor/.env`). Set the same value on every end." }, + { name: "WORKER_TOKEN", audience: "runtime", default: "unset (both surfaces off)", readBy: "common/lib/workerToken.ts, scripts/archilyzer-ops.mjs, common/bin/gen.ts, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, mcp/src/archivalTools.ts, umtool/lib/annotations/agentAuth.mjs", doc: "Bearer token for the remote-worker API and for `/api/ops/*` (`pnpm ops` and `archilyzer gen`; the MCP's `fetch_clip`, `enqueue`, `get_job`, `channel_coverage`, `generation_policy`, `generate` and `get_transcript`'s editor fallback), and for an agent's write to umtool's notes (the MCP's `notes` reply, stamped \"agent\"; umtool reads it from its environment, else the editor's `editor/.env`). Set the same value on every end." }, { name: "ANTHROPIC_API_KEY", audience: "runtime", default: "unset (the API key file is read instead)", readBy: "common/lib/llm/anthropic.ts", doc: "The Claude API key for report and video generation on the API (release 27): read first, before the mode-600 key file the generation settings name. Sent only to the Messages API in `x-api-key`; never logged, and never in an error, a job record or a transcript." }, { name: "SYNC_HEARTBEAT_SECONDS", audience: "runtime", default: "`settings.syncScheduler.heartbeatSeconds`", readBy: "editor/app/scheduler/heartbeat.ts", doc: "Overrides the editor's in-process sync heartbeat. `0` = no internal timer (tick from cron instead)." }, { name: "SYNC_TICK_URL", audience: "runtime", default: "`http://127.0.0.1:3001/api/scheduler/tick`", readBy: "common/bin/sync-tick.ts", doc: "Where `archilyzer sync tick` (cron's heartbeat) posts." }, @@ -134,7 +134,7 @@ const DECLARED: EnvVarDecl[] = [ { name: "ARCHILYZER_INDEX_ALLOW_HELD", audience: "runtime", default: "off", readBy: "common/controller/buildIndex.ts", doc: "`1` lets a FULL index rebuild (a schema change, or no index yet) proceed while a channel's media cannot be read; that channel stays out of the index until its media is back and the index is built again. Unset, such a build refuses and names each channel." }, { name: "UV_THREADPOOL_SIZE", audience: "runtime", default: "`16` for the editor (`4` is Node's own)", readBy: "Node's libuv (set by editor/package.json `start` and docker/entrypoint.sh)", doc: "Threads in Node's pool for filesystem calls. A call on a stalled drive holds one until the drive answers, so the editor starts with 16. It buys time for calls already in flight and isolates nothing: the storage health probe and its gate keep new calls off a stalled drive." }, { name: "MCP_IO_STATS", audience: "runtime", default: "off", readBy: "common/lib/archive/io-stats.ts", doc: "`1` turns on per-call I/O accounting, for `mcp/bench`." }, - { name: "ARCHILYZER_EDITOR_URL", audience: "runtime", default: "`http://localhost:3001`", readBy: "scripts/archilyzer-ops.mjs, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, umtool, common/bin/migrate-media-tier.ts", doc: "Which editor `pnpm ops` and the MCP's editor-backed tools (`fetch_clip`, `enqueue`, `get_job`, `channel_coverage`, `get_transcript`'s fallback) talk to, and whose `/api/pulse` `archilyzer storage migrate-tier` asks before it refuses to run beside it." }, + { name: "ARCHILYZER_EDITOR_URL", audience: "runtime", default: "`http://localhost:3001`", readBy: "scripts/archilyzer-ops.mjs, common/bin/gen.ts, mcp/src/fetchClip.ts, mcp/src/editorOps.ts, umtool, common/bin/migrate-media-tier.ts", doc: "Which editor `pnpm ops`, `archilyzer gen` and the MCP's editor-backed tools (`fetch_clip`, `enqueue`, `get_job`, `channel_coverage`, `generation_policy`, `generate`, `get_transcript`'s fallback) talk to, and whose `/api/pulse` `archilyzer storage migrate-tier` asks before it refuses to run beside it." }, { name: "ARCHILYZER_AGENT", audience: "runtime", default: "`cli`", readBy: "scripts/archilyzer-ops.mjs", doc: "Who is asking, recorded as the provenance of a curated-tag write through `pnpm ops`." }, { name: "DIARIZE_ENGINE_KIND", audience: "runtime", default: "`sherpa-onnx`", readBy: "scripts/diarize.mjs", doc: "The diarization engine: `sherpa-onnx` or `sortformer`." }, { name: "DIARIZE_ENGINE_CMD", audience: "runtime", default: "the bundled sherpa script", readBy: "scripts/diarize.mjs", doc: "The engine command the wrapper runs." }, diff --git a/mcp/README.md b/mcp/README.md @@ -12,8 +12,11 @@ The exceptions all ask a local Archilyzer editor (`ARCHILYZER_EDITOR_URL` + window, `enqueue` queues archival work, `get_job` / `channel_coverage` read the editor's jobs and disk, and `get_transcript` falls back to the editor's disk for a video not yet published; `notes` reads umtool (`UMTOOL_URL`) and writes a reply -there as the agent's. The MCP itself still writes nothing. Settings, storage and -deletes are not reachable from it (`pnpm ops` only). +there as the agent's; `generate` runs a report or video generation as an editor +job and `generation_policy` reads (and, when the operator asks, sets) where each +generation task runs. The MCP itself still writes nothing. Settings — but for the +generation routes — storage and deletes are not reachable from it (`pnpm ops` +only). ## Tools @@ -33,10 +36,12 @@ deletes are not reachable from it (`pnpm ops` 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. | | `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. | -| `sweep_plan` / `ask_plan` | Turn a plain-English request (plus an optional pasted link) into a resolved, step-by-step plan. What `/sweep` and `/ask` call. | +| `sweep_plan` / `ask_plan` | Turn a plain-English request (plus an optional pasted link) into a resolved, step-by-step plan. What `/sweep` and `/ask` call. With an editor configured they read the generation policy: a sweep routed to `api` or `local` becomes "call `generate`, wait, review it" (`via=code` in the request runs it here instead); an ask names the routed tasks. | **Clickable moment links.** Every timestamp the read tools emit is a Markdown link to the exact second — an **archilyzer viewer** deep link (`…/?v=<slug>&t=<sec>`, @@ -298,6 +303,14 @@ tools and the prompt — rather than duplicated into the markdown command files, so it cannot drift out of sync with the tools it names. A test asserts every tool the instructions mention actually exists. +### `/gen` + +`.claude/commands/gen.md` is the generation balance's entry point (release 27): +it reads `generation_policy`, maps the request to tasks, runs each task routed to +`api` or `local` through `generate` and **reviews** what it made, and does a task +routed to `code` in the session (`/sweep` for a report). `archilyzer gen +policy|preset|set|run` is the same balance from a terminal. + ## Counts are of recordings, not uploads Some videos exist in the archive more than once — the same recording mirrored to @@ -505,8 +518,8 @@ nothing to reset). **Still read-only.** A `source` handle only changes *which* already-published static shards are read — the same capability the startup flags already grant -this locally-run tool. This server never writes to any corpus; `fetch_clip` and -`enqueue` ask the editor, and the editor writes. +this locally-run tool. This server never writes to any corpus; `fetch_clip`, +`enqueue` and `generate` ask the editor, and the editor writes. ## Protocol diff --git a/mcp/src/editorOps.ts b/mcp/src/editorOps.ts @@ -18,7 +18,9 @@ import { // said in words, never as a stack. // // Settings, storage and deletes are NOT reachable from here (operator ruling, -// release 19): those stay `pnpm ops` / `archilyzer` only. +// release 19): those stay `pnpm ops` / `archilyzer` only. The one exception is +// the generation routes, which generation_policy writes when the operator asks +// (release 27 D8; generation.ts). export type EditorDeps = Pick<FetchClipDeps, "env" | "fetch" | "requestTimeoutMs">;