gabriel / musehub public
Open #91 Enhancement
filed by gabriel human · 2 days ago

Replace artifact_type with domain on Mists

0 Anchors
Blast radius
Churn 30d
0 Proposals

Replace artifact_type with domain on Mists

Background

Mists are quick one-off artifacts — the Muse equivalent of a GitHub Gist. They map naturally to Muse domains: a Python snippet is a code mist, a MIDI phrase is a midi mist, a future audio clip would be a stems mist.

The current artifact_type field predates this domain model and has accumulated conflicting classifications:

Current artifact_type What it actually is
code code mist — correct
midi midi mist — correct
schema code mist, language=json
json_schema code mist, language=json
abi code mist, language=json
config code mist, language=yaml
dataset code mist, language=text
text code mist
prose hallucinated — never existed as a domain
unknown code mist

The language field already carries the specificity that the subtypes were trying to capture. artifact_type is a redundant and confusing layer.

Goal

Replace artifact_type with domain everywhere: DB column, API wire format, CLI flags, and UI. Valid domain values are code, midi, and stems. All text-based subtypes collapse to domain=code with language retaining the specificity (e.g. markdown, python, json, yaml).

Before:

{ "artifactType": "schema", "language": "" }
{ "artifactType": "prose",  "language": "markdown" }
{ "artifactType": "code",   "language": "python" }

After:

{ "domain": "code", "language": "json" }
{ "domain": "code", "language": "markdown" }
{ "domain": "code", "language": "python" }

Phases

Phase 1 — Database migration

Must be fully green before Phase 2 begins.

Add domain column to musehub_mists and backfill from artifact_type + language. Then drop artifact_type.

Backfill rules:

artifact_type domain language if empty
code code (unchanged)
prose code markdown
text code text
schema code json
json_schema code json
abi code json
config code yaml
dataset code text
unknown code (unchanged)
midi midi (unchanged)

Deliverables:

  • 0071_mist_domain.py — alembic migration (MD_01, MD_02, MD_03)
    • upgrade(): add domain NOT NULL with default code, backfill from table, drop artifact_type
    • downgrade(): restore artifact_type from domain, drop domain

Tests (run against a real DB, no mocks — tests/test_migration_0071.py):

  • MD_01 — all existing artifact_type values map to the correct domain after upgrade
  • MD_02language is backfilled correctly for schema, abi, config, dataset, prose
  • MD_03 — downgrade restores artifact_type; no rows lost

Phase 2 — Server models + API

Depends on Phase 1. Must be fully green before Phase 3 or Phase 4 begins.

Replace artifact_type with domain in the server-side models and all API endpoints.

Deliverables:

  • musehub/db/musehub_repo_models.pyMusehubMist.domain: str replaces artifact_type
  • musehub/models/mists.pyMistResponse, MistListEntry, MistForkResponse use domain; MistCreateRequest accepts domain, rejects unknown values with 422; MistUpdateRequest accepts optional domain
  • musehub/services/musehub_mists.py — all references to artifact_type replaced with domain
  • musehub/services/musehub_proposals.py_DOMAIN_WEIGHTS keys use actual domain values; domain heat dict updated
  • musehub/services/spectral_sigil.pyDOMAIN_COLORS keyed on code, midi, stems
  • Wire format: domain in camelCase is still domain (no rename needed)

Tests (tests/test_mist_routes.py):

  • MD_04POST /api/mists with domain=code returns 201 with domain in response
  • MD_05POST /api/mists with domain=midi returns 201
  • MD_06POST /api/mists with unknown domain returns 422
  • MD_07GET /api/mists/{id} returns domain, no artifactType key
  • MD_08GET /api/{owner}/mists list entries contain domain

Phase 3 — CLI

Depends on Phase 2. Must be fully green before Phase 5 begins.

Replace --type with --domain on muse hub mist create. Update all --json output keys.

Deliverables:

  • muse/cli/commands/hub/mists.py--domain flag (values: code, midi, stems; default code); remove --type
  • All --json output: domain key replaces artifactType / artifact_type

Tests (tests/test_hub_mist_cli.py):

  • MD_09muse hub mist create --domain code succeeds and --json output contains domain: "code"
  • MD_10muse hub mist create --domain midi succeeds
  • MD_11--type flag no longer exists (passing it raises an error)

Phase 4 — UI + templates

Depends on Phase 2. Must be fully green before Phase 5 begins.

Update all template and route logic that reads artifact_type / prism_lang mapping.

Deliverables:

  • musehub/api/routes/musehub/ui_mists.py_prism_map keyed on domain + language; _TYPE_COLORS_DOMAIN_COLORS; display_artifact_typedisplay_domain; md_html branch still driven by language == "markdown"
  • musehub/templates/musehub/pages/mist_detail.html — badge shows domain + language (e.g. code · markdown, midi)
  • musehub/templates/musehub/pages/mist_list.html, mist_explore.html, mist_embed.html — same badge update
  • musehub/templates/musehub/fragments/mist_rows.html — same

Tests (visual — no test ID; verify manually on staging):

  • MD_12 — markdown mist shows code · markdown badge and renders as HTML
  • MD_13 — Python mist shows code · python badge and syntax-highlighted source
  • MD_14 — MIDI mist shows midi badge and download placeholder

Phase 5 — Integration + cleanup

Depends on Phases 3 and 4.

End-to-end round-trip and removal of all remaining artifact_type references.

Deliverables:

  • muse content-grep "artifact_type" returns zero results across both repos
  • muse content-grep "artifactType" returns zero results (excluding this issue body)
  • Integration test: create mist via CLI → read via API → verify detail page renders correctly (MD_15)

Tests:

  • MD_15 — full round-trip: muse hub mist create --domain code --language markdownGET /api/mists/{id} returns domain=code, language=markdown → detail page renders HTML

Acceptance Criteria

  • No artifact_type or artifactType anywhere in code, tests, templates, or docs (except this issue body and migration downgrade path)
  • All existing mists have domain set correctly after migration
  • domain is one of code, midi, stems — no other values accepted
  • language continues to drive syntax highlighting and markdown rendering
  • The "prose" badge is gone forever

Out of Scope

  • Adding stems domain rendering (MIDI is the only non-code domain with active rendering today)
  • API versioning / backwards compatibility for external callers
  • Mist search or filtering by domain (follow-on feature)
Activity
gabriel opened this issue 2 days ago
No activity yet. Use the CLI to comment.