Mizan IR: cut over to KDL, delete OpenAPI envelope

Replaces the transitional OpenAPI 3.0 + `x-mizan-*` extensions
substrate with the canonical Mizan IR as KDL, per docs/AFI_ARCHITECTURE.md:
"KDL is the contract; everything else (REST envelopes, OpenAPI
documents, framework idioms) is sediment around it."

End-to-end cutover. No transitional path left on main.

Forward direction:
  cores/mizan-python/src/mizan_core/ir.py
    build_ir() walks mizan_core.registry, introspects Pydantic
    models directly (no JSON-Schema indirection), and emits the
    Mizan IR document. The KDL grammar is locked in this file's
    module docstring.

Backends emit KDL:
  backends/mizan-fastapi/src/mizan_fastapi/ir.py
    `python -m mizan_fastapi.ir <module>` — CLI entry point.
  backends/mizan-django/.../management/commands/export_mizan_ir.py
    `manage.py export_mizan_ir` — Django mgmt command.

Codegen consumes KDL:
  protocol/mizan-codegen/Cargo.toml: + kdl = "6"
  protocol/mizan-codegen/src/ir.rs: NamedType { Struct/List/Enum/Alias }
    + TypeShape { Primitive/Ref/List/Optional/Enum/Union } sum types,
    replacing the JsonSchema sprawl. KDL parser walks the
    `kdl::KdlDocument` tree into typed Rust structs.
  protocol/mizan-codegen/src/fetch.rs: subprocess command switches
    to the new IR-export entry points.
  All emit modules (stage1 / react / python / rust / vue / svelte /
    channels) port their type-walkers from JsonSchema to the new
    sum types — case analysis collapses substantially.

Substrate-honesty wins beyond the moat closure:
  - `int | bool` multi-arm unions land as `TypeShape::Union` (was
    silently coerced to "string" before).
  - `<CamelName>Output = list[T]` returns emit as named alias
    types instead of struct-shaped wrappers, so consumer code
    `.map()` works directly on the type.
  - Pydantic field defaults flow through to `default` properties
    in KDL, then back to non-optional shape in every target.

Deleted:
  - backends/mizan-fastapi/src/mizan_fastapi/{cli,schema}.py
  - backends/mizan-django/.../export_mizan_schema.py
  - openapi-bearing half of mizan/export/__init__.py (edge
    manifest generator preserved — separate concern).
  - tests/afi/schema_normalizer.py
  - tests/fixtures/{afi_schema.json, channels_schema.json}
  - tests/fixtures/js_* baseline directories.

Verification:
  - 20 mizan-codegen unit tests green (IR deserialization,
    byte-equivalence parity across stage1/rust/python/react/vue/svelte
    against fresh KDL-driven baselines, channels structural).
  - tests/rust/run_wire_parity.py: 12/12 probes green driving
    the binary end-to-end through KDL.
  - Blazr studio-ui typechecks against the regenerated React client.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 19:14:47 -04:00
parent 7fb0c4a400
commit 9900f8a36f
86 changed files with 2231 additions and 2272 deletions

View File

@@ -0,0 +1,4 @@
# AUTO-GENERATED by mizan — do not edit
from .client import MizanClient # noqa: F401
from .types import * # noqa: F401, F403

View File

@@ -0,0 +1,67 @@
# AUTO-GENERATED by mizan — do not edit
from __future__ import annotations
from collections.abc import Callable
from typing import Any
# Built from frontends/mizan-rust with `maturin develop --features pyo3`.
from mizan_rust import PyMizanClient, PyContextSubscription
from .types import * # noqa: F401, F403
from .types import BaseModel # re-import for the synthesized ContextData classes
class MizanClient:
"""Typed Python facade over the PyO3 mizan-rust kernel."""
def __init__(self, base_url: str, *, session: bool = False,
csrf_cookie_name: str = "csrftoken",
csrf_header_name: str = "X-CSRFToken") -> None:
self._inner = PyMizanClient(
base_url,
session=session,
csrf_cookie_name=csrf_cookie_name,
csrf_header_name=csrf_header_name,
)
def fetch_user_context(self, user_id: int) -> "UserContextData":
raw = self._inner.fetch_context("user", {"user_id": user_id})
return UserContextData(**raw)
def subscribe_user_context(self, user_id: int,
callback: Callable[[dict[str, Any]], None]) -> PyContextSubscription:
return self._inner.subscribe_context("user", {"user_id": user_id}, callback)
def call_echo(self, args: EchoInput) -> EchoOutput:
raw = self._inner.call("echo", args.model_dump())
return EchoOutput(**raw)
def call_whoami(self) -> WhoamiOutput:
raw = self._inner.call("whoami", {})
return WhoamiOutput(**raw)
def call_update_profile(self, args: UpdateProfileInput) -> UpdateProfileOutput:
raw = self._inner.call("update_profile", args.model_dump())
return UpdateProfileOutput(**raw)
def call_find_user(self, args: FindUserInput) -> FindUserOutput | None:
raw = self._inner.call("find_user", args.model_dump())
return FindUserOutput(**raw) if raw is not None else None
def call_rename_user(self, args: RenameUserInput) -> RenameUserOutput:
raw = self._inner.call("rename_user", args.model_dump())
return RenameUserOutput(**raw)
def invalidate(self, context: str) -> None:
self._inner.invalidate(context)
def invalidate_scoped(self, context: str, params: dict[str, Any]) -> None:
self._inner.invalidate_scoped(context, params)
# ── Context data shapes (per-context bundle) ──────────────────────────────
class UserContextData(BaseModel):
"""Bundled return of fetch_user_context."""
user_profile: UserProfileOutput
user_orders: UserOrdersOutput

View File

@@ -0,0 +1,56 @@
# AUTO-GENERATED by mizan — do not edit
from __future__ import annotations
from typing import Any, Literal
from pydantic import BaseModel
class OrderOutput(BaseModel):
id: int
user_id: int
total: int
class EchoInput(BaseModel):
text: str
class EchoOutput(BaseModel):
message: str
class FindUserInput(BaseModel):
user_id: int
class FindUserOutput(BaseModel):
user_id: int
name: str
class RenameUserInput(BaseModel):
user_id: int
name: str
class RenameUserOutput(BaseModel):
user_id: int
name: str
class UpdateProfileInput(BaseModel):
user_id: int
name: str
class UpdateProfileOutput(BaseModel):
ok: bool
class UserOrdersInput(BaseModel):
user_id: int
UserOrdersOutput = list[OrderOutput]
class UserProfileInput(BaseModel):
user_id: int
class UserProfileOutput(BaseModel):
user_id: int
name: str
class WhoamiOutput(BaseModel):
email: str
authenticated: bool