@kaynooo/cli-workspace 0.2.0 → 0.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/dist/sweep-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/sweep-cli.ts
5
- import process13 from "process";
5
+ import process17 from "process";
6
6
 
7
7
  // ../kit/src/advisory.ts
8
8
  var SEVERITIES = ["low", "moderate", "high", "critical"];
@@ -13,14 +13,35 @@ function isIgnored(advisory, ignore) {
13
13
  return ignore.includes(advisory.ghsa ?? "") || ignore.includes(String(advisory.id));
14
14
  }
15
15
  // ../kit/src/args.ts
16
- import process5 from "process";
16
+ import process9 from "process";
17
17
  import { parseArgs } from "util";
18
18
 
19
19
  // ../kit/src/format.ts
20
- import process3 from "process";
20
+ import process7 from "process";
21
21
 
22
- // ../kit/src/style.ts
22
+ // ../kit/src/mode.ts
23
23
  import process2 from "process";
24
+ var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
25
+ var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
26
+ function isSet(value) {
27
+ return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
28
+ }
29
+ function outputMode(stream = process2.stdout, env = process2.env) {
30
+ const chosen = env.KIT_MODE;
31
+ if (chosen !== undefined && MODES.has(chosen))
32
+ return chosen;
33
+ if (AGENT_VARIABLES.some((name) => isSet(env[name])))
34
+ return "agent";
35
+ if (stream.isTTY === true)
36
+ return "terminal";
37
+ return isSet(env.CI) ? "ci" : "pipe";
38
+ }
39
+ function isInteractive(streams = process2) {
40
+ return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
41
+ }
42
+
43
+ // ../kit/src/style.ts
44
+ import process6 from "process";
24
45
 
25
46
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
26
47
  function x(s) {
@@ -283,52 +304,256 @@ function le(i = {}) {
283
304
  }
284
305
  var t = le();
285
306
 
286
- // ../kit/src/style.ts
287
- var MARKS = {
288
- ok: { symbol: "\u2713", word: "ok:", paint: (colors) => colors.green },
289
- warn: { symbol: "!", word: "warning:", paint: (colors) => colors.yellow },
290
- problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
291
- note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
307
+ // ../kit/src/theme.ts
308
+ import { existsSync as existsSync3, readFileSync, statSync } from "fs";
309
+ import { homedir as homedir2 } from "os";
310
+ import { join as join3, resolve as resolve2 } from "path";
311
+ import process5 from "process";
312
+
313
+ // ../kit/src/config.ts
314
+ import { existsSync } from "fs";
315
+ import { dirname, join, resolve } from "path";
316
+ import process3 from "process";
317
+ function findUp(names, from = process3.cwd(), stop = () => false) {
318
+ const wanted = typeof names === "string" ? [names] : names;
319
+ for (let dir = resolve(from);; dir = dirname(dir)) {
320
+ const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
321
+ if (found !== undefined)
322
+ return found;
323
+ if (stop(dir) || dirname(dir) === dir)
324
+ return;
325
+ }
326
+ }
327
+
328
+ // ../kit/src/user-config.ts
329
+ import { existsSync as existsSync2 } from "fs";
330
+ import { homedir } from "os";
331
+ import { join as join2 } from "path";
332
+ import process4 from "process";
333
+ function configBase(where = {}) {
334
+ const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
335
+ return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
336
+ }
337
+ function userConfigPath(bin, where = {}) {
338
+ return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
339
+ }
340
+ function userConfigReadPath(bin, legacy = [], where = {}) {
341
+ const current = userConfigPath(bin, where);
342
+ if (existsSync2(current))
343
+ return current;
344
+ const base = configBase(where);
345
+ return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
346
+ }
347
+
348
+ // ../kit/src/theme.ts
349
+ var DEFAULT = {
350
+ colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
351
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
352
+ accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
353
+ bins: {}
292
354
  };
293
- function takesControlCodes(stream, env = process2.env) {
294
- return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
355
+ var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
356
+ var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
357
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
358
+ var PRESETS = {
359
+ default: {},
360
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
361
+ mono: { colors: MONO, accents: ["bold"] },
362
+ ascii: { glyphs: ASCII }
363
+ };
364
+ var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
365
+ var HEX = /^#[0-9a-f]{6}$/i;
366
+ var CONTROL = /\p{Cc}/u;
367
+ var MAX_FILE_BYTES = 64 * 1024;
368
+ var SPACES = /\s+/;
369
+ function isColorSpec(spec) {
370
+ if (typeof spec === "number")
371
+ return Number.isInteger(spec) && spec >= 0 && spec <= 255;
372
+ return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
373
+ }
374
+ var CUBE = [0, 95, 135, 175, 215, 255];
375
+ function cubeLevel(channel) {
376
+ return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
377
+ }
378
+ function nearest256(hex) {
379
+ const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
380
+ const levels = rgb.map(cubeLevel);
381
+ const cube = levels.map((level) => CUBE[level]);
382
+ const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
383
+ const greyValue = 8 + grey * 10;
384
+ const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
385
+ return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
386
+ }
387
+ function hasTrueColor(env) {
388
+ return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
389
+ }
390
+ function tinted(colors, spec, env = process5.env) {
391
+ if (typeof spec === "number")
392
+ return colors.ansi256(spec);
393
+ return spec.trim().split(SPACES).reduce((chain, token) => {
394
+ if (HEX.test(token))
395
+ return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
396
+ return chain[token] ?? chain;
397
+ }, colors);
398
+ }
399
+ function isRecord(value) {
400
+ return typeof value === "object" && value !== null && !Array.isArray(value);
401
+ }
402
+ function readThemeFile(path, warn) {
403
+ try {
404
+ const stat = statSync(path, { throwIfNoEntry: false });
405
+ if (stat === undefined)
406
+ return;
407
+ if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
408
+ warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
409
+ return;
410
+ }
411
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
412
+ if (isRecord(parsed))
413
+ return parsed;
414
+ warn(`${path} is not a JSON object, theme ignored`);
415
+ } catch (error) {
416
+ warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
417
+ }
418
+ return;
295
419
  }
296
- function paint(stream, env = process2.env) {
420
+ function applyPreset(theme, name, warn, where) {
421
+ if (name === undefined)
422
+ return;
423
+ if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
424
+ warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
425
+ return;
426
+ }
427
+ const preset = PRESETS[name];
428
+ Object.assign(theme.colors, preset.colors);
429
+ Object.assign(theme.glyphs, preset.glyphs);
430
+ if (preset.accents !== undefined)
431
+ theme.accents = [...preset.accents];
432
+ return name;
433
+ }
434
+ function applyFile(theme, file, where, warn) {
435
+ if (isRecord(file.colors)) {
436
+ for (const [key, value] of Object.entries(file.colors)) {
437
+ if (!Object.hasOwn(DEFAULT.colors, key))
438
+ warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
439
+ else if (!isColorSpec(value))
440
+ warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
441
+ else
442
+ theme.colors[key] = value;
443
+ }
444
+ }
445
+ if (isRecord(file.glyphs)) {
446
+ for (const [key, value] of Object.entries(file.glyphs)) {
447
+ if (!Object.hasOwn(DEFAULT.glyphs, key))
448
+ warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
449
+ else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
450
+ warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
451
+ else
452
+ theme.glyphs[key] = value;
453
+ }
454
+ }
455
+ if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
456
+ theme.accents = [...file.accents];
457
+ else if (file.accents !== undefined)
458
+ warn(`${where}: accents must be a non-empty list of colours`);
459
+ if (isRecord(file.bins)) {
460
+ for (const [bin, value] of Object.entries(file.bins)) {
461
+ if (isColorSpec(value))
462
+ theme.bins[bin] = value;
463
+ else
464
+ warn(`${where}: bin ${bin} has no valid colour`);
465
+ }
466
+ }
467
+ }
468
+ function endsWalk(home) {
469
+ return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
470
+ }
471
+ var warned = new Set;
472
+ function warnOnce(message) {
473
+ if (warned.has(message))
474
+ return;
475
+ warned.add(message);
476
+ console.error(`warning: theme ${message}`);
477
+ }
478
+ function isPath(chosen) {
479
+ return chosen.includes("/") || chosen.endsWith(".json");
480
+ }
481
+ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
482
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
483
+ const sources = [];
484
+ const chosen = env.KIT_THEME ?? "";
485
+ const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
486
+ if (isPath(chosen))
487
+ wanted.push(resolve2(from, chosen));
488
+ const files = [];
489
+ for (const path of wanted) {
490
+ const file = path === undefined ? undefined : readThemeFile(path, warn);
491
+ if (path !== undefined && file !== undefined)
492
+ files.push({ path, file });
493
+ }
494
+ let preset = "default";
495
+ if (chosen !== "" && !isPath(chosen)) {
496
+ preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
497
+ } else {
498
+ const named = files.findLast(({ file }) => file.preset !== undefined);
499
+ if (named !== undefined)
500
+ preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
501
+ }
502
+ for (const { path, file } of files) {
503
+ applyFile(theme, file, path, warn);
504
+ sources.push(path);
505
+ }
506
+ return { theme, sources, preset };
507
+ }
508
+ var current;
509
+ var currentKey = "";
510
+ function activeTheme() {
511
+ const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
512
+ if (current === undefined || key !== currentKey) {
513
+ current = loadTheme();
514
+ currentKey = key;
515
+ }
516
+ return current;
517
+ }
518
+
519
+ // ../kit/src/style.ts
520
+ var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
521
+ function takesControlCodes(stream, env = process6.env) {
522
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
523
+ }
524
+ function paint(stream, env = process6.env) {
297
525
  return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
298
526
  }
299
- function marked(mark, text, stream, detail, env = process2.env) {
527
+ function marked(mark, text, stream, detail, env = process6.env) {
300
528
  const colors = paint(stream, env);
301
- const { symbol, word, paint: tint } = MARKS[mark];
302
- const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
529
+ let head = MARK_WORDS[mark];
530
+ if (takesControlCodes(stream, env)) {
531
+ const { theme } = activeTheme();
532
+ head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
533
+ }
303
534
  return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
304
535
  }
305
536
  function ok(text, detail) {
306
- console.log(marked("ok", text, process2.stdout, detail));
537
+ console.log(marked("ok", text, process6.stdout, detail));
307
538
  }
308
539
  function note(text, detail) {
309
- console.log(marked("note", text, process2.stdout, detail));
540
+ console.log(marked("note", text, process6.stdout, detail));
310
541
  }
311
542
  function problem(text, detail) {
312
- console.error(marked("problem", text, process2.stderr, detail));
313
- }
314
- var ROLES = {
315
- accent: (colors) => colors.cyan,
316
- id: (colors) => colors.yellow,
317
- path: (colors) => colors.blue,
318
- label: (colors) => colors.dim,
319
- value: (colors) => colors.bold
320
- };
321
- function role(name, stream, env = process2.env) {
322
- return ROLES[name](paint(stream, env));
323
- }
324
- var STATUSES = {
325
- passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
326
- failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
327
- running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
328
- queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
329
- skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
543
+ console.error(marked("problem", text, process6.stderr, detail));
544
+ }
545
+ function role(name, stream, env = process6.env) {
546
+ const colors = paint(stream, env);
547
+ return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
548
+ }
549
+ var STATUS_WORDS = {
550
+ passed: ["passed", "success", "succeeded", "ok"],
551
+ failed: ["failed", "failure", "error", "errored"],
552
+ running: ["running", "in_progress", "started", "holding"],
553
+ queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
554
+ skipped: ["skipped", "cancelled", "canceled", "manual"]
330
555
  };
331
- var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
556
+ var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
332
557
  // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-hrsswv1w.js
333
558
  function $e(t, e = false, i = 1) {
334
559
  let n = typeof e === "object" ? e : { units: e ? "si" : "iec", dp: i }, { units: s = "iec", dp: u = 1 } = n, r = s === "si" ? 1000 : 1024;
@@ -378,15 +603,18 @@ var ESCAPE = String.fromCharCode(27);
378
603
  function textWidth(text) {
379
604
  return Bun.stringWidth(text);
380
605
  }
381
- function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
606
+ function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
382
607
  const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
608
+ if (outputMode(stream, env) === "agent")
609
+ return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
610
+ `);
383
611
  const widths = [];
384
612
  for (const row of cells) {
385
613
  for (const [index, cell] of row.entries())
386
614
  widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
387
615
  }
388
616
  const shown = fit === undefined ? cells : narrow(cells, widths, fit);
389
- const colors = paint(process3.stdout);
617
+ const colors = paint(stream);
390
618
  const lines = shown.map((row) => row.map((cell, index) => {
391
619
  const width = widths[index] ?? 0;
392
620
  const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
@@ -394,7 +622,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
394
622
  return `${gap}${cell}`;
395
623
  return index === row.length - 1 ? cell : `${cell}${gap}`;
396
624
  }).join(" ").trimEnd());
397
- return lines.map((line, index) => header && index === 0 ? colors.bold(line) : line).join(`
625
+ const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
626
+ return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
398
627
  `);
399
628
  }
400
629
  function narrow(rows, widths, limit) {
@@ -413,32 +642,35 @@ function narrow(rows, widths, limit) {
413
642
  }
414
643
  return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
415
644
  }
645
+ function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
646
+ return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
647
+ }
416
648
  function printJson(value) {
417
- console.log(JSON.stringify(value, undefined, 2));
649
+ console.log(jsonText(value));
418
650
  }
419
651
 
420
652
  // ../kit/src/help.ts
421
- import process4 from "process";
653
+ import process8 from "process";
422
654
  var OPTIONAL = /\[[^\]]+\]/g;
423
655
  var USAGE_PREFIX = /^usage:\s*/i;
424
656
  var FULL_STOP = /\.$/;
425
- function usageLine(usage, colors = paint(process4.stdout)) {
657
+ function usageLine(usage, colors = paint(process8.stdout)) {
426
658
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
427
659
  }
428
- function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
660
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
429
661
  return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
430
662
  `);
431
663
  }
432
- function exitRows(exits, colors = paint(process4.stdout)) {
664
+ function exitRows(exits, colors = paint(process8.stdout)) {
433
665
  if (exits.length === 0)
434
666
  return [];
435
667
  const width = Math.max(...exits.map(([code]) => String(code).length));
436
668
  return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
437
669
  }
438
- function replacesRows(replaces, colors = paint(process4.stdout)) {
439
- return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
670
+ function replacesRows(replaces, colors = paint(process8.stdout)) {
671
+ return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
440
672
  }
441
- function wantsHelpJson(env = process4.env) {
673
+ function wantsHelpJson(env = process8.env) {
442
674
  return env.KIT_HELP === "json";
443
675
  }
444
676
  function description(usage, { examples = [], replaces, exits } = {}, options) {
@@ -457,12 +689,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
457
689
  ...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
458
690
  };
459
691
  }
460
- function exampleRows(examples, colors = paint(process4.stdout)) {
461
- if (examples.length === 0)
692
+ function exampleRows(examples, colors = paint(process8.stdout)) {
693
+ if (examples.length === 0 || outputMode() === "agent")
462
694
  return [];
463
695
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
464
696
  }
465
- function optionRows(options, colors = paint(process4.stdout)) {
697
+ function optionRows(options, colors = paint(process8.stdout)) {
466
698
  const rows = Object.entries(options).map(([name, option]) => {
467
699
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
468
700
  const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
@@ -555,7 +787,7 @@ var OUTPUT_OPTIONS = {
555
787
  color: { type: "string", description: "auto (on a terminal alone), always or never" },
556
788
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
557
789
  };
558
- function applyOutput(color, plain, env = process5.env) {
790
+ function applyOutput(color, plain, env = process9.env) {
559
791
  const when = plain === true ? "never" : color ?? "auto";
560
792
  if (when === "auto")
561
793
  return;
@@ -726,7 +958,7 @@ function nearestOption(message, options, allowNegative) {
726
958
  }
727
959
  // ../kit/src/process.ts
728
960
  import { constants } from "os";
729
- import process6 from "process";
961
+ import process10 from "process";
730
962
  var KILL_GRACE_MS = 2000;
731
963
  function exitCodeOf(code, signal) {
732
964
  if (code !== null)
@@ -746,7 +978,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
746
978
  return;
747
979
  try {
748
980
  if (grouped)
749
- process6.kill(-proc.pid, killing);
981
+ process10.kill(-proc.pid, killing);
750
982
  else
751
983
  proc.kill(killing);
752
984
  } catch {}
@@ -821,10 +1053,10 @@ var RESET_STYLE = `${ESC}[0m`;
821
1053
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
822
1054
 
823
1055
  // ../kit/src/tool.ts
824
- import process7 from "process";
1056
+ import process11 from "process";
825
1057
  function cwdGone() {
826
1058
  try {
827
- process7.cwd();
1059
+ process11.cwd();
828
1060
  return false;
829
1061
  } catch {
830
1062
  return true;
@@ -846,7 +1078,7 @@ function spawnFailure(command, error) {
846
1078
  async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
847
1079
  let ran;
848
1080
  try {
849
- ran = await runCommand(argv, { env: process7.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
1081
+ ran = await runCommand(argv, { env: process11.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
850
1082
  } catch (error) {
851
1083
  throw spawnFailure(label, error);
852
1084
  }
@@ -861,15 +1093,15 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
861
1093
  return { code: ran.code, ...streams };
862
1094
  }
863
1095
  // ../kit/src/cli.ts
864
- import { readFileSync, realpathSync } from "fs";
865
- import { dirname as dirname2, join as join2 } from "path";
866
- import process9 from "process";
1096
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
1097
+ import { dirname as dirname3, join as join5 } from "path";
1098
+ import process13 from "process";
867
1099
 
868
1100
  // ../kit/src/usage.ts
869
1101
  import { appendFileSync, mkdirSync } from "fs";
870
- import { homedir } from "os";
871
- import { dirname, isAbsolute, join } from "path";
872
- import process8 from "process";
1102
+ import { homedir as homedir3 } from "os";
1103
+ import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1104
+ import process12 from "process";
873
1105
 
874
1106
  // ../kit/src/logs.ts
875
1107
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -883,14 +1115,14 @@ var usageError;
883
1115
  function noteUsageError(message) {
884
1116
  usageError = message;
885
1117
  }
886
- function stateHome(env = process8.env) {
1118
+ function stateHome(env = process12.env) {
887
1119
  const dir = env.XDG_STATE_HOME;
888
- return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
1120
+ return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
889
1121
  }
890
- function usagePath(env = process8.env) {
891
- return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
1122
+ function usagePath(env = process12.env) {
1123
+ return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
892
1124
  }
893
- function usageRecorded(env = process8.env) {
1125
+ function usageRecorded(env = process12.env) {
894
1126
  const off = env.KAYNOOO_CLI_NO_USAGE;
895
1127
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
896
1128
  }
@@ -904,12 +1136,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
904
1136
  usageError = undefined;
905
1137
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
906
1138
  }
907
- function recordUsage(entry, env = process8.env) {
1139
+ function recordUsage(entry, env = process12.env) {
908
1140
  if (!usageRecorded(env))
909
1141
  return;
910
1142
  try {
911
1143
  const path = usagePath(env);
912
- mkdirSync(dirname(path), { recursive: true, mode: 448 });
1144
+ mkdirSync(dirname2(path), { recursive: true, mode: 448 });
913
1145
  appendFileSync(path, `${JSON.stringify(entry)}
914
1146
  `, { mode: 384 });
915
1147
  } catch {}
@@ -995,8 +1227,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
995
1227
  `);
996
1228
  }
997
1229
  function printError(prefix, message, hint, cause) {
998
- const colors = paint(process9.stderr);
999
- const styled = takesControlCodes(process9.stderr);
1230
+ const colors = paint(process13.stderr);
1231
+ const styled = takesControlCodes(process13.stderr);
1000
1232
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1001
1233
  const under = (label, text, tint) => text === undefined ? "" : `
1002
1234
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1039,11 +1271,11 @@ async function dispatch(level, typed, { version, redact }) {
1039
1271
  }
1040
1272
  }
1041
1273
  if (name === undefined && level.path.length > 1) {
1042
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stderr));
1274
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
1043
1275
  return 2;
1044
1276
  }
1045
1277
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1046
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stdout));
1278
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
1047
1279
  return 0;
1048
1280
  }
1049
1281
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1160,17 +1392,17 @@ async function printCandidates(found) {
1160
1392
  return 0;
1161
1393
  }
1162
1394
  function packageVersion(entry = Bun.main) {
1163
- for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
1395
+ for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1164
1396
  try {
1165
- const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
1397
+ const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1166
1398
  if (typeof version === "string")
1167
1399
  return version;
1168
1400
  } catch {}
1169
- if (dirname2(dir) === dir)
1401
+ if (dirname3(dir) === dir)
1170
1402
  return "0.0.0";
1171
1403
  }
1172
1404
  }
1173
- async function runCli(cli, argv = process9.argv.slice(2)) {
1405
+ async function runCli(cli, argv = process13.argv.slice(2)) {
1174
1406
  const version = cli.version ?? packageVersion();
1175
1407
  if (argv[0] === COMPLETE)
1176
1408
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1197,7 +1429,7 @@ function commandPath(scope, argv) {
1197
1429
  }
1198
1430
  return path.length === 0 ? undefined : path.join(" ");
1199
1431
  }
1200
- async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
1432
+ async function runMain({ name, version, run, redact, usage }, argv = process13.argv.slice(2)) {
1201
1433
  if (argv[0] === COMPLETE)
1202
1434
  return printCandidates(leafCandidates(run, argv.slice(1)));
1203
1435
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1217,6 +1449,19 @@ async function runMain({ name, version, run, redact, usage }, argv = process9.ar
1217
1449
  }
1218
1450
  return code;
1219
1451
  }
1452
+ // ../kit/src/pool.ts
1453
+ async function pool(items, limit, task) {
1454
+ const results = Array.from({ length: items.length });
1455
+ let next = 0;
1456
+ async function worker() {
1457
+ while (next < items.length) {
1458
+ const index = next++;
1459
+ results[index] = await task(items[index]);
1460
+ }
1461
+ }
1462
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
1463
+ return results;
1464
+ }
1220
1465
  // ../kit/src/secrets.ts
1221
1466
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1222
1467
  // ../kit/src/sessions.ts
@@ -1233,37 +1478,44 @@ function parseSize(text, bareUnit = 1) {
1233
1478
  const suffix = match[2].toLowerCase();
1234
1479
  return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1235
1480
  }
1236
- // ../kit/src/user-config.ts
1237
- import { existsSync } from "fs";
1238
- import { homedir as homedir2 } from "os";
1239
- import { join as join3 } from "path";
1240
- import process10 from "process";
1241
- function configBase(where = {}) {
1242
- const xdg = where.xdg ?? (where.home === undefined ? process10.env.XDG_CONFIG_HOME : undefined);
1243
- return xdg !== undefined && xdg !== "" ? xdg : join3(where.home ?? homedir2(), ".config");
1244
- }
1245
- function userConfigPath(bin, where = {}) {
1246
- return join3(configBase(where), "kaynooo-cli", `${bin}.json`);
1481
+ // ../kit/src/workspace-root.ts
1482
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
1483
+ import { homedir as homedir4 } from "os";
1484
+ import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
1485
+ import process14 from "process";
1486
+ function expandHome(path, home) {
1487
+ if (path === "~")
1488
+ return home;
1489
+ return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
1490
+ }
1491
+ function configured(env, home) {
1492
+ const path = userConfigPath("config", { home, xdg: env.XDG_CONFIG_HOME });
1493
+ if (!existsSync4(path))
1494
+ return;
1495
+ try {
1496
+ const parsed = JSON.parse(readFileSync3(path, "utf8"));
1497
+ const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
1498
+ return typeof folder === "string" && folder !== "" ? folder : undefined;
1499
+ } catch {
1500
+ return;
1501
+ }
1247
1502
  }
1248
- function userConfigReadPath(bin, legacy = [], where = {}) {
1249
- const current = userConfigPath(bin, where);
1250
- if (existsSync(current))
1251
- return current;
1252
- const base = configBase(where);
1253
- return legacy.map((parts) => join3(base, ...parts)).find((path) => existsSync(path)) ?? current;
1503
+ function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
1504
+ const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1505
+ return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1254
1506
  }
1255
1507
  // src/sweep.ts
1256
- import { existsSync as existsSync4, statSync } from "fs";
1257
- import { homedir as homedir4 } from "os";
1258
- import { join as join7, relative, resolve } from "path";
1508
+ import { existsSync as existsSync7, statSync as statSync2 } from "fs";
1509
+ import { homedir as homedir6 } from "os";
1510
+ import { relative } from "path";
1259
1511
 
1260
1512
  // ../kit/src/prompt.ts
1261
- import process12 from "process";
1513
+ import process16 from "process";
1262
1514
  var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|[\s\S]/giu;
1263
- var CONTROL = /^[\x00-\x1F\x7F]/;
1515
+ var CONTROL2 = /^[\x00-\x1F\x7F]/;
1264
1516
  var KEYS = { "\x1B[A": "up", "\x1BOA": "up", "\x1B[B": "down", "\x1BOB": "down", "\r": "enter", "\n": "enter", "\x03": "cancel", "\x1B": "cancel", "\x7F": "erase", "\b": "erase" };
1265
1517
  function readKeys(input) {
1266
- return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => KEYS[sequence] ?? (CONTROL.test(sequence) ? [] : [{ text: sequence }]));
1518
+ return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => KEYS[sequence] ?? (CONTROL2.test(sequence) ? [] : [{ text: sequence }]));
1267
1519
  }
1268
1520
  async function confirm(question, { default: fallback, ...settings } = {}) {
1269
1521
  let answered = fallback;
@@ -1287,9 +1539,9 @@ function asking(colors, question, typed, keys) {
1287
1539
  function answer(colors, question, state, picked) {
1288
1540
  return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1289
1541
  }
1290
- async function ask(question, { hint, terminal = process12 }, render, press) {
1542
+ async function ask(question, { hint, terminal = process16 }, render, press) {
1291
1543
  const { stdin, stderr } = terminal;
1292
- if (stdin.isTTY !== true || stderr.isTTY !== true)
1544
+ if (!isInteractive(terminal))
1293
1545
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
1294
1546
  const colors = paint(stderr);
1295
1547
  let drawn = 0;
@@ -1338,31 +1590,22 @@ async function ask(question, { hint, terminal = process12 }, render, press) {
1338
1590
  }
1339
1591
 
1340
1592
  // src/apply.ts
1341
- import { existsSync as existsSync3 } from "fs";
1593
+ import { existsSync as existsSync6 } from "fs";
1342
1594
  import { lstat as lstat3, rm } from "fs/promises";
1343
- import { basename as basename2, join as join6 } from "path";
1595
+ import { basename as basename2, join as join9 } from "path";
1344
1596
 
1345
1597
  // src/sweep-scan.ts
1346
- import { existsSync as existsSync2 } from "fs";
1598
+ import { existsSync as existsSync5 } from "fs";
1347
1599
  import { lstat as lstat2, readdir as readdir2, realpath } from "fs/promises";
1348
- import { homedir as homedir3 } from "os";
1349
- import { basename, dirname as dirname3, join as join5 } from "path";
1600
+ import { homedir as homedir5 } from "os";
1601
+ import { basename, dirname as dirname5, join as join8 } from "path";
1350
1602
 
1351
1603
  // src/size.ts
1352
1604
  import { lstat, readdir } from "fs/promises";
1353
- import { join as join4 } from "path";
1354
- async function pooled(items, limit, work) {
1355
- const results = Array.from({ length: items.length });
1356
- let next = 0;
1357
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
1358
- while (next < items.length) {
1359
- const index = next++;
1360
- results[index] = await work(items[index]);
1361
- }
1362
- }));
1363
- return results;
1364
- }
1605
+ import { join as join7 } from "path";
1365
1606
  var FS_LIMIT = 32;
1607
+ var FIND_MS = 60000;
1608
+ var FIND_LINE = /^(\d+) (\S+) (\d+)$/gm;
1366
1609
  var waiting = [];
1367
1610
  var running = 0;
1368
1611
  async function gated(call) {
@@ -1376,7 +1619,7 @@ async function gated(call) {
1376
1619
  waiting.shift()?.();
1377
1620
  }
1378
1621
  }
1379
- async function sizeOf(folder) {
1622
+ async function walkSize(folder) {
1380
1623
  const seen = new Set;
1381
1624
  let total = 0;
1382
1625
  const visit = async (dir) => {
@@ -1387,7 +1630,7 @@ async function sizeOf(folder) {
1387
1630
  return;
1388
1631
  }
1389
1632
  await Promise.all(entries.map(async (entry) => {
1390
- const path = join4(dir, entry.name);
1633
+ const path = join7(dir, entry.name);
1391
1634
  if (entry.isDirectory())
1392
1635
  return visit(path);
1393
1636
  try {
@@ -1405,14 +1648,38 @@ async function sizeOf(folder) {
1405
1648
  await visit(folder);
1406
1649
  return total;
1407
1650
  }
1651
+ async function findSize(folder) {
1652
+ try {
1653
+ const ran = await runCommand(["find", "-P", folder, "(", "-type", "f", "-o", "-type", "l", ")", "-printf", "%n %D:%i %s\\n"], { timeoutMs: FIND_MS });
1654
+ const lines = [...ran.text.matchAll(FIND_LINE)];
1655
+ if (ran.timedOut || ran.code !== 0 && lines.length === 0)
1656
+ return;
1657
+ const seen = new Set;
1658
+ let total = 0;
1659
+ for (const [, links, id, bytes] of lines) {
1660
+ if (Number(links) > 1) {
1661
+ if (seen.has(id))
1662
+ continue;
1663
+ seen.add(id);
1664
+ }
1665
+ total += Number(bytes);
1666
+ }
1667
+ return total;
1668
+ } catch {
1669
+ return;
1670
+ }
1671
+ }
1672
+ async function sizeOf(folder) {
1673
+ return await findSize(folder) ?? await walkSize(folder);
1674
+ }
1408
1675
 
1409
1676
  // src/sweep-scan.ts
1410
1677
  var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target"]);
1411
1678
  var MAX_DEPTH = 3;
1412
1679
  var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit"]);
1413
1680
  var GLOBAL_CACHES = [".bun/install/cache", ".npm/_cacache", ".cache/pip", ".cache/uv", ".cache/ms-playwright", ".cache/puppeteer", ".cache/go-build", ".cache/typescript", ".cargo/registry"];
1414
- function isCachePath(path, home = homedir3()) {
1415
- return GLOBAL_CACHES.some((cache) => join5(home, cache) === path) || basename(path) === ".cache" && basename(dirname3(path)) === "node_modules";
1681
+ function isCachePath(path, home = homedir5()) {
1682
+ return GLOBAL_CACHES.some((cache) => join8(home, cache) === path) || basename(path) === ".cache" && basename(dirname5(path)) === "node_modules";
1416
1683
  }
1417
1684
  async function listing(dir) {
1418
1685
  try {
@@ -1423,7 +1690,7 @@ async function listing(dir) {
1423
1690
  }
1424
1691
  async function addGlobalCaches(found, home) {
1425
1692
  for (const cache of GLOBAL_CACHES) {
1426
- const path = join5(home, cache);
1693
+ const path = join8(home, cache);
1427
1694
  try {
1428
1695
  const stat = await lstat2(path);
1429
1696
  if (stat.isSymbolicLink())
@@ -1433,12 +1700,12 @@ async function addGlobalCaches(found, home) {
1433
1700
  } catch {}
1434
1701
  }
1435
1702
  }
1436
- async function findCandidates(root, home = homedir3(), withGlobal = true) {
1703
+ async function findCandidates(root, home = homedir5(), withGlobal = true) {
1437
1704
  const found = { candidates: [], skipped: [] };
1438
1705
  const visit = async (dir, depth) => {
1439
1706
  const entries = await listing(dir);
1440
1707
  for (const entry of entries) {
1441
- const path = join5(dir, entry.name);
1708
+ const path = join8(dir, entry.name);
1442
1709
  if (entry.name === ".git")
1443
1710
  continue;
1444
1711
  if (entry.name === ".worktrees" || entry.name === "worktrees" && basename(dir) === ".claude") {
@@ -1448,13 +1715,13 @@ async function findCandidates(root, home = homedir3(), withGlobal = true) {
1448
1715
  }
1449
1716
  for (const worktree of await listing(path)) {
1450
1717
  if (worktree.isDirectory())
1451
- found.candidates.push({ path: join5(path, worktree.name), kind: "worktree" });
1718
+ found.candidates.push({ path: join8(path, worktree.name), kind: "worktree" });
1452
1719
  else if (worktree.isSymbolicLink())
1453
- found.skipped.push({ path: join5(path, worktree.name), reason: "symlink" });
1720
+ found.skipped.push({ path: join8(path, worktree.name), reason: "symlink" });
1454
1721
  }
1455
1722
  continue;
1456
1723
  }
1457
- if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync2(join5(dir, "Cargo.toml")))) {
1724
+ if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync5(join8(dir, "Cargo.toml")))) {
1458
1725
  if (entry.isSymbolicLink()) {
1459
1726
  found.skipped.push({ path, reason: "symlink" });
1460
1727
  } else if (entry.isDirectory()) {
@@ -1462,9 +1729,9 @@ async function findCandidates(root, home = homedir3(), withGlobal = true) {
1462
1729
  if (entry.name === "node_modules") {
1463
1730
  const cache = (await listing(path)).find((inner) => inner.name === ".cache");
1464
1731
  if (cache?.isSymbolicLink())
1465
- found.skipped.push({ path: join5(path, ".cache"), reason: "symlink" });
1732
+ found.skipped.push({ path: join8(path, ".cache"), reason: "symlink" });
1466
1733
  else if (cache?.isDirectory())
1467
- found.candidates.push({ path: join5(path, ".cache"), kind: "cache", inside: path });
1734
+ found.candidates.push({ path: join8(path, ".cache"), kind: "cache", inside: path });
1468
1735
  }
1469
1736
  }
1470
1737
  continue;
@@ -1535,12 +1802,12 @@ var worktreesOf = memo(async (repo) => {
1535
1802
  return branches;
1536
1803
  });
1537
1804
  async function judgeFolder(path, kind, inside) {
1538
- const parent = dirname3(path);
1805
+ const parent = dirname5(path);
1539
1806
  const name = basename(path);
1540
1807
  const located = await toplevelOf(parent);
1541
1808
  if (located === "failed")
1542
1809
  return { skip: "git failed" };
1543
- if (existsSync2(join5(path, ".git")))
1810
+ if (existsSync5(join8(path, ".git")))
1544
1811
  return { skip: "holds a git repository" };
1545
1812
  if (located === "none")
1546
1813
  return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
@@ -1552,7 +1819,7 @@ async function judgeFolder(path, kind, inside) {
1552
1819
  return { entry: { path, kind, committedAt: await lastCommitOf(located.top), action: "remove", inside } };
1553
1820
  }
1554
1821
  async function judgeWorktree(path) {
1555
- const located = await toplevelOf(dirname3(path));
1822
+ const located = await toplevelOf(dirname5(path));
1556
1823
  if (located === "failed")
1557
1824
  return { skip: "git failed" };
1558
1825
  if (located === "none")
@@ -1591,7 +1858,7 @@ async function judge(candidate) {
1591
1858
  async function inspect({ candidates, skipped }) {
1592
1859
  const entries = [];
1593
1860
  const rejected = [...skipped];
1594
- await pooled(candidates, 8, async (candidate) => {
1861
+ await pool(candidates, 8, async (candidate) => {
1595
1862
  const verdict = await judge(candidate);
1596
1863
  if ("skip" in verdict)
1597
1864
  rejected.push({ path: candidate.path, reason: verdict.skip });
@@ -1608,7 +1875,7 @@ async function removeFolder(entry) {
1608
1875
  const stat = await lstat3(entry.path);
1609
1876
  if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename2(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
1610
1877
  return { path: entry.path, removed: false, error: "no longer a plain folder" };
1611
- if (existsSync3(join6(entry.path, ".git")))
1878
+ if (existsSync6(join9(entry.path, ".git")))
1612
1879
  return { path: entry.path, removed: false, error: "holds a git repository" };
1613
1880
  await rm(entry.path, { recursive: true, force: true });
1614
1881
  return { path: entry.path, removed: true };
@@ -1639,7 +1906,9 @@ async function applyAll(entries, done) {
1639
1906
  }
1640
1907
 
1641
1908
  // src/sweep.ts
1642
- var USAGE = `sweep [options] [root]: lists the regenerable folders (node_modules, .output, dist, build, target beside a Cargo.toml), the caches (.nuxt, .next, .turbo, .svelte-kit and node_modules/.cache per project; ~/.bun/install/cache, ~/.npm/_cacache, ~/.cache/{pip,uv,ms-playwright,puppeteer,go-build,typescript} and ~/.cargo/registry, exact paths only, listed only when no root is given or with --only caches) and the .worktrees/* and .claude/worktrees/* entries under root (~/Workspace by default, ${MAX_DEPTH} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
1909
+ var LARGE = 100 * 1024 ** 2;
1910
+ var BIG = 1024 ** 3;
1911
+ var USAGE = `sweep [options] [root]: lists the regenerable folders (node_modules, .output, dist, build, target beside a Cargo.toml), the caches (.nuxt, .next, .turbo, .svelte-kit and node_modules/.cache per project; ~/.bun/install/cache, ~/.npm/_cacache, ~/.cache/{pip,uv,ms-playwright,puppeteer,go-build,typescript} and ~/.cargo/registry, exact paths only, listed only when no root is given or with --only caches) and the .worktrees/* and .claude/worktrees/* entries under root (the configured workspace, ~/Workspace by default, ${MAX_DEPTH} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
1643
1912
 
1644
1913
  Dry unless --apply, which deletes after a confirm showing the total (read from the terminal; off one, pass --yes). A folder is deleted for good, not trashed. Never touched: a symlink, a folder git tracks files in, a build folder git does not ignore. A worktree is removed with git worktree remove, never forced, and only when it is clean and every commit of its branch is on another branch or a remote; the others stay listed as kept and count for nothing in the total. With --docker the Docker usage comes after the list, left to dclean.
1645
1914
 
@@ -1668,8 +1937,8 @@ async function sweep(args) {
1668
1937
  const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], replaces: "find ~/Workspace -name node_modules, du -sh and rm -rf by hand", examples: ["sweep", "sweep ~/Workspace --older 30d --min 100M --apply", "sweep --only worktrees --apply"] });
1669
1938
  if (positionals.length > 1)
1670
1939
  badUsage("give one root");
1671
- const root = resolve(positionals[0] ?? join7(homedir4(), "Workspace"));
1672
- if (!existsSync4(root) || !statSync(root).isDirectory())
1940
+ const root = workspaceRoot({ given: positionals[0] });
1941
+ if (!existsSync7(root) || !statSync2(root).isDirectory())
1673
1942
  fail(`${root} is not a folder`);
1674
1943
  if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
1675
1944
  badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
@@ -1678,7 +1947,7 @@ async function sweep(args) {
1678
1947
  if (minBytes === undefined)
1679
1948
  badUsage(`--min takes a size such as 500K, 10M or 1G, not ${values.min}`);
1680
1949
  const now = Date.now();
1681
- const found = await findCandidates(root, homedir4(), positionals.length === 0 || values.only === "caches");
1950
+ const found = await findCandidates(root, homedir6(), positionals.length === 0 || values.only === "caches");
1682
1951
  const wanted = values.only === undefined ? found.candidates : found.candidates.filter((candidate) => candidate.kind === ONLY_KINDS[values.only]);
1683
1952
  const { entries: all, skipped } = await inspect({ candidates: wanted, skipped: found.skipped });
1684
1953
  const entries = all.filter((entry) => entry.bytes >= minBytes && (olderMs === undefined || entry.committedAt !== undefined && now - entry.committedAt >= olderMs)).sort((a, b) => b.bytes - a.bytes || a.path.localeCompare(b.path));
@@ -1730,10 +1999,17 @@ function print(root, entries, skipped, reclaimable, now) {
1730
1999
  console.log("nothing to sweep");
1731
2000
  return;
1732
2001
  }
1733
- console.log(table([["size", "age", "what", "path", "note"], ...entries.map((entry) => [$e(entry.bytes), entry.committedAt === undefined ? "-" : formatAge(entry.committedAt, now), entry.kind, relative(root, entry.path), entry.action === "keep" ? `kept: ${entry.reason}` : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
2002
+ const colors = paint(process.stdout);
2003
+ const path = role("path", process.stdout);
2004
+ const sized = (bytes) => {
2005
+ if (bytes >= BIG)
2006
+ return colors.red($e(bytes));
2007
+ return bytes >= LARGE ? colors.yellow($e(bytes)) : $e(bytes);
2008
+ };
2009
+ console.log(table([["size", "age", "what", "path", "note"], ...entries.map((entry) => [sized(entry.bytes), entry.committedAt === undefined ? colors.dim("-") : colors.dim(formatAge(entry.committedAt, now)), entry.kind, path(relative(root, entry.path)), entry.action === "keep" ? colors.dim(`kept: ${entry.reason}`) : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
1734
2010
  console.log(`
1735
2011
  ${$e(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (symlinks, tracked or not ignored by git)`}`);
1736
2012
  }
1737
2013
 
1738
2014
  // src/sweep-cli.ts
1739
- process13.exitCode = await runMain({ name: "sweep", run: sweep });
2015
+ process17.exitCode = await runMain({ name: "sweep", run: sweep });