Frame-aware AI fallback module scaffolded under src/phase_z2_ai_fallback/ with master flag ai_fallback_enabled=False; normal-path AI call count remains 0. AI output constrained to builder_options_patch / partial_overrides / slot_mapping_proposal; MDX / frame_id / raw HTML / raw CSS mutations rejected at schema layer. IMP-46 cache gate (cache.py) raises AiFallbackCacheGateError unless visual_check_passed AND user_approved. Step 12 wires AI repair after IMP-30 provisional payload only; Step 17 stays blocked behind IMP-34 / IMP-35 prerequisites. AST isolation guard forbids fallback package from importing Phase Q / Kei / pipeline runtime symbols. Docs IMP-17 / IMP-31 bound to runtime module surface via 11-row structural test pin (test_docs_sync.py) so drift fails CI. Tests: 116 fallback / 161 phase_z2 regression / 526 scoped full sweep all passing. Existing pre-IMP-33 fixture issue in scripts/test_phase_t_* remains untouched (out of scope). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""IMP-33 u2 — AI fallback proposal schema.
|
|
|
|
Whitelisted proposal kinds (Stage 2 plan):
|
|
- builder_options_patch : zone/frame builder option overrides
|
|
- partial_overrides : Internal Region / Frame Slot content overrides
|
|
- slot_mapping_proposal : restructuring proposal (content unit mapping)
|
|
|
|
Forbidden output forms (rejected by validator):
|
|
- mdx_text (MDX read-only — `feedback_ai_isolation_contract`)
|
|
- frame_id_change (V4 rank-1 protected — `feedback_phase_z_spacing_direction`)
|
|
- raw_html (HTML structure is code-decided, not AI-generated)
|
|
- raw_css (same)
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from enum import Enum
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
|
|
|
|
class ProposalKind(str, Enum):
|
|
BUILDER_OPTIONS_PATCH = "builder_options_patch"
|
|
PARTIAL_OVERRIDES = "partial_overrides"
|
|
SLOT_MAPPING_PROPOSAL = "slot_mapping_proposal"
|
|
|
|
|
|
FORBIDDEN_KINDS: frozenset[str] = frozenset(
|
|
{"mdx_text", "frame_id_change", "raw_html", "raw_css"}
|
|
)
|
|
|
|
|
|
class AiFallbackProposal(BaseModel):
|
|
"""Single AI fallback proposal (output contract for u4 client)."""
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
proposal_kind: ProposalKind
|
|
payload: dict[str, Any] = Field(default_factory=dict)
|
|
rationale: str = ""
|
|
|
|
@field_validator("proposal_kind", mode="before")
|
|
@classmethod
|
|
def _reject_forbidden_kind(cls, value: Any) -> Any:
|
|
if isinstance(value, str) and value in FORBIDDEN_KINDS:
|
|
raise ValueError(
|
|
f"proposal_kind={value!r} is forbidden (MDX/frame/raw HTML/CSS "
|
|
"mutations are not permitted under IMP-33)."
|
|
)
|
|
return value
|