@lexmanh/shed-cli 0.2.0-beta.4 → 0.2.0-beta.5

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.
Files changed (2) hide show
  1. package/dist/cli.js +118 -6
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -421,9 +421,80 @@ import {
421
421
  XcodeDetector as XcodeDetector2
422
422
  } from "@lexmanh/shed-core";
423
423
  import pc4 from "picocolors";
424
+
425
+ // src/commands/scan-aggregate.ts
426
+ import { dirname } from "path";
427
+ var AGGREGATE_THRESHOLD = 3;
428
+ function aggregateForDisplay(items) {
429
+ const buckets = /* @__PURE__ */ new Map();
430
+ const singles = [];
431
+ for (const item of items) {
432
+ const kind = item.metadata?.kind ?? null;
433
+ if (!kind) {
434
+ singles.push(item);
435
+ continue;
436
+ }
437
+ const key = `${dirname(item.path)}::${item.detector}::${kind}`;
438
+ const arr = buckets.get(key) ?? [];
439
+ arr.push(item);
440
+ buckets.set(key, arr);
441
+ }
442
+ const result = [];
443
+ for (const arr of buckets.values()) {
444
+ if (arr.length >= AGGREGATE_THRESHOLD) {
445
+ const first = arr[0];
446
+ if (!first) continue;
447
+ const totalBytes = arr.reduce((s, i) => s + i.sizeBytes, 0);
448
+ const kind = first.metadata?.kind;
449
+ result.push({
450
+ type: "aggregate",
451
+ risk: first.risk,
452
+ displayPath: dirname(first.path),
453
+ description: `${arr.length} ${kind} files`,
454
+ totalBytes,
455
+ detector: first.detector,
456
+ itemCount: arr.length,
457
+ items: arr
458
+ });
459
+ } else {
460
+ for (const item of arr) result.push(toSingle(item));
461
+ }
462
+ }
463
+ for (const item of singles) result.push(toSingle(item));
464
+ return result;
465
+ }
466
+ function toSingle(item) {
467
+ return {
468
+ type: "single",
469
+ risk: item.risk,
470
+ displayPath: item.path,
471
+ description: item.description,
472
+ totalBytes: item.sizeBytes,
473
+ detector: item.detector,
474
+ itemCount: 1,
475
+ items: [item]
476
+ };
477
+ }
478
+ function selectTopGroups(groups, topN) {
479
+ const sorted = [...groups].sort((a, b) => b.totalBytes - a.totalBytes);
480
+ const shown = sorted.slice(0, topN);
481
+ const rest = sorted.slice(topN);
482
+ return {
483
+ shown,
484
+ hidden: {
485
+ groupCount: rest.length,
486
+ itemCount: rest.reduce((s, g) => s + g.itemCount, 0),
487
+ totalBytes: rest.reduce((s, g) => s + g.totalBytes, 0)
488
+ }
489
+ };
490
+ }
491
+
492
+ // src/commands/scan.ts
424
493
  var require2 = createRequire(import.meta.url);
425
494
  var { version: SHED_VERSION } = require2("../package.json");
426
495
  var JSON_SCHEMA_VERSION = 1;
496
+ var COMPACT_TOP_N = 15;
497
+ var DETECTOR_BREAKDOWN_TOP_N = 6;
427
498
  var RISK_LABEL = {
428
499
  [RiskTier2.Green]: pc4.green("\u25CF Green"),
429
500
  [RiskTier2.Yellow]: pc4.yellow("\u25CF Yellow"),
@@ -535,6 +606,52 @@ async function scanCommand(path = ".", options = {}) {
535
606
  p4.outro(pc4.dim("All clear!"));
536
607
  return;
537
608
  }
609
+ if (options.all) {
610
+ renderFull(allItems);
611
+ } else {
612
+ renderCompact(allItems);
613
+ }
614
+ console.log();
615
+ p4.outro(
616
+ `Total recoverable: ${pc4.bold(pc4.green(formatBytes2(totalBytes)))} \u2014 run ${pc4.cyan("shed clean")} to proceed.`
617
+ );
618
+ }
619
+ function renderCompact(allItems) {
620
+ const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
621
+ const byRisk = { green: 0, yellow: 0, red: 0 };
622
+ let detectOnly = 0;
623
+ const byDetector = /* @__PURE__ */ new Map();
624
+ for (const item of allItems) {
625
+ byRisk[item.risk]++;
626
+ if (item.metadata?.detectOnly === true) detectOnly++;
627
+ byDetector.set(item.detector, (byDetector.get(item.detector) ?? 0) + item.sizeBytes);
628
+ }
629
+ const riskLine = `${pc4.green(`\u25CF ${byRisk.green} Green`)} ${pc4.yellow(`\u25CF ${byRisk.yellow} Yellow`)} ${pc4.red(`\u25CF ${byRisk.red} Red`)}${detectOnly > 0 ? pc4.dim(` (${detectOnly} detect-only)`) : ""}`;
630
+ const detectorLine = [...byDetector.entries()].sort(([, a], [, b]) => b - a).slice(0, DETECTOR_BREAKDOWN_TOP_N).map(([d, b]) => `${d} ${formatBytes2(b)}`).join(" \xB7 ");
631
+ console.log();
632
+ console.log(` By risk: ${riskLine}`);
633
+ console.log(` By detector: ${pc4.dim(detectorLine)}`);
634
+ const groups = aggregateForDisplay(allItems);
635
+ const { shown, hidden } = selectTopGroups(groups, COMPACT_TOP_N);
636
+ console.log();
637
+ console.log(` ${pc4.bold(`Top ${shown.length} items:`)}`);
638
+ for (const g of shown) {
639
+ const path = home ? g.displayPath.replace(home, "~") : g.displayPath;
640
+ const tag = g.type === "aggregate" ? pc4.dim(` (${g.itemCount} ${g.detector} items)`) : "";
641
+ const size = g.totalBytes > 0 ? pc4.dim(` ${formatBytes2(g.totalBytes)}`) : "";
642
+ console.log(` ${RISK_LABEL[g.risk]} ${path}${tag}${size}`);
643
+ }
644
+ if (hidden.groupCount > 0) {
645
+ console.log();
646
+ console.log(
647
+ pc4.dim(
648
+ ` \u2026 ${hidden.groupCount} more groups (${hidden.itemCount} items, ${formatBytes2(hidden.totalBytes)}) \u2014 use --all to see everything`
649
+ )
650
+ );
651
+ }
652
+ }
653
+ function renderFull(allItems) {
654
+ const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
538
655
  const byProject = /* @__PURE__ */ new Map();
539
656
  for (const item of allItems) {
540
657
  const key = item.projectRoot ?? "(global)";
@@ -543,7 +660,6 @@ async function scanCommand(path = ".", options = {}) {
543
660
  byProject.set(key, group);
544
661
  }
545
662
  for (const [projectRoot, items] of byProject.entries()) {
546
- const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
547
663
  const projectLabel = projectRoot === "(global)" ? pc4.dim("global caches") : pc4.cyan(home ? projectRoot.replace(home, "~") : projectRoot);
548
664
  const groupTotal = items.reduce((s, i) => s + i.sizeBytes, 0);
549
665
  console.log(`
@@ -556,10 +672,6 @@ async function scanCommand(path = ".", options = {}) {
556
672
  console.log(` ${pc4.dim(` ${item.description}`)}`);
557
673
  }
558
674
  }
559
- console.log();
560
- p4.outro(
561
- `Total recoverable: ${pc4.bold(pc4.green(formatBytes2(totalBytes)))} \u2014 run ${pc4.cyan("shed clean")} to proceed.`
562
- );
563
675
  }
564
676
 
565
677
  // src/commands/undo.ts
@@ -627,7 +739,7 @@ var require3 = createRequire2(import.meta.url);
627
739
  var { version } = require3("../package.json");
628
740
  var program = new Command();
629
741
  program.name("shed").description("Safe disk cleanup for dev machines and Linux servers").version(version).option("-v, --verbose", "Enable verbose logging");
630
- program.command("scan [path]").description("Scan for cleanable items without modifying anything").option("--json", "Output machine-readable JSON").option("--max-age <days>", "Only include items older than N days", "30").action(scanCommand);
742
+ program.command("scan [path]").description("Scan for cleanable items without modifying anything").option("--json", "Output machine-readable JSON").option("--max-age <days>", "Only include items older than N days", "30").option("--all", "Show every item (default: compact summary with top 15)").action(scanCommand);
631
743
  program.command("clean [path]").description("Interactive cleanup of detected items").option("--dry-run", "Preview operations without executing", true).option("--execute", "Actually perform the cleanup (overrides --dry-run)").option("--hard-delete", "Skip Trash, delete permanently").option("--include-red", "Include Red-tier (high-risk) items").option("--yes", "Skip interactive confirmations (CI mode)").action(cleanCommand);
632
744
  program.command("undo").description("List and restore items from previous cleanups").action(undoCommand);
633
745
  program.command("doctor").description("Check environment and configuration").action(doctorCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexmanh/shed-cli",
3
- "version": "0.2.0-beta.4",
3
+ "version": "0.2.0-beta.5",
4
4
  "description": "Safe disk cleanup CLI for dev machines and Linux servers — git-aware, cross-stack, trash-by-default",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,7 +23,7 @@
23
23
  "conf": "^13.1.0",
24
24
  "execa": "^9.5.0",
25
25
  "picocolors": "^1.1.1",
26
- "@lexmanh/shed-core": "0.2.0-beta.4"
26
+ "@lexmanh/shed-core": "0.2.0-beta.5"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^22.10.0",