feat(phase-2): domain schema declaration + diff algorithm library (#15)
Implements Phase 2 of the supercharge plan: plugins now declare their data structure schema, and the core engine provides a shared diff algorithm library for free.
## New: muse/core/schema.py - `SequenceSchema`, `TreeSchema`, `TensorSchema`, `SetSchema`, `MapSchema` — five element schema TypedDicts covering the structural primitives of any domain. - `DimensionSpec` — a named semantic sub-dimension with its own schema. - `DomainSchema` — top-level plugin declaration used by the algorithm library and (in Phase 3) the operation-level merge engine.
## New: muse/core/diff_algorithms/ - `lcs.py` — `myers_ses()` / `detect_moves()` / `diff()` on `list[str]` (content IDs). Generic LCS usable by any sequence-schema domain. - `tree_edit.py` — LCS-based labeled ordered tree diff producing `ReplaceOp` (relabel), `InsertOp`, `DeleteOp`, `MoveOp`. Defines `TreeNode` frozen dataclass. - `numerical.py` — epsilon-tolerant sparse / block / full tensor diff on `list[float]`. - `set_ops.py` — hash-set algebra for unordered collections of content IDs. - `__init__.py` — `diff_by_schema()` dispatch + typed input containers (`SequenceInput`, `SetInput`, `TensorInput`, `MapInput`, `TreeInput`).
## Updated: muse/domain.py - `MuseDomainPlugin` gains a sixth method: `schema() -> DomainSchema`.
## Updated: muse/plugins/registry.py - `schema_for(domain) -> DomainSchema | None` — schema lookup without requiring a plugin instance.
## Updated: muse/plugins/music/plugin.py - `MusicPlugin.schema()` returns the full four-dimension `DomainSchema` (melodic/SequenceSchema, harmonic/SequenceSchema, dynamic/TensorSchema, structural/TreeSchema).
## Updated: muse/plugins/music/midi_diff.py - `lcs_edit_script()` is now a thin adapter over `lcs.myers_ses()` from the core library — music domain no longer has its own LCS copy. - `diff_midi_notes()` delegates the SES step to the shared core algorithm.
## New: tests/test_diff_algorithms.py — 54 tests ## New: tests/test_domain_schema.py — 20 tests
Verification: mypy 0 errors · typing_audit 0 violations · 530 tests green
Co-authored-by: Gabriel Cardona <gabriel@tellurstori.com>
Comments
0No comments yet. Be the first to start the discussion.