{"record":{"id":"da268b674d6b017d","repo":"Hmbown/CodeWhale","slug":"tui-fragment-module-must-include-projectinstructions-variant","errorCode":null,"errorMessage":"TUI fragment module must include ProjectInstructions variant (unified with core)","messagePattern":"TUI fragment module must include ProjectInstructions variant \\(unified with core\\)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":606,"sourceCode":"    if \"MAX_FRAGMENT_BYTES\" not in text or \"enforce_byte_cap\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must enforce byte caps via enforce_byte_cap and MAX_FRAGMENT_BYTES\"\n        )\n\n    # TUI must be unified with the core boundary (shared crates/core module)\n    tui_fragment = REPO_ROOT / \"crates\" / \"tui\" / \"src\" / \"model_context\" / \"fragment.rs\"\n    try:\n        tui_text = tui_fragment.read_text(encoding=\"utf-8\")\n    except FileNotFoundError as error:\n        raise RuntimeContractError(\n            f\"missing TUI fragment module: {tui_fragment} ({error})\"\n        ) from error\n    if \"codewhale_core::fragments\" not in tui_text:\n        raise RuntimeContractError(\n            \"TUI model_context/fragment.rs must re-export caps from codewhale_core::fragments (shared crates/core boundary)\"\n        )\n    if \"ProjectInstructions\" not in tui_text:\n        raise RuntimeContractError(\n            \"TUI fragment module must include ProjectInstructions variant (unified with core)\"\n        )\n    if \"MAX_FRAGMENT_BYTES\" not in tui_text:\n        raise RuntimeContractError(\n            \"TUI fragment module must enforce MAX_FRAGMENT_BYTES (10K-token ceiling)\"\n        )\n    if \"matches_text\" not in tui_text:\n        raise RuntimeContractError(\n            \"TUI fragment module must expose a matches_text recognizer\"\n        )\n\n\ndef main(argv: Sequence[str] | None = None) -> int:\n    parser = argparse.ArgumentParser(description=__doc__)\n    parser.add_argument(\n        \"--receipt\",\n        type=Path,\n        help=\"check an existing measurement JSON instead of compiling\",","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L588-L624","documentation":"check_fragment_caps requires the TUI fragment module to mention `ProjectInstructions`, i.e. the enum/variant set in crates/tui/src/model_context/fragment.rs must include the ProjectInstructions fragment so project-instruction imports flow through the same unified fragment type as core. Missing it raises this error. This keeps the TUI and core fragment models aligned (shared crates/core boundary).","triggerScenarios":"Running the contract check when crates/tui/src/model_context/fragment.rs exists, re-exports from codewhale_core::fragments, but its local fragment enum lacks a ProjectInstructions variant — e.g. a trimmed enum, a variant renamed to ProjectRules, or project instructions handled outside the fragment system.","commonSituations":"A developer removes the variant thinking project instructions are only a core concern; a rename to match a new product name; a partial sync where core gained the variant but the TUI enum was hand-written instead of re-exported.","solutions":["Add a `ProjectInstructions` variant to the fragment enum in crates/tui/src/model_context/fragment.rs (or re-export the unified enum containing it from codewhale_core::fragments).","Handle the new variant in any exhaustive matches over fragment kinds in the TUI so it compiles.","Prefer importing the enum wholesale from codewhale_core::fragments so TUI and core cannot drift again."],"exampleFix":"// before (tui fragment enum)\npub enum Fragment { SystemPrompt(...), Retrieved(...), ToolResult(...) }\n\n// after\npub enum Fragment {\n    SystemPrompt(...),\n    ProjectInstructions(...),\n    Retrieved(...),\n    ToolResult(...),\n}","handlingStrategy":"validation","validationCode":"text = open('crates/tui/src/model_context/fragment.rs').read()\nassert 'ProjectInstructions' in text, 'TUI fragment enum must include ProjectInstructions'","typeGuard":"def has_project_instructions_variant(tui_text: str) -> bool:\n    return 'ProjectInstructions' in tui_text","tryCatchPattern":"try:\n    check_fragment_caps()\nexcept RuntimeContractError as e:\n    if 'ProjectInstructions variant' in str(e):\n        add_project_instructions_variant_to_tui_enum()","preventionTips":["Derive the TUI fragment enum from (or re-export) the core enum instead of hand-maintaining a copy.","Never drop a variant during enum cleanup without checking scripts/check-runtime-contract-budget.py.","Keep core and TUI fragment kinds in lockstep: one PR, both sides."],"tags":["rust","static-analysis","contract-check","tui","fragments"],"backgroundTag":"missing-enum-values","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}