Hmbown/CodeWhale · error · RuntimeContractError
TUI model_context/fragment.rs must re-export caps from…
Error message
TUI model_context/fragment.rs must re-export caps from codewhale_core::fragments (shared crates/core boundary)
What it means
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).
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.
Example fix
// before (tui/src/model_context/fragment.rs)
pub const MAX_FRAGMENT_BYTES: usize = 40000; // duplicated
// after
pub use codewhale_core::fragments::{enforce_byte_cap, matches_text, ContextFragment, MAX_FRAGMENT_BYTES}; Defensive patterns
Strategy: validation
Validate before calling
text = open('crates/tui/src/model_context/fragment.rs').read()
assert 'codewhale_core::fragments' in text, 'TUI fragment module must import codewhale_core::fragments' Type guard
def tui_reexports_core_caps(tui_text: str) -> bool:
return 'codewhale_core::fragments' in tui_text Try / catch
try:
check_fragment_caps()
except RuntimeContractError as e:
if 're-export caps from codewhale_core::fragments' in str(e):
add_core_fragments_use_to_tui_module() Prevention
- 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/.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- TUI fragment module must enforce MAX_FRAGMENT_BYTES…
- TUI fragment module must include ProjectInstructions…
- bounded fragment module must define a matches_text…
- bounded fragment module must define…
- bounded fragment module must define trait ContextFragment…
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/e21ceaaf6d03b975.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/check-runtime-contract-budget.py:602
"bounded fragment module must define trait ContextFragment with matches_text"
)
# No unbounded fragment — enforce that creation clamps to MAX_FRAGMENT_BYTES
if "MAX_FRAGMENT_BYTES" not in text or "enforce_byte_cap" not in text:
raise RuntimeContractError(
"bounded fragment module must enforce byte caps via enforce_byte_cap and MAX_FRAGMENT_BYTES"
)
# TUI must be unified with the core boundary (shared crates/core module)
tui_fragment = REPO_ROOT / "crates" / "tui" / "src" / "model_context" / "fragment.rs"
try:
tui_text = tui_fragment.read_text(encoding="utf-8")
except FileNotFoundError as error:
raise RuntimeContractError(
f"missing TUI fragment module: {tui_fragment} ({error})"
) from error
if "codewhale_core::fragments" not in tui_text:
raise RuntimeContractError(
"TUI model_context/fragment.rs must re-export caps from codewhale_core::fragments (shared crates/core boundary)"
)
if "ProjectInstructions" not in tui_text:
raise RuntimeContractError(
"TUI fragment module must include ProjectInstructions variant (unified with core)"
)
if "MAX_FRAGMENT_BYTES" not in tui_text:
raise RuntimeContractError(
"TUI fragment module must enforce MAX_FRAGMENT_BYTES (10K-token ceiling)"
)
if "matches_text" not in tui_text:
raise RuntimeContractError(
"TUI fragment module must expose a matches_text recognizer"
)
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)View on GitHub (pinned to 433685b202)