Task: B2: Switch model-type detection from filename suffix to #+type: frontmatter
This page documents a task in the Resolve codegen model unification blockers story. It captures the goal, current status, acceptance, and any notes or results.
Goal
get_model_type() and load_model() resolve model type from #+type: frontmatter. Suffix rules become a fallback for files that lack #+type:. No behavioural change for any currently registered model.
Status
| Field | Value |
|---|---|
| State | DONE |
| Parent story | Resolve codegen model unification blockers |
| Now | Nothing. |
| Waiting on | Nothing. |
| Next | Nothing. |
| Last touched | 2026-06-27 |
Acceptance
- get_model_type() reads #+type: via a lightweight frontmatter parse before falling back to suffix rules
- load_model() dispatches to the correct loader for every #+type: value in _CODEGEN_ORG_TYPES
- All existing codegen regression tests pass with zero diff
Plan
(Implementation strategy. Written when work starts; key decisions
are distilled into the parent story's * Decisions at close, but the
plan itself stays — it is the historical record of what we did.)
Notes
PRs
| PR | Title |
|---|---|
Review
| Comment summary | File | Decision | Notes |
|---|---|---|---|
Result
Shipped in two commits on feature/codegen-unification-blockers.
- Added
_ORG_TYPE_RE,_ORG_TYPE_TO_MODEL_TYPEmap, and_read_org_type()helper tocodegen/core.py._read_org_type()reads the first 4096 bytes of an.orgfile, matches#+type:via a compiled regex, and returns the mapped model-type string. RaisesValueErrorfor an unrecognised#+type:value (list of known types included in the message); raisesOSErrorif the file is unreadable; returnsNonewhen no#+type:header is present so the suffix fallback applies. - Updated
get_model_type(model_filename, model_path=None)to accept the full path and call_read_org_type()before any suffix predicate whenmodel_pathis supplied. - Updated
load_model()to call_read_org_type()and dispatch to the correct loader based on the frontmatter type; the full suffix-chain fallback applies when there is no#+type:header. - Updated all four call sites (
generate.py, three incompass_codegen_entity.py) to passmodel_path. - All existing component scaffold regression tests pass with zero diff.
Acceptance met:
get_model_type()reads#+type:before suffix rules. ✓load_model()dispatches correctly for every value in_ORG_TYPE_TO_MODEL_TYPE. ✓- Unrecognised
#+type:raisesValueErrorwith a helpful message rather than silently falling through to suffix detection. ✓ - All existing regression tests pass. ✓