feat(phase-1): typed delta algebra — replace DeltaManifest with StructuredDelta (#13)
Implements Phase 1 of the supercharge plan end-to-end.
## What changed
**Core type system (muse/domain.py)** - Remove `DeltaManifest` entirely. - Add `InsertOp`, `DeleteOp`, `MoveOp`, `ReplaceOp`, `PatchOp` TypedDicts — each discriminated by a `Literal["op-name"]` field for mypy narrowing. - Add `StructuredDelta` — `{domain, ops: list[DomainOp], summary}`. - `StateDelta = StructuredDelta` (was `DeltaManifest`). - `MergeResult` gains `op_log: list[DomainOp]`. - `DriftReport.delta` defaults to an empty `StructuredDelta`. - `MuseDomainPlugin.diff()` gains `repo_root: Path | None = None`.
**Storage (muse/core/store.py)** - `CommitRecord` and `CommitDict` gain `structured_delta: StructuredDelta | None`. - Stored at commit time; deserialized on read for `muse show`.
**Myers LCS MIDI diff (muse/plugins/music/midi_diff.py)** — new module - `NoteKey` TypedDict as the LCS comparison unit (5 fields). - `lcs_edit_script()`: O(nm) LCS DP + traceback → `list[EditStep]`. - `extract_notes()`: MIDI bytes → sorted `list[NoteKey]`. - `diff_midi_notes()`: top-level entry point → `StructuredDelta`. - Content IDs are deterministic SHA-256 of note field tuples.
**Music plugin (muse/plugins/music/plugin.py)** - `diff()`: returns `StructuredDelta` with `InsertOp`/`DeleteOp` for file additions/removals, `ReplaceOp` for non-MIDI modifications, and `PatchOp` with note-level `child_ops` for MIDI files when `repo_root` is available. - `apply()`: handles `DeleteOp`/`ReplaceOp`/`InsertOp` in-memory; workdir path rescans as before. - `drift()`: counts op kinds instead of accessing old manifest keys.
**CLI commands** - `commit.py`: computes and stores `structured_delta` against parent. - `show.py`: displays `commit.structured_delta` with per-op lines and `PatchOp` child_summary; falls back to manifest diff for old commits. - `diff.py`: calls `plugin.diff(repo_root=root)` and prints structured output. - `status.py`: extracts added/modified/deleted sets from `delta.ops`. - `checkout.py`: extracts removed/to_restore paths from `delta.ops`.
**Tests** - `test_structured_delta.py` (new): 38 tests for all op types and plugin behaviour. - `test_midi_diff.py` (new): 29 tests for note extraction, LCS algorithm, and `diff_midi_notes()` end-to-end. - `test_music_plugin.py`: updated to StructuredDelta API. - `test_cli_plugin_dispatch.py`, `test_plugin_apply_and_checkout.py`, `test_cli_coverage_gaps.py`: updated for new delta shape.
All 456 tests green. mypy strict: 0 errors. typing_audit --max-any 0: 0 violations.
Co-authored-by: Gabriel Cardona <gabriel@tellurstori.com>
Comments
0No comments yet. Be the first to start the discussion.