One set of removal guards for all three platforms: guard_key folds macOS firmlinks and case, and now Windows case and verbatim prefixes, so within/same from #14 become key comparisons. System trees are one keyed list per platform. Fixed while merging: - plan() found home through $HOME, which Windows does not set, so every home guard was off there; std::env::home_dir() instead. - Scan: #14's Listed/Facts shape with #13's never-scanned paths, dataless iCloud folders and track-only-shared-inodes; OneDrive cloud-only folders are skipped the same way on Windows. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
6.4 KiB
disktree — agent guide
A GPUI + gpui-omarchy treemap explorer for disk usage on Omarchy. Read
README.md for the product; this file is the working contract.
What this is
Find what is eating a volume, mark paths for removal, review the list, and remove it — with the volume's free space live on screen the whole time. Two phases: explore (treemap, breadcrumbs, the selection and status lines) and review (the marked list, the removal mode, the confirmation). Marking is never destructive.
Commands
make build # release build
make run # build and run, scanning $HOME
make install # ~/.local: binary, desktop entry, icon
make install PREFIX=/usr/local # system-wide (needs root)
make uninstall
make bundle # macOS: target/bundle/disktree.app and its zip
make lint # rustfmt --check, then clippy --all-targets -D warnings
make test # core and window-harness tests
make ci # lint, then test
make fmt # format in place
make install is the supported way to put this on a machine: it installs the
release binary, packaging/disktree.desktop.in (rendered with the real install
prefix and the crate version) and assets/disktree.svg. Keep the desktop
entry's Categories to a single main category plus additional ones, or
desktop-file-validate complains.
On macOS make install installs target/bundle/disktree.app into
~/Applications instead, built by cargo xtask bundle from
packaging/macos/ (the Info.plist template and the icon's SVG). The bundle
identifier there keys every macOS permission grant; do not change it lightly.
cargo xtask lint is the gate. It must be green before anything is called
done, and it must not fix anything: a red local run is the same signal CI gives.
On Windows, where there is no make, run cargo xtask lint, cargo xtask test
and cargo build --release directly; CI runs the gate on both systems.
House rules
- Strict lints from omatrack's style.
clippy::allandclippy::pedanticare errors,clippy::nurserywarns, and-D warningspromotes the rest. Every deliberate exception is listed with its reason in the workspaceCargo.tomlor as an#[allow(..., reason = "...")]on the item — never silently. - 80 columns, 4-space indent, by
rustfmt.toml. Only stable rustfmt options, because the gate runs on stable; unstable options would be ignored with a warning instead of applying. - Comments say why. The code says what. Any non-obvious number, ordering or boundary deserves the reason next to it.
- Tests live beside the promise they make.
disktree-coretests size accounting, layout and deletion guards against real temporary trees;disktree-app/src/tests.rsdrives the real window harness — draw a frame, press keys — so a screen that panics while painting fails a test. - Never delete anything outside a marked path. See
removal.rs; the guards are load-bearing and are covered by tests.
Invariants
- Sizes come from
st_blocks * 512unless apparent size was asked for. That is the number that comes back when a file is deleted. On Windows it is the allocation the directory listing reports; seewindows.rs. own_bytes/own_filesare derived, never tracked.tree::aggregatecomputes the totals from the children. Hardlink de-duplication rewrites a leaf's weight and re-aggregates; anything that patchesbytesdirectly will be overwritten.- A directory is only built when its own scan and every subdirectory task
has finished. That is the
+1sentinel inPendingDir::pending. Building early silently drops whole subtrees — it has happened once. - Only paths under the scanned root may be removed, and mount points, the root, the home directory, any directory holding it, and symlink targets are refused.
- Marks are keyed by absolute path, not tree position, so they survive a
re-scan;
Marks::refreshre-reads their sizes and drops what is gone. - The treemap is painted, not composed of elements. Thousands of rectangles belong in one canvas callback; labels are shaped there too so they clip to their own tile.
- Tile crumbs are absolute.
treemap::layouttakes the drawn node's crumbs and every tile extends them, so a tile resolves from the scanned root at any depth. Relative crumbs look right at~and silently point at other directories after descending — including for marks. Any code that turns a path into crumbs walks from the scanned root, too. - The view transform is the only thing zoom changes. Layout runs in
base-space pixels and is cached;
screen = (base - origin) * scale. - The status bar never claims a saving it cannot measure. Projections come
from marked bytes; the final number comes from
statvfsbefore and after.
Where changes belong
| change | where |
|---|---|
| measurement, filtering, parallelism | crates/disktree-core/src/scan.rs |
| what a node is, or a derived total | crates/disktree-core/src/tree.rs |
| tile geometry, nesting, the merged tail | crates/disktree-core/src/treemap.rs |
| anything that deletes, or refuses to | crates/disktree-core/src/removal.rs |
| free space and projections | crates/disktree-core/src/space.rs |
| what Windows lists, measures and compares differently | crates/disktree-core/src/windows.rs — the only unsafe |
| a key, a screen transition, a mark | crates/disktree-app/src/state.rs |
| spacing, type and size | crates/disktree-app/src/ui.rs — tokens only, no px in layout |
| the mosaic's painting or labels | crates/disktree-app/src/treemap_view.rs |
| layout of a screen | crates/disktree-app/src/views.rs |
| colours derived from the theme | crates/disktree-app/src/palette.rs |
Verification expectations
- Size accounting, hardlinks, symlinks, hidden entries, depth limits, the
removal guards and squarified layout are covered by
disktree-coretests against real temporary trees. - The screens are covered by window-harness tests that draw frames and press keys, including one that marks a directory, confirms the removal and checks the files are gone while unmarked neighbours are untouched.
- Rendering was verified by those tests and by running the app against a real home directory; it has not been eyeballed in every theme and font size.