dustclaw 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Petri Sandholm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # Dustclaw 🦀
2
+
3
+ Find out what is eating your disk space and where the bloat is hiding.
4
+
5
+ <p align="center">
6
+ <img src="assets/dustclaw.png" alt="Dustclaw" width="400">
7
+ </p>
8
+
9
+ `dustclaw` answers the question every developer asks once a month: where did all my disk space go?
10
+
11
+ It scans your disk, shows you what is big, and knows where macOS and dev tools hide gigabytes of caches, build artifacts, and forgotten dependencies. Plain table output by default. Use `--json` for scripts and automation.
12
+
13
+ ## Why Dustclaw Exists
14
+
15
+ There are excellent disk space tools out there — [dust](https://github.com/bootandy/dust) and [dua-cli](https://github.com/Byron/dua-cli) are blazing fast Rust scanners, [duf](https://github.com/muesli/duf) is a beautiful Go replacement for `df`, and [npkill](https://github.com/voidcosmos/npkill) is great for cleaning up `node_modules`.
16
+
17
+ Dustclaw takes a different angle. It focuses on dev-aware scanning and lives in the npm ecosystem:
18
+
19
+ - **Dev-aware scanning** — knows about Xcode DerivedData, Docker data, Homebrew caches, Playwright browsers, Gradle, Maven, Cargo, and dozens of other known space wasters
20
+ - **Cache breakdown** — shows every application cache individually instead of one mystery lump
21
+ - **npm-installable** — `npx dustclaw` and you are running
22
+
23
+ ## 10-Second Proof
24
+
25
+ ```bash
26
+ npx dustclaw wasteland
27
+ ```
28
+
29
+ ```text
30
+ Wasteland Report
31
+
32
+ Known space wasters:
33
+
34
+ ┌────────────────────────────────┬───────────┬──────────────────────────────────────────────────┐
35
+ │ Name │ Size │ Path │
36
+ ┼────────────────────────────────┼───────────┼──────────────────────────────────────────────────┼
37
+ │ Docker Desktop │ 460.5 GB │ ~/Library/Containers/com.docker.docker/Data │
38
+ │ npm Cache │ 14.1 GB │ ~/.npm/_cacache │
39
+ │ Cache: Cursor Updates │ 7.8 GB │ ~/Library/Caches/com.todesktop.230313mzl4w4u92 │
40
+ │ Android Emulators │ 7.8 GB │ ~/.android/avd │
41
+ │ Cache: Google/Chrome │ 3.9 GB │ ~/Library/Caches/Google │
42
+ │ Homebrew Cache │ 3.4 GB │ ~/Library/Caches/Homebrew │
43
+ │ Gradle Cache │ 2.5 GB │ ~/.gradle/caches │
44
+ │ pnpm Store │ 2.4 GB │ ~/Library/pnpm/store │
45
+ │ Cache: Playwright Browsers │ 2.2 GB │ ~/Library/Caches/ms-playwright │
46
+ │ Cache: Spotify │ 1.3 GB │ ~/Library/Caches/com.spotify.client │
47
+ └────────────────────────────────┴───────────┴──────────────────────────────────────────────────┘
48
+
49
+ Total reclaimable: 515.1 GB
50
+ ```
51
+
52
+ That is real output from a real machine.
53
+
54
+ ## Commands
55
+
56
+ | Command | What it does |
57
+ |---------|-------------|
58
+ | `dustclaw` | Quick overview — disk usage, free space, top 10 biggest items |
59
+ | `dustclaw scan [path]` | Deep scan — ranked list of largest files and folders |
60
+ | `dustclaw wasteland` | Finds known space wasters — caches, build artifacts, Trash, Docker |
61
+
62
+ ## Requirements
63
+
64
+ - Node.js 18+
65
+ - macOS or Linux
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ npm install -g dustclaw
71
+ ```
72
+
73
+ Or run without installing:
74
+
75
+ ```bash
76
+ npx dustclaw
77
+ ```
78
+
79
+ ## Usage
80
+
81
+ ### Overview (default)
82
+
83
+ ```bash
84
+ dustclaw
85
+ dustclaw -n 20 # show top 20 instead of 10
86
+ dustclaw -p ~/Projects # scan a specific path
87
+ ```
88
+
89
+ ### Scan
90
+
91
+ ```bash
92
+ dustclaw scan ~/Projects
93
+ dustclaw scan -n 30 -d 5 # top 30, depth 5
94
+ dustclaw scan --older-than 30d # only items older than 30 days
95
+ dustclaw scan --files-only # only files, no directories
96
+ dustclaw scan --dirs-only # only directories, no files
97
+ ```
98
+
99
+ ### Wasteland
100
+
101
+ Scans known locations where dev tools and macOS pile up gigabytes:
102
+
103
+ - Xcode DerivedData, archives, device support
104
+ - Docker Desktop data
105
+ - Homebrew, npm, pnpm, Yarn, pip caches
106
+ - Gradle, Maven, Cargo caches
107
+ - Android emulators, iOS simulators
108
+ - Playwright and Cypress browsers
109
+ - Every application cache in `~/Library/Caches`, broken down individually
110
+ - Trash
111
+
112
+ ```bash
113
+ dustclaw wasteland
114
+ dustclaw wasteland --node-modules ~/Projects # also find all node_modules
115
+ ```
116
+
117
+ ## Flags
118
+
119
+ | Flag | Available on | What it does |
120
+ |------|-------------|-------------|
121
+ | `--json` | all commands | Output as JSON for scripting |
122
+ | `--older-than <age>` | scan | Filter by age — `30d`, `6m`, `1y` |
123
+ | `-n, --top <count>` | overview, scan | Number of items to show |
124
+ | `-d, --depth <depth>` | scan | Max directory depth |
125
+ | `--files-only` | scan | Show only files |
126
+ | `--dirs-only` | scan | Show only directories |
127
+ | `--node-modules <path>` | wasteland | Also search for node_modules recursively |
128
+
129
+ ## Standing on the Shoulders of Giants
130
+
131
+ Dustclaw exists because of the excellent work done by these projects:
132
+
133
+ - [dust](https://github.com/bootandy/dust) — fast, intuitive disk usage viewer written in Rust. If raw scanning speed is what you need, dust is hard to beat.
134
+ - [duf](https://github.com/muesli/duf) — a modern `df` replacement written in Go. Beautiful output and JSON support.
135
+ - [dua-cli](https://github.com/Byron/dua-cli) — parallel disk usage analyzer with interactive deletion, written in Rust. Maxes out your SSD.
136
+ - [npkill](https://github.com/voidcosmos/npkill) — finds and deletes `node_modules` folders. Simple, effective, widely used.
137
+ - [space-hogs](https://github.com/dylang/space-hogs) — discovers surprisingly large directories from the command line.
138
+
139
+ These tools do what they do very well. Dustclaw does not try to outperform them on raw speed. Instead, it brings dev-aware scanning and cache breakdown to the npm ecosystem — things those tools were not built to do.
140
+
141
+ ## Development
142
+
143
+ ```bash
144
+ git clone https://github.com/psandis/dustclaw.git
145
+ cd dustclaw
146
+ pnpm install
147
+ pnpm build
148
+ pnpm test
149
+ pnpm lint
150
+ ```
151
+
152
+ ## Roadmap
153
+
154
+ - **watch** — track disk usage over time, spot trends before you run out of space
155
+ - **duplicates** — find duplicate large files by hash
156
+ - **clean** — interactive cleanup with dry-run safety
157
+
158
+ ## Related
159
+
160
+ - 🦀 [Feedclaw](https://github.com/psandis/feedclaw) — RSS/Atom feed reader and AI digest CLI
161
+ - 🦀 [Driftclaw](https://github.com/psandis/driftclaw) — Deployment drift detection across environments
162
+ - 🦀 [OpenClaw](https://github.com/openclaw/openclaw) — Personal AI assistant
163
+
164
+ ## License
165
+
166
+ See [MIT](./LICENSE)
Binary file
@@ -0,0 +1,7 @@
1
+ interface OverviewOptions {
2
+ top: string;
3
+ path: string;
4
+ json?: boolean;
5
+ }
6
+ export declare function overview(opts: OverviewOptions): void;
7
+ export {};
@@ -0,0 +1,46 @@
1
+ import { resolve } from "node:path";
2
+ import chalk from "chalk";
3
+ import { getDiskInfo } from "../utils/disk.js";
4
+ import { boxTable, colorSize, formatPercent, formatSize } from "../utils/format.js";
5
+ import { scanDir } from "../utils/scan.js";
6
+ export function overview(opts) {
7
+ const count = Number.parseInt(opts.top, 10);
8
+ const targetPath = resolve(opts.path);
9
+ const disks = getDiskInfo();
10
+ const entries = scanDir(targetPath, { depth: 1 });
11
+ const topEntries = entries.sort((a, b) => b.size - a.size).slice(0, count);
12
+ if (opts.json) {
13
+ console.log(JSON.stringify({
14
+ disks: disks.map((d) => ({
15
+ ...d,
16
+ total: d.total,
17
+ used: d.used,
18
+ available: d.available,
19
+ })),
20
+ topItems: topEntries.map((e) => ({
21
+ path: e.path,
22
+ size: e.size,
23
+ type: e.isDirectory ? "directory" : "file",
24
+ })),
25
+ }, null, 2));
26
+ return;
27
+ }
28
+ console.log(chalk.bold("\n Disk Usage\n"));
29
+ const diskRows = disks.map((d) => [
30
+ d.mountpoint,
31
+ formatSize(d.total),
32
+ colorSize(d.used),
33
+ colorSize(d.available),
34
+ formatPercent(d.used / d.total),
35
+ ]);
36
+ console.log(boxTable(["Mount", "Total", "Used", "Available", "Use%"], diskRows));
37
+ console.log(chalk.bold(`\n Top ${count} in ${targetPath}\n`));
38
+ const itemRows = topEntries.map((e, i) => [
39
+ String(i + 1),
40
+ colorSize(e.size),
41
+ e.isDirectory ? "dir" : "file",
42
+ e.path,
43
+ ]);
44
+ console.log(boxTable(["#", "Size", "Type", "Path"], itemRows));
45
+ console.log();
46
+ }
@@ -0,0 +1,10 @@
1
+ interface ScanCommandOptions {
2
+ top: string;
3
+ depth: string;
4
+ olderThan?: string;
5
+ filesOnly?: boolean;
6
+ dirsOnly?: boolean;
7
+ json?: boolean;
8
+ }
9
+ export declare function scan(path: string | undefined, opts: ScanCommandOptions): void;
10
+ export {};
@@ -0,0 +1,40 @@
1
+ import { resolve } from "node:path";
2
+ import chalk from "chalk";
3
+ import { boxTable, colorSize } from "../utils/format.js";
4
+ import { parseAge, scanDir } from "../utils/scan.js";
5
+ export function scan(path, opts) {
6
+ const targetPath = resolve(path ?? ".");
7
+ const count = Number.parseInt(opts.top, 10);
8
+ const scanOpts = {
9
+ depth: Number.parseInt(opts.depth, 10),
10
+ filesOnly: opts.filesOnly,
11
+ dirsOnly: opts.dirsOnly,
12
+ };
13
+ if (opts.olderThan) {
14
+ scanOpts.olderThan = parseAge(opts.olderThan);
15
+ }
16
+ const entries = scanDir(targetPath, scanOpts);
17
+ const sorted = entries.sort((a, b) => b.size - a.size).slice(0, count);
18
+ if (opts.json) {
19
+ console.log(JSON.stringify(sorted.map((e) => ({
20
+ path: e.path,
21
+ size: e.size,
22
+ type: e.isDirectory ? "directory" : "file",
23
+ modified: e.mtime.toISOString(),
24
+ })), null, 2));
25
+ return;
26
+ }
27
+ if (sorted.length === 0) {
28
+ console.log(chalk.yellow("\n No items found.\n"));
29
+ return;
30
+ }
31
+ console.log(chalk.bold(`\n Scan: ${targetPath}\n`));
32
+ const rows = sorted.map((e, i) => [
33
+ String(i + 1),
34
+ colorSize(e.size),
35
+ e.isDirectory ? "dir" : "file",
36
+ e.path,
37
+ ]);
38
+ console.log(boxTable(["#", "Size", "Type", "Path"], rows));
39
+ console.log();
40
+ }
@@ -0,0 +1,6 @@
1
+ interface WastelandOptions {
2
+ nodeModules?: string;
3
+ json?: boolean;
4
+ }
5
+ export declare function wasteland(opts: WastelandOptions): void;
6
+ export {};
@@ -0,0 +1,43 @@
1
+ import { resolve } from "node:path";
2
+ import chalk from "chalk";
3
+ import { boxTable, colorSize, formatSize } from "../utils/format.js";
4
+ import { findNodeModules, findWaste } from "../utils/wasteland.js";
5
+ export function wasteland(opts) {
6
+ const waste = findWaste();
7
+ let nmEntries = [];
8
+ if (opts.nodeModules) {
9
+ const searchPath = resolve(opts.nodeModules);
10
+ nmEntries = findNodeModules(searchPath);
11
+ }
12
+ const allEntries = [...waste, ...nmEntries];
13
+ const totalSize = allEntries.reduce((sum, e) => sum + e.size, 0);
14
+ if (opts.json) {
15
+ console.log(JSON.stringify({
16
+ total: totalSize,
17
+ items: allEntries.map((e) => ({
18
+ name: e.name,
19
+ path: e.path,
20
+ size: e.size,
21
+ description: e.description,
22
+ })),
23
+ }, null, 2));
24
+ return;
25
+ }
26
+ if (allEntries.length === 0) {
27
+ console.log(chalk.green("\n No wasteland found. Your disk is clean!\n"));
28
+ return;
29
+ }
30
+ console.log(chalk.bold("\n Wasteland Report\n"));
31
+ if (waste.length > 0) {
32
+ console.log(chalk.bold(" Known space wasters:\n"));
33
+ const rows = waste.map((e) => [e.name, colorSize(e.size), e.path]);
34
+ console.log(boxTable(["Name", "Size", "Path"], rows));
35
+ }
36
+ if (nmEntries.length > 0) {
37
+ const nmTotal = nmEntries.reduce((sum, e) => sum + e.size, 0);
38
+ console.log(chalk.bold(`\n node_modules (${nmEntries.length} found, ${formatSize(nmTotal)} total):\n`));
39
+ const nmRows = nmEntries.map((e) => [colorSize(e.size), e.path]);
40
+ console.log(boxTable(["Size", "Path"], nmRows));
41
+ }
42
+ console.log(chalk.bold(`\n Total reclaimable: ${colorSize(totalSize)}\n`));
43
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { overview } from "./commands/overview.js";
4
+ import { scan } from "./commands/scan.js";
5
+ import { wasteland } from "./commands/wasteland.js";
6
+ const program = new Command();
7
+ program
8
+ .name("dustclaw")
9
+ .description("Disk space monitoring, analysis, and cleanup CLI")
10
+ .version("0.1.0");
11
+ program
12
+ .command("overview", { isDefault: true })
13
+ .description("Quick overview: disk usage, free space, top 10 biggest dirs")
14
+ .option("-n, --top <count>", "Number of top items to show", "10")
15
+ .option("-p, --path <path>", "Path to analyze", ".")
16
+ .option("--json", "Output as JSON")
17
+ .action(overview);
18
+ program
19
+ .command("scan [path]")
20
+ .description("Deep scan: ranked list of largest files and folders")
21
+ .option("-n, --top <count>", "Number of top items to show", "20")
22
+ .option("-d, --depth <depth>", "Max directory depth", "3")
23
+ .option("--older-than <age>", "Filter by age (e.g. 30d, 6m, 1y)")
24
+ .option("--files-only", "Show only files, not directories")
25
+ .option("--dirs-only", "Show only directories, not files")
26
+ .option("--json", "Output as JSON")
27
+ .action(scan);
28
+ program
29
+ .command("wasteland")
30
+ .description("Find known dev/OS space wasters (caches, build artifacts, Trash)")
31
+ .option("--node-modules <path>", "Also search for node_modules under this path")
32
+ .option("--json", "Output as JSON")
33
+ .action(wasteland);
34
+ program.parse();
@@ -0,0 +1,8 @@
1
+ export interface DiskInfo {
2
+ filesystem: string;
3
+ total: number;
4
+ used: number;
5
+ available: number;
6
+ mountpoint: string;
7
+ }
8
+ export declare function getDiskInfo(): DiskInfo[];
@@ -0,0 +1,29 @@
1
+ import { execSync } from "node:child_process";
2
+ import { platform } from "node:os";
3
+ export function getDiskInfo() {
4
+ const os = platform();
5
+ if (os !== "darwin" && os !== "linux") {
6
+ throw new Error(`Unsupported platform: ${os}`);
7
+ }
8
+ const output = execSync("df -Pk", { encoding: "utf-8" });
9
+ const lines = output.trim().split("\n").slice(1);
10
+ const disks = [];
11
+ for (const line of lines) {
12
+ const parts = line.trim().split(/\s+/);
13
+ if (parts.length < 6)
14
+ continue;
15
+ const filesystem = parts[0];
16
+ if (filesystem === "devfs" || filesystem === "map")
17
+ continue;
18
+ if (filesystem.startsWith("/dev/") || filesystem.startsWith("/System/")) {
19
+ disks.push({
20
+ filesystem,
21
+ total: Number.parseInt(parts[1], 10) * 1024,
22
+ used: Number.parseInt(parts[2], 10) * 1024,
23
+ available: Number.parseInt(parts[3], 10) * 1024,
24
+ mountpoint: parts.slice(5).join(" "),
25
+ });
26
+ }
27
+ }
28
+ return disks;
29
+ }
@@ -0,0 +1,4 @@
1
+ export declare function formatSize(bytes: number): string;
2
+ export declare function colorSize(bytes: number): string;
3
+ export declare function formatPercent(ratio: number): string;
4
+ export declare function boxTable(headers: string[], rows: string[][]): string;
@@ -0,0 +1,38 @@
1
+ import chalk from "chalk";
2
+ export function formatSize(bytes) {
3
+ if (bytes < 1024)
4
+ return `${bytes} B`;
5
+ if (bytes < 1024 ** 2)
6
+ return `${(bytes / 1024).toFixed(1)} KB`;
7
+ if (bytes < 1024 ** 3)
8
+ return `${(bytes / 1024 ** 2).toFixed(1)} MB`;
9
+ if (bytes < 1024 ** 4)
10
+ return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
11
+ return `${(bytes / 1024 ** 4).toFixed(1)} TB`;
12
+ }
13
+ export function colorSize(bytes) {
14
+ const text = formatSize(bytes);
15
+ if (bytes >= 1024 ** 3)
16
+ return chalk.red(text);
17
+ if (bytes >= 100 * 1024 ** 2)
18
+ return chalk.yellow(text);
19
+ return chalk.green(text);
20
+ }
21
+ export function formatPercent(ratio) {
22
+ const pct = ratio * 100;
23
+ const text = `${pct.toFixed(1)}%`;
24
+ if (pct >= 90)
25
+ return chalk.red(text);
26
+ if (pct >= 70)
27
+ return chalk.yellow(text);
28
+ return chalk.green(text);
29
+ }
30
+ export function boxTable(headers, rows) {
31
+ const colWidths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
32
+ const sep = `┼${colWidths.map((w) => "─".repeat(w + 2)).join("┼")}┼`;
33
+ const top = `┌${colWidths.map((w) => "─".repeat(w + 2)).join("┬")}┐`;
34
+ const bot = `└${colWidths.map((w) => "─".repeat(w + 2)).join("┴")}┘`;
35
+ const fmtRow = (cells) => `│${cells.map((c, i) => ` ${c.padEnd(colWidths[i])} `).join("│")}│`;
36
+ const lines = [top, fmtRow(headers), sep, ...rows.map(fmtRow), bot];
37
+ return lines.join("\n");
38
+ }
@@ -0,0 +1,15 @@
1
+ export interface ScanEntry {
2
+ path: string;
3
+ size: number;
4
+ isDirectory: boolean;
5
+ mtime: Date;
6
+ }
7
+ export interface ScanOptions {
8
+ depth?: number;
9
+ olderThan?: Date;
10
+ filesOnly?: boolean;
11
+ dirsOnly?: boolean;
12
+ }
13
+ export declare function scanDir(root: string, opts?: ScanOptions, currentDepth?: number): ScanEntry[];
14
+ export declare function dirSize(dirPath: string): number;
15
+ export declare function parseAge(age: string): Date;
@@ -0,0 +1,105 @@
1
+ import { readdirSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ export function scanDir(root, opts = {}, currentDepth = 0) {
4
+ const maxDepth = opts.depth ?? 3;
5
+ const entries = [];
6
+ let items;
7
+ try {
8
+ items = readdirSync(root);
9
+ }
10
+ catch {
11
+ return entries;
12
+ }
13
+ for (const name of items) {
14
+ if (name.startsWith(".") && currentDepth === 0)
15
+ continue;
16
+ const fullPath = join(root, name);
17
+ let stat;
18
+ try {
19
+ stat = statSync(fullPath);
20
+ }
21
+ catch {
22
+ continue;
23
+ }
24
+ if (stat.isDirectory()) {
25
+ if (name === "node_modules" || name === ".git") {
26
+ const size = dirSize(fullPath);
27
+ if (!opts.filesOnly) {
28
+ if (!opts.olderThan || stat.mtime < opts.olderThan) {
29
+ entries.push({ path: fullPath, size, isDirectory: true, mtime: stat.mtime });
30
+ }
31
+ }
32
+ continue;
33
+ }
34
+ if (currentDepth < maxDepth) {
35
+ const childEntries = scanDir(fullPath, opts, currentDepth + 1);
36
+ entries.push(...childEntries);
37
+ }
38
+ else {
39
+ const size = dirSize(fullPath);
40
+ if (!opts.filesOnly) {
41
+ if (!opts.olderThan || stat.mtime < opts.olderThan) {
42
+ entries.push({ path: fullPath, size, isDirectory: true, mtime: stat.mtime });
43
+ }
44
+ }
45
+ }
46
+ }
47
+ else if (stat.isFile()) {
48
+ if (!opts.dirsOnly) {
49
+ if (!opts.olderThan || stat.mtime < opts.olderThan) {
50
+ entries.push({
51
+ path: fullPath,
52
+ size: stat.size,
53
+ isDirectory: false,
54
+ mtime: stat.mtime,
55
+ });
56
+ }
57
+ }
58
+ }
59
+ }
60
+ return entries;
61
+ }
62
+ export function dirSize(dirPath) {
63
+ let total = 0;
64
+ let items;
65
+ try {
66
+ items = readdirSync(dirPath);
67
+ }
68
+ catch {
69
+ return 0;
70
+ }
71
+ for (const name of items) {
72
+ const fullPath = join(dirPath, name);
73
+ try {
74
+ const stat = statSync(fullPath);
75
+ if (stat.isFile()) {
76
+ total += stat.size;
77
+ }
78
+ else if (stat.isDirectory()) {
79
+ total += dirSize(fullPath);
80
+ }
81
+ }
82
+ catch { }
83
+ }
84
+ return total;
85
+ }
86
+ export function parseAge(age) {
87
+ const match = age.match(/^(\d+)(d|m|y)$/);
88
+ if (!match)
89
+ throw new Error(`Invalid age format: ${age}. Use e.g. 30d, 6m, 1y`);
90
+ const num = Number.parseInt(match[1], 10);
91
+ const unit = match[2];
92
+ const now = new Date();
93
+ switch (unit) {
94
+ case "d":
95
+ now.setDate(now.getDate() - num);
96
+ break;
97
+ case "m":
98
+ now.setMonth(now.getMonth() - num);
99
+ break;
100
+ case "y":
101
+ now.setFullYear(now.getFullYear() - num);
102
+ break;
103
+ }
104
+ return now;
105
+ }
@@ -0,0 +1,9 @@
1
+ export interface WasteEntry {
2
+ name: string;
3
+ path: string;
4
+ size: number;
5
+ description: string;
6
+ }
7
+ export declare function findCaches(): WasteEntry[];
8
+ export declare function findWaste(): WasteEntry[];
9
+ export declare function findNodeModules(root: string, maxDepth?: number): WasteEntry[];
@@ -0,0 +1,208 @@
1
+ import { execSync } from "node:child_process";
2
+ import { existsSync, readdirSync, statSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { dirSize } from "./scan.js";
6
+ const home = homedir();
7
+ const targets = [
8
+ {
9
+ name: "Xcode DerivedData",
10
+ path: join(home, "Library/Developer/Xcode/DerivedData"),
11
+ description: "Xcode build artifacts",
12
+ },
13
+ {
14
+ name: "Xcode Archives",
15
+ path: join(home, "Library/Developer/Xcode/Archives"),
16
+ description: "Xcode archived builds",
17
+ },
18
+ {
19
+ name: "Xcode Device Support",
20
+ path: join(home, "Library/Developer/Xcode/iOS DeviceSupport"),
21
+ description: "iOS device support files",
22
+ },
23
+ {
24
+ name: "Homebrew Cache",
25
+ path: () => {
26
+ try {
27
+ return execSync("brew --cache", { encoding: "utf-8" }).trim();
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ },
33
+ description: "Homebrew downloaded packages",
34
+ },
35
+ {
36
+ name: "Gradle Cache",
37
+ path: join(home, ".gradle/caches"),
38
+ description: "Gradle build cache",
39
+ },
40
+ {
41
+ name: "Maven Cache",
42
+ path: join(home, ".m2/repository"),
43
+ description: "Maven dependency cache",
44
+ },
45
+ {
46
+ name: "Cargo Cache",
47
+ path: join(home, ".cargo/registry"),
48
+ description: "Rust crate cache",
49
+ },
50
+ {
51
+ name: "pnpm Store",
52
+ path: join(home, "Library/pnpm/store"),
53
+ description: "pnpm content-addressable store",
54
+ },
55
+ {
56
+ name: "npm Cache",
57
+ path: join(home, ".npm/_cacache"),
58
+ description: "npm download cache",
59
+ },
60
+ {
61
+ name: "Docker Desktop",
62
+ path: join(home, "Library/Containers/com.docker.docker/Data"),
63
+ description: "Docker images, containers, and volumes",
64
+ },
65
+ {
66
+ name: "iOS Simulators",
67
+ path: join(home, "Library/Developer/CoreSimulator/Devices"),
68
+ description: "iOS Simulator device data",
69
+ },
70
+ {
71
+ name: "Android Emulators",
72
+ path: join(home, ".android/avd"),
73
+ description: "Android emulator images",
74
+ },
75
+ {
76
+ name: "Trash",
77
+ path: join(home, ".Trash"),
78
+ description: "Files in Trash",
79
+ },
80
+ {
81
+ name: "System Logs",
82
+ path: join(home, "Library/Logs"),
83
+ description: "Application and system logs",
84
+ },
85
+ ];
86
+ const MIN_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB minimum to show in breakdown
87
+ export function findCaches() {
88
+ const cachesDir = join(home, "Library/Caches");
89
+ if (!existsSync(cachesDir))
90
+ return [];
91
+ // Paths already covered by specific targets — skip to avoid double-counting
92
+ const skip = new Set(["Homebrew", "CocoaPods", "Yarn"]);
93
+ const results = [];
94
+ let items;
95
+ try {
96
+ items = readdirSync(cachesDir);
97
+ }
98
+ catch {
99
+ return [];
100
+ }
101
+ for (const name of items) {
102
+ if (skip.has(name))
103
+ continue;
104
+ const fullPath = join(cachesDir, name);
105
+ try {
106
+ const stat = statSync(fullPath);
107
+ if (!stat.isDirectory())
108
+ continue;
109
+ }
110
+ catch {
111
+ continue;
112
+ }
113
+ const size = dirSize(fullPath);
114
+ if (size >= MIN_CACHE_SIZE) {
115
+ results.push({
116
+ name: `Cache: ${friendlyName(name)}`,
117
+ path: fullPath,
118
+ size,
119
+ description: `${name} cache`,
120
+ });
121
+ }
122
+ }
123
+ return results.sort((a, b) => b.size - a.size);
124
+ }
125
+ function friendlyName(dirName) {
126
+ const map = {
127
+ "com.spotify.client": "Spotify",
128
+ "com.apple.Safari": "Safari",
129
+ "com.google.Chrome": "Chrome",
130
+ Google: "Google/Chrome",
131
+ "com.docker.docker": "Docker",
132
+ "com.microsoft.VSCode": "VS Code",
133
+ "com.todesktop.230313mzl4w4u92.ShipIt": "Cursor Updates",
134
+ "com.google.antigravity.ShipIt": "Chrome Updates",
135
+ icloudmailagent: "iCloud Mail",
136
+ "com.apple.callintelligenced": "Apple Call Intelligence",
137
+ "ms-playwright": "Playwright Browsers",
138
+ pip: "pip",
139
+ Cypress: "Cypress",
140
+ "node-gyp": "node-gyp",
141
+ typescript: "TypeScript",
142
+ pnpm: "pnpm",
143
+ colima: "Colima",
144
+ "com.openai.codex": "OpenAI Codex",
145
+ };
146
+ return map[dirName] ?? dirName;
147
+ }
148
+ export function findWaste() {
149
+ const results = [];
150
+ for (const target of targets) {
151
+ const resolvedPath = typeof target.path === "function" ? target.path() : target.path;
152
+ if (!resolvedPath)
153
+ continue;
154
+ if (!existsSync(resolvedPath))
155
+ continue;
156
+ const size = dirSize(resolvedPath);
157
+ if (size > 0) {
158
+ results.push({
159
+ name: target.name,
160
+ path: resolvedPath,
161
+ size,
162
+ description: target.description,
163
+ });
164
+ }
165
+ }
166
+ results.push(...findCaches());
167
+ return results.sort((a, b) => b.size - a.size);
168
+ }
169
+ export function findNodeModules(root, maxDepth = 5) {
170
+ const results = [];
171
+ searchNodeModules(root, results, 0, maxDepth);
172
+ return results.sort((a, b) => b.size - a.size);
173
+ }
174
+ function searchNodeModules(dir, results, depth, maxDepth) {
175
+ if (depth > maxDepth)
176
+ return;
177
+ let items;
178
+ try {
179
+ items = readdirSync(dir);
180
+ }
181
+ catch {
182
+ return;
183
+ }
184
+ for (const name of items) {
185
+ if (name.startsWith("."))
186
+ continue;
187
+ const fullPath = join(dir, name);
188
+ if (name === "node_modules") {
189
+ const size = dirSize(fullPath);
190
+ if (size > 0) {
191
+ results.push({
192
+ name: "node_modules",
193
+ path: fullPath,
194
+ size,
195
+ description: `node_modules in ${dir}`,
196
+ });
197
+ }
198
+ continue;
199
+ }
200
+ try {
201
+ const stat = statSync(fullPath);
202
+ if (stat.isDirectory()) {
203
+ searchNodeModules(fullPath, results, depth + 1, maxDepth);
204
+ }
205
+ }
206
+ catch { }
207
+ }
208
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "dustclaw",
3
+ "version": "0.1.0",
4
+ "description": "Disk space monitoring, analysis, and cleanup CLI",
5
+ "type": "module",
6
+ "bin": {
7
+ "dustclaw": "dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md",
12
+ "LICENSE",
13
+ "assets/dustclaw.png"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsx src/index.ts",
18
+ "test": "vitest run",
19
+ "test:watch": "vitest",
20
+ "lint": "biome check src tests",
21
+ "format": "biome format --write src tests"
22
+ },
23
+ "keywords": [
24
+ "disk",
25
+ "space",
26
+ "cleanup",
27
+ "monitor",
28
+ "cli",
29
+ "devtools"
30
+ ],
31
+ "author": "psandis <petri.sandholm@gmail.com>",
32
+ "license": "MIT",
33
+ "packageManager": "pnpm@10.12.1",
34
+ "dependencies": {
35
+ "better-sqlite3": "^12.8.0",
36
+ "chalk": "^5.6.2",
37
+ "commander": "^14.0.3"
38
+ },
39
+ "pnpm": {
40
+ "onlyBuiltDependencies": [
41
+ "better-sqlite3",
42
+ "esbuild"
43
+ ]
44
+ },
45
+ "devDependencies": {
46
+ "@biomejs/biome": "^2.4.8",
47
+ "@types/better-sqlite3": "^7.6.13",
48
+ "@types/node": "^25.5.0",
49
+ "tsx": "^4.21.0",
50
+ "typescript": "^6.0.2",
51
+ "vitest": "^4.1.1"
52
+ }
53
+ }