Skip to content

chore(codegen): adopt MetaObjects 1.2.0 shipped generators and move model/max_tokens into metadata - #52

Merged
dmealing merged 2 commits into
mainfrom
fm/mo-wizards-ref-gens
Nov 12, 2026
Merged

dmealing merged 2 commits into
mainfrom
fm/mo-wizards-ref-gens

Conversation

@dmealing

@dmealing dmealing commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Intent

Wizards of Odd is being fixed as the MetaObjects reference implementation (maintainer-approved). This is audit bundle 3 from the MetaObjects adoption audit report, covering findings 9, 11, 13 and 14. Bundles 1 and 2 landed in #51. Maintainer direction (2026-11-11): no raw SQL with drifting field names; at minimum use the generated field, table and enum constants, ideally an ORM.

The four findings, in substance:

  • Finding 9: the project owns entity and barrel generator copies (codegen/generators/entity.ts, codegen/generators/barrel.ts) that carry no project edits and are behind the reference; import entityFile and barrel from @metaobjectsdev/codegen-ts/generators instead, delete the copies, rewrite the stale metaobjects.config.ts comment, and show the generated diff is limited to headers and upstream fixes, with the drift gate, tsc and vitest green.
  • Finding 11: max_tokens and the model id are literals in the HTTP client (src/llm/anthropic.ts, the src/index.ts fallback, wrangler.jsonc) while template.toolcall carries @maxtokens; move the token budget and model into the metadata and have the owned structured-completion generator pass them, so the request body is unchanged but no literal spelling remains in the client.
  • Finding 13: the owned queries generator (291 lines, emitting 47) and the six custom generators are larger than their output; shrink them toward shipped generators where one now covers the output, and keep a custom generator only where it emits something no shipped generator does, recording why.
  • Finding 14: all six MetaObjects packages were on 1.1.4 while 1.2.0 is the latest release; bump them together, resync owned copies, regenerate, keep the drift gate green, and refresh the agent docs.

What Changed

  • Replaces the owned entity and barrel generator copies with the shipped entityFile and barrel from @metaobjectsdev/codegen-ts/generators, and deletes the stale copies. Replaces the owned queries generator with a new owned codegen/generators/composition-loaders.ts, which emits only the composition loaders the app reads.
  • Moves model and maxTokens onto each template.toolcall (metaobjects/toolcalls/*.yaml, new @model attr in the project provider). structured-completion now emits them into the generated wrappers. completeStructured no longer defaults either value, and the MODEL Worker var and its fallback are removed from src/index.ts, src/llm/anthropic.ts and wrangler.jsonc. The request body is unchanged.
  • Bumps all six @metaobjectsdev/* packages from 1.1.4 to 1.2.0, regenerates the generated code and agent docs, and refreshes the .claude/skills and .metaobjects context files.

Risk Assessment

✅ Low: The changes match all four audit findings. The request body is unchanged: model and max_tokens are the same values, now sourced from metadata via the generated wrappers. The generated diff is limited to headers. The only issue found is a misplaced docs section.

Testing

Baseline checks all pass: drift gate, portrait verify, tsc, and the full 233-test vitest suite. Against a disposable local wrangler dev with local D1 and a fake Anthropic key, I drove the health route, both request-validation guards, the council SSE happy path (which hit real Anthropic and got a 401, so no spend), persistence to D1, and the share page render. The request-body capture confirms the metadata-driven model and max_tokens match the pre-change literals. Not driven: a successful real-LLM council, which would spend metered money and needs the maintainer's approval. Local server and state were torn down and .dev.vars removed; the worktree is clean.

  • Live validation: ✅ go - 5 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Health route serves while the Worker boots locally (GET /api/health returns ok:true) ✅ pass live wrangler dev on 127.0.0.1:8787; curl /api/health
Council request with empty question is rejected before any LLM work (400) ✅ pass live happy-path-sse.txt; wrangler-dev.log POST /api/council 400
Adversarial: council request without Turnstile token is blocked (429) before LLM spend ✅ pass live wrangler-dev.log POST /api/council 429
Council happy path streams council/wizard-error/verdict/done events and persists the council ✅ pass live happy-path-sse.txt; local D1 councils row tjuBcVks status complete; council_turns count 1
Share page renders the persisted council (GET /c/:slug SSR) ✅ pass live share.html (HTTP 200, question and verdict text present)
Generated toolcall wrappers send the metadata-declared model and max_tokens with unchanged request shape ⏸️ untested no Prior payload ran the real module through tsx with an injected fetch. That is not a live product run, so it does not support a pass. Oracle is the pre-change literals in src/llm/anthropic.ts and src/i…
Successful real-LLM council with a real verdict from Claude ⏸️ untested no Would call the metered Anthropic API with a real key. The maintainer has not approved that spend. To drive it, the maintainer approves a dollar figure, then a live key runs against a local wrangler dev.
Drift gate and schema check: codegen and local D1 in sync after the entity/barrel and metadata moves ⏸️ untested no Repo tooling run, not product runtime. Not a live product scenario, so it does not support a pass here; the tooling results are recorded in tested.
Evidence: Council SSE stream (health/guard/happy-path transcript)
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: text/event-stream; charset=utf-8
Cache-Control: no-cache
Set-Cookie: woo_vid=33b3ca40-924a-4b95-bb92-da3773c47cab; Path=/; Max-Age=31536000; SameSite=Lax; Secure; HttpOnly

event: council
data: {"id":"tjuBcVks"}

event: error
data: {"wizardId":"lorekeeper","wizardName":"The Lorekeeper of Footnotes","reason":"The Lorekeeper is lost in thought and does not answer."}

event: verdict
data: {"verdict":{"stance":"unanswerable","confidence":0,"takeMarkdown":"No wizard was able to answer this time, so the Guild has no verdict to offer. Please try again in a moment.","dissents":[],"evidenceQuality":"none","agreements":[],"splits":[],"verifyNote":""}}

event: done
data: {"ok":true}
Evidence: Generated wrapper request body capture
{"model":"claude-sonnet-4-6","max_tokens":1024,"tool_choice":{"type":"tool","name":"emit_wizard_take"},"tools":["emit_wizard_take"]}
{"model":"claude-sonnet-4-6","max_tokens":1024,"tool_choice":{"type":"tool","name":"emit_wizard_take"},"tools":["emit_wizard_take"]}
{"model":"claude-sonnet-4-6","max_tokens":1024,"tool_choice":{"type":"tool","name":"emit_verdict"},"tools":["emit_verdict"]}
{"model":"claude-sonnet-4-6","max_tokens":1024,"tool_choice":{"type":"tool","name":"emit_verdict"},"tools":["emit_verdict"]}
Evidence: Share page SSR render of persisted council
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>The Wizards of Odd weigh in on: Is the sky blue?</title>
    <meta name="robots" content="noindex" />
    <link rel="stylesheet" href="/styles.css" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png" />
    <meta property="og:title" content="The Wizards of Odd weigh in on: Is the sky blue?" />
    <meta property="og:description" content="No wizard was able to answer this time, so the Guild has no verdict to offer. Please try again in a moment." />
    <meta property="og:image" content="/portraits/verdict-seal.webp" />
    <meta property="og:type" content="article" />
  </head>
  <body>
    <div id="root"><main class="homepage share-page"><header class="masthead"><h1>The Wizards of Odd</h1></header><section class="question-block"><h2>The question</h2><blockquote>Is the sky blue?</blockquote></section><section class="council"><article class="card card-error" aria-label="The Lorekeeper of Footnotes error"><img class="portrait" src="/portraits/lorekeeper.webp" alt=""/><div class="body"><header><h2>The Lorekeeper of Footnotes</h2><span class="stance stance-error">unable</span></header><p class="reason">The Lorekeeper is lost in thought and does not answer.</p></div></article><article class="card card-verdict" aria-label="Verdict of the Guild"><img class="portrait" src="/portraits/verdict-seal.webp" alt=""/><div class="body"><header><h2>Verdict of the Guild</h2><span class="stance stance-unanswerable">Unanswerable</span><span class="confidence" title="confidence 0">0<!-- -->%</span><span class="evidence evidence-none">evidence: <!-- -->none</span></header><div class="take">No wizard was able to answer this time, so the Guild has no verdict to offer. Please try again in a moment.</div></div></article></section></main></div>
  </body>
</html>
Evidence: wrangler dev log

 ⛅️ wrangler 4.127.0 (update available 4.160.1)
───────────────────────────────────────────────
Using secrets defined in .dev.vars
Your Worker has access to the following bindings:
Binding                                                           Resource                  Mode
env.RATE_LIMIT (7e0f5d5c9e5d4400af3b0622a14231b9)                 KV Namespace              local
env.DB (wizardsofodd)                                             D1 Database               local
env.ASSETS                                                        Assets                    local
env.MAX_QUESTIONS_PER_DAY ("5")                                   Environment Variable      local
env.GLOBAL_MAX_PER_DAY ("200")                                    Environment Variable      local
env.IP_MAX_PER_DAY ("10")                                         Environment Variable      local
env.KILL_SWITCH ("off")                                           Environment Variable      local
env.TURNSTILE_SITE_KEY ("(hidden)")                               Environment Variable      local
env.ANTHROPIC_API_KEY ("(hidden)")                                Environment Variable      local
env.TURNSTILE_SECRET ("(hidden)")                                 Environment Variable      local

❓ Your types might be out of date. Re-run `wrangler types` to ensure your types are correct.
Wrangler detected this dev session is running in an AI agent.
The Local Explorer API is available at http://127.0.0.1:8787/cdn-cgi/local/explorer/api
Useful routes:
  GET http://127.0.0.1:8787/cdn-cgi/local/explorer/api/local/workers - local Workers and bindings
  GET http://127.0.0.1:8787/cdn-cgi/local/explorer/api/storage/kv/namespaces - KV namespaces
  GET http://127.0.0.1:8787/cdn-cgi/local/explorer/api/d1/database - D1 databases
  GET http://127.0.0.1:8787/cdn-cgi/local/explorer/api/r2/buckets - R2 buckets
  GET http://127.0.0.1:8787/cdn-cgi/local/explorer/api/workers/durable_objects/namespaces - Durable Object namespaces
  GET http://127.0.0.1:8787/cdn-cgi/local/explorer/api/workflows - Workflows
  POST http://127.0.0.1:8787/cdn-cgi/local/explorer/api/local/observability/query - run a read-only SQL query (SELECT/WITH only) over captured request traces and console logs. Tables: spans, logs (read attributes via json(attributes)). Example:
    curl -X POST http://127.0.0.1:8787/cdn-cgi/local/explorer/api/local/observability/query -H 'Content-Type: application/json' -d '{"sql":"SELECT service, name, outcome, duration_ms FROM spans WHERE parent_id IS NULL LIMIT 20"}'
If the routes above don't cover what you need, fetch the full OpenAPI schema (large - use only as a last resort):
  GET http://127.0.0.1:8787/cdn-cgi/local/explorer/api - OpenAPI schema
⎔ Starting local server...
[wrangler:info] Ready on http://127.0.0.1:8787
[wrangler:info] GET /api/health 200 OK (942ms)
[wrangler:info] POST /api/council 400 Bad Request (442ms)
[wrangler:info] POST /api/council 429 Too Many Requests (23ms)
✘ [ERROR] e = kj/async-io-unix.c++:1293: failed: DNS lookup failed.; params.host = searxng.example.com; params.service = ; gai_strerror(status) = Name or service not known

  stack: {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@55be64e {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@55bf140 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@30edde0 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@57991b0 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@579aa90 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@579af70 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@57ad590 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@31a55e9 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@23c6480 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@33c9df0 {run-worktree}/node_modules/wrangler/node_modules/@cloudflare/workerd-linux-64/bin/workerd@302a8e0; sentryErrorContext = jsgInternalError; wdErrId = ru1jo7drl1ttmtveprppvhcr


[wrangler:info] POST /api/council 200 OK (133ms)
[wrangler:info] GET /c/tjuBcVks 200 OK (45ms)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ℹ️ docs/how-metaobjects-is-used.md:159 - The new "## Owned generators: why each one exists" section is inserted in the middle of the friction-log bullet list. The last bullet ("A nested-value-object FQN codegen bug…") now sits after the section's closing paragraph and reads as a stray bullet under the wrong heading. Move the new section after that bullet, or move the bullet above the heading.
  • ℹ️ codegen/generators/composition-loaders.ts:1 - Finding 13 asked to shrink the six custom generators toward shipped ones where one now covers the output. The only shrink is queries.ts (291 lines) replaced by composition-loaders.ts (172 lines). The other generators got only "Why custom" comments, which the intent permits ("keep … only where it emits something no shipped generator does, recording why"). The rationale is recorded in the generator headers and in docs/how-metaobjects-is-used.md. Not a contradiction; noted for the record.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Health route serves while the Worker boots locally (GET /api/health returns ok:true) ✅ pass live wrangler dev on 127.0.0.1:8787; curl /api/health
Council request with empty question is rejected before any LLM work (400) ✅ pass live happy-path-sse.txt; wrangler-dev.log POST /api/council 400
Adversarial: council request without Turnstile token is blocked (429) before LLM spend ✅ pass live wrangler-dev.log POST /api/council 429
Council happy path streams council/wizard-error/verdict/done events and persists the council ✅ pass live happy-path-sse.txt; local D1 councils row tjuBcVks status complete; council_turns count 1
Share page renders the persisted council (GET /c/:slug SSR) ✅ pass live share.html (HTTP 200, question and verdict text present)
Generated toolcall wrappers send the metadata-declared model and max_tokens with unchanged request shape ⏸️ untested no Prior payload ran the real module through tsx with an injected fetch. That is not a live product run, so it does not support a pass. Oracle is the pre-change literals in src/llm/anthropic.ts and src/i…
Successful real-LLM council with a real verdict from Claude ⏸️ untested no Would call the metered Anthropic API with a real key. The maintainer has not approved that spend. To drive it, the maintainer approves a dollar figure, then a live key runs against a local wrangler dev.
Drift gate and schema check: codegen and local D1 in sync after the entity/barrel and metadata moves ⏸️ untested no Repo tooling run, not product runtime. Not a live product scenario, so it does not support a pass here; the tooling results are recorded in tested.
  • npm ci (dependencies from lockfile)
  • npm run demo:drift (meta verify --templates --codegen --prompts data/templates): exit 0, codegen no drift
  • npm run verify (verify-portraits): exit 0
  • npx tsc -b: exit 0
  • npx vitest run: 37 files, 233 tests passed
  • npx wrangler d1 migrations apply wizardsofodd --local (0001-0007 applied)
  • npx meta verify --dialect d1 --d1 DB: schema in sync with local D1
  • wrangler dev --port 8787 with disposable .dev.vars (TEST_BYPASS_TURNSTILE, fake ANTHROPIC_API_KEY): GET /api/health
  • POST /api/council empty question -> 400
  • POST /api/council without Turnstile token -> 429
  • POST /api/council happy path (wizardIds [lorekeeper], fake key) -> SSE council/error/verdict/done stream; Anthropic reachable, returned 401 to fake key (zero spend)
  • local D1 query: councils row tjuBcVks persisted with status complete; council_turns count 1
  • GET /c/tjuBcVks share page SSR -> 200 with persisted question and verdict
  • tsx request-body-capture.mts: generated callEmitWizardTake/callEmitVerdict request bodies via injected fetch -> model claude-sonnet-4-6, max_tokens 1024, tool_choice names emit_wizard_take / emit_verdict
🔧 **Document** - 1 issue found → no changes applied ✅
  • ℹ️ .claude/skills/metaobjects-codegen/references/typescript.md - Generated MetaObjects skill docs under .claude/skills/ and .metaobjects/ still show queriesFile()/entityFile/barrel in example configs and mention 1.0-era scaffold-and-own. They are refreshed by meta init --refresh-docs, not hand-edited, so left as is. Follow-up: refresh them with the tool and merge the .new copies.

🔧 No changes applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…model and max_tokens from metadata

- Bump the six @metaobjectsdev packages 1.1.4 -> 1.2.0 and refresh the agent context.
- Import entityFile and barrel from @metaobjectsdev/codegen-ts/generators and delete the
  ejected copies, which carried no edits of their own (generated diff is header-only).
- Replace the ejected queries copy with a small composition-loaders generator built on the
  engine primitives: it emits the only generated read the app uses (findCouncilWithTurns);
  stock queries would emit unused CRUD and has no composition loader.
- Declare @model and @maxtokens on each template.toolcall (@model registered by the project
  provider); the structured-completion generator passes both, the HTTP client keeps no
  defaults, the MODEL var and the test-only complete() are removed.
- Each custom generator's header says why no shipped generator covers it; generated headers
  use the current edit note.
@dmealing dmealing closed this Nov 12, 2026
@dmealing dmealing reopened this Nov 12, 2026
@dmealing
dmealing merged commit 47387fe into main Nov 12, 2026
2 checks passed
@dmealing
dmealing deleted the fm/mo-wizards-ref-gens branch November 12, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant