gabriel / muse public
refactor BREAKING core task/blob-id-hash-file #1 / 1
AI Agent gabriel · 161 days ago · Apr 18, 2026 · Diff

refactor(core): add blob_id() and hash_file() to _types.py, wire into call sites

- Add blob_id(data: bytes) -> str — long_id(sha256(data)) for raw bytes - Add hash_file(path, chunk_size=65536) -> str — streaming file hasher - Both live in _types.py alongside content_hash(); one canonical location for all three SHA-256 ID-derivation patterns - Add 15 new tests in test_core_types.py (blob_id × 7, hash_file × 8) - Document that blob_id(canonical_json_bytes) == content_hash(obj)

Call sites wired (removes ~20 inline long_id/hashlib patterns): snapshot.py — delete local hash_file(); replace 2× blob_id payloads object_store.py — 3× hash_file() for integrity checks; 1× blob_id() workdir.py — inline streaming hash → hash_file() stat_cache.py — _hash_bytes/_hash_str delegate to hash_file() code/plugin.py — delete local _hash_file(); 2× blob_id(merged_bytes) bundle.py — 2× blob_id(raw) for bundle verification verify_pack.py — blob_id(content) for pack integrity check hash_object.py — _hash_bytes() delegates to blob_id() range_diff.py — blob_id(commit_id.encode()) fallback patch ID

Stale hashlib imports removed from all converted files.

sha256:1b890982bd2d008c676dff4daf9d6c38be433878c005d7737a76dc21a8acee00 sha
+35 ~30 −17 symbols
sha256:3d88f100c1533a3b7c2f6bba217ed2b8cdfea4b1c12fb90bfc06f86121ca4cbe snapshot
+35
symbols added
~30
symbols modified
−17
symbols removed
0
dead code introduced
Semantic Changes 82 symbols
~ muse/cli/commands/bundle.py .py 1 symbol added, 2 symbols removed, 3 symbols modified
− hashlib import import hashlib L59–59
− long_id import import long_id L71–71
+ blob_id import import blob_id L70–70
~ muse/cli/commands/hash_object.py .py 1 symbol added, 2 symbols removed, 1 symbol modified
− hashlib import import hashlib L34–34
− long_id import import long_id L41–41
+ blob_id import import blob_id L40–40
~ muse/cli/commands/range_diff.py .py 1 symbol added, 1 symbol removed, 4 symbols modified
− hashlib import import hashlib L83–83
+ blob_id import import blob_id L102–102
~ muse/cli/commands/verify_pack.py .py 1 symbol added, 2 symbols removed, 2 symbols modified
− hashlib import import hashlib L85–85
− long_id import import long_id L93–93
+ blob_id import import blob_id L92–92
~ run
~ muse/core/_types.py .py 3 symbols added
+ blob_id function function blob_id L118–136
+ hash_file function function hash_file L139–162
+ pathlib import import pathlib L11–11
~ muse/core/object_store.py .py 2 symbols added, 5 symbols modified
+ blob_id import import blob_id L55–55
+ hash_file import import hash_file L55–55
~ muse/core/snapshot.py .py 2 symbols added, 3 symbols removed, 3 symbols modified
− hash_file function function hash_file L176–185
− hashlib import import hashlib L54–54
− long_id import import long_id L61–61
+ blob_id import import blob_id L60–60
+ hash_file import import hash_file L60–60
~ muse/core/stat_cache.py .py 1 symbol added, 2 symbols removed, 3 symbols modified
− _CHUNK variable variable _CHUNK L90–90
− hashlib import import hashlib L72–72
+ hash_file import import hash_file L80–80
~ muse/core/workdir.py .py 1 symbol added, 2 symbols removed, 2 symbols modified
− hashlib import import hashlib L11–11
− long_id import import long_id L19–19
+ hash_file import import hash_file L18–18
~ muse/plugins/code/plugin.py .py 2 symbols added, 3 symbols removed, 4 symbols modified
− _hash_file function function _hash_file L1260–1266
− hashlib import import hashlib L86–86
− long_id import import long_id L104–104
+ blob_id import import blob_id L103–103
+ hash_file import import hash_file L103–103
~ merge
~ tests/test_core_types.py .py 20 symbols added, 3 symbols modified
+ TestBlobId class class TestBlobId L143–178
+ test_deterministic method method test_deterministic L151–153
+ test_differs_for_different_bytes method method test_differs_for_different_bytes L155–156
+ test_empty_bytes method method test_empty_bytes L163–166
+ test_large_payload method method test_large_payload L168–172
+ test_matches_manual_sha256 method method test_matches_manual_sha256 L158–161
+ test_relationship_with_content_hash method method test_relationship_with_content_hash L174–178
+ test_returns_sha256_prefixed_id method method test_returns_sha256_prefixed_id L146–149
+ TestHashFile class class TestHashFile L186–238
+ test_custom_chunk_size method method test_custom_chunk_size L233–238
+ test_deterministic method method test_deterministic L214–217
+ test_differs_for_different_content method method test_differs_for_different_content L219–224
+ test_empty_file method method test_empty_file L209–212
+ test_matches_blob_id_for_large_file method method test_matches_blob_id_for_large_file L202–207
+ test_matches_blob_id_for_small_file method method test_matches_blob_id_for_small_file L196–200
+ test_matches_manual_sha256 method method test_matches_manual_sha256 L226–231
+ test_returns_sha256_prefixed_id method method test_returns_sha256_prefixed_id L189–194
+ blob_id import import blob_id L11–11
+ hash_file import import hash_file L11–11
+ pathlib import import pathlib L7–7
← Older Oldest on task/blob-id-hash-file
All commits
Newer → Latest on task/blob-id-hash-file

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