dustclaw 0.3.0 → 0.4.1
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 +101 -23
- package/data/config.json +23 -0
- package/data/targets.json +396 -0
- package/dist/commands/clean.js +38 -16
- package/dist/commands/overview.d.ts +1 -1
- package/dist/commands/overview.js +3 -3
- package/dist/commands/scan.d.ts +3 -3
- package/dist/commands/scan.js +4 -6
- package/dist/commands/wasteland.js +2 -1
- package/dist/index.js +48 -10
- package/dist/utils/config.d.ts +3 -1
- package/dist/utils/config.js +35 -7
- package/dist/utils/disk.d.ts +1 -0
- package/dist/utils/disk.js +29 -0
- package/dist/utils/format.js +1 -1
- package/dist/utils/scan.js +8 -4
- package/dist/utils/state.d.ts +1 -0
- package/dist/utils/state.js +3 -4
- package/dist/utils/wasteland.js +4 -6
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Dustclaw 🦀
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/dustclaw)
|
|
4
|
+
[](https://github.com/psandis/dustclaw/actions/workflows/ci.yml)
|
|
4
5
|
|
|
5
6
|
Find out what is eating your disk space and where the bloat is hiding.
|
|
6
7
|
|
|
@@ -36,7 +37,7 @@ npx dustclaw wasteland
|
|
|
36
37
|
|
|
37
38
|
┌─────────────────────────────────────┬──────────┬───────────────────────────────────────────────────────────────────┐
|
|
38
39
|
│ Name │ Size │ Path │
|
|
39
|
-
|
|
40
|
+
├─────────────────────────────────────┼──────────┼───────────────────────────────────────────────────────────────────┤
|
|
40
41
|
│ Docker Desktop │ 50.9 GB │ /Users/you/Library/Containers/com.docker.docker/Data │
|
|
41
42
|
│ Android Emulators │ 7.7 GB │ /Users/you/.android/avd │
|
|
42
43
|
│ Puppeteer Cache │ 4.0 GB │ /Users/you/.cache/puppeteer │
|
|
@@ -65,7 +66,7 @@ npx dustclaw clean --force
|
|
|
65
66
|
|
|
66
67
|
┌──────────────────────┬────────┬──────────────────────────────────┐
|
|
67
68
|
│ Name │ Size │ Path │
|
|
68
|
-
|
|
69
|
+
├──────────────────────┼────────┼──────────────────────────────────┤
|
|
69
70
|
│ Gradle Cache │ 2.5 GB │ /Users/you/.gradle/caches │
|
|
70
71
|
│ Puppeteer Cache │ 4.0 GB │ /Users/you/.cache/puppeteer │
|
|
71
72
|
│ Playwright Browsers │ 2.2 GB │ /Users/you/Library/Caches/ms-... │
|
|
@@ -83,15 +84,17 @@ npx dustclaw clean --force
|
|
|
83
84
|
|
|
84
85
|
| Command | What it does |
|
|
85
86
|
|---------|-------------|
|
|
86
|
-
| `dustclaw` | Quick overview: disk usage, free space, top 10 biggest items |
|
|
87
|
+
| `dustclaw [path]` | Quick overview: disk usage, free space, top 10 biggest items |
|
|
87
88
|
| `dustclaw scan [path]` | Deep scan: ranked list of largest files and folders |
|
|
88
89
|
| `dustclaw wasteland` | Finds known space wasters: caches, build artifacts, Trash, Docker |
|
|
89
90
|
| `dustclaw clean` | Clean safe items from last wasteland scan (dry run by default) |
|
|
90
91
|
|
|
91
92
|
## Requirements
|
|
92
93
|
|
|
93
|
-
- Node.js
|
|
94
|
-
- macOS or
|
|
94
|
+
- Node.js 22.12+
|
|
95
|
+
- macOS, Linux or Windows
|
|
96
|
+
|
|
97
|
+
CI runs lint, build, tests and the built CLI on all three with Node.js 22 and 24 for every push.
|
|
95
98
|
|
|
96
99
|
## Install
|
|
97
100
|
|
|
@@ -111,15 +114,38 @@ npx dustclaw
|
|
|
111
114
|
|
|
112
115
|
```bash
|
|
113
116
|
dustclaw
|
|
117
|
+
dustclaw ~/Projects # overview of a specific path
|
|
118
|
+
dustclaw -p ~/Projects # same, as an option
|
|
114
119
|
dustclaw -n 20 # show top 20 instead of 10
|
|
115
|
-
dustclaw -p ~/Projects # scan a specific path
|
|
116
120
|
```
|
|
117
121
|
|
|
122
|
+
If you pass both a path and `-p`, the path after the command is used.
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
Disk Usage
|
|
126
|
+
|
|
127
|
+
┌────────────────────────────┬──────────┬──────────┬───────────┬───────┐
|
|
128
|
+
│ Mount │ Total │ Used │ Available │ Use% │
|
|
129
|
+
├────────────────────────────┼──────────┼──────────┼───────────┼───────┤
|
|
130
|
+
│ / │ 460.4 GB │ 11.8 GB │ 56.0 GB │ 17.4% │
|
|
131
|
+
│ /System/Volumes/VM │ 460.4 GB │ 18.0 GB │ 56.0 GB │ 24.3% │
|
|
132
|
+
│ /System/Volumes/Preboot │ 460.4 GB │ 8.4 GB │ 56.0 GB │ 13.0% │
|
|
133
|
+
│ /System/Volumes/Update │ 460.4 GB │ 2.1 MB │ 56.0 GB │ 0.0% │
|
|
134
|
+
│ /System/Volumes/xarts │ 500.0 MB │ 6.0 MB │ 481.1 MB │ 1.2% │
|
|
135
|
+
│ /System/Volumes/iSCPreboot │ 500.0 MB │ 5.6 MB │ 481.1 MB │ 1.1% │
|
|
136
|
+
│ /System/Volumes/Hardware │ 500.0 MB │ 2.6 MB │ 481.1 MB │ 0.5% │
|
|
137
|
+
│ /System/Volumes/Data │ 460.4 GB │ 364.9 GB │ 56.0 GB │ 86.7% │
|
|
138
|
+
└────────────────────────────┴──────────┴──────────┴───────────┴───────┘
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Use% is calculated like `df`: used / (used + available). On macOS, volumes in the same APFS container share its space, so they all report the same total and the same free space (the 460.4 GB rows above, and separately the 500 MB rows). `/System/Volumes/Data` holds your files and apps and is the row that matters. The others are macOS system volumes.
|
|
142
|
+
|
|
118
143
|
### Scan
|
|
119
144
|
|
|
120
145
|
```bash
|
|
121
146
|
dustclaw scan ~/Projects
|
|
122
147
|
dustclaw scan -n 30 -d 5 # top 30, depth 5
|
|
148
|
+
dustclaw scan -d 0 # each top-level item with its total size
|
|
123
149
|
dustclaw scan --older-than 30d # only items older than 30 days
|
|
124
150
|
dustclaw scan --files-only # only files, no directories
|
|
125
151
|
dustclaw scan --dirs-only # only directories, no files
|
|
@@ -140,11 +166,16 @@ Scans known locations where dev tools and macOS pile up gigabytes:
|
|
|
140
166
|
- Every application cache in `~/Library/Caches`, broken down individually
|
|
141
167
|
- Trash and system logs
|
|
142
168
|
|
|
169
|
+
On Windows, wasteland checks the npm, pnpm, Yarn, pip, Poetry, Go, Composer, Playwright and Cypress caches in `AppData\Local`, plus the tools that use your home folder on every platform (Gradle, Maven, Cargo, Go modules, Bun, Android, Ollama, Hugging Face). The per-app cache breakdown, Trash, logs, Xcode and Docker Desktop are macOS only. On Windows, the disk usage table shows one row per drive.
|
|
170
|
+
|
|
143
171
|
```bash
|
|
144
172
|
dustclaw wasteland
|
|
145
173
|
dustclaw wasteland --node-modules ~/Projects # also find all node_modules
|
|
174
|
+
dustclaw wasteland --json # JSON output, the scan is still saved for clean
|
|
146
175
|
```
|
|
147
176
|
|
|
177
|
+
Every run saves its result for `clean`, including `--json` runs and runs that find nothing.
|
|
178
|
+
|
|
148
179
|
### Clean
|
|
149
180
|
|
|
150
181
|
Reads the last wasteland scan and removes safe items. Dry run by default.
|
|
@@ -154,9 +185,12 @@ dustclaw clean # preview what would be removed
|
|
|
154
185
|
dustclaw clean --force # delete safe items, prompts per item
|
|
155
186
|
dustclaw clean --only "gradle cache" # filter to a specific entry
|
|
156
187
|
dustclaw clean --only playwright --force
|
|
188
|
+
printf 'y\nn\n' | dustclaw clean --force # answers can be piped, one per line
|
|
157
189
|
```
|
|
158
190
|
|
|
159
|
-
|
|
191
|
+
If a delete fails, for example because of permissions, `clean` reports it and continues with the next item. Deleted items are removed from the saved scan, so running `clean` again only shows what is left.
|
|
192
|
+
|
|
193
|
+
Items marked `safe: false` (for example Docker Desktop, Android Emulators, pnpm Store, Xcode Archives and Ollama Models) are always shown but never auto-deleted. To override, add to `~/.dustclaw.json`:
|
|
160
194
|
|
|
161
195
|
```json
|
|
162
196
|
{
|
|
@@ -170,29 +204,51 @@ Items marked `safe: false` (Docker, Android Emulators, pnpm Store) are always sh
|
|
|
170
204
|
|
|
171
205
|
| Flag | Available on | What it does |
|
|
172
206
|
|------|-------------|-------------|
|
|
173
|
-
| `--json` |
|
|
207
|
+
| `--json` | overview, scan, wasteland | Output as JSON for scripting |
|
|
208
|
+
| `-p, --path <path>` | overview | Path to analyze (same as the positional path) |
|
|
174
209
|
| `--older-than <age>` | scan | Filter by age: `30d`, `6m`, `1y` |
|
|
175
210
|
| `-n, --top <count>` | overview, scan | Number of items to show |
|
|
176
|
-
| `-d, --depth <depth>` | scan | Max directory depth |
|
|
211
|
+
| `-d, --depth <depth>` | scan | Max directory depth, `0` for top-level items only |
|
|
177
212
|
| `--files-only` | scan | Show only files |
|
|
178
213
|
| `--dirs-only` | scan | Show only directories |
|
|
179
214
|
| `--node-modules <path>` | wasteland | Also search for node_modules recursively |
|
|
180
215
|
| `--force` | clean | Actually delete (prompts per item) |
|
|
181
216
|
| `--only <name>` | clean | Filter to entries matching this name |
|
|
182
217
|
|
|
218
|
+
Invalid values are rejected before any scanning starts, followed by usage examples:
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
$ dustclaw scan . -n abc
|
|
222
|
+
error: option '-n, --top <count>' argument 'abc' is invalid. Must be a whole number of 1 or more.
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Run `dustclaw --help` or `dustclaw <command> --help` for all options and examples.
|
|
226
|
+
|
|
183
227
|
## Configuration
|
|
184
228
|
|
|
185
|
-
Dustclaw reads `~/.dustclaw.json` for user overrides.
|
|
229
|
+
Defaults ship in `data/config.json`. Dustclaw reads `~/.dustclaw.json` for user overrides, and any key you set replaces the default. Command line flags such as `-n` override both.
|
|
230
|
+
|
|
231
|
+
| Key | Default | What it does |
|
|
232
|
+
|-----|---------|--------------|
|
|
233
|
+
| `overviewTopCount` | `10` | Items shown by `dustclaw` |
|
|
234
|
+
| `overviewDepth` | `1` | Directory depth for `dustclaw` |
|
|
235
|
+
| `scanTopCount` | `20` | Items shown by `scan` |
|
|
236
|
+
| `scanDepth` | `3` | Directory depth for `scan` |
|
|
237
|
+
| `minCacheSizeMb` | `50` | Smallest `~/Library/Caches` entry listed by `wasteland` (macOS) |
|
|
238
|
+
| `nodeModulesMaxDepth` | `5` | How deep `wasteland --node-modules` searches |
|
|
239
|
+
| `staleThresholdHours` | `24` | `clean` warns when the last scan is older than this |
|
|
240
|
+
| `cachesPath` | `Library/Caches` | Cache folder under your home directory, broken down per app (macOS) |
|
|
241
|
+
| `cacheSkipList` | Homebrew, CocoaPods, ... | Caches skipped in the breakdown because a known target already covers them |
|
|
242
|
+
| `opaqueDirectories` | `node_modules`, `.git` | Folders measured as one item instead of being opened |
|
|
243
|
+
| `blockSize` | `512` | Bytes per disk block when sizing files |
|
|
244
|
+
| `encoding` | `utf-8` | Encoding of the saved scan file |
|
|
245
|
+
|
|
246
|
+
Example `~/.dustclaw.json`:
|
|
186
247
|
|
|
187
248
|
```json
|
|
188
249
|
{
|
|
189
|
-
"
|
|
190
|
-
"
|
|
191
|
-
"nodeModulesMaxDepth": 5,
|
|
192
|
-
"encoding": "utf-8",
|
|
193
|
-
"scanDepth": 3,
|
|
194
|
-
"overviewTopCount": 10,
|
|
195
|
-
"scanTopCount": 20,
|
|
250
|
+
"overviewTopCount": 15,
|
|
251
|
+
"scanDepth": 4,
|
|
196
252
|
"overrides": {
|
|
197
253
|
"pnpm Store": { "safe": true }
|
|
198
254
|
},
|
|
@@ -217,25 +273,41 @@ Dustclaw writes two things to your home directory:
|
|
|
217
273
|
|
|
218
274
|
Nothing else is written. To reset state, delete `~/.dustclaw/last-scan.json`.
|
|
219
275
|
|
|
276
|
+
`~` is your home folder: `/Users/<you>` on macOS, `/home/<you>` on Linux and `C:\Users\<you>` on Windows. Paths in `~/.dustclaw.json` can start with `~/` or `~\`.
|
|
277
|
+
|
|
220
278
|
## Project Structure
|
|
221
279
|
|
|
222
280
|
```
|
|
281
|
+
.github/
|
|
282
|
+
workflows/
|
|
283
|
+
ci.yml # lint, build, tests and CLI runs on macOS, Linux and Windows
|
|
284
|
+
data/
|
|
285
|
+
config.json # default configuration (minCacheSizeMb, scanDepth, encoding, ...)
|
|
286
|
+
targets.json # known waste targets and cache display names
|
|
223
287
|
src/
|
|
224
|
-
commands/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
288
|
+
commands/
|
|
289
|
+
overview.ts # disk usage summary and top N items
|
|
290
|
+
scan.ts # deep recursive scan ranked by size
|
|
291
|
+
wasteland.ts # known space waster report
|
|
292
|
+
clean.ts # interactive cleanup from last wasteland scan
|
|
228
293
|
utils/
|
|
229
294
|
config.ts # loads and merges config.json with ~/.dustclaw.json
|
|
230
|
-
disk.ts # disk info via df
|
|
295
|
+
disk.ts # disk info via df (macOS, Linux) and statfs (Windows)
|
|
231
296
|
format.ts # table rendering and size formatting
|
|
232
297
|
scan.ts # recursive directory walker and dirSize
|
|
233
298
|
state.ts # persists last wasteland scan to ~/.dustclaw/last-scan.json
|
|
234
299
|
wasteland.ts # finds known waste targets and Library/Caches entries
|
|
235
300
|
index.ts # CLI entry point
|
|
301
|
+
tests/
|
|
302
|
+
setup/
|
|
303
|
+
isolate-home.ts # runs tests against a temporary HOME
|
|
304
|
+
cli.test.ts # runs the real command line
|
|
305
|
+
*.test.ts # Vitest suites
|
|
306
|
+
.gitattributes # LF line endings on every platform
|
|
307
|
+
CHANGELOG.md # release notes
|
|
236
308
|
```
|
|
237
309
|
|
|
238
|
-
All behavior is driven by `
|
|
310
|
+
All behavior is driven by `data/config.json` and `data/targets.json`. To add a new waste target or change defaults, edit those files. No code changes needed.
|
|
239
311
|
|
|
240
312
|
## Standing on the Shoulders of Giants
|
|
241
313
|
|
|
@@ -260,6 +332,12 @@ pnpm test
|
|
|
260
332
|
pnpm lint
|
|
261
333
|
```
|
|
262
334
|
|
|
335
|
+
Tests run with `HOME` pointed at a temporary folder, so they never read or delete your real `~/.dustclaw` data.
|
|
336
|
+
|
|
337
|
+
## Changelog
|
|
338
|
+
|
|
339
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release notes.
|
|
340
|
+
|
|
263
341
|
## Roadmap
|
|
264
342
|
|
|
265
343
|
- **spinner**: progress indicator during slow scans
|
package/data/config.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"minCacheSizeMb": 50,
|
|
3
|
+
"staleThresholdHours": 24,
|
|
4
|
+
"nodeModulesMaxDepth": 5,
|
|
5
|
+
"encoding": "utf-8",
|
|
6
|
+
"scanDepth": 3,
|
|
7
|
+
"overviewDepth": 1,
|
|
8
|
+
"overviewTopCount": 10,
|
|
9
|
+
"scanTopCount": 20,
|
|
10
|
+
"blockSize": 512,
|
|
11
|
+
"cachesPath": "Library/Caches",
|
|
12
|
+
"cacheSkipList": [
|
|
13
|
+
"Homebrew",
|
|
14
|
+
"CocoaPods",
|
|
15
|
+
"Yarn",
|
|
16
|
+
"pip",
|
|
17
|
+
"ms-playwright",
|
|
18
|
+
"Cypress",
|
|
19
|
+
"pypoetry",
|
|
20
|
+
"composer"
|
|
21
|
+
],
|
|
22
|
+
"opaqueDirectories": ["node_modules", ".git"]
|
|
23
|
+
}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"name": "Xcode DerivedData",
|
|
5
|
+
"path": "~/Library/Developer/Xcode/DerivedData",
|
|
6
|
+
"description": "Xcode build artifacts, fully regenerated on next build",
|
|
7
|
+
"platform": "mac",
|
|
8
|
+
"safe": true
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "Xcode Device Support",
|
|
12
|
+
"path": "~/Library/Developer/Xcode/iOS DeviceSupport",
|
|
13
|
+
"description": "iOS device debug symbols, re-downloaded when device connects",
|
|
14
|
+
"platform": "mac",
|
|
15
|
+
"safe": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "Xcode Archives",
|
|
19
|
+
"path": "~/Library/Developer/Xcode/Archives",
|
|
20
|
+
"description": "Archived app builds, may contain your only copy of a release",
|
|
21
|
+
"platform": "mac",
|
|
22
|
+
"safe": false
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "Xcode Simulators",
|
|
26
|
+
"path": "~/Library/Developer/CoreSimulator/Devices",
|
|
27
|
+
"description": "iOS simulator device data, can be recreated but takes time",
|
|
28
|
+
"platform": "mac",
|
|
29
|
+
"safe": false
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "npm Cache",
|
|
33
|
+
"path": "~/.npm/_cacache",
|
|
34
|
+
"description": "npm download cache, fully regenerated on next install",
|
|
35
|
+
"platform": "all",
|
|
36
|
+
"safe": true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "pnpm Store",
|
|
40
|
+
"path": "~/Library/pnpm/store",
|
|
41
|
+
"description": "pnpm content-addressable store shared across all projects",
|
|
42
|
+
"platform": "mac",
|
|
43
|
+
"safe": false
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "pnpm Store",
|
|
47
|
+
"path": "~/.local/share/pnpm/store",
|
|
48
|
+
"description": "pnpm content-addressable store shared across all projects",
|
|
49
|
+
"platform": "linux",
|
|
50
|
+
"safe": false
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "Yarn Cache",
|
|
54
|
+
"path": "~/Library/Caches/Yarn",
|
|
55
|
+
"description": "Yarn download cache, fully regenerated on next install",
|
|
56
|
+
"platform": "mac",
|
|
57
|
+
"safe": true
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "Yarn Cache",
|
|
61
|
+
"path": "~/.cache/yarn",
|
|
62
|
+
"description": "Yarn download cache, fully regenerated on next install",
|
|
63
|
+
"platform": "all",
|
|
64
|
+
"safe": true
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "Bun Cache",
|
|
68
|
+
"path": "~/.bun/install/cache",
|
|
69
|
+
"description": "Bun package cache, fully regenerated on next install",
|
|
70
|
+
"platform": "all",
|
|
71
|
+
"safe": true
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "Gradle Cache",
|
|
75
|
+
"path": "~/.gradle/caches",
|
|
76
|
+
"description": "Gradle build and dependency cache, re-downloaded on next build",
|
|
77
|
+
"platform": "all",
|
|
78
|
+
"safe": true
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "Gradle Daemon",
|
|
82
|
+
"path": "~/.gradle/daemon",
|
|
83
|
+
"description": "Gradle daemon logs and metadata",
|
|
84
|
+
"platform": "all",
|
|
85
|
+
"safe": true
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "Maven Cache",
|
|
89
|
+
"path": "~/.m2/repository",
|
|
90
|
+
"description": "Maven local repository, re-downloaded on next build",
|
|
91
|
+
"platform": "all",
|
|
92
|
+
"safe": true
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "Android Emulators",
|
|
96
|
+
"path": "~/.android/avd",
|
|
97
|
+
"description": "Android emulator images and user data",
|
|
98
|
+
"platform": "all",
|
|
99
|
+
"safe": false
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "Android Cache",
|
|
103
|
+
"path": "~/.android/cache",
|
|
104
|
+
"description": "Android SDK download cache",
|
|
105
|
+
"platform": "all",
|
|
106
|
+
"safe": true
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "Cargo Registry",
|
|
110
|
+
"path": "~/.cargo/registry",
|
|
111
|
+
"description": "Rust crate source cache, re-downloaded on next build",
|
|
112
|
+
"platform": "all",
|
|
113
|
+
"safe": true
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "Cargo Git",
|
|
117
|
+
"path": "~/.cargo/git",
|
|
118
|
+
"description": "Rust git dependency cache, re-downloaded on next build",
|
|
119
|
+
"platform": "all",
|
|
120
|
+
"safe": true
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": "pip Cache",
|
|
124
|
+
"path": "~/Library/Caches/pip",
|
|
125
|
+
"description": "pip download cache, fully regenerated on next install",
|
|
126
|
+
"platform": "mac",
|
|
127
|
+
"safe": true
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "pip Cache",
|
|
131
|
+
"path": "~/.cache/pip",
|
|
132
|
+
"description": "pip download cache, fully regenerated on next install",
|
|
133
|
+
"platform": "linux",
|
|
134
|
+
"safe": true
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"name": "pypoetry Cache",
|
|
138
|
+
"path": "~/Library/Caches/pypoetry",
|
|
139
|
+
"description": "Poetry package cache, fully regenerated on next install",
|
|
140
|
+
"platform": "mac",
|
|
141
|
+
"safe": true
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "pypoetry Cache",
|
|
145
|
+
"path": "~/.cache/pypoetry",
|
|
146
|
+
"description": "Poetry package cache, fully regenerated on next install",
|
|
147
|
+
"platform": "linux",
|
|
148
|
+
"safe": true
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "Bundler Cache",
|
|
152
|
+
"path": "~/.bundle/cache",
|
|
153
|
+
"description": "Bundler gem cache, re-downloaded on next bundle install",
|
|
154
|
+
"platform": "all",
|
|
155
|
+
"safe": true
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "CocoaPods Cache",
|
|
159
|
+
"path": "~/Library/Caches/CocoaPods",
|
|
160
|
+
"description": "CocoaPods download cache, re-downloaded on next pod install",
|
|
161
|
+
"platform": "mac",
|
|
162
|
+
"safe": true
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"name": "Go Module Cache",
|
|
166
|
+
"path": "~/go/pkg/mod",
|
|
167
|
+
"description": "Go module cache, re-downloaded on next go build",
|
|
168
|
+
"platform": "all",
|
|
169
|
+
"safe": true
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"name": "Go Build Cache",
|
|
173
|
+
"path": "~/Library/Caches/go-build",
|
|
174
|
+
"description": "Go build cache, fully regenerated on next build",
|
|
175
|
+
"platform": "mac",
|
|
176
|
+
"safe": true
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"name": "Go Build Cache",
|
|
180
|
+
"path": "~/.cache/go-build",
|
|
181
|
+
"description": "Go build cache, fully regenerated on next build",
|
|
182
|
+
"platform": "linux",
|
|
183
|
+
"safe": true
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"name": "Composer Cache",
|
|
187
|
+
"path": "~/Library/Caches/composer",
|
|
188
|
+
"description": "Composer package cache, re-downloaded on next install",
|
|
189
|
+
"platform": "mac",
|
|
190
|
+
"safe": true
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"name": "Composer Cache",
|
|
194
|
+
"path": "~/.cache/composer",
|
|
195
|
+
"description": "Composer package cache, re-downloaded on next install",
|
|
196
|
+
"platform": "linux",
|
|
197
|
+
"safe": true
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"name": "Homebrew Cache",
|
|
201
|
+
"path": "~/Library/Caches/Homebrew",
|
|
202
|
+
"description": "Homebrew downloaded package cache, re-downloaded on next install",
|
|
203
|
+
"platform": "mac",
|
|
204
|
+
"safe": true
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"name": "Docker Desktop",
|
|
208
|
+
"path": "~/Library/Containers/com.docker.docker/Data",
|
|
209
|
+
"description": "Docker images, containers, and volumes",
|
|
210
|
+
"platform": "mac",
|
|
211
|
+
"safe": false
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"name": "Playwright Browsers",
|
|
215
|
+
"path": "~/Library/Caches/ms-playwright",
|
|
216
|
+
"description": "Playwright browser binaries, re-downloaded on next install",
|
|
217
|
+
"platform": "mac",
|
|
218
|
+
"safe": true
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"name": "Playwright Browsers",
|
|
222
|
+
"path": "~/.cache/ms-playwright",
|
|
223
|
+
"description": "Playwright browser binaries, re-downloaded on next install",
|
|
224
|
+
"platform": "linux",
|
|
225
|
+
"safe": true
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"name": "Cypress Cache",
|
|
229
|
+
"path": "~/Library/Caches/Cypress",
|
|
230
|
+
"description": "Cypress browser binaries, re-downloaded on next install",
|
|
231
|
+
"platform": "mac",
|
|
232
|
+
"safe": true
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"name": "Cypress Cache",
|
|
236
|
+
"path": "~/.cache/Cypress",
|
|
237
|
+
"description": "Cypress browser binaries, re-downloaded on next install",
|
|
238
|
+
"platform": "linux",
|
|
239
|
+
"safe": true
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"name": "Puppeteer Cache",
|
|
243
|
+
"path": "~/.cache/puppeteer",
|
|
244
|
+
"description": "Puppeteer Chrome binaries, re-downloaded on next install",
|
|
245
|
+
"platform": "all",
|
|
246
|
+
"safe": true
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"name": "Terraform Plugins",
|
|
250
|
+
"path": "~/.terraform.d/plugin-cache",
|
|
251
|
+
"description": "Terraform provider plugin cache, re-downloaded on next init",
|
|
252
|
+
"platform": "all",
|
|
253
|
+
"safe": true
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"name": "Helm Cache",
|
|
257
|
+
"path": "~/Library/Caches/helm",
|
|
258
|
+
"description": "Helm chart repository cache, rebuilt by helm repo update",
|
|
259
|
+
"platform": "mac",
|
|
260
|
+
"safe": true
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"name": "Helm Cache",
|
|
264
|
+
"path": "~/.cache/helm",
|
|
265
|
+
"description": "Helm chart repository cache, rebuilt by helm repo update",
|
|
266
|
+
"platform": "linux",
|
|
267
|
+
"safe": true
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "Ollama Models",
|
|
271
|
+
"path": "~/.ollama/models",
|
|
272
|
+
"description": "Downloaded Ollama AI models, safe only if willing to re-download",
|
|
273
|
+
"platform": "all",
|
|
274
|
+
"safe": false
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
"name": "Hugging Face Cache",
|
|
278
|
+
"path": "~/.cache/huggingface",
|
|
279
|
+
"description": "Hugging Face model cache, re-downloaded on next use",
|
|
280
|
+
"platform": "all",
|
|
281
|
+
"safe": true
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
"name": "Trash",
|
|
285
|
+
"path": "~/.Trash",
|
|
286
|
+
"description": "Files waiting in Trash",
|
|
287
|
+
"platform": "mac",
|
|
288
|
+
"safe": true
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"name": "System Logs",
|
|
292
|
+
"path": "~/Library/Logs",
|
|
293
|
+
"description": "Application and system log files",
|
|
294
|
+
"platform": "mac",
|
|
295
|
+
"safe": true
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
"name": "Thumbnail Cache",
|
|
299
|
+
"path": "~/.cache/thumbnails",
|
|
300
|
+
"description": "File manager thumbnail cache, rebuilt as you browse",
|
|
301
|
+
"platform": "linux",
|
|
302
|
+
"safe": true
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"name": "npm Cache",
|
|
306
|
+
"path": "~/AppData/Local/npm-cache/_cacache",
|
|
307
|
+
"description": "npm download cache, fully regenerated on next install",
|
|
308
|
+
"platform": "windows",
|
|
309
|
+
"safe": true
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"name": "pnpm Store",
|
|
313
|
+
"path": "~/AppData/Local/pnpm/store",
|
|
314
|
+
"description": "pnpm content-addressable store shared across all projects",
|
|
315
|
+
"platform": "windows",
|
|
316
|
+
"safe": false
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"name": "Yarn Cache",
|
|
320
|
+
"path": "~/AppData/Local/Yarn/Cache",
|
|
321
|
+
"description": "Yarn download cache, fully regenerated on next install",
|
|
322
|
+
"platform": "windows",
|
|
323
|
+
"safe": true
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"name": "pip Cache",
|
|
327
|
+
"path": "~/AppData/Local/pip/Cache",
|
|
328
|
+
"description": "pip download cache, fully regenerated on next install",
|
|
329
|
+
"platform": "windows",
|
|
330
|
+
"safe": true
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"name": "pypoetry Cache",
|
|
334
|
+
"path": "~/AppData/Local/pypoetry/Cache",
|
|
335
|
+
"description": "Poetry package cache, fully regenerated on next install",
|
|
336
|
+
"platform": "windows",
|
|
337
|
+
"safe": true
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
"name": "Go Build Cache",
|
|
341
|
+
"path": "~/AppData/Local/go-build",
|
|
342
|
+
"description": "Go build cache, fully regenerated on next build",
|
|
343
|
+
"platform": "windows",
|
|
344
|
+
"safe": true
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
"name": "Composer Cache",
|
|
348
|
+
"path": "~/AppData/Local/Composer",
|
|
349
|
+
"description": "Composer package cache, re-downloaded on next install",
|
|
350
|
+
"platform": "windows",
|
|
351
|
+
"safe": true
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
"name": "Playwright Browsers",
|
|
355
|
+
"path": "~/AppData/Local/ms-playwright",
|
|
356
|
+
"description": "Playwright browser binaries, re-downloaded on next install",
|
|
357
|
+
"platform": "windows",
|
|
358
|
+
"safe": true
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
"name": "Cypress Cache",
|
|
362
|
+
"path": "~/AppData/Local/Cypress/Cache",
|
|
363
|
+
"description": "Cypress browser binaries, re-downloaded on next install",
|
|
364
|
+
"platform": "windows",
|
|
365
|
+
"safe": true
|
|
366
|
+
}
|
|
367
|
+
],
|
|
368
|
+
"cacheNames": {
|
|
369
|
+
"com.spotify.client": "Spotify",
|
|
370
|
+
"com.apple.Safari": "Safari",
|
|
371
|
+
"com.google.Chrome": "Chrome",
|
|
372
|
+
"Google": "Google/Chrome",
|
|
373
|
+
"com.docker.docker": "Docker",
|
|
374
|
+
"com.microsoft.VSCode": "VS Code",
|
|
375
|
+
"com.todesktop.230313mzl4w4u92": "Cursor",
|
|
376
|
+
"com.todesktop.230313mzl4w4u92.ShipIt": "Cursor Updates",
|
|
377
|
+
"com.google.antigravity.ShipIt": "Chrome Updates",
|
|
378
|
+
"icloudmailagent": "iCloud Mail",
|
|
379
|
+
"com.apple.callintelligenced": "Apple Call Intelligence",
|
|
380
|
+
"ms-playwright": "Playwright Browsers",
|
|
381
|
+
"ms-playwright-go": "Playwright Go Browsers",
|
|
382
|
+
"pip": "pip",
|
|
383
|
+
"Cypress": "Cypress",
|
|
384
|
+
"node-gyp": "node-gyp",
|
|
385
|
+
"typescript": "TypeScript",
|
|
386
|
+
"pnpm": "pnpm",
|
|
387
|
+
"colima": "Colima",
|
|
388
|
+
"com.openai.chat": "ChatGPT",
|
|
389
|
+
"com.openai.codex": "OpenAI Codex",
|
|
390
|
+
"ollama": "Ollama",
|
|
391
|
+
"pypoetry": "pypoetry",
|
|
392
|
+
"composer": "Composer",
|
|
393
|
+
"us.zoom.xos": "Zoom",
|
|
394
|
+
"GeoServices": "GeoServices"
|
|
395
|
+
}
|
|
396
|
+
}
|
package/dist/commands/clean.js
CHANGED
|
@@ -2,15 +2,20 @@ import { rmSync } from "node:fs";
|
|
|
2
2
|
import { createInterface } from "node:readline";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { boxTable, colorSize, formatSize } from "../utils/format.js";
|
|
5
|
-
import { loadLastScan, scanAgePath, staleThresholdMs } from "../utils/state.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { loadLastScan, scanAgePath, staleThresholdMs, writeScanState } from "../utils/state.js";
|
|
6
|
+
// One reader for the whole session. A new reader per question loses piped
|
|
7
|
+
// input: the first one buffers every line and the rest are dropped.
|
|
8
|
+
function createPrompter() {
|
|
9
|
+
const rl = createInterface({ input: process.stdin, terminal: false });
|
|
10
|
+
const lines = rl[Symbol.asyncIterator]();
|
|
11
|
+
return {
|
|
12
|
+
ask: async (question) => {
|
|
13
|
+
process.stdout.write(question);
|
|
14
|
+
const { value, done } = await lines.next();
|
|
15
|
+
return done ? "" : String(value).trim().toLowerCase();
|
|
16
|
+
},
|
|
17
|
+
close: () => rl.close(),
|
|
18
|
+
};
|
|
14
19
|
}
|
|
15
20
|
function deleteEntry(entry) {
|
|
16
21
|
rmSync(entry.path, { recursive: true, force: true });
|
|
@@ -60,16 +65,33 @@ export async function clean(opts) {
|
|
|
60
65
|
}
|
|
61
66
|
console.log(chalk.red.bold(" WARNING: Deletion is permanent. There is no undo.\n"));
|
|
62
67
|
let freed = 0;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
const deleted = new Set();
|
|
69
|
+
const prompter = createPrompter();
|
|
70
|
+
try {
|
|
71
|
+
for (const entry of safe) {
|
|
72
|
+
const answer = await prompter.ask(` Delete ${chalk.bold(entry.name)} (${formatSize(entry.size)})? [y/N] `);
|
|
73
|
+
if (answer !== "y") {
|
|
74
|
+
console.log(chalk.gray(` Skipped: ${entry.path}`));
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
deleteEntry(entry);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.log(chalk.red(` Failed: ${entry.path} (${err.message})`));
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
deleted.add(entry.path);
|
|
67
85
|
freed += entry.size;
|
|
68
86
|
console.log(chalk.green(` Deleted: ${entry.path}`));
|
|
69
87
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
prompter.close();
|
|
91
|
+
}
|
|
92
|
+
// Keep the original scan time so the stale warning stays accurate.
|
|
93
|
+
if (deleted.size > 0) {
|
|
94
|
+
writeScanState({ ...state, entries: state.entries.filter((e) => !deleted.has(e.path)) });
|
|
73
95
|
}
|
|
74
96
|
console.log(chalk.bold(`\n Freed: ${colorSize(freed)}\n`));
|
|
75
97
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { resolveConfig } from "../utils/config.js";
|
|
4
|
-
import { getDiskInfo } from "../utils/disk.js";
|
|
4
|
+
import { getDiskInfo, usedRatio } from "../utils/disk.js";
|
|
5
5
|
import { boxTable, colorSize, formatPercent, formatSize } from "../utils/format.js";
|
|
6
6
|
import { scanDir } from "../utils/scan.js";
|
|
7
7
|
export function overview(opts) {
|
|
8
8
|
const { overviewDepth } = resolveConfig();
|
|
9
|
-
const count =
|
|
9
|
+
const count = opts.top;
|
|
10
10
|
const targetPath = resolve(opts.path);
|
|
11
11
|
const disks = getDiskInfo();
|
|
12
12
|
const entries = scanDir(targetPath, { depth: overviewDepth });
|
|
@@ -33,7 +33,7 @@ export function overview(opts) {
|
|
|
33
33
|
formatSize(d.total),
|
|
34
34
|
colorSize(d.used),
|
|
35
35
|
colorSize(d.available),
|
|
36
|
-
formatPercent(d
|
|
36
|
+
formatPercent(usedRatio(d)),
|
|
37
37
|
]);
|
|
38
38
|
console.log(boxTable(["Mount", "Total", "Used", "Available", "Use%"], diskRows));
|
|
39
39
|
console.log(chalk.bold(`\n Top ${count} in ${targetPath}\n`));
|
package/dist/commands/scan.d.ts
CHANGED
package/dist/commands/scan.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { boxTable, colorSize } from "../utils/format.js";
|
|
4
|
-
import {
|
|
4
|
+
import { scanDir } from "../utils/scan.js";
|
|
5
5
|
export function scan(path, opts) {
|
|
6
6
|
const targetPath = resolve(path ?? ".");
|
|
7
|
-
const count =
|
|
7
|
+
const count = opts.top;
|
|
8
8
|
const scanOpts = {
|
|
9
|
-
depth:
|
|
9
|
+
depth: opts.depth,
|
|
10
10
|
filesOnly: opts.filesOnly,
|
|
11
11
|
dirsOnly: opts.dirsOnly,
|
|
12
|
+
olderThan: opts.olderThan,
|
|
12
13
|
};
|
|
13
|
-
if (opts.olderThan) {
|
|
14
|
-
scanOpts.olderThan = parseAge(opts.olderThan);
|
|
15
|
-
}
|
|
16
14
|
const entries = scanDir(targetPath, scanOpts);
|
|
17
15
|
const sorted = entries.sort((a, b) => b.size - a.size).slice(0, count);
|
|
18
16
|
if (opts.json) {
|
|
@@ -12,6 +12,8 @@ export async function wasteland(opts) {
|
|
|
12
12
|
}
|
|
13
13
|
const allEntries = [...waste, ...nmEntries];
|
|
14
14
|
const totalSize = allEntries.reduce((sum, e) => sum + e.size, 0);
|
|
15
|
+
// Always saved, even for --json or an empty result, so clean never acts on an older scan.
|
|
16
|
+
saveLastScan(allEntries);
|
|
15
17
|
if (opts.json) {
|
|
16
18
|
console.log(JSON.stringify({
|
|
17
19
|
total: totalSize,
|
|
@@ -28,7 +30,6 @@ export async function wasteland(opts) {
|
|
|
28
30
|
console.log(chalk.green("\n No wasteland found. Your disk is clean!\n"));
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
31
|
-
saveLastScan(allEntries);
|
|
32
33
|
console.log(chalk.bold("\n Wasteland Report\n"));
|
|
33
34
|
if (waste.length > 0) {
|
|
34
35
|
console.log(chalk.bold(" Known space wasters:\n"));
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,70 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { Command } from "commander";
|
|
4
|
+
import { Command, InvalidArgumentError } from "commander";
|
|
5
5
|
import { clean } from "./commands/clean.js";
|
|
6
6
|
import { overview } from "./commands/overview.js";
|
|
7
7
|
import { scan } from "./commands/scan.js";
|
|
8
8
|
import { wasteland } from "./commands/wasteland.js";
|
|
9
9
|
import { resolveConfig } from "./utils/config.js";
|
|
10
|
+
import { parseAge } from "./utils/scan.js";
|
|
11
|
+
function intOption(min) {
|
|
12
|
+
return (value) => {
|
|
13
|
+
const n = Number(value);
|
|
14
|
+
if (!Number.isInteger(n) || n < min) {
|
|
15
|
+
throw new InvalidArgumentError(`Must be a whole number of ${min} or more.`);
|
|
16
|
+
}
|
|
17
|
+
return n;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// Depth 0 is valid: each top-level item is listed with its total size.
|
|
21
|
+
const countOption = intOption(1);
|
|
22
|
+
const depthOption = intOption(0);
|
|
23
|
+
function ageOption(value) {
|
|
24
|
+
try {
|
|
25
|
+
return parseAge(value);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
throw new InvalidArgumentError(err.message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
10
31
|
const { version } = JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf-8"));
|
|
11
32
|
const { overviewTopCount, scanTopCount, scanDepth } = resolveConfig();
|
|
12
33
|
const program = new Command();
|
|
13
34
|
program
|
|
14
35
|
.name("dustclaw")
|
|
15
36
|
.description("Disk space monitoring, analysis, and cleanup CLI")
|
|
16
|
-
.version(version)
|
|
37
|
+
.version(version)
|
|
38
|
+
.showHelpAfterError(`
|
|
39
|
+
Examples:
|
|
40
|
+
dustclaw ../.. overview of a path
|
|
41
|
+
dustclaw scan ~/Projects -n 20 top 20 largest items in a path
|
|
42
|
+
dustclaw wasteland find caches and build junk
|
|
43
|
+
dustclaw clean dry run cleanup
|
|
44
|
+
|
|
45
|
+
Run dustclaw <command> --help for all options.`)
|
|
46
|
+
.addHelpText("after", `
|
|
47
|
+
Examples:
|
|
48
|
+
dustclaw overview of the current directory
|
|
49
|
+
dustclaw ../.. overview of a path
|
|
50
|
+
dustclaw scan ~/Projects -n 20 top 20 largest items in a path
|
|
51
|
+
dustclaw scan --older-than 6m items not modified in 6 months
|
|
52
|
+
dustclaw wasteland find caches and build junk
|
|
53
|
+
dustclaw clean dry run cleanup
|
|
54
|
+
dustclaw clean --force delete safe items, prompts per item`);
|
|
17
55
|
program
|
|
18
|
-
.command("overview", { isDefault: true })
|
|
19
|
-
.description(
|
|
20
|
-
.option("-n, --top <count>", "Number of top items to show",
|
|
21
|
-
.option("-p, --path <path>", "Path to analyze", ".")
|
|
56
|
+
.command("overview [path]", { isDefault: true })
|
|
57
|
+
.description(`Quick overview: disk usage, free space, top ${overviewTopCount} biggest items`)
|
|
58
|
+
.option("-n, --top <count>", "Number of top items to show", countOption, overviewTopCount)
|
|
59
|
+
.option("-p, --path <path>", "Path to analyze (same as the positional path)", ".")
|
|
22
60
|
.option("--json", "Output as JSON")
|
|
23
|
-
.action(overview);
|
|
61
|
+
.action((path, opts) => overview({ ...opts, path: path ?? opts.path }));
|
|
24
62
|
program
|
|
25
63
|
.command("scan [path]")
|
|
26
64
|
.description("Deep scan: ranked list of largest files and folders")
|
|
27
|
-
.option("-n, --top <count>", "Number of top items to show",
|
|
28
|
-
.option("-d, --depth <depth>", "Max directory depth",
|
|
29
|
-
.option("--older-than <age>", "Filter by age (e.g. 30d, 6m, 1y)")
|
|
65
|
+
.option("-n, --top <count>", "Number of top items to show", countOption, scanTopCount)
|
|
66
|
+
.option("-d, --depth <depth>", "Max directory depth", depthOption, scanDepth)
|
|
67
|
+
.option("--older-than <age>", "Filter by age (e.g. 30d, 6m, 1y)", ageOption)
|
|
30
68
|
.option("--files-only", "Show only files, not directories")
|
|
31
69
|
.option("--dirs-only", "Show only directories, not files")
|
|
32
70
|
.option("--json", "Output as JSON")
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export type Platform = "mac" | "linux" | "windows";
|
|
2
|
+
export declare function currentPlatform(): Platform;
|
|
1
3
|
export interface TargetDef {
|
|
2
4
|
name: string;
|
|
3
5
|
path: string;
|
|
4
6
|
description: string;
|
|
5
|
-
platform:
|
|
7
|
+
platform: Platform | "all";
|
|
6
8
|
safe: boolean;
|
|
7
9
|
}
|
|
8
10
|
export interface DustclawConfig {
|
package/dist/utils/config.js
CHANGED
|
@@ -2,10 +2,22 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
export function currentPlatform() {
|
|
6
|
+
if (process.platform === "darwin")
|
|
7
|
+
return "mac";
|
|
8
|
+
if (process.platform === "win32")
|
|
9
|
+
return "windows";
|
|
10
|
+
return "linux";
|
|
11
|
+
}
|
|
5
12
|
const USER_CONFIG_PATH = join(homedir(), ".dustclaw.json");
|
|
13
|
+
// Bundled defaults live in <package root>/data. This file runs from either
|
|
14
|
+
// src/utils (dev, tests) or dist/utils (build), both two levels below the root.
|
|
15
|
+
const DATA_DIR = fileURLToPath(new URL("../../data/", import.meta.url));
|
|
16
|
+
function loadDataFile(name) {
|
|
17
|
+
return JSON.parse(readFileSync(join(DATA_DIR, name), "utf-8"));
|
|
18
|
+
}
|
|
6
19
|
function loadDefaultConfig() {
|
|
7
|
-
|
|
8
|
-
return JSON.parse(readFileSync(file, "utf-8"));
|
|
20
|
+
return loadDataFile("config.json");
|
|
9
21
|
}
|
|
10
22
|
function loadUserConfig() {
|
|
11
23
|
if (!existsSync(USER_CONFIG_PATH))
|
|
@@ -17,7 +29,15 @@ function loadUserConfig() {
|
|
|
17
29
|
return {};
|
|
18
30
|
}
|
|
19
31
|
}
|
|
32
|
+
// Config is read once per process. The scanners call resolveConfig() for every
|
|
33
|
+
// directory they visit, so re-reading the JSON files each time is very slow.
|
|
34
|
+
let cachedConfig;
|
|
35
|
+
let cachedTargetsFile;
|
|
20
36
|
export function resolveConfig() {
|
|
37
|
+
cachedConfig ??= buildConfig();
|
|
38
|
+
return cachedConfig;
|
|
39
|
+
}
|
|
40
|
+
function buildConfig() {
|
|
21
41
|
const defaults = loadDefaultConfig();
|
|
22
42
|
const user = loadUserConfig();
|
|
23
43
|
const minCacheSizeMb = user.minCacheSizeMb ?? defaults.minCacheSizeMb;
|
|
@@ -40,26 +60,34 @@ export function resolveConfig() {
|
|
|
40
60
|
};
|
|
41
61
|
}
|
|
42
62
|
function loadTargetsFile() {
|
|
43
|
-
|
|
44
|
-
return
|
|
63
|
+
cachedTargetsFile ??= loadDataFile("targets.json");
|
|
64
|
+
return cachedTargetsFile;
|
|
45
65
|
}
|
|
46
66
|
export function resolveCacheNames() {
|
|
47
67
|
return loadTargetsFile().cacheNames;
|
|
48
68
|
}
|
|
69
|
+
// join, not string replace, so Windows paths get backslashes throughout.
|
|
70
|
+
function expandHome(path) {
|
|
71
|
+
if (path === "~")
|
|
72
|
+
return homedir();
|
|
73
|
+
if (path.startsWith("~/") || path.startsWith("~\\"))
|
|
74
|
+
return join(homedir(), path.slice(2));
|
|
75
|
+
return path;
|
|
76
|
+
}
|
|
49
77
|
export function resolveTargets() {
|
|
50
|
-
const platform =
|
|
78
|
+
const platform = currentPlatform();
|
|
51
79
|
const base = loadTargetsFile().targets.filter((t) => t.platform === platform || t.platform === "all");
|
|
52
80
|
const user = loadUserConfig();
|
|
53
81
|
const overrides = user.overrides ?? {};
|
|
54
82
|
const merged = base.map((t) => {
|
|
55
|
-
const expanded = { ...t, path: t.path
|
|
83
|
+
const expanded = { ...t, path: expandHome(t.path) };
|
|
56
84
|
return overrides[t.name] !== undefined
|
|
57
85
|
? { ...expanded, safe: overrides[t.name].safe }
|
|
58
86
|
: expanded;
|
|
59
87
|
});
|
|
60
88
|
const custom = (user.targets ?? []).map((t) => ({
|
|
61
89
|
name: t.name,
|
|
62
|
-
path: t.path
|
|
90
|
+
path: expandHome(t.path),
|
|
63
91
|
description: t.description ?? "",
|
|
64
92
|
platform: "all",
|
|
65
93
|
safe: t.safe,
|
package/dist/utils/disk.d.ts
CHANGED
package/dist/utils/disk.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
|
+
import { statfsSync } from "node:fs";
|
|
2
3
|
import { platform } from "node:os";
|
|
3
4
|
export function getDiskInfo() {
|
|
4
5
|
const os = platform();
|
|
6
|
+
if (os === "win32")
|
|
7
|
+
return getWindowsDiskInfo();
|
|
5
8
|
if (os !== "darwin" && os !== "linux") {
|
|
6
9
|
throw new Error(`Unsupported platform: ${os}`);
|
|
7
10
|
}
|
|
@@ -27,3 +30,29 @@ export function getDiskInfo() {
|
|
|
27
30
|
}
|
|
28
31
|
return disks;
|
|
29
32
|
}
|
|
33
|
+
// Windows has no df. statfs reads each drive's volume information directly.
|
|
34
|
+
// A: and B: are skipped because they are reserved for floppy drives.
|
|
35
|
+
function getWindowsDiskInfo() {
|
|
36
|
+
const disks = [];
|
|
37
|
+
for (const letter of "CDEFGHIJKLMNOPQRSTUVWXYZ") {
|
|
38
|
+
const root = `${letter}:\\`;
|
|
39
|
+
try {
|
|
40
|
+
const fs = statfsSync(root);
|
|
41
|
+
disks.push({
|
|
42
|
+
filesystem: `${letter}:`,
|
|
43
|
+
total: fs.blocks * fs.bsize,
|
|
44
|
+
used: (fs.blocks - fs.bfree) * fs.bsize,
|
|
45
|
+
available: fs.bavail * fs.bsize,
|
|
46
|
+
mountpoint: root,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch { }
|
|
50
|
+
}
|
|
51
|
+
return disks;
|
|
52
|
+
}
|
|
53
|
+
// Same as df's Capacity column. Dividing by total is wrong on APFS, where every
|
|
54
|
+
// volume reports the whole shared container as its total.
|
|
55
|
+
export function usedRatio(disk) {
|
|
56
|
+
const usable = disk.used + disk.available;
|
|
57
|
+
return usable === 0 ? 0 : disk.used / usable;
|
|
58
|
+
}
|
package/dist/utils/format.js
CHANGED
|
@@ -36,7 +36,7 @@ function padEndVis(str, width) {
|
|
|
36
36
|
}
|
|
37
37
|
export function boxTable(headers, rows) {
|
|
38
38
|
const colWidths = headers.map((h, i) => Math.max(visLen(h), ...rows.map((r) => visLen(r[i] ?? ""))));
|
|
39
|
-
const sep =
|
|
39
|
+
const sep = `├${colWidths.map((w) => "─".repeat(w + 2)).join("┼")}┤`;
|
|
40
40
|
const top = `┌${colWidths.map((w) => "─".repeat(w + 2)).join("┬")}┐`;
|
|
41
41
|
const bot = `└${colWidths.map((w) => "─".repeat(w + 2)).join("┴")}┘`;
|
|
42
42
|
const fmtRow = (cells) => `│${cells.map((c, i) => ` ${padEndVis(c, colWidths[i])} `).join("│")}│`;
|
package/dist/utils/scan.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync, statSync } from "node:fs";
|
|
1
|
+
import { lstatSync, readdirSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { resolveConfig } from "./config.js";
|
|
4
4
|
export function scanDir(root, opts = {}, currentDepth = 0) {
|
|
@@ -63,7 +63,11 @@ export function scanDir(root, opts = {}, currentDepth = 0) {
|
|
|
63
63
|
return entries;
|
|
64
64
|
}
|
|
65
65
|
export function dirSize(dirPath) {
|
|
66
|
-
|
|
66
|
+
return sumDir(dirPath, resolveConfig().blockSize);
|
|
67
|
+
}
|
|
68
|
+
// lstat, not stat: symlinks are not followed, matching du. Following them
|
|
69
|
+
// double-counts linked data and loops forever on a link to a parent folder.
|
|
70
|
+
function sumDir(dirPath, blockSize) {
|
|
67
71
|
let total = 0;
|
|
68
72
|
let items;
|
|
69
73
|
try {
|
|
@@ -75,12 +79,12 @@ export function dirSize(dirPath) {
|
|
|
75
79
|
for (const name of items) {
|
|
76
80
|
const fullPath = join(dirPath, name);
|
|
77
81
|
try {
|
|
78
|
-
const stat =
|
|
82
|
+
const stat = lstatSync(fullPath);
|
|
79
83
|
if (stat.isFile()) {
|
|
80
84
|
total += stat.blocks * blockSize;
|
|
81
85
|
}
|
|
82
86
|
else if (stat.isDirectory()) {
|
|
83
|
-
total +=
|
|
87
|
+
total += sumDir(fullPath, blockSize);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
catch { }
|
package/dist/utils/state.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface ScanState {
|
|
|
4
4
|
entries: WasteEntry[];
|
|
5
5
|
}
|
|
6
6
|
export declare function saveLastScan(entries: WasteEntry[]): void;
|
|
7
|
+
export declare function writeScanState(state: ScanState): void;
|
|
7
8
|
export declare function loadLastScan(): ScanState | null;
|
|
8
9
|
export declare function scanAgePath(state: ScanState): number;
|
|
9
10
|
export declare function staleThresholdMs(): number;
|
package/dist/utils/state.js
CHANGED
|
@@ -5,12 +5,11 @@ import { resolveConfig } from "./config.js";
|
|
|
5
5
|
const STATE_DIR = join(homedir(), ".dustclaw");
|
|
6
6
|
const SCAN_FILE = join(STATE_DIR, "last-scan.json");
|
|
7
7
|
export function saveLastScan(entries) {
|
|
8
|
+
writeScanState({ scannedAt: new Date().toISOString(), entries });
|
|
9
|
+
}
|
|
10
|
+
export function writeScanState(state) {
|
|
8
11
|
const { encoding } = resolveConfig();
|
|
9
12
|
mkdirSync(STATE_DIR, { recursive: true });
|
|
10
|
-
const state = {
|
|
11
|
-
scannedAt: new Date().toISOString(),
|
|
12
|
-
entries,
|
|
13
|
-
};
|
|
14
13
|
writeFileSync(SCAN_FILE, JSON.stringify(state, null, 2), encoding);
|
|
15
14
|
}
|
|
16
15
|
export function loadLastScan() {
|
package/dist/utils/wasteland.js
CHANGED
|
@@ -68,16 +68,14 @@ export function findWaste() {
|
|
|
68
68
|
return results.sort((a, b) => b.size - a.size);
|
|
69
69
|
}
|
|
70
70
|
export function findNodeModules(root, maxDepth) {
|
|
71
|
-
const
|
|
71
|
+
const { nodeModulesMaxDepth, opaqueDirectories } = resolveConfig();
|
|
72
72
|
const results = [];
|
|
73
|
-
searchNodeModules(root, results, 0,
|
|
73
|
+
searchNodeModules(root, results, 0, maxDepth ?? nodeModulesMaxDepth, new Set(opaqueDirectories));
|
|
74
74
|
return results.sort((a, b) => b.size - a.size);
|
|
75
75
|
}
|
|
76
|
-
function searchNodeModules(dir, results, depth, maxDepth) {
|
|
76
|
+
function searchNodeModules(dir, results, depth, maxDepth, opaqueSet) {
|
|
77
77
|
if (depth > maxDepth)
|
|
78
78
|
return;
|
|
79
|
-
const { opaqueDirectories } = resolveConfig();
|
|
80
|
-
const opaqueSet = new Set(opaqueDirectories);
|
|
81
79
|
let items;
|
|
82
80
|
try {
|
|
83
81
|
items = readdirSync(dir);
|
|
@@ -107,7 +105,7 @@ function searchNodeModules(dir, results, depth, maxDepth) {
|
|
|
107
105
|
try {
|
|
108
106
|
const stat = statSync(fullPath);
|
|
109
107
|
if (stat.isDirectory()) {
|
|
110
|
-
searchNodeModules(fullPath, results, depth + 1, maxDepth);
|
|
108
|
+
searchNodeModules(fullPath, results, depth + 1, maxDepth, opaqueSet);
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
catch { }
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dustclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Disk space monitoring, analysis, and cleanup CLI",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22.12.0"
|
|
7
|
+
},
|
|
5
8
|
"homepage": "https://github.com/psandis/dustclaw",
|
|
6
9
|
"type": "module",
|
|
7
10
|
"repository": {
|
|
@@ -13,6 +16,7 @@
|
|
|
13
16
|
},
|
|
14
17
|
"files": [
|
|
15
18
|
"dist",
|
|
19
|
+
"data",
|
|
16
20
|
"README.md",
|
|
17
21
|
"LICENSE",
|
|
18
22
|
"assets/dustclaw.png"
|
|
@@ -37,22 +41,19 @@
|
|
|
37
41
|
"license": "MIT",
|
|
38
42
|
"packageManager": "pnpm@10.12.1",
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"commander": "^14.0.3"
|
|
44
|
+
"chalk": "^6.0.1",
|
|
45
|
+
"commander": "^15.0.0"
|
|
43
46
|
},
|
|
44
47
|
"pnpm": {
|
|
45
48
|
"onlyBuiltDependencies": [
|
|
46
|
-
"better-sqlite3",
|
|
47
49
|
"esbuild"
|
|
48
50
|
]
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@biomejs/biome": "^2.
|
|
52
|
-
"@types/
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"vitest": "^4.1.1"
|
|
53
|
+
"@biomejs/biome": "^2.5.15",
|
|
54
|
+
"@types/node": "^26.6.5",
|
|
55
|
+
"tsx": "^4.23.15",
|
|
56
|
+
"typescript": "^7.0.2",
|
|
57
|
+
"vitest": "^5.0.3"
|
|
57
58
|
}
|
|
58
59
|
}
|