README.md
markdown
| 1 | # Muse Documentation |
| 2 | |
| 3 | > **Version:** v0.1.2 · [Project README](../README.md) · [Source](../muse/) |
| 4 | |
| 5 | This directory contains the complete documentation for Muse — a domain-agnostic version control system for multidimensional state. |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## Quick Navigation |
| 10 | |
| 11 | | I want to… | Start here | |
| 12 | |-------------|-----------| |
| 13 | | Understand the full architecture | [Architecture Reference](architecture/muse-vcs.md) | |
| 14 | | Browse the CLI command tiers | [CLI Tiers Reference](reference/cli-tiers.md) | |
| 15 | | See all MIDI semantic commands | [MIDI Domain Reference](reference/midi-domain.md) | |
| 16 | | See all Code semantic commands | [Code Domain Reference](reference/code-domain.md) | |
| 17 | | Build a new domain plugin | [Plugin Authoring Guide](guide/plugin-authoring-guide.md) | |
| 18 | | Learn CRDT semantics | [CRDT Reference](guide/crdt-reference.md) | |
| 19 | | See an end-to-end walkthrough | [E2E Demo](architecture/muse-e2e-demo.md) | |
| 20 | | Read the protocol spec | [Plugin Protocol](protocol/muse-protocol.md) | |
| 21 | | Understand domain concepts | [Domain Concepts](protocol/muse-domain-concepts.md) | |
| 22 | | Look up a named type | [Type Contracts](reference/type-contracts.md) | |
| 23 | | Configure merge strategies | [`.museattributes` Reference](reference/muse-attributes.md) | |
| 24 | | Exclude files from snapshots | [`.museignore` Reference](reference/museignore.md) | |
| 25 | | Watch the demo narration | [Demo Script](demo/demo-script.md) | |
| 26 | |
| 27 | --- |
| 28 | |
| 29 | ## Directory Map |
| 30 | |
| 31 | ``` |
| 32 | docs/ |
| 33 | ├── README.md ← you are here |
| 34 | │ |
| 35 | ├── architecture/ |
| 36 | │ ├── muse-vcs.md — full technical design: protocol stack, storage, |
| 37 | │ │ diff algorithms, OT merge, CRDT semantics, |
| 38 | │ │ config system, and CLI command map |
| 39 | │ └── muse-e2e-demo.md — step-by-step lifecycle: init → commit → branch |
| 40 | │ → merge conflict → resolve → tag |
| 41 | │ |
| 42 | ├── guide/ |
| 43 | │ ├── plugin-authoring-guide.md — complete walkthrough for writing a new domain |
| 44 | │ │ plugin, from core protocol through OT merge |
| 45 | │ │ and CRDT convergent merge |
| 46 | │ └── crdt-reference.md — CRDT primer: lattice laws, all six primitives |
| 47 | │ (VectorClock, LWWRegister, ORSet, RGA, AWMap, |
| 48 | │ GCounter), composition patterns, when to use CRDTs |
| 49 | │ |
| 50 | ├── protocol/ |
| 51 | │ ├── muse-protocol.md — language-agnostic MuseDomainPlugin spec: six |
| 52 | │ │ required methods, StructuredMergePlugin and |
| 53 | │ │ CRDTPlugin optional extensions, invariants |
| 54 | │ ├── muse-domain-concepts.md — universal vocabulary: what "state", "delta", |
| 55 | │ │ "dimension", "drift", and "merge" mean across |
| 56 | │ │ music, genomics, simulation, and beyond |
| 57 | │ └── muse-variation-spec.md — variation semantics for the MIDI domain |
| 58 | │ |
| 59 | ├── reference/ |
| 60 | │ ├── cli-tiers.md — three-tier CLI architecture: Tier 1 plumbing |
| 61 | │ │ (JSON, pipeable), Tier 2 porcelain (core VCS), |
| 62 | │ │ Tier 3 semantic (midi/code/coord namespaces) |
| 63 | │ ├── midi-domain.md — MIDI domain complete reference: all 31 semantic |
| 64 | │ │ porcelain commands, flags, JSON schemas, types |
| 65 | │ ├── code-domain.md — Code domain complete reference: all semantic |
| 66 | │ │ porcelain commands, symbol identity model, types |
| 67 | │ ├── type-contracts.md — single source of truth for every named type: |
| 68 | │ │ TypedDicts, dataclasses, Protocols, Enums, |
| 69 | │ │ and TypeAliases with Mermaid diagrams |
| 70 | │ ├── muse-attributes.md — .museattributes TOML format reference: |
| 71 | │ │ [meta] domain, [[rules]] syntax, all five |
| 72 | │ │ strategies, multi-domain usage, examples |
| 73 | │ └── museignore.md — .museignore format: glob patterns, negation, |
| 74 | │ dotfile exclusion rules |
| 75 | │ |
| 76 | └── demo/ |
| 77 | ├── midi-demo.md — MIDI domain demo walkthrough: all 31 semantic |
| 78 | │ porcelain commands with CLI output examples |
| 79 | ├── demo-code.md — Code domain demo walkthrough |
| 80 | └── demo-script.md — narration script for the video demo |
| 81 | ``` |
| 82 | |
| 83 | --- |
| 84 | |
| 85 | ## Architecture at a Glance |
| 86 | |
| 87 | Muse separates the **VCS engine** (domain-agnostic) from **domain plugins** (domain-specific). The engine never changes when a new domain is added — only a new plugin is registered. |
| 88 | |
| 89 | ``` |
| 90 | ┌─────────────────────────────────────────────┐ |
| 91 | │ muse CLI │ |
| 92 | │ Tier 1: plumbing · Tier 2: porcelain │ |
| 93 | │ Tier 3: midi / code / coord domains │ |
| 94 | └──────────────────────┬──────────────────────┘ |
| 95 | │ |
| 96 | ┌──────────────────────▼──────────────────────┐ |
| 97 | │ Muse Core Engine │ |
| 98 | │ DAG · object store · branching · merging │ |
| 99 | │ content-addressed blobs · lineage walking │ |
| 100 | └──────┬────────────────────────────┬─────────┘ |
| 101 | │ │ |
| 102 | ┌──────▼──────┐ ┌──────▼──────┐ |
| 103 | │MuseDomainPlugin│ │MuseDomainPlugin│ |
| 104 | │ (music) │ │ (your domain) │ |
| 105 | │ 6 methods │ │ 6 methods │ |
| 106 | └──────────────┘ └───────────────┘ |
| 107 | ``` |
| 108 | |
| 109 | The six required methods: |
| 110 | |
| 111 | | Method | What it does | |
| 112 | |--------|-------------| |
| 113 | | `snapshot()` | Capture live state → content-addressed dict | |
| 114 | | `diff()` | Compute typed delta between two snapshots | |
| 115 | | `merge()` | Three-way reconciliation against a common ancestor | |
| 116 | | `drift()` | Compare committed state against live working tree | |
| 117 | | `apply()` | Apply a delta to reconstruct historical state | |
| 118 | | `schema()` | Declare data structure → drives diff algorithm selection | |
| 119 | |
| 120 | Two optional protocol extensions enable richer merge semantics: |
| 121 | |
| 122 | | Extension | Adds | Effect | |
| 123 | |-----------|------|--------| |
| 124 | | `StructuredMergePlugin` | `merge_ops()` | Operation-level OT merge — minimal real conflicts | |
| 125 | | `CRDTPlugin` | `join()` + 3 helpers | Convergent merge — `join` always succeeds, no conflict state | |
| 126 | |
| 127 | --- |
| 128 | |
| 129 | ## Adding a New Domain |
| 130 | |
| 131 | 1. Copy `muse/plugins/scaffold/` → `muse/plugins/<your_domain>/` |
| 132 | 2. Rename `ScaffoldPlugin` → `<YourDomain>Plugin` |
| 133 | 3. Replace every `raise NotImplementedError(...)` with real implementation |
| 134 | 4. Register in `muse/plugins/registry.py` |
| 135 | 5. Run `muse init --domain <your_domain>` in a project directory |
| 136 | |
| 137 | All Tier 2 core VCS commands work immediately for the new domain. Tier 3 semantic commands live in the new `muse/<domain> …` sub-namespace. See the [Plugin Authoring Guide](guide/plugin-authoring-guide.md) for the full walkthrough. |
| 138 | |
| 139 | --- |
| 140 | |
| 141 | ## Config Files Generated by `muse init` |
| 142 | |
| 143 | | File | Location | Purpose | |
| 144 | |------|----------|---------| |
| 145 | | `repo.json` | `.muse/repo.json` | Immutable identity: repo UUID, schema version, domain | |
| 146 | | `config.toml` | `.muse/config.toml` | Mutable: `[user]`, `[auth]`, `[remotes]`, `[domain]` | |
| 147 | | `HEAD` | `.muse/HEAD` | Current branch ref | |
| 148 | | `.museattributes` | repo root | TOML merge strategy overrides (`[[rules]]`) | |
| 149 | | `.museignore` | repo root | Glob patterns to exclude from snapshots | |
| 150 | |
| 151 | --- |
| 152 | |
| 153 | ## Testing Standards |
| 154 | |
| 155 | Every public function has a unit test. Integration tests wire real components. E2E tests invoke the CLI via `typer.testing.CliRunner`. |
| 156 | |
| 157 | ```bash |
| 158 | # Run all tests |
| 159 | pytest tests/ -v |
| 160 | |
| 161 | # Type-check |
| 162 | mypy muse/ |
| 163 | |
| 164 | # Zero-Any audit |
| 165 | python tools/typing_audit.py --dirs muse/ tests/ --max-any 0 |
| 166 | ``` |
| 167 | |
| 168 | All three gates must be green before any PR merges. |