cgcardona / muse public
feat phase-1 main

feat(phase-1): typed delta algebra — replace DeltaManifest with StructuredDelta

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.

G Gabriel Cardona <gabriel@tellurstori.com> · 2d ago Mar 18, 2026 · d7054e63 · parent 25a0c523

Snapshot Diff

74 files in tree
+1 ~27 -62
AGENTS.md .md
README.md .md
docs/README.md .md
docs/demo/README.md .md
docs/demo/tour-de-force-code.md .md
docs/demo/tour-de-force-music.md .md
docs/guide/crdt-reference.md .md
docs/guide/plugin-authoring-guide.md .md
muse/cli/commands/blame.py .py
muse/cli/commands/compare.py .py
muse/cli/commands/coupling.py .py
muse/cli/commands/coverage.py .py
muse/cli/commands/dead.py .py
muse/cli/commands/deps.py .py
muse/cli/commands/detect_refactor.py .py
muse/cli/commands/domains.py .py
muse/cli/commands/find_symbol.py .py
muse/cli/commands/grep.py .py
muse/cli/commands/harmony.py .py
muse/cli/commands/hotspots.py .py
muse/cli/commands/impact.py .py
muse/cli/commands/languages.py .py
muse/cli/commands/mix.py .py
muse/cli/commands/note_blame.py .py
muse/cli/commands/note_hotspots.py .py
muse/cli/commands/note_log.py .py
muse/cli/commands/notes.py .py
muse/cli/commands/patch.py .py
muse/cli/commands/piano_roll.py .py
muse/cli/commands/query.py .py
muse/cli/commands/stable.py .py
muse/cli/commands/symbol_log.py .py
muse/cli/commands/symbols.py .py
muse/cli/commands/transpose.py .py
muse/cli/commands/velocity_profile.py .py
muse/core/crdts/__init__.py .py
muse/core/crdts/aw_map.py .py
muse/core/crdts/g_counter.py .py
muse/core/crdts/lww_register.py .py
muse/core/crdts/or_set.py .py
muse/core/crdts/rga.py .py
muse/core/crdts/vclock.py .py
muse/core/diff_algorithms/__init__.py .py
muse/core/diff_algorithms/lcs.py .py
muse/core/diff_algorithms/numerical.py .py
muse/core/diff_algorithms/set_ops.py .py
muse/core/diff_algorithms/tree_edit.py .py
muse/core/op_transform.py .py
muse/core/schema.py .py
muse/plugins/code/__init__.py .py
muse/plugins/code/_callgraph.py .py
muse/plugins/code/_query.py .py
muse/plugins/code/ast_parser.py .py
muse/plugins/code/plugin.py .py
muse/plugins/code/symbol_diff.py .py
muse/plugins/music/_query.py .py
muse/plugins/scaffold/__init__.py .py
muse/plugins/scaffold/plugin.py .py
tests/test_code_plugin.py .py
tests/test_crdts.py .py
tests/test_diff_algorithms.py .py
tests/test_domain_schema.py .py
tests/test_op_transform.py .py
tools/render_domain_registry.py .py
← Older Oldest commit on main
All commits
Newer → Latest commit on main

Comments

0

No comments yet. Be the first to start the discussion.