Operational procedures for wizardsofodd.com. For what and why, see
architecture.md and adr/.
cd <repo-root>
npm run deploy # predeploy gates, then wrangler deploynpm run deploy is the only supported way to ship. Its predeploy step runs
npm run check (the drift gate npm run demo:drift, the portrait check, local D1
schema drift, tsc, the test suite), then npm run verify:db:remote (production D1
schema drift) and npm run build:web, and stops at the first failure. Never call
wrangler deploy directly: it skips every one of those gates.
Deploy credentials. npm run deploy, npm run db:migrate:remote and
npm run verify:db:remote run through scripts/cf-deploy.sh,
which uses the site's narrow deploy-only token, not wrangler login OAuth or an
account-wide key. It pulls CLOUDFLARE_WORKERS_TOKEN_WIZARDSOFODD and
CLOUDFLARE_ACCOUNT_ID from Infisical (deploy project, dev env) via keys-axi run,
exposes the token to wrangler as CLOUDFLARE_API_TOKEN, drops any inherited
CLOUDFLARE_EMAIL / CLOUDFLARE_API_KEY / CLOUDFLARE_API_TOKEN, and runs the
repo's own pinned wrangler from node_modules/.bin. The token covers Workers
Scripts, D1 and Workers KV writes plus Account Settings read on the account, and
Workers Routes write plus Zone read on wizardsofodd.com only, so a command outside
that scope (such as wrangler tail) still needs your own login.
Production deploys are direct from main. Smoke-check:
curl -s https://wizardsofodd.com/api/health # {"ok":true}curl -sN -X POST https://wizardsofodd.com/api/council \
-H 'content-type: application/json' \
-d '{"question":"What was the South Sea Bubble?"}' \
| grep -E '^(event|data):' | head -30Look for: 5 event: wizard frames, 1 event: verdict with the 4-point
structure ending in High confidence: ... / Open question: ..., then
event: done. Lorekeeper's reply should contain real URLs (Wikipedia /
StackOverflow / etc.) when SearXNG is up; otherwise his prompt lampshades
the unreachable library.
echo 'ANTHROPIC_API_KEY = "<dev key from <your-secrets-file>>"' > .dev.vars
npm run dev # wrangler dev, default port 8787Open the printed URL. .dev.vars is gitignored and only used by wrangler dev.
-
Start ComfyUI (if not already running):
cd <your ComfyUI checkout> nohup ./venv/bin/python main.py --listen 127.0.0.1 --port 8188 --lowvram \ > /tmp/comfy.log 2>&1 & disown
Use
--lowvramto avoid theBrokenPipeErrorcold-start issue. -
Wait until ready:
until curl -s http://127.0.0.1:8188/system_stats >/dev/null; do sleep 1; done; echo ready
-
Iterate on a prompt (
scripts/prompts/<slug>.txt) and regenerate:npm run gen:assets -- --wizard grumbel # one wizard npm run gen:assets -- --background # the background npm run gen:assets # all 7
Outputs land at
public/background.webpandpublic/portraits/<slug>.webp. -
Stop ComfyUI when done:
pkill -f "main.py --listen" -
If the verdict-seal regenerates, also redo the favicons:
npm run gen:favicons # writes 16/32/180/192/512.png -
Commit + deploy — same as the deploy procedure above.
See ADR-0003 for why local ComfyUI instead of RunPod/CF AI for one-off content.
Adding (or replacing) a wizard is a pure metadata change — no TypeScript edits:
- Wizard identity — author
data/wizards/<id>.yaml(id, name, title, technique, bickersWith, usesSearch, techniqueBlurb, defaultEnabled, optional order). - Prompt declarations — add two
template.promptnodes (<id>System,<id>User) tometaobjects/prompts/meta-prompts-wizards.yaml, following the existing pattern (payloadRef + textRef + format). - Personality — author
data/templates/wizards/<id>-system.mustache(voice, technique guidance) and<id>-user.mustache(how the wizard reads the question, prior takes, sources). - Portrait — drop
public/portraits/<id>.webp(lowercase id). - Regenerate —
npm run gen:dbreruns codegen (the wizard-registry generator fails naming any missing declaration), thennpm run checkruns the drift gate, validates, and runs tests.
To remove a wizard, delete its data/template/portrait files and its two prompt
nodes, then npm run gen:db && npm run check. test/wizards.test.ts asserts the roster count —
update the expected number to match.
All Worker secrets are set via wrangler secret put <NAME> (interactive paste —
never on the command line). The host-side copies live in
<your-secrets-file> (chmod 600).
| Secret | Source | What it does |
|---|---|---|
ANTHROPIC_API_KEY |
Anthropic console → Settings → API Keys | LLM calls for council |
CF_ACCESS_CLIENT_ID |
CF Zero Trust → Access → Service Auth → Service Tokens → wizardsofodd-worker |
Search-endpoint auth |
CF_ACCESS_CLIENT_SECRET |
Same | (paired with above; shown ONCE on creation) |
Rotation procedure:
# 1. Create a fresh value in the issuing console (Anthropic / CF dashboard).
# 2. Push to Worker:
cd <repo-root>
npx wrangler secret put ANTHROPIC_API_KEY # paste new value
# 3. Update the host-side mirror:
$EDITOR <your-secrets-file>
chmod 600 <your-secrets-file>
# 4. Revoke the old value in the issuing console.
# 5. Smoke-test the live council (above) to confirm nothing broke.For the CF Access service token specifically, the dashboard path is:
Zero Trust → Access → Service Auth → Service Tokens → find
wizardsofodd-worker → Refresh (creates a new secret; the policy on the
"Home Portal" Access app keeps pointing at the same token id, no policy change
needed).
The Worker reaches the protected SearXNG via the wizardsofodd-worker service
token, which is attached to the "Home Portal" Access app (id <access-app-id>,
covers <your-host> + searxng.example.com via self_hosted_domains).
# Verify the policy is still in place (needs a CF API token with Access:Apps:Edit)
CF=<your-api-token>
ACCT=<account-id>
APP=<access-app-id>
curl -s "https://api.cloudflare.com/client/v4/accounts/$ACCT/access/apps/$APP" \
-H "Authorization: Bearer $CF" \
| python3 -c "import sys,json;a=json.load(sys.stdin)['result'];print([p['name'] for p in (a.get('policies') or [])])"
# Expect: ["Allow wizardsofodd-worker service token"]npx wrangler tail wizardsofodd # live tailconsole.error calls from the stream's catastrophic-error branch ([council] stream error)
show up here.
New D1 migrations in migrations/ are generated from the metadata by meta migrate --dialect d1.
After changing an entity under metaobjects/, run npm run gen:db, then write the
migration and apply it locally:
npx meta migrate --dialect d1 --d1 DB --out-dir migrations --slug <what-changed>
npm run verify:db # applies it to local D1, then checks schema drift
npm run db:migrate:remote # apply to production D1 (before npm run deploy)meta migrate also writes a down file under migrations/.down/; move it to
migrations/rollbacks/<name>.down.sql (wrangler applies every .sql in
migrations/, so a down file must not sit there). Read the generated SQL before
committing it: a change SQLite cannot ALTER (a new CHECK, a narrower column) is a
table rebuild, and a CHECK fails on any existing row that violates it, so query
production for violating rows first.
Shipped so far: 0001_init.sql to 0005_drop_dead_followups.sql (hand-written,
from before the project adopted meta migrate), 0006_reconcile-schema.sql (rebuild
that brought the live schema in line with the metadata's CHECKs) and
0007_link-verdict-and-council-id.sql (rebuild for the verdict confidence CHECK,
council_turns.council_id at the slug width, and the 600-char question cap).
Precheck before migration 0007. Run these against production D1 before
npm run db:migrate:remote:
SELECT count(*) FROM councils WHERE verdict_confidence < 0 OR verdict_confidence > 1;
SELECT count(*) FROM councils WHERE length(question) > 600;
SELECT count(*) FROM council_turns WHERE length(council_id) <> 8;If the first returns a non-zero count, the rebuild's INSERT fails on the new
confidence CHECK: stop, then correct or clamp those rows before migrating. The other
two do not fail the migration (SQLite does not enforce VARCHAR widths) but mark rows
that break the declared model: review them before migrating.
db:migrate:remote is NOT automatic — for a change that adds a migration, run it
against production D1 before npm run deploy. The predeploy step runs
npm run verify:db:remote, which fails on the schema drift until the migration is
applied, so the deploy stops there instead of shipping a Worker that writes to a
schema production does not have yet.
Test schema: the Workers-pool test D1 replays
migrations/*.sqldirectly (test/setup.tsloads them via a Vite?rawglob, inlined at build time since the workerd pool has no filesystem). New migrations are picked up automatically — no manual schema sync.
- Wrangler is on 3.x and out-of-date; works fine, but emits a warning on every
command. Don't blindly run
wrangler@4upgrade — verify against the Vitest pool's pinned compat first. compatibility_dateis2024-12-30intentionally (matches the Workers runtime version the test pool bundles). Don't bump it past whatever the installed@cloudflare/vitest-pool-workerssupports or tests will warn-spam.wrangler.jsonc'srun_worker_first: ["/api/*"]is what lets/api/*paths reach the Worker through the SPA fallback. If/api/healthever starts returning the homepage HTML, that's the first thing to check.- ComfyUI cold start sometimes hits
BrokenPipeErroron the first generation. Always start with--lowvram; if it errors anyway, restart it.
-
Create the Turnstile site in the Cloudflare dashboard:
- Zero Trust → Turnstile → Add site
- Domain:
wizardsofodd.com(addwww.wizardsofodd.comandlocalhosttoo) - Widget mode: Managed (lets CF pick invisible vs interactive per request)
- Copy the site key (public) and secret key (private)
-
Swap the public site key in
public/index.html:sed -i 's|1x00000000000000000000AA|<your-real-sitekey>|' public/index.htmlThe placeholder
1x00000000000000000000AAis CF's "always passes" test key — fine for dev, must be replaced for prod. Commit the change. -
Set the secret key as a Worker secret (NOT a var):
echo -n '<your-real-secret>' | npx wrangler secret put TURNSTILE_SECRET
This overrides the
TEST_BYPASS_TURNSTILEvalue inwrangler.jsoncfor the deployed Worker. Localwrangler devcontinues using the bypass marker (no real verification calls during dev).
The ultimate safety net — independent of any Worker code path.
- Anthropic Console → Settings → Billing → Usage limits
- Pick the
wizards-of-oddAPI key - Set Monthly spend limit: $20
- When hit, Anthropic returns 429s; our existing error path renders "the tower went dark unexpectedly" gracefully.
Before every npm run deploy:
# 1. Gates green (predeploy runs this again, but run it before the checks below)
npm run check
# 2. Turnstile secret is set as a SECRET (overriding the bypass var)
npx wrangler secret list | grep -q '^TURNSTILE_SECRET' \
|| (echo 'FATAL: TURNSTILE_SECRET not set as secret'; exit 1)
# 3. public/index.html has the real sitekey (not the test placeholder)
grep -q '1x00000000000000000000AA' public/index.html \
&& (echo 'FATAL: public/index.html still has the test Turnstile sitekey'; exit 1)
# 4. Deploy (predeploy reruns the gates, then wrangler deploy)
npm run deployThe grep guards are intentionally hard-fail. If you see "FATAL", fix before deploying — bypassing them ships the site open to abuse.
# Healthcheck
curl -s https://wizardsofodd.com/api/health # {"ok":true}
# Missing-token → 429
curl -s -X POST https://wizardsofodd.com/api/council \
-H 'content-type: application/json' \
-d '{"question":"test"}' \
| grep -i ghost # should match "...not a ghost."Then open https://wizardsofodd.com in a browser and confirm:
- Turnstile widget renders
- Solving it (or auto-solving) → form submits → the selected wizards (5 by default) + verdict
Through the rc era this project relied on several codegen workarounds (vendored
tarballs, local Zod schemas, as unknown as casts) for bugs in the payload/queries
generators. They all shipped upstream and were removed; the project now tracks the
released line (the @metaobjectsdev/* pins in package.json). The short version of that friction
— and the bugs this project surfaced, including the drift-gate blind spot it had and the
promptRender FQN fix that landed in 0.15.18 — lives in the friction log in
how-metaobjects-is-used.md.