feat: add prune command to remove dangling overlay links - #6
Merged
Conversation
apply only ever creates or repoints symlinks; it never removes one. Deleting a file from an overlay entry after apply has already linked it leaves a dangling ghostq-managed symlink behind in every checkout that linked it — nothing in the CLI could clean that up. collectEntryFiles can't help here since it walks the overlay entry, and the whole point of a dangling link is that its overlay file is gone. prune instead walks the checkout tree directly (skipping .git) and, for each symlink found, checks whether it resolves inside this repo's overlay entry (proving it's ghostq's) but no longer exists on disk (proving it's dangling) — mirroring apply's no-clobber and check-ignore invariants so live links and user files are never touched. Empty parent directories left behind are removed too, but only ones that became empty as a result, never a directory that still holds other entries. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013mAzjNvVWGBJT81cfTSJJN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
applyonly ever creates or repoints symlinks — it never removes one.When a file is deleted from an overlay entry after
applyhas alreadylinked it into one or more checkouts, the symlink it created becomes a
dangling ghostq-managed link: it still points into this repo's
overlay entry, but the target no longer exists. Nothing in the CLI
could clean these up.
Approach
pruneFiles(insrc/apply.ts, following the "modules return data,index.tsprints" convention) walks the checkout tree directly,skipping
.git, rather than the overlay entry —collectEntryFilescan't help here since the overlay file behind a dangling link is, by
definition, already gone. For every symlink it finds, it checks two
things:
(
resolve(target).startsWith(resolve(ctx.entryDir) + "/")) — i.e.is it ghostq-managed?
Only links satisfying both are removed, and only after an additional
git check-ignoregate (mirroringapply's own gating) confirms thepath isn't committed. After removing a dangling link,
pruneopportunistically walks up removing now-empty parent directories, but
stops as soon as it hits a directory that still has other entries, and
never goes above the repo root.
Wired up as
ghostq prune [path], added toUSAGEinsrc/index.tsand to the usage block / a new safety note in
README.md.Safety guarantees
touched — that's
apply's job, notprune's.(user data) are never touched.
pruning; directories with other entries are left alone.
Test plan
bun test— 42 pass, including a newtest/prune.test.tsfilecovering: dangling link removal, live links left untouched, real
user files / symlinks-to-outside left untouched, empty-directory
cleanup vs. non-empty directories, and idempotency.
bun run typecheck— clean.ghostq apply→ delete overlay file →ghostq prune→ re-runpruneagainst a scratch repo; confirmed thedangling link is removed and the second run is a no-op.
🤖 Generated with Claude Code
https://claude.ai/code/session_013mAzjNvVWGBJT81cfTSJJN