Skip to content

scan: add a local JSON Lines mode to the headless helper - #119

Open
snowsword20 wants to merge 1 commit into
tobi:mainfrom
snowsword20:scan-jsonl-mode
Open

snowsword20 wants to merge 1 commit into
tobi:mainfrom
snowsword20:scan-jsonl-mode

Conversation

@snowsword20

@snowsword20 snowsword20 commented Oct 28, 2026 •

Copy link
Copy Markdown

Closes the proposal in issue #118 (headless scan mode for scripts and coding agents).

What

A scan subcommand on disktree-scan, the GPUI-free helper:

disktree-scan scan PATH [--apparent-size] [--no-hidden] [--min-size N]

It runs the same read-only scan the treemap draws and writes JSON Lines to stdout — one directory per line, parent before children, children largest first:

{"path":"E:\\aaprojects","bytes":33676751920,"files":364554,"dirs":69384,"modified":1793212365,"read_error":false}
{"path":"E:\\aaprojects\\githubrepo","bytes":27952605184,"files":298120,"dirs":61072,"modified":1793300000,"read_error":false}

--min-size N prunes printed directories while totals on surviving lines stay complete. Same promises as --stdio-v1: no stdin, no deletion surface, no GPUI dependency.

Why

Scripts and coding agents cannot open a window, and du is an order of magnitude slower than the scanner on the same tree (measured: >20 min vs 30 s cold / 2.6 s warm on a 364k-file HDD tree). The app already exports agent_prompt for the cleanup half; this gives agents the scan half, so the whole loop can run headless.

How

disktree_core::scan::scan is reused unchanged; the mode parses its own flags, calls it, and walks the returned tree writing one JSON object per line. ~180 lines in the helper, one new dependency (serde_json), no app or protocol changes.

Tests

Four new tests in the helper: root summary first, --min-size pruning (pruned subtree still counted on the parent), apparent vs allocated bytes, and flag validation (missing/repeated path, unknown option).

Related prior art (and why this still exists)

Three open proposals overlap with this one, all worth reading before judging it:

This PR deliberately takes the smallest slice: JSON Lines out of the existing read-only helper. No new binary, no destructive surface, no opinion about what a fuller CLI should eventually be. If the direction lands on #32 or a --cli flag instead, this is ~180 lines to rebase or close — and the tests travel.

disktree-scan scan PATH [--apparent-size] [--no-hidden] [--min-size N]
writes the finished tree as JSON Lines, one directory per line, parent
before children, children largest first. Same read-only promise as the
SSH helper: no stdin, no deletion.

Scripts and coding agents cannot open a window, and du is an order of
magnitude slower than the scanner on the same tree. The mode reuses
disktree_core::scan unchanged; directories below --min-size are left
out of the output while the totals on surviving lines stay complete.
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