Skip to content

feat(du): add du disk usage filter with compact output#414

Closed
TheAgentWire wants to merge 4 commits intortk-ai:developfrom
TheAgentWire:feat/du-disk-usage-filter
Closed

feat(du): add du disk usage filter with compact output#414
TheAgentWire wants to merge 4 commits intortk-ai:developfrom
TheAgentWire:feat/du-disk-usage-filter

Conversation

@TheAgentWire
Copy link

@TheAgentWire TheAgentWire commented Mar 8, 2026

Summary

Adds rtk du — a compact filter for du (disk usage) output. Closes #284.

84 invocations in the last 30 days (per issue reporter) — this is a frequently used command that benefits from token-optimized output.

What it does

  • Strips whitespace padding from sizes
  • Sorts by size descending (largest first) — immediately surfaces what is eating disk
  • Strips common directory prefix from paths for shorter output
  • Shows total as Σ at bottom — clearly distinguishable from directory entries
  • Graceful fallback on filter failure (raw du output)
  • -h flag passthroughdisable_help_flag prevents clap from swallowing -h (human-readable), since du -h is the most common usage pattern. Help is still accessible via --help.

Examples

rtk du -sh /path/to/project/src/*

Before (raw du):

 32K    src/aws_cmd.rs
 60K    src/cargo_cmd.rs
 40K    src/cc_economics.rs
 12K    src/ccusage.rs
8.0K    src/config.rs
 28K    src/container.rs
104K    src/discover
 68K    src/main.rs
 60K    src/git.rs

After (rtk du):

104K    discover
68K     main.rs
60K     cargo_cmd.rs
60K     git.rs
40K     cc_economics.rs
32K     aws_cmd.rs
28K     container.rs
12K     ccusage.rs
8.0K    config.rs

Sorted largest-first, common src/ prefix stripped, padding normalized.

rtk du -h -d 1 /path/to/project

1.2G    target
1.9M    .git
1.2M    src
316K    docs
84K     scripts
36K     .github
20K     hooks
Σ 1.2G

Root directory detected as total, shown with Σ marker. Immediately obvious that target/ dominates.

rtk du -sh /path/to/workspace/*

3.1G    project-alpha
1.5G    project-beta
1.2G    project-gamma
212M    project-delta
48M     project-epsilon

Quick disk audit across all projects, sorted by size.

Token savings

≥60% verified in tests. Biggest wins on recursive output with long absolute paths — common prefix stripping + sort + padding removal compound significantly.

Files changed

File Change
src/du_cmd.rs New filter module (run, filter, sort, prefix strip, total detection, 10 tests)
src/main.rs Register mod, Commands enum variant, match arm
src/discover/rules.rs Hook rewrite pattern + rule for du → rtk du
tests/fixtures/du_*.txt 4 real fixture files for test reference

Testing

  • 10 unit tests: single entry, multi entry, sorting, empty input, raw blocks, common prefix stripping, parent path total detection, size parsing, token savings ≥60%
  • Full suite: 718 tests pass, 0 failures
  • Manual testing: verified on macOS with real directories
  • Pre-commit gate: cargo fmt --all --check && cargo clippy --all-targets && cargo test

Checklist

  • Unit tests added for all filter logic
  • Token savings ≥60% verified
  • Edge cases covered (empty, single, raw blocks, parent total)
  • cargo fmt && cargo clippy && cargo test passes
  • Manual test: rtk du inspected and verified
  • DCO sign-off included
  • No personal/sensitive data in fixtures or tests

aeppling and others added 4 commits March 7, 2026 11:23
add security check cicd on dev branch PR

Signed-off-by: aesoft <43991222+aeppling@users.noreply.github.com>
fix(cicd): Add security check on dev branch PR
- New src/du_cmd.rs: strips padding, sorts by size desc, strips common
  path prefix, shows total as Σ
- Registered in main.rs (mod, Commands enum, match arm)
- Hook rewrite support in discover/rules.rs (pattern + rule)
- 9 unit tests covering single/multi entry, sorting, raw blocks,
  prefix stripping, size parsing, and >=60% token savings
- Closes rtk-ai#284

Signed-off-by: TheAgentWire <login@theagentwire.ai>
@pszymkowiak
Copy link
Collaborator

Hey @TheAgentWire, thanks for this work!

However, since PRs #349, #351, #386 landed, RTK now includes a built-in TOML filter for du (see src/filters/du.toml). Tested savings: 96.8% on du -h . with large directory trees.

The TOML filter covers the core use case declaratively in ~6 lines. Closing this PR as the functionality is already shipped.

If you'd like to contribute more advanced filtering (e.g., sorting, aggregation), feel free to open a new PR building on top of the TOML filter. Thanks again!

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.

4 participants