Replies: 3 comments 2 replies
|
@hhh2210 Thanks for working the design out before writing code, and for reading the purge internals first. I want the git worktree half, not the scratch path half. And the worktree half is simpler than you framed it. You proposed breaking the "must not be a direct child of the search root" rule. You don't need to. That rule exists because a top-level directory carries no authority saying it is reproducible; all purge has for So the authorization comes from the git registration, not from the path. No Two corrections, since your safety design rests on both: Your three guards also need a fourth: staleness. A worktree can be clean, fully pushed and remote-backed and still be where I am working right now, and I had exactly that on this machine today. Take the age from git rather than Not taking the scratch path mode. Your real weight, You are right about one thing separately: purge undercounts inside checkouts. A 789 MB agent worktree here reclaims nothing, because 394 MB of it is Jekyll's Send the worktree PR and I will review it. No objection to shelling out to |
|
One thing to know before you open it. Short version. Reasons (2) and (4) name failure modes this implementation does not have: nothing looks at merge state or deleted remote branches, and the unpushed check uses the per-worktree Reason (3) is the real one, and your own sentence names the fix: a whitelist check against So it is five independently provable negatives rather than a positive verdict. I am not claiming staleness is decidable in general. Your All three constraints from your second comment are implemented with tests. If the rule still stands after you have read it, say so and I will re-cut this as the blockers-only column it permits. |
|
@hhh2210 closing the loop here after PR #1289. The later safety rule stands: Mole will not delete whole git worktrees or label them safe to delete, because repository-local Git configuration can hide state and pruning can affect registrations the user did not select.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi @tw93 — floating a design idea before writing code, per the contributing flow.
Problem
AI coding agents now create git worktrees and throwaway clones at a high rate, and they pile up as multi-GB dead weight that
mo purgecan't currently reclaim. On my machine a single scratch dir held 27 GB, almost all of it:<repo>/.claude/worktrees/agent-*, Codex CLI →<repo>/.codex/worktrees/*, opencode →$TMPDIR/opencode/*, plus hand-made ones under a scratch dir.foo-proof/frozen-home/(3.6 GB),bar-build/out/(2 GB). Not matched byMOLE_PURGE_TARGETS, so purge never sees them.Two gaps in today's
purge(I readlib/clean/project.sh):git worktree list→prunable). I found 29 dead registrations in one repo.rmis the wrong tool here — it needsgit worktree remove/prune.The architectural question (up front)
I read
lib/clean/project.sh.is_safe_project_artifactenforces a deliberate invariant: purge only removes known-named artifacts nested inside a detected project, and explicitly "must not be a direct child of the search root". That's the right safety model fornode_modules/.build.But AI-agent scratch is the opposite shape: the GB-scale dead weight is whole top-level entries — worktree checkouts, and custom-named build/proof trees (
frozen-home/3.6 GB,out/2 GB) that don't matchPURGE_TARGETS. Reclaiming them means removing top-level entries under a search root, which today's purge deliberately refuses.So this is a scope decision only you can make: is there room for an opt-in, per-path mode that removes whole top-level entries under paths the user explicitly designates as scratch — or should this live outside purge's nested-only model entirely (separate verb, or Mole Mac)?
Proposed solution (opt-in, config-gated) — if you're open to it
A scratch mode for
purge, active only on paths the user explicitly marks as scratch in~/.config/mole/purge_paths(never a default root), presented through purge's existing list → confirm flow:MIN_AGE_DAYS), offer the whole entry for removal.mole_deletefunnel (Trash routing, oplog, path protection — no second delete path), thengit worktree prunethe parent so no dangling registration is left. Also GC already-dead registrations found during discovery.Safety design (the crux)
--dry-rundefault, same as purge today;mole_deletefor all removals, never rawrm -rf.git status --porcelain), has unpushed commits on HEAD (git log --not --remotes HEAD), or has no remote..keepsentinel, plus existing whitelist andCACHEDIR.TAGrespect.purge_paths— no new default scan roots..metadata_never_index-excluded dir into~/.Trashre-exposes it to indexing (I hit a reproduciblemds_storesCPU storm). For excluded scratch paths, permanent-delete is safer than trashing — worth a flag.Questions for you
mo purge --scratchflag, a per-path mode inpurge_paths, or a separate subcommand?purge's scope, or would you rather keep purge to artifact sub-dirs and put this behind an explicit new verb?git worktreefrom the purge path?Happy to send a draft PR once the shape is agreed.
All reactions