Archilyzer · Source

archilyzer

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

commit e3f79f25f31e4ee595eb696031f92e5d82d0c84f
parent 27d208e463b2e56eed46f2bc1ff0b287a0797a3a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 05:46:48 -0400

plans: release 27 — report and video generation inside the application (draft for ratification)

Moves the ~/reports/local-reports stopgap (providers, agent loop, sweeps, revisions,
narration, the pipeline, the routing policy, /gen) into common/, editor jobs and umtool,
with tests and the usual gates; supersedes Q1–Q5 of local-llm-report-media.md.

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

Diffstat:
Mplans/local-llm-report-media.md | 2+-
Aplans/release-27.md | 200+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 201 insertions(+), 1 deletion(-)

diff --git a/plans/local-llm-report-media.md b/plans/local-llm-report-media.md @@ -1,6 +1,6 @@ # Report media from a local model — draft it in umtool, no agent session -Status: RATIFIED 2026-10-11 — D1, D2, D4, D5 as recommended; **D3 amended: the model may PROPOSE fact-check verdicts** +Status: Q1–Q5 SUPERSEDED by `plans/release-27.md` (2026-10-13). Was RATIFIED 2026-10-11 — D1, D2, D4, D5 as recommended; **D3 amended: the model may PROPOSE fact-check verdicts** (as `AWAITING_REVIEW`, the operator confirms each); ledger adjudication and posts stay human. Q0 runs now; Q1–Q5 are release 27, after release 26. diff --git a/plans/release-27.md b/plans/release-27.md @@ -0,0 +1,200 @@ +# Release 27 — report and video generation inside the application + +Status: DRAFT for ratification (2026-10-13). This plan supersedes slices Q1–Q5 of `plans/local-llm-report-media.md`. Its +Q0 record, rulings and scope changes stand, and are the inputs here. + +## Why + +The work is proven, but it runs in the wrong place. Since 2026-10-11, reports, revisions, narration and videos have +been made without Claude Code by a stopgap in `~/reports/local-reports/`: +- 2,850 lines of Python and bash; +- driven by the umtool POC page `/drafts`, which spawns those scripts. + +Real runs went through it on qwen3:8b and Claude Sonnet 5 / 5.5: +- an article with its video and podcast; +- revisions of a report and of a video; +- a model compared against another on the same base. + +It now has to become the application. That means: +- TypeScript in `common/`, run as editor jobs, driven from umtool; +- tested like everything else, with the same gates; +- no scripts outside the repo, and no `~/.config` files but the API key. + +## What moves, and where + +| Stopgap (`~/reports/local-reports/`) | What it does | Becomes | +|---|---|---| +| `claude_api.py` | Messages API over HTTPS. Key from env or a mode-600 file, never printed. Retries. Top-level `cache_control` plus a system breakpoint, 5m/1h TTL. Sonnet 5.5 rules (no temperature, no forced `tool_choice` so a strict tool instead, `thinking: between_tools`, append-only history). Price table and USD meter. | `common/lib/llm/anthropic.ts` | +| ollama calls (`local_sweep.chat`, `agentloop`) | `/api/chat` with a `format` schema or tools, `think:false`, `num_ctx` ≤ 12k, the 8k prompt cap, `done:false` read as a GPU fault | `common/lib/llm/ollama.ts` (extends `digestApps.ts`'s call) | +| `agentloop.py` | A tool loop on either provider. Claude server `web_search` and `pause_turn`. Local context fitting. Budget stop. | `common/lib/llm/agent.ts` | +| `mcpclient.py` | The MCP over stdio | the MCP's tools **in process** (D2) | +| `agentloop.web_search/web_fetch` | Paced DuckDuckGo search and a page reader, both read-only | editor actions `web-search` / `web-fetch` and an in-process paced module | +| `api_sweep.py` | `/sweep` as an agent: the `sweep_plan` text, Haiku `extract_batch`, report-file tools, convert, verify-quotes, the strict check, one bounded repair round, prompt rules (no quotes in claims, moment links) | task `sweep` (agent) | +| `local_sweep.py` (778) | A code-driven qwen sweep. The model proposes terms, judges, extracts and groups; code enumerates, windows, verifies, cites and covers. | task `sweep` (pipeline), D4 | +| `revise.py` | Report and video revisions through checked ops (drop, claim, merge, move, add, section, title, summary; drop, move, heading, narration, trim, add_clip, title), agent tools, quotes untouched | tasks `revise-report`, `revise-video` plus pure op engines | +| `local_narrate.py` | Card narration under `NARRATION_HARD_RULE`, the writing rules and the house taste, plus grounding checks (numbers and names in the report, no quotes read out, no tags, banned phrases) | task `narrate` plus `grounding.ts` | +| `bin/local-article` | Writes the article, fetches windows (`fetch-windows`), prepares and checks (other articles' gaps only a warning; captures this article's post screenshots), runs `to-manifest`, fixes the manifest | a umtool job chain over existing CLIs and functions, with `prepare --only` | +| `bin/local-video` + `with-editor.sh` | Editor TTS, `build-video --skip-fetch`, podcast, `attach-video`, dedupe | the same chain (`buildVideo` / `buildPodcast` are callable) | +| `seed_version.py`, `dedupe_media.py` | Carries narration and links voices from the parent; hard-links identical segments and voices (only files never written in place) | `umtool/lib/report/iterations.mjs` | +| `fix_manifest.py`, `windows_of.py`, `write-article.ts`, `apply-narration.mjs` | Glue | gone (the fixes land in `to-manifest`) | +| `gen.py` plus `~/.config/archilyzer/generation.json` | The routing policy (code / api / local per task, presets, models) | settings key `generation` (D6), MCP `generation_policy` | +| `~/.claude/commands/gen.md` | `/gen` for Claude Code | `.claude/commands/gen.md` in the repo, over MCP tools only (D8) | +| umtool `/drafts` (`lib/drafts.ts`, `DraftsPanel.tsx`) | Runs, versions, copy with model, compare, cancel, channel picker, policy panel | `/articles/new` and an article's **Iterations** tab (S7) | + +## Shape + +- **Vocabulary: an iteration.** An article's iterations are `i1`, `i2`, …. + - "version" is taken: `Report.version` is the format version, and the site history says "Revision N". + - "draft" is taken: an unpublished article is a draft. + - "take" is taken: umtool's alternative renders are takes. + - FACTS.md gets the hazard. +- **An iteration** is one generation's result plus its provenance: + - **kind:** `sweep`, `revise-report` or `revise-video`; + - the model, the parent iteration, the feedback or question, `copyOf`; + - cost and tokens per model, ops applied and refused, minutes, checks. +- **Iteration storage (D1).** + - The report side is kept in the article registry at `transcripts/reports/<id>/iterations/<n>/`: `report.json`, `sweep.md`, `iteration.json` and the transcript of turns. Every write goes through `registry.ts`: locked, validated, atomic. + - The article's own `report.json` is the **current** iteration, made current by "use this iteration". It is never written by a generation. + - Video projects and renders live off the corpus disk, under `settings.generation.projectsRoot` (default `~/reports/articles/<id>/i<n>/`). The iteration records its project path. +- **Generation runs as editor jobs**, in two queues: + - `report-draft` on `draft:local`. It yields to transcription AND to TTS: a new shared GPU arbiter, with `digestYield.ts`'s pattern extended to `ttsFile.ts`'s `waitForGpu`. It unloads ollama (`keep_alive: 0`) at the end. + - `report-draft` on `draft:api`: network work with its own concurrency, never the GPU lane or the heavy slot. + - Per-job and daily USD caps (D6). + - One ops action, `pnpm ops report-draft {task, article, iteration?, model, …}`, plus `job cancel`. + - The job writes the iteration through the registry. +- **The pipeline steps stay code and run as a umtool job chain over an iteration:** + - make current; fetch windows (editor); prepare `--only <id>`; capture this article's post screenshots (editor); + - `to-manifest`, seeded from the parent; voices (editor TTS); `buildVideo`; `buildPodcast`; `attach-video`; dedupe. + - umtool's job runner already kills a step's process group. +- **The corpus tools are the MCP's tools** (D2): + - `mcp/` exports `callTool(name, args, source)` over the SDK's in-memory transport, so the agent sees exactly what Claude Code sees. + - `source` is forced. + - The read-only set plus `notes` (list and read). + - `web-search` / `web-fetch` for the local model; Claude uses its server-side search. +- **Moment links never depend on `moment_base`.** A private site's build has no `siteUrl` (`corpus.ts:306`), so `moment_base` falls back to the platform URL or null. Drafting builds citation links from `(slug, id, seconds)` against the article's citation origin. The prompt rule and the YouTube→moment rewrite stay as a backstop. +- **Quotes.** + - verify-quotes scores token recall against a 0.6 threshold (`citations/verify.ts:34`), which passed a reversed quote at 0.85. + - A strict check is added: every quoted fragment verbatim (normalized) in the record's text within ±90 s. + - It refuses a generated quote, and verify-quotes reports it as a new status `inexact` (D3). + - Claims never carry quoted words. convertSweep makes every quoted span before a link that link's quote. This is enforced by the op engine and the prompts. +- **Claude Code integration** (D8): + - MCP tools `generation_policy` and `generate`. `generate` enqueues `report-draft` through the editor, like `enqueue`. + - `sweep_plan` / `ask_plan` read the policy. When a task routes to `api` or `local`, the plan tells Claude Code to call `generate`, wait, and REVIEW the result instead of doing the work itself. + - The policy's presets (`code`, `balanced`, `api`, `local`) move the balance either way. + - `.claude/commands/gen.md` in the repo wraps it. + +## Slices + +| # | Slice | Contents | Depends on | Gate | +|---|---|---|---|---| +| S0 | Setup (orchestrator) | `r27/integration` from `main`. The FACTS.md naming hazard ("iteration"; "version", "revision", "draft", "take" are taken). Synthetic fixtures: sweep.md variants (quotes in claims, several quotes per link, posts only, paragraphs between findings), manifests, a fixture corpus record with cues. **No real transcripts.** Fake servers: Anthropic Messages (scripted turns, `pause_turn`, server tool blocks, 400s for the Sonnet 5.5 rules) and ollama (`/api/chat` with tools and `format`). | — | — | +| S1 | Providers and agent loop | `common/lib/llm/{anthropic,ollama,structured,agent,meter,prices}.ts`. The key from `settings.generation.apiKeyFile` or env, never logged (test: the key string appears in no log, error or job record). Caching, TTL, strict-model rules, the strict structured answer, retries, `pause_turn`, budget stop, append-only once thinking blocks appear, local context fitting. | S0 | unit vs the fakes | +| S2 | Checks and op engines | Strict check in `citations/verify.ts` plus the verify-quotes `inexact` status. `report/draft/grounding.ts` (narration). `report/draft/reportOps.ts`: the sweep.md model (claim / sep / rest split at the first quote; sections keep body order) and the ops, including merge chains. `videoOps.ts` (trim bounds, add_clip from citations, narration via grounding). | S0 | unit: **round-trip over every fixture**; op batches number against the start of the batch; refusals carry reasons | +| S3 | Tools | `mcp/` exports `callTool` (in-memory transport, `source` forced, a read-only allowlist, `notes` list/read). Editor actions `web-search` / `web-fetch`: paced one at a time with 3 s gaps, read-only, through `_lib.ts` adapters, COMMANDS.md. An in-process paced module for jobs. | S0 | unit; the mcp suite unchanged | +| S4 | Iterations store | `common/lib/report/iterations.ts`: create, list, read, `makeCurrent` (writes `report.json` through `writeArticle`), `copy` (same base, another model), lineage, `projectOf`. The registry's locking. `archilyzer reports iterations <id>`. | S0 | unit: lineage, current, copy, locking under contention | +| S5 | Tasks | `report/draft/tasks/{sweep-agent,sweep-pipeline,revise-report,revise-video,narrate}.ts` on S1–S4. Each returns an iteration. The prompts are read from `instructions.ts` and `authoringRules.ts` (rules moved there once). | S1 S2 S3 S4 | unit vs fakes over the fixture corpus; one recorded transcript per task | +| S6 | Editor jobs, settings, ops | Job kinds `report-draft` (queues `draft:local`, `draft:api`). The GPU arbiter shared with TTS and transcription. Unloading ollama. Caps. `pnpm ops report-draft` + route + `job cancel`. Settings key `generation` (routes, models api/local/extractor, caps, cacheTtl, apiKeyFile, projectsRoot, web provider) plus SETTINGS.md. Usage rows for the metered lane (the digest "metered" precedent). | S5 | unit; one editor e2e spec (`report-draft` against the fakes) | +| S7 | Pipeline chain and owed bugs | umtool chain over an iteration (above). `reports prepare --article <id> --only`. Capture this article's posts. `to-manifest`: title `foot` (`convertManifest.ts:428` + a guard at `render-cards.mjs:112`), no silent Coverage end card, the parent seed. `fetch-windows` folds `pad` into coverage (`fetchWindows.ts:379`, `fetchWindowManaged.ts:171`). `umtool build --dry` resolves from the module, not cwd (`driver.mjs:14,416`). Dedupe (segments and voices only). | S4 | unit per bug; `umtool` build e2e | +| S8 | umtool UI | `/articles/new`: question, a channel picker over the editor's channels, model, caps. The article's **Iterations** tab: the list, current article and current video, new iteration (target report or video, model, feedback), copy with model, per-step model, cancel, cost, live job progress from `/api/ops/job`. `/articles/<id>/compare?a=&b=`: side by side, with ops applied and refused. The policy panel (writes `generation` through the editor's settings action). `/drafts` redirects. | S6 S7 | e2e: `article-new.spec`, `article-iterations.spec`, `article-compare.spec` over the editor stub + fake LLM | +| S9 | Claude Code balance | MCP `generation_policy` and `generate` (enqueue + follow). `instructions.ts`: the routing step in `sweep_plan` / `ask_plan`, plus review guidance. `.claude/commands/gen.md`. `archilyzer gen policy\|preset\|set\|run` (CLI over the same settings). | S6 | mcp unit; protocol test lists the tools | +| S10 | Migration, docs, retire | `archilyzer reports import-local-runs` (dry run by default): the stopgap's kept runs become iterations (D9), and `generation.json` becomes settings. OPERATING.md "Generate and iterate". `umtool/docs/authoring.md` "Generating with a model". REPORT.md. CHANGELOG. `plans/STATE.md`. The stopgap's RUNBOOK points here. | S8 S9 | the import's dry run reviewed by the operator | + +**Dependency graph.** +``` +S0 ─┬─ S1 ─┐ + ├─ S2 ─┼─ S5 ─ S6 ─┬─ S8 ─┐ + ├─ S3 ─┤ └─ S9 ─┼─ S10 + └─ S4 ─┴─ S7 ──────── S8 ┘ +``` +**Lanes.** At most three Opus implementers at once, each in its own worktree from `r27/integration`: +- **Phase 1:** lane A S1, lane B S2 then S3, lane C S4 then S7. +- **Phase 2:** S5 then S6 (one implementer, since they share the job's surface). +- **Phase 3:** S8 and S9 in parallel, then S10. + +Each slice is merged `--no-ff` as it finishes, with its suites re-run. + +## Gates (on the `r27/integration` tip) + +- `pnpm typecheck`, `pnpm test`, `docs env|files|cli --check`, `settings example --check`. +- The four builds through the heavy slot (capped). +- `pnpm e2e:all`: editor, export, umtool (with the three new specs) and homepage. A red is re-run alone; a red that stays red blocks. +- **Live smoke** (operator's key, ≤ $3, through the UI): + - a Sonnet 5.5 sweep on a small channel; + - a report iteration and a video iteration; + - a qwen narration; + - a copy-with-model compare; + - the chain to a video and podcast; + - a cancel mid-step; + - `/gen` from Claude Code routing one task to the API. +- Privacy greps on `main..r27/integration`, counts only: + - no session links; + - no key-like strings (`sk-ant-`); + - no Candace data; + - no `~/.config/archilyzer` contents; + - the source mirror's `--check`. + +## Rollout + +- Fast-forward `main`. +- Editor: build, restart, smoke (new job kinds and actions). +- umtool: build, restart. +- MCP: Claude Code picks up the new tools on its next start. +- Homepage source-mirror publish. No public site changes. +- Then `import-local-runs --apply` after the operator reads the dry run. +- The stopgap stays read-only until the operator deletes it (D9). + +## Pacing + +- Phase 1 is three parallel lanes, about 3–4 h each. +- Phase 2 is about 4 h. +- Phase 3 is about 4 h plus the gate round (about 1.5 h) and the rollout. +- That's about two working days of agent time, within the weekly budget at the usual two heavyweight jobs and one marathon per 5 h window. +- Each slice commits as it goes, so a session limit mid-slice loses nothing. +- The stopgap keeps working throughout. Nothing in the live editor or umtool changes until the rollout. + +## Decisions (for the operator) + +- **D1 — where iterations live.** + - The report side in the registry (`transcripts/reports/<id>/iterations/<n>/`). + - Video projects and renders under `settings.generation.projectsRoot` (default `~/reports/articles/<id>/i<n>/`), off the corpus disk. + - *Recommended.* + - Alternative: everything under the article dir, renders included. That is about 50–100 MB per iteration on the corpus SSD. +- **D2 — corpus tools for the agents.** + - The MCP's own tools in process (an export over the in-memory transport). *Recommended:* one behaviour for Claude Code and the jobs. + - Alternative: re-implement search, enumerate and transcript reads in `common/`. +- **D3 — strict quotes.** + - Generated quotes must pass the strict check (verbatim within ±90 s). + - verify-quotes reports `inexact` as a warning for existing reports. + - Compose and publish are unchanged until an audit of the 27 articles. + - *Recommended.* + - Alternative: compose refuses `inexact` now, which may hold articles. +- **D4 — the free sweep.** + - Port the code-driven qwen sweep pipeline (778 lines; the only sweep that fits qwen's 8k context). *Recommended.* + - Alternative: drop it; qwen then only revises and narrates, and sweeps are Claude Code or the API. +- **D5 — scope of tasks in r27.** + - Move and test what the stopgap does (sweep, revise report/video, narrate, the pipeline). *Recommended.* + - Leave release 28 for the plan's remaining media tasks (clip selection and order, on-screen titles, teaser, flips, threads, YouTube title and description, proposed verdicts) on the same machinery. + - Alternative: all in r27, about two days more. +- **D6 — spend caps and policy in settings.** + - A per-job default ($5 sweep, $2 revision, $1 narration). + - A daily API cap of $20; a job past it is refused with the day's total. + - The routing policy as the `generation` settings key, replacing `generation.json`. + - *Recommended.* +- **D7 — web search for the local model.** + - A paced DuckDuckGo HTML read (works today, no service to run). *Recommended.* + - Alternative: a self-hosted SearXNG. +- **D8 — Claude Code balance.** + - MCP `generate` / `generation_policy`, with `sweep_plan` routing by the policy, and `/gen` in the repo. *Recommended.* + - Alternative: keep `/gen` as a shell-command wrapper only. +- **D9 — the stopgap's runs.** + - Import `piratesoftware-ai-friends` and `api-shondo-recent` (and any others you name) as iterations. + - Delete the `ui-test-*`, `shondo-*`, `local-test-*` runs and projects (about 320 MB). + - Keep `~/reports/local-reports` read-only until you delete it after r27 is live. + - *Recommended.* + +## Not in this release + +- The A7 leftovers: 42 post screenshots and 2 windows (`~/reports/release-26/scripts/a7-fill-media.sh`). +- Deleting the candalyzer site. +- The hub tombstone. +- The owed items listed in `plans/local-llm-report-media.md`'s record.