Skip to content

feat(sidebar): a cleaner for worktrees and old sessions - #58

Merged
viktorvillalobos merged 1 commit into
mainfrom
feature/clean/worktrees
Oct 19, 2026
Merged

viktorvillalobos merged 1 commit into
mainfrom
feature/clean/worktrees

Conversation

@viktorvillalobos

Copy link
Copy Markdown
Contributor

What

A cleaner for worktrees and old sessions. A broom beside the project filter (or Clean up worktrees and old sessions… in the palette) opens an overlay with two lists.

Worktrees: every linked worktree of every project, with:

  • what it weighs on disk, and how much of that is build output (node_modules, target, .venv, dist…)
  • how many sessions ran in it and when the last one did
  • why it is suggested, or what keeps it

A worktree is suggested when removing it loses nothing and its pull request is merged or nobody worked in it for 14 days. "Loses nothing" uses the same rules as Remove merged worktrees… (leon_core::cleanup::blockers): no changes, no unpushed commits, nothing running, its checkout read. The other worktrees are listed with the reason and cannot be ticked.

The chips filter the list (all, suggested, merged, idle, kept), the field filters it by project, branch or folder, and the list can be ordered by size, idle time or name. The footer says how much the ticked worktrees free. Removing goes through Shell::remove_worktrees: git worktree remove, one at a time, never forced, and the branches stay.

Old sessions: the sessions of the history untouched for 7, 30 or 90 days that are not pinned, running or on a shelf. SETTLE puts them on the Settled shelf; nothing is deleted.

Keys: up and down move, Enter ticks, Shift+Enter cleans, Tab switches the list. Anything else typed goes to the filter.

How

  • crates/app/src/ui/sweep.rs: the rules, as pure functions with tests (candidates, visible, suggested, ticked, old_sessions).
  • crates/app/src/ui/sweep_view.rs: the overlay (Overlay::Cleanup), its keys and its actions.
  • crates/app/src/disk.rs and Engine::measure_folder: on this computer the folder is walked; on other machines du -sk is asked and parsed. Every worktree is measured in the background when the overlay opens.
  • Command::CleanUp is added to the registry, with no chord. The README and ARCHITECTURE describe it.

Tested

  • scripts/check.sh passes on Linux (Omarchy/Hyprland), including the simulated Windows runs. After it ran I changed the text of the activity column; cargo clippy -p leon --all-targets -D warnings, cargo fmt --check and the cleaner's tests pass with that change.
  • New tests: the sweep and disk units (rules, du parsing, the local walk) and tests_sweep.rs (the broom and the palette open it, Escape closes it, a worktree nobody read cannot be ticked, typing filters, Tab switches the list).
  • Checked visually with the scripts/media rig on the demo workspace (screenshots of both lists). The REMOVE and SETTLE buttons were not pressed there; they reuse paths that already have tests.

A broom beside the project filter (and "Clean up worktrees and old
sessions…" in the palette) opens an overlay that lists every linked
worktree with what it weighs on disk and how much of that is build
output, how many sessions ran in it and when the last one did.

A worktree is suggested when removing it loses nothing (no changes, no
unpushed commits, nothing running, its checkout read) and its pull
request is merged or nobody worked in it for 14 days; the others are
listed with what keeps them and cannot be ticked. Chips filter the list,
the field filters by project, branch or folder, and it orders by size,
idle time or name. Removing goes through the same path as "Remove merged
worktrees": git worktree remove, one at a time, never forced.

A second list has the sessions of the history untouched for 7, 30 or 90
days that are not pinned, running or shelved; the cleaner settles them,
it never deletes them.

Sizes are measured in the background when the overlay opens: walked on
this computer, asked of du on other machines (disk.rs). The rules are
pure functions with tests (ui/sweep.rs).
@viktorvillalobos
viktorvillalobos marked this pull request as ready for review October 19, 2026 02:11
@viktorvillalobos
viktorvillalobos merged commit 6e27747 into main Oct 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant