Skip to content

catalog_v1

catalog_v1

Lossless converter from the v1 instrument catalog to the v2 directory (GH #549, MC1a).

Pure functions plus one writer. mzt instruments catalog convert is the CLI home. The conversion keeps every v1 musician (as a v2 model), every route v1 states (instruments.*.runs_models and available_via) and every v1 field that has no v2 home (under legacy). Tiers are derived guesses, always marked provisional: v1 tiers are price bands, which mean nothing on a subscription.

Functions:

family_slug

family_slug(label)

Family file slug for a v1 family label ('Claude 5' -> 'claude').

Source code in src/marianne/instruments/catalog_v1.py
def family_slug(label: str) -> str:
    """Family file slug for a v1 family label ('Claude 5' -> 'claude')."""
    base = re.sub(r"[^a-z0-9]+", "-", label.lower()).strip("-")
    for prefix, slug in _FAMILY_PREFIXES:
        if base.startswith(prefix):
            return slug
    stripped = re.sub(r"\s+v?\d[\w.\-]*$", "", label.strip())
    return re.sub(r"[^a-z0-9]+", "-", stripped.lower()).strip("-") or base

convert_v1

convert_v1(v1, generated_at=None)

Convert a loaded v1 catalog into family files and an index.

Source code in src/marianne/instruments/catalog_v1.py
def convert_v1(
    v1: dict[str, Any], generated_at: date | None = None
) -> tuple[dict[str, CatalogFile], CatalogIndex]:
    """Convert a loaded v1 catalog into family files and an index."""
    if v1.get("schema_version") != 1:
        raise ValueError(f"expected a v1 catalog, got schema_version={v1.get('schema_version')!r}")
    generated_at = generated_at or date.today()
    routes, unmatched = _routes(v1)
    by_family: dict[str, list[CatalogModel]] = {}
    for key, row in v1["musicians"].items():
        model = _model(key, row, routes[key])
        by_family.setdefault(model.family, []).append(model)
    files = {
        slug: CatalogFile(
            schema_version=CATALOG_SCHEMA_VERSION,  # type: ignore[arg-type]
            generated_at=generated_at,
            generated_by=CONVERTER_NAME,
            families={slug: models},
        )
        for slug, models in sorted(by_family.items())
    }
    index = CatalogIndex(
        schema_version=CATALOG_SCHEMA_VERSION,  # type: ignore[arg-type]
        generated_at=generated_at,
        generated_by=CONVERTER_NAME,
        source="instrument-catalog.yaml (schema_version 1)",
        model_count=sum(len(m) for m in by_family.values()),
        families={
            slug: IndexFamily(file=f"{slug}.yaml", model_ids=[m.id for m in models])
            for slug, models in sorted(by_family.items())
        },
        unmatched_routes=unmatched,
    )
    return files, index

write_catalog

write_catalog(source, out_dir, generated_at=None)

Read a v1 catalog file and write the v2 directory; returns the index.

Source code in src/marianne/instruments/catalog_v1.py
def write_catalog(source: Path, out_dir: Path, generated_at: date | None = None) -> CatalogIndex:
    """Read a v1 catalog file and write the v2 directory; returns the index."""
    v1 = yaml.safe_load(source.read_text(encoding="utf-8"))
    files, index = convert_v1(v1, generated_at)
    out_dir.mkdir(parents=True, exist_ok=True)
    for slug, file in files.items():
        header = (
            f"# Catalog v2 family '{slug}'. Generated by `{CONVERTER_NAME}` from the v1 "
            "catalog.\n# Tiers marked provisional are guesses from v1 tags, not evidence.\n"
        )
        (out_dir / f"{slug}.yaml").write_text(header + _dump(file), encoding="utf-8")
    (out_dir / INDEX_FILENAME).write_text(_dump(index), encoding="utf-8")
    return index