gabriel / muse public
feat patch feat/53-symlog-prune-orphans #1 / 1
AI Agent gabriel · 1 day ago · Oct 22, 2026 · Diff

feat: muse#53 item 12 — muse symlog prune-orphans

Adds `muse symlog prune-orphans [--dry-run] [--json]`: finds and removes symlog journals whose symbol no longer exists at HEAD — the file was deleted/renamed away, or the symbol was removed from a file that still exists. Journals are append-only and never auto-deleted on symbol removal, so without this they'd accumulate indefinitely after large-scale renames/deletions. Analogous to `muse gc` for unreachable objects.

Core additions in muse/core/symlog.py: - `_symbol_exists_in_head()`: walks HEAD commit -> snapshot manifest -> file object -> extract_symbols(), returning False (never raising) on any failure along the way, matching extract_symbols()'s own fail-silent contract. - `find_orphan_symlogs()`: filters list_symlog_symbols() by the above. - `prune_orphan_symlogs(dry_run=...)`: reuses the existing, already- tested delete_symlog_entry(addr, index=None) for the actual removal rather than reimplementing file deletion.

Covered by tests/test_cmd_symlog_prune_orphans.py (4 cases: clean repo reports zero orphans and leaves the live journal intact, a symbol removed from a surviving file is pruned while the sibling symbol's journal is untouched, a deleted file's symbol is pruned, --dry-run reports without deleting). Confirmed genuine RED by reverting both changed files and re-running (all 4 failed with JSONDecodeError, since 'prune-orphans' wasn't a recognized dispatch keyword), then GREEN with the fix restored plus the full symlog regression suite (233 tests, zero regressions). Live-verified via muse-dev against a disposable /tmp sandbox (dry-run then real prune correctly left compute_total's journal intact while removing apply_discount's).

Co-Authored-By: Claude Sonnet 5 <[email protected]>

sha256:986277e88b9de700cfb77ed3385e7b344df08fbb801c9615906da7df9c45c91d sha
+24 ~16 symbols
4 changed · 1235 in snapshot files
sha256:368cdb727888f0eafe19920c8785d91969ac4398af4dc50858d8af2bf692c31d snapshot
+24
symbols added
~16
symbols modified
4
files changed
1235
files in snapshot
0
dead code introduced
Semantic Changes 40 symbols
+ TestPruneOrphans class class TestPruneOrphans L61–131
+ test_dry_run_does_not_delete method method test_dry_run_does_not_delete L114–131
+ test_no_orphans_in_clean_repo method method test_no_orphans_in_clean_repo L62–75
+ test_orphan_from_deleted_file_is_pruned method method test_orphan_from_deleted_file_is_pruned L101–112
+ test_orphan_from_deleted_symbol_is_pruned method method test_orphan_from_deleted_symbol_is_pruned L77–99
+ _commit function function _commit L39–49
+ _init_repo function function _init_repo L28–30
+ _invoke function function _invoke L19–25
+ _make_repo function function _make_repo L52–54
+ _symlog function function _symlog L57–58
+ _write_file function function _write_file L33–36
+ CliRunner import import CliRunner L14–14
+ annotations import import annotations L7–7
+ json import import json L9–9
+ os import import os L10–10
+ pathlib import import pathlib L11–11
+ textwrap import import textwrap L12–12
+ runner variable variable runner L16–16
~ muse/cli/commands/symlog.py .py 3 symbols added, 13 symbols modified
+ _PruneOrphansJson class class _PruneOrphansJson L162–167
+ prune_orphan_symlogs import import prune_orphan_symlogs L84–84
+ run_prune_orphans function function run_prune_orphans L749–797
~ run
~ muse/core/symlog.py .py 3 symbols added
+ _symbol_exists_in_head function function _symbol_exists_in_head L687–720
+ find_orphan_symlogs function function find_orphan_symlogs L723–734
+ prune_orphan_symlogs function function prune_orphan_symlogs L737–760
Files Changed
+1 ~3
1235 in snapshot
← Older Oldest on feat/53-symlog-prune-orphans
All commits
Newer → Latest on feat/53-symlog-prune-orphans

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