Skip to content

feat(domain): add the typed registry view and its ClickHouse SQL compiler - #433

Closed
JeremyFunk wants to merge 1 commit into
ai/03-rust-classifier-corefrom
ai/04-registry-ts-sql-compiler
Closed

feat(domain): add the typed registry view and its ClickHouse SQL compiler#433
JeremyFunk wants to merge 1 commit into
ai/03-rust-classifier-corefrom
ai/04-registry-ts-sql-compiler

Conversation

@JeremyFunk

@JeremyFunk JeremyFunk commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What this layer contains

Maple's typed view of the registry artifact, under the @maple/domain/ai-registry subpath export:

  • schema.ts — Effect Schema for the whole document; registry.json is decoded at module load and exported deep-frozen.
  • validate.ts / validate.test.ts — the semantic invariants Schema cannot express (globally unique integer priorities, the D4 priority bands, the closed slug set with unknown: reserved, value_prefix confined to pseudo-keys, justification on sufficient resource matchers).
  • compile-sql.ts and its unit + ClickHouse e2e tests — lowers the registry to ClickHouse expressions over a traces row.
  • registry-fixtures.ts, index.ts, the ./ai-registry export in package.json, resolveJsonModule in tsconfig.json, and the README's "TypeScript consumers" section.

Why it is shaped this way

Decoding at module load means a resync that changes the artifact's shape fails the import rather than the first classification, and validate.test.ts is the gate a future resync must pass — it reports violations and never repairs them, because a violation means the upstream compiler produced a bad artifact and must be fixed in trace-capture.

The SQL compiler exists for two consumers that both need to evaluate the registry without the Rust classifier: the differential tests that prove the two evaluators agree, and the rollup rebuild job, which cannot read the stored AiVendor because that is the column it is repairing. It emits no hash SQL, only because nothing in v1 consumes one: sessionKeyValueExpr yields the winning candidate's raw value and cityHash64 over it is a one-liner the caller can write. The subpath export keeps the ~280 KB artifact off the root @maple/domain barrel that web and cli import.

Gates run at this level

  • bun typecheck — 37/37 tasks pass.
  • packages/domain vitest — 532 passed, 7 skipped.
  • compile-sql.clickhouse.e2e.test.ts under CLICKHOUSE_E2E=1 against a real ClickHouse — 7 passed.

Dependencies

Requires #430 for registry.json. Independent of the Rust layer in #432 — the two evaluators are only tied together in #435.

Partition note: index.ts here exports everything except the rollup-enablement constants; that module belongs to the rollup and its export line is restored in #436.

🤖 Generated with Claude Code


Stack created with GitHub Stacks CLIGive Feedback 💬


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…iler

Adds `@maple/domain/ai-registry`: an Effect Schema decode of `registry.json`
at module load (so a bad resync fails the import, not the first
classification), the semantic invariants Schema cannot express
(`validate.ts`: globally unique priorities, the D4 priority bands, the
closed slug set, `value_prefix` confined to pseudo-keys), and
`compile-sql.ts`, which lowers the registry to ClickHouse expressions over
a `traces` row.

The SQL compiler exists so the Rust classifier can be proven equivalent to
a SQL evaluation of the same artifact, and so the rollup rebuild job has a
way to recompute vendors without reading the `AiVendor` column it is
fixing. It emits no hash SQL, but only because nothing in v1 consumes one:
`sessionKeyValueExpr` yields the winning candidate's raw value and
`cityHash64` over it is a one-liner the caller can write. The subpath
export keeps the ~280 KB artifact off the root `@maple/domain` barrel that
web and cli import, and `resolveJsonModule` is enabled for the vendored
JSON.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@JeremyFunk
JeremyFunk force-pushed the ai/04-registry-ts-sql-compiler branch from 1b7fc47 to e621844 Compare August 12, 2026 21:05
@JeremyFunk

Copy link
Copy Markdown
Collaborator Author

Superseded by the v2 stack: #451#452#453. The registry-artifact + SQL-equivalence design this stack implemented was dropped in the write-side plan's v2 revision; vendor rules are now plain Rust with the vendored classification fixture as the CI gate.

@github-actions

Copy link
Copy Markdown

🍁 Maple PR preview

Note

Preview resources were removed when this pull request closed.

Final commit e621844 · View workflow run

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