Task: B2: Switch model-type detection from filename suffix to #+type: frontmatter

Table of Contents

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_TYPE map, and _read_org_type() helper to codegen/core.py. _read_org_type() reads the first 4096 bytes of an .org file, matches #+type: via a compiled regex, and returns the mapped model-type string. Raises ValueError for an unrecognised #+type: value (list of known types included in the message); raises OSError if the file is unreadable; returns None when 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 when model_path is 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 in compass_codegen_entity.py) to pass model_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: raises ValueError with a helpful message rather than silently falling through to suffix detection. ✓
  • All existing regression tests pass. ✓

Emacs 29.1 (Org mode 9.6.6)