Skip to content

Add disktree-web: browser dashboard for remote/headless machines - #16

Closed
marospekarik wants to merge 1 commit into
tobi:mainfrom
marospekarik:add-disktree-web
Closed

marospekarik wants to merge 1 commit into
tobi:mainfrom
marospekarik:add-disktree-web

Conversation

@marospekarik

Copy link
Copy Markdown

Problem

disktree is a native GPUI app, so it needs a local GPU and display. There is
no way to point it at a remote machine and view it over SSH/Tailscale/a
browser — you have to be physically at that machine's desktop.

Approach

Adds a new workspace crate, disktree-web, that reuses disktree-core
as-is (it already has no GPUI dependency by design — see its module doc)
and exposes it over HTTP:

  • A small axum server scans a root once at startup and keeps the
    disktree_core::tree::Node tree in memory.
  • /api/node?crumbs=1,4 returns one node plus one level of children,
    addressed the same way disktree-core::treemap already addresses tiles
    (crumb = child-index path from the root). This is lazy on purpose: an
    earlier version of this PR serialized the whole tree in one response,
    and on a real ~325 GB / 4.8M-file home directory that came out to about
    971 MB of JSON, which locked up the browser tab before it could paint
    anything. Fetching one level at a time keeps every response in the tens
    of KB and sub-2ms.
  • A static page (crates/disktree-web/static/index.html) lays the current
    level out as a squarified treemap in a <canvas> (same algorithm family
    as disktree-core::treemap, reimplemented in JS since the browser can't
    call into the Rust layout code), with the same category colours and
    reclaim hatching as the native app, plus breadcrumbs, click-to-drill-in,
    and Escape/Backspace to go up.

disktree-core is untouched — no changes needed there.

Usage

cargo run -p disktree-web --release -- --listen 0.0.0.0:7878 ~
# then open http://<host>:7878/ from another machine, e.g. over Tailscale

Defaults to $HOME if no path is given, matching disktree's own default.
--apparent-size mirrors the native app's flag.

Testing

  • cargo fmt --check, cargo clippy --release --all-targets -- -D warnings (zero warnings), and cargo test --release all pass for
    disktree-core and disktree-web.
  • The existing disktree-core suite (77 tests) is unaffected — nothing in
    it changed.
  • Exercised end-to-end in a real browser against a ~325 GB / 4.8M-file home
    directory: instant page load after the one-time scan, correct totals,
    category colours, reclaim hatching, breadcrumb navigation, and
    drill-down all work. Also reproduced and confirmed the whole-tree-JSON
    approach failing the way described above, before switching to the lazy
    per-node API.
  • Did not run disktree-app's window-harness tests (they need a real
    GPU/display); this PR doesn't touch that crate.

Out of scope

Marking/removal, git status, age-mode coloring, and keyboard parity with
the native app are not implemented — this is read-only viewing for a first
cut. Happy to follow up if there's interest.

disktree is a native GPUI app, so it needs a local GPU and display —
there is no way to point it at a remote server or view it over SSH/
Tailscale. This adds disktree-web, a small axum server that reuses
disktree-core (no UI dependency, already a plain library) to scan a
root and serve the tree lazily over HTTP, plus a static page that
lays it out as a squarified treemap in a <canvas>, mirroring the
native app's mosaic, category colours and reclaim hatching.

Design notes:

* The API is lazy by directory (`/api/node?crumbs=1,4`): each request
  returns one node plus one level of children, not the whole subtree.
  Serializing the full tree in one response does not scale — scanning
  a home directory with a few million files produces roughly a
  gigabyte of JSON, which locks up the browser tab before it can draw
  anything. This was caught by actually running it against a real
  home directory, not just a small test tree.
* The scan happens once at startup and is kept in memory
  (`disktree_core::tree::Node` is `Clone`-free and not cheap to
  re-walk); `Node::resolve` addresses it by crumb path, which is the
  same crumb scheme `disktree-core::treemap` already uses.
* `disktree-core` needed no changes: it has no GPUI dependency by
  design (see its module doc), so the new crate only adds a
  presentation layer, same as `disktree-app` does.
* Bind with `--listen 0.0.0.0:PORT` to reach it over a private network
  (e.g. Tailscale) instead of only localhost.

Usage:

    cargo run -p disktree-web --release -- --listen 0.0.0.0:7878 ~
    # then open http://<host>:7878/ from another machine

Verified: `cargo fmt --check`, `cargo clippy --release --all-targets
-- -D warnings` (zero warnings) and `cargo test --release` all pass
for disktree-core and disktree-web; the existing disktree-core test
suite (77 tests) is unaffected. Exercised end-to-end in a browser
against a real ~325 GB / 4.8M-file home directory: instant page load,
drill-down, breadcrumbs and totals all work, and the previous
whole-tree-JSON approach was confirmed broken the same way (971 MB
response, blank tab) before being replaced with the lazy API.
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