diff --git a/.ascii-to-svg-manifest.json b/.ascii-to-svg-manifest.json
new file mode 100644
index 0000000..689c7a8
--- /dev/null
+++ b/.ascii-to-svg-manifest.json
@@ -0,0 +1,56 @@
+{
+ "version": "1.0.0",
+ "lastSync": "2026-11-05T19:40:31Z",
+ "diagrams": [
+ {
+ "id": "three-outputs",
+ "sourceFile": "README.md",
+ "sourceLine": 42,
+ "svgFile": "assets/diagrams/three-outputs.svg",
+ "asciiHash": "sha256:7082517f21d167c59b50d6abde2576e45af1403eedab8492e11877477d84b88f",
+ "svgHash": "sha256:2dadf13f32f4e295fac5349ce47ed1e74fc1a571a22f906de647e78c2887b7d3",
+ "diagramType": "flowchart",
+ "lastConverted": "2026-11-05T19:08:23Z"
+ },
+ {
+ "id": "stations",
+ "sourceFile": "README.md",
+ "sourceLine": 70,
+ "svgFile": "assets/diagrams/stations.svg",
+ "asciiHash": "sha256:dd9281870048657b723ef94cc813dff8205f3c9ae78976946726b6120fe1a581",
+ "svgHash": "sha256:295f1246180abfa142db95e9064df861b1447d33fb7cb6107a7c4906cc2877d8",
+ "diagramType": "architecture",
+ "lastConverted": "2026-11-05T19:08:23Z"
+ },
+ {
+ "id": "quality-gate",
+ "sourceFile": "README.md",
+ "sourceLine": 105,
+ "svgFile": "assets/diagrams/quality-gate.svg",
+ "asciiHash": "sha256:5ff394c8fac5028bd000d6bc2c9d3049f2f46cd42d836b76f456e0e0701f1d38",
+ "svgHash": "sha256:aa9cf10d6b700ba38f87d528b88ca0aa32c80792a05540eb72a64d18a9e316ec",
+ "diagramType": "flowchart",
+ "lastConverted": "2026-11-05T19:08:23Z"
+ },
+ {
+ "id": "learning-loop",
+ "sourceFile": "README.md",
+ "sourceLine": 136,
+ "svgFile": "assets/diagrams/learning-loop.svg",
+ "asciiHash": "sha256:345b491348a7383ef598b0f8ee7422fb536314b89eee21f365bfaba4755ede7f",
+ "svgHash": "sha256:8a6e6b453f4b94bfa87d3ecde1ede90f54ffd9cdcfbc27e399216c4c3348d2b8",
+ "diagramType": "flowchart",
+ "lastConverted": "2026-11-05T19:08:23Z"
+ },
+ {
+ "id": "two-doors",
+ "sourceFile": "README.md",
+ "sourceLine": 162,
+ "svgFile": "assets/diagrams/two-doors.svg",
+ "asciiHash": "sha256:22445671b2e3f554eefc3a6bd8fd1a49ad2c83fd5c7f036831774edc70ac8b51",
+ "svgHash": "sha256:858bb7f307f752ece197c6730e906476fed3e942145201b723d1eca6157d7109",
+ "diagramType": "architecture",
+ "lastConverted": "2026-11-05T19:08:23Z"
+ }
+ ]
+}
diff --git a/.github/workflows/build-explainer.yml b/.github/workflows/build-explainer.yml
index 711827b..3de1b0c 100644
--- a/.github/workflows/build-explainer.yml
+++ b/.github/workflows/build-explainer.yml
@@ -4,13 +4,8 @@ name: Build Explainer
# keys (repo secrets), deploy it to its own Netlify site, and write progress back to a status
# gist that the website polls. Triggered by the /build Netlify function.
#
-# ARCHITECTURE (2026-07-04 rebuild — see project memory "hosted-agentic-architecture", approved
-# 2026-06-30 but never actually wired until now): this invokes bin/agentic-runner.mjs, which runs
-# the real explainmyrepo SKILL as a headless Claude Code agent — the brain decides, tools/*.mjs do
-# the mechanics — instead of the old deterministic orchestrator.mjs pipeline. GitHub Actions is
-# still the right HOST for this (ADR-033, agent-harness-generator: triggered, autonomous, no human
-# at the keyboard); what changed is that it now runs the AGENT, which adapts per-repo, instead of a
-# fixed script that broke on off-mold repos (empty dep-graphs, oversized monorepos).
+# ARCHITECTURE: bin/agentic-runner.mjs runs the explainmyrepo SKILL as a headless Claude Code agent (the brain
+# decides, tools/*.mjs do the mechanics); GitHub Actions is only the host. The local door is src/orchestrator.mjs.
#
# RAILS: timeout-minutes is COMPUTED from budget_min (a pre-flight repo-size signal from build.js)
# instead of one fixed ceiling for every repo · serialized concurrency (no cost fan-out) · the
@@ -57,19 +52,16 @@ jobs:
runs-on: ubuntu-latest
# The agent enforces its OWN budget (budget_min) internally and exits cleanly well before this
# outer ceiling would ever need to fire — this is just the backstop. timeout_min is budget_min +
- # a fixed overhead buffer, computed in build.js (plain JS), not here: GitHub Actions expressions
- # don't support arithmetic on inputs the way `fromJSON(x) + 10` implies — learned this the hard
- # way, it rejects the whole dispatch at parse time, which a YAML-structure check doesn't catch
- # since it's an expression-syntax error, not a YAML one.
+ # a fixed overhead buffer computed in build.js (Actions expressions cannot add to an input).
timeout-minutes: ${{ fromJSON(inputs.timeout_min || '30') }}
steps:
- name: Checkout the explainer tool
- uses: actions/checkout@v4
+ uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
- name: Set up Node
- uses: actions/setup-node@v4
+ uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
- node-version: "20"
+ node-version: 22
- name: Validate input (abuse guard)
env:
@@ -79,34 +71,29 @@ jobs:
REPO: ${{ github.event.inputs.target_repo }}
run: |
echo "target: $REPO"
- if ! printf '%s' "$REPO" | grep -qE '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; then
+ if ! printf '%s' "$REPO" | grep -qE '^[A-Za-z0-9_][A-Za-z0-9_.-]*/[A-Za-z0-9_][A-Za-z0-9_.-]*$'; then
echo "::error::invalid repo format (expected owner/name): $REPO"; exit 1
fi
- name: Install dependencies
run: |
- npm ci || npm install
- # Belt-and-suspenders: guarantee the 3 runtime deps are present (CI 'npm ci' was leaving
- # playwright unresolved -> quality-grade failed). EXACT pinned versions + --no-save so this
- # cannot drift to a newer/compromised patch or rewrite the committed lockfile (no supply-
- # chain bypass; these match package-lock.json).
- npm install --no-save playwright@1.61.1 @xenova/transformers@2.17.2 @ruvector/rvf@0.2.2
+ # The lockfile is the single source of truth for runtime deps (playwright, @xenova/transformers,
+ # @ruvector/rvf, sharp); no ad-hoc --no-save installs that could drift from it.
+ npm ci
npx playwright install --with-deps chromium
# System tools the pipeline shells out to (scanned from tools/*.mjs), not all preinstalled
# on the runner: ImageMagick (magick/convert/identify — favicon, social card), xmllint
- # (libxml2-utils — diagram SVG validation), dot (graphviz — diagram layout), zip (AI pack).
+ # (libxml2-utils — diagram SVG validation), zip (AI pack).
# Fonts help text render in generated imagery.
- sudo apt-get update && sudo apt-get install -y imagemagick libxml2-utils graphviz zip fonts-liberation fonts-dejavu-core
+ sudo apt-get update && sudo apt-get install -y imagemagick libxml2-utils zip fonts-liberation fonts-dejavu-core
# The agentic kernel itself (bin/agentic-runner.mjs spawns this headless) — pinned exact
# version, same rationale as the runtime deps above: no supply-chain drift on a bare runner.
npm install -g @anthropic-ai/claude-code@2.1.201
claude --version
- # 2026-07-16 HF outage (build 79f135b3): a CloudFront outage made the mandatory embedding
- # model undownloadable and the agent burned its whole budget discovering it. Cache the
- # 33 MB model between runs so KB builds are offline-first; the warm step downloads it only
- # when the cache is cold and VALIDATES it with one real embedding. Warm failure is a soft
- # warning: the runner's own embedding preflight is the honest gate and alerts in seconds.
+ # Cache the embedding model between runs so KB builds are offline-first (an HF outage once burned a whole
+ # agent budget); the warm step downloads only when cold and validates with one real embedding. A warm
+ # failure is a soft warning: the runner's embedding preflight is the honest gate.
- name: Restore embedding model cache (offline-first KB)
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
@@ -122,9 +109,7 @@ jobs:
# failure alert) — the runner builds a SEPARATE, much narrower allowlist for the spawned
# agent process itself (see bin/agentic-runner.mjs), which never sees GH/SMTP creds.
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- # Failover lane only (2026-07-19): engaged by the runner's preflight EXCLUSIVELY when the
- # primary key is usage-limited — same executor model via OpenRouter's Anthropic Skin.
- # Empty when the secret is unset: the lane stays inert and behavior is unchanged.
+ # Failover lane only: the runner's preflight uses it when the primary key is usage-limited.
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
@@ -164,11 +149,8 @@ jobs:
exit 1
fi
- # A failed run's assembled work is NOT garbage (learned 2026-07-15: autonomous-wealth-builder
- # built a complete grounded site, stalled at B5 56/58, and the runner's _temp dir evaporated
- # with the job — the whole spend was lost when a 10-minute operator cure could have finished
- # it). Preserve the curable core (site + build.json + graded assets; NOT the repo clone, NOT
- # logs) so the operator can download, fix, re-grade, and deploy without a rebuild.
+ # A failed run's assembled work is not garbage: keep the curable core (site + build.json + graded assets;
+ # not the clone, not logs) so an operator can fix, re-grade and deploy without a rebuild.
- name: Preserve curable build on failure
if: failure()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9927abc..0b693ad 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,9 +1,7 @@
# The test gate — ONE definition, used two ways: on every pull request and push to main (so a red suite
# cannot merge unnoticed), and called by release.yml before it will publish anything.
#
-# 2026-10-06: the tests used to run ONLY when a release tag was pushed. Ten commits merged on Sep 20 with
-# two tests newly red and nobody knew — and the release job had by then been failing for three months
-# for a different reason (the sharp step below), so there was no signal at all.
+# Why: the tests used to run ONLY when a release tag was pushed, so a red suite could merge unnoticed.
name: CI
@@ -26,18 +24,18 @@ jobs:
with:
node-version: 22
- # --ignore-scripts: dependency install hooks never run in CI (supply-chain posture) ...
+ # --ignore-scripts: dependency install hooks never run in CI (supply-chain posture).
- run: npm ci --ignore-scripts
- # ... with ONE deliberate exception. @xenova/transformers carries its own nested `sharp`, whose native
- # binary is fetched by its install script. Skipped, importing the package throws and the 9 kb-delta
- # end-to-end tests fail — which blocked every release since July. Rebuilding ONLY sharp restores the
- # one binary that needs it. Reproduced and verified in a clean v0.9.0 checkout (185 tests, 0 failing).
- - run: npm rebuild sharp
+ # The ask-service has its own manifest (it deploys as a separate Netlify site); its tests import it.
+ - run: npm ci --ignore-scripts --prefix ask-service
- # The diagram tests spawn make-diagrams, which shells out to graphviz's `dot` and `xmllint` — present
- # locally and in build-explainer.yml but not on a bare runner. Their absence failed the v0.4.0 release's
- # test job (execSync ENOENT) with a green suite locally; system deps here must mirror what the tools invoke.
- - run: sudo apt-get update && sudo apt-get install -y graphviz libxml2-utils
+ # The diagram tests spawn make-diagrams, which shells out to `xmllint` to validate every SVG. A bare
+ # runner does not have it; system deps here must mirror what the tools invoke (nothing calls `dot`).
+ # imagemagick: make-social-card renders the share card with it; without it the card-legibility tests SKIP.
+ - run: sudo apt-get update && sudo apt-get install -y libxml2-utils imagemagick
- run: npm test
+
+ # End-to-end suite (real embeddings + RVF stores in a temp dir; downloads the small bge model on a fresh runner).
+ - run: npm run test:e2e
diff --git a/.github/workflows/deploy-preserved-goodies.yml b/.github/workflows/deploy-preserved-goodies.yml
deleted file mode 100644
index 822b41c..0000000
--- a/.github/workflows/deploy-preserved-goodies.yml
+++ /dev/null
@@ -1,47 +0,0 @@
-name: Deploy preserved Goodies artifact
-on:
- workflow_dispatch:
-permissions:
- actions: read
- contents: read
-jobs:
- deploy:
- runs-on: ubuntu-latest
- timeout-minutes: 15
- steps:
- - uses: actions/checkout@v4
- - uses: actions/setup-node@v4
- with:
- node-version: '22'
- - name: Install deterministic runtime only
- run: sudo apt-get update && sudo apt-get install -y libxml2-utils zip unzip
- - name: Recover Build 120 artifact
- env:
- GH_TOKEN: ${{ github.token }}
- run: |
- gh api repos/${{ github.repository }}/actions/artifacts/10608084895/zip > artifact.zip
- echo '0f15e8c8abecd5432742764962fc24c4571a35faceaa022259e96f64be1c5364 artifact.zip' | sha256sum -c -
- mkdir build && unzip -q artifact.zip -d build
- mkdir -p kb/stores/the-goodies /tmp/pack
- unzip -oq build/site/the-goodies-knowledge-pack.zip 'for-ai/*' 'for-humans/*' -d /tmp/pack
- cp /tmp/pack/for-ai/the-goodies-* kb/stores/the-goodies/
- cp /tmp/pack/for-humans/the-goodies-primer.md kb/stores/the-goodies/
- jq '
- .repo.clonePath="/tmp/no-clone-needed" |
- .visuals.hero.file="assets/hero.png" |
- .visuals.sections |= map(.file=("assets/" + (.file|split("/")|last))) |
- .brand.socialCard.file="assets/social-card.png"
- ' build/build.json > build/build.tmp && mv build/build.tmp build/build.json
- - name: Deterministically redraw and assemble
- run: |
- node tools/make-diagrams.mjs build
- node tools/assemble-page.mjs build
- ! grep -Rqi 'concept archetype: strata\|Nested containment\|nested frames' build/site/assets/big-idea.svg build/site/index.html
- grep -q 'concept archetype: ribbon' build/site/assets/big-idea.svg
- test "$(find build/site -type f | wc -l)" -ge 20
- - name: Deploy preserved site without model calls
- env:
- NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
- NETLIFY_SITE_NAME: the-goodies-explainer
- EXPLAINER_SUBMITTED_REPO: adrianco/the-goodies
- run: node tools/deploy.mjs build
diff --git a/.gitignore b/.gitignore
index 6c95c19..891576a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,9 +5,9 @@
docs/.env
# deps & build
+node_modules
node_modules/
**/node_modules/
-.vercel/
# cloned upstream repos (not ours)
.targets/
@@ -27,6 +27,7 @@ ruvector.db
# local agent DB + model cache + per-run build outputs (all regenerable, not source)
agentdb.rvf
agentdb.rvf.lock
+agentdb.rvf.idmap.json
kb/models-cache/
explainer-builds/
@@ -50,3 +51,6 @@ explainer-builds/
# pasted screenshots — one showed a complete npm token on 2026-10-06; never source
.docs/
+
+# generated explainer builds at the repo root (the ruv-explainer-* hand-built generation was removed; builds live on Netlify)
+/ruv-explainer-*/
diff --git a/README.md b/README.md
index 9e01070..d8a1595 100644
--- a/README.md
+++ b/README.md
@@ -4,15 +4,13 @@
### Point it at any GitHub repo. Get back an explainer a stranger — and their AI — actually understands.
-## 🌐 The website — there is only ONE
+## The website
# → **[explainmyrepo.isovision.ai](https://explainmyrepo.isovision.ai)** ←
-This is the live site: the concept, the full process, and all six example explainers on one page.
+Paste a public repo's URL, get the page by email. Private repos and your own keys: use the command below.
-> **Heads up:** the old `repo-explainer-website.vercel.app` was an earlier draft that told people to run a command (`npx repo-explainer`) that was never published. It now **redirects here**. If you ever land on anything other than **explainmyrepo.isovision.ai**, you're on the wrong (old) page.
-
-*Complex repos deserve clear introductions. This builds them, then refuses to ship until they're good.*
+*Complex repos deserve clear introductions. This builds them, grades them honestly, and tells you the grade.*
@@ -39,109 +37,164 @@ That's the bar. `explainmyrepo` exists to clear it, on every build.
---
-## What you get — three artifacts from one command
+## What you get from one command
+
+
-One command reads a repo and produces three things, each quality-gated:
+
+ASCII Version (for AI/accessibility)
-
+```
+github.com/owner/name
+ |
+ v
+ explainmyrepo
+ |
+ +--> 1. a live explainer page (both doors) the link you share; diagrams drawn from the code
+ +--> 2. an AI knowledge pack (both doors) a .zip: vector KB + search CLI + MCP server
+ +--> 3. a GitHub repo you own (local door only) you are invited as collaborator
+```
-1. **A live explainer web page** — the link you share. A bespoke, art-directed walkthrough with a real architecture diagram and a real data-flow diagram drawn from the code itself.
-2. **A GitHub repo you own** — you're invited as a collaborator on the explainer's own repo, so you can edit it. It's yours.
-3. **A downloadable AI knowledge pack** — a drop-in `.zip` containing a vector knowledge base of the repo, a search CLI, and an MCP server, so Claude Code or Cursor answer from the **real source** instead of guessing.
+
+
+1. **A live explainer web page** — a bespoke, art-directed walkthrough with an architecture diagram and a flow diagram drawn from the repo's real dependency graph and entrypoints, never invented.
+2. **A downloadable AI knowledge pack** — a `.zip` with a vector knowledge base of the repo, a search CLI and an MCP server, so Claude Code or Cursor answer from the **real source** instead of guessing.
+3. **A GitHub repo you own** *(local door only)* — the explainer gets its own repo and you are invited as a collaborator, so you can edit it.
---
-## How it works — the process
+## How it works — one station table
-`explainmyrepo` is not a template filler and not a doc scraper. It's a single Claude Code **skill** that holds the judgment (the *brain*) plus small, pure **tools** that do the mechanics — with one data contract flowing between them. No brittle multi-phase pipeline.
+`explainmyrepo` is not a template filler. The judgment (understand, conceive, author, judge) is done by a model; small, deterministic **tools** do the mechanics; one `build.json` carries the data between them. The order of every step lives in **one file**, [`src/stations.mjs`](src/stations.mjs), and the CLI help, the `--from/--to/--only` checks and the tests all read it; a drift test fails if the hosted station table in `skills/explainmyrepo/SKILL.md` stops matching the hosted tool stations here (same set, same order).
-The brain runs the repo through an ordered sequence. Each step has one job:
+
-
+
+ASCII Version (for AI/accessibility)
-1. **Read** — clone the **exact** repo (identity-pinned, so nothing can substitute a lookalike) and **live-probe every credential** before a cent is spent: the preflight walks each key's candidate sources and self-heals onto the first one that actually works.
-2. **Compete** — before any expensive work, **three frontier models fight in plain text** (Claude Sonnet, Claude Fable, GPT-5.6) to art-direct this repo: each pitches a visual metaphor, palette, hero animation, and story arc; an independent judge scores them swap-test-first and the winner's concept seeds the build. Premium creative judgment at *pennies*, so the expensive execution runs once, on the cheaper tier.
-3. **Understand** — build a real RVF vector knowledge base from the actual code: structure-aware chunks, local 384-dim embeddings (`bge-small-en-v1.5`), plus an extracted symbol index, dependency graph, and entrypoints. Then author a plain-language primer. Everything downstream is grounded in this KB — **no invented capabilities**.
-4. **Conceive** — validate the tournament's winning concept against the full KB and sharpen it with grounded specifics. The truth rails stay with the agent; the creativity already won its seat.
-5. **Author** — write the copy along a **comprehension arc** — the questions a newcomer actually asks, in order: *What world am I in? Why does this exist? What does it do? Why is it clever? How is it built? Could I use it? How do I start?* Every claim is traceable to a KB passage.
-6. **Visualize** — every image must **teach** (the swap test: if an image could ship unchanged on a different repo, it fails). Labeled, mechanism-bearing illustrations via `gpt-image-2`/Grok; **bespoke *animated* SVG diagrams** hand-authored per an archetype menu (journey · containment · field · fan · tree · exchange — **no two diagrams on one page may share a form**), with every label width-budgeted so text can never collide. The flow diagram must *perform* the repo's thesis in motion, not name stages. Architecture and data-flow diagrams are mandatory and drawn from the repo's *real* dependency graph — never invented.
-7. **Assemble** — render the page **once** onto a shared design system (with universal click-to-zoom on every figure), build the downloadable AI knowledge pack, and wire in SEO + social (JSON-LD, a 1200×630 social card, `llms.txt` for AI crawlers).
-8. **Grade** — the quality gate (see below). Real screenshots, both devices, every diagram at full size, and **animations sampled at multiple loop phases and judged at their worst frame**.
-9. **Ship** — the gate's verdict is enforced as a **deterministic rail at the deploy boundary** (its only override is human-only, terminal-gated — an agent cannot reach it). A refused build isn't garbage: it survives as an artifact with the grader's own words, and the runner can spend one trusted "operator's grade" on a documented post-cap fix. On success: deploy, verify HTTP 200, update the public status page with the full scorecard, and email you every link — including a one-click **grade-this-page** ask.
+```
+1 set up clone-repo > kb:register > build-kb > concept-tournament (advisory)
+2 build + grade primer > index-primer > concept > content > check-claims (advisory) > visual-brief
+ > generate-image > make-favicon > make-social-card > make-diagrams > assemble-page
+ > make-pack > make-ask (advisory, local) > quality-grade
+3 ship deploy > publish-repo (local) > repo-seo (local) > readme-enhance (local, advisory) > notify (advisory)
+4 follow-ups make-overview (local) > redeploy (local) > republish (local) all advisory, after delivery
+
+solid = a failure stops the build dashed = advisory, the build carries on L = local door only
+```
+
+
+
+In plain words:
+
+1. **Read** — clone the **exact** repo (identity-pinned, so nothing can substitute a lookalike).
+2. **Compete** — before expensive work, three models (Claude Sonnet, Claude Fable, GPT-5.6) each pitch a visual metaphor, palette, hero animation and story arc in plain text; a judge picks one. It is a cheap step that fails open: it needs both an Anthropic and an OpenAI key, and when it skips, a single-shot concept is authored instead.
+3. **Understand** — build a real RVF vector knowledge base from the actual code (structure-aware chunks, local 384-dim embeddings, a symbol index, a dependency graph, entrypoints), then author a plain-language primer. Everything downstream is grounded in it.
+4. **Author** — write the copy along a comprehension arc for a curious fifteen-year-old: *What world am I in? Why does this exist? What does it do? Why is it clever? How is it built? Could I use it? How do I start?* An advisory check compares the page's citations and commands with the KB.
+5. **Visualize** — every image must teach (if it could ship unchanged on a different repo, it fails). Diagrams are **drawn by code** from the real graph, or from the structure the model authored; no two diagrams on a page share a form.
+6. **Assemble** — render the page once onto a shared design system and wire in SEO and social: JSON-LD, `llms.txt`, and a required, verified 1200×630 share card.
+7. **Grade** — the quality gate, below.
+8. **Ship** — deploy to its own Netlify site, verify it answers 200, and email you every link.
---
-## The quality gate — why the output is a class above
+## The quality gate — it tells you the truth
-This is the part that makes the difference. A generic generator emits something and stops. `explainmyrepo` **does not ship until an independent critic and a set of operator questions both pass.**
+A generic generator emits something and stops. `explainmyrepo` renders the page in a real browser and grades it. **The gate advises; it does not veto** ([ADR-0011](docs/adr/0011-the-gate-advises-never-destroys.md)): a below-bar page is delivered with its weakest axis named, instead of the requester getting nothing.
-
+
-The gate renders the live page in a real browser at **390px (mobile)** and **1440px (desktop)**, takes full-page screenshots, and scores them on **two independent rubrics**:
+
+ASCII Version (for AI/accessibility)
-- **Gate A — "Do they actually get it?"** (substance): visual effectiveness, storytelling, clueless-to-convinced, usefulness-to-*you*, completeness of the arc, and implementation confidence.
-- **Gate B — "Did someone who gives a shit make this?"** (craft / anti-slop): typography, alignment, spacing, polish, and imagery craft — including whether the diagrams are genuinely explanatory.
+```
+1 render for real 390px phone + 1440px desktop, full-page screenshots
+2 free checks first INV-20 unexplained jargon, INV-24 reads at fifteen (no model call)
+3 vision critic 11 axes (A1-A6 substance, B1-B5 craft) + six operator questions
+ mean 79-85: graded twice, samples merged
+verdict
+ exemplary mean 90+, min axis 85+, all six YES
+ ships mean 82+, min axis 70+, five ship questions YES, both diagrams present
+ below the bar still ships, its weakest axis named to the requester
+At most 3 grading passes. Deploy refuses only on integrity: unassembled page, a different repo
+than submitted, a page linking files it does not ship, or no scorecard with no recorded reason.
+```
-The bar has **two tiers, both enforced in code**: the **exemplar bar** (mean ≥ 90, minimum axis ≥ 85, both devices) is what the refine loop climbs toward, and the **ship floor** (mean ≥ 82, minimum axis ≥ 70, all operator questions YES) is a hard rail at the deploy boundary — `deploy` recomputes it from the scorecard and refuses anything below it, no matter what any agent believes. The minimum-axis floor is the anti-slop catch: one weak axis (a raw ASCII diagram, a mood image that fails the swap test, an animation whose *worst sampled frame* has colliding text) fails the whole build. Every image is individually interrogated — what does a stranger learn from its pixels alone, and could it ship unchanged on a different repo?
+
-On top of the numbers, the operator must answer **YES to all six questions** — a separate, independent gate:
+The gate scores two independent rubrics:
-1. Would this make me believe I understand this?
-2. Would this make it approachable?
-3. Would this explain it for somebody who doesn't understand it?
-4. Would it give me confidence I understand the architecture?
-5. Does it make me smile — "oh, that's cool"?
-6. Could someone who knows **nothing** about this domain read the first four sections and explain the problem and the solution back to me?
+- **Gate A — "Do they actually get it?"** (substance): visual effectiveness, storytelling, clueless-to-convinced, usefulness to *you*, completeness of the arc, implementation confidence.
+- **Gate B — "Did someone who cares make this?"** (craft): typography, alignment, spacing, polish, and imagery craft, including whether the diagrams explain anything.
-A single axis below the bar, or a single NO, names the exact weakness, reopens just that slot, re-renders, and re-grades. **Iterating over a few revisions is expected by design** — it's how the build climbs to genuinely high quality. Three sets of eyes see the same pixels: the vision-model critic, the operator, and finally you (the owner) on delivery. If a repo genuinely can't reach the bar, the build **says so honestly** rather than shipping slop and calling it done — and the honest refusal is preserved (site + scorecard + the grader's reasons) so a ten-minute cure beats a rebuild.
+Six operator questions sit beside the numbers (understand it? approachable? explainable to a novice? confident about the architecture? makes me smile? could a zero-knowledge reader follow the first four sections?). The minimum-axis floor is the anti-slop catch: one weak axis fails a tier no matter how good the mean is. The reader on every page is a curious fifteen-year-old, and two free checks measure that before a single vision token is spent.
---
-## The factory learns — every build makes the next one better
+## The factory learns
-Most generators are amnesiac: build #100 is exactly as naive as build #1. This one closes the loop:
+
-
+
+ASCII Version (for AI/accessibility)
-- **Two verdicts per page, side by side**: the machine grader's scorecard *and* the reader's own 1–100 + comments (every delivery email asks for it). The admin dashboard plots the synthesized score over time — the factory has to prove it's getting better, not claim it.
-- **Only measured truth is promoted**: build outcomes and human grades land in an oracle-tier learning store; patterns distilled from it are marked trustworthy only when execution-observed.
-- **Lessons live in the recipe, not in anyone's memory**: when a failure teaches something (an animation that hid its worst frame, a label that collided at column scale, a $0 pre-check that burned real grade budget), the *skill, the gate, or a tool* is changed the same day — so the fix fires on every future build even when nobody remembers the incident.
+```
+a shipped page --> scorecard, cost, weakest axis, diagram forms are recorded
+ |
+ v
+reader's own grade (1-100 + comments, linked from the delivery email; npm run pull-ratings ingests them)
+ |
+ v
+learning store (local ruflo memory namespace; the admin page plots the trend)
+ |
+ v
+the recipe changes: when a failure teaches something, the skill, the gate or a tool is changed
+```
+
+
-The receipts are in the git log: the first fully-autonomous build after this week's lessons went **first-try exemplary — one grade pass, 37 minutes, zero human minutes**.
+Lessons live in the recipe (the skill, the gate, the tools), not in anyone's memory, so a fix fires on every later build.
---
-## One brain, three doors
+## Two doors
+
+
-The judgment lives in **one** place — a Claude Code skill. The same core is exposed through three thin adapters that each run the *identical* skill; none of them contains explainer logic of its own. Improve the brain once, and it improves everywhere.
+
+ASCII Version (for AI/accessibility)
+
+```
+ src/stations.mjs + tools/*.mjs
+ / \
+ local door hosted door
+ npx explainmyrepo explainmyrepo.isovision.ai
+ your keys, any repo incl. private zero keys, public repos only
+ src/orchestrator.mjs runs every GitHub Action -> bin/agentic-runner.mjs: clone, credential
+ local station (authoring: src/brain.mjs) probes, concept tournament, then a headless agent that follows
+ also: explainer repo, Ask box, skills/explainmyrepo/SKILL.md; the runner adds a bounded cure
+ video + infographic, README outreach stage, the claims check and the delivery email
+ no GitHub repo, no Ask box yet
+```
-
+
-- **Hosted website** — paste a GitHub URL in the browser. **Public repos, zero setup** — the easiest door.
-- **npx CLI** — the one-liner below. **Private repos and your own keys.**
-- **Claude Code plugin** — run it from inside Claude Code with a slash command.
+**Pick your door with one question — is the repo public, and whose keys should do the work?** Public repo and you just want the page: use the website. Private repo, or you want it on your own accounts: use the CLI, and run it **inside a VS Code / Claude Code session** in a project whose `.env` already holds your keys, so everything is picked up automatically. (`/explainmyrepo ` inside Claude Code runs the same skill by hand.)
-**Pick your door with one question — is the repo public, and whose keys should do the work?**
-Public repo and you just want the page: use the website, done. Private repo, or you want it on
-your own accounts: use the CLI — and run it **inside a VS Code / Claude Code session**, in a
-project whose `.env` already holds your keys, so everything is picked up automatically.
+The two doors stay in step by test, not by hope: `tests/two-doors-conform.test.mjs` pins the reader standard and the image rules in both places, and a drift test parses the hosted station table in `skills/explainmyrepo/SKILL.md` and fails unless it lists exactly the hosted tool stations of `src/stations.mjs`, in the same order (the brain stations and the runner's own prose are checked more loosely: each both-door station must be named somewhere the hosted agent reads).
---
-## Every explainer can answer follow-up questions
+## Local door: every explainer can answer follow-up questions
-Each page ends with an **Ask box**: type a question in plain words and get a short written answer, with
-numbered links to the exact files it came from. It searches the page and the repo's own files in the reader's
-browser, then a small model writes the answer through one central service (`ask-service/`) — the explainer stays
-a plain static site. If the service is down it shows the closest passages instead, and says so. Set
-`ASK_SIGNING_SECRET` (same value on the service and your build machine) to turn on written answers;
-`ASK_DISABLE=1` leaves the box off. Deploy also now refuses a page that links a file it does not ship.
-See `docs/adr/0016-ask-this-project.md`.
+Pages built by the **local door** end with an **Ask box**: type a question in plain words and get a short written answer with numbered links to the exact files it came from. It searches the page and the repo's own files in the reader's browser, then a small model writes the answer through one central service ([`ask-service/`](ask-service/README.md)), so the explainer itself stays a plain static site. If the service is down it shows the closest passages and says so. Set `ASK_SIGNING_SECRET` (the same value on the service and your build machine) to turn on written answers; `ASK_DISABLE=1` leaves the box off. The service screens every question and every answer with AIMDS and fails closed. Hosted-door builds do not get the box yet. Deploy also refuses a page that links a file it does not ship. See [ADR-0016](docs/adr/0016-ask-this-project.md).
+
+---
## Get started
```bash
-# Point it at any GitHub repo. Walk away. Get back a live page, a repo you own, and an AI pack.
+# Point it at any GitHub repo. Walk away. Get back a live page and an AI pack.
npx explainmyrepo https://github.com/owner/repo
```
@@ -149,38 +202,33 @@ npx explainmyrepo https://github.com/owner/repo
| For | What | Notes |
|---|---|---|
-| The brain | `OPENROUTER_API_KEY`, **or** `ANTHROPIC_API_KEY`, **or nothing** if you're logged into Claude Code | any one of the three is enough. With an OpenRouter key the authoring runs on `z-ai/glm-5.2` — measured 15× cheaper than Sonnet 5 *and* higher-scoring on a blind art-direction A/B. Pin the old model with `EXPLAINMYREPO_AUTHORING=anthropic` |
-| Art + quality gate | `OPENAI_API_KEY` in `.env` | hero imagery and the vision grader |
-| **ImageMagick** | `magick` (v7) or `convert` (v6) on your `PATH` | **required** — the favicon station shells out to it and fails loudly without it. `brew install imagemagick` on macOS, `apt install imagemagick` on Debian/Ubuntu |
-| The live URL | `NETLIFY_AUTH_TOKEN` in `.env` — optional | skip with `--no-deploy` and you still get the complete page locally |
+| The brain | `ANTHROPIC_API_KEY`, **or** `OPENROUTER_API_KEY`, **or nothing** if you're logged into Claude Code | any one of the three is enough. With an Anthropic key (or Claude Code login) authoring runs on `claude-sonnet-5-5`. With **only** an OpenRouter key it runs on `z-ai/glm-5.3`; set `EXPLAINMYREPO_AUTHORING=openrouter` to choose it on purpose or `=anthropic` to refuse it |
+| Art + quality gate | `OPENAI_API_KEY` in `.env` | hero imagery (`gpt-image-2.5-flare`, falling back to `gpt-image-2`, then Grok when there is no OpenAI key or the OpenAI chain fails) and the vision grader |
+| **ImageMagick** | `magick` (v7) or `convert` (v6) on your `PATH` | **required** — the favicon and share-card stations shell out to it and fail loudly without it. `brew install imagemagick` on macOS, `apt install imagemagick` on Debian/Ubuntu |
+| The live URL | `NETLIFY_AUTH_TOKEN` in `.env` | required unless you pass `--no-deploy` (the preflight stops without it); with `--no-deploy` you still get the complete page locally |
| Private repos | `gh auth login` | public repos need nothing |
-**The count, plainly:** website — **zero keys**. npx **inside Claude Code** (recommended) —
-**one key** (OpenAI); add a Netlify token only if you want the live URL. npx in a bare
-terminal — **two keys** (add Anthropic). Private repo — no extra key, just `gh auth login` once.
+**The count, plainly:** website — **zero keys**. npx **inside Claude Code** (recommended) — **one key** (OpenAI); add a Netlify token for the live URL (or pass `--no-deploy`). npx in a bare terminal — **two keys** (add Anthropic). Private repo — no extra key, just `gh auth login` once.
-**Recommended:** run it inside a **VS Code / Claude Code session** in a project whose `.env`
-already has these — nothing to export, nothing to paste, and Claude Code itself carries the
-brain on your existing subscription. In a bare terminal it works too; you'll just be told up
-front which keys to add.
+**Recommended:** run it inside a **VS Code / Claude Code session** in a project whose `.env` already has these — nothing to export, nothing to paste, and Claude Code itself carries the brain on your existing subscription.
-**What happens:** it reads the repo, understands it, art-directs and writes the page, generates the imagery and the real architecture + data-flow diagrams, grades the result on mobile and desktop until it clears the bar, then deploys it.
+**What you get back:** a live URL (in your terminal and by email), the downloadable AI pack, and on the local door a GitHub repo you're a collaborator on — plus the scorecard and both screenshots, so you're the final set of eyes.
-**What you get back:** a live URL (in your terminal and by email), a GitHub repo you're a collaborator on, and the downloadable AI knowledge pack — plus the scorecard and both screenshots, so you're the final set of eyes.
+> **Status:** `npx explainmyrepo` is **live on npm** (3.x). The hosted website is live at [explainmyrepo.isovision.ai](https://explainmyrepo.isovision.ai). Found it valuable? **[A star on this repo](https://github.com/stuinfla/Repo-Explainer)** genuinely helps. Hit a problem? **[Open an issue](https://github.com/stuinfla/Repo-Explainer/issues)** — happy to help fix it and make it better.
-> **Status:** `npx explainmyrepo` is **live on npm** (v0.2+). The hosted website is live at [explainmyrepo.isovision.ai](https://explainmyrepo.isovision.ai). Found it valuable? **[A star on this repo](https://github.com/stuinfla/Repo-Explainer)** genuinely helps. Hit a problem? **[Open an issue](https://github.com/stuinfla/Repo-Explainer/issues)** — happy to help fix it and make it better.
+**Don't want to pay per token for the authoring brain?** The same skill runs through a **Codex** session signed in with a ChatGPT subscription, which drops the text-model cost to $0 (only `gpt-image-2.5-flare` imagery stays metered). It also builds straight from a **local checkout**, so private source never leaves the machine. See [`docs/prompts/codex-explainer-build.md`](docs/prompts/codex-explainer-build.md) for the setup and a copy-paste prompt template.
-**Don't want to pay per token for the authoring brain?** The same skill runs through a **Codex** session signed in with a ChatGPT subscription, which drops the text-model cost to $0 (only `gpt-image-2` imagery stays metered, at cents per build). It also builds straight from a **local checkout**, so private source never leaves the machine. See [`docs/prompts/codex-explainer-build.md`](docs/prompts/codex-explainer-build.md) for the setup and a copy-paste prompt template.
+**Contacting maintainers.** After a local build ships, the readme-enhance station opens **one** friendly GitHub issue showing the maintainer a better README for their repo (their README exactly as written, plus an explainer link and diagrams), and offers a pull request only if they say yes. Never your own repo or a private one, one contact per repo, at most five a day. A single check-in note, sent only by running `npx explainmyrepo outreach followup` a week or more later, is posted only if they have not replied, and any maintainer-email draft goes to you, never to them. Switch it off with `--no-readme-pr` or `README_ENHANCE=0`. See [ADR-0015](docs/adr/0015-readme-outreach-issue-first.md).
---
## See a real one
-The agenticow explainer below was generated end to end from [`ruvnet/agenticow`](https://github.com/ruvnet/agenticow): a captivating hero, a plain-language walkthrough, **a real architecture diagram and data-flow diagram drawn from agenticow's own code**, concrete use-cases, and a one-click AI knowledge pack.
+The agenticow explainer above was generated end to end from [`ruvnet/agenticow`](https://github.com/ruvnet/agenticow): a captivating hero, a plain-language walkthrough, **an architecture diagram and a data-flow diagram drawn from agenticow's own code**, concrete use-cases, and a one-click AI knowledge pack.
-### [Open the live agenticow explainer →](https://stuinfla.github.io/Repo-Explainer/agenticow/)
+### [Open the live agenticow explainer →](https://agenticow-explainer.netlify.app/)
-The bar these are calibrated against — five hand-built explainers, five completely different looks, same engine, same gate:
+Earlier hand-built explainers the bar is calibrated against — five completely different looks, same engine, same gate:
| | | |
|---|---|---|
@@ -195,36 +243,44 @@ The bar these are calibrated against — five hand-built explainers, five comple
| Layer | Tool |
|---|---|
-| Concept tournament | Claude Sonnet 5 · Claude Fable 5 · GPT-5.6 competing in text; GPT-5.6 judging |
-| Knowledge base | RVF single-file vector DB (`@ruvector/rvf`) + `bge-small-en-v1.5` (local, 384-dim) |
-| Imagery | `gpt-image-2` / Grok (labeled, mechanism-bearing illustration) + bespoke hand-authored **animated SVG** diagrams (archetype-diverse, width-budgeted) |
-| Quality gate | Playwright dual-viewport render + GPT-5.6 vision grading (configurable) — every diagram at full size, animations at their worst sampled frame, ship floor enforced as a deploy rail |
-| Feedback + learning | Reader 1–100 grades beside machine grades on the admin; outcomes + grades feed an oracle-tier learning store |
-| Companions (local) | [HyperFrames](https://github.com/heygen-com/hyperframes) — the page's own gated assets re-rendered into a 30–40s trailer and a 10s social loop (16:9 + 9:16), locally, for ~$0 |
-| Hosting | Netlify by default (provider-agnostic adapter) |
+| Concept tournament | Claude Sonnet 5.5 · Claude Fable 5.1 · GPT-5.6 Sol competing in text; GPT-5.6 Terra judging |
+| Authoring brain | `claude-sonnet-5-5` by default; `z-ai/glm-5.3` via OpenRouter only as the sole credential or by opt-in |
+| Knowledge base | RVF single-file vector DB (`@ruvector/rvf`) + a local embedder named by each target's `embed` block (`bge-small-en-v1.5`, 384-dim, for every registered target) |
+| Imagery | `gpt-image-2.5-flare` at `xhigh`, then `gpt-image-2`, then Grok when there is no OpenAI key or the OpenAI chain fails (labeled, mechanism-bearing illustration) · diagrams drawn deterministically as SVG by `tools/make-diagrams.mjs` |
+| Quality gate | Playwright dual-viewport render + GPT-5.6 Sol vision grading (`QUALITY_VISION_MODEL`) — ship tier 82/70, exemplary tier 90/85, deploy refuses only on integrity |
+| Feedback + learning | Reader 1–100 grades beside machine grades; outcomes feed a local learning store |
+| Companions (local) | [HyperFrames](https://github.com/heygen-com/hyperframes) — a page's own assets re-rendered into a trailer and a social loop, locally |
+| Hosting | Netlify, one site per explainer |
+
+Prices for `gpt-image-2.5-flare` are not published to us, so cost receipts say **unpriced** for it rather than guessing; rates for the Anthropic models come from third-party price lists, not a bill.
-The full recipe lives in [`docs/adr/0005-skill-based-explainer-recipe.md`](docs/adr/0005-skill-based-explainer-recipe.md); the domain model in [`docs/ddd/explainmyrepo-recipe-domain.md`](docs/ddd/explainmyrepo-recipe-domain.md).
+The founding decision is [`docs/adr/0005-skill-based-explainer-recipe.md`](docs/adr/0005-skill-based-explainer-recipe.md) (read its banner first: later ADRs 0006–0016 supersede parts of it); the slot-by-slot data contract is [`tools/CONTRACT.md`](tools/CONTRACT.md); every tool's own header is collected in [`skills/explainmyrepo/TOOLS-CONTRACT.md`](skills/explainmyrepo/TOOLS-CONTRACT.md), which a test keeps in step with the tools.
## The Alive Kit — what a finished page can become (local runs only)
-A gated build's assets are reusable creative truth, so this repo can turn a finished
-explainer into **companion artifacts** — but only when you clone it and run them yourself,
-and only for capabilities that have actually been **proven**:
+A gated build's assets are reusable creative truth, so this repo can turn a finished explainer into **companion artifacts** — but only when you clone it and run them yourself, and only for capabilities that have actually been **proven**:
```
npx explainmyrepo capabilities
```
-That command renders the verified-capability registry (`capabilities.json`) — the *only*
-source of what's enabled, so it can never overstate. Today it shows two ✓ (a shareable
-**trailer** and a 16:9 + 9:16 **social loop**, each verified end-to-end with recorded
-receipts, ~$0 to render) and two ○ that are specified but honestly *not enabled* until
-they pass their own supervised verification runs. Companions never run on the hosted door,
-never touch a build's artifacts, and can never block a page from shipping. Governance:
-[`docs/adr/0009-alive-kit-local-companions.md`](docs/adr/0009-alive-kit-local-companions.md).
+That command renders the verified-capability registry (`capabilities.json`) — the *only* source of what's enabled, so it can never overstate. Companions never run on the hosted door, never touch a build's artifacts, and can never block a page from shipping. Governance: [`docs/adr/0009-alive-kit-local-companions.md`](docs/adr/0009-alive-kit-local-companions.md).
---
+## Known limits
+
+Plainly, as of this release:
+
+- **The Ask box is local-door only.** Hosted-door pages do not have one yet.
+- **The hosted door cannot yet move deploy into the runner.** The hosted agent still runs `deploy` itself; the runner only retries and cures around it.
+- **Image prices are partly unknown.** `gpt-image-2.5-flare` has no known per-image price, so cost totals leave it out and say so.
+- **Story diagrams on a phone.** Every diagram is drawn twice, wide and as a 360px phone twin, and `make-diagrams` fails the step if any label would be under 11px on a 390px phone. The story diagrams (system map, decision) have been exercised on fewer real builds than the radial architecture map.
+- **Hero scenes are untested against a live model.** The local brain now authors an animated hero scene and a valid one replaces the raster hero, but the validator and repair pass have been proven on fixtures, not across real builds.
+- **Page weight is checked, not tuned.** `deploy` and the site check fail a page whose images total over 1.5 MB (lightbox originals are not counted) and warn when the first view (gzipped HTML + CSS + the images above the fold) passes 300 KB (`src/site-check.mjs`). Image files are not content-fingerprinted and `deploy` writes no `_headers` file, so pages use Netlify's default revalidating cache; fingerprinted long-cache filenames would need `tools/deploy.mjs` to emit a `_headers` file first, and that is not built.
+- **No branch protection on `main` yet.** CI runs on every pull request, but nothing forces it.
+- **Outreach response rates are unmeasured.** The ledger exists to find out; no claim is made yet.
+
## Credit
The tools in the examples above belong to [Reuven Cohen / @ruvnet](https://github.com/ruvnet). `explainmyrepo` is an independent project that exists to help more people — and their AIs — discover, understand, and adopt great work.
diff --git a/ask-service/README.md b/ask-service/README.md
index ce08944..349f772 100644
--- a/ask-service/README.md
+++ b/ask-service/README.md
@@ -1,20 +1,44 @@
# explainmyrepo ask service
-One Netlify function (`/api/ask`) that writes the short, cited answers for the "Ask this project" box on every
-explainer. Explainer sites call it; they keep no key and need no function of their own.
+One Netlify function (`/api/ask`) that writes the short, cited answers for the "Ask this project" box on
+explainers built by the **local door** (the hosted door does not add the box yet; see ADR-0016). Explainer sites
+call it; they keep no key and need no function of their own.
**Why central:** the first prototype put a function and the model key on each explainer site. Review showed the
page supplied its own excerpts, so the endpoint was an open proxy on the key. Here the browser sends only the
question and passage ids; the service verifies a signed token for the site's host, fetches that site's own
`ask/index.json`, and builds the passages itself.
-**Environment (set on this site):**
+## What a request goes through (in order, `netlify/functions/ask.mjs`)
+
+1. Not configured (no `ASK_SIGNING_SECRET` or `OPENROUTER_API_KEY`): refused, so the page shows the closest passages.
+2. The signed token must verify (`verifyToken`) and the browser `Origin` must match the signed host.
+3. **AIMDS inbound** (`lib/guard.mjs`, `@claude-flow/aidefence`): the question is scanned before anything is spent or
+ sent. Threats at medium severity or above are refused, and so are personal data and credentials (they must not be
+ forwarded to a third-party model).
+4. The per-site and global daily counters (Netlify Blobs) take a slot. No working counter means no answer.
+5. The model writes the answer from the site's own passages.
+6. **AIMDS outbound**: the answer is scanned before the visitor sees it. A threat withholds it. Every scanner error
+ on either side blocks (fail closed).
+
+**Answers are buffered, not streamed.** The reply is held until it has been scanned, because a stream cannot be taken
+back once it has started. Answers are under 150 words, so the wait is a few seconds.
+
+## Environment (set on this site)
| Variable | Purpose |
| --- | --- |
-| `OPENROUTER_API_KEY` | model access. Give this site its own key with a spend limit set at OpenRouter — that limit is the hard backstop |
-| `ASK_SIGNING_SECRET` | same value as in the build machine's `.env`; tokens are `base64url(host).HMAC(host)` |
+| `OPENROUTER_API_KEY` | model access. Give this site its own key with a spend limit set at OpenRouter; that limit is the hard backstop |
+| `ASK_SIGNING_SECRET` | same value as in the build machine's `.env` (at least 24 characters); tokens are `base64url(host).HMAC(host)` |
| `ASK_MODEL` | default `anthropic/claude-haiku-5.5` |
| `ASK_SITE_CAP` / `ASK_DAILY_CAP` | questions per site per day (default 150) / across all sites (default 1500) |
-Fails closed: no key, no secret, or no working counter means no answer — the page falls back to showing the closest passages.
+## Where the token code lives
+
+The service **verifies** (`verifyToken` in `netlify/functions/ask.mjs`); the build machine only **signs**
+(`src/ask-token.mjs`). They are deployed separately, so each side owns its half, and `tests/ask.test.mjs` runs the
+signer and the service's verifier against each other (forged, truncated and wrong-secret tokens are rejected).
+`tests/ask-service.test.mjs` drives the guard through the service's real handler.
+
+Fails closed: no key, no secret, no working counter, or no scanner verdict means no answer. The page then falls back
+to showing the closest passages and says so.
diff --git a/ask-service/lib/guard.mjs b/ask-service/lib/guard.mjs
new file mode 100644
index 0000000..b733f22
--- /dev/null
+++ b/ask-service/lib/guard.mjs
@@ -0,0 +1,35 @@
+// guard.mjs — AIMDS screening for the Ask service (global rule 8): the visitor's question is scanned before it
+// reaches the model, the model's answer is scanned before it reaches the visitor. Every failure path BLOCKS.
+//
+// @claude-flow/aidefence 3.1.0 has no `blockThreshold` option (checked against its published types), so the
+// threshold is applied here to the severity of each returned threat: 'medium' blocks medium, high and critical.
+import { createAIDefence } from '@claude-flow/aidefence';
+
+const RANK = { low: 1, medium: 2, high: 3, critical: 4 };
+export const BLOCK_THRESHOLD = 'medium';
+
+/** @param {{ scanner?: { detect(text: string): Promise