dir-analysis-tool 3.0.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,8 +32,9 @@ npx dir-analysis-tool
32
32
 
33
33
  ## Why dir-analysis-tool?
34
34
 
35
- - **Fast.** A concurrent, bounded scanner `stat`s every file exactly once. On a 140,000-file tree it is about 3× faster than v2, and duplicate detection is about 4× faster.
36
- - **Light.** Memory stays flat while scanning (about 9 MB retained for 140,000 files), and the package has just three direct dependencies.
35
+ - **Fast.** A concurrent, bounded scanner `stat`s every file exactly once and runs at the speed of the filesystem: the Linux kernel source tree (96,000 files) scans in about 0.3 s, close to `du` in the benchmark below.
36
+ - **Light.** The default scan keeps only top-N files and folder aggregates, and the process starts in about 20 ms.
37
+ - **Zero dependencies.** The CLI and the library are pure Node.js: no third-party runtime packages are installed. Development tools are only needed when working on the source.
37
38
  - **Answers the real question.** _Which folders and files take the space?_ Then types, extensions, duplicates, stale files, and empty ones.
38
39
  - **Correct.** Hard-linked data is counted once, symlinks can be followed without looping, unreadable paths are reported instead of silently skipped, and output is deterministic.
39
40
  - **Built for CI.** Size budgets fail the build with exit code 2, Markdown output drops straight into a pull request or job summary, and `--json` stays clean when piped.
@@ -51,6 +52,7 @@ npx dir-analysis-tool
51
52
  - [Output formats](#output-formats)
52
53
  - [Configuration](#configuration)
53
54
  - [Library API](#library-api)
55
+ - [Agent skill](#agent-skill)
54
56
  - [How it works](#how-it-works)
55
57
  - [Exit codes](#exit-codes)
56
58
  - [Migrating from v2](#migrating-from-v2)
@@ -58,7 +60,7 @@ npx dir-analysis-tool
58
60
 
59
61
  ## Installation
60
62
 
61
- Requires Node.js 22.12 or later.
63
+ Requires Node.js 22.12 or later. The published CLI and library have **zero runtime dependencies**; all imports use Node.js built-ins or code shipped in this package.
62
64
 
63
65
  ```bash
64
66
  npm install -g dir-analysis-tool # or: pnpm add -g dir-analysis-tool
@@ -93,35 +95,35 @@ dat . --json | jq '.largestFiles[0]' # machine-readable output
93
95
 
94
96
  ## What it shows
95
97
 
96
- `dat . -g -d` on this repository:
98
+ `dat . -g -d -n 5` on this repository (sizes and timing vary by checkout):
97
99
 
98
100
  ```text
99
- dat ~/code/dir-analysis-tool 5ms
101
+ dat ~/code/dir-analysis-tool 4ms
100
102
 
101
- Size 1.4 MiB (1.58 MiB on disk)
102
- Files 83
103
+ Size 806 KiB (1 MiB on disk)
104
+ Files 93
103
105
  Folders 19
104
- Skipped 22 excluded
106
+ Skipped 23 excluded (--all includes .git and node_modules)
105
107
 
106
108
  File types
107
- Images ██████████▌ 937 KiB 65% 1 file
108
- Code █████▏ 458 KiB 32% 71 files
109
- Documents ▌ 39.3 KiB 3% 8 files
109
+ Code ███████████▏ 559 KiB 69% 82 files
110
+ Images ███▉ 195 KiB 24% 1 file
111
+ Documents █ 51.7 KiB 6% 7 files
110
112
  Other 113 B <1% 3 files
111
113
 
112
114
  Largest folders
113
- 937 KiB .github/assets/ 1 file
114
- 212 KiB src/ 38 files
115
- 78.7 KiB src/core/ 11 files
116
- 74.7 KiB test/ 14 files
117
- 51.1 KiB src/cli/ 12 files
115
+ 261 KiB src/ 41 files
116
+ 195 KiB .github/assets/ 1 file
117
+ 109 KiB test/ 18 files
118
+ 94.4 KiB src/core/ 12 files
119
+ 82.9 KiB src/cli/ 14 files
118
120
 
119
121
  Largest files
120
- 937 KiB .github/assets/dir-analysis-tool-banner.png
121
- 147 KiB pnpm-lock.yaml
122
- 20.8 KiB src/core/analyze.ts
123
- 18.1 KiB test/integration/analyze.test.ts
124
- 17.2 KiB src/reporters/html.ts
122
+ 195 KiB .github/assets/dir-analysis-tool-banner.png
123
+ 146 KiB pnpm-lock.yaml
124
+ 33.1 KiB README.md
125
+ 24.8 KiB src/cli/command.ts
126
+ 21 KiB src/core/analyze.ts
125
127
 
126
128
  Duplicates none found
127
129
  ```
@@ -132,15 +134,13 @@ A size tree (`dat src -t --tree-depth 2`):
132
134
 
133
135
  ```text
134
136
  Tree
135
- 212 KiB .
136
- 78.7 KiB ├─ core/
137
- 20.8 KiB │ ├─ analyze.ts
138
- 13.9 KiB │ ├─ scanner.ts
139
- 10 KiB │ ├─ compare.ts
140
- 535 B │ └─ … 1 more entry
141
- 51.1 KiB ├─ cli/
142
- 23.1 KiB │ ├─ commands/
143
- 13.5 KiB │ ├─ options.ts
137
+ 261 KiB .
138
+ 94.4 KiB ├─ core/
139
+ 21 KiB │ ├─ analyze.ts
140
+ 14 KiB │ ├─ scanner.ts
141
+ 12.6 KiB │ ├─ gitignore.ts
142
+ 10.2 KiB │ ├─ compare.ts
143
+ 8.17 KiB │ ├─ duplicates.ts
144
144
  …
145
145
  ```
146
146
 
@@ -230,7 +230,7 @@ A size tree (`dat src -t --tree-depth 2`):
230
230
  | `-n, --top <n>` | Items per list. Default `10`. |
231
231
  | `-f, --format <format>` | `pretty`, `json`, `markdown`, or `csv`. |
232
232
 
233
- All scan and output options above are accepted too.
233
+ All scan options and shared output options above are accepted too; `--html`, `--csv`, and HTML format are analyze-only. Use `--format csv` to export a comparison.
234
234
 
235
235
  ### `dat watch`
236
236
 
@@ -426,26 +426,41 @@ await writeFile('report.md', renderAnalysisMarkdown(result));
426
426
 
427
427
  Sizes and times accept the same strings as the CLI (`minSize: '10MB'`, `modifiedAfter: '30d'`), as well as numbers and `Date`s.
428
428
 
429
+ ## Agent skill
430
+
431
+ An official [Agent Skill](https://agentskills.io) lets coding agents such as Claude Code, Codex, Gemini CLI, and OpenCode use `dat` to explain what takes up space in a repository, find duplicate assets, and check size budgets. The agents run the CLI and read its JSON output instead of guessing.
432
+
433
+ ```bash
434
+ npx skills add KhaledSaeed18/dir-analysis-tool --skill dir-analysis-tool
435
+ ```
436
+
437
+ Then ask in your own words, for example "why is this repo so big?" or "fail CI if `dist` goes over 2 MB". See [skills/README.md](skills/README.md) for other ways to install it, tested agents, and the evals.
438
+
429
439
  ## How it works
430
440
 
431
- - **Scanning.** Directories are read with `readdir({ withFileTypes })`, so they never need a `stat`, and each regular file is `lstat`ed once. All filesystem calls go through one concurrency limiter, so no tree, however wide, can exhaust file handles. Work is scheduled depth-first to keep the queue small.
441
+ - **Scanning.** Directories are read with `readdir({ withFileTypes })`, so they never need a `stat`, and each regular file is `lstat`ed once. All filesystem calls go through one concurrency limiter (32 operations in flight by default), so no tree, however wide, can exhaust file handles. Work is scheduled depth-first to keep the queue small.
442
+ - **Patterns.** Exclude patterns and `.gitignore` files are compiled by a built-in matcher: consecutive rules become a few regular expressions, and plain names and `*.ext` rules are resolved with hash lookups, reducing pattern-matching overhead without caching results per path.
432
443
  - **Memory.** Totals, type and extension statistics, folder sizes, and the top-N lists are computed while scanning; the lists use bounded heaps. Reports you opt into keep only what they match. Duplicate detection keeps one small record per file that shares its size with another.
433
444
  - **Largest folders.** Folders are ranked by the total size below them. A folder whose size comes almost entirely (95% or more) from one subfolder is folded into that subfolder, so the list points to where the data actually lives instead of repeating every parent.
434
445
  - **Duplicates,** in stages so most files are never read in full:
435
446
  1. Only sizes shared by at least two files are considered. Empty files are excluded, and hard links to the same data are not copies.
436
447
  2. Files over 256 KiB are compared by a SHA-256 sample of their first and last 64 KiB.
437
- 3. Remaining candidates are hashed in full with streaming SHA-256 and reusable buffers.
448
+ 3. Remaining candidates are hashed in full: small files in a single read, large files streamed through reusable buffers. Each size group is finished as soon as its last file is hashed, so intermediate hash maps are retained only for groups in flight; candidates and results still use memory proportional to their count.
438
449
  - **Disk usage.** Sizes are apparent sizes (file lengths). `On disk` is the space allocated in blocks, which is what `du` reports.
439
450
  - **Determinism.** Results are sorted by size and then by path, so the same tree always produces the same output, whatever order the filesystem returned it in.
440
451
 
441
- **Benchmarks** (Apple M4, warm cache, 140,237 files, 2.97 GB):
452
+ **Benchmarks** (Apple M4, warm cache, best of three; measurements from the optimization work, not performance guarantees). On the Linux kernel source tree, 96,127 files and 1.53 GiB:
453
+
454
+ | Task | v3.0 | v3.1 | `du -s` |
455
+ | ---------------------------------- | -----: | ---------: | ------: |
456
+ | Scan | 0.32 s | **0.28 s** | 0.25 s |
457
+ | Scan honoring `.gitignore` | 0.98 s | **0.33 s** | |
458
+ | Scan and find duplicates | 2.64 s | **1.20 s** | |
459
+ | Peak heap while finding duplicates | 118 MB | **45 MB** | |
442
460
 
443
- | Task | v2.0.7 | v3 |
444
- | ------------------------ | -----: | ---------: |
445
- | Scan | 1.74 s | **0.61 s** |
446
- | Scan and find duplicates | 12.3 s | **2.9 s** |
461
+ On a synthetic tree of 1,000,000 files, v3.1 scans in 8.9 s where `du -s` takes 13 s. Compared with v2.0.7 on a 140,237-file tree, v3 scans about 3× faster and finds duplicates about 4× faster, with identical results. Run `pnpm bench` (or `pnpm bench <directory>`) to measure on your machine.
447
462
 
448
- Both versions found the same files, bytes, and duplicate groups. Run `pnpm bench` (or `pnpm bench <directory>`) to measure on your machine.
463
+ The benchmark script reports scan and duplicate timings plus process peak RSS (not JavaScript heap). Results vary with storage, cache state, tree shape, and Node.js version. `du` measures allocated disk space and does not produce the same reports.
449
464
 
450
465
  ## Exit codes
451
466
 
@@ -478,9 +493,9 @@ v3 is a rewrite with a new output format. Most commands keep working unchanged.
478
493
 
479
494
  **Why does the total differ from `du`?** `du` reports blocks allocated on disk, while the headline size is the sum of file lengths. The `On disk` line matches `du`. Also check what was skipped: `.git` and `node_modules` are excluded by default (`--all` includes them), and hard-linked data is counted once, as `du` does.
480
495
 
481
- **Is it safe to run on a huge directory?** Yes. Memory does not grow with the number of files unless you ask for a report that lists them, filesystem concurrency is bounded, and unreadable paths are reported rather than fatal. Press Ctrl+C at any time.
496
+ **Is it safe to run on a huge directory?** Yes. The default scan keeps bounded top-N file lists, but folder metadata, hard-link tracking, and symlink tracking still require memory. Duplicate detection, directory comparisons, and optional file lists use additional memory, filesystem concurrency is bounded, and unreadable paths are reported rather than fatal. Press Ctrl+C at any time.
482
497
 
483
- **Does it modify anything?** No. `dat` only reads, except for report files you ask it to write.
498
+ **Does it modify anything?** `dat` reads the scanned files. It writes report files when requested, and `dat init` writes a configuration file.
484
499
 
485
500
  ## Contributing
486
501