Skip to content

disktree --cli: print the tree to stdout, for agents and headless sessions #74

Open

Description

@X-SCI-TECH

The gap

disktree is window-only today. Everything — the treemap, marking, the review screen, and the "copy as agent prompt" export — lives behind the GUI. That leaves out callers that can only read stdout:

  • coding agents: they run commands and read the output; they cannot click a window. The project already leans this way — "Agent scratch" is a category, and the review screen hands the marked list to a coding agent — but without a human at a display, an agent can't reach any of it.
  • SSH, containers, CI: no display, no window.
  • and it would come to the artifacts people already have (including the Windows zip), with no new binary to ship.

I know #32 adds disktree-cli with JSON output for scan/check/trash, and #47 builds on that with an agent-focused du personality. Those are strong programmatic surfaces. This is the other half: a human- and agent-readable text tree from the binary people already have, so agent -> disktree --cli -> decide works in one step while the JSON surface stays JSON. (Agents are fluent in this shape — as #47 notes, they run du -sh * constantly.)

Proposal: disktree --cli

--cli scans through the existing pipeline and prints the tree to stdout instead of opening a window:

38 GiB  /home/me/work
├──     21 GiB  55%  builds/
│   ├──     12 GiB  57%  release/
│   └──    9.0 GiB  43%  debug/
├──    9.4 GiB  25%  node_modules/
└──    7.6 GiB  20%  datasets/

38 GiB in 512.0k files, 48.0k directories — 3 unreadable
  • Largest first; each row shows its size and its share of the parent; directories are trailed with /.
  • Every existing scan flag applies unchanged: --apparent-size, --follow-links, --no-hidden, --disk, --cross-filesystems, the power/thread flags, and --metric files (rank by count; the row shows the count).
  • -d/--depth decides how many levels print (same meaning as in the window; 1 prints only the root's children).
  • The tail merges like the treemap does: 96 children kept (the LayoutOptions::max_children default), then one … N more row with the summed size; a directory cut by the depth limit is marked with … rather than reading as empty.
  • Names go through the same line-safety rules as export.rs — a name with control characters can never read as two rows.
  • stdout only; a failed scan exits non-zero; a closed pipe (| head) is not an error.

Implementation

I have this working already, following the repo's conventions: a report.rs in disktree-core (re-ranks children by metric like the layout pass, keeps CHILDREN_KEPT = 96 to match the treemap, shares the escaping with export.rs, comments state the why, tests beside the promise) plus the --cli path in main.rs; the README gains a short "In the terminal" section and AGENTS.md's map gets the new module. Verified under Rust 1.97.1: cargo xtask lint clean, cargo xtask test green (one permission-sensitive scan test that also fails on unmodified main when run as root was excluded).

If this direction fits, I can contribute it as a PR — and if you'd rather have it as a format on #32's disktree-cli (--format text or a plain mode) instead of a flag on the window binary, the renderer moves over as-is. Same for the name: --cli is what I built, but --print/--text reads better next to #32 and I'm happy to rename.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions