{"record":{"id":"e21ceaaf6d03b975","repo":"Hmbown/CodeWhale","slug":"tui-model-context-fragment-rs-must-re-export-caps-from","errorCode":null,"errorMessage":"TUI model_context/fragment.rs must re-export caps from codewhale_core::fragments (shared crates/core boundary)","messagePattern":"TUI model_context/fragment\\.rs must re-export caps from codewhale_core::fragments \\(shared crates/core boundary\\)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":602,"sourceCode":"            \"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        )\n\n\ndef main(argv: Sequence[str] | None = None) -> int:\n    parser = argparse.ArgumentParser(description=__doc__)","sourceCodeStart":584,"sourceCodeEnd":620,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-runtime-contract-budget.py#L584-L620","documentation":"After reading the TUI fragment module, check_fragment_caps requires it to reference `codewhale_core::fragments`, proving crates/tui/src/model_context/fragment.rs re-exports the byte-cap constants from the shared core crate rather than defining its own. Missing the literal raises this error. This enforces the single shared crates/core boundary for fragment caps (no duplicated cap logic in the TUI).","triggerScenarios":"Running the contract check when the TUI fragment module exists but does not mention codewhale_core::fragments — it defines its own MAX_FRAGMENT_BYTES locally, imports via a re-export path with a different spelling, or uses no caps at all.","commonSituations":"The TUI module was written before the core-unification and still holds local constants; an import was collapsed to `use codewhale_core::fragments::*` rewritten as individual `use codewhale_core::fragments::MAX_FRAGMENT_BYTES` that later got removed; crate renamed and paths updated wholesale.","solutions":["Add `use codewhale_core::fragments::{enforce_byte_cap, matches_text, ContextFragment, MAX_FRAGMENT_BYTES, ...};` (or `pub use codewhale_core::fragments;`) to crates/tui/src/model_context/fragment.rs.","Delete any locally duplicated cap constants/recognizers from the TUI module and delegate to codewhale_core::fragments.","Run the contract check to confirm the re-export and remaining TUI assertions (ProjectInstructions, MAX_FRAGMENT_BYTES, matches_text) all pass."],"exampleFix":"// before (tui/src/model_context/fragment.rs)\npub const MAX_FRAGMENT_BYTES: usize = 40000; // duplicated\n\n// after\npub use codewhale_core::fragments::{enforce_byte_cap, matches_text, ContextFragment, MAX_FRAGMENT_BYTES};","handlingStrategy":"validation","validationCode":"text = open('crates/tui/src/model_context/fragment.rs').read()\nassert 'codewhale_core::fragments' in text, 'TUI fragment module must import codewhale_core::fragments'","typeGuard":"def tui_reexports_core_caps(tui_text: str) -> bool:\n    return 'codewhale_core::fragments' in tui_text","tryCatchPattern":"try:\n    check_fragment_caps()\nexcept RuntimeContractError as e:\n    if 're-export caps from codewhale_core::fragments' in str(e):\n        add_core_fragments_use_to_tui_module()","preventionTips":["Always import TUI fragment caps from codewhale_core::fragments; never duplicate constants in the TUI.","Avoid glob re-exports being collapsed in ways that drop the codewhale_core::fragments path from the file.","Run the contract check after any import cleanup in model_context/."],"tags":["rust","static-analysis","contract-check","tui","code-duplication"],"backgroundTag":"missing-dependency","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"}