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

feat(harmony): code domain plugin — normalized token-bag fingerprint + Tanimoto similarity

- muse/core/plugins/code_harmony.py: CodePlugin (HarmonyPlugin Protocol), code_fingerprint() (Python tokenize + regex fallback, sorted token-bag), Tanimoto coefficient on token multisets, 512 KiB input guard - muse/core/harmony.py: _validate_fingerprint() (non-empty, no null bytes, ≤4 KiB) replacing hex64 requirement for semantic_fingerprint field - harmony CLI: --semantic-fingerprint now accepts any valid fingerprint string (token-bag or hex64) — no breaking change for existing callers - 548/548 tests green

sha256:507c3a1973c87fec6ce0deff8bcb4dcb540bd31829800b3dc7f2955329a76b19 sha
+120 ~37 symbols
sha256:5a5fc012c5452d1af12ba1220dfd851b6357d63111f26777525e82d65e1739e6 snapshot
+120
symbols added
~37
symbols modified
0
dead code introduced
Semantic Changes 157 symbols
~ muse/core/plugins/code_harmony.py .py 14 symbols added
+ CodePlugin class class CodePlugin L246–286
+ similarity method method similarity L263–286
+ _MAX_SOURCE_BYTES variable variable _MAX_SOURCE_BYTES L111–111
+ _SKIP_TYPES variable variable _SKIP_TYPES L168–176
+ _TOKEN_RE variable variable _TOKEN_RE L120–129
+ _tokenize_fallback function function _tokenize_fallback L132–160
+ _tokenize_python function function _tokenize_python L179–205
+ code_fingerprint function function code_fingerprint L213–243
+ Counter import import Counter L103–103
+ annotations import import annotations L97–97
+ io import import io L99–99
+ keyword import import keyword L100–100
+ re import import re L101–101
+ tokenize import import tokenize L102–102
~ tests/test_code_harmony_plugin.py .py 103 symbols added
+ TestCliFingerprint class class TestCliFingerprint L612–664
+ test_cli_accepts_code_fingerprint_as_semantic method method test_cli_accepts_code_fingerprint_as_semantic L639–664
+ test_validate_fingerprint_accepts_hex64 method method test_validate_fingerprint_accepts_hex64 L620–622
+ test_validate_fingerprint_accepts_token_string method method test_validate_fingerprint_accepts_token_string L615–618
+ test_validate_fingerprint_rejects_empty method method test_validate_fingerprint_rejects_empty L624–627
+ test_validate_fingerprint_rejects_null_byte method method test_validate_fingerprint_rejects_null_byte L629–632
+ test_validate_fingerprint_rejects_oversized method method test_validate_fingerprint_rejects_oversized L634–637
+ TestCodeFingerprintDeterminism class class TestCodeFingerprintDeterminism L195–215
+ test_deterministic_same_call method method test_deterministic_same_call L198–200
+ test_extra_blank_lines_irrelevant method method test_extra_blank_lines_irrelevant L207–210
+ test_indentation_irrelevant method method test_indentation_irrelevant L202–205
+ test_output_is_sorted method method test_output_is_sorted L212–215
+ TestCodeFingerprintNormalization class class TestCodeFingerprintNormalization L143–192
+ test_class_keyword_preserved class method test_class_keyword_preserved L171–174
+ test_comments_stripped method method test_comments_stripped L180–183
+ test_identifiers_become_ID method method test_identifiers_become_ID L146–150
+ test_import_keyword_preserved method method test_import_keyword_preserved L176–178
+ test_keywords_preserved method method test_keywords_preserved L166–169
+ test_numbers_become_NUM method method test_numbers_become_NUM L152–155
+ test_operators_preserved method method test_operators_preserved L185–187
+ test_parens_preserved method method test_parens_preserved L189–192
+ test_single_quoted_strings_become_STR method method test_single_quoted_strings_become_STR L162–164
+ test_string_literals_become_STR method method test_string_literals_become_STR L157–160
+ TestCodeFingerprintShape class class TestCodeFingerprintShape L120–140
+ test_comment_only_returns_empty method method test_comment_only_returns_empty L135–136
+ test_empty_source_returns_empty method method test_empty_source_returns_empty L129–130
+ test_non_empty_for_real_code method method test_non_empty_for_real_code L126–127
+ test_returns_string method method test_returns_string L123–124
+ test_tokens_are_space_separated method method test_tokens_are_space_separated L138–140
+ test_whitespace_only_returns_empty method method test_whitespace_only_returns_empty L132–133
+ TestCodePluginDifferent class class TestCodePluginDifferent L276–299
+ test_completely_different_low method method test_completely_different_low L284–294
+ test_function_vs_class_low class method test_function_vs_class_low L279–282
+ test_import_vs_class_low class method test_import_vs_class_low L296–299
+ TestCodePluginEdgeCases class class TestCodePluginEdgeCases L302–322
+ test_both_empty_returns_1 method method test_both_empty_returns_1 L305–306
+ test_one_empty_returns_0 method method test_one_empty_returns_0 L308–311
+ test_returns_float method method test_returns_float L319–322
+ test_single_token_different method method test_single_token_different L316–317
+ test_single_token_identical method method test_single_token_identical L313–314
+ TestCodePluginIdentical class class TestCodePluginIdentical L223–245
+ test_identical_source_is_1 method method test_identical_source_is_1 L226–229
+ test_same_assignment_different_names_high method method test_same_assignment_different_names_high L242–245
+ test_same_import_different_module_is_1 method method test_same_import_different_module_is_1 L237–240
+ test_same_structure_different_names_is_1 method method test_same_structure_different_names_is_1 L231–235
+ TestCodePluginSimilar class class TestCodePluginSimilar L248–273
+ test_added_docstring method method test_added_docstring L269–273
+ test_added_return_type_annotation method method test_added_return_type_annotation L263–267
+ test_function_vs_method method method test_function_vs_method L257–261
+ test_same_function_extra_parameter method method test_same_function_extra_parameter L251–255
+ TestDataIntegrity class class TestDataIntegrity L454–500
+ test_fingerprint_deterministic_across_calls method method test_fingerprint_deterministic_across_calls L476–479
+ test_fingerprint_is_sorted method method test_fingerprint_is_sorted L496–500
+ test_protocol_conformance method method test_protocol_conformance L490–494
+ test_self_similarity_is_1 method method test_self_similarity_is_1 L481–488
+ test_similarity_always_in_01 method method test_similarity_always_in_01 L463–474
+ test_similarity_symmetric method method test_similarity_symmetric L457–461
+ TestEndToEnd class class TestEndToEnd L330–399
+ test_code_plugin_satisfies_harmony_plugin_protocol method method test_code_plugin_satisfies_harmony_plugin_protocol L376–378
+ test_dissimilar_patterns_not_proposed method method test_dissimilar_patterns_not_proposed L359–374
+ test_engine_finds_similar_code_patterns method method test_engine_finds_similar_code_patterns L333–357
+ test_partial_match_above_threshold_proposed method method test_partial_match_above_threshold_proposed L380–399
+ TestPerformance class class TestPerformance L551–604
+ test_find_similar_20_patterns_under_100ms method method test_find_similar_20_patterns_under_100ms L587–604
+ test_fingerprint_100_functions_under_100ms method method test_fingerprint_100_functions_under_100ms L569–577
+ test_fingerprint_typical_function_under_10ms method method test_fingerprint_typical_function_under_10ms L554–567
+ test_similarity_under_1ms method method test_similarity_under_1ms L579–585
+ TestSecurity class class TestSecurity L508–543
+ test_binary_looking_text_does_not_raise method method test_binary_looking_text_does_not_raise L520–523
+ test_malformed_python_does_not_raise method method test_malformed_python_does_not_raise L511–514
+ test_null_bytes_handled method method test_null_bytes_handled L531–533
+ test_similarity_with_garbage_strings method method test_similarity_with_garbage_strings L540–543
+ test_unclosed_string_does_not_raise method method test_unclosed_string_does_not_raise L516–518
+ test_unicode_identifiers_handled method method test_unicode_identifiers_handled L535–538
+ test_very_large_input_does_not_oom method method test_very_large_input_does_not_oom L525–529
+ TestStress class class TestStress L407–446
+ test_find_similar_50_patterns method method test_find_similar_50_patterns L431–446
+ test_fingerprint_500_line_file method method test_fingerprint_500_line_file L410–420
+ test_similarity_of_large_fingerprints method method test_similarity_of_large_fingerprints L422–429
+ _fake_id function function _fake_id L60–61
+ _make_pattern function function _make_pattern L74–96
+ _make_resolution function function _make_resolution L99–112
+ _utc_now function function _utc_now L64–65
+ AgentProvenance import import AgentProvenance L40–40
+ CodePlugin import import CodePlugin L52–52
+ ConflictPattern import import ConflictPattern L40–40
+ EngineConfig import import EngineConfig L51–51
+ Resolution import import Resolution L40–40
+ ResolutionStrategy import import ResolutionStrategy L40–40
+ annotations import import annotations L31–31
+ best_resolution import import best_resolution L40–40
+ blob_fingerprint import import blob_fingerprint L40–40
+ code_fingerprint import import code_fingerprint L52–52
+ compute_pattern_id import import compute_pattern_id L40–40
+ datetime import import datetime L33–33
+ find_similar import import find_similar L51–51
+ hashlib import import hashlib L34–34
+ pathlib import import pathlib L35–35
+ pytest import import pytest L38–38
+ record_pattern import import record_pattern L40–40
+ save_resolution import import save_resolution L40–40
+ time import import time L36–36
+ repo function function repo L69–71
~ muse/core/harmony.py .py 2 symbols added
+ _MAX_FINGERPRINT_BYTES variable variable _MAX_FINGERPRINT_BYTES L128–128
+ _validate_fingerprint function function _validate_fingerprint L621–648
← Older Oldest on task/code-harmony-plugin
All commits
Newer → Latest on task/code-harmony-plugin

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