A treemap for finding and removing what fills your disk, for Omarchy. Rust + GPUI.
Rust
app: harden source selection and verify chooser lifecycle
Tobi Lutke6a234aa4c3a3
diff --git a/AGENTS.md b/AGENTS.mdindex a567ce8..03416ac 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -7,14 +7,15 @@ A GPUI + gpui-omarchy treemap explorer for disk usage on Omarchy. ReadFind what is eating a volume, mark paths for removal, review the list, andremove 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,+phases after choosing a local/SSH source and root: explore (treemap,+breadcrumbs, selection and status) and review (the marked list,the removal mode, the confirmation). Marking is never destructive.## Commands```shmake build # release build-make run # build and run, scanning $HOME+make run # build and open the source/root choosermake install # ~/.local: binary, desktop entry, iconmake install PREFIX=/usr/local # system-wide (needs root)make uninstall@@ -107,10 +108,18 @@ and `cargo build --release` directly; CI runs the gate on both systems.added to this volume's free space; see `space::attribution`. The final numbercomes from `statvfs` before and after.+10. **Discovery is not a scan.** No implicit home walk at startup. List+ mounts in the selected machine's namespace without probing them; scans+ stop at nested mounts, including bind mounts and same-device subvolumes.+ Switching machines clears marks and identity. The Unix SSH helper streams+ records and never retains the tree.+## Where changes belong| change | where || --- | --- |+| bounded Unix SSH traversal | `crates/disktree-core/src/remote_walk.rs` |+| SSH protocol, discovery and transport | `crates/disktree-core/src/remote.rs` || 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` |diff --git a/Makefile b/Makefileindex 5b7a410..75fc361 100644--- a/Makefile+++ b/Makefile@@ -53,7 +53,7 @@ help:@echo "disktree"@echo@echo " make build release build"- @echo " make run build and run, scanning $$HOME"+ @echo " make run build and open the source/root chooser"@echo " make install-scan build/install the headless SSH helper only"@echo " make install install to $(PREFIX): binary, desktop entry, icon"@echo " (macOS: disktree.app into $(APPS))"diff --git a/README.md b/README.mdindex 02526bb..738411b 100644--- a/README.md+++ b/README.md@@ -5,8 +5,9 @@Find what is filling a disk, mark what should go, and remove it — with thevolume's free space in view the whole time.-disktree is a treemap for Omarchy. It scans your home directory by default,-draws every directory as a nested mosaic sized by what it really costs on disk,+disktree is a treemap for Omarchy. Choose a local or SSH source, then a+mounted volume or directory; no scan starts until you explicitly accept.+It draws every directory as a nested mosaic sized by its real disk cost,and lets you walk into it with the keyboard or the mouse. Mark as much as youlike; nothing happens until you review the list and commit, and the permanentpath always asks first.@@ -138,7 +139,8 @@ See [On Windows](#on-windows) for what differs there.## Use```sh-disktree # scan the home directory+disktree # choose a local/SSH source and root+disktree ~ # explicitly scan homedisktree --disk # the whole disk it lives ondisktree ~/src # or any directorydisktree --help # options: apparent size, follow links, skip hidden, …@@ -147,7 +149,7 @@ disktree --help # options: apparent size, follow links, skip hidden, …### Servers over SSH (read-only)```sh-disktree ssh dev # remote home; dev is an SSH config alias+disktree ssh dev # connect and choose a remote rootdisktree ssh user@server /var # an explicit remote pathdisktree ssh dev --disk # the disk containing the remote homedisktree ssh dev -a /srv # apparent size instead of allocated blocks@@ -243,7 +245,7 @@ There are no trash/delete buttons or removal-mode choices in remote review.Deletion shortcuts and removal entry points are disabled too. Git inspection,local folder selection and file-manager reveal are disabled so remote namescannot accidentally act on this computer. Free space is sampled when the-scan completes, **not live**; press `r` to refresh.+scan starts, **not live**; press `r` to refresh.Before deleting, scripts compare the server's actual kernel hostname andmachine ID against the identity captured in the scan—not the SSH alias.@@ -349,7 +351,7 @@ and shows how much free space was actually gained.| `i` | include or skip hidden entries || `r` | scan again || `esc` while scanning | stop the scan |-| `v` | scan another mounted volume |+| `v` | choose a local/SSH source and root || `ctrl o` (`⌘O` on macOS) | choose another directory to scan || `g` | the whole disk || `p` | show or hide the selection line |@@ -393,14 +395,31 @@ scope per root, a completion counter per directory so no directory is builtbefore its last subdirectory lands, and one bottom-up pass that aggregates sizesand removes duplicate hardlinks.-## Switching volumes+## Choosing sources and roots-Press `v` (or click **Volumes** beside the disk name in the side panel) to-bring up the volume picker. It lists every candidate volume mounted on the-system together with its free space, ordered fullest first, filtering out-pseudo-filesystems and snapshots. Linux bind mounts and btrfs subvolumes-remain separately selectable, even when they share a device. Selecting any-entry resets the scan root directly to that volume.+Launch without a path to choose **This computer** or enter an SSH alias /+`user@host` and press **Connect SSH**. Discovery reads that machine's mount+namespace, not file contents. It never starts a scan or probes mounted+network filesystems just to fill the list.++Select a mount and choose **Scan selected root**, or enter an absolute+directory path and choose **Scan directory**. Enter acts on the focused+host/path field or the highlighted mount. Escape cancels discovery and+returns to the current scan, or the idle welcome screen at startup.++During exploration, press `v`, click **Source…** beside the disk name,+or click the disktree logo to reopen the same chooser. The source being+browsed is shown explicitly, and connecting never retargets an existing+scan. Changing machines on acceptance clears the old machine's marks,+identity and navigation history; an absolute path is not an identity+across hosts. A rescan that detects a changed or lost remote machine+identity also clears marks, even if the SSH alias is unchanged.++Pseudo-filesystems, snapshots and automount triggers are filtered out.+Linux bind mounts and btrfs subvolumes remain individually selectable,+even when they share a device. Free space is measured only after choosing+a root. Explicit command-line paths and `--disk` still start directly;+`ssh HOST --check [PATH]` remains the headless scan command.## The whole disk@@ -512,7 +531,7 @@ windowrule = size 1400 900, class:^(disktree)$## Develop```sh-make run # release build, scanning $HOME+make run # release build, opening the source/root choosermake lint # rustfmt --check, then clippy with every warning an errormake test # scanner, layout and removal tests, plus window-harness testsmake test-ssh # real localhost SSH scans/errors; Linux, bun + openssh requireddiff --git a/crates/disktree-app/src/main.rs b/crates/disktree-app/src/main.rsindex 22111b0..904a931 100644--- a/crates/disktree-app/src/main.rs+++ b/crates/disktree-app/src/main.rs@@ -66,19 +66,21 @@ Remote sessions are read-only: mark, export list/prompt/delete script.Use --check with ssh to deploy and scan without opening a window.arguments:- PATH directory to scan (default: the home directory)+ PATH explicit directory to scan; omitted opens root selection-The window opens on a treemap of the root, largest first. Space marks the+Without PATH, choose this computer or SSH, then a mount or directory.+No scan starts before explicit acceptance. Nested mounts are excluded.+With PATH the window scans it directly, largest first. Space marks theselected tile, Enter opens it, c reviews the marked list, ? lists every key.options:-a, --apparent-size measure apparent length instead of allocated blocks- -l, --follow-links follow symlinks+ -l, --follow-links follow symlinks (local scans only)-H, --no-hidden skip dotfiles and dot-directories-D, --disk scan the whole disk the home directory is on-X, --cross-filesystemsalso measure other disks, network shares and pseudo- filesystems mounted below PATH (off by default)+ filesystems mounted below PATH (local only; off by default)-d, --depth N how many levels to draw at once (1-6, default 3)--power-efficiency PRESETmiser, balanced (default), aggressive, drain-my-batterydiff --git a/crates/disktree-app/src/state.rs b/crates/disktree-app/src/state.rsindex 4dc8809..41d372d 100644--- a/crates/disktree-app/src/state.rs+++ b/crates/disktree-app/src/state.rs@@ -821,7 +821,7 @@ impl Disktree {false}- fn finish_volume_listing(+ pub(crate) fn finish_volume_listing(&mut self,result: std::io::Result<(Vec<disktree_core::space::Volume>,@@ -867,6 +867,7 @@ impl Disktree {if matches!(event, InputEvent::PressEnter { .. }) {this.connect_picker(cx);}+ cx.notify();}).detach();self.picker_host = Some(host);@@ -885,6 +886,24 @@ impl Disktree {}}+ pub fn picker_source_matches(&self, cx: &Context<'_, Self>) -> bool {+ self.picker_host.as_ref().is_none_or(|input| {+ input.read(cx).value().trim()+ == self.volumes_source.as_deref().unwrap_or_default()+ })+ }++ pub fn choose_local_source(+ &mut self,+ window: &mut Window,+ cx: &mut Context<'_, Self>,+ ) {+ if let Some(host) = self.picker_host.clone() {+ host.update(cx, |host, cx| host.set_value("", window, cx));+ }+ self.load_volume_source(None, cx);+ }+pub fn connect_picker(&mut self, cx: &mut Context<'_, Self>) {let host = self.picker_host@@ -915,6 +934,13 @@ impl Disktree {{return;}+ if !self.picker_source_matches(cx) {+ self.picker_error = Some(+ "Connect SSH or choose This computer before scanning.".into(),+ );+ cx.notify();+ return;+ }if !path.is_absolute() {self.picker_error =Some("Enter an absolute directory path.".into());@@ -954,6 +980,10 @@ impl Disktree {};}self.remote.clone_from(&self.volumes_source);+ if self.remote.is_some() {+ self.options.follow_links = false;+ self.options.one_filesystem = true;+ }self.awaiting_root = false;self.close_volumes(cx);self.set_root(path, cx);@@ -1266,6 +1296,22 @@ impl Disktree {.detach();}+ pub(crate) fn update_remote_identity(+ &mut self,+ identity: Option<disktree_core::identity::HostIdentity>,+ ) {+ // A stable SSH alias can be repointed to a different machine.+ // Old marks must not acquire that machine's freshly captured guard.+ if self.remote_identity != identity && !self.marks.is_empty() {+ self.marks.clear();+ self.notice = Some((+ "Remote identity changed; previous marks were cleared.".into(),+ Status::Warning,+ ));+ }+ self.remote_identity = identity;+ }+/// Drain the scan channel once. Returns whether the poller should keep/// ticking. Driven by the poll task above, and by the tests, which cannot/// wait on the test clock while a real worker thread walks a directory.@@ -1289,7 +1335,7 @@ impl Disktree {self.disk_root = snapshot.header.disk_root;self.space = snapshot.header.space;self.remote_platform = snapshot.header.platform;- self.remote_identity = snapshot.header.identity;+ self.update_remote_identity(snapshot.header.identity);self.device = self.remote.as_ref().map(|host| {format!("{host} · read-only · space at scan")});@@ -3636,16 +3682,20 @@ impl Render for Disktree {self.tick_transition(window);// The titlebar names the directory on screen, however it got there:// a key, a click, a rescan or a folder chosen from the menu.- let title = format!(- "disktree{} · {}",- self.remote.as_ref().map_or_else(String::new, |host| {- format!(" · {host} · read-only")- }),- crate::marks::display_path(- &self.current_path(),- self.home.as_deref()+ let title = if self.awaiting_root {+ "disktree · Choose a source".into()+ } else {+ format!(+ "disktree{} · {}",+ self.remote.as_ref().map_or_else(String::new, |host| {+ format!(" · {host} · read-only")+ }),+ crate::marks::display_path(+ &self.current_path(),+ self.home.as_deref()+ ))- );+ };if title != self.window_title {window.set_window_title(&title);self.window_title = title;diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rsindex 7571a74..e6f1e8d 100644--- a/crates/disktree-app/src/tests.rs+++ b/crates/disktree-app/src/tests.rs@@ -206,6 +206,181 @@ fn switching_from_remote_to_local_clears_machine_specific_marks(finish_scan(&view, cx);}+#[gpui_kit::test]+fn chooser_fits_a_small_window_at_large_interface_zoom(+ cx: &mut TestAppContext,+) {+ cx.update(gpui_omarchy::init);+ let (_, cx) =+ cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));+ cx.run_until_parked();+ cx.simulate_resize(gpui_kit::size(px(900.), px(600.)));+ for rem in [16., 28.] {+ cx.update(|window, _| window.set_rem_size(px(rem)));+ draw(cx);+ let bounds = cx+ .debug_bounds("source-picker")+ .expect("scrollable chooser");+ assert!(bounds.size.width > px(200.), "{bounds:?}");+ assert!(+ bounds.origin.x >= px(0.) && bounds.right() <= px(900.),+ "{bounds:?}"+ );+ assert!(+ bounds.origin.y >= px(0.) && bounds.bottom() <= px(600.),+ "{bounds:?}"+ );+ }+}++#[gpui_kit::test]+fn editing_a_host_never_retargets_an_existing_scan(cx: &mut TestAppContext) {+ cx.update(gpui_omarchy::init);+ let temp = fixture();+ let (view, cx) = view_over(temp.path(), cx);+ update(&view, cx, Disktree::open_volumes);+ cx.run_until_parked();+ draw(cx);+ let before = read(&view, cx, |app| app.scan_epoch);+ let input = cx.debug_bounds("source-host").unwrap();+ cx.simulate_click(input.center(), gpui_kit::Modifiers::none());+ cx.simulate_input("new-host-not-connected");+ update(&view, cx, |app, cx| {+ app.choose_source_root(temp.path().into(), cx);+ assert!(app.picker_error.is_some());+ assert!(app.remote.is_none());+ assert_eq!(app.scan_epoch, before);+ assert!(app.tree.is_some());+ });+ press(cx, "escape");+ assert!(!read(&view, cx, |app| app.volumes_open));+}++#[gpui_kit::test]+fn a_directory_error_can_be_corrected_without_reconnecting(+ cx: &mut TestAppContext,+) {+ cx.update(gpui_omarchy::init);+ let temp = fixture();+ let (view, cx) =+ cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));+ cx.run_until_parked();+ update(&view, cx, |app, cx| {+ app.choose_source_root(PathBuf::from("relative"), cx);+ assert!(app.picker_error.is_some());+ assert!(app.awaiting_root);+ app.choose_source_root(temp.path().into(), cx);+ assert!(app.picker_error.is_none());+ assert!(!app.awaiting_root);+ });+ finish_scan(&view, cx);+}++#[gpui_kit::test]+fn stale_local_discovery_cannot_overwrite_a_new_source_error(+ cx: &mut TestAppContext,+) {+ cx.update(gpui_omarchy::init);+ let (view, cx) =+ cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));+ // The old discovery is still queued. The new host fails validation+ // without any network connection; only its error may remain.+ update(&view, cx, |app, cx| {+ app.load_volume_source(Some("-invalid".into()), cx);+ });+ cx.run_until_parked();+ draw(cx);+ read(&view, cx, |app| {+ assert_eq!(app.volumes_source.as_deref(), Some("-invalid"));+ assert!(app.volumes_error.is_some());+ assert!(app.volumes.is_empty());+ assert!(app.remote.is_none());+ });+ update(&view, cx, |app, cx| {+ app.close_volumes(cx);+ assert!(!app.poll_roots_once(1, cx));+ });+}++#[gpui_kit::test]+fn remote_root_acceptance_never_stats_the_path_locally(+ cx: &mut TestAppContext,+) {+ cx.update(gpui_omarchy::init);+ let temp = fixture();+ let (view, cx) = view_over(temp.path(), cx);+ update(&view, cx, |app, cx| {+ let crumbs = app.crumbs_for_path(&temp.path().join("junk")).unwrap();+ app.select(Some(crumbs), cx);+ app.toggle_mark_selected(cx);+ app.volumes_open = true;+ // An intentionally invalid SSH destination ensures acceptance cannot+ // contact any machine. The listing is a decoded fixture, not a walk.+ app.volumes_source = Some("-test-fixture".into());+ app.finish_volume_listing(+ Ok((+ vec![Volume {+ point: PathBuf::from("/only-on-the-remote-host"),+ device: Some("/dev/remote-disk".into()),+ space: None,+ }],+ None,+ )),+ cx,+ );+ });+ draw(cx);+ update(&view, cx, |app, cx| {+ app.choose_volume(cx);+ assert_eq!(app.remote.as_deref(), Some("-test-fixture"));+ assert_eq!(app.root_path, PathBuf::from("/only-on-the-remote-host"));+ assert!(app.marks.is_empty() && app.remote_identity.is_none());+ assert!(+ app.tree.is_none()+ && app.scan.is_none()+ && app.remote_scan.is_none()+ );+ assert!(+ app.scan_error+ .as_ref()+ .is_some_and(|error| error.contains("invalid SSH"))+ );+ });+}++#[gpui_kit::test]+fn repointing_an_ssh_alias_never_reuses_old_machine_marks(+ cx: &mut TestAppContext,+) {+ cx.update(gpui_omarchy::init);+ let temp = fixture();+ let (view, cx) = view_over(temp.path(), cx);+ update(&view, cx, |app, cx| {+ let old = disktree_core::identity::HostIdentity {+ hostname: "same-name".into(),+ machine_id: Some("machine-a".into()),+ };+ app.remote = Some("stable-alias".into());+ app.update_remote_identity(Some(old.clone()));+ let crumbs = app.crumbs_for_path(&temp.path().join("junk")).unwrap();+ app.select(Some(crumbs), cx);+ app.toggle_mark_selected(cx);+ app.update_remote_identity(Some(old.clone()));+ assert!(!app.marks.is_empty(), "same machine keeps its marks");+ app.update_remote_identity(Some(+ disktree_core::identity::HostIdentity {+ hostname: old.hostname,+ machine_id: Some("machine-b".into()),+ },+ ));+ assert!(app.marks.is_empty(), "same alias is not proof of identity");+ app.toggle_mark_selected(cx);+ assert!(!app.marks.is_empty());+ app.update_remote_identity(None);+ assert!(app.marks.is_empty(), "lost identity also fails closed");+ });+}+#[gpui_kit::test]fn remote_review_never_deletes_even_through_direct_actions(cx: &mut TestAppContext,diff --git a/crates/disktree-app/src/ui.rs b/crates/disktree-app/src/ui.rsindex 1cebdd7..3e21ed4 100644--- a/crates/disktree-app/src/ui.rs+++ b/crates/disktree-app/src/ui.rs@@ -99,6 +99,8 @@ pub mod size {/// Source/root chooser, with room for host, path and mount labels.pub const SOURCE_PICKER: Rems = Rems(40.0);pub const SOURCE_LIST_HEIGHT: Rems = Rems(18.0);+ /// Leave a visible backdrop even at large interface zoom.+ pub const SOURCE_VIEWPORT_FRACTION: f32 = 0.92;/// The keyboard overlay.pub const HELP: Rems = Rems(32.5);/// The key column of the keyboard overlay.diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rsindex 06b314e..78f1470 100644--- a/crates/disktree-app/src/views.rs+++ b/crates/disktree-app/src/views.rs@@ -129,8 +129,7 @@ pub fn root(root}-/// Picking another volume scans it from scratch: the picker lists every-/// volume with its free space, and the choice is the new root.+/// Discovery is lightweight; a separate, explicit action starts the walk.fn volumes_dialog(app: &Disktree,window: &Window,@@ -138,6 +137,7 @@ fn volumes_dialog() -> impl IntoElement {let theme = cx.omarchy().clone();let cancel = cx.entity().downgrade();+ let source_ready = app.picker_source_matches(cx);let source = app.volumes_source.as_ref().map_or_else(|| "This computer".to_owned(),|host| format!("{host} · SSH · read-only"),@@ -200,14 +200,14 @@ fn volumes_dialog(.picker_path.as_ref().expect("picker prepared before rendering");- let popup = dialog_popup(cx).w(size::SOURCE_PICKER)+ let popup = dialog_popup(cx).w_full().child(dialog_title("Choose what to scan", cx)).child(dialog_description(- "Connect, then select a mount or directory. Nothing is scanned until you choose Scan.",+ "Connect, then select a mount or directory. No new scan starts until you choose Scan.",cx)).child(div().flex().flex_row().gap(space::SM).child(button("source-local", "This computer", ButtonVariant::Secondary, cx)- .on_click(cx.listener(|this, _, _, cx| this.load_volume_source(None, cx))))+ .on_click(cx.listener(|this, _, window, cx| this.choose_local_source(window, cx)))).child(gpui_omarchy::input("source-host", host, window, cx).debug_selector(|| "source-host".into()).flex_1()).child(button("source-connect", "Connect SSH", ButtonVariant::Secondary, cx)@@ -220,7 +220,7 @@ fn volumes_dialog(.child(gpui_omarchy::input("source-path", path, window, cx).debug_selector(|| "source-path".into()).flex_1()).child(button("source-scan-path", "Scan directory", ButtonVariant::Secondary, cx)- .disabled(app.volumes_loading || app.volumes_error.is_some())+ .disabled(!source_ready || app.volumes_loading || app.volumes_error.is_some()).on_click(cx.listener(|this, _, _, cx| this.choose_picker_path(cx))))).children(app.picker_error.as_ref().map(|error| div().text_color(theme.danger).child(error.clone()))).child(div().flex().flex_row().justify_end().gap(space::SM)@@ -228,11 +228,25 @@ fn volumes_dialog(.on_click(cx.listener(|this, _, window, cx| {this.close_volumes(cx); this.apply_focus(window, cx);})))- .child(dialog_button("source-scan", "Scan selected mount", ButtonVariant::Primary, cx)- .disabled(app.volumes_loading || app.volumes_error.is_some() || app.volumes.is_empty())+ .child(dialog_button("source-scan", "Scan selected root", ButtonVariant::Primary, cx)+ .disabled(!source_ready || app.volumes_loading || app.volumes_error.is_some() || app.volumes.is_empty()).on_click(cx.listener(|this, _, window, cx| {this.choose_volume(cx); this.apply_focus(window, cx);}))));+ let popup = div()+ .id("source-picker-scroll")+ .debug_selector(|| "source-picker".into())+ .w(size::SOURCE_PICKER)+ .max_w(Rems(+ window.viewport_size().width.as_f32() / app.rem+ * size::SOURCE_VIEWPORT_FRACTION,+ ))+ .max_h(Rems(+ window.viewport_size().height.as_f32() / app.rem+ * size::SOURCE_VIEWPORT_FRACTION,+ ))+ .overflow_y_scroll()+ .child(popup);let centred = centred_popup(popup, {let close = cancel.clone();move |_, window, cx| {diff --git a/crates/disktree-core/src/identity.rs b/crates/disktree-core/src/identity.rsindex 11cea93..393ede3 100644--- a/crates/disktree-core/src/identity.rs+++ b/crates/disktree-core/src/identity.rs@@ -1,7 +1,7 @@//! Identity captured on the scanned machine, never inferred from an alias.use serde::{Deserialize, Serialize};-#[derive(Clone, Debug, Serialize, Deserialize)]+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]pub struct HostIdentity {pub hostname: String,pub machine_id: Option<String>,