cgcardona / muse public
gc.md markdown
72 lines 2.3 KB
e0353dfe feat: muse reflog, gc, archive, bisect, blame, worktree, workspace Gabriel Cardona <cgcardona@gmail.com> 7h ago
1 # `muse gc` — garbage-collect unreachable objects
2
3 Muse stores every tracked file as a content-addressed blob under `.muse/objects/`. Over time — after branch deletions, abandoned experiments, or squash merges — blobs that are no longer reachable from any live commit accumulate and waste disk space. `muse gc` identifies and removes them.
4
5 ## How it works
6
7 1. **Reachability walk**: Starting from every live branch head and tag, Muse walks the commit graph:
8 ```
9 branch HEAD → CommitRecord → SnapshotRecord → manifest → object SHA-256
10 ```
11 2. **Unreachable detection**: Any object *not* reachable from step 1 is garbage.
12 3. **Deletion** (if not `--dry-run`): Unreachable objects are deleted. Empty prefix directories are also cleaned up.
13
14 ## Usage
15
16 ```bash
17 muse gc # remove unreachable objects (safe default)
18 muse gc --dry-run # show what would be removed without touching anything
19 muse gc --verbose # print each removed object ID
20 ```
21
22 ## Options
23
24 | Flag | Default | Description |
25 |------|---------|-------------|
26 | `--dry-run`, `-n` | false | Preview only — no files are deleted |
27 | `--verbose`, `-v` | false | Print each collected object ID |
28
29 ## Output
30
31 ```
32 Removed 12 object(s) (48.3 KiB) in 0.031s [247 reachable]
33 ```
34
35 In `--dry-run` mode:
36
37 ```
38 [dry-run] Would remove 12 object(s) (48.3 KiB) in 0.028s [247 reachable]
39 ```
40
41 ## Safety guarantees
42
43 - The reachability walk always completes **before** any deletion begins.
44 - `--dry-run` is always safe to run — even in production, even by agents.
45 - GC never touches commit or snapshot records — only content blobs.
46 - Running GC is idempotent: running it twice produces the same result.
47
48 ## When to run
49
50 | Trigger | Recommendation |
51 |---------|---------------|
52 | After deleting branches | `muse gc` |
53 | Weekly CI maintenance | `muse gc --dry-run` to audit, then `muse gc` |
54 | Before `muse archive` | `muse gc` to shrink the repo |
55 | After a large squash merge | `muse gc` to free replaced blobs |
56
57 ## Agent workflows
58
59 ```bash
60 # Audit unreachable bloat before a deployment:
61 muse gc --dry-run
62
63 # Automated nightly cleanup:
64 muse gc 2>&1 | logger -t muse-gc
65 ```
66
67 ## Exit codes
68
69 | Code | Meaning |
70 |------|---------|
71 | 0 | Success (even if nothing was collected) |
72 | 1 | Internal error (corrupt store, permission issue) |