{"record":{"id":"84d429086cff7df1","repo":"Hmbown/CodeWhale","slug":"missing-tui-fragment-module-tui-fragment-error","errorCode":null,"errorMessage":"missing TUI fragment module: {tui_fragment} ({error})","messagePattern":"missing TUI fragment module: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":598,"sourceCode":"            \"bounded fragment module must define a matches_text recognizer on the fragment trait\"\n        )\n    if \"trait ContextFragment\" not in text:\n        raise RuntimeContractError(\n            \"bounded fragment module must define trait ContextFragment with matches_text\"\n        )\n\n    # No unbounded fragment — enforce that creation clamps to MAX_FRAGMENT_BYTES\n    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        )","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L580-L616","documentation":"check_fragment_caps unifies the TUI with the shared core fragment boundary by reading crates/tui/src/model_context/fragment.rs. If that file does not exist, the FileNotFoundError is converted to this RuntimeContractError naming the missing path. The check fails closed because a missing TUI module means the shared-boundary contract cannot be verified.","triggerScenarios":"Running the contract check when crates/tui/src/model_context/fragment.rs is absent — the module was deleted, renamed (e.g. fragments.rs), moved out of model_context/, or a fresh branch predates the unification.","commonSituations":"A refactor moves the TUI fragment module to another directory; a stale worktree/branch from before the core-unification work; a bulk rename of model_context/ modules; contributor branch created before the module landed.","solutions":["Recreate crates/tui/src/model_context/fragment.rs (restore from git history: `git log --diff-filter=D -- crates/tui/src/model_context/fragment.rs`).","If the module was intentionally moved, update this script's tui_fragment path in scripts/check-runtime-contract-budget.py as part of the documented migration.","Verify the TUI crate's module tree declares the file (mod fragment; in model_context/mod.rs) so it compiles and exists on disk."],"exampleFix":"// before (model_context/mod.rs)\nmod session; // fragment.rs deleted\n\n// after\nmod fragment;\nmod session;","handlingStrategy":"validation","validationCode":"from pathlib import Path\nassert Path('crates/tui/src/model_context/fragment.rs').exists(), 'TUI fragment module missing'","typeGuard":"def tui_fragment_module_exists() -> bool:\n    from pathlib import Path\n    return Path('crates/tui/src/model_context/fragment.rs').is_file()","tryCatchPattern":"try:\n    text = Path('crates/tui/src/model_context/fragment.rs').read_text()\nexcept FileNotFoundError:\n    restore_tui_fragment_module_from_git()","preventionTips":["When moving or renaming TUI modules, update scripts/check-runtime-contract-budget.py path constants in the same commit.","Declare fragment module in model_context/mod.rs so refactor tooling sees it as live code.","Rebase stale branches onto main before running contract checks to avoid pre-unification trees."],"tags":["rust","file-not-found","contract-check","tui"],"backgroundTag":"file-not-found","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"}