gabriel / muse public
refactor BREAKING harmony task/harmony-decompose #9 / 13
AI Agent gabriel · 114 days ago · May 22, 2026 · Diff

refactor(harmony): Phase 4 — extract patterns.py

Move pattern CRUD, _write_atomic, and serialisation helpers out of the 2210-line harmony __init__.py into a focused muse/core/harmony/patterns.py.

- patterns.py: _MAX_PATTERN_BYTES, _MAX_SCAN, _write_atomic, _pattern_to_dict, _dict_to_pattern, record_pattern, load_pattern, list_patterns, forget_pattern, clear_all (189 lines) - __init__.py: re-exports all extracted symbols; duplicated bodies removed - test_harmony_phase1.py: monkeypatch now targets muse.core.harmony.patterns directly for _MAX_SCAN after it moved out of __init__.py

707/707 harmony tests green.

sha256:cd613942f08fb261f6d94b89e93abaed26e6d4d57dba4de2aa0ff9f40be8c435 sha
+43 ~2 −10 symbols
sha256:2b850cee18f85af32f3b9aacf941011e1543d8c61da5906ebbcc0604f5cf98b2 snapshot
+43
symbols added
~2
symbols modified
−10
symbols removed
0
dead code introduced
Semantic Changes 55 symbols
~ muse/core/harmony/patterns.py .py 33 symbols added
+ _MAX_PATTERN_BYTES variable variable _MAX_PATTERN_BYTES L33–33 ← moved from muse/core/harmony/__init__.py
+ _MAX_SCAN variable variable _MAX_SCAN L36–36 ← moved from muse/core/harmony/__init__.py
+ _dict_to_pattern function function _dict_to_pattern L82–100 ← moved from muse/core/harmony/__init__.py
+ _pattern_to_dict function function _pattern_to_dict L67–80 ← moved from muse/core/harmony/__init__.py
+ _write_atomic function function _write_atomic L42–61 ← moved from muse/core/harmony/__init__.py
+ clear_all function function clear_all L286–313 ← moved from muse/core/harmony/__init__.py
+ forget_pattern function function forget_pattern L233–284
+ ConflictPattern import import ConflictPattern L28–28
+ ConflictType import import ConflictType L28–28
+ JsonValue import import JsonValue L16–16
+ Mapping import import Mapping L14–14
+ _BARE_HEX64_RE import import _BARE_HEX64_RE L19–19
+ _PATTERN_FILE import import _PATTERN_FILE L19–19
+ _PatternDict import import _PatternDict L28–28
+ _RESOLUTIONS import import _RESOLUTIONS L19–19
+ _parse_dt import import _parse_dt L18–18
+ _pattern_entry_dir import import _pattern_entry_dir L19–19
+ _resolutions_dir import import _resolutions_dir L19–19
+ _validate_id import import _validate_id L19–19
+ annotations import import annotations L7–7
+ json import import json L9–9
+ load_json_file import import load_json_file L16–16
+ logging import import logging L10–10
+ long_id import import long_id L16–16
+ os import import os L11–11
+ pathlib import import pathlib L12–12
+ patterns_dir import import patterns_dir L19–19
+ short_id import import short_id L16–16
+ tempfile import import tempfile L13–13
+ list_patterns function function list_patterns L187–231 ← moved from muse/core/harmony/__init__.py
+ load_pattern function function load_pattern L142–185
+ logger variable variable logger L30–30
+ record_pattern function function record_pattern L106–140
~ muse/core/harmony/__init__.py .py 10 symbols added, 10 symbols removed
_MAX_PATTERN_BYTES variable variable _MAX_PATTERN_BYTES L171–171 → moved to muse/core/harmony/patterns.py
_MAX_SCAN variable variable _MAX_SCAN L186–186 → moved to muse/core/harmony/patterns.py
_dict_to_pattern function function _dict_to_pattern L238–256 → moved to muse/core/harmony/patterns.py
_pattern_to_dict function function _pattern_to_dict L223–236 → moved to muse/core/harmony/patterns.py
_write_atomic function function _write_atomic L198–217 → moved to muse/core/harmony/patterns.py
clear_all function function clear_all L526–553 → moved to muse/core/harmony/patterns.py
forget_pattern function function forget_pattern L471–524
list_patterns function function list_patterns L424–469 → moved to muse/core/harmony/patterns.py
load_pattern function function load_pattern L381–422
record_pattern function function record_pattern L345–379
+ _MAX_PATTERN_BYTES import import _MAX_PATTERN_BYTES L113–113
+ _MAX_SCAN import import _MAX_SCAN L113–113
+ _dict_to_pattern import import _dict_to_pattern L113–113
+ _pattern_to_dict import import _pattern_to_dict L113–113
+ _write_atomic import import _write_atomic L113–113
+ clear_all import import clear_all L113–113
+ forget_pattern import import forget_pattern L113–113
+ list_patterns import import list_patterns L113–113
+ load_pattern import import load_pattern L113–113
+ record_pattern import import record_pattern L113–113

0 comments

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

To add a comment, use the Muse CLI: muse hub commit comment sha256:cd613942f08fb261f6d94b89e93abaed26e6d4d57dba4de2aa0ff9f40be8c435 --body "your comment"