Files
disktree/AGENTS.md
T
Sebastian Sieber cbdfe1c332 macOS support: native Trash, APFS-aware scans, a signed app bundle
disktree built and drew on macOS already, through GPUI's Metal backend,
but the Linux plumbing underneath did not carry over. This makes it work
well there, without unsafe code, and tightens removal safety for every
platform on the way.

Trash and removal
- On macOS always the system Trash, through NSFileManager (the trash
  crate): the same move as Finder's, into the item's own disk's Trash.
  gio/trash-put/XDG would put files in ~/.local/share/Trash, which Finder
  never shows.
- Refuse a directory holding the home directory (/Users is on the same
  volume as / on macOS) or a system tree (/opt holds /opt/homebrew); add
  /System, /Library, /private, /opt/homebrew, /cores, /Network.
- Refuse a directory with a mount inside it; on macOS the mount list comes
  from /sbin/mount, read on a background thread.
- Permanent deletion walks the tree itself and stops at a mount boundary,
  like rm -rf --one-file-system (the walker is from #10).
- Guards see through /System/Volumes/Data spellings and, on macOS, case.

Scanning
- Skip /System/Volumes/Data when scanning /: it is /Users, /Applications
  and the rest again under firmlinks, so / was counted twice.
- Whole disk (g, --disk) works: the disk root and device come from statfs.
- Never list cloud-only (dataless) iCloud/File Provider folders, which
  would download them.
- Keep a file's identity only when it has more than one name.

App
- Explain unreadable items when Full Disk Access is missing, with a button
  to the privacy settings.
- A menu bar: Open Folder… (⌘O), Show in Finder (o, ⌘⇧R), Rescan (⌘R),
  Hide, Quit; closing the window quits; other ⌘ chords are not read as
  plain letters; help shows ⌘.
- Follow the system light/dark appearance when no Omarchy theme exists.
- Worth a look knows Xcode DerivedData, DeviceSupport and ~/Library/Logs.
- git: skipped without the developer tools (its stub opens a dialog), and
  never runs a checkout's programs: fsmonitor, hooks and pager off, and no
  status for a checkout that defines its own filter drivers.

Packaging
- cargo xtask bundle builds disktree.app and a zip: Info.plist (bundle id
  io.github.tobi.disktree, macOS 11+), an icon drawn from an SVG on the
  macOS grid, ad-hoc or Developer ID signing, and --notarize.
- make install on macOS puts the app in ~/Applications and links
  ~/.local/bin/disktree to it.
- CI lints, tests and bundles on macOS; the release adds an arm64 macOS
  zip, signed and notarized when the repository has the Apple secrets.
2026-09-25 17:29:55 +08:00

6.0 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.

House rules

  • Strict lints from omatrack's style. clippy::all and clippy::pedantic are errors, clippy::nursery warns, and -D warnings promotes the rest. Every deliberate exception is listed with its reason in the workspace Cargo.toml or 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-core tests size accounting, layout and deletion guards against real temporary trees; disktree-app/src/tests.rs drives 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

  1. Sizes come from st_blocks * 512 unless apparent size was asked for. That is the number that comes back when a file is deleted.
  2. own_bytes/own_files are derived, never tracked. tree::aggregate computes the totals from the children. Hardlink de-duplication rewrites a leaf's weight and re-aggregates; anything that patches bytes directly will be overwritten.
  3. A directory is only built when its own scan and every subdirectory task has finished. That is the +1 sentinel in PendingDir::pending. Building early silently drops whole subtrees — it has happened once.
  4. Only paths under the scanned root may be removed, and mount points, the root, the home directory and symlink targets are refused.
  5. Marks are keyed by absolute path, not tree position, so they survive a re-scan; Marks::refresh re-reads their sizes and drops what is gone.
  6. 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.
  7. Tile crumbs are absolute. treemap::layout takes 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.
  8. The view transform is the only thing zoom changes. Layout runs in base-space pixels and is cached; screen = (base - origin) * scale.
  9. The status bar never claims a saving it cannot measure. Projections come from marked bytes; the final number comes from statvfs before 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
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-core tests 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.