gabriel / muse public
feat BREAKING harmony task/harmony-phase3 #1 / 1
AI Agent gabriel · 162 days ago · Apr 17, 2026 · Diff

feat(harmony): Phase 3 — three-tier resolution engine

- harmony_engine.py: EngineStatus, HarmonyPlugin protocol, DefaultPlugin, EngineConfig (thresholds + limits), EngineResult (frozen dataclass), find_similar() (semantic search, plugin-extensible, capped at max_proposals), resolve() (four-tier pipeline: policy → exact replay → semantic → escalate) - harmony.py: add AuditEventType.ESCALATION_RECORDED constant - harmony.py CLI: _HarmonyEngineJson + _HarmonySimilarJson TypedDicts, engine subcommand (run_engine), similar subcommand (run_similar) - 364/364 tests green (Phase 1 + 2 + 3 engine + 3 CLI)

sha256:e85d7e2f58b6dfc4693fc15a24f365328e1b7243fddda8f6b98fb84edc01e81e sha
+238 ~2 symbols
sha256:5b4518b6e3b5e4c25981242bb6a2272b157d67331f5b8e12ef8c14c0105303ca snapshot
+238
symbols added
~2
symbols modified
0
dead code introduced
Semantic Changes 240 symbols
~ muse/core/harmony_engine.py .py 33 symbols added
+ DefaultPlugin class class DefaultPlugin L141–151
+ similarity method method similarity L149–151
+ EngineConfig class class EngineConfig L160–179
+ EngineResult class class EngineResult L188–218
+ EngineStatus class class EngineStatus L102–115
+ HarmonyPlugin class class HarmonyPlugin L124–138
+ similarity method method similarity L136–138
+ _write_applied_audit function function _write_applied_audit L477–493
+ _write_escalation_audit function function _write_escalation_audit L496–512
+ find_similar function function find_similar L226–300
+ AgentProvenance import import AgentProvenance L77–77
+ AuditEventType import import AuditEventType L77–77
+ ConflictPattern import import ConflictPattern L77–77
+ PolicyAction import import PolicyAction L77–77
+ Protocol import import Protocol L73–73
+ Resolution import import Resolution L77–77
+ ResolutionProposal import import ResolutionProposal L77–77
+ ResolutionStrategy import import ResolutionStrategy L77–77
+ annotations import import annotations L69–69
+ append_audit import import append_audit L77–77
+ best_resolution import import best_resolution L77–77
+ dataclass class import dataclass L72–72
+ field import import field L72–72
+ increment_applied_count import import increment_applied_count L77–77
+ list_patterns import import list_patterns L77–77
+ list_policies import import list_policies L77–77
+ list_resolutions import import list_resolutions L77–77
+ logging import import logging L71–71
+ match_policy import import match_policy L77–77
+ pathlib import import pathlib L75–75
+ runtime_checkable import import runtime_checkable L73–73
+ logger variable variable logger L94–94
+ resolve function function resolve L308–469
~ tests/test_harmony_cli_phase3.py .py 68 symbols added
+ TestDataIntegrity class class TestDataIntegrity L409–450
+ test_engine_applied_applied_resolution_id_is_hex64 method method test_engine_applied_applied_resolution_id_is_hex64 L420–426
+ test_engine_escalated_fields_all_present method method test_engine_escalated_fields_all_present L412–418
+ test_engine_proposed_proposal_confidence_in_range method method test_engine_proposed_proposal_confidence_in_range L434–440
+ test_similar_empty_proposals_is_list_not_null method method test_similar_empty_proposals_is_list_not_null L428–432
+ test_similar_similarity_in_range method method test_similar_similarity_in_range L442–450
+ TestEndToEnd class class TestEndToEnd L355–401
+ test_escalation_audit_trail method method test_escalation_audit_trail L368–374
+ test_exact_replay_increments_applied_count_via_cli method method test_exact_replay_increments_applied_count_via_cli L376–384
+ test_policy_engine_audit_trail method method test_policy_engine_audit_trail L358–366
+ test_similar_then_engine_workflow method method test_similar_then_engine_workflow L386–401
+ TestEngineErrors class class TestEngineErrors L304–333
+ test_engine_invalid_id_exits_1 method method test_engine_invalid_id_exits_1 L307–309
+ test_engine_invalid_threshold_exits_1 method method test_engine_invalid_threshold_exits_1 L317–324
+ test_engine_negative_threshold_exits_1 method method test_engine_negative_threshold_exits_1 L326–333
+ test_engine_nonexistent_id_exits_0_escalated method method test_engine_nonexistent_id_exits_0_escalated L311–315
+ TestEngineSuccess class class TestEngineSuccess L167–237
+ test_engine_applied_via_exact_replay method method test_engine_applied_via_exact_replay L189–196
+ test_engine_applied_via_policy method method test_engine_applied_via_policy L179–187
+ test_engine_escalated_via_escalate_policy method method test_engine_escalated_via_escalate_policy L232–237
+ test_engine_escalates_no_policy_no_resolution method method test_engine_escalates_no_policy_no_resolution L170–177
+ test_engine_proposed_low_confidence method method test_engine_proposed_low_confidence L198–206
+ test_engine_proposed_via_policy_low_confidence method method test_engine_proposed_via_policy_low_confidence L224–230
+ test_engine_text_output method method test_engine_text_output L208–212
+ test_engine_with_custom_threshold method method test_engine_with_custom_threshold L214–222
+ TestPerformance class class TestPerformance L479–494
+ test_engine_under_300ms method method test_engine_under_300ms L482–487
+ test_similar_under_300ms method method test_similar_under_300ms L489–494
+ TestRegistration class class TestRegistration L150–159
+ test_engine_help method method test_engine_help L153–155
+ test_similar_help method method test_similar_help L157–159
+ TestSecurity class class TestSecurity L458–471
+ test_engine_null_byte_rejected method method test_engine_null_byte_rejected L469–471
+ test_engine_traversal_rejected method method test_engine_traversal_rejected L461–463
+ test_similar_traversal_rejected method method test_similar_traversal_rejected L465–467
+ TestSimilarErrors class class TestSimilarErrors L336–347
+ test_similar_invalid_id_exits_1 method method test_similar_invalid_id_exits_1 L339–341
+ test_similar_nonexistent_exits_0_empty method method test_similar_nonexistent_exits_0_empty L343–347
+ TestSimilarSuccess class class TestSimilarSuccess L240–296
+ test_similar_empty_when_no_match method method test_similar_empty_when_no_match L243–250
+ test_similar_entry_has_required_fields method method test_similar_entry_has_required_fields L266–275
+ test_similar_finds_shared_semantic_fingerprint method method test_similar_finds_shared_semantic_fingerprint L252–264
+ test_similar_limit method method test_similar_limit L285–296
+ test_similar_text_output method method test_similar_text_output L277–283
+ TestTypedDictSchemas class class TestTypedDictSchemas L117–147
+ _hints method method _hints L120–123
+ test_engine_json_has_applied_resolution_id method method test_engine_json_has_applied_resolution_id L134–135
+ test_engine_json_has_escalation_reason method method test_engine_json_has_escalation_reason L137–138
+ test_engine_json_has_pattern_id method method test_engine_json_has_pattern_id L128–129
+ test_engine_json_has_proposal method method test_engine_json_has_proposal L131–132
+ test_engine_json_has_status method method test_engine_json_has_status L125–126
+ test_similar_json_has_pattern_id method method test_similar_json_has_pattern_id L140–141
+ test_similar_json_has_proposals method method test_similar_json_has_proposals L146–147
+ test_similar_json_has_total method method test_similar_json_has_total L143–144
+ _add_policy function function _add_policy L92–109
+ _fake_id function function _fake_id L37–38
+ _record function function _record L50–71
+ _resolve function function _resolve L74–89
+ CliRunner import import CliRunner L27–27
+ annotations import import annotations L17–17
+ hashlib import import hashlib L19–19
+ json import import json L20–20
+ pathlib import import pathlib L21–21
+ pytest import import pytest L25–25
+ time import import time L22–22
+ typing import import typing L23–23
+ repo function function repo L42–47
+ runner variable variable runner L29–29
~ tests/test_harmony_engine.py .py 127 symbols added
+ TestDataIntegrity class class TestDataIntegrity L845–899
+ test_applied_result_has_no_escalation_reason method method test_applied_result_has_no_escalation_reason L859–865
+ test_engine_result_is_json_serialisable method method test_engine_result_is_json_serialisable L893–899
+ test_engine_result_pattern_id_matches_input method method test_engine_result_pattern_id_matches_input L876–880
+ test_escalated_result_fields_complete method method test_escalated_result_fields_complete L848–857
+ test_proposal_confidence_in_range method method test_proposal_confidence_in_range L867–874
+ test_proposal_is_json_serialisable method method test_proposal_is_json_serialisable L882–891
+ TestDefaultPlugin class class TestDefaultPlugin L258–276
+ test_different_fps_return_0 method method test_different_fps_return_0 L265–266
+ test_identical_fps_return_1 method method test_identical_fps_return_1 L261–263
+ test_similarity_commutative method method test_similarity_commutative L268–271
+ test_similarity_range method method test_similarity_range L273–276
+ TestEndToEnd class class TestEndToEnd L665–766
+ test_escalation_writes_audit method method test_escalation_writes_audit L696–706
+ test_exact_replay_applied_writes_audit method method test_exact_replay_applied_writes_audit L682–694
+ test_full_lifecycle_policy_to_replay method method test_full_lifecycle_policy_to_replay L708–750
+ test_policy_applied_writes_audit method method test_policy_applied_writes_audit L668–680
+ test_resolve_with_explicit_config method method test_resolve_with_explicit_config L752–766
+ TestEngineConfig class class TestEngineConfig L191–212
+ test_custom_config method method test_custom_config L203–207
+ test_default_auto_apply_threshold method method test_default_auto_apply_threshold L194–195
+ test_default_max_proposals method method test_default_max_proposals L200–201
+ test_default_semantic_threshold method method test_default_semantic_threshold L197–198
+ test_frozen method method test_frozen L209–212
+ TestEngineResult class class TestEngineResult L215–255
+ test_applied_result method method test_applied_result L218–226
+ test_escalated_result method method test_escalated_result L244–250
+ test_frozen method method test_frozen L252–255
+ test_proposed_result method method test_proposed_result L228–242
+ TestEngineStatus class class TestEngineStatus L174–188
+ test_applied_is_string method method test_applied_is_string L177–178
+ test_distinct_values method method test_distinct_values L186–188
+ test_escalated_is_string method method test_escalated_is_string L183–184
+ test_proposed_is_string method method test_proposed_is_string L180–181
+ TestFindSimilar class class TestFindSimilar L298–385
+ test_find_similar_below_threshold_excluded method method test_find_similar_below_threshold_excluded L374–385
+ test_find_similar_empty_store method method test_find_similar_empty_store L301–305
+ test_find_similar_respects_max_proposals method method test_find_similar_respects_max_proposals L357–372
+ test_find_similar_returns_semantically_matching_pattern method method test_find_similar_returns_semantically_matching_pattern L317–335
+ test_find_similar_skips_self method method test_find_similar_skips_self L307–315
+ test_find_similar_sorted_by_confidence_desc method method test_find_similar_sorted_by_confidence_desc L337–355
+ TestHarmonyPluginProtocol class class TestHarmonyPluginProtocol L279–295
+ test_custom_plugin_accepted method method test_custom_plugin_accepted L282–295
+ TestPerformance class class TestPerformance L967–1010
+ test_find_similar_100_patterns_under_500ms method method test_find_similar_100_patterns_under_500ms L998–1010
+ test_resolve_exact_replay_under_50ms method method test_resolve_exact_replay_under_50ms L988–996
+ test_resolve_no_match_under_50ms method method test_resolve_no_match_under_50ms L970–976
+ test_resolve_policy_under_50ms method method test_resolve_policy_under_50ms L978–986
+ TestSecurity class class TestSecurity L907–959
+ test_plugin_exception_caught method method test_plugin_exception_caught L910–926
+ test_plugin_returning_out_of_range_similarity_clamped method method test_plugin_returning_out_of_range_similarity_clamped L928–947
+ test_resolve_safe_with_empty_repo method method test_resolve_safe_with_empty_repo L949–953
+ test_resolve_safe_with_nonexistent_root method method test_resolve_safe_with_nonexistent_root L955–959
+ TestStress class class TestStress L774–837
+ test_engine_with_100_patterns_completes method method test_engine_with_100_patterns_completes L777–796
+ test_find_similar_100_patterns method method test_find_similar_100_patterns L798–820
+ test_many_policy_first_match_wins method method test_many_policy_first_match_wins L822–837
+ TestTierEscalate class class TestTierEscalate L626–657
+ test_escalation_has_no_applied_resolution method method test_escalation_has_no_applied_resolution L638–643
+ test_escalation_has_no_proposal method method test_escalation_has_no_proposal L645–650
+ test_no_policy_no_resolution_escalates method method test_no_policy_no_resolution_escalates L629–636
+ test_unrecorded_pattern_escalates method method test_unrecorded_pattern_escalates L652–657
+ TestTierExactReplay class class TestTierExactReplay L508–568
+ test_exact_replay_increments_applied_count method method test_exact_replay_increments_applied_count L543–554
+ test_exact_replay_prefers_highest_quality_resolution method method test_exact_replay_prefers_highest_quality_resolution L556–568
+ test_high_confidence_resolution_auto_applied method method test_high_confidence_resolution_auto_applied L511–519
+ test_human_verified_always_auto_applied method method test_human_verified_always_auto_applied L521–529
+ test_low_confidence_resolution_proposed method method test_low_confidence_resolution_proposed L531–541
+ TestTierPolicy class class TestTierPolicy L393–505
+ test_policy_below_threshold_returns_proposed method method test_policy_below_threshold_returns_proposed L424–433
+ test_policy_delegate_returns_escalated method method test_policy_delegate_returns_escalated L459–471
+ test_policy_domain_filter_does_not_fire_for_wrong_domain method method test_policy_domain_filter_does_not_fire_for_wrong_domain L473–483
+ test_policy_escalate_action_returns_escalated method method test_policy_escalate_action_returns_escalated L435–448
+ test_policy_prefer_ours_above_threshold_returns_applied method method test_policy_prefer_ours_above_threshold_returns_applied L396–410
+ test_policy_prefer_theirs_above_threshold_returns_applied method method test_policy_prefer_theirs_above_threshold_returns_applied L412–422
+ test_policy_require_human_returns_escalated method method test_policy_require_human_returns_escalated L450–457
+ test_workspace_policy_fires_before_repo_policy method method test_workspace_policy_fires_before_repo_policy L485–505
+ TestTierSemantic class class TestTierSemantic L571–623
+ test_custom_plugin_similarity_drives_semantic_match method method test_custom_plugin_similarity_drives_semantic_match L604–623
+ test_semantic_match_below_threshold_escalates method method test_semantic_match_below_threshold_escalates L592–602
+ test_semantic_match_returns_proposed method method test_semantic_match_returns_proposed L574–590
+ _fake_id function function _fake_id L69–70
+ _make_pattern function function _make_pattern L83–108
+ _make_policy function function _make_policy L140–166
+ _make_resolution function function _make_resolution L111–137
+ _utc_now function function _utc_now L73–74
+ AgentProvenance import import AgentProvenance L29–29
+ Any import import Any L22–22
+ AuditEventType import import AuditEventType L29–29
+ ConflictPattern import import ConflictPattern L29–29
+ ConflictType import import ConflictType L29–29
+ DefaultPlugin import import DefaultPlugin L53–53
+ EngineConfig import import EngineConfig L53–53
+ EngineResult import import EngineResult L53–53
+ EngineStatus import import EngineStatus L53–53
+ HarmonyPlugin import import HarmonyPlugin L53–53
+ Policy import import Policy L29–29
+ PolicyAction import import PolicyAction L29–29
+ PolicyCondition import import PolicyCondition L29–29
+ PolicyScope import import PolicyScope L29–29
+ Resolution import import Resolution L29–29
+ ResolutionProposal import import ResolutionProposal L29–29
+ ResolutionStrategy import import ResolutionStrategy L29–29
+ annotations import import annotations L15–15
+ append_audit import import append_audit L29–29
+ best_resolution import import best_resolution L29–29
+ blob_fingerprint import import blob_fingerprint L29–29
+ compute_pattern_id import import compute_pattern_id L29–29
+ compute_resolution_id import import compute_resolution_id L29–29
+ dataclasses class import dataclasses L17–17
+ datetime import import datetime L18–18
+ eng import import eng L28–28
+ find_similar import import find_similar L53–53
+ h import import h L27–27
+ hashlib import import hashlib L19–19
+ list_audit import import list_audit L29–29
+ list_patterns import import list_patterns L29–29
+ list_resolutions import import list_resolutions L29–29
+ mock import import mock L23–23
+ pathlib import import pathlib L20–20
+ pytest import import pytest L25–25
+ record_pattern import import record_pattern L29–29
+ resolve import import resolve L53–53
+ save_policy import import save_policy L29–29
+ save_resolution import import save_resolution L29–29
+ time import import time L21–21
+ repo function function repo L78–80
~ muse/cli/commands/harmony.py .py 10 symbols added, 1 symbol modified
+ _HarmonyEngineJson class class _HarmonyEngineJson L353–360
+ _HarmonyProposalJson class class _HarmonyProposalJson L339–350
+ _HarmonySimilarJson class class _HarmonySimilarJson L363–368
+ _fake_hex64 function function _fake_hex64 L1823–1826
+ _proposal_to_json function function _proposal_to_json L1706–1719
+ EngineConfig import import EngineConfig L184–184
+ _engine_find_similar import import _engine_find_similar L184–184
+ _engine_resolve import import _engine_resolve L184–184
+ run_engine function function run_engine L1722–1820
+ run_similar function function run_similar L1834–1908
~ muse/core/harmony.py .py 1 symbol modified
← Older Oldest on task/harmony-phase3
All commits
Newer → Latest on task/harmony-phase3

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