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

refactor(harmony): Phase 9 — split CLI into package (shapes / handlers / args)

Convert muse/cli/commands/harmony.py (2493 lines) into a package:

harmony/__init__.py 55 lines — thin shim, re-exports register + all public names harmony/_shapes.py 531 lines — all JSON TypedDicts + serialisation helpers harmony/_handlers.py 1286 lines — all run_* handler functions harmony/_args.py 717 lines — register() + full CLI docstring

The old harmony.py is deleted; harmony/__init__.py re-exports every name the tests access via getattr(module, name) so all 707 tests continue to pass. Also removes stale 'import muse.core.harmony_engine as eng' from test_harmony_engine.py.

sha256:16ba4bc2efedd2002dc11ca20b3f35f4b2f89e3a1386147d85343f3fe1f6caef sha
+162 ~8 −69 symbols
sha256:7fa98a3fd0a9385bb8b74dae38303c24bf43ea4778be5fba1aad4376275210c9 snapshot
+162
symbols added
~8
symbols modified
−69
symbols removed
0
dead code introduced
Semantic Changes 239 symbols
~ muse/cli/commands/harmony/__init__.py .py 46 symbols added
+ _HarmonyAuditJson import import _HarmonyAuditJson L7–7
+ _HarmonyBestJson import import _HarmonyBestJson L7–7
+ _HarmonyEngineJson import import _HarmonyEngineJson L7–7
+ _HarmonyEscalateJson import import _HarmonyEscalateJson L7–7
+ _HarmonyEscalationEntryJson import import _HarmonyEscalationEntryJson L7–7
+ _HarmonyEscalationsJson import import _HarmonyEscalationsJson L7–7
+ _HarmonyForgetJson import import _HarmonyForgetJson L7–7
+ _HarmonyGcJson import import _HarmonyGcJson L7–7
+ _HarmonyListEntryJson import import _HarmonyListEntryJson L7–7
+ _HarmonyListJson import import _HarmonyListJson L7–7
+ _HarmonyPatternDetailJson import import _HarmonyPatternDetailJson L7–7
+ _HarmonyPolicyAddJson import import _HarmonyPolicyAddJson L7–7
+ _HarmonyPolicyEntryJson import import _HarmonyPolicyEntryJson L7–7
+ _HarmonyPolicyListJson import import _HarmonyPolicyListJson L7–7
+ _HarmonyPolicyRemoveJson import import _HarmonyPolicyRemoveJson L7–7
+ _HarmonyProposalJson import import _HarmonyProposalJson L7–7
+ _HarmonyRecordJson import import _HarmonyRecordJson L7–7
+ _HarmonyResolutionDetailJson import import _HarmonyResolutionDetailJson L7–7
+ _HarmonyResolveEscalationJson import import _HarmonyResolveEscalationJson L7–7
+ _HarmonyResolveJson import import _HarmonyResolveJson L7–7
+ _HarmonyScalarJson import import _HarmonyScalarJson L7–7
+ _HarmonyShowJson import import _HarmonyShowJson L7–7
+ _HarmonySimilarJson import import _HarmonySimilarJson L7–7
+ _escalation_to_entry import import _escalation_to_entry L7–7
+ _pattern_to_detail import import _pattern_to_detail L7–7
+ _pattern_to_list_entry import import _pattern_to_list_entry L7–7
+ _policy_to_entry import import _policy_to_entry L7–7
+ _resolution_to_detail import import _resolution_to_detail L7–7
+ register import import register L6–6
+ run_audit import import run_audit L37–37
+ run_best import import run_best L37–37
+ run_clear import import run_clear L37–37
+ run_engine import import run_engine L37–37
+ run_escalate import import run_escalate L37–37
+ run_escalations import import run_escalations L37–37
+ run_forget import import run_forget L37–37
+ run_gc import import run_gc L37–37
+ run_list import import run_list L37–37
+ run_policy_add import import run_policy_add L37–37
+ run_policy_list import import run_policy_list L37–37
+ run_policy_remove import import run_policy_remove L37–37
+ run_record import import run_record L37–37
+ run_resolve import import run_resolve L37–37
+ run_resolve_escalation import import run_resolve_escalation L37–37
+ run_show import import run_show L37–37
+ run_similar import import run_similar L37–37
~ muse/cli/commands/harmony/_args.py .py 20 symbols added
+ annotations import import annotations L143–143
+ argparse import import argparse L145–145
+ run_audit import import run_audit L147–147
+ run_best import import run_best L147–147
+ run_clear import import run_clear L147–147
+ run_engine import import run_engine L147–147
+ run_escalate import import run_escalate L147–147
+ run_escalations import import run_escalations L147–147
+ run_forget import import run_forget L147–147
+ run_gc import import run_gc L147–147
+ run_list import import run_list L147–147
+ run_policy_add import import run_policy_add L147–147
+ run_policy_list import import run_policy_list L147–147
+ run_policy_remove import import run_policy_remove L147–147
+ run_record import import run_record L147–147
+ run_resolve import import run_resolve L147–147
+ run_resolve_escalation import import run_resolve_escalation L147–147
+ run_show import import run_show L147–147
+ run_similar import import run_similar L147–147
+ register function function register L168–717 ← moved from muse/cli/commands/harmony/_shapes.py
+ _proposal_to_json function function _proposal_to_json L879–892 ← moved from muse/cli/commands/harmony/_shapes.py
+ _stub_id function function _stub_id L894–896 ← moved from muse/cli/commands/harmony/_shapes.py
+ AgentProvenance import import AgentProvenance L14–14
+ Any import import Any L10–10
+ AuditEventType import import AuditEventType L14–14
+ ConflictPattern import import ConflictPattern L14–14
+ EngineConfig import import EngineConfig L48–48
+ EscalationRecord import import EscalationRecord L14–14
+ ExitCode import import ExitCode L13–13 ← moved from muse/cli/commands/harmony/_shapes.py
+ Policy import import Policy L14–14
+ PolicyCondition import import PolicyCondition L14–14
+ Resolution import import Resolution L14–14
+ _HarmonyAuditJson import import _HarmonyAuditJson L53–53
+ _HarmonyBestJson import import _HarmonyBestJson L53–53
+ _HarmonyEngineJson import import _HarmonyEngineJson L53–53
+ _HarmonyEscalateJson import import _HarmonyEscalateJson L53–53
+ _HarmonyEscalationEntryJson import import _HarmonyEscalationEntryJson L53–53
+ _HarmonyEscalationsJson import import _HarmonyEscalationsJson L53–53
+ _HarmonyForgetJson import import _HarmonyForgetJson L53–53
+ _HarmonyGcJson import import _HarmonyGcJson L53–53
+ _HarmonyListEntryJson import import _HarmonyListEntryJson L53–53
+ _HarmonyListJson import import _HarmonyListJson L53–53
+ _HarmonyPolicyAddJson import import _HarmonyPolicyAddJson L53–53
+ _HarmonyPolicyListJson import import _HarmonyPolicyListJson L53–53
+ _HarmonyPolicyRemoveJson import import _HarmonyPolicyRemoveJson L53–53
+ _HarmonyProposalJson import import _HarmonyProposalJson L53–53
+ _HarmonyRecordJson import import _HarmonyRecordJson L53–53
+ _HarmonyResolveEscalationJson import import _HarmonyResolveEscalationJson L53–53
+ _HarmonyResolveJson import import _HarmonyResolveJson L53–53
+ _HarmonyScalarJson import import _HarmonyScalarJson L53–53
+ _HarmonyShowJson import import _HarmonyShowJson L53–53
+ _HarmonySimilarJson import import _HarmonySimilarJson L53–53
+ _engine_find_similar import import _engine_find_similar L48–48
+ _engine_resolve import import _engine_resolve L48–48 ← moved from muse/cli/commands/harmony/_shapes.py
+ _escalation_to_entry import import _escalation_to_entry L53–53
+ _pattern_to_detail import import _pattern_to_detail L53–53
+ _pattern_to_list_entry import import _pattern_to_list_entry L53–53
+ _policy_to_entry import import _policy_to_entry L53–53
+ _resolution_to_detail import import _resolution_to_detail L53–53
+ _validate_fingerprint import import _validate_fingerprint L14–14
+ _validate_id import import _validate_id L14–14
+ _validate_policy_id import import _validate_policy_id L14–14
+ annotations import import annotations L3–3
+ append_audit import import append_audit L14–14
+ argparse import import argparse L5–5 ← moved from muse/cli/commands/harmony/_shapes.py
+ best_resolution import import best_resolution L14–14
+ blob_fingerprint import import blob_fingerprint L14–14
+ blob_id import import blob_id L51–51
+ clamp_int import import clamp_int L52–52
+ clear_all import import clear_all L14–14
+ compute_escalation_id import import compute_escalation_id L14–14
+ compute_pattern_id import import compute_pattern_id L14–14
+ compute_resolution_id import import compute_resolution_id L14–14
+ datetime import import datetime L6–6
+ forget_pattern import import forget_pattern L14–14
+ gc_stale import import gc_stale L14–14
+ json import import json L7–7 ← moved from muse/cli/commands/harmony/_shapes.py
+ list_audit import import list_audit L14–14
+ list_escalations import import list_escalations L14–14
+ list_patterns import import list_patterns L14–14
+ list_policies import import list_policies L14–14
+ list_resolutions import import list_resolutions L14–14
+ load_pattern import import load_pattern L14–14
+ logging import import logging L8–8 ← moved from muse/cli/commands/harmony/_shapes.py
+ make_envelope import import make_envelope L12–12
+ patterns_dir import import patterns_dir L14–14
+ record_escalation import import record_escalation L14–14
+ record_pattern import import record_pattern L14–14
+ remove_policy import import remove_policy L14–14
+ require_repo import import require_repo L49–49 ← moved from muse/cli/commands/harmony/_shapes.py
+ resolve_escalation import import resolve_escalation L14–14
+ sanitize_display import import sanitize_display L52–52 ← moved from muse/cli/commands/harmony/_shapes.py
+ save_policy import import save_policy L14–14
+ save_resolution import import save_resolution L14–14
+ short_id import import short_id L51–51 ← moved from muse/cli/commands/harmony/_shapes.py
+ start_timer import import start_timer L50–50 ← moved from muse/cli/commands/harmony/_shapes.py
+ sys import import sys L9–9 ← moved from muse/cli/commands/harmony/_shapes.py
+ logger variable variable logger L81–81 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_audit function function run_audit L838–873 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_best function function run_best L474–523 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_clear function function run_clear L574–617
+ run_engine function function run_engine L902–1018
+ run_escalate function function run_escalate L1101–1172
+ run_escalations function function run_escalations L1178–1220 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_forget function function run_forget L529–568 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_gc function function run_gc L623–665 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_list function function run_list L209–270 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_policy_add function function run_policy_add L671–744
+ run_policy_list function function run_policy_list L750–787 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_policy_remove function function run_policy_remove L793–832 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_record function function run_record L87–203
+ run_resolve function function run_resolve L344–468
+ run_resolve_escalation function function run_resolve_escalation L1226–1286
+ run_show function function run_show L276–338 ← moved from muse/cli/commands/harmony/_shapes.py
+ run_similar function function run_similar L1024–1095
~ tests/test_harmony_engine.py .py 1 symbol removed
eng import import eng L28–28
~ muse/cli/commands/harmony/_shapes.py .py moved from muse/cli/commands/harmony.py; 1 added, 68 removed, 8 modified
_proposal_to_json function function _proposal_to_json L2070–2083 → moved to muse/cli/commands/harmony/_handlers.py
_stub_id function function _stub_id L2206–2208 → moved to muse/cli/commands/harmony/_handlers.py
AgentProvenance import import AgentProvenance L153–153
AuditEventType import import AuditEventType L153–153
EngineConfig import import EngineConfig L192–192
EscalationStatus import import EscalationStatus L153–153
ExitCode import import ExitCode L152–152 → moved to muse/cli/commands/harmony/_handlers.py
PolicyCondition import import PolicyCondition L153–153
ResolutionStrategy import import ResolutionStrategy L153–153
_engine_find_similar import import _engine_find_similar L192–192
_engine_resolve import import _engine_resolve L192–192 → moved to muse/cli/commands/harmony/_handlers.py
_validate_fingerprint import import _validate_fingerprint L153–153
_validate_id import import _validate_id L153–153
_validate_policy_id import import _validate_policy_id L153–153
append_audit import import append_audit L153–153
argparse import import argparse L143–143 → moved to muse/cli/commands/harmony/_handlers.py
best_resolution import import best_resolution L153–153
blob_fingerprint import import blob_fingerprint L153–153
blob_id import import blob_id L150–150
clamp_int import import clamp_int L195–195 → moved to muse/cli/commands/harmony/_handlers.py
clear_all import import clear_all L153–153
compute_escalation_id import import compute_escalation_id L153–153
compute_pattern_id import import compute_pattern_id L153–153
compute_resolution_id import import compute_resolution_id L153–153
forget_pattern import import forget_pattern L153–153
gc_stale import import gc_stale L153–153
json import import json L144–144 → moved to muse/cli/commands/harmony/_handlers.py
list_audit import import list_audit L153–153
list_escalations import import list_escalations L153–153
list_patterns import import list_patterns L153–153
list_policies import import list_policies L153–153
list_resolutions import import list_resolutions L153–153
load_escalation import import load_escalation L153–153
load_pattern import import load_pattern L153–153
load_policy import import load_policy L153–153
load_resolution import import load_resolution L153–153
logging import import logging L145–145 → moved to muse/cli/commands/harmony/_handlers.py
make_envelope import import make_envelope L151–151
pathlib import import pathlib L146–146
record_escalation import import record_escalation L153–153
record_pattern import import record_pattern L153–153
remove_policy import import remove_policy L153–153
require_repo import import require_repo L193–193 → moved to muse/cli/commands/harmony/_handlers.py
resolve_escalation import import resolve_escalation L153–153
save_policy import import save_policy L153–153
save_resolution import import save_resolution L153–153
short_id import import short_id L150–150 → moved to muse/cli/commands/harmony/_handlers.py
start_timer import import start_timer L194–194 → moved to muse/cli/commands/harmony/_handlers.py
sys import import sys L147–147 → moved to muse/cli/commands/harmony/_handlers.py
logger variable variable logger L197–197 → moved to muse/cli/commands/harmony/_handlers.py
register function function register L719–1268 → moved to muse/cli/commands/harmony/_args.py
run_audit function function run_audit L2029–2064 → moved to muse/cli/commands/harmony/_handlers.py
run_best function function run_best L1663–1712 → moved to muse/cli/commands/harmony/_handlers.py
run_clear function function run_clear L1763–1807
run_engine function function run_engine L2085–2204
run_escalate function function run_escalate L2306–2378
run_escalations function function run_escalations L2384–2426 → moved to muse/cli/commands/harmony/_handlers.py
run_forget function function run_forget L1718–1757 → moved to muse/cli/commands/harmony/_handlers.py
run_gc function function run_gc L1813–1855 → moved to muse/cli/commands/harmony/_handlers.py
run_list function function run_list L1397–1458 → moved to muse/cli/commands/harmony/_handlers.py
run_policy_add function function run_policy_add L1861–1935
run_policy_list function function run_policy_list L1941–1978 → moved to muse/cli/commands/harmony/_handlers.py
run_policy_remove function function run_policy_remove L1984–2023 → moved to muse/cli/commands/harmony/_handlers.py
run_record function function run_record L1274–1391
run_resolve function function run_resolve L1532–1657
run_resolve_escalation function function run_resolve_escalation L2432–2493
run_show function function run_show L1464–1526 → moved to muse/cli/commands/harmony/_handlers.py
run_similar function function run_similar L2214–2287
+ annotations import import annotations L3–3
~ Policy

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:16ba4bc2efedd2002dc11ca20b3f35f4b2f89e3a1386147d85343f3fe1f6caef --body "your comment"