dir-analysis-tool 3.3.0 → 3.4.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
@@ -92,6 +92,7 @@ dat explain -g # what a scan skips, and which rule skippe
92
92
  dat . -b "size<=200MB" -b "duplicates=0" # fail CI when a budget is exceeded
93
93
  dat . --html report.html # a self-contained HTML report
94
94
  dat . --json | jq '.largestFiles[0]' # machine-readable output
95
+ dat . -d --compact # bounded one-line JSON for scripts and agents
95
96
  ```
96
97
 
97
98
  ## What it shows
@@ -184,17 +185,18 @@ A size tree (`dat src -t --tree-depth 2`):
184
185
 
185
186
  **Output options:**
186
187
 
187
- | Option | Description |
188
- | ----------------------- | ------------------------------------------------------------------------------------ |
189
- | `-f, --format <format>` | `pretty` (default), `json`, `markdown`, `csv`, or `html`. |
190
- | `-j, --json` | Same as `--format json`. |
191
- | `-o, --output <file>` | Write the report to a file instead of stdout. |
192
- | `--html [file.html]` | Also write an HTML report. Default name `directory-analysis-<date>.html`. |
193
- | `--csv [file.csv]` | Also write a CSV export. Default name `directory-analysis.csv`. |
194
- | `--si` | Decimal units (kB, MB, powers of 1000) instead of binary (KiB, MiB, powers of 1024). |
195
- | `--color`, `--no-color` | Force colors on or off. `NO_COLOR` and `FORCE_COLOR` are honored. |
196
- | `--no-progress` | Hide the progress line. It is only ever drawn on an interactive stderr. |
197
- | `-q, --quiet` | Print only the report and errors. |
188
+ | Option | Description |
189
+ | ----------------------- | -------------------------------------------------------------------------------------- |
190
+ | `-f, --format <format>` | `pretty` (default), `json`, `markdown`, `csv`, or `html`. |
191
+ | `-j, --json` | Same as `--format json`. |
192
+ | `--compact` | One-line JSON with every list cut to `--top` items. See [Compact JSON](#compact-json). |
193
+ | `-o, --output <file>` | Write the report to a file instead of stdout. |
194
+ | `--html [file.html]` | Also write an HTML report. Default name `directory-analysis-<date>.html`. |
195
+ | `--csv [file.csv]` | Also write a CSV export. Default name `directory-analysis.csv`. |
196
+ | `--si` | Decimal units (kB, MB, powers of 1000) instead of binary (KiB, MiB, powers of 1024). |
197
+ | `--color`, `--no-color` | Force colors on or off. `NO_COLOR` and `FORCE_COLOR` are honored. |
198
+ | `--no-progress` | Hide the progress line. It is only ever drawn on an interactive stderr. |
199
+ | `-q, --quiet` | Print only the report and errors. |
198
200
 
199
201
  ### `dat compare`
200
202
 
@@ -399,6 +401,28 @@ JSON is versioned (`"schemaVersion": 3`). Sizes are raw bytes, dates are ISO 860
399
401
  }
400
402
  ```
401
403
 
404
+ ### Compact JSON
405
+
406
+ Large trees can produce very long lists, mostly duplicate groups: 650 KB of JSON for a `node_modules` folder with `-d`. `--compact` (3.4 or later) prints the same document on one line with every list cut to the `--top` value (10 when `--top` is unset or 0), so a script or an agent gets the facts without the bulk. The example above shrinks to 11 KB.
407
+
408
+ - **Totals stay complete.** `summary`, `types`, `budgets`, and every `count`, `bytes`, `files`, and `wastedBytes` are the same as without `--compact`. Only the item lists are shorter, and they keep their order, so each list is the start of the full one.
409
+ - **Cut lists are named.** A top-level `compact` object says what was left out:
410
+
411
+ ```jsonc
412
+ "compact": {
413
+ "limit": 10,
414
+ "truncated": true,
415
+ "omitted": { "extensions": 44, "duplicates.items": 1679, "errors": 3 }
416
+ }
417
+ ```
418
+
419
+ `omitted` has an entry only for a list that was cut, with the number of items not listed. A duplicate group whose copies were cut also has `omittedFiles`, and `duplicates.items[].files` in `omitted` is the sum. A missing section means its report was off; `count: 0` with `items: []` means nothing was found.
420
+
421
+ - **Lists that are cut:** `extensions`, the `items` of `largeFiles`, `duplicates`, `emptyFiles`, `emptyDirectories`, and `staleFiles`, the `files` of each listed duplicate group, and `errors` (counted against `summary.errors`). `largestFiles` and `largestDirectories` follow `--top` as always, and the tree keeps its own `omitted`.
422
+ - **Follow up** with a focused scan when you need more: `dat . -d --compact -n 50` for more items, `dat . -d -n 0 --json | jq .duplicates` for one full section, `dat ./assets -d --compact` for a smaller scope, and `dat explain` for what was skipped.
423
+
424
+ `--compact` implies `--json` and cannot be combined with another `--format`. Without it, JSON output is unchanged.
425
+
402
426
  Optional sections appear only when their report is on: `largeFiles`, `duplicates`, `emptyFiles`, `emptyDirectories`, `staleFiles`, `tree`, and `budgets`.
403
427
 
404
428
  ## Configuration
@@ -469,6 +493,7 @@ await writeFile('report.md', renderAnalysisMarkdown(result));
469
493
  | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
470
494
  | `analyze(path, options?)` | Analyze a tree. Options mirror the CLI flags: `exclude`, `gitignore`, `maxDepth`, `minSize`, `modifiedAfter`, `top`, `largeFiles`, `duplicates`, `empty`, `stale`, `tree`, `budgets`, `concurrency`, `signal`, `onProgress`, and more. |
471
495
  | `compare(left, right, options?)` | Diff two trees. |
496
+ | `compactAnalysis(result, { limit })` | The `--compact` form of a result: lists cut to `limit`, totals kept, cuts listed in `compact`. Returns a new object. |
472
497
  | `listDirectories(path, options?)` | The folders a scan would enter. |
473
498
  | `explainPath(root, path, options?)`, `explainSkips(root, options?)` | Why a scan counts or skips one path, and everything a scan skips grouped by rule (`limit` caps listed entries). Render with `renderPathExplanation` and `renderSkipsExplanation`. |
474
499
  | `renderAnalysis`, `renderAnalysisMarkdown`, `renderAnalysisCsv`, `renderAnalysisHtml` | Render a result in any format. `renderComparison*` does the same for comparisons. |
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { B as parseBudget, C as MAX_EXPLAIN_LIMIT, E as compare, H as parseSize, J as DatError, K as parsePointInTime, M as joinRelative, P as Excluder, T as explainSkips, V as formatBytes, W as VERSION, X as errorMessage, Y as errorCode, a as renderComparisonCsv, c as renderAnalysis, d as escapeControlInLines, f as formatCount, h as supportsColor, i as renderAnalysisCsv, j as listDirectories, k as analyze, l as renderComparison, m as createStyle, n as renderSkipsExplanation, o as renderAnalysisMarkdown, p as stringifyJson, q as AbortError, r as renderAnalysisHtml, s as renderComparisonMarkdown, t as renderPathExplanation, u as escapeControl, v as loadConfig, w as explainPath, z as formatBudgetActual } from "./shared-DfKY8fSl.js";
2
+ import { $ as errorMessage, C as MAX_EXPLAIN_LIMIT, D as outsideRootError, E as isOutside, F as joinRelative, G as parseSize, H as formatBudgetActual, L as Excluder, M as analyze, O as compare, P as listDirectories, Q as errorCode, T as explainSkips, U as parseBudget, W as formatBytes, X as AbortError, Y as parsePointInTime, Z as DatError, a as renderComparisonCsv, c as renderAnalysis, d as escapeControlInLines, f as formatCount, h as supportsColor, i as renderAnalysisCsv, k as compactAnalysis, l as renderComparison, m as createStyle, n as renderSkipsExplanation, o as renderAnalysisMarkdown, p as stringifyJson, q as VERSION, r as renderAnalysisHtml, s as renderComparisonMarkdown, t as renderPathExplanation, u as escapeControl, v as loadConfig, w as explainPath } from "./shared-CikLbzoj.js";
3
3
  import { existsSync, watch } from "node:fs";
4
4
  import { mkdir, writeFile } from "node:fs/promises";
5
5
  import { dirname, join, relative, resolve, sep } from "node:path";
@@ -716,6 +716,10 @@ function addReportOptions(command) {
716
716
  function addOutputOptions(command, formats = FORMATS) {
717
717
  return command.addOption(option("-f, --format <format>", "output format", OUTPUT_GROUP).choices(formats)).addOption(option("-j, --json", "same as --format json", OUTPUT_GROUP)).addOption(option("-o, --output <file>", "write the report to a file instead of stdout", OUTPUT_GROUP)).addOption(option("--si", "use decimal units (kB, MB) instead of binary (KiB, MiB)", OUTPUT_GROUP)).addOption(option("--color", "force colors", OUTPUT_GROUP)).addOption(option("--no-color", "disable colors (also honors NO_COLOR)", OUTPUT_GROUP)).addOption(option("--no-progress", "hide the progress line", OUTPUT_GROUP)).addOption(option("-q, --quiet", "print only the report and errors", OUTPUT_GROUP));
718
718
  }
719
+ /** Bounded JSON for scripts and agents. Analyze only. */
720
+ function addCompactOption(command) {
721
+ return command.addOption(option("--compact", "print one-line JSON with every list cut to --top items (implies --json)", OUTPUT_GROUP));
722
+ }
719
723
  /** Legacy file outputs kept from v2: they write a file in addition to the normal output. */
720
724
  function addFileReportOptions(command) {
721
725
  return command.addOption(option("--html [file]", "also write a self-contained HTML report", OUTPUT_GROUP)).addOption(option("--csv [file]", "also write a CSV export", OUTPUT_GROUP));
@@ -787,8 +791,12 @@ function resolveAnalyzeOptions(cli, config) {
787
791
  };
788
792
  }
789
793
  function resolveDisplay(cli, config) {
794
+ const compact = cli["compact"] === true;
795
+ const requested = FORMATS.find((f) => f === cli["format"]);
796
+ if (compact && requested !== void 0 && requested !== "json") throw new DatError(`--compact prints JSON; remove --format ${requested}.`);
790
797
  return {
791
- format: cli["json"] === true ? "json" : FORMATS.find((f) => f === cli["format"]) ?? "pretty",
798
+ format: cli["json"] === true || compact ? "json" : requested ?? "pretty",
799
+ compact,
792
800
  output: read.string(cli["output"]),
793
801
  units: cli["si"] === true ? "si" : config.units ?? "iec",
794
802
  color: read.boolean(cli["color"]),
@@ -864,6 +872,7 @@ Examples:
864
872
  enforce budgets in CI (exit code 2 on failure)
865
873
  $ dat . -f markdown >> "$GITHUB_STEP_SUMMARY"
866
874
  $ dat . --json | jq '.largestFiles[0]'
875
+ $ dat . -d --compact bounded one-line JSON for scripts and agents
867
876
  $ dat . --html report.html self-contained HTML report
868
877
  `;
869
878
  function registerAnalyze(program, ctx) {
@@ -871,6 +880,7 @@ function registerAnalyze(program, ctx) {
871
880
  addScanOptions(command);
872
881
  addReportOptions(command);
873
882
  addOutputOptions(command);
883
+ addCompactOption(command);
874
884
  addFileReportOptions(command);
875
885
  command.addHelpText("after", EXAMPLES$3);
876
886
  command.action(async (directory, _options, cmd) => {
@@ -909,7 +919,7 @@ async function emit(ctx, result, display, limit) {
909
919
  }
910
920
  let output = display.output;
911
921
  if (!output && display.format === "html" && ctx.io.stdout.isTTY) output = `directory-analysis-${today}.html`;
912
- const text = renderAnalysisAs(display.format, result, {
922
+ const text = display.compact ? stringifyJson(compactAnalysis(result, { limit })) : renderAnalysisAs(display.format, result, {
913
923
  style: ctx.outputStyle(display.color, output !== void 0),
914
924
  units: display.units,
915
925
  width: terminalWidth(ctx.io),
@@ -1028,7 +1038,9 @@ function registerExplain(program, ctx) {
1028
1038
  const style = ctx.outputStyle(read.boolean(cli["color"]), false);
1029
1039
  const width = terminalWidth(ctx.io);
1030
1040
  if (path !== void 0) {
1031
- const result = await explainPath(root, ctx.resolvePath(path), {
1041
+ const target = ctx.resolvePath(path);
1042
+ if (isOutside(root, target)) throw outsideRootError(path, root);
1043
+ const result = await explainPath(root, target, {
1032
1044
  ...settings,
1033
1045
  signal: ctx.io.signal
1034
1046
  });
package/dist/index.d.ts CHANGED
@@ -66,6 +66,8 @@ export interface DuplicateGroup {
66
66
  /** Space reclaimable by keeping one copy: `bytes * (files.length - 1)`. */
67
67
  wastedBytes: number;
68
68
  files: string[];
69
+ /** Copies not listed in `files`; present only on a group cut by compact output. */
70
+ omittedFiles?: number;
69
71
  }
70
72
  export interface ItemList<T> {
71
73
  /** Number of matching items. */
@@ -172,6 +174,21 @@ export interface AnalysisResult {
172
174
  budgets?: BudgetResult[];
173
175
  /** At most 100 entries; `summary.errors` has the full count. */
174
176
  errors: ScanError[];
177
+ /** Present only in compact output (`--compact`, `compactAnalysis`): what was cut. */
178
+ compact?: CompactInfo;
179
+ }
180
+ /** Lists that compact output can cut, named by their JSON path. */
181
+ export type CompactList = "extensions" | "errors" | "largeFiles.items" | "duplicates.items" | "duplicates.items[].files" | "emptyFiles.items" | "emptyDirectories.items" | "staleFiles.items";
182
+ export interface CompactInfo {
183
+ /** Maximum number of items kept in each list. */
184
+ limit: number;
185
+ /** Whether any list was cut. */
186
+ truncated: boolean;
187
+ /**
188
+ * Items not listed, per cut list, in document order. A list that is absent
189
+ * here was not cut. `duplicates.items[].files` is the sum over listed groups.
190
+ */
191
+ omitted: Partial<Record<CompactList, number>>;
175
192
  }
176
193
  export interface ChangedFile {
177
194
  path: string;
@@ -314,6 +331,22 @@ type AnalysisProgress = {
314
331
  * ```
315
332
  */
316
333
  export declare function analyze(path: string, options?: AnalyzeOptions): Promise<AnalysisResult>;
334
+ interface CompactOptions {
335
+ /** Maximum number of items kept in each list (a whole number of at least 0). */
336
+ limit: number;
337
+ }
338
+ /**
339
+ * Bounds every list in an analysis result to `limit` items, for scripts and
340
+ * agents that read the JSON. Counts and sizes stay the full totals; what was
341
+ * cut is listed in `compact.omitted`. Returns a new result and leaves the
342
+ * input untouched.
343
+ *
344
+ * Cut: `extensions`, the `items` of `largeFiles`, `duplicates`, `emptyFiles`,
345
+ * `emptyDirectories`, and `staleFiles`, the `files` of each listed duplicate
346
+ * group, and `errors`. Not cut: `summary`, `types`, `budgets`, and the lists
347
+ * already bounded by `top` or by the tree's own per-folder limit.
348
+ */
349
+ export declare function compactAnalysis(result: AnalysisResult, options: CompactOptions): AnalysisResult;
317
350
  interface CompareOptions extends ScanSettings {
318
351
  /** Also compare the contents of same-sized files (SHA-256). Default: `false`, size only. */
319
352
  content?: boolean | undefined;
@@ -333,6 +366,24 @@ interface CompareOptions extends ScanSettings {
333
366
  * rules and filters. Memory grows with the number of files in both trees.
334
367
  */
335
368
  export declare function compare(left: string, right: string, options?: CompareOptions): Promise<ComparisonResult>;
369
+ /**
370
+ * An expected, user-facing failure (bad input, missing directory, invalid
371
+ * config). The CLI prints its message without a stack trace.
372
+ */
373
+ export declare class DatError extends Error {
374
+ override readonly name = "DatError";
375
+ /** Optional hint printed after the message. */
376
+ readonly hint: string | undefined;
377
+ constructor(message: string, options?: {
378
+ hint?: string;
379
+ cause?: unknown;
380
+ });
381
+ }
382
+ /** Thrown when an operation is cancelled through its `AbortSignal`. */
383
+ export declare class AbortError extends Error {
384
+ override readonly name = "AbortError";
385
+ constructor(message?: string);
386
+ }
336
387
  /** Version of the `explain` JSON shape, independent of the analysis `schemaVersion`. */
337
388
  export declare const EXPLAIN_VERSION = 1;
338
389
  /** Default number of entries listed per group by {@link explainSkips}. */
@@ -637,23 +688,5 @@ interface ExplainRenderOptions {
637
688
  export declare function renderPathExplanation(result: PathExplanation, options?: ExplainRenderOptions): string;
638
689
  /** Human-readable summary of everything a scan left out. */
639
690
  export declare function renderSkipsExplanation(result: SkipsExplanation, options?: ExplainRenderOptions): string;
640
- /**
641
- * An expected, user-facing failure (bad input, missing directory, invalid
642
- * config). The CLI prints its message without a stack trace.
643
- */
644
- export declare class DatError extends Error {
645
- override readonly name = "DatError";
646
- /** Optional hint printed after the message. */
647
- readonly hint: string | undefined;
648
- constructor(message: string, options?: {
649
- hint?: string;
650
- cause?: unknown;
651
- });
652
- }
653
- /** Thrown when an operation is cancelled through its `AbortSignal`. */
654
- export declare class AbortError extends Error {
655
- override readonly name = "AbortError";
656
- constructor(message?: string);
657
- }
658
691
  export declare const VERSION: string;
659
- export type { AnalysisProgress, AnalyzeOptions, Budget, ByteUnits, CompareOptions, DatConfig, ExplainDecision, ExplainEntryType, ExplainGroup, ExplainNote, ExplainNoteCode, ExplainReason, ExplainRenderOptions, ExplainSkipsOptions, ExplainSource, ExplainTotals, LoadedConfig, PathExplanation, PrettyOptions, ScanSettings, SkipsExplanation, Style };
692
+ export type { AnalysisProgress, AnalyzeOptions, Budget, ByteUnits, CompactOptions, CompareOptions, DatConfig, ExplainDecision, ExplainEntryType, ExplainGroup, ExplainNote, ExplainNoteCode, ExplainReason, ExplainRenderOptions, ExplainSkipsOptions, ExplainSource, ExplainTotals, LoadedConfig, PathExplanation, PrettyOptions, ScanSettings, SkipsExplanation, Style };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { q as AbortError, L as BUDGET_METRICS, U as CATEGORIES, g as CONFIG_FILE_NAMES, A as DEFAULT_CONCURRENCY, N as DEFAULT_EXCLUDES, x as DEFAULT_EXPLAIN_LIMIT, D as DEFAULT_LARGE_FILE_THRESHOLD, O as DEFAULT_STALE_AGE, J as DatError, S as EXPLAIN_VERSION, C as MAX_EXPLAIN_LIMIT, W as VERSION, k as analyze, y as buildJsonSchema, F as classify, E as compare, m as createStyle, R as evaluateBudgets, w as explainPath, T as explainSkips, I as extensionOf, _ as findConfigFile, V as formatBytes, j as listDirectories, v as loadConfig, B as parseBudget, G as parseDuration, K as parsePointInTime, H as parseSize, c as renderAnalysis, i as renderAnalysisCsv, r as renderAnalysisHtml, o as renderAnalysisMarkdown, l as renderComparison, a as renderComparisonCsv, s as renderComparisonMarkdown, t as renderPathExplanation, n as renderSkipsExplanation, b as validateConfig } from "./shared-DfKY8fSl.js";
1
+ export { X as AbortError, B as BUDGET_METRICS, K as CATEGORIES, g as CONFIG_FILE_NAMES, N as DEFAULT_CONCURRENCY, I as DEFAULT_EXCLUDES, x as DEFAULT_EXPLAIN_LIMIT, A as DEFAULT_LARGE_FILE_THRESHOLD, j as DEFAULT_STALE_AGE, Z as DatError, S as EXPLAIN_VERSION, C as MAX_EXPLAIN_LIMIT, q as VERSION, M as analyze, y as buildJsonSchema, R as classify, k as compactAnalysis, O as compare, m as createStyle, V as evaluateBudgets, w as explainPath, T as explainSkips, z as extensionOf, _ as findConfigFile, W as formatBytes, P as listDirectories, v as loadConfig, U as parseBudget, J as parseDuration, Y as parsePointInTime, G as parseSize, c as renderAnalysis, i as renderAnalysisCsv, r as renderAnalysisHtml, o as renderAnalysisMarkdown, l as renderComparison, a as renderComparisonCsv, s as renderComparisonMarkdown, t as renderPathExplanation, n as renderSkipsExplanation, b as validateConfig } from "./shared-CikLbzoj.js";
@@ -2500,6 +2500,93 @@ function createProgressReporter(report, interval, snapshot) {
2500
2500
  }
2501
2501
  };
2502
2502
  }
2503
+ // src/core/compact.ts
2504
+ /**
2505
+ * Bounds every list in an analysis result to `limit` items, for scripts and
2506
+ * agents that read the JSON. Counts and sizes stay the full totals; what was
2507
+ * cut is listed in `compact.omitted`. Returns a new result and leaves the
2508
+ * input untouched.
2509
+ *
2510
+ * Cut: `extensions`, the `items` of `largeFiles`, `duplicates`, `emptyFiles`,
2511
+ * `emptyDirectories`, and `staleFiles`, the `files` of each listed duplicate
2512
+ * group, and `errors`. Not cut: `summary`, `types`, `budgets`, and the lists
2513
+ * already bounded by `top` or by the tree's own per-folder limit.
2514
+ */
2515
+ function compactAnalysis(result, options) {
2516
+ const { limit } = options;
2517
+ if (!Number.isSafeInteger(limit) || limit < 0) throw new RangeError(`compact limit must be a whole number of at least 0 (got ${limit}).`);
2518
+ const previous = result.compact?.omitted ?? {};
2519
+ const cuts = [];
2520
+ const note = (list, total, shown) => {
2521
+ if (total > shown) cuts.push([list, total - shown]);
2522
+ };
2523
+ const cut = (list, items, total) => {
2524
+ const shown = items.slice(0, limit);
2525
+ note(list, Math.max(total, items.length), shown.length);
2526
+ return shown;
2527
+ };
2528
+ const out = { ...result };
2529
+ out.extensions = cut("extensions", result.extensions, result.extensions.length + (previous.extensions ?? 0));
2530
+ out.errors = cut("errors", result.errors, result.summary.errors);
2531
+ if (result.largeFiles) {
2532
+ const s = result.largeFiles;
2533
+ out.largeFiles = {
2534
+ ...s,
2535
+ items: cut("largeFiles.items", s.items, s.count)
2536
+ };
2537
+ }
2538
+ if (result.emptyFiles) {
2539
+ const s = result.emptyFiles;
2540
+ out.emptyFiles = {
2541
+ ...s,
2542
+ items: cut("emptyFiles.items", s.items, s.count)
2543
+ };
2544
+ }
2545
+ if (result.emptyDirectories) {
2546
+ const s = result.emptyDirectories;
2547
+ out.emptyDirectories = {
2548
+ ...s,
2549
+ items: cut("emptyDirectories.items", s.items, s.count)
2550
+ };
2551
+ }
2552
+ if (result.staleFiles) {
2553
+ const s = result.staleFiles;
2554
+ out.staleFiles = {
2555
+ ...s,
2556
+ items: cut("staleFiles.items", s.items, s.count)
2557
+ };
2558
+ }
2559
+ if (result.duplicates) {
2560
+ const s = result.duplicates;
2561
+ let cutFiles = 0;
2562
+ const items = cut("duplicates.items", s.items, s.count).map((group) => {
2563
+ const copies = group.files.length + (group.omittedFiles ?? 0);
2564
+ if (copies <= limit && group.omittedFiles === void 0) return group;
2565
+ const files = group.files.slice(0, limit);
2566
+ cutFiles += copies - files.length;
2567
+ return {
2568
+ ...group,
2569
+ files,
2570
+ omittedFiles: copies - files.length
2571
+ };
2572
+ });
2573
+ out.duplicates = {
2574
+ ...s,
2575
+ items
2576
+ };
2577
+ note("duplicates.items[].files", cutFiles, 0);
2578
+ }
2579
+ const order = Object.keys(result);
2580
+ const position = (list) => order.indexOf(list.split(".")[0]);
2581
+ cuts.sort((a, b) => position(a[0]) - position(b[0]));
2582
+ const omitted = Object.fromEntries(cuts);
2583
+ out.compact = {
2584
+ limit,
2585
+ truncated: cuts.length > 0,
2586
+ omitted
2587
+ };
2588
+ return out;
2589
+ }
2503
2590
  // src/core/compare.ts
2504
2591
  const PASS_THROUGH_SHARE = .95;
2505
2592
  /** Records every file by its root-relative path, for diffing. */
@@ -2980,6 +3067,15 @@ function entryType(stats) {
2980
3067
  function isSpecial(entry) {
2981
3068
  return entry.isBlockDevice() || entry.isCharacterDevice() || entry.isFIFO() || entry.isSocket();
2982
3069
  }
3070
+ /** Whether an absolute `target` lies outside the absolute directory `root`. */
3071
+ function isOutside(root, target) {
3072
+ const fromRoot = relative(root, target);
3073
+ return fromRoot === ".." || fromRoot.startsWith(`..${sep}`) || isAbsolute(fromRoot);
3074
+ }
3075
+ /** The error for a path outside the root, naming the path as the caller gave it. */
3076
+ function outsideRootError(path, root) {
3077
+ return new DatError(`${path} is outside the root ${root}.`, { hint: "Pass the directory that contains it with --root." });
3078
+ }
2983
3079
  /**
2984
3080
  * Explains what a scan of `root` with these settings does with one path:
2985
3081
  * whether it is counted, and if not, which rule or limit decided and where.
@@ -3001,9 +3097,8 @@ async function explainPath(root, path, settings = {}) {
3001
3097
  const { options, settings: resolved } = await resolveScan(root, settings, Date.now());
3002
3098
  const absRoot = options.root;
3003
3099
  const target = resolve(absRoot, path);
3004
- const fromRoot = relative(absRoot, target);
3005
- if (fromRoot === ".." || fromRoot.startsWith(`..${sep}`) || isAbsolute(fromRoot)) throw new DatError(`${path} is outside the root ${absRoot}.`, { hint: "Pass the directory that contains it with --root." });
3006
- const relPath = fromRoot.split(sep).join("/");
3100
+ if (isOutside(absRoot, target)) throw outsideRootError(path, absRoot);
3101
+ const relPath = relative(absRoot, target).split(sep).join("/");
3007
3102
  const segments = relPath ? relPath.split("/") : [];
3008
3103
  const excluder = options.excluder;
3009
3104
  const book = new RuleBook(excluder, absRoot, resolved.exclude);
@@ -4767,7 +4862,7 @@ function renderSkipsExplanation(result, options = {}) {
4767
4862
  result.groups.forEach((group, i) => {
4768
4863
  lines.push(` ${padEndVisible(labels[i], labelWidth)} ${s.bold(formatCount(group.count).padStart(countWidth))}`);
4769
4864
  for (const entry of group.entries) lines.push(` ${fitPath(entry, width - 6)}`);
4770
- if (group.truncated) {
4865
+ if (group.truncated && result.limit > 0) {
4771
4866
  const rest = group.count - group.entries.length;
4772
4867
  lines.push(s.dim(` … and ${formatCount(rest)} more (raise --limit, up to 1000, to list more)`));
4773
4868
  }
@@ -4785,4 +4880,4 @@ function renderSkipsExplanation(result, options = {}) {
4785
4880
  }
4786
4881
  return `${lines.join("\n")}\n`;
4787
4882
  }
4788
- export { DEFAULT_CONCURRENCY as A, parseBudget as B, MAX_EXPLAIN_LIMIT as C, DEFAULT_LARGE_FILE_THRESHOLD as D, compare as E, classify as F, parseDuration as G, parseSize as H, extensionOf as I, DatError as J, parsePointInTime as K, BUDGET_METRICS as L, joinRelative as M, DEFAULT_EXCLUDES as N, DEFAULT_STALE_AGE as O, Excluder as P, evaluateBudgets as R, EXPLAIN_VERSION as S, explainSkips as T, CATEGORIES as U, formatBytes as V, VERSION as W, errorMessage as X, errorCode as Y, findConfigFile as _, renderComparisonCsv as a, validateConfig as b, renderAnalysis as c, escapeControlInLines as d, formatCount as f, CONFIG_FILE_NAMES as g, supportsColor as h, renderAnalysisCsv as i, listDirectories as j, analyze as k, renderComparison as l, createStyle as m, renderSkipsExplanation as n, renderAnalysisMarkdown as o, stringifyJson as p, AbortError as q, renderAnalysisHtml as r, renderComparisonMarkdown as s, renderPathExplanation as t, escapeControl as u, loadConfig as v, explainPath as w, DEFAULT_EXPLAIN_LIMIT as x, buildJsonSchema as y, formatBudgetActual as z };
4883
+ export { errorMessage as $, DEFAULT_LARGE_FILE_THRESHOLD as A, BUDGET_METRICS as B, MAX_EXPLAIN_LIMIT as C, outsideRootError as D, isOutside as E, joinRelative as F, parseSize as G, formatBudgetActual as H, DEFAULT_EXCLUDES as I, parseDuration as J, CATEGORIES as K, Excluder as L, analyze as M, DEFAULT_CONCURRENCY as N, compare as O, listDirectories as P, errorCode as Q, classify as R, EXPLAIN_VERSION as S, explainSkips as T, parseBudget as U, evaluateBudgets as V, formatBytes as W, AbortError as X, parsePointInTime as Y, DatError as Z, findConfigFile as _, renderComparisonCsv as a, validateConfig as b, renderAnalysis as c, escapeControlInLines as d, formatCount as f, CONFIG_FILE_NAMES as g, supportsColor as h, renderAnalysisCsv as i, DEFAULT_STALE_AGE as j, compactAnalysis as k, renderComparison as l, createStyle as m, renderSkipsExplanation as n, renderAnalysisMarkdown as o, stringifyJson as p, VERSION as q, renderAnalysisHtml as r, renderComparisonMarkdown as s, renderPathExplanation as t, escapeControl as u, loadConfig as v, explainPath as w, DEFAULT_EXPLAIN_LIMIT as x, buildJsonSchema as y, extensionOf as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dir-analysis-tool",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Fast, zero-dependency directory analysis for your terminal and CI: largest folders and files, type and extension breakdowns, staged duplicate detection, size budgets, directory diffs, and self-contained HTML, Markdown, JSON, and CSV reports.",
5
5
  "type": "module",
6
6
  "exports": {